OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ovsdb_resource_vxlan_id.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include <ovsdb_entry.h>
6 #include <ovsdb_object.h>
8 
9 using namespace OVSDB;
10 
12  KSyncEntry *entry)
13  : table_(table), entry_(entry), resource_id_(0), vxlan_id_(0),
14  active_vxlan_id_(0) {
15 }
16 
18  ReleaseVxLanId(true);
19  ReleaseVxLanId(false);
20 }
21 
22 bool OvsdbResourceVxLanId::AcquireVxLanId(uint32_t vxlan_id) {
23  if (vxlan_id_ == vxlan_id) {
24  return (resource_id_ == 0);
25  }
26 
27  if (vxlan_id_ != 0) {
28  if (resource_id_ != 0 || active_vxlan_id_ != 0) {
29  ReleaseVxLanId(false);
30  } else {
32  }
33  }
34  vxlan_id_ = vxlan_id;
35 
36  if (vxlan_id_ == 0) {
37  return true;
38  }
39 
40  if (vxlan_id_ == active_vxlan_id_) {
41  active_vxlan_id_ = 0;
42  resource_id_ = 0;
43  return true;
44  }
45 
46  return table_->AcquireVxLanId(this, vxlan_id);
47 }
48 
50  if (active) {
51  if (active_vxlan_id_ != 0) {
53  active_vxlan_id_ = 0;
54  }
55  } else {
56  if (vxlan_id_ != 0) {
58  vxlan_id_ = 0;
59  resource_id_ = 0;
60  }
61  }
62 }
63 
65  if (vxlan_id_ == vxlan_id) {
66  assert(resource_id_ == 0);
67  // release previous active vxlan id
68  ReleaseVxLanId(true);
69  return;
70  }
71  if (active_vxlan_id_ == vxlan_id) {
72  // if it is same as active vxlan id return from here
73  return;
74  }
75  assert(vxlan_id == 0);
76  // release previous active vxlan id
77  ReleaseVxLanId(true);
78 }
79 
81  return ((resource_id_ == 0) ? vxlan_id_ : 0);
82 }
83 
85  if (active_vxlan_id_ == 0) {
86  return VxLanId();
87  }
88  return active_vxlan_id_;
89 }
90 
92 }
93 
95 }
96 
98  uint32_t vxlan_id) {
99  std::map<uint32_t, ResourceEntry*>::iterator tbl_it =
100  vxlan_table_.find(vxlan_id);
101  ResourceEntry *res_entry;
102  if (tbl_it != vxlan_table_.end()) {
103  res_entry = tbl_it->second;
104  } else {
105  res_entry = new ResourceEntry();
106  vxlan_table_[vxlan_id] = res_entry;
107  }
108 
109  entry->resource_id_ = res_entry->resource_id_count_;
110  res_entry->resource_id_count_++;
111  if (entry->resource_id_ == 0) {
112  // first entry in the list
113  res_entry->active_entry = entry;
114  return true;
115  } else {
116  res_entry->pending_list.insert(entry);
117  }
118  return false;
119 }
120 
122  uint32_t vxlan_id,
123  uint32_t resource_id) {
124  std::map<uint32_t, ResourceEntry*>::iterator tbl_it =
125  vxlan_table_.find(vxlan_id);
126  assert(tbl_it != vxlan_table_.end());
127  ResourceEntry *res_entry = tbl_it->second;
128 
129  if (resource_id == 0) {
130  assert(res_entry->active_entry == entry);
131  ResourcePendingList::iterator it = res_entry->pending_list.begin();
132  if (it == res_entry->pending_list.end()) {
133  vxlan_table_.erase(tbl_it);
134  delete res_entry;
135  } else {
136  (*it)->resource_id_ = 0;
137  res_entry->active_entry = (*it);
138  KSyncEntry *ovs_entry = (*it)->entry_;
139  // only trigger for active entry
140  if (ovs_entry->IsActive() &&
141  ovs_entry->GetObject() &&
142  (ovs_entry->GetObject()->delete_scheduled() == false)) {
143  ovs_entry->GetObject()->Change(ovs_entry);
144  }
145  res_entry->pending_list.erase(it);
146  if (res_entry->pending_list.empty()) {
147  res_entry->resource_id_count_ = 1;
148  }
149  }
150  } else {
151  OvsdbResourceVxLanId key(NULL, entry->entry_);
152  key.resource_id_ = resource_id;
153  ResourcePendingList::iterator it = res_entry->pending_list.find(&key);
154  assert(it != res_entry->pending_list.end());
155  res_entry->pending_list.erase(it);
156  }
157 }
158 
void Change(KSyncEntry *entry)
bool AcquireVxLanId(OvsdbResourceVxLanId *entry, uint32_t vxlan_id)
OvsdbResourceVxLanIdTable * table_
bool delete_scheduled()
Definition: ksync_object.h:146
bool AcquireVxLanId(uint32_t vxlan_id)
virtual KSyncObject * GetObject() const =0
void set_active_vxlan_id(uint32_t vxlan_id)
bool IsActive()
Definition: ksync_entry.h:172
OvsdbResourceVxLanId(OvsdbResourceVxLanIdTable *table, KSyncEntry *entry)
std::map< uint32_t, ResourceEntry * > vxlan_table_
void ReleaseVxLanId(OvsdbResourceVxLanId *entry, uint32_t vxlan_id, uint32_t resource_id)