LCOV - code coverage report
Current view: top level - vnsw/agent/oper - physical_device.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 30 41 73.2 %
Date: 2026-11-09 02:10:49 Functions: 21 31 67.7 %
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_H_
       6             : #define SRC_VNSW_AGENT_OPER_PHYSICAL_DEVICE_H_
       7             : 
       8             : #include <cmn/agent_cmn.h>
       9             : #include <cmn/agent.h>
      10             : #include <nexthop.h>
      11             : #include <agent_types.h>
      12             : #include <oper_db.h>
      13             : #include <string>
      14             : 
      15             : class IFMapDependencyManager;
      16             : class PhysicalDevice;
      17             : class PhysicalDeviceTable;
      18             : 
      19             : struct PhysicalDeviceKey : public AgentOperDBKey {
      20          29 :     PhysicalDeviceKey(const boost::uuids::uuid &id) :
      21          29 :         AgentOperDBKey(), uuid_(id) { }
      22           0 :     PhysicalDeviceKey(const boost::uuids::uuid &id, DBSubOperation sub_op) :
      23           0 :         AgentOperDBKey(sub_op), uuid_(id) { }
      24          40 :     virtual ~PhysicalDeviceKey() { }
      25             : 
      26             :     boost::uuids::uuid uuid_;
      27             : };
      28             : 
      29             : struct PhysicalDeviceDataBase : public AgentOperDBData {
      30           4 :     PhysicalDeviceDataBase(Agent *agent, IFMapNode *ifmap_node) :
      31           4 :         AgentOperDBData(agent, ifmap_node) {
      32           4 :     }
      33           4 :     virtual ~PhysicalDeviceDataBase() { }
      34             : };
      35             : 
      36             : struct PhysicalDeviceData : public PhysicalDeviceDataBase {
      37           4 :     PhysicalDeviceData(Agent *agent, const std::string &fq_name,
      38             :                        const std::string &name, const std::string &vendor,
      39             :                        const IpAddress &ip, const IpAddress &mgmt_ip,
      40           4 :                        const std::string &protocol, IFMapNode *ifmap_node) :
      41           4 :         PhysicalDeviceDataBase(agent, ifmap_node), fq_name_(fq_name),
      42           4 :         name_(name), vendor_(vendor), ip_(ip), management_ip_(mgmt_ip),
      43           8 :         protocol_(protocol) {
      44           4 :     }
      45           8 :     virtual ~PhysicalDeviceData() { }
      46             : 
      47             :     std::string fq_name_;
      48             :     std::string name_;
      49             :     std::string vendor_;
      50             :     IpAddress ip_;
      51             :     IpAddress management_ip_;
      52             :     std::string protocol_;
      53             : };
      54             : 
      55             : struct PhysicalDeviceTsnManagedData : public PhysicalDeviceDataBase {
      56           0 :     PhysicalDeviceTsnManagedData(Agent *agent, bool master) :
      57           0 :         PhysicalDeviceDataBase(agent, NULL), master_(master) {
      58           0 :     }
      59           0 :     virtual ~PhysicalDeviceTsnManagedData() { }
      60             : 
      61             :     bool master_;
      62             : };
      63             : 
      64             : class PhysicalDevice : AgentRefCount<PhysicalDevice>, public AgentOperDBEntry {
      65             :  public:
      66             :     typedef enum {
      67             :         INVALID,
      68             :         OVS
      69             :     } ManagementProtocol;
      70             : 
      71          25 :     explicit PhysicalDevice(const boost::uuids::uuid &id) :
      72          25 :         AgentOperDBEntry(), uuid_(id), name_(""), vendor_(""), ip_(),
      73          50 :         protocol_(INVALID), master_(false) { }
      74          50 :     virtual ~PhysicalDevice() { }
      75             : 
      76             :     virtual bool IsLess(const DBEntry &rhs) const;
      77             :     virtual KeyPtr GetDBRequestKey() const;
      78             :     virtual void SetKey(const DBRequestKey *key);
      79             :     virtual std::string ToString() const;
      80           7 :     uint32_t GetRefCount() const {
      81           7 :         return AgentRefCount<PhysicalDevice>::GetRefCount();
      82             :     }
      83             : 
      84             :     bool Copy(PhysicalDeviceTable *table, const PhysicalDeviceData *data);
      85          10 :     const boost::uuids::uuid &uuid() const { return uuid_; }
      86           0 :     const std::string &fq_name() const { return fq_name_; }
      87           8 :     const std::string &name() const { return name_; }
      88           0 :     const std::string &vendor() const { return vendor_; }
      89           7 :     const IpAddress &ip() const { return ip_; }
      90             :     const IpAddress &management_ip() const { return management_ip_; }
      91           0 :     ManagementProtocol protocol() const { return protocol_; }
      92           3 :     bool master() const { return master_; }
      93           0 :     void set_master(bool value) { master_ = value; }
      94             : 
      95             :     void SendObjectLog(AgentLogEvent::type event) const;
      96             :     bool DBEntrySandesh(Sandesh *resp, std::string &name) const;
      97             : 
      98             :  private:
      99             :     friend class PhysicalDeviceTable;
     100             :     boost::uuids::uuid uuid_;
     101             :     std::string fq_name_;
     102             :     std::string name_;
     103             :     std::string vendor_;
     104             :     IpAddress ip_;
     105             :     IpAddress management_ip_;
     106             :     ManagementProtocol protocol_;
     107             :     bool master_;
     108             :     DISALLOW_COPY_AND_ASSIGN(PhysicalDevice);
     109             : };
     110             : 
     111             : class PhysicalDeviceTable : public AgentOperDBTable {
     112             :  public:
     113             :     typedef std::set<boost::uuids::uuid> PhysicalDeviceSet;
     114             :     typedef std::map<const std::string, PhysicalDeviceSet> VrfDevicesMap;
     115             :     typedef std::pair<const std::string, PhysicalDeviceSet> VrfDevicesPair;
     116             :     typedef std::set<std::string> VrfSet;
     117             :     typedef std::map<const boost::uuids::uuid, VrfSet> DeviceVrfMap;
     118             :     typedef std::pair<const boost::uuids::uuid, VrfSet> DeviceVrfPair;
     119             :     typedef std::map<IpAddress, PhysicalDevice *> IpToDeviceMap;
     120             :     typedef std::pair<IpAddress, PhysicalDevice *> IpToDevicePair;
     121             : 
     122           2 :     PhysicalDeviceTable(DB *db, const std::string &name) :
     123           2 :         AgentOperDBTable(db, name), ip_tree_(), managed_pd_set_(),
     124           4 :         vrf2devices_map_(), device2vrf_map_() { }
     125           4 :     virtual ~PhysicalDeviceTable() { }
     126             : 
     127             :     virtual std::unique_ptr<DBEntry> AllocEntry(const DBRequestKey *k) const;
     128          12 :     virtual size_t Hash(const DBEntry *entry) const {return 0;}
     129          24 :     virtual size_t Hash(const DBRequestKey *key) const {return 0;}
     130             : 
     131             :     virtual DBEntry *OperDBAdd(const DBRequest *req);
     132             :     virtual bool OperDBOnChange(DBEntry *entry, const DBRequest *req);
     133             :     virtual bool OperDBDelete(DBEntry *entry, const DBRequest *req);
     134             :     virtual bool OperDBResync(DBEntry *entry, const DBRequest *req);
     135             :     virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req,
     136             :             const boost::uuids::uuid &u);
     137             :     bool ProcessConfig(IFMapNode *node, DBRequest &req,
     138             :             const boost::uuids::uuid &u);
     139             :     virtual bool IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u);
     140             :     virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args,
     141             :                                             const std::string &context);
     142             : 
     143             :     PhysicalDevice *Find(const boost::uuids::uuid &u);
     144             : 
     145             :     void RegisterDBClients(IFMapDependencyManager *dep);
     146             :     static DBTableBase *CreateTable(DB *db, const std::string &name);
     147             :     void UpdateIpToDevMap(IpAddress old, IpAddress new_ip, PhysicalDevice *p);
     148             :     void DeleteIpToDevEntry(IpAddress ip);
     149             :     PhysicalDevice *IpToPhysicalDevice(IpAddress ip);
     150           0 :     const PhysicalDeviceSet &managed_pd_set() const { return managed_pd_set_; }
     151             :     void EnqueueDeviceChange(const boost::uuids::uuid &u, bool master);
     152             :     void UpdateDeviceMastership(const std::string &vrf, ComponentNHList clist,
     153             :                                 bool del);
     154             : 
     155             :  private:
     156             :     void ResetDeviceMastership(const boost::uuids::uuid &u,
     157             :                                const std::string &vrf);
     158             :     void AddDeviceToVrfEntry(const boost::uuids::uuid &u,
     159             :                              const std::string &vrf);
     160             :     bool RemoveDeviceToVrfEntry(const boost::uuids::uuid &u,
     161             :                                 const std::string &vrf);
     162             :     IpToDeviceMap ip_tree_;
     163             :     PhysicalDeviceSet managed_pd_set_;
     164             :     VrfDevicesMap vrf2devices_map_;
     165             :     DeviceVrfMap device2vrf_map_;
     166             :     DISALLOW_COPY_AND_ASSIGN(PhysicalDeviceTable);
     167             : };
     168             : 
     169             : #endif  // SRC_VNSW_AGENT_OPER_PHYSICAL_DEVICE_H_

Generated by: LCOV version 1.14