LCOV - code coverage report
Current view: top level - ifmap - ifmap_agent_table.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 8 8 100.0 %
Date: 2026-06-04 02:06:09 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #ifndef ctrlplane_ifmap_agent_table_h
       6             : #define ctrlplane_ifmap_agent_table_h
       7             : 
       8             : #include "db/db_graph_base.h"
       9             : #include "ifmap/ifmap_table.h"
      10             : #include "ifmap/ifmap_link_table.h"
      11             : #include "ifmap/ifmap_object.h"
      12             : #include "boost/asio/io_service.hpp"
      13             : #include "base/timer.h"
      14             : #include "base/task.h"
      15             : #include "sandesh/sandesh_trace.h"
      16             : 
      17             : #define IFMAP_AGENT_LINK_DB_NAME "__ifmap_agentlinkdata__.0"
      18             : extern SandeshTraceBufferPtr IFMapAgentTraceBuf;
      19             : 
      20             : #define IFMAP_AGENT_TRACE(obj, ...) do {                                      \
      21             :     if (LoggingDisabled()) break;                                              \
      22             :     IFMapAgent##obj::TraceMsg(IFMapAgentTraceBuf, __FILE__, __LINE__, ##__VA_ARGS__);     \
      23             : } while (false)
      24             : 
      25             : 
      26             : class DBGraph;
      27             : class IFMapNode;
      28             : 
      29             : 
      30             : class IFMapAgentTable : public IFMapTable {
      31             : public:
      32             : 
      33             :     struct IFMapAgentData : DBRequestData {
      34             :         std::unique_ptr<IFMapObject>content;
      35             :     };
      36             :     typedef boost::function<bool(DBTable *table, IFMapNode *node, DBRequest *req)> PreFilterFn;
      37             : 
      38             :     IFMapAgentTable(DB *db, const std::string &name, DBGraph *graph);
      39             : 
      40             :     virtual void Input(DBTablePartition *partition, DBClient *client,
      41             :                        DBRequest *req);
      42             :     virtual void Clear();
      43             : 
      44             :      // Allocate an IFMapNode.
      45             :     virtual std::unique_ptr<DBEntry> AllocEntry(const DBRequestKey *key) const;
      46             : 
      47             :     static IFMapNode *TableEntryLookup(DB *db, RequestKey *key);
      48             :     void NotifyNode(IFMapNode *node);
      49             :     const DBGraph *GetGraph() const {return graph();};
      50        2776 :     DBGraph *GetGraph() {return graph();};
      51             :     void DeleteNode(IFMapNode *node);
      52          84 :     void RegisterPreFilter(PreFilterFn fn) {pre_filter_ = fn;};
      53             : 
      54             : private:
      55             :     IFMapNode *EntryLocate(IFMapNode *node, RequestKey *key);
      56             :     IFMapNode *EntryLookup(RequestKey *key);
      57             :     IFMapAgentTable* TableFind(const std::string &node_name);
      58             :     void HandlePendingLinks(IFMapNode *);
      59             :     PreFilterFn pre_filter_;
      60             : };
      61             : 
      62             : class IFMapAgentLinkTable : public IFMapLinkTable {
      63             : public:
      64             :     struct RequestKey : DBRequestKey {
      65             :         IFMapTable::RequestKey left_key;
      66             :         IFMapTable::RequestKey right_key;
      67             :         std::string metadata;
      68             :     };
      69             : 
      70             :     struct DeferredNode {
      71             :         IFMapTable::RequestKey node_key;
      72             :         std::string link_metadata;
      73             :     };
      74             : 
      75             :     class comp {
      76             :         public:
      77        2578 :             bool operator()(const IFMapTable::RequestKey &left,
      78             :                             const IFMapTable::RequestKey &right) const {
      79        2578 :                 if (left.id_type != right.id_type)
      80        1470 :                     return left.id_type < right.id_type;
      81             : 
      82        1108 :                 return left.id_name < right.id_name;
      83             :             }
      84             :     };
      85             : 
      86             :     IFMapAgentLinkTable(DB *db, const std::string &name, DBGraph *graph);
      87             :     typedef std::map<IFMapTable::RequestKey, std::list<DeferredNode> *, comp> LinkDefMap;
      88             :     virtual void Input(DBTablePartition *partition, DBClient *client,
      89             :                        DBRequest *req);
      90             :     void IFMapAgentLinkTable_Init(DB *db, DBGraph *graph);
      91             :     static DBTable *CreateTable(DB *db, const std::string &name,
      92             :                                      DBGraph *graph);
      93             :     void EvalDefLink(IFMapTable::RequestKey *key);
      94             :     bool RemoveDefListEntry(LinkDefMap *map, LinkDefMap::iterator &map_it,
      95             :                             std::list<DeferredNode>::iterator *list_it);
      96             :     void DestroyDefLink(uint64_t);
      97           1 :     const LinkDefMap &GetLinkDefMap() const {
      98           1 :         return link_def_map_;
      99             :     }
     100             :     void DelLink(IFMapNode *first, IFMapNode *second, DBGraphEdge *edge);
     101             :     void LinkDefAdd(DBRequest *request);
     102             : private:
     103             :     void AddLink(IFMapNode *left, IFMapNode *right,
     104             :                  const std::string &metadata, uint64_t seq);
     105             : 
     106             :     IFMapLink *FindLink(IFMapNode *left, IFMapNode *right, const std::string &metadata);
     107             : 
     108             :     LinkDefMap link_def_map_;
     109             : };
     110             : 
     111             : 
     112             : class IFMapAgentStaleCleaner {
     113             : public:
     114             :     IFMapAgentStaleCleaner(DB *db, DBGraph *graph);
     115             :     ~IFMapAgentStaleCleaner();
     116             :     class IFMapAgentStaleCleanerWorker;
     117             :     void Clear();
     118             :     bool StaleTimeout(uint64_t);
     119             : 
     120             : private:
     121             :     DB *db_;
     122             :     DBGraph *graph_;
     123             :     uint64_t seq_;
     124             : };
     125             : 
     126             : extern void IFMapAgentLinkTable_Init(DB *db, DBGraph *graph);
     127             : #endif

Generated by: LCOV version 1.14