OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
physical_device.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  */
4 #ifndef SRC_VNSW_AGENT_OPER_PHYSICAL_DEVICE_H_
5 #define SRC_VNSW_AGENT_OPER_PHYSICAL_DEVICE_H_
6 
7 #include <cmn/agent_cmn.h>
8 #include <cmn/agent.h>
9 #include <nexthop.h>
10 #include <agent_types.h>
11 #include <oper_db.h>
12 #include <string>
13 
15 class PhysicalDevice;
17 
20  AgentOperDBKey(), uuid_(id) { }
22  AgentOperDBKey(sub_op), uuid_(id) { }
23  virtual ~PhysicalDeviceKey() { }
24 
26 };
27 
30  AgentOperDBData(agent, ifmap_node) {
31  }
33 };
34 
36  PhysicalDeviceData(Agent *agent, const std::string &fq_name,
37  const std::string &name, const std::string &vendor,
38  const IpAddress &ip, const IpAddress &mgmt_ip,
39  const std::string &protocol, IFMapNode *ifmap_node) :
40  PhysicalDeviceDataBase(agent, ifmap_node), fq_name_(fq_name),
41  name_(name), vendor_(vendor), ip_(ip), management_ip_(mgmt_ip),
42  protocol_(protocol) {
43  }
44  virtual ~PhysicalDeviceData() { }
45 
46  std::string fq_name_;
47  std::string name_;
48  std::string vendor_;
51  std::string protocol_;
52 };
53 
56  PhysicalDeviceDataBase(agent, NULL), master_(master) {
57  }
59 
60  bool master_;
61 };
62 
63 class PhysicalDevice : AgentRefCount<PhysicalDevice>, public AgentOperDBEntry {
64  public:
65  typedef enum {
69 
70  explicit PhysicalDevice(const boost::uuids::uuid &id) :
71  AgentOperDBEntry(), uuid_(id), name_(""), vendor_(""), ip_(),
72  protocol_(INVALID), master_(false) { }
73  virtual ~PhysicalDevice() { }
74 
75  virtual bool IsLess(const DBEntry &rhs) const;
76  virtual KeyPtr GetDBRequestKey() const;
77  virtual void SetKey(const DBRequestKey *key);
78  virtual std::string ToString() const;
79  uint32_t GetRefCount() const {
81  }
82 
83  bool Copy(PhysicalDeviceTable *table, const PhysicalDeviceData *data);
84  const boost::uuids::uuid &uuid() const { return uuid_; }
85  const std::string &fq_name() const { return fq_name_; }
86  const std::string &name() const { return name_; }
87  const std::string &vendor() const { return vendor_; }
88  const IpAddress &ip() const { return ip_; }
89  const IpAddress &management_ip() const { return management_ip_; }
91  bool master() const { return master_; }
92  void set_master(bool value) { master_ = value; }
93 
94  void SendObjectLog(AgentLogEvent::type event) const;
95  bool DBEntrySandesh(Sandesh *resp, std::string &name) const;
96 
97  private:
98  friend class PhysicalDeviceTable;
100  std::string fq_name_;
101  std::string name_;
102  std::string vendor_;
106  bool master_;
108 };
109 
111  public:
112  typedef std::set<boost::uuids::uuid> PhysicalDeviceSet;
113  typedef std::map<const std::string, PhysicalDeviceSet> VrfDevicesMap;
114  typedef std::pair<const std::string, PhysicalDeviceSet> VrfDevicesPair;
115  typedef std::set<std::string> VrfSet;
116  typedef std::map<const boost::uuids::uuid, VrfSet> DeviceVrfMap;
117  typedef std::pair<const boost::uuids::uuid, VrfSet> DeviceVrfPair;
118  typedef std::map<IpAddress, PhysicalDevice *> IpToDeviceMap;
119  typedef std::pair<IpAddress, PhysicalDevice *> IpToDevicePair;
120 
121  PhysicalDeviceTable(DB *db, const std::string &name) :
122  AgentOperDBTable(db, name), ip_tree_(), managed_pd_set_(),
124  virtual ~PhysicalDeviceTable() { }
125 
126  virtual std::unique_ptr<DBEntry> AllocEntry(const DBRequestKey *k) const;
127  virtual size_t Hash(const DBEntry *entry) const {return 0;}
128  virtual size_t Hash(const DBRequestKey *key) const {return 0;}
129 
130  virtual DBEntry *OperDBAdd(const DBRequest *req);
131  virtual bool OperDBOnChange(DBEntry *entry, const DBRequest *req);
132  virtual bool OperDBDelete(DBEntry *entry, const DBRequest *req);
133  virtual bool OperDBResync(DBEntry *entry, const DBRequest *req);
134  virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req,
135  const boost::uuids::uuid &u);
136  bool ProcessConfig(IFMapNode *node, DBRequest &req,
137  const boost::uuids::uuid &u);
138  virtual bool IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u);
140  const std::string &context);
141 
143 
145  static DBTableBase *CreateTable(DB *db, const std::string &name);
146  void UpdateIpToDevMap(IpAddress old, IpAddress new_ip, PhysicalDevice *p);
147  void DeleteIpToDevEntry(IpAddress ip);
150  void EnqueueDeviceChange(const boost::uuids::uuid &u, bool master);
151  void UpdateDeviceMastership(const std::string &vrf, ComponentNHList clist,
152  bool del);
153 
154  private:
156  const std::string &vrf);
158  const std::string &vrf);
160  const std::string &vrf);
166 };
167 
168 #endif // SRC_VNSW_AGENT_OPER_PHYSICAL_DEVICE_H_
virtual bool OperDBDelete(DBEntry *entry, const DBRequest *req)
void SendObjectLog(AgentLogEvent::type event) const
virtual ~PhysicalDeviceDataBase()
ManagementProtocol protocol() const
const std::string & vendor() const
uint32_t GetRefCount() const
Definition: agent_db.h:54
virtual void SetKey(const DBRequestKey *key)
void UpdateDeviceMastership(const std::string &vrf, ComponentNHList clist, bool del)
DeviceVrfMap device2vrf_map_
void UpdateIpToDevMap(IpAddress old, IpAddress new_ip, PhysicalDevice *p)
virtual KeyPtr GetDBRequestKey() const
std::string fq_name_
static DBTableBase * CreateTable(DB *db, const std::string &name)
const PhysicalDeviceSet & managed_pd_set() const
std::set< boost::uuids::uuid > PhysicalDeviceSet
PhysicalDeviceKey(const boost::uuids::uuid &id)
PhysicalDeviceSet managed_pd_set_
boost::asio::ip::address IpAddress
Definition: address.h:13
std::pair< const boost::uuids::uuid, VrfSet > DeviceVrfPair
VrfDevicesMap vrf2devices_map_
PhysicalDevice(const boost::uuids::uuid &id)
std::string fq_name_
DISALLOW_COPY_AND_ASSIGN(PhysicalDeviceTable)
boost::uuids::uuid uuid
virtual bool OperDBResync(DBEntry *entry, const DBRequest *req)
void RegisterDBClients(IFMapDependencyManager *dep)
const boost::uuids::uuid & uuid() const
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)
bool DBEntrySandesh(Sandesh *resp, std::string &name) const
void EnqueueDeviceChange(const boost::uuids::uuid &u, bool master)
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
virtual size_t Hash(const DBEntry *entry) const
const IpAddress & ip() const
virtual ~PhysicalDeviceTable()
virtual std::string ToString() const
virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, const std::string &context)
std::map< const boost::uuids::uuid, VrfSet > DeviceVrfMap
PhysicalDeviceTsnManagedData(Agent *agent, bool master)
Definition: db.h:24
PhysicalDevice * Find(const boost::uuids::uuid &u)
std::pair< const std::string, PhysicalDeviceSet > VrfDevicesPair
IpAddress management_ip_
uint8_t type
Definition: load_balance.h:109
Definition: agent.h:358
void AddDeviceToVrfEntry(const boost::uuids::uuid &u, const std::string &vrf)
bool master() const
virtual ~PhysicalDevice()
std::pair< IpAddress, PhysicalDevice * > IpToDevicePair
void set_master(bool value)
PhysicalDeviceKey(const boost::uuids::uuid &id, DBSubOperation sub_op)
boost::uuids::uuid uuid_
virtual std::unique_ptr< DBEntry > AllocEntry(const DBRequestKey *k) const
virtual ~PhysicalDeviceKey()
class boost::shared_ptr< AgentSandesh > AgentSandeshPtr
Definition: agent_db.h:18
boost::uuids::uuid uuid_
bool Copy(PhysicalDeviceTable *table, const PhysicalDeviceData *data)
const std::string & name() const
Definition: db_table.h:110
bool RemoveDeviceToVrfEntry(const boost::uuids::uuid &u, const std::string &vrf)
PhysicalDeviceDataBase(Agent *agent, IFMapNode *ifmap_node)
const std::string & fq_name() const
IFMapNode * ifmap_node() const
Definition: oper_db.h:59
PhysicalDevice * IpToPhysicalDevice(IpAddress ip)
std::string protocol_
std::map< const std::string, PhysicalDeviceSet > VrfDevicesMap
const Agent * agent() const
Definition: oper_db.h:65
std::map< IpAddress, PhysicalDevice * > IpToDeviceMap
const IpAddress & management_ip() const
const std::string & name() const
DBSubOperation
Definition: agent_db.h:96
bool ProcessConfig(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
virtual bool IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u)
std::vector< ComponentNHPtr > ComponentNHList
Definition: nexthop.h:1637
void DeleteIpToDevEntry(IpAddress ip)
virtual bool OperDBOnChange(DBEntry *entry, const DBRequest *req)
uint32_t GetRefCount() const
virtual bool IsLess(const DBEntry &rhs) const
ManagementProtocol protocol_
virtual size_t Hash(const DBRequestKey *key) const
std::set< std::string > VrfSet
DISALLOW_COPY_AND_ASSIGN(PhysicalDevice)
IpAddress management_ip_
std::string name_
IpToDeviceMap ip_tree_
virtual DBEntry * OperDBAdd(const DBRequest *req)
virtual ~PhysicalDeviceData()
std::string vendor_
virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
void ResetDeviceMastership(const boost::uuids::uuid &u, const std::string &vrf)
PhysicalDeviceTable(DB *db, const std::string &name)