OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vxlan.h
Go to the documentation of this file.
1 // vxlan.h
3 // vnsw/agent
5 
6 #ifndef vnsw_agent_vxlan_hpp
7 #define vnsw_agent_vxlan_hpp
8 
9 #include <cmn/agent_cmn.h>
10 #include <cmn/agent.h>
11 #include <agent_types.h>
12 #include <oper/nexthop.h>
13 
14 class VxLanId : AgentRefCount<VxLanId>, public AgentDBEntry {
15 public:
16  VxLanId(uint32_t vxlan_id) : AgentDBEntry(), vxlan_id_(vxlan_id){ }
17  virtual ~VxLanId();
18 
19  bool IsLess(const DBEntry &rhs) const {
20  const VxLanId &vxlan_id = static_cast<const VxLanId &>(rhs);
21  return vxlan_id_ < vxlan_id.vxlan_id_;
22  };
23  virtual string ToString() const { return "vxlan_id"; };
24  virtual void SetKey(const DBRequestKey *key);
25  virtual KeyPtr GetDBRequestKey() const;
26 
27  uint32_t vxlan_id() const {return vxlan_id_;};
28  const NextHop *nexthop() const {return nh_.get();};
29 
30  uint32_t GetRefCount() const {
32  }
33 
34  bool DBEntrySandesh(Sandesh *sresp, std::string &name) const;
35  void SendObjectLog(const AgentDBTable *table,
36  AgentLogEvent::type event) const;
37 
38 private:
39  uint32_t vxlan_id_;
41  friend class VxLanTable;
43 };
44 
45 class VxLanIdKey : public AgentKey {
46 public:
47  VxLanIdKey(uint32_t vxlan_id) :
48  AgentKey(), vxlan_id_(vxlan_id) { };
49  virtual ~VxLanIdKey() { };
50  uint32_t vxlan_id() const {return vxlan_id_;}
51 
52 private:
53  uint32_t vxlan_id_;
54 };
55 
56 class VxLanIdData : public AgentData {
57 public:
58  VxLanIdData(const string &vrf_name,
59  DBRequest &req,
60  bool mirror_destination,
61  bool bridge) :
62  vrf_name_(vrf_name) {
63  nh_req_.Swap(&req);
65  bridge_ = bridge;
66  };
67  virtual ~VxLanIdData() { };
68  string &vrf_name() {return vrf_name_;}
69  DBRequest &nh_req() {return nh_req_;}
70  bool mirror_destination() const {return mirror_destination_;}
71  bool bridge() const {return bridge_;}
72 
73 private:
74  string vrf_name_;
77  bool bridge_;
78 };
79 
81 // Implementation of Vxlan(vxlan_id) Table
83 class VxLanTable : public AgentDBTable {
84 public:
86  // VxLan entries are created from VN.
87  // Ideally, each VN should have a different VxLan configured. However,
88  // there can be transition where more than one VN can have same VxLan.
89  // A config tree is maintained to handle the transition cases.
90  //
91  // The config tree is keyed with <vxlan-id, vn-name> and data is
92  // <vrf-name, flood_unknown_unicast, active>
93  //
94  // For a given vxlan, there can be more than one ConfigEntries. The active
95  // flag speicified, which config-entry is master for the vxlan.
96  //
97  // When first config entry is added for a vxlan, it becomes "active" and
98  // also creates a vxlan entry.
99  //
100  // When subsequent config entry are added, they become "inactive" and are
101  // added to config-tree. There is no change done to vxlan entry
102  //
103  // If an "active" config-entry is deleted, we will pick the first entry
104  // for given vxlan and make it "active"
106  struct ConfigKey {
107  ConfigKey(uint32_t vxlan_id, const boost::uuids::uuid &vn) :
108  vxlan_id_(vxlan_id), vn_(vn) {
109  }
110  ConfigKey() : vxlan_id_(0), vn_() { }
111 
112  bool operator()(const ConfigKey &lhs, const ConfigKey &rhs) const {
113  if (lhs.vxlan_id_ != rhs.vxlan_id_)
114  return lhs.vxlan_id_ < rhs.vxlan_id_;
115 
116  return lhs.vn_ < rhs.vn_;
117  }
118 
119  uint32_t vxlan_id_;
121  };
122 
123  struct ConfigEntry {
124  ConfigEntry(const std::string &vrf, bool flood_unknown_unicast,
125  bool active, bool mirror_destination, bool bridge) :
126  vrf_(vrf), flood_unknown_unicast_(flood_unknown_unicast),
127  active_(active), mirror_destination_(mirror_destination),
128  learning_enabled_(false), bridge_(bridge) {
129  }
130 
131  std::string vrf_;
133  bool active_;
136  bool bridge_;
137  };
138  typedef std::map<ConfigKey, ConfigEntry, ConfigKey> ConfigTree;
139  typedef std::map<uint32_t, ComponentNHKeyList>VxlanCompositeNHList;
140  typedef std::pair<uint32_t , ComponentNHKeyList> VxlanCompositeNHEntry;
141  static const uint32_t kInvalidvxlan_id = 0;
142  VxLanTable(DB *db, const std::string &name) : AgentDBTable(db, name) { };
143  virtual ~VxLanTable() { };
144 
145  virtual std::unique_ptr<DBEntry> AllocEntry(const DBRequestKey *k) const;
146  virtual size_t Hash(const DBEntry *entry) const {return 0;};
147  virtual size_t Hash(const DBRequestKey *key) const {return 0;};
148 
149  virtual DBEntry *Add(const DBRequest *req);
150  virtual bool OnChange(DBEntry *entry, const DBRequest *req);
151  virtual bool Delete(DBEntry *entry, const DBRequest *req);
152  virtual void OnZeroRefcount(AgentDBEntry *e);
154  const std::string &context);
155 
156  void Process(DBRequest &req);
157 
158  void Create(uint32_t vxlan_id, const std::string &vrf_name,
159  bool flood_unknown_unicast, bool mirror_destination,
160  bool learning_enabled, bool bridge);
161  void Delete(uint32_t vxlan_id);
162 
163  VxLanId *Find(uint32_t vxlan_id);
164  VxLanId *FindNoLock(uint32_t vxlan_id);
165  VxLanId *Locate(uint32_t vxlan_id, const boost::uuids::uuid &vn,
166  const std::string &vrf, bool flood_unknown_unicast,
167  bool mirror_destination, bool learning_enabled,
168  bool bridge);
169  VxLanId *Delete(uint32_t vxlan_id, const boost::uuids::uuid &vn);
170  const ConfigTree &config_tree() const { return config_tree_; }
171  static DBTableBase *CreateTable(DB *db, const std::string &name);
172  void Initialize();
173  void Register();
174  void Shutdown();
175  void VmInterfaceNotify(DBTablePartBase *partition, DBEntryBase *e);
176  bool AddCompositeNH(uint32_t vxlan_id, ComponentNHKeyPtr nh_key);
177  bool DeleteCompositeNH(uint32_t vxlan_id, ComponentNHKeyPtr nh_key);
178 private:
179  bool ChangeHandler(VxLanId *vxlan_id, const DBRequest *req);
185 };
186 
187 #endif // vnsw_agent_vxlan_hpp
bool DeleteCompositeNH(uint32_t vxlan_id, ComponentNHKeyPtr nh_key)
Definition: vxlan.cc:101
DISALLOW_COPY_AND_ASSIGN(VxLanTable)
virtual void OnZeroRefcount(AgentDBEntry *e)
Definition: vxlan.cc:233
boost::uuids::uuid vn_
Definition: vxlan.h:120
virtual size_t Hash(const DBEntry *entry) const
Definition: vxlan.h:146
void SendObjectLog(const AgentDBTable *table, AgentLogEvent::type event) const
Definition: vxlan.cc:386
uint32_t GetRefCount() const
Definition: agent_db.h:54
virtual DBEntry * Add(const DBRequest *req)
Definition: vxlan.cc:158
uint32_t vxlan_id_
Definition: vxlan.h:119
VxLanId(uint32_t vxlan_id)
Definition: vxlan.h:16
string vrf_name_
Definition: vxlan.h:74
void Register()
Definition: vxlan.cc:39
static DBTableBase * CreateTable(DB *db, const std::string &name)
Definition: vxlan.cc:324
ConfigEntry(const std::string &vrf, bool flood_unknown_unicast, bool active, bool mirror_destination, bool bridge)
Definition: vxlan.h:124
bool IsLess(const DBEntry &rhs) const
Definition: vxlan.h:19
VxlanCompositeNHList vxlan_composite_nh_map_
Definition: vxlan.h:183
int ListenerId
Definition: db_table.h:62
virtual size_t Hash(const DBRequestKey *key) const
Definition: vxlan.h:147
bool operator()(const ConfigKey &lhs, const ConfigKey &rhs) const
Definition: vxlan.h:112
boost::uuids::uuid uuid
boost::shared_ptr< const ComponentNHKey > ComponentNHKeyPtr
Definition: nexthop.h:1639
DBRequest nh_req_
Definition: vxlan.h:75
uint32_t GetRefCount() const
Definition: vxlan.h:30
std::map< ConfigKey, ConfigEntry, ConfigKey > ConfigTree
Definition: vxlan.h:138
Definition: vxlan.h:14
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
uint32_t vxlan_id_
Definition: vxlan.h:53
std::string vrf_
Definition: vxlan.h:131
void Swap(DBRequest *rhs)
Definition: db_table.cc:43
ConfigTree config_tree_
Definition: vxlan.h:180
virtual ~VxLanIdKey()
Definition: vxlan.h:49
uint32_t vxlan_id() const
Definition: vxlan.h:50
bool DBEntrySandesh(Sandesh *sresp, std::string &name) const
Definition: vxlan.cc:373
virtual KeyPtr GetDBRequestKey() const
Definition: vxlan.cc:25
virtual std::unique_ptr< DBEntry > AllocEntry(const DBRequestKey *k) const
Definition: vxlan.cc:145
Definition: db.h:24
VxLanTable(DB *db, const std::string &name)
Definition: vxlan.h:142
void Process(DBRequest &req)
Definition: vxlan.cc:151
virtual ~VxLanTable()
Definition: vxlan.h:143
DBTableBase::ListenerId interface_listener_id_
Definition: vxlan.h:182
ConfigKey(uint32_t vxlan_id, const boost::uuids::uuid &vn)
Definition: vxlan.h:107
static const uint32_t kInvalidvxlan_id
Definition: vxlan.h:141
uint8_t type
Definition: load_balance.h:109
bool mirror_destination() const
Definition: vxlan.h:70
bool mirror_destination_
Definition: vxlan.h:76
void Create(uint32_t vxlan_id, const std::string &vrf_name, bool flood_unknown_unicast, bool mirror_destination, bool learning_enabled, bool bridge)
Definition: vxlan.cc:330
VxLanId * Locate(uint32_t vxlan_id, const boost::uuids::uuid &vn, const std::string &vrf, bool flood_unknown_unicast, bool mirror_destination, bool learning_enabled, bool bridge)
Definition: vxlan.cc:242
std::pair< uint32_t, ComponentNHKeyList > VxlanCompositeNHEntry
Definition: vxlan.h:140
VxLanIdData(const string &vrf_name, DBRequest &req, bool mirror_destination, bool bridge)
Definition: vxlan.h:58
void VmInterfaceNotify(DBTablePartBase *partition, DBEntryBase *e)
Definition: vxlan.cc:49
class boost::shared_ptr< AgentSandesh > AgentSandeshPtr
Definition: agent_db.h:18
const std::string & name() const
Definition: db_table.h:110
DBRequest & nh_req()
Definition: vxlan.h:69
void Initialize()
Definition: vxlan.cc:35
virtual string ToString() const
Definition: vxlan.h:23
NextHopRef nh_
Definition: vxlan.h:40
const NextHop * nexthop() const
Definition: vxlan.h:28
DISALLOW_COPY_AND_ASSIGN(VxLanId)
virtual bool Delete(DBEntry *entry, const DBRequest *req)
Definition: vxlan.cc:217
bool bridge() const
Definition: vxlan.h:71
std::map< uint32_t, ComponentNHKeyList > VxlanCompositeNHList
Definition: vxlan.h:139
uint32_t vxlan_id() const
Definition: vxlan.h:27
bool AddCompositeNH(uint32_t vxlan_id, ComponentNHKeyPtr nh_key)
Definition: vxlan.cc:122
VxLanId * Find(uint32_t vxlan_id)
Definition: vxlan.cc:223
virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, const std::string &context)
Definition: vxlan.cc:432
void Shutdown()
Definition: vxlan.cc:45
const ConfigTree & config_tree() const
Definition: vxlan.h:170
VxLanIdKey(uint32_t vxlan_id)
Definition: vxlan.h:47
uint32_t vxlan_id_
Definition: vxlan.h:39
bool flood_unknown_unicast_
Definition: vxlan.h:132
bool bridge_
Definition: vxlan.h:77
virtual ~VxLanId()
Definition: vxlan.cc:19
DBTableBase::ListenerId vn_table_listener_id_
Definition: vxlan.h:181
bool ChangeHandler(VxLanId *vxlan_id, const DBRequest *req)
Definition: vxlan.cc:176
virtual void SetKey(const DBRequestKey *key)
Definition: vxlan.cc:30
string & vrf_name()
Definition: vxlan.h:68
VxLanId * FindNoLock(uint32_t vxlan_id)
Definition: vxlan.cc:228
virtual ~VxLanIdData()
Definition: vxlan.h:67
boost::intrusive_ptr< NextHop > NextHopRef
Definition: agent.h:124
virtual bool OnChange(DBEntry *entry, const DBRequest *req)
Definition: vxlan.cc:167