-
Notifications
You must be signed in to change notification settings - Fork 390
/
ovsdb_object.cc
161 lines (138 loc) · 5.32 KB
/
ovsdb_object.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
*/
extern "C" {
#include <ovsdb_wrapper.h>
};
#include <ovsdb_entry.h>
#include <ovsdb_object.h>
using OVSDB::OvsdbObject;
using OVSDB::OvsdbDBObject;
using OVSDB::OvsdbDBEntry;
OvsdbObject::OvsdbObject(OvsdbClientIdl *idl) : KSyncObject(),
client_idl_(idl) {
}
OvsdbObject::~OvsdbObject() {
}
bool OvsdbObject::IsActiveEntry(KSyncEntry *entry) {
return (entry->GetState() != KSyncEntry::TEMP && !entry->IsDeleted());
}
KSyncEntry *OvsdbObject::FindActiveEntry(KSyncEntry *key) {
KSyncEntry *entry = Find(key);
if (entry != NULL && IsActiveEntry(entry)) {
return entry;
}
return NULL;
}
void OvsdbObject::DeleteTable(void) {
client_idl_->ksync_obj_manager()->Delete(this);
}
void OvsdbObject::EmptyTable(void) {
if (delete_scheduled()) {
client_idl_ = NULL;
}
}
OvsdbDBObject::OvsdbDBObject(OvsdbClientIdl *idl,
bool init_stale_entry_cleanup) : KSyncDBObject(),
client_idl_(idl), walkid_(DBTableWalker::kInvalidWalkerId) {
if (init_stale_entry_cleanup) {
InitStaleEntryCleanup(*(idl->agent()->event_manager())->io_service(),
StaleEntryCleanupTimer, StaleEntryYeildTimer,
StaleEntryDeletePerIteration);
}
}
OvsdbDBObject::OvsdbDBObject(OvsdbClientIdl *idl, DBTable *tbl,
bool init_stale_entry_cleanup) :
KSyncDBObject(tbl), client_idl_(idl),
walkid_(DBTableWalker::kInvalidWalkerId) {
DBTableWalker *walker = client_idl_->agent()->db()->GetWalker();
// Start a walker to get the entries which were already present,
// when we register to the DB Table
walkid_ = walker->WalkTable(tbl, NULL,
boost::bind(&OvsdbDBObject::DBWalkNotify, this, _1, _2),
boost::bind(&OvsdbDBObject::DBWalkDone, this, _1));
if (init_stale_entry_cleanup) {
InitStaleEntryCleanup(*(idl->agent()->event_manager())->io_service(),
StaleEntryCleanupTimer, StaleEntryYeildTimer,
StaleEntryDeletePerIteration);
}
}
OvsdbDBObject::~OvsdbDBObject() {
assert(walkid_ == DBTableWalker::kInvalidWalkerId);
}
void OvsdbDBObject::OvsdbRegisterDBTable(DBTable *tbl) {
assert(client_idl_.get() != NULL);
RegisterDb(tbl);
DBTableWalker *walker = client_idl_->agent()->db()->GetWalker();
// Start a walker to get the entries which were already present,
// when we register to the DB Table
walkid_ = walker->WalkTable(tbl, NULL,
boost::bind(&OvsdbDBObject::DBWalkNotify, this, _1, _2),
boost::bind(&OvsdbDBObject::DBWalkDone, this, _1));
}
void OvsdbDBObject::NotifyAddOvsdb(OvsdbDBEntry *key, struct ovsdb_idl_row *row) {
OvsdbDBEntry *entry = static_cast<OvsdbDBEntry *>(Find(key));
// Check if entry is present and active. in case if we find an entry
// which is inactive, we will need to alloc ovs entry and trigger
// delete to update ovsdb-server
if (entry && entry->IsActive()) {
// trigger notify add for the entry, to update ovs_idl state
entry->NotifyAdd(row);
} else {
OvsdbDBEntry *del_entry = AllocOvsEntry(row);
// trigger notify add for the entry, to update ovs_idl state
del_entry->NotifyAdd(row);
// entry created by AllocOvsEntry should always be stale
assert(del_entry->stale());
}
}
void OvsdbDBObject::NotifyDeleteOvsdb(OvsdbDBEntry *key,
struct ovsdb_idl_row *row) {
OvsdbDBEntry *entry = static_cast<OvsdbDBEntry *>(Find(key));
if (entry) {
// trigger notify delete for the entry, to reset ovs_idl state
entry->NotifyDelete(row);
if (!entry->IsDelAckWaiting()) {
// we were not waiting for delete to happen, state for
// OVSDB server and client mismatch happend.
// Trigger Add/Change Req on entry to resync
NotifyEvent(entry, KSyncEntry::ADD_CHANGE_REQ);
}
}
}
bool OvsdbDBObject::DBWalkNotify(DBTablePartBase *part, DBEntryBase *entry) {
Notify(part, entry);
return true;
}
void OvsdbDBObject::DBWalkDone(DBTableBase *partition) {
walkid_ = DBTableWalker::kInvalidWalkerId;
}
void OvsdbDBObject::DeleteTable(void) {
client_idl_->ksync_obj_manager()->Delete(this);
}
void OvsdbDBObject::EmptyTable(void) {
if (delete_scheduled()) {
if (walkid_ != DBTableWalker::kInvalidWalkerId) {
DBTableWalker *walker = client_idl_->agent()->db()->GetWalker();
walker->WalkCancel(walkid_);
walkid_ = DBTableWalker::kInvalidWalkerId;
}
client_idl_ = NULL;
}
}
KSyncDBObject::DBFilterResp OvsdbDBObject::OvsdbDBEntryFilter(
const DBEntry *entry) {
// Accept by default, unless overriden by dereived class
return DBFilterAccept;
}
KSyncDBObject::DBFilterResp OvsdbDBObject::DBEntryFilter(const DBEntry *entry) {
// Ignore Add/Change notifications while client idl is deleted
// there can be cases that the current table might be pending
// for delete schedule in KSyncObjectManager Queue and in
// the mean while we get a notification, where we should not
// process it further.
if (client_idl_->deleted()) {
return DBFilterIgnore;
}
return OvsdbDBEntryFilter(entry);
}