OpenSDN source code
ha_stale_vn.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 
15 #include <ha_stale_vn.h>
16 #include <ha_stale_dev_vn.h>
17 
18 using namespace OVSDB;
19 
21  const boost::uuids::uuid &uuid) : OvsdbDBEntry(table), uuid_(uuid),
22  vn_name_(""), bridge_table_(NULL) {
23 }
24 
26 }
27 
28 void HaStaleVnEntry::AddMsg(struct ovsdb_idl_txn *txn) {
29  HaStaleVnTable *table = static_cast<HaStaleVnTable *>(table_);
30  if (table->dev_vn_table_ != NULL) {
31  // trigger VnReEval for Any Change
32  table->dev_vn_table_->VnReEvalEnqueue(uuid_);
33  }
34 }
35 
36 void HaStaleVnEntry::ChangeMsg(struct ovsdb_idl_txn *txn) {
37  AddMsg(txn);
38 }
39 
40 void HaStaleVnEntry::DeleteMsg(struct ovsdb_idl_txn *txn) {
41  HaStaleVnTable *table = static_cast<HaStaleVnTable *>(table_);
42  if (table->dev_vn_table_ != NULL) {
43  table->dev_vn_table_->VnReEvalEnqueue(uuid_);
44  }
45 }
46 
47 bool HaStaleVnEntry::Sync(DBEntry *db_entry) {
48  VnEntry *vn = static_cast<VnEntry *>(db_entry);
49  bool change = false;
50  if (vn_name_ != vn->GetName()) {
51  vn_name_ = vn->GetName();
52  change = true;
53  }
54  if (bridge_table_ != vn->GetVrf()->GetBridgeRouteTable()) {
56  change = true;
57  }
58  return change;
59 }
60 
61 bool HaStaleVnEntry::IsLess(const KSyncEntry &entry) const {
62  const HaStaleVnEntry &vn_entry = static_cast<const HaStaleVnEntry&>(entry);
63  return uuid_ < vn_entry.uuid_;
64 }
65 
67  return NULL;
68 }
69 
70 const std::string &HaStaleVnEntry::vn_name() const {
71  return vn_name_;
72 }
73 
75  return bridge_table_;
76 }
77 
79  OvsdbDBObject(NULL, false), agent_(agent), dev_vn_table_(dev_vn_table) {
81 }
82 
84 }
85 
86 KSyncEntry *HaStaleVnTable::Alloc(const KSyncEntry *key, uint32_t index) {
87  const HaStaleVnEntry *k_entry =
88  static_cast<const HaStaleVnEntry *>(key);
89  HaStaleVnEntry *entry = new HaStaleVnEntry(this, k_entry->uuid_);
90  return entry;
91 }
92 
94  const VnEntry *entry = static_cast<const VnEntry *>(db_entry);
95  HaStaleVnEntry *key = new HaStaleVnEntry(this, entry->GetUuid());
96  return static_cast<KSyncEntry *>(key);
97 }
98 
100  const DBEntry *entry, const OvsdbDBEntry *ovsdb_entry) {
101  const VnEntry *vn = static_cast<const VnEntry *>(entry);
102  // only accept Virtual Networks with non-NULL vrf
103  // and non zero vxlan id
104  if (vn->GetVrf() == NULL || vn->GetVxLanId() == 0) {
105  return DBFilterDelete;
106  }
107  return DBFilterAccept;
108 }
109 
112  // unregister the object if emptytable is called with
113  // object being scheduled for delete
114  if (delete_scheduled()) {
116  }
117 }
118 
120  return agent_;
121 }
122 
124  dev_vn_table_ = NULL;
125 }
126 
Agent supports multiple route tables - Inet-unicast (IPv4/IPv6), Inet-multicast, bridge,...
Definition: agent_route.h:110
Definition: agent.h:361
VnTable * vn_table() const
Definition: agent.h:498
static void Unregister(KSyncObject *)
bool delete_scheduled()
Definition: ksync_object.h:147
bool IsLess(const KSyncEntry &) const
Definition: ha_stale_vn.cc:61
KSyncEntry * UnresolvedReference()
Definition: ha_stale_vn.cc:66
HaStaleVnEntry(HaStaleVnTable *table, const boost::uuids::uuid &uuid)
Definition: ha_stale_vn.cc:20
virtual ~HaStaleVnEntry()
Definition: ha_stale_vn.cc:25
std::string vn_name_
Definition: ha_stale_vn.h:64
AgentRouteTable * bridge_table_
Definition: ha_stale_vn.h:65
boost::uuids::uuid uuid_
Definition: ha_stale_vn.h:63
bool Sync(DBEntry *)
Definition: ha_stale_vn.cc:47
void AddMsg(struct ovsdb_idl_txn *)
Definition: ha_stale_vn.cc:28
void DeleteMsg(struct ovsdb_idl_txn *)
Definition: ha_stale_vn.cc:40
AgentRouteTable * bridge_table() const
Definition: ha_stale_vn.cc:74
const std::string & vn_name() const
Definition: ha_stale_vn.cc:70
void ChangeMsg(struct ovsdb_idl_txn *)
Definition: ha_stale_vn.cc:36
HaStaleVnTable(Agent *agent, HaStaleDevVnTable *dev_vn_table)
Definition: ha_stale_vn.cc:78
Agent * agent() const
Definition: ha_stale_vn.cc:119
virtual ~HaStaleVnTable()
Definition: ha_stale_vn.cc:83
virtual void EmptyTable(void)
Definition: ha_stale_vn.cc:110
HaStaleDevVnTable * dev_vn_table_
Definition: ha_stale_vn.h:35
DBFilterResp OvsdbDBEntryFilter(const DBEntry *entry, const OvsdbDBEntry *ovsdb_entry)
Definition: ha_stale_vn.cc:99
KSyncEntry * DBToKSyncEntry(const DBEntry *)
Definition: ha_stale_vn.cc:93
friend class HaStaleVnEntry
Definition: ha_stale_vn.h:32
KSyncEntry * Alloc(const KSyncEntry *key, uint32_t index)
Definition: ha_stale_vn.cc:86
OvsdbDBObject * table_
Definition: ovsdb_entry.h:111
OvsdbDBObject * table()
Definition: ovsdb_entry.h:97
virtual void OvsdbRegisterDBTable(DBTable *tbl)
Definition: ovsdb_object.cc:77
virtual void EmptyTable(void)
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
AgentRouteTable * GetBridgeRouteTable() const
Definition: vrf.cc:335
Definition: agent.h:44
boost::uuids::uuid uuid