LCOV - code coverage report
Current view: top level - vnsw/agent/oper - vm.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 17 23 73.9 %
Date: 2026-11-09 02:10:49 Functions: 17 19 89.5 %
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             : #ifndef vnsw_agent_vm_hpp
       7             : #define vnsw_agent_vm_hpp
       8             : 
       9             : #include <atomic>
      10             : 
      11             : #include <cmn/agent_cmn.h>
      12             : #include <oper/oper_db.h>
      13             : #include <agent_types.h>
      14             : 
      15             : typedef std::map<std::string, boost::uuids::uuid> VmNameUuidTree;
      16             : 
      17             : struct VmKey : public AgentOperDBKey {
      18        2156 :     VmKey(boost::uuids::uuid id) : AgentOperDBKey(), uuid_(id) {} ;
      19        2985 :     virtual ~VmKey() { }
      20             : 
      21             :     boost::uuids::uuid uuid_;
      22             : };
      23             : 
      24             : struct VmData : public AgentOperDBData {
      25             :     typedef vector<boost::uuids::uuid> SGUuidList;
      26         662 :     VmData(Agent *agent, IFMapNode *node, const std::string &name,
      27         662 :            const SGUuidList &sg_list) :
      28         662 :         AgentOperDBData(agent, node), name_(name), sg_list_(sg_list) { }
      29        1324 :     virtual ~VmData() { }
      30             : 
      31             :     std::string name_;
      32             :     SGUuidList sg_list_;
      33             : };
      34             : 
      35             : class VmEntry : AgentRefCount<VmEntry>, public AgentOperDBEntry {
      36             : public:
      37             :     static const int kVectorIncreaseSize = 16;
      38             : 
      39             :     VmEntry(const boost::uuids::uuid &id);
      40             :     virtual ~VmEntry();
      41             : 
      42             :     virtual bool IsLess(const DBEntry &rhs) const;
      43             :     virtual KeyPtr GetDBRequestKey() const;
      44             :     virtual void SetKey(const DBRequestKey *key);
      45             :     virtual string ToString() const;
      46        1618 :     const string &GetCfgName() const { return name_; }
      47         165 :     void SetCfgName(std::string name) { name_ = name; }
      48             : 
      49        3294 :     const boost::uuids::uuid &GetUuid() const { return uuid_; }
      50             : 
      51         994 :     uint32_t GetRefCount() const {
      52         994 :         return AgentRefCount<VmEntry>::GetRefCount();
      53             :     }
      54             : 
      55             :     void SendObjectLog(AgentLogEvent::type event) const;
      56             :     bool DBEntrySandesh(Sandesh *sresp, std::string &name) const;
      57             : 
      58          79 :     uint32_t flow_count() const { return flow_count_; }
      59             :     void update_flow_count(int val) const;
      60             : 
      61           0 :     uint32_t linklocal_flow_count() const { return linklocal_flow_count_; }
      62           0 :     void update_linklocal_flow_count(int val) const {
      63           0 :         int tmp = linklocal_flow_count_.fetch_add(val);
      64           0 :         if (val < 0)
      65           0 :             assert(tmp >= val);
      66           0 :     }
      67             : 
      68        1000 :     bool drop_new_flows() const { return drop_new_flows_; }
      69             : 
      70             : private:
      71             :     void SetInterfacesDropNewFlows(bool drop_new_flows) const;
      72             :     friend class VmTable;
      73             :     boost::uuids::uuid uuid_;
      74             :     std::string name_;
      75             :     mutable std::atomic<int> flow_count_;
      76             :     mutable std::atomic<int> linklocal_flow_count_;
      77             :     mutable bool drop_new_flows_;
      78             :     DISALLOW_COPY_AND_ASSIGN(VmEntry);
      79             : };
      80             : 
      81             : class VmTable : public AgentOperDBTable {
      82             : public:
      83           2 :     VmTable(DB *db, const std::string &name) : AgentOperDBTable(db, name) { }
      84           4 :     virtual ~VmTable() { }
      85             : 
      86             :     virtual std::unique_ptr<DBEntry> AllocEntry(const DBRequestKey *k) const;
      87        1816 :     virtual size_t Hash(const DBEntry *entry) const {return 0;}
      88        2156 :     virtual size_t Hash(const DBRequestKey *key) const {return 0;}
      89             : 
      90             :     virtual DBEntry *OperDBAdd(const DBRequest *req);
      91             :     virtual bool OperDBOnChange(DBEntry *entry, const DBRequest *req);
      92             :     virtual bool OperDBDelete(DBEntry *entry, const DBRequest *req);
      93             :     virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req,
      94             :             const boost::uuids::uuid &u);
      95             :     virtual bool IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u);
      96             :     bool ProcessConfig(IFMapNode *node, DBRequest &req,
      97             :             const boost::uuids::uuid &u);
      98             :     virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args,
      99             :                                             const std::string &context);
     100             : 
     101             :     static DBTableBase *CreateTable(DB *db, const std::string &name);
     102             :     static VmTable *GetInstance() {return vm_table_;}
     103             : 
     104             :     boost::uuids::uuid GetVmUuid(const std::string &name);
     105             : 
     106             : private:
     107             :     static VmTable *vm_table_;
     108             :     VmNameUuidTree vm_name_uuid_tree_;
     109             :     DISALLOW_COPY_AND_ASSIGN(VmTable);
     110             : };
     111             : 
     112             : #endif // vnsw_agent_vm_hpp

Generated by: LCOV version 1.14