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