OpenSDN source code
vn_ovsdb.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 extern "C" {
7 #include <ovsdb_wrapper.h>
8 };
9 
10 #include <oper/vn.h>
11 #include <oper/vrf.h>
12 #include <oper/vxlan.h>
13 #include <ovsdb_types.h>
14 
17 #include <vn_ovsdb.h>
18 
22 
23 VnOvsdbEntry::VnOvsdbEntry(VnOvsdbObject *table,
24  const boost::uuids::uuid &uuid) : OvsdbDBEntry(table), uuid_(uuid),
25  vrf_(NULL, this), vxlan_id_(0), name_("") {
26 }
27 
28 void VnOvsdbEntry::AddMsg(struct ovsdb_idl_txn *txn) {
29  VnEntry *vn = static_cast<VnEntry *>(GetDBEntry());
30  vrf_ = vn->GetVrf();
31 }
32 
33 void VnOvsdbEntry::ChangeMsg(struct ovsdb_idl_txn *txn) {
34  UnicastMacLocalOvsdb *uc_obj =
36  // Entries in Unicast Mac Local Table are dependent on vn/vrf
37  // and VxLAN ID on Change of this entry trigger Vrf re-eval for
38  // entries in Unicast Mac Local Table
39  uc_obj->VrfReEvalEnqueue(vrf_.get());
40 
41  // Update VRF with the current value.
42  VnEntry *vn = static_cast<VnEntry *>(GetDBEntry());
43  vrf_ = vn->GetVrf();
44 }
45 
46 void VnOvsdbEntry::DeleteMsg(struct ovsdb_idl_txn *txn) {
47  UnicastMacLocalOvsdb *uc_obj =
49  // Entries in Unicast Mac Local Table are dependent on vn/vrf
50  // on delete of this entry trigger Vrf re-eval for entries in
51  // Unicast Mac Local Table
52  uc_obj->VrfReEvalEnqueue(vrf_.get());
53  //For multicast vrf delete needs to known for deleting
54  //route.
55  MulticastMacLocalOvsdb *mc_obj =
57  mc_obj->VrfReEvalEnqueue(vrf_.get());
58  vrf_ = NULL;
59 }
60 
61 bool VnOvsdbEntry::Sync(DBEntry *db_entry) {
62  VnEntry *vn = static_cast<VnEntry *>(db_entry);
63  uint32_t vxlan_id = vn->GetVxLanId();
64  bool ret = false;
65 
66  if (vrf_.get() != vn->GetVrf()) {
67  // Update Vrf After taking action on previous vrf in Add/Change
68  ret = true;
69  }
70 
71  if (vxlan_id_ != vxlan_id) {
73  ret = true;
74  }
75 
76  if (name_ != vn->GetName()) {
77  name_ = vn->GetName();
78  ret = true;
79  }
80 
81  return ret;
82 }
83 
84 bool VnOvsdbEntry::IsLess(const KSyncEntry &entry) const {
85  const VnOvsdbEntry &vn_entry = static_cast<const VnOvsdbEntry&>(entry);
86  return uuid_ < vn_entry.uuid_;
87 }
88 
90  return NULL;
91 }
92 
94  return vrf_.get();
95 }
96 
98  OvsdbDBObject(idl, table, false) {
99 }
100 
102 }
103 
104 KSyncEntry *VnOvsdbObject::Alloc(const KSyncEntry *key, uint32_t index) {
105  const VnOvsdbEntry *k_entry =
106  static_cast<const VnOvsdbEntry *>(key);
107  VnOvsdbEntry *entry = new VnOvsdbEntry(this, k_entry->uuid_);
108  return entry;
109 }
110 
112  const VnEntry *entry = static_cast<const VnEntry *>(db_entry);
113  VnOvsdbEntry *key = new VnOvsdbEntry(this, entry->GetUuid());
114  return static_cast<KSyncEntry *>(key);
115 }
116 
118  const DBEntry *entry, const OvsdbDBEntry *ovsdb_entry) {
119  const VnEntry *vn = static_cast<const VnEntry *>(entry);
120  // only accept Virtual Networks with non-NULL vrf
121  // and non zero vxlan id
122  if (vn->GetVrf() == NULL || vn->GetVxLanId() == 0) {
123  return DBFilterDelete;
124  }
125  return DBFilterAccept;
126 }
127 
DBEntry * GetDBEntry()
Definition: ksync_entry.h:272
UnicastMacLocalOvsdb * unicast_mac_local_ovsdb()
MulticastMacLocalOvsdb * multicast_mac_local_ovsdb()
OvsdbDBObject * table_
Definition: ovsdb_entry.h:111
OvsdbClientIdl * client_idl()
Definition: ovsdb_object.h:77
uint32_t vxlan_id()
Definition: vn_ovsdb.h:45
void ChangeMsg(struct ovsdb_idl_txn *)
Definition: vn_ovsdb.cc:33
uint32_t vxlan_id_
Definition: vn_ovsdb.h:52
VrfEntryRef vrf_
Definition: vn_ovsdb.h:51
bool IsLess(const KSyncEntry &) const
Definition: vn_ovsdb.cc:84
void DeleteMsg(struct ovsdb_idl_txn *)
Definition: vn_ovsdb.cc:46
std::string name_
Definition: vn_ovsdb.h:53
VrfEntry * vrf()
Definition: vn_ovsdb.cc:93
bool Sync(DBEntry *)
Definition: vn_ovsdb.cc:61
void AddMsg(struct ovsdb_idl_txn *)
Definition: vn_ovsdb.cc:28
KSyncEntry * UnresolvedReference()
Definition: vn_ovsdb.cc:89
boost::uuids::uuid uuid_
Definition: vn_ovsdb.h:50
virtual ~VnOvsdbObject()
Definition: vn_ovsdb.cc:101
KSyncEntry * Alloc(const KSyncEntry *key, uint32_t index)
Definition: vn_ovsdb.cc:104
VnOvsdbObject(OvsdbClientIdl *idl, DBTable *table)
Definition: vn_ovsdb.cc:97
KSyncEntry * DBToKSyncEntry(const DBEntry *)
Definition: vn_ovsdb.cc:111
DBFilterResp OvsdbDBEntryFilter(const DBEntry *entry, const OvsdbDBEntry *ovsdb_entry)
Definition: vn_ovsdb.cc:117
Definition: vn.h:152
const boost::uuids::uuid & GetUuid() const
Definition: vn.h:162
VrfEntry * GetVrf() const
Definition: vn.h:171
int GetVxLanId() const
Definition: vn.cc:729
const string & GetName() const
Definition: vn.h:163
Definition: vrf.h:90
boost::uuids::uuid uuid