OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ovsdb_object.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 extern "C" {
6 #include <ovsdb_wrapper.h>
7 };
8 
9 #include <ovsdb_entry.h>
10 #include <ovsdb_object.h>
11 
12 using OVSDB::OvsdbObject;
15 
16 OvsdbObject::OvsdbObject(OvsdbClientIdl *idl) : KSyncObject("OvsdbDBObject"),
17  client_idl_(idl) {
18 }
19 
21 }
22 
24  KSyncEntry *entry = Find(key);
25  if (entry != NULL && entry->IsActive()) {
26  return entry;
27  }
28  return NULL;
29 }
30 
32  client_idl_->ksync_obj_manager()->Delete(this);
33  // trigger DeleteTableDone for derived class to take action on
34  // delete table callback
36 }
37 
39  if (delete_scheduled()) {
40  client_idl_ = NULL;
41  }
42 }
43 
45  bool init_stale_entry_cleanup) :
46  KSyncDBObject("OvsdbDBObject"),
47  client_idl_(idl), delete_triggered_(false) {
48  if (init_stale_entry_cleanup) {
49  InitStaleEntryCleanup(*(idl->agent()->event_manager())->io_service(),
52  }
53 }
54 
56  bool init_stale_entry_cleanup) :
57  KSyncDBObject("OvsdbDBObject", tbl), client_idl_(idl),
58  delete_triggered_(false) {
59  // Start a walker to get the entries which were already present,
60  // when we register to the DB Table
61  walk_ref_ = tbl->AllocWalker(
62  boost::bind(&OvsdbDBObject::DBWalkNotify, this, _1, _2),
63  boost::bind(&OvsdbDBObject::DBWalkDone, this, _2));
64  tbl->WalkAgain(walk_ref_);
65  if (init_stale_entry_cleanup) {
66  InitStaleEntryCleanup(*(idl->agent()->event_manager())->io_service(),
69  }
70 }
71 
73  assert(walk_ref_ == NULL);
74 }
75 
77  RegisterDb(tbl);
78  // Start a walker to get the entries which were already present,
79  // when we register to the DB Table
80  if (walk_ref_.get() == NULL) {
81  walk_ref_ = tbl->AllocWalker(
82  boost::bind(&OvsdbDBObject::DBWalkNotify, this, _1, _2),
83  boost::bind(&OvsdbDBObject::DBWalkDone, this, _2));
84  }
85  tbl->WalkAgain(walk_ref_);
86 }
87 
89  (static_cast<DBTable*>(GetDBTable()))->WalkAgain(walk_ref_);
90 }
91 
92 void OvsdbDBObject::NotifyAddOvsdb(OvsdbDBEntry *key, struct ovsdb_idl_row *row) {
93  OvsdbDBEntry *entry = static_cast<OvsdbDBEntry *>(Find(key));
94  // Check if entry is present and active. in case if we find an entry
95  // which is inactive, we will need to alloc ovs entry and trigger
96  // delete to update ovsdb-server
97  if (entry && entry->IsActive()) {
98  // trigger notify add for the entry, to update ovs_idl state
99  entry->NotifyAdd(row);
100  } else {
101  OvsdbDBEntry *del_entry = AllocOvsEntry(row);
102  // trigger notify add for the entry, to update ovs_idl state
103  del_entry->NotifyAdd(row);
104  // entry created by AllocOvsEntry should always be stale
105  assert(del_entry->stale());
106  // if delete of table is already triggered delete the created
107  // stale entry immediately
108  if (delete_triggered_) {
109  Delete(del_entry);
110  }
111  }
112 }
113 
115  struct ovsdb_idl_row *row) {
116  OvsdbDBEntry *entry = static_cast<OvsdbDBEntry *>(Find(key));
117  if (entry) {
118  // trigger notify delete for the entry, to reset ovs_idl state
119  entry->NotifyDelete(row);
120  if (!entry->IsDelAckWaiting()) {
121  // we were not waiting for delete to happen, state for
122  // OVSDB server and client mismatch happend.
123  // Trigger Add/Change Req on entry to resync
125  }
126  }
127 }
128 
130  Notify(part, entry);
131  return true;
132 }
133 
135 }
136 
138  return client_idl_->agent();
139 }
140 
142  // validate delete should not be triggered twice for an object
143  assert(!delete_triggered_);
144  delete_triggered_ = true;
145  if (client_idl_ != NULL) {
146  client_idl_->ksync_obj_manager()->Delete(this);
147  } else {
149  }
150  // trigger DeleteTableDone for derived class to take action on
151  // delete table callback
152  DeleteTableDone();
153 }
154 
156  if (delete_scheduled()) {
157  if (walk_ref_.get() != NULL)
158  (static_cast<DBTable*>(GetDBTable()))->ReleaseWalker(walk_ref_);
159  walk_ref_ = NULL;
160  client_idl_ = NULL;
161  }
162 }
163 
165  const DBEntry *entry, const OvsdbDBEntry *ovsdb_entry) {
166  // Accept by default, unless overriden by dereived class
167  return DBFilterAccept;
168 }
169 
171  const DBEntry *entry, const KSyncDBEntry *ksync) {
172  // Ignore Add/Change notifications while client idl is deleted
173  // there can be cases that the current table might be pending
174  // for delete schedule in KSyncObjectManager Queue and in
175  // the mean while we get a notification, where we should not
176  // process it further.
177  if (client_idl_ != NULL && client_idl_->deleted()) {
178  return DBFilterIgnore;
179  }
180 
181  return OvsdbDBEntryFilter(entry, static_cast<const OvsdbDBEntry *>(ksync));
182 }
183 
void InitStaleEntryCleanup(boost::asio::io_context &ios, uint32_t cleanup_time, uint32_t cleanup_intvl, uint16_t entries_per_intvl)
Definition: ksync_object.cc:79
OvsdbDBObject(OvsdbClientIdl *idl, bool init_stale_entry_cleanup)
Definition: ovsdb_object.cc:44
void RegisterDb(DBTableBase *table)
OvsdbClientIdlPtr client_idl_
Definition: ovsdb_object.h:83
virtual void EmptyTable(void)
void Delete(KSyncEntry *entry)
DBTableWalkRef AllocWalker(WalkFn walk_fn, WalkCompleteFn walk_complete)
Definition: db_table.cc:613
virtual void OvsdbRegisterDBTable(DBTable *tbl)
Definition: ovsdb_object.cc:76
Agent * agent() const
virtual OvsdbDBEntry * AllocOvsEntry(struct ovsdb_idl_row *row)
Definition: ovsdb_object.h:63
virtual void DeleteTableDone(void)
Definition: ovsdb_object.h:81
bool delete_scheduled()
Definition: ksync_object.h:146
KSyncEntry * FindActiveEntry(KSyncEntry *key)
Definition: ovsdb_object.cc:23
DBTable::DBTableWalkRef walk_ref_
Definition: ovsdb_object.h:87
void WalkAgain(DBTableWalkRef walk)
Definition: db_table.cc:631
DBFilterResp DBEntryFilter(const DBEntry *entry, const KSyncDBEntry *ksync)
static const uint16_t StaleEntryDeletePerIteration
Definition: ovsdb_object.h:47
void DBWalkDone(DBTableBase *partition)
virtual DBFilterResp OvsdbDBEntryFilter(const DBEntry *entry, const OvsdbDBEntry *ovsdb_entry)
Definition: agent.h:358
void SafeNotifyEvent(KSyncEntry *entry, KSyncEntry::KSyncEvent event)
DBTableBase * GetDBTable()
Definition: ksync_object.h:244
EventManager * event_manager() const
Definition: agent.h:1103
void NotifyDeleteOvsdb(OvsdbDBEntry *key, struct ovsdb_idl_row *row)
bool DBWalkNotify(DBTablePartBase *partition, DBEntryBase *entry)
bool stale() const
Definition: ksync_entry.h:161
void Notify(DBTablePartBase *partition, DBEntryBase *entry)
void DeleteTable(void)
Definition: ovsdb_object.cc:31
virtual void DeleteTableDone(void)
Definition: ovsdb_object.h:37
KSyncEntry * Find(const KSyncEntry *key)
Definition: ksync_object.cc:99
bool IsActive()
Definition: ksync_entry.h:172
virtual Agent * agent() const
virtual void NotifyDelete(struct ovsdb_idl_row *)
Definition: ovsdb_entry.cc:190
virtual void NotifyAdd(struct ovsdb_idl_row *)
Definition: ovsdb_entry.cc:179
virtual ~OvsdbDBObject()
Definition: ovsdb_object.cc:72
void Delete(KSyncObject *)
virtual void EmptyTable(void)
Definition: ovsdb_object.cc:38
virtual ~OvsdbObject()
Definition: ovsdb_object.cc:20
static const uint32_t StaleEntryYeildTimer
Definition: ovsdb_object.h:46
OvsdbClientIdlPtr client_idl_
Definition: ovsdb_object.h:34
static KSyncObjectManager * GetInstance()
static const uint32_t StaleEntryCleanupTimer
Definition: ovsdb_object.h:45
void NotifyAddOvsdb(OvsdbDBEntry *key, struct ovsdb_idl_row *row)
Definition: ovsdb_object.cc:92