LCOV - code coverage report
Current view: top level - vnsw/agent/oper - physical_device_vn.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 31 40 77.5 %
Date: 2026-11-09 02:10:49 Functions: 18 26 69.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : #ifndef SRC_VNSW_AGENT_OPER_PHYSICAL_DEVICE_VN_H_
       6             : #define SRC_VNSW_AGENT_OPER_PHYSICAL_DEVICE_VN_H_
       7             : 
       8             : /////////////////////////////////////////////////////////////////////////////
       9             : // Manages DB Table of "Physical Device and Virtual-Network" membership. The
      10             : // table is built based on the IFMap schema
      11             : /////////////////////////////////////////////////////////////////////////////
      12             : #include <cmn/agent_cmn.h>
      13             : #include <cmn/agent.h>
      14             : #include <string>
      15             : 
      16             : class IFMapDependencyManager;
      17             : 
      18             : struct PhysicalDeviceVnToVmi {
      19           8 :     PhysicalDeviceVnToVmi(const boost::uuids::uuid &dev,
      20             :                           const boost::uuids::uuid &vn,
      21           8 :                           const boost::uuids::uuid vmi) :
      22           8 :         dev_(dev), vn_(vn), vmi_(vmi) {
      23           8 :     }
      24           2 :     PhysicalDeviceVnToVmi() :
      25           2 :         dev_(boost::uuids::nil_uuid()), vn_(boost::uuids::nil_uuid()),
      26           4 :         vmi_(boost::uuids::nil_uuid()) {
      27           2 :     }
      28             : 
      29           2 :     PhysicalDeviceVnToVmi(const PhysicalDeviceVnToVmi &rhs) :
      30           2 :         dev_(rhs.dev_), vn_(rhs.vn_), vmi_(rhs.vmi_) {
      31           2 :     }
      32             : 
      33          12 :     virtual ~PhysicalDeviceVnToVmi() { }
      34             : 
      35          14 :     bool operator() (const PhysicalDeviceVnToVmi &lhs,
      36             :                      const PhysicalDeviceVnToVmi &rhs) const {
      37          14 :         if (lhs.dev_ != rhs.dev_)
      38           0 :             return lhs.dev_ < rhs.dev_;
      39          14 :         if (lhs.vn_ != rhs.vn_)
      40           0 :             return lhs.vn_ < rhs.vn_;
      41          14 :         return lhs.vmi_ < rhs.vmi_;
      42             :     }
      43             : 
      44             :     boost::uuids::uuid dev_;
      45             :     boost::uuids::uuid vn_;
      46             :     boost::uuids::uuid vmi_;
      47             : };
      48             : 
      49             : struct PhysicalDeviceVnKey : public AgentKey {
      50           6 :     explicit PhysicalDeviceVnKey(const boost::uuids::uuid &dev_uuid,
      51           6 :                                  const boost::uuids::uuid &vn_uuid) :
      52           6 :         AgentKey(), device_uuid_(dev_uuid), vn_uuid_(vn_uuid) { }
      53          11 :     virtual ~PhysicalDeviceVnKey() { }
      54             : 
      55             :     boost::uuids::uuid device_uuid_;
      56             :     boost::uuids::uuid vn_uuid_;
      57             : };
      58             : 
      59             : struct PhysicalDeviceVnData : public AgentData {
      60           4 :     PhysicalDeviceVnData() { }
      61           8 :     virtual ~PhysicalDeviceVnData() { }
      62             : };
      63             : 
      64             : class PhysicalDeviceVn : AgentRefCount<PhysicalDeviceVn>,
      65             :     public AgentDBEntry {
      66             :  public:
      67           7 :     PhysicalDeviceVn(const boost::uuids::uuid &device_uuid,
      68           7 :                           const boost::uuids::uuid &vn_uuid) :
      69           7 :         device_uuid_(device_uuid), vn_uuid_(vn_uuid), device_(), vn_(),
      70          14 :         vxlan_id_(0), tor_ip_(Ip4Address(0)), device_display_name_() { }
      71          14 :     virtual ~PhysicalDeviceVn() { }
      72             : 
      73             :     virtual bool IsLess(const DBEntry &rhs) const;
      74             :     virtual void SetKey(const DBRequestKey *key);
      75             :     virtual std::string ToString() const;
      76           3 :     uint32_t GetRefCount() const {
      77           3 :         return AgentRefCount<PhysicalDeviceVn>::GetRefCount();
      78             :     }
      79             :     DBEntryBase::KeyPtr GetDBRequestKey() const;
      80             : 
      81           0 :     const boost::uuids::uuid &device_uuid() const { return device_uuid_; }
      82           0 :     PhysicalDevice *device() const { return device_.get(); }
      83             : 
      84           0 :     const boost::uuids::uuid &vn_uuid() const { return vn_uuid_; }
      85           0 :     VnEntry *vn() const { return vn_.get(); }
      86           0 :     int vxlan_id() const { return vxlan_id_; }
      87             :     const IpAddress &tor_ip() const {return tor_ip_;}
      88             :     const std::string &device_display_name() const {return device_display_name_;}
      89             : 
      90             :     bool Copy(PhysicalDeviceVnTable *table, const PhysicalDeviceVnData *data);
      91             :     void SendObjectLog(AgentLogEvent::type event) const;
      92             :     bool DBEntrySandesh(Sandesh *sresp, std::string &name) const;
      93             : 
      94             :  private:
      95             :     friend class PhysicalDeviceVnTable;
      96             :     boost::uuids::uuid device_uuid_;
      97             :     boost::uuids::uuid vn_uuid_;
      98             : 
      99             :     PhysicalDeviceRef device_;
     100             :     VnEntryRef vn_;
     101             :     int vxlan_id_;
     102             :     IpAddress tor_ip_;
     103             :     std::string device_display_name_;
     104             :     DISALLOW_COPY_AND_ASSIGN(PhysicalDeviceVn);
     105             : };
     106             : 
     107             : class PhysicalDeviceVnTable : public AgentDBTable {
     108             :  public:
     109             :     struct Compare {
     110             :         bool operator() (const PhysicalDeviceVnKey &left,
     111             :                          const PhysicalDeviceVnKey &right) const {
     112             :             if (left.device_uuid_ != right.device_uuid_) {
     113             :                 return left.device_uuid_ < right.device_uuid_;
     114             :             }
     115             :             return left.vn_uuid_ < right.vn_uuid_;
     116             :         }
     117             :     };
     118             : 
     119             :     typedef std::set<PhysicalDeviceVnToVmi, PhysicalDeviceVnToVmi> ConfigTree;
     120             : 
     121             :     PhysicalDeviceVnTable(DB *db, const std::string &name);
     122           4 :     virtual ~PhysicalDeviceVnTable() { }
     123             : 
     124             :     virtual std::unique_ptr<DBEntry> AllocEntry(const DBRequestKey *k) const;
     125           0 :     virtual size_t Hash(const DBEntry *entry) const {return 0;}
     126           6 :     virtual size_t Hash(const DBRequestKey *key) const {return 0;}
     127             : 
     128             :     virtual DBEntry *Add(const DBRequest *req);
     129             :     virtual bool OnChange(DBEntry *entry, const DBRequest *req);
     130             :     virtual bool Delete(DBEntry *entry, const DBRequest *req);
     131             :     virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req,
     132             :             const boost::uuids::uuid &u);
     133             :     virtual bool Resync(DBEntry *entry, const DBRequest *req);
     134             :     virtual void Clear();
     135             :     virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args,
     136             :                                             const std::string &context);
     137             : 
     138             :     void ProcessConfig(const boost::uuids::uuid &dev,
     139             :                        const boost::uuids::uuid &vn);
     140             :     bool AddConfigEntry(const boost::uuids::uuid &vmi,
     141             :                         const boost::uuids::uuid &dev,
     142             :                         const boost::uuids::uuid &vn);
     143             :     bool DeleteConfigEntry(const boost::uuids::uuid &vmi,
     144             :                            const boost::uuids::uuid &dev,
     145             :                            const boost::uuids::uuid &vn);
     146           0 :     const ConfigTree &config_tree() const { return config_tree_; }
     147             : 
     148             :     static DBTableBase *CreateTable(DB *db, const std::string &name);
     149             : 
     150             :     bool DeviceVnWalk(DBTablePartBase *partition, DBEntryBase *entry);
     151             :     void DeviceVnWalkDone(DBTable::DBTableWalkRef walk_ref, DBTableBase *partition);
     152             :     // Handle change in VxLan Identifier mode from global-config
     153             :     void UpdateVxLanNetworkIdentifierMode();
     154             : 
     155             :  private:
     156             :     ConfigTree config_tree_;
     157             :     DBTable::DBTableWalkRef vxlan_id_walk_ref_;
     158             :     DISALLOW_COPY_AND_ASSIGN(PhysicalDeviceVnTable);
     159             : };
     160             : 
     161             : #endif  // SRC_VNSW_AGENT_OPER_PHYSICAL_DEVICE_VN_H_

Generated by: LCOV version 1.14