LCOV - code coverage report
Current view: top level - vnsw/agent/cmn - agent_db.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 0 151 0.0 %
Date: 2026-11-23 02:04:52 Functions: 0 31 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #include "agent_cmn.h"
       7             : #include "agent_db.h"
       8             : #include <cfg/cfg_init.h>
       9             : 
      10           0 : void AgentDBEntry::SetRefState() const {
      11           0 :     AgentDBTable *table = static_cast<AgentDBTable *>(get_table());
      12             :     // Force calling SetState on a const object.
      13             :     // Ideally, SetState should be 'const method' and StateMap mutable
      14           0 :     AgentDBEntry *entry = (AgentDBEntry *)this;
      15           0 :     entry->SetState(table, table->GetRefListenerId(), new AgentDBState(this));
      16           0 : }
      17             : 
      18           0 : void AgentDBEntry::ClearRefState() const {
      19           0 :     AgentDBTable *table = static_cast<AgentDBTable *>(get_table());
      20             :     // Force calling SetState on a const object.
      21             :     // Ideally, ClearState should be 'const method' and StateMap mutable
      22           0 :     AgentDBEntry *entry = (AgentDBEntry *)this;
      23           0 :     table->OnZeroRefcount(entry);
      24           0 :     delete(entry->GetState(table, table->GetRefListenerId()));
      25           0 :     entry->ClearState(table, table->GetRefListenerId());
      26           0 : }
      27             : 
      28           0 : bool AgentDBEntry::IsActive() const {
      29           0 :     return !IsDeleted();
      30             : }
      31             : 
      32           0 : DBState *AgentDBEntry::GetAgentDBEntryState(int listener_id) {
      33             :     DBState *state = dynamic_cast<DBState *>
      34           0 :         (GetState(get_table(), listener_id));
      35           0 :     return state;
      36             : }
      37             : 
      38           0 : const DBState *AgentDBEntry::GetAgentDBEntryState(int listener_id) const {
      39             :     const DBState *state = dynamic_cast<const DBState *>
      40           0 :         (GetState(get_table(), listener_id));
      41           0 :     return state;
      42             : }
      43             : 
      44           0 : void AgentDBEntry::AllocateResources(ResourceManager *resource_manager) {
      45           0 : }
      46             : 
      47           0 : void AgentDBEntry::FreeResources(ResourceManager *resource_manager) {
      48           0 : }
      49             : 
      50           0 : void AgentDBEntry::PostAdd() {
      51           0 : }
      52             : 
      53           0 : static bool FlushNotify(DBTablePartBase *partition, DBEntryBase *e) {
      54           0 :     if (e->IsDeleted()) {
      55           0 :         return true;
      56             :     }
      57             : 
      58           0 :     DBRequest req(DBRequest::DB_ENTRY_DELETE);
      59           0 :     req.key = e->GetDBRequestKey();
      60           0 :     (static_cast<AgentDBTable *>(e->get_table()))->Process(req);
      61           0 :     return true;
      62           0 : }
      63             : 
      64           0 : static void FlushWalkDone(DBTable::DBTableWalkRef walk_ref,
      65             :                           DBTableBase *partition) {
      66           0 :     AgentDBTable *table = static_cast<AgentDBTable *>(partition);
      67           0 :     table->ReleaseWalker(walk_ref);
      68           0 :     table->reset_flush_walk_ref();
      69           0 : }
      70             : 
      71           0 : AgentDBTable::AgentDBTable(DB *db, const std::string &name) :
      72           0 :     DBTable(db, name), ref_listener_id_(-1), agent_(NULL),
      73           0 :     OperDBTraceBuf(SandeshTraceBufferCreate(("Oper " + name), 5000)),
      74           0 :     flush_walk_ref_() {
      75           0 :     ref_listener_id_ = Register(boost::bind(&AgentDBTable::Notify,
      76             :                                             this, _1, _2));
      77           0 : };
      78             : 
      79           0 : AgentDBTable::AgentDBTable(DB *db, const std::string &name,
      80           0 :                            bool del_on_zero_refcount) :
      81           0 :     DBTable(db, name), ref_listener_id_(-1) , agent_(NULL),
      82           0 :     OperDBTraceBuf(SandeshTraceBufferCreate(("Oper " + name), 5000)),
      83           0 :     flush_walk_ref_() {
      84           0 :     ref_listener_id_ = Register(boost::bind(&AgentDBTable::Notify,
      85             :                                             this, _1, _2));
      86           0 : };
      87             : 
      88           0 : AgentDBTable::~AgentDBTable() {
      89           0 :     assert(HasWalkers() == false);
      90           0 : }
      91             : 
      92           0 : void AgentDBTable::NotifyEntry(DBEntryBase *e) {
      93           0 :     agent_->ConcurrencyCheck();
      94             :     DBTablePartBase *tpart =
      95           0 :         static_cast<DBTablePartition *>(GetTablePartition(e));
      96           0 :     tpart->Notify(e);
      97           0 : }
      98             : 
      99           0 : void AgentDBTable::reset_flush_walk_ref() {
     100           0 :     flush_walk_ref_ = NULL;
     101           0 : }
     102             : 
     103           0 : AgentDBEntry *AgentDBTable::FindActiveEntryNoLock(const DBEntry *key) {
     104           0 :     AgentDBEntry *entry = static_cast<AgentDBEntry *> (FindNoLock(key));
     105           0 :     if (entry && (entry->IsActive() == false)) {
     106           0 :         return NULL;
     107             :     }
     108           0 :     return entry;
     109             : }
     110             : 
     111           0 : AgentDBEntry *AgentDBTable::FindActiveEntry(const DBEntry *key) {
     112           0 :     AgentDBEntry *entry = static_cast<AgentDBEntry *> (Find(key));
     113           0 :     if (entry && (entry->IsActive() == false)) {
     114           0 :         return NULL;
     115             :     }
     116           0 :     return entry;
     117             : }
     118             : 
     119           0 : AgentDBEntry *AgentDBTable::FindActiveEntryNoLock(const DBRequestKey *key) {
     120           0 :     AgentDBEntry *entry = static_cast<AgentDBEntry *>(FindNoLock(key));
     121           0 :     if (entry && (entry->IsActive() == false)) {
     122           0 :         return NULL;
     123             :     }
     124           0 :     return entry;
     125             : }
     126             : 
     127           0 : AgentDBEntry *AgentDBTable::FindActiveEntry(const DBRequestKey *key) {
     128           0 :     AgentDBEntry *entry = static_cast<AgentDBEntry *>(Find(key));
     129           0 :     if (entry && (entry->IsActive() == false)) {
     130           0 :         return NULL;
     131             :     }
     132           0 :     return entry;
     133             : }
     134             : 
     135           0 : AgentDBEntry *AgentDBTable::Find(const DBEntry *key, bool ret_del) {
     136           0 :     if (ret_del) {
     137           0 :         return Find(key);
     138             :     } else {
     139           0 :         return FindActiveEntry(key);
     140             :     }
     141             : }
     142             : 
     143           0 : AgentDBEntry *AgentDBTable::Find(const DBRequestKey *key, bool ret_del) {
     144           0 :     if (ret_del) {
     145           0 :         return Find(key);
     146             :     } else {
     147           0 :         return FindActiveEntry(key);
     148             :     }
     149             : }
     150             : 
     151           0 : AgentDBEntry *AgentDBTable::Find(const DBEntry *key) {
     152           0 :     return static_cast<AgentDBEntry *> (DBTable::Find(key));
     153             : }
     154             : 
     155           0 : AgentDBEntry *AgentDBTable::Find(const DBRequestKey *key) {
     156           0 :     return static_cast<AgentDBEntry *>(DBTable::Find(key));
     157             : }
     158             : 
     159           0 : void AgentDBTablePartition::Add(DBEntry *entry) {
     160           0 :     entry->set_table_partition(static_cast<DBTablePartBase *>(this));
     161           0 :     Agent *agent = (static_cast<AgentDBTable *>(parent()))->agent();
     162           0 :     if (agent) {
     163             :         (static_cast<AgentDBEntry *>(entry))->AllocateResources
     164           0 :             (agent->resource_manager());
     165             :     }
     166           0 :     DBTablePartition::Add(entry);
     167           0 :     static_cast<AgentDBEntry *>(entry)->PostAdd();
     168           0 : }
     169             : 
     170           0 : void AgentDBTablePartition::Remove(DBEntryBase *entry) {
     171           0 :     AgentDBEntry *agent_dbentry = static_cast<AgentDBEntry *>(entry);
     172           0 :     if (agent_dbentry->GetRefCount() != 0) {
     173           0 :         agent_dbentry->ClearOnRemoveQ();
     174           0 :         return;
     175             :     }
     176           0 :     Agent *agent = (static_cast<AgentDBTable *>(parent()))->agent();
     177           0 :     if (agent) {
     178             :         (static_cast<AgentDBEntry *>(entry))->FreeResources
     179           0 :             (agent->resource_manager());
     180             :     }
     181           0 :     DBTablePartition::Remove(entry);
     182             : }
     183             : 
     184           0 : bool AgentDBTable::IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &id) {
     185           0 :     id = boost::uuids::nil_uuid();
     186           0 :     return false;
     187             : }
     188             : 
     189           0 : void AgentDBTable::Input(DBTablePartition *partition, DBClient *client,
     190             :                          DBRequest *req) {
     191           0 :     AgentKey *key = static_cast<AgentKey *>(req->key.get());
     192             : 
     193           0 :     if (key->sub_op_ == AgentKey::ADD_DEL_CHANGE) {
     194           0 :         DBTable::Input(partition, client, req);
     195           0 :         return;
     196             :     }
     197             : 
     198           0 :     AgentDBEntry *entry = static_cast<AgentDBEntry *>(partition->Find(key));
     199           0 :     if (entry && (entry->IsActive() == false)) {
     200           0 :         return;
     201             :     }
     202             : 
     203             :     // Dont create an entry on RESYNC sub_op
     204           0 :     if (key->sub_op_ == AgentKey::RESYNC) {
     205           0 :         if (entry == NULL) {
     206           0 :             return;
     207             :         }
     208           0 :         if (Resync(entry, req)) {
     209           0 :             partition->Change(entry);
     210             :         }
     211           0 :         return;
     212             :     }
     213           0 :     return;
     214             : }
     215             : 
     216           0 : void AgentDBTable::Clear() {
     217           0 :     Unregister(ref_listener_id_);
     218           0 :     assert(!HasListeners());
     219             :     DBTablePartition *partition = static_cast<DBTablePartition *>(
     220           0 :         GetTablePartition(0));
     221             : 
     222           0 :     DBEntryBase *next = NULL;
     223           0 :     for (DBEntryBase *entry = partition->GetFirst(); entry; entry = next) {
     224           0 :         next = partition->GetNext(entry);
     225           0 :         if (entry->IsDeleted()) {
     226           0 :             continue;
     227             :         }
     228           0 :         partition->Delete(entry);
     229             :     }
     230           0 : }
     231             : 
     232           0 : void AgentDBTable::Process(DBRequest &req) {
     233           0 :     agent_->ConcurrencyCheck();
     234             :     DBTablePartition *tpart =
     235           0 :         static_cast<DBTablePartition *>(GetTablePartition(req.key.get()));
     236           0 :     tpart->Process(NULL, &req);
     237           0 : }
     238             : 
     239           0 : void AgentDBTable::Flush() {
     240           0 :     flush_walk_ref_ = AllocWalker(boost::bind(FlushNotify, _1, _2),
     241           0 :                                   boost::bind(FlushWalkDone, _1, _2));
     242           0 :     WalkAgain(flush_walk_ref_);
     243           0 : }

Generated by: LCOV version 1.14