OpenSDN source code
logical_switch_ovsdb.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 extern "C" {
7 #include <ovsdb_wrapper.h>
8 };
10 #include <ovsdb_client.h>
11 #include <ovsdb_client_idl.h>
12 #include <ovsdb_client_session.h>
13 #include <physical_switch_ovsdb.h>
14 #include <logical_switch_ovsdb.h>
15 #include <physical_locator_ovsdb.h>
18 
19 #include <oper/vn.h>
20 #include <oper/vrf.h>
22 #include <ovsdb_sandesh.h>
23 #include <ovsdb_types.h>
24 
25 using namespace OVSDB;
26 
27 namespace OVSDB {
28 
30  p->back_ref_set_.insert(ref);
31 }
32 
34  p->back_ref_set_.erase(ref);
35 }
36 };
37 
39  const std::string &name) :
40  OvsdbDBEntry(table), name_(name), device_name_(), vxlan_id_(0),
41  mcast_local_row_list_(), mcast_remote_row_(NULL), delete_ovs_(false),
42  res_vxlan_id_(table->client_idl()->vxlan_table(), this), del_task_(NULL) {
43 }
44 
46  const PhysicalDeviceVn *entry) : OvsdbDBEntry(table),
47  name_(UuidToString(entry->vn()->GetUuid())), mcast_local_row_list_(),
48  mcast_remote_row_(NULL), delete_ovs_(false),
49  res_vxlan_id_(table->client_idl()->vxlan_table(), this), del_task_(NULL) {
50  vxlan_id_ = entry->vxlan_id();
52 }
53 
55  const LogicalSwitchEntry *entry) : OvsdbDBEntry(table),
56  mcast_local_row_list_(), mcast_remote_row_(NULL), delete_ovs_(false),
57  res_vxlan_id_(table->client_idl()->vxlan_table(), this), del_task_(NULL) {
58  name_ = entry->name_;
59  vxlan_id_ = entry->vxlan_id_;;
60  device_name_ = entry->device_name_;
61 }
62 
64  struct ovsdb_idl_row *entry) : OvsdbDBEntry(table, entry),
65  name_(ovsdb_wrapper_logical_switch_name(entry)), device_name_(""),
67  mcast_remote_row_(NULL), delete_ovs_(false),
68  res_vxlan_id_(table->client_idl()->vxlan_table(), this), del_task_(NULL) {
69 }
70 
72  assert(pl_create_ref_.get() == NULL);
73 }
74 
76  PhysicalSwitchEntry *p_switch =
77  static_cast<PhysicalSwitchEntry *>(physical_switch_.get());
78  return p_switch->tunnel_ip();
79 }
80 
81 void LogicalSwitchEntry::AddMsg(struct ovsdb_idl_txn *txn) {
83  PhysicalSwitchEntry key(p_table, device_name_.c_str());
84  physical_switch_ = p_table->GetReference(&key);
85 
86  if (stale()) {
87  // skip add encoding for stale entry
88  return;
89  }
90 
91  struct ovsdb_idl_row *row =
94 
95  // Encode Delete for Old remote multicast entries
97 
98  // Add remote multicast entry if not already present
99  // and if old mcast remote MAC list is empty
100  if (old_mcast_remote_row_list_.empty() && mcast_remote_row_ == NULL) {
101  std::string dest_ip = table_->client_idl()->tsn_ip().to_string();
102  PhysicalLocatorTable *pl_table =
104  PhysicalLocatorEntry pl_key(pl_table, dest_ip);
105  /*
106  * we don't take reference to physical locator, just use if locator
107  * is existing or we will create a new one.
108  */
109  PhysicalLocatorEntry *pl_entry =
110  static_cast<PhysicalLocatorEntry *>(pl_table->Find(&pl_key));
111  struct ovsdb_idl_row *pl_row = NULL;
112  if (pl_entry)
113  pl_row = pl_entry->ovs_entry();
114  ovsdb_wrapper_add_mcast_mac_remote(txn, NULL, "unknown-dst", row,
115  pl_row, dest_ip.c_str());
116  }
117 
119 }
120 
121 void LogicalSwitchEntry::ChangeMsg(struct ovsdb_idl_txn *txn) {
122  AddMsg(txn);
123 }
124 
125 void LogicalSwitchEntry::DeleteMsg(struct ovsdb_idl_txn *txn) {
126  physical_switch_ = NULL;
127 
128  // encode delete of entry if it is non-NULL
129  if (mcast_remote_row_ != NULL) {
131  }
133 
134  if (ovs_entry_ != NULL) {
136  }
137 
138  OvsdbIdlRowList::iterator it;
139  for (it = mcast_local_row_list_.begin();
140  it != mcast_local_row_list_.end(); ++it) {
142  }
143  for (it = ucast_local_row_list_.begin();
144  it != ucast_local_row_list_.end(); ++it) {
146  }
147 
149 }
150 
152  if (!IsResolved())
154 }
155 
156 const std::string &LogicalSwitchEntry::name() const {
157  return name_;
158 }
159 
160 const std::string &LogicalSwitchEntry::device_name() const {
161  return device_name_;
162 }
163 
165  return vxlan_id_;
166 }
167 
170 }
171 
173  return res_vxlan_id_;
174 }
175 
177  return delete_ovs_;
178 }
179 
181  PhysicalDeviceVn *entry =
182  static_cast<PhysicalDeviceVn *>(db_entry);
183  bool change = false;
184  if (vxlan_id_ != entry->vxlan_id()) {
185  vxlan_id_ = entry->vxlan_id();
186  change = true;
187  }
188  if (device_name_ != entry->device_display_name()) {
190  change = true;
191  }
192  return change;
193 }
194 
195 bool LogicalSwitchEntry::IsLess(const KSyncEntry &entry) const {
196  const LogicalSwitchEntry &ps_entry =
197  static_cast<const LogicalSwitchEntry&>(entry);
198  return (name_.compare(ps_entry.name_) < 0);
199 }
200 
202  assert(pl_create_ref_.get() == NULL);
203 
204  if (stale()) {
205  // while creating stale entry we should not wait for physical
206  // switch object since it will not be available till config
207  // comes up
208 
209  // for stale entry we should always be able to acquire vxlan id
210  // However in certain cases, where OVSDB database is already
211  // in a state where two Logical switch entries exists with
212  // same VxLAN ID, we need to recover by deleting the entry
213  // from OVSDB database
214  bool ret = res_vxlan_id_.AcquireVxLanId((uint32_t)vxlan_id_);
215  if (!ret) {
217  }
218 
219  return NULL;
220  }
221 
223  PhysicalSwitchEntry key(p_table, device_name_.c_str());
224  PhysicalSwitchEntry *p_switch =
225  static_cast<PhysicalSwitchEntry *>(p_table->GetReference(&key));
226  if (!p_switch->IsResolved()) {
227  return p_switch;
228  }
229 
230  bool ret = res_vxlan_id_.AcquireVxLanId((uint32_t)vxlan_id_);
231  if (!ret) {
232  // failed to get vxlan-id hold entry in defer state
233  // and delete ovs
234  DeleteOvs(true);
236  }
237 
238  // cancel running delete process
239  CancelDeleteOvs();
240 
241  // check if physical locator is available
242  std::string dest_ip = table_->client_idl()->tsn_ip().to_string();
243  PhysicalLocatorTable *pl_table =
245  PhysicalLocatorEntry pl_key(pl_table, dest_ip);
246  PhysicalLocatorEntry *pl_entry =
247  static_cast<PhysicalLocatorEntry *>(pl_table->GetReference(&pl_key));
248  if (!pl_entry->IsResolved()) {
249  if (!pl_entry->AcquireCreateRequest(this)) {
250  // failed to Acquire Create Request, wait for physical locator
251  return pl_entry;
252  }
253  pl_create_ref_ = pl_entry;
254  }
255 
256  return NULL;
257 }
258 
260  return (local_mac_ref_.get() != NULL);
261 }
262 
263 void LogicalSwitchEntry::Ack(bool success) {
264  if (success) {
265  if (ovs_entry_ != NULL) {
266  uint32_t active_vxlan_id =
268  res_vxlan_id_.set_active_vxlan_id(active_vxlan_id);
269  } else {
271  // trigger delete ovs completed/cancel
272  CancelDeleteOvs();
273  }
274  } else {
275  if (delete_ovs_) {
276  // trigger delete ovs completed/cancel
277  CancelDeleteOvs();
278  // try delete OVS again
279  DeleteOvs(false);
280  }
281  }
283  OvsdbDBEntry::Ack(success);
284 }
285 
287  if (ovs_entry_ != NULL) {
288  uint32_t active_vxlan_id =
290  res_vxlan_id_.set_active_vxlan_id(active_vxlan_id);
291  } else {
293  // trigger delete ovs completed/cancel
294  CancelDeleteOvs();
295  }
297 }
298 
299 void LogicalSwitchEntry::DeleteOvs(bool add_change_in_progress) {
300  if (ovs_entry_ == NULL || delete_ovs_ == true) {
301  return;
302  }
303 
304  delete_ovs_ = true;
305  assert(del_task_ == NULL);
306  // should not be triggered on stale entry
307  assert(!stale());
308 
309  // skip assert if this API is called inline from an Add/Change
310  // processing, where the state may say not active while this API
311  // is called and will result in false failures
312  if (!add_change_in_progress) {
313  // this API internally triggers DELADD_REQ on KSync entry
314  // which will activate the entry, if it needs to handle this
315  // operation for an inactive entry, it also needs to ensure
316  // that eventually an ADD should not be triggered
317  assert(IsActive());
318  }
319 
321  TaskScheduler *scheduler = table_->client_idl()->agent()->task_scheduler();
322  scheduler->Enqueue(del_task_);
323 }
324 
326  LogicalSwitchEntry *entry) :
327  Task((entry->table()->client_idl()->agent()->task_scheduler()\
328  ->GetTaskId("Agent::KSync")), 0), entry_(entry) {
329 }
330 
332 }
333 
335  LogicalSwitchEntry *entry = static_cast<LogicalSwitchEntry*>(entry_.get());
336 
337  // start from the entry where the last iteration stopped
338  // entries are removed from this tree in PostDelete which
339  // is triggered only on Delete Acks, using begin_ref_ helps
340  // skip already delete-add processed entries.
341  IntrusiveReferrer reffer(begin_ref_.get(), NULL);
342  std::set<IntrusiveReferrer>::const_iterator it =
343  entry->back_ref_set_.lower_bound(reffer);
344  OvsdbDBEntry *ref_entry = NULL;
345 
346  for (int i = 0; i < kEntriesPerIteration; i++) {
347  if (it == entry->back_ref_set_.end()) {
348  break;
349  }
350  ref_entry = static_cast<OvsdbDBEntry*>((*it).first);
351  it++;
352  ref_entry->TriggerDeleteAdd();
353  }
354 
355  if (it != entry->back_ref_set_.end()) {
356  // keep reference to the entry to be processes next
357  begin_ref_ = static_cast<OvsdbDBEntry*>((*it).first);
358  } else {
359  // finished with the complete set reset begin_ref_ as NULL
360  begin_ref_ = NULL;
361  }
362 
363  if (!entry->back_ref_set_.empty()) {
364  return false;
365  }
366 
367  entry->del_task_ = NULL;
368 
369  if (entry->ovs_entry() != NULL && !entry->IsLocalMacsRef()) {
370  entry->TriggerDeleteAdd();
371  }
372 
373  // on task completion reset intrusive pointer in context of task itself
374  // rather than processing it in the Task destructor, since in case of
375  // task completion task destructor will be called in context of scheduler
376  entry_ = NULL;
377  return true;
378 }
379 
381  delete_ovs_ = false;
382  if (del_task_ != NULL) {
383  TaskScheduler *scheduler = table_->client_idl()->agent()->task_scheduler();
384  assert(scheduler->Cancel(del_task_) == TaskScheduler::CANCELLED);
385  del_task_ = NULL;
386  }
387 }
388 
390  SandeshLogicalSwitchInfo info;
391  switch (event) {
392  case ADD_REQ:
393  info.set_op("Add Requested");
394  break;
395  case DEL_REQ:
396  info.set_op("Delete Requested");
397  break;
398  case ADD_ACK:
399  info.set_op("Add Received");
400  break;
401  case DEL_ACK:
402  info.set_op("Delete Received");
403  break;
404  case DUP_TUNNEL_KEY_ADD:
405  info.set_op("Add Request with Duplicate tunnel key");
406  break;
407  default:
408  info.set_op("unknown");
409  }
410  info.set_name(name_);
411  info.set_device_name(device_name_);
412  info.set_vxlan(vxlan_id_);
413  OVSDB_TRACE(LogicalSwitch, info);
414 }
415 
417  OvsdbIdlRowList::iterator it;
418  for (it = old_mcast_remote_row_list_.begin();
419  it != old_mcast_remote_row_list_.end(); ++it) {
421  }
422 }
423 
425  // on Ack Release the physical locator create ref, if present
426  if (pl_create_ref_.get() != NULL) {
427  // release creator reference on txn complete
428  PhysicalLocatorEntry *pl_entry =
429  static_cast<PhysicalLocatorEntry *>(pl_create_ref_.get());
430  pl_entry->ReleaseCreateRequest(this);
431  pl_create_ref_ = NULL;
432  }
433 }
434 
435 void LogicalSwitchEntry::NotifyDelete(struct ovsdb_idl_row *row) {
436  OvsdbIdlRowList::iterator it;
437  //Since logical-switch delete is received from ovsdb node,
438  //aggresively delete the local macs.
439  for (it = mcast_local_row_list_.begin();
440  it != mcast_local_row_list_.end(); ++it) {
442  Notify(OvsdbClientIdl::OVSDB_DEL, (*it));
444  }
445  for (it = ucast_local_row_list_.begin();
446  it != ucast_local_row_list_.end(); ++it) {
448  Notify(OvsdbClientIdl::OVSDB_DEL, (*it));
450  }
451 
453  return;
454 }
455 
456 // No config seen for this logical switch, so do the cleanup so that delete can
457 // proceed.
459  //Release self reference.
460  local_mac_ref_ = NULL;
461 }
462 
464  OvsdbDBObject(idl, true) {
466  boost::bind(&LogicalSwitchTable::OvsdbNotify, this, _1, _2));
469  this, _1, _2));
470 }
471 
473 }
474 
476  struct ovsdb_idl_row *row) {
477  LogicalSwitchEntry key(this, row);
478  if (op == OvsdbClientIdl::OVSDB_DEL) {
479  NotifyDeleteOvsdb((OvsdbDBEntry*)&key, row);
480  key.SendTrace(LogicalSwitchEntry::DEL_ACK);
481  } else if (op == OvsdbClientIdl::OVSDB_ADD) {
482  NotifyAddOvsdb((OvsdbDBEntry*)&key, row);
483  key.SendTrace(LogicalSwitchEntry::ADD_ACK);
484  } else {
485  assert(0);
486  }
487 }
488 
490  struct ovsdb_idl_row *row) {
491  const char *mac = ovsdb_wrapper_mcast_mac_local_mac(row);
492  const char *ls = ovsdb_wrapper_mcast_mac_local_logical_switch(row);
493  LogicalSwitchEntry *entry = NULL;
494  if (ls) {
495  LogicalSwitchEntry key(this, ls);
496  entry = static_cast<LogicalSwitchEntry *>(Find(&key));
497  }
498  struct ovsdb_idl_row *l_set =
500  // physical locator set is immutable, multicast row with NULL
501  // physical locator is not valid, and it may not observe further
502  // delete trigger, so trigger delete for row and wait for
503  // locator set to be available
504  if (op == OvsdbClientIdl::OVSDB_DEL || l_set == NULL) {
505  // trigger deletion based on the entry for which add was triggered
506  OvsdbIdlRowMap::iterator idl_it = idl_row_map_.find(row);
507  if (idl_it != idl_row_map_.end()) {
508  entry = idl_it->second;
509  idl_row_map_.erase(idl_it);
510  }
511 
512  OVSDB_TRACE(Trace, "Delete : Local Mcast MAC " + std::string(mac) +
513  ", logical switch " + (entry != NULL ? entry->name() : ""));
514  if (entry) {
515  entry->mcast_local_row_list_.erase(row);
516  }
517  } else if (op == OvsdbClientIdl::OVSDB_ADD) {
518  OVSDB_TRACE(Trace, "Add : Local Mcast MAC " + std::string(mac) +
519  ", logical switch " + (ls ? std::string(ls) : ""));
520  if (entry) {
521  idl_row_map_[row] = entry;
522  entry->mcast_local_row_list_.insert(row);
523  }
524  } else {
525  assert(0);
526  }
527 
528  if (entry) {
529  if (!entry->mcast_local_row_list_.empty() ||
530  !entry->ucast_local_row_list_.empty()) {
531  if (entry->IsActive())
532  entry->local_mac_ref_ = entry;
533  } else {
534  entry->local_mac_ref_ = NULL;
535  if (entry->delete_ovs_ && entry->ovs_entry() != NULL) {
536  entry->TriggerDeleteAdd();
537  }
538  }
539  }
540 }
541 
543  struct ovsdb_idl_row *row) {
544  const char *mac = ovsdb_wrapper_mcast_mac_remote_mac(row);
545  const char *ls = ovsdb_wrapper_mcast_mac_remote_logical_switch(row);
546  LogicalSwitchEntry *entry = NULL;
547  if (ls) {
548  LogicalSwitchEntry key(this, ls);
549  entry = static_cast<LogicalSwitchEntry *>(Find(&key));
550  }
551  if (op == OvsdbClientIdl::OVSDB_DEL) {
552  // trigger deletion based on the entry for which add was triggered
553  OvsdbIdlRowMap::iterator idl_it = idl_row_map_.find(row);
554  if (idl_it != idl_row_map_.end()) {
555  entry = idl_it->second;
556  idl_row_map_.erase(idl_it);
557  }
558 
559  OVSDB_TRACE(Trace, "Delete : Remote Mcast MAC " + std::string(mac) +
560  ", logical switch " + (entry != NULL ? entry->name() : ""));
561  if (entry) {
562  entry->old_mcast_remote_row_list_.erase(row);
563  if (entry->mcast_remote_row_ == row) {
564  entry->mcast_remote_row_ = NULL;
565  }
566 
567  // trigger change for active entry, once we are done deleting
568  // all old mcast remote rows
569  if (entry->IsActive() && entry->old_mcast_remote_row_list_.empty())
570  Change(entry);
571  }
572  } else if (op == OvsdbClientIdl::OVSDB_ADD) {
573  OVSDB_TRACE(Trace, "Add : Remote Mcast MAC " + std::string(mac) +
574  ", logical switch " + (ls ? std::string(ls) : ""));
575  if (entry) {
576  idl_row_map_[row] = entry;
577  if (entry->mcast_remote_row_ != row) {
578  if (entry->mcast_remote_row_) {
579  // if we already had an entry move old and current
580  // entry to old remote mac list to trigger delete
581  // for both the mcast remote mac entries.
582  // once both are deleted, we will trigger add
583  // for new entry
584  entry->old_mcast_remote_row_list_.insert(
585  entry->mcast_remote_row_);
586  entry->mcast_remote_row_ = NULL;
587  entry->old_mcast_remote_row_list_.insert(row);
588  } else {
589  entry->mcast_remote_row_ = row;
590  }
591  }
592 
593  std::string dest_ip = ovsdb_wrapper_mcast_mac_remote_dst_ip(row);
594  std::string tsn_ip = client_idl()->tsn_ip().to_string();
595  if (dest_ip.compare(tsn_ip) != 0) {
596  // dest ip is different from tsn ip
597  // move this row to old mcast list, to delete curreny
598  // entry and reprogram new entry with correct TSN IP
599  entry->old_mcast_remote_row_list_.insert(row);
600  entry->mcast_remote_row_ = NULL;
601  }
602 
603  // trigger change on active entry to delete all old
604  // mcast remote rows.
605  if (entry->IsActive() && !entry->old_mcast_remote_row_list_.empty())
606  Change(entry);
607  }
608  } else {
609  assert(0);
610  }
611 }
612 
614  struct ovsdb_idl_row *row) {
615  const char *mac = ovsdb_wrapper_ucast_mac_local_mac(row);
616  const char *ls = ovsdb_wrapper_ucast_mac_local_logical_switch(row);
617  LogicalSwitchEntry *entry = NULL;
618  if (ls) {
619  LogicalSwitchEntry key(this, ls);
620  entry = static_cast<LogicalSwitchEntry *>(Find(&key));
621  }
622  if (op == OvsdbClientIdl::OVSDB_DEL) {
623  // trigger deletion based on the entry for which add was triggered
624  OvsdbIdlRowMap::iterator idl_it = idl_row_map_.find(row);
625  if (idl_it != idl_row_map_.end()) {
626  entry = idl_it->second;
627  idl_row_map_.erase(idl_it);
628  }
629 
630  OVSDB_TRACE(Trace, "Delete : Local Ucast MAC " + std::string(mac) +
631  ", logical switch " + (entry != NULL ? entry->name() : ""));
632  if (entry) {
633  entry->ucast_local_row_list_.erase(row);
634  }
635  } else if (op == OvsdbClientIdl::OVSDB_ADD) {
636  OVSDB_TRACE(Trace, "Add : Local Ucast MAC " + std::string(mac) +
637  ", logical switch " + (ls ? std::string(ls) : ""));
638  if (entry) {
639  idl_row_map_[row] = entry;
640  entry->ucast_local_row_list_.insert(row);
641  }
642  } else {
643  assert(0);
644  }
645 
646  if (entry) {
647  if (!entry->mcast_local_row_list_.empty() ||
648  !entry->ucast_local_row_list_.empty()) {
649  if (entry->IsActive())
650  entry->local_mac_ref_ = entry;
651  } else {
652  entry->local_mac_ref_ = NULL;
653  if (entry->delete_ovs_ && entry->ovs_entry() != NULL) {
654  entry->TriggerDeleteAdd();
655  }
656  }
657  }
658 }
659 
660 KSyncEntry *LogicalSwitchTable::Alloc(const KSyncEntry *key, uint32_t index) {
661  const LogicalSwitchEntry *k_entry =
662  static_cast<const LogicalSwitchEntry *>(key);
663  LogicalSwitchEntry *entry = new LogicalSwitchEntry(this, k_entry);
664  return entry;
665 }
666 
668  const PhysicalDeviceVn *entry =
669  static_cast<const PhysicalDeviceVn *>(db_entry);
670  LogicalSwitchEntry *key = new LogicalSwitchEntry(this, entry);
671  return static_cast<KSyncEntry *>(key);
672 }
673 
674 OvsdbDBEntry *LogicalSwitchTable::AllocOvsEntry(struct ovsdb_idl_row *row) {
675  LogicalSwitchEntry key(this, row);
676  return static_cast<OvsdbDBEntry *>(CreateStale(&key));
677 }
678 
680  const DBEntry *db_entry, const OvsdbDBEntry *ovsdb_entry) {
681  const PhysicalDeviceVn *entry =
682  static_cast<const PhysicalDeviceVn *>(db_entry);
683 
684  // Delete the entry which has invalid VxLAN id associated.
685  if (entry->vxlan_id() == 0) {
686  return DBFilterDelete;
687  }
688  return DBFilterAccept;
689 }
690 
693  new ProcessDeleteTableReqTask(this);
694  TaskScheduler *scheduler = client_idl()->agent()->task_scheduler();
695  scheduler->Enqueue(task);
696 }
697 
699  LogicalSwitchTable *table) :
700  Task((table->client_idl()->agent()->task_scheduler()\
701  ->GetTaskId("Agent::KSync")), 0), table_(table), entry_(NULL) {
702 }
703 
705 }
706 
708  KSyncEntry *kentry = entry_.get();
709  if (kentry == NULL) {
710  kentry = table_->Next(kentry);
711  }
712 
713  int count = 0;
714  while (kentry != NULL) {
715  LogicalSwitchEntry *entry = static_cast<LogicalSwitchEntry *>(kentry);
716  count++;
717  kentry = table_->Next(kentry);
718  // while table is set for deletion reset the local_mac_ref
719  // since there will be no trigger from OVSDB database
720  entry->local_mac_ref_ = NULL;
721 
722  // check for yield
723  if (count == kEntriesPerIteration && kentry != NULL) {
724  entry_ = kentry;
725  return false;
726  }
727  }
728 
729  entry_ = NULL;
730  // Done processing delete request, schedule delete table
731  table_->DeleteTable();
732  return true;
733 }
734 
736 // Sandesh routines
739  std::string resp_ctx, AgentSandeshArguments &args) :
740  OvsdbSandeshTask(resp_ctx, args), name_("") {
741  if (false == args.Get("name", &name_)) {
742  name_ = "";
743  }
744  int vxlan_id = 0;
745  if (false == args.Get("vxlan_id", &vxlan_id)) {
746  vxlan_id = 0;
747  }
748  vxlan_id_ = vxlan_id;
749 }
750 
752  const std::string &ip,
753  uint32_t port,
754  const std::string &name,
755  uint32_t vxlan_id) :
756  OvsdbSandeshTask(resp_ctx, ip, port), name_(name), vxlan_id_(vxlan_id) {
757 }
758 
760 }
761 
763  if (!name_.empty()) {
764  args.Add("name", name_);
765  }
766  if (vxlan_id_ != 0) {
767  args.Add("vxlan_id", vxlan_id_);
768  }
769 }
770 
773  if (!name_.empty()) {
774  LogicalSwitchEntry *entry = static_cast<LogicalSwitchEntry *>(kentry);
775  if (entry->name().find(name_) == std::string::npos) {
776  return FilterDeny;
777  }
778  }
779  if (vxlan_id_ != 0) {
780  LogicalSwitchEntry *entry = static_cast<LogicalSwitchEntry *>(kentry);
781  const OvsdbResourceVxLanId &res = entry->res_vxlan_id();
782  if (entry->vxlan_id() != vxlan_id_ &&
783  res.active_vxlan_id() != vxlan_id_) {
784  return FilterDeny;
785  }
786  }
787  return FilterAllow;
788 }
789 
791  SandeshResponse *resp) {
792  LogicalSwitchEntry *entry = static_cast<LogicalSwitchEntry *>(kentry);
793  OvsdbLogicalSwitchEntry lentry;
794  lentry.set_state(entry->StateString());
795  lentry.set_name(entry->name());
796  lentry.set_physical_switch(entry->device_name());
797  lentry.set_vxlan_id(entry->vxlan_id());
798  lentry.set_tor_service_node(entry->tor_service_node());
799  const OvsdbResourceVxLanId &res = entry->res_vxlan_id();
800  lentry.set_vxlan_id_available(res.VxLanId() != 0);
801  lentry.set_ovs_vxlan_id(res.active_vxlan_id());
802  lentry.set_delete_in_progress(entry->IsDeleteOvsInProgress());
803 
804  //Debugs to find out what keeps logical switch pending.
805  lentry.set_mcast_local_size(entry->mcast_local_row_list_size());
806  lentry.set_ucast_local_size(entry->ucast_local_row_list_size());
807  lentry.set_old_mcast_remote_size(entry->old_mcast_remote_row_list_size());
808  lentry.set_mcast_remote_set(entry->is_mcast_remote_set());
809  lentry.set_local_mac_ref_set(entry->is_local_mac_ref_set());
810 
811  if ((entry->IsDeleted() || entry->IsDeleteOvsInProgress()) &&
812  entry->IsLocalMacsRef()) {
813  lentry.set_message("Waiting for Local Macs Cleanup");
814  }
815  OvsdbLogicalSwitchResp *ls_resp =
816  static_cast<OvsdbLogicalSwitchResp *>(resp);
817  std::vector<OvsdbLogicalSwitchEntry> &lswitch =
818  const_cast<std::vector<OvsdbLogicalSwitchEntry>&>(
819  ls_resp->get_lswitch());
820  lswitch.push_back(lentry);
821 }
822 
824  return static_cast<SandeshResponse *>(new OvsdbLogicalSwitchResp());
825 }
826 
828  return static_cast<KSyncObject *>(
829  session->client_idl()->logical_switch_table());
830 }
831 
832 void OvsdbLogicalSwitchReq::HandleRequest() const {
834  new LogicalSwitchSandeshTask(context(), get_session_remote_ip(),
835  get_session_remote_port(),
836  get_name(), get_vxlan_id());
838  scheduler->Enqueue(task);
839 }
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
bool Add(const std::string &key, const std::string &val)
bool Get(const std::string &key, std::string *val) const
TaskScheduler * task_scheduler() const
Definition: agent.h:1123
DBTableBase * table_
Definition: ksync_object.h:263
bool IsActive()
Definition: ksync_entry.h:191
std::string StateString() const
@ ADD_CHANGE_REQ
Definition: ksync_entry.h:53
bool IsResolved()
bool stale() const
Definition: ksync_entry.h:180
bool IsDeleted()
Definition: ksync_entry.h:182
static KSyncEntry * default_defer_entry()
KSyncEntry * Find(const KSyncEntry *key)
void Change(KSyncEntry *entry)
void SafeNotifyEvent(KSyncEntry *entry, KSyncEntry::KSyncEvent event)
KSyncEntry * CreateStale(const KSyncEntry *key)
KSyncEntry * GetReference(const KSyncEntry *key)
bool Run()
Code to execute in a task. Returns true if task is completed. Return false to reschedule the task.
void SendTrace(Trace event) const
OvsdbResourceVxLanId res_vxlan_id_
void DeleteOvs(bool add_change_in_progress)
uint32_t ucast_local_row_list_size() const
void AddMsg(struct ovsdb_idl_txn *)
const std::string & device_name() const
OvsdbResourceVxLanId & res_vxlan_id()
void DeleteMsg(struct ovsdb_idl_txn *)
void ChangeMsg(struct ovsdb_idl_txn *)
ProcessDeleteOvsReqTask * del_task_
const std::string & name() const
std::string tor_service_node() const
bool IsLess(const KSyncEntry &) const
struct ovsdb_idl_row * mcast_remote_row_
uint32_t old_mcast_remote_row_list_size() const
Ip4Address & physical_switch_tunnel_ip()
LogicalSwitchEntry(OvsdbDBObject *table, const std::string &name)
virtual void NotifyDelete(struct ovsdb_idl_row *)
uint32_t mcast_local_row_list_size() const
OvsdbIdlRowList old_mcast_remote_row_list_
std::set< IntrusiveReferrer > back_ref_set_
LogicalSwitchSandeshTask(std::string resp_ctx, AgentSandeshArguments &args)
KSyncObject * GetObject(OvsdbClientSession *session)
FilterResp Filter(KSyncEntry *entry)
void EncodeArgs(AgentSandeshArguments &args)
void UpdateResp(KSyncEntry *kentry, SandeshResponse *resp)
bool Run()
Code to execute in a task. Returns true if task is completed. Return false to reschedule the task.
KSyncEntry * DBToKSyncEntry(const DBEntry *)
void OvsdbUcastLocalMacNotify(OvsdbClientIdl::Op, struct ovsdb_idl_row *)
LogicalSwitchTable(OvsdbClientIdl *idl)
void OvsdbMcastRemoteMacNotify(OvsdbClientIdl::Op, struct ovsdb_idl_row *)
KSyncEntry * Alloc(const KSyncEntry *key, uint32_t index)
void OvsdbMcastLocalMacNotify(OvsdbClientIdl::Op, struct ovsdb_idl_row *)
OvsdbDBEntry * AllocOvsEntry(struct ovsdb_idl_row *row)
DBFilterResp OvsdbDBEntryFilter(const DBEntry *entry, const OvsdbDBEntry *ovsdb_entry)
void OvsdbNotify(OvsdbClientIdl::Op, struct ovsdb_idl_row *)
PhysicalSwitchTable * physical_switch_table()
LogicalSwitchTable * logical_switch_table()
UnicastMacLocalOvsdb * unicast_mac_local_ovsdb()
PhysicalLocatorTable * physical_locator_table()
MulticastMacLocalOvsdb * multicast_mac_local_ovsdb()
void Register(EntryType type, NotifyCB cb)
struct ovsdb_idl_row * ovs_entry_
Definition: ovsdb_entry.h:112
virtual void Ack(bool success)
Definition: ovsdb_entry.cc:199
struct ovsdb_idl_row * ovs_entry()
Definition: ovsdb_entry.h:95
OvsdbDBObject * table_
Definition: ovsdb_entry.h:111
virtual void NotifyDelete(struct ovsdb_idl_row *)
Definition: ovsdb_entry.cc:191
void NotifyAddOvsdb(OvsdbDBEntry *key, struct ovsdb_idl_row *row)
Definition: ovsdb_object.cc:93
void NotifyDeleteOvsdb(OvsdbDBEntry *key, struct ovsdb_idl_row *row)
OvsdbClientIdl * client_idl()
Definition: ovsdb_object.h:77
struct ovsdb_idl_row * ovs_entry()
Definition: ovsdb_entry.h:48
bool AcquireVxLanId(uint32_t vxlan_id)
void set_active_vxlan_id(uint32_t vxlan_id)
bool AcquireCreateRequest(KSyncEntry *creator)
void ReleaseCreateRequest(KSyncEntry *creator)
const std::string & device_display_name() const
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:307
@ CANCELLED
Definition: task.h:335
void Enqueue(Task *task)
Enqueues a task for running. Starts task if all policy rules are met else puts task in waitq....
Definition: task.cc:662
static TaskScheduler * GetInstance()
Definition: task.cc:574
CancelReturnCode Cancel(Task *task)
Cancels a Task that can be in RUN/WAIT state. The caller needs to ensure that the task exists when Ca...
Definition: task.cc:727
Task is a class to describe a computational task within OpenSDN control plane applications....
Definition: task.h:82
Definition: trace.h:289
std::pair< void *, void * > IntrusiveReferrer
Definition: agent.h:44
void intrusive_ptr_del_back_ref(IntrusiveReferrer ref, LogicalSwitchEntry *p)
void intrusive_ptr_add_back_ref(IntrusiveReferrer ref, LogicalSwitchEntry *p)
#define OVSDB_TRACE(obj,...)
void ovsdb_wrapper_delete_mcast_mac_remote(struct ovsdb_idl_row *row)
char * ovsdb_wrapper_mcast_mac_local_logical_switch(struct ovsdb_idl_row *row)
void ovsdb_wrapper_delete_ucast_mac_local(struct ovsdb_idl_row *row)
void ovsdb_wrapper_delete_mcast_mac_local(struct ovsdb_idl_row *row)
void ovsdb_wrapper_add_mcast_mac_remote(struct ovsdb_idl_txn *txn, struct ovsdb_idl_row *row, const char *mac, struct ovsdb_idl_row *ls, struct ovsdb_idl_row *pl, const char *dst_ip)
char * ovsdb_wrapper_ucast_mac_local_mac(struct ovsdb_idl_row *row)
char * ovsdb_wrapper_mcast_mac_local_mac(struct ovsdb_idl_row *row)
int64_t ovsdb_wrapper_logical_switch_tunnel_key(struct ovsdb_idl_row *row)
char * ovsdb_wrapper_mcast_mac_remote_dst_ip(struct ovsdb_idl_row *row)
struct ovsdb_idl_row * ovsdb_wrapper_add_logical_switch(struct ovsdb_idl_txn *, struct ovsdb_idl_row *, const char *, int64_t)
void ovsdb_wrapper_delete_logical_switch(struct ovsdb_idl_row *)
struct ovsdb_idl_row * ovsdb_wrapper_mcast_mac_local_physical_locator_set(struct ovsdb_idl_row *row)
char * ovsdb_wrapper_mcast_mac_remote_logical_switch(struct ovsdb_idl_row *row)
char * ovsdb_wrapper_logical_switch_name(struct ovsdb_idl_row *row)
char * ovsdb_wrapper_ucast_mac_local_logical_switch(struct ovsdb_idl_row *row)
char * ovsdb_wrapper_mcast_mac_remote_mac(struct ovsdb_idl_row *row)
static std::string UuidToString(const boost::uuids::uuid &id)
Definition: string_util.h:139
Definition: task_int.h:11