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