OpenSDN source code
physical_device.h
Go to the documentation of this file.
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 
16 class PhysicalDevice;
18 
21  AgentOperDBKey(), uuid_(id) { }
23  AgentOperDBKey(sub_op), uuid_(id) { }
24  virtual ~PhysicalDeviceKey() { }
25 
27 };
28 
32  }
34 };
35 
37  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  const std::string &protocol, IFMapNode *ifmap_node) :
42  name_(name), vendor_(vendor), ip_(ip), management_ip_(mgmt_ip),
43  protocol_(protocol) {
44  }
45  virtual ~PhysicalDeviceData() { }
46 
47  std::string fq_name_;
48  std::string name_;
49  std::string vendor_;
52  std::string protocol_;
53 };
54 
57  PhysicalDeviceDataBase(agent, NULL), master_(master) {
58  }
60 
61  bool master_;
62 };
63 
64 class PhysicalDevice : AgentRefCount<PhysicalDevice>, public AgentOperDBEntry {
65  public:
66  typedef enum {
68  OVS
70 
71  explicit PhysicalDevice(const boost::uuids::uuid &id) :
72  AgentOperDBEntry(), uuid_(id), name_(""), vendor_(""), ip_(),
73  protocol_(INVALID), master_(false) { }
74  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  uint32_t GetRefCount() const {
82  }
83 
84  bool Copy(PhysicalDeviceTable *table, const PhysicalDeviceData *data);
85  const boost::uuids::uuid &uuid() const { return uuid_; }
86  const std::string &fq_name() const { return fq_name_; }
87  const std::string &name() const { return name_; }
88  const std::string &vendor() const { return vendor_; }
89  const IpAddress &ip() const { return ip_; }
90  const IpAddress &management_ip() const { return management_ip_; }
92  bool master() const { return master_; }
93  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;
101  std::string fq_name_;
102  std::string name_;
103  std::string vendor_;
107  bool master_;
109 };
110 
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  PhysicalDeviceTable(DB *db, const std::string &name) :
125  virtual ~PhysicalDeviceTable() { }
126 
127  virtual std::unique_ptr<DBEntry> AllocEntry(const DBRequestKey *k) const;
128  virtual size_t Hash(const DBEntry *entry) const {return 0;}
129  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);
141  const std::string &context);
142 
144 
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);
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:
157  const std::string &vrf);
159  const std::string &vrf);
161  const std::string &vrf);
167 };
168 
169 #endif // SRC_VNSW_AGENT_OPER_PHYSICAL_DEVICE_H_
boost::asio::ip::address IpAddress
Definition: address.h:14
class boost::shared_ptr< AgentSandesh > AgentSandeshPtr
Definition: agent_db.h:21
uint32_t GetRefCount() const
Definition: agent_db.h:57
Definition: agent.h:361
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
const std::string & name() const
Definition: db_table.h:111
Definition: db.h:25
void ResetDeviceMastership(const boost::uuids::uuid &u, const std::string &vrf)
virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
VrfDevicesMap vrf2devices_map_
void AddDeviceToVrfEntry(const boost::uuids::uuid &u, const std::string &vrf)
std::set< boost::uuids::uuid > PhysicalDeviceSet
std::map< const boost::uuids::uuid, VrfSet > DeviceVrfMap
DISALLOW_COPY_AND_ASSIGN(PhysicalDeviceTable)
virtual size_t Hash(const DBRequestKey *key) const
std::pair< const std::string, PhysicalDeviceSet > VrfDevicesPair
std::pair< const boost::uuids::uuid, VrfSet > DeviceVrfPair
void RegisterDBClients(IFMapDependencyManager *dep)
virtual std::unique_ptr< DBEntry > AllocEntry(const DBRequestKey *k) const
PhysicalDevice * IpToPhysicalDevice(IpAddress ip)
std::map< const std::string, PhysicalDeviceSet > VrfDevicesMap
PhysicalDevice * Find(const boost::uuids::uuid &u)
void DeleteIpToDevEntry(IpAddress ip)
virtual bool OperDBOnChange(DBEntry *entry, const DBRequest *req)
std::map< IpAddress, PhysicalDevice * > IpToDeviceMap
PhysicalDeviceSet managed_pd_set_
virtual ~PhysicalDeviceTable()
static DBTableBase * CreateTable(DB *db, const std::string &name)
std::pair< IpAddress, PhysicalDevice * > IpToDevicePair
virtual bool OperDBResync(DBEntry *entry, const DBRequest *req)
void UpdateIpToDevMap(IpAddress old, IpAddress new_ip, PhysicalDevice *p)
DeviceVrfMap device2vrf_map_
void UpdateDeviceMastership(const std::string &vrf, ComponentNHList clist, bool del)
virtual bool IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u)
std::set< std::string > VrfSet
virtual bool OperDBDelete(DBEntry *entry, const DBRequest *req)
const PhysicalDeviceSet & managed_pd_set() const
virtual DBEntry * OperDBAdd(const DBRequest *req)
bool RemoveDeviceToVrfEntry(const boost::uuids::uuid &u, const std::string &vrf)
PhysicalDeviceTable(DB *db, const std::string &name)
IpToDeviceMap ip_tree_
virtual size_t Hash(const DBEntry *entry) const
void EnqueueDeviceChange(const boost::uuids::uuid &u, bool master)
bool ProcessConfig(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, const std::string &context)
const IpAddress & management_ip() const
IpAddress management_ip_
const boost::uuids::uuid & uuid() const
const IpAddress & ip() const
boost::uuids::uuid uuid_
bool Copy(PhysicalDeviceTable *table, const PhysicalDeviceData *data)
ManagementProtocol protocol_
bool master() const
bool DBEntrySandesh(Sandesh *resp, std::string &name) const
const std::string & name() const
virtual std::string ToString() const
std::string fq_name_
virtual void SetKey(const DBRequestKey *key)
virtual ~PhysicalDevice()
uint32_t GetRefCount() const
ManagementProtocol protocol() const
virtual KeyPtr GetDBRequestKey() const
const std::string & fq_name() const
DISALLOW_COPY_AND_ASSIGN(PhysicalDevice)
std::string vendor_
void SendObjectLog(AgentLogEvent::type event) const
void set_master(bool value)
std::string name_
virtual bool IsLess(const DBEntry &rhs) const
const std::string & vendor() const
PhysicalDevice(const boost::uuids::uuid &id)
uint8_t type
Definition: load_balance.h:2
std::vector< ComponentNHPtr > ComponentNHList
Definition: nexthop.h:1638
DBSubOperation
Definition: agent_db.h:99
const Agent * agent() const
Definition: oper_db.h:66
IFMapNode * ifmap_node() const
Definition: oper_db.h:60
virtual ~PhysicalDeviceDataBase()
PhysicalDeviceDataBase(Agent *agent, IFMapNode *ifmap_node)
PhysicalDeviceData(Agent *agent, const std::string &fq_name, const std::string &name, const std::string &vendor, const IpAddress &ip, const IpAddress &mgmt_ip, const std::string &protocol, IFMapNode *ifmap_node)
virtual ~PhysicalDeviceData()
IpAddress management_ip_
std::string protocol_
std::string fq_name_
virtual ~PhysicalDeviceKey()
boost::uuids::uuid uuid_
PhysicalDeviceKey(const boost::uuids::uuid &id, DBSubOperation sub_op)
PhysicalDeviceKey(const boost::uuids::uuid &id)
PhysicalDeviceTsnManagedData(Agent *agent, bool master)
boost::uuids::uuid uuid