OpenSDN source code
prouter_uve_table.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 
8 #include <uve/agent_uve_base.h>
9 
10 using boost::uuids::nil_uuid;
11 
13  ("ProuterUve", 500));
14 
15 ProuterUveTable::ProuterUveTable(Agent *agent, uint32_t default_intvl)
16  : uve_prouter_map_(), uve_phy_interface_map_(), agent_(agent),
17  physical_device_listener_id_(DBTableBase::kInvalidId),
18  interface_listener_id_(DBTableBase::kInvalidId),
19  pr_timer_last_visited_(nil_uuid()),
20  pr_timer_(TimerManager::CreateTimer
21  (*(agent->event_manager())->io_service(),
22  "ProuterUveTimer",
23  TaskScheduler::GetInstance()->GetTaskId(kTaskDBExclude), 0)),
24  pi_timer_last_visited_(""),
25  pi_timer_(TimerManager::CreateTimer
26  (*(agent->event_manager())->io_service(),
27  "PIUveTimer",
28  TaskScheduler::GetInstance()->GetTaskId(kTaskDBExclude), 0)),
29  li_timer_last_visited_(nil_uuid()),
30  li_timer_(TimerManager::CreateTimer
31  (*(agent->event_manager())->io_service(),
32  "LIUveTimer",
33  TaskScheduler::GetInstance()->GetTaskId(kTaskDBExclude), 0)) {
34 
35  pr_timer_->Start(default_intvl,
36  boost::bind(&ProuterUveTable::TimerExpiry, this));
37  pi_timer_->Start(default_intvl,
38  boost::bind(&ProuterUveTable::PITimerExpiry, this));
39  li_timer_->Start(default_intvl,
40  boost::bind(&ProuterUveTable::LITimerExpiry, this));
41 }
42 
47 }
48 
50  if (timer) {
51  timer->Cancel();
53  }
54 }
55 
57  UveProuterMap::iterator it = uve_prouter_map_.lower_bound
59  if (it == uve_prouter_map_.end()) {
60  pr_timer_last_visited_ = nil_uuid();
61  return true;
62  }
63 
64  uint32_t count = 0;
65  while (it != uve_prouter_map_.end() &&
67  ProuterUveEntry* entry = it->second.get();
68  UveProuterMap::iterator prev = it;
69  it++;
70  count++;
71 
72  if (entry->deleted_) {
73  SendProuterDeleteMsg(entry);
74  if (!entry->renewed_) {
75  uve_prouter_map_.erase(prev);
77  } else {
78  entry->deleted_ = false;
79  entry->renewed_ = false;
80  entry->changed_ = false;
81  SendProuterMsg(entry);
82  }
83  } else if (entry->changed_) {
84  SendProuterMsg(entry);
85  entry->changed_ = false;
86  /* Clear renew flag to be on safer side. Not really required */
87  entry->renewed_ = false;
88  }
89  }
90 
91  if (it == uve_prouter_map_.end()) {
92  pr_timer_last_visited_ = nil_uuid();
94  } else {
95  pr_timer_last_visited_ = it->first;
97  }
98  /* Return true to trigger auto-restart of timer */
99  return true;
100 }
101 
103  UvePhyInterfaceMap::iterator it = uve_phy_interface_map_.lower_bound
105  if (it == uve_phy_interface_map_.end()) {
107  return true;
108  }
109 
110  uint32_t count = 0;
111  while (it != uve_phy_interface_map_.end() &&
113  PhyInterfaceUveEntry* entry = it->second.get();
114  string cfg_name = it->first;
115  UvePhyInterfaceMap::iterator prev = it;
116  it++;
117  count++;
118 
119  if (entry->deleted_) {
121  if (!entry->renewed_) {
122  uve_phy_interface_map_.erase(prev);
123  } else {
124  entry->deleted_ = false;
125  entry->renewed_ = false;
126  entry->changed_ = false;
127  SendPhysicalInterfaceMsg(cfg_name, entry);
128  }
129  } else if (entry->changed_) {
130  SendPhysicalInterfaceMsg(cfg_name, entry);
131  entry->changed_ = false;
132  /* Clear renew flag to be on safer side. Not really required */
133  entry->renewed_ = false;
134  }
135  }
136 
137  if (it == uve_phy_interface_map_.end()) {
140  } else {
141  pi_timer_last_visited_ = it->first;
143  }
144  /* Return true to trigger auto-restart of timer */
145  return true;
146 }
147 
149  LogicalInterfaceMap::iterator it = uve_logical_interface_map_.lower_bound
151  if (it == uve_logical_interface_map_.end()) {
152  li_timer_last_visited_ = nil_uuid();
153  return true;
154  }
155 
156  uint32_t count = 0;
157  while (it != uve_logical_interface_map_.end() &&
159  LogicalInterfaceUveEntry* entry = it->second.get();
160  boost::uuids::uuid u = it->first;
161  LogicalInterfaceMap::iterator prev = it;
162  it++;
163  count++;
164 
165  if (entry->deleted_) {
167  if (!entry->renewed_) {
168  uve_logical_interface_map_.erase(prev);
169  } else {
170  entry->deleted_ = false;
171  entry->renewed_ = false;
172  entry->changed_ = false;
173  SendLogicalInterfaceMsg(u, entry);
174  }
175  } else if (entry->changed_) {
176  SendLogicalInterfaceMsg(u, entry);
177  entry->changed_ = false;
178  /* Clear renew flag to be on safer side. Not really required */
179  entry->renewed_ = false;
180  }
181  }
182 
183  if (it == uve_logical_interface_map_.end()) {
184  li_timer_last_visited_ = nil_uuid();
186  } else {
187  li_timer_last_visited_ = it->first;
189  }
190  /* Return true to trigger auto-restart of timer */
191  return true;
192 }
193 
194 void ProuterUveTable::set_expiry_time(int time, Timer *timer) {
195  if (time != timer->time()) {
196  timer->Reschedule(time);
197  }
198 }
199 
201  (const Interface *pintf) :
202  uuid_(pintf->GetUuid()), logical_interface_set_(), changed_(true),
203  deleted_(false), renewed_(false) {
204  Update(pintf);
205 }
206 
208 }
209 
211  name_(p->name()), uuid_(p->uuid()), physical_interface_set_(),
212  changed_(true), deleted_(false), renewed_(false), mastership_(p->master()) {
213 }
214 
216  (const LogicalInterface *li) : name_(li->name()), vlan_(kInvalidVlanId),
217  vmi_list_(), changed_(true), deleted_(false), renewed_(false) {
218  Update(li);
219 }
220 
222  (const LogicalInterface *li) {
223  const VlanLogicalInterface *vlif = dynamic_cast
224  <const VlanLogicalInterface *>(li);
225  if (vlif) {
226  vlan_ = vlif->vlan();
227  } else {
228  vlan_ = kInvalidVlanId;
229  }
230  changed_ = true;
231 }
232 
234 }
235 
237  physical_interface_set_.clear();
238  logical_interface_set_.clear();
239  deleted_ = true;
240  renewed_ = false;
241 }
242 
244  (const Interface *itf) {
245  InterfaceSet::iterator it = physical_interface_set_.find(itf->name());
246  if (it == physical_interface_set_.end()) {
247  physical_interface_set_.insert(itf->name());
248  changed_ = true;
249  }
250 }
251 
253  (const Interface *itf) {
254  InterfaceSet::iterator it = physical_interface_set_.find(itf->name());
255  if (it != physical_interface_set_.end()) {
256  physical_interface_set_.erase(it);
257  changed_ = true;
258  }
259 }
260 
262  (const LogicalInterface *itf) {
263  LogicalInterfaceSet::iterator it = logical_interface_set_.find
264  (itf->GetUuid());
265  if (it == logical_interface_set_.end()) {
266  logical_interface_set_.insert(itf->GetUuid());
267  }
268 }
269 
271  (const LogicalInterface *itf) {
272  bool deleted = false;
273  LogicalInterfaceSet::iterator it = logical_interface_set_.find(itf->
274  GetUuid());
275  if (it != logical_interface_set_.end()) {
276  logical_interface_set_.erase(it);
277  deleted = true;
278  }
279  return deleted;
280 }
281 
283  (const PhysicalDevice *pr) {
284  ProuterUveEntryPtr uve(new ProuterUveEntry(pr));
285  return uve;
286 }
287 
290  UveProuterMap::const_iterator it = uve_prouter_map_.find(u);
291  if (it == uve_prouter_map_.end()) {
292  return NULL;
293  }
294  return it->second.get();
295 }
296 
298  NameToPhyInterfaceUveEntry(const string &name) const {
299  UvePhyInterfaceMap::const_iterator it = uve_phy_interface_map_.find(name);
300  if (it != uve_phy_interface_map_.end()) {
301  return it->second.get();
302  }
303  return NULL;
304 }
305 
306 const Interface *ProuterUveTable::NameToInterface(const string &name) const {
307  PhysicalInterfaceKey phy_key(name);
308  Interface *intf = static_cast<PhysicalInterface *>
309  (agent_->interface_table()->FindActiveEntry(&phy_key));
310  if (intf == NULL) {
311  RemotePhysicalInterfaceKey rem_key(name);
312  intf = static_cast<RemotePhysicalInterface *>
313  (agent_->interface_table()->FindActiveEntry(&rem_key));
314  }
315  return intf;
316 }
317 
319  (const Interface *intf) {
320  PhysicalDevice *pde = NULL;
321  const RemotePhysicalInterface *rpintf;
322  const PhysicalInterface *pintf;
323  if (intf->type() == Interface::REMOTE_PHYSICAL) {
324  rpintf = static_cast<const RemotePhysicalInterface *>(intf);
325  pde = rpintf->physical_device();
326  } else if (intf->type() == Interface::PHYSICAL) {
327  pintf = static_cast<const PhysicalInterface *>(intf);
328  pde = pintf->physical_device();
329  }
330  return pde;
331 }
332 
334  (vector<string> &vmi_list) const {
335  ProuterUveTable::InterfaceSet::iterator vit = vmi_list_.begin();
336  while (vit != vmi_list_.end()) {
337  vmi_list.push_back((*vit));
338  ++vit;
339  }
340  return;
341 }
342 
344  (vector<string> &list) const {
345  ProuterUveTable::LogicalInterfaceSet::iterator it =
346  logical_interface_set_.begin();
347  while (it != logical_interface_set_.end()) {
348  list.push_back((to_string(*it)));
349  ++it;
350  }
351  return;
352 }
353 
355  ProuterData *uve) const {
356  vector<string> phy_if_list;
357  vector<string> logical_list;
358  vector<string> empty_agent_list;
359  /* We are using hostname instead of fq-name because Prouter UVE sent by
360  * other modules to send topology information uses hostname and we want
361  * both these information to be seen in same UVE */
362  uve->set_name(entry->name_);
363  uve->set_uuid(to_string(entry->uuid_));
364  uve->set_agent_name(agent_->agent_name());
365  InterfaceSet::iterator pit = entry->physical_interface_set_.begin();
366  while (pit != entry->physical_interface_set_.end()) {
367  phy_if_list.push_back(*pit);
368  ++pit;
369  }
370  uve->set_physical_interface_list(phy_if_list);
371 
372 
373  LogicalInterfaceSet::const_iterator lit = entry->logical_interface_set_.
374  begin();
375 
376  while (lit != entry->logical_interface_set_.end()) {
377  logical_list.push_back(to_string(*lit));
378  ++lit;
379  }
380  uve->set_logical_interface_list(logical_list);
381  if (entry->mastership_) {
382  vector<string> agent_list;
383  agent_list.push_back(agent_->agent_name());
384  if (agent_->tsn_enabled()) {
385  uve->set_tsn_agent_list(agent_list);
386  } else if (agent_->tor_agent_enabled()) {
387  uve->set_connected_agent_list(agent_list);
388  }
389  } else {
390  /* Send Empty list */
391  if (agent_->tsn_enabled()) {
392  uve->set_tsn_agent_list(empty_agent_list);
393  } else if (agent_->tor_agent_enabled()) {
394  uve->set_connected_agent_list(empty_agent_list);
395  }
396  }
397  vnsConstants vnsVrouterType;
398  if (agent_->vcpe_gateway_mode()) {
399  uve->set_gateway_mode(vnsVrouterType.VrouterAgentGatewayModeMap.at
400  (VrouterAgentGatewayMode::VCPE));
401  } else if ((agent_->server_gateway_mode()) ||
402  (agent_->pbb_gateway_mode())) {
403  uve->set_gateway_mode(vnsVrouterType.VrouterAgentGatewayModeMap.at
404  (VrouterAgentGatewayMode::SERVER));
405  } else {
406  uve->set_gateway_mode(vnsVrouterType.VrouterAgentGatewayModeMap.at
408  }
409 }
410 
412  ProuterData uve;
413  FrameProuterMsg(entry, &uve);
414  DispatchProuterMsg(uve);
415  return true;
416 }
417 
419  ProuterData uve;
420  uve.set_name(e->name_);
421  uve.set_deleted(true);
422  DispatchProuterMsg(uve);
423 }
424 
426  if (pde && !pde->IsDeleted()) {
428  if (entry) {
429  entry->changed_ = true;
430  }
431  }
432 }
433 
435  const PhysicalDevice *pde = InterfaceToProuter(pi);
437 }
438 
439 void ProuterUveTable::DispatchProuterMsg(const ProuterData &uve) {
440  UveProuterAgent::Send(uve);
441 }
442 
444  vector<string> plist;
445  UveProuterMap::iterator it = uve_prouter_map_.begin();
446  while (it != uve_prouter_map_.end()) {
447  ProuterUveEntry* entry = it->second.get();
448  plist.push_back(entry->name_);
449  ++it;
450  }
452 }
453 
455  (const PhysicalDevice *p) {
456  ProuterUveEntryPtr uve = Allocate(p);
457  pair<UveProuterMap::iterator, bool> ret;
458  ret = uve_prouter_map_.insert(UveProuterPair(p->uuid(), uve));
459  UveProuterMap::iterator it = ret.first;
460  ProuterUveEntry *entry = it->second.get();
461  entry->changed_ = true;
462  entry->mastership_ = p->master();
463  if (entry->deleted_) {
464  entry->renewed_ = true;
465  }
466  if (!entry->renewed_) {
468  }
469  return entry;
470 }
471 
473  UveProuterMap::iterator it = uve_prouter_map_.find(p->uuid());
474  if (it == uve_prouter_map_.end()) {
475  return;
476  }
477 
478  ProuterUveEntry* entry = it->second.get();
479  /* Reset all the non-key fields of entry so that it has proper values in
480  * case it gets reused. Also update deleted_ and renewed_ flags */
481  entry->Reset();
482 }
483 
485  LogicalInterfaceMap::iterator it = uve_logical_interface_map_.find(itf->
486  GetUuid());
487  if (it != uve_logical_interface_map_.end()) {
488  LogicalInterfaceUveEntry *entry = it->second.get();
489  entry->deleted_ = true;
490  }
491 }
492 
494  LogicalInterfaceMap::iterator it = uve_logical_interface_map_.find(itf->
495  GetUuid());
496  if (it == uve_logical_interface_map_.end()) {
499  uve));
500  return;
501  } else {
502  LogicalInterfaceUveEntry *entry = it->second.get();
503  entry->Update(itf);
504  }
505 }
506 
508  UvePhyInterfaceMap::iterator it = uve_phy_interface_map_.find(pintf->
509  name());
510  PhyInterfaceUveEntry *entry = NULL;
511  if (it != uve_phy_interface_map_.end()) {
512  entry = it->second.get();
513  entry->deleted_ = true;
514  }
515 }
516 
518  const LogicalInterface *intf) {
519  UvePhyInterfaceMap::iterator it = uve_phy_interface_map_.find(pintf->
520  name());
521  PhyInterfaceUveEntry *ientry = NULL;
522  if (it == uve_phy_interface_map_.end()) {
525  entry));
526  ientry = entry.get();
527  } else {
528  ientry = it->second.get();
529  }
530  LogicalInterfaceSet::iterator lit = ientry->logical_interface_set_.
531  find(intf->GetUuid());
532  if (lit == ientry->logical_interface_set_.end()) {
533  ientry->logical_interface_set_.insert(intf->GetUuid());
534  ientry->changed_ = true;
535  }
536 }
537 
539  (const PhysicalDevice *p, const LogicalInterface *intf) {
540  UveProuterMap::iterator it = uve_prouter_map_.find(p->uuid());
541  if (it == uve_prouter_map_.end()) {
542  return;
543  }
544 
545  ProuterUveEntry* entry = it->second.get();
546  entry->AddLogicalInterface(intf);
547  entry->changed_ = true;
548 }
549 
551  const LogicalInterface *intf) {
553  if (entry != NULL) {
554  LogicalInterfaceSet::iterator it = entry->logical_interface_set_.
555  find(intf->GetUuid());
556  if (it != entry->logical_interface_set_.end()) {
557  entry->logical_interface_set_.erase(it);
558  entry->changed_ = true;
559  }
560  }
561 }
562 
564  (const boost::uuids::uuid &u, const LogicalInterface *intf) {
565  UveProuterMap::iterator it = uve_prouter_map_.find(u);
566  if (it == uve_prouter_map_.end()) {
567  return;
568  }
569 
570  ProuterUveEntry* entry = it->second.get();
571  bool deleted = entry->DeleteLogicalInterface(intf);
572  if (deleted) {
573  entry->changed_ = true;
574  }
575 }
576 
578  DBEntryBase *e) {
579  const PhysicalDevice *pr = static_cast<const PhysicalDevice *>(e);
580  PhysicalDeviceState *state = static_cast<PhysicalDeviceState *>
581  (e->GetState(partition->parent(), physical_device_listener_id_));
582  if (e->IsDeleted()) {
583  if (state) {
584  /* Uve Msg send is part of Delete API */
585  DeleteHandler(pr);
587  delete state;
588  }
589  } else {
590  if (!state) {
591  state = new PhysicalDeviceState();
593  state);
594  /* Uve Msg send is part of Add API */
595  AddHandler(pr);
596  } else {
597  /* For Change notifications send only the msg */
599  entry->mastership_ = pr->master();
600  entry->changed_ = true;
601  }
602  }
603 }
604 
606  const boost::uuids::uuid &u) {
608  if (!entry) {
609  return;
610  }
611  entry->DeletePhysicalInterface(intf);
612  entry->changed_ = true;
613 }
614 
616  UvePhyInterfaceMap::iterator it = uve_phy_interface_map_.find(intf->name());
617  if (it == uve_phy_interface_map_.end()) {
619  uve_phy_interface_map_.insert(UvePhyInterfacePair(intf->name(), uve));
620  return;
621  }
622  PhyInterfaceUveEntry *entry = it->second.get();
623  entry->Update(intf);
624 }
625 
627  const boost::uuids::uuid &u) {
628  if (intf->IsDeleted()) {
629  MarkDeletedPhysical(intf);
630  }
631  /* Ignore notifications for PhysicalInterface if it has no
632  PhysicalDevice */
633  if (u == nil_uuid()) {
634  return;
635  }
637  if (entry == NULL) {
638  /* We hit this condition when physical-device is deleted before
639  * physical interface */
640  return;
641  }
642  if (intf->IsDeleted()) {
643  entry->DeletePhysicalInterface(intf);
644  } else {
645  entry->AddPhysicalInterface(intf);
646  }
647 }
648 
651  const boost::uuids::uuid li = vmi->logical_interface();
652  LogicalInterfaceMap::iterator it = uve_logical_interface_map_.find(li);
653  if (it != uve_logical_interface_map_.end()) {
654  entry = it->second.get();
655  } else {
656  LogicalInterface *intf;
657  VlanLogicalInterfaceKey key(li, "");
658  intf = static_cast<LogicalInterface *>
660  if (!intf) {
661  return;
662  }
665  entry = uve.get();
666  }
667  InterfaceSet::iterator vit = entry->vmi_list_.find(vmi->cfg_name());
668  if (vit == entry->vmi_list_.end()) {
669  entry->vmi_list_.insert(vmi->cfg_name());
670  entry->changed_ = true;
671  }
672 }
673 
675  const VmInterface *vmi) {
676  LogicalInterfaceMap::iterator it = uve_logical_interface_map_.find(li);
677  if (it != uve_logical_interface_map_.end()) {
678  LogicalInterfaceUveEntry *entry = it->second.get();
679  ProuterUveTable::InterfaceSet::iterator vit = entry->vmi_list_.find
680  (vmi->cfg_name());
681  if (vit != entry->vmi_list_.end()) {
682  entry->vmi_list_.erase(vit);
683  entry->changed_ = true;
684  }
685  }
686 }
687 
689  DBEntryBase *e) {
690  VmInterfaceState *state = static_cast<VmInterfaceState *>
691  (e->GetState(partition->parent(), interface_listener_id_));
692  const VmInterface *intf = static_cast<const VmInterface *>(e);
693  if (e->IsDeleted()) {
694  if (state) {
696  e->ClearState(partition->parent(), interface_listener_id_);
697  delete state;
698  }
699  return;
700  }
701  if (!state) {
702  state = new VmInterfaceState();
703  e->SetState(partition->parent(), interface_listener_id_, state);
704  }
705  if (state->logical_interface_ != intf->logical_interface()) {
706  if (state->logical_interface_ != nil_uuid()) {
708  }
709  state->logical_interface_ = intf->logical_interface();
710  }
711  if (intf->logical_interface() != nil_uuid()) {
712  VMInterfaceAdd(intf);
713  }
714 }
715 
717  DBEntryBase *e) {
718  const Interface *intf = static_cast<const Interface *>(e);
719  const LogicalInterface *lintf = NULL;
720  const RemotePhysicalInterface *rpintf = NULL;
721  const PhysicalInterface *pintf = NULL;
722  const Interface *physical_interface = NULL;
723  PhysicalDevice *pde = NULL;
724  if (intf->type() == Interface::REMOTE_PHYSICAL) {
725  rpintf = static_cast<const RemotePhysicalInterface *>(intf);
726  pde = rpintf->physical_device();
727  } else if (intf->type() == Interface::LOGICAL) {
728  lintf = static_cast<const LogicalInterface *>(intf);
729  physical_interface = lintf->physical_interface();
730  pde = lintf->physical_device();
731  } else if (intf->type() == Interface::PHYSICAL) {
732  pintf = static_cast<const PhysicalInterface *>(intf);
733  /* Ignore PhysicalInterface notifications if it is not of subtype
734  * CONFIG */
735  if (pintf->subtype() != PhysicalInterface::CONFIG) {
736  return;
737  }
738  pde = pintf->physical_device();
739  } else if (intf->type() == Interface::VM_INTERFACE) {
740  VmInterfaceHandler(partition, e);
741  return;
742  } else {
743  /* Ignore notifications for interface which are not
744  RemotePhysical/Logical */
745  return;
746  }
747  ProuterInterfaceState *state = static_cast<ProuterInterfaceState *>
748  (e->GetState(partition->parent(), interface_listener_id_));
749  if (e->IsDeleted()) {
750  if (state) {
751  if (pintf) {
753  } else if (rpintf) {
755  } else if (lintf) {
756  if (!state->physical_interface_.empty()) {
758  lintf);
759  }
760  if (state->physical_device_ != nil_uuid()) {
762  lintf);
763  }
764  MarkDeletedLogical(lintf);
765  }
766  e->ClearState(partition->parent(), interface_listener_id_);
767  delete state;
768  }
769  } else {
770  if (!state) {
771  state = new ProuterInterfaceState();
772  e->SetState(partition->parent(), interface_listener_id_, state);
773  }
774  boost::uuids::uuid pde_uuid = nil_uuid();
775  if (pde) {
776  pde_uuid = pde->uuid();
777  }
778  string pname;
779  if (physical_interface) {
780  pname = physical_interface->name();
781  }
782  if (intf->type() == Interface::LOGICAL) {
783  if (state->physical_interface_ != pname) {
784  if (!state->physical_interface_.empty()) {
786  lintf);
787  }
788  if (physical_interface) {
789  AddLogicalToPhysical(physical_interface, lintf);
790  }
791  state->physical_interface_ = pname;
792  }
793  if (state->physical_device_ != pde_uuid) {
794  if (state->physical_device_ != nil_uuid()) {
796  lintf);
797  }
798  if (!physical_interface && pde) {
799  AddProuterLogicalInterface(pde, lintf);
800  }
801  state->physical_device_ = pde_uuid;
802  }
804  } else {
805  if (state->physical_device_ != pde_uuid) {
806  if (state->physical_device_ != nil_uuid()) {
808  }
809  if (pde) {
810  if (pintf) {
811  PhysicalInterfaceHandler(pintf, pde->uuid());
812  } else if (rpintf) {
813  PhysicalInterfaceHandler(rpintf, pde->uuid());
814  }
815  }
816  state->physical_device_ = pde_uuid;
817  }
819  }
820  }
821 }
822 
826  (boost::bind(&ProuterUveTable::PhysicalDeviceNotify, this, _1, _2));
827 
828  InterfaceTable *i_table = agent_->interface_table();
830  (boost::bind(&ProuterUveTable::InterfaceNotify, this, _1, _2));
831 }
832 
836  Unregister(physical_device_listener_id_);
839 }
840 
841 void ProuterUveTable::SendLogicalInterfaceDeleteMsg(const string &config_name) {
842  UveLogicalInterfaceAgent uve;
843  uve.set_name(config_name);
844  uve.set_deleted(true);
846 }
847 
849  LogicalInterfaceUveEntry *entry) {
850  UveLogicalInterfaceAgent uve;
851  vector<string> list;
852 
853  uve.set_name(to_string(u));
854  uve.set_config_name(entry->name_);
855  uve.set_vlan(entry->vlan_);
856 
857  entry->FillVmInterfaceList(list);
858  uve.set_vm_interface_list(list);
859 
861 }
862 
864  (const UveLogicalInterfaceAgent &uve) {
865  UveLogicalInterfaceAgentTrace::Send(uve);
866 }
867 
869  UvePhysicalInterfaceAgent uve;
870  uve.set_name(cfg_name);
871  uve.set_deleted(true);
873 }
874 
875 void ProuterUveTable::SendPhysicalInterfaceMsg(const string &cfg_name,
876  PhyInterfaceUveEntry *entry) {
877  UvePhysicalInterfaceAgent uve;
878  vector<string> list;
879 
880  uve.set_name(cfg_name);
881  uve.set_uuid(to_string(entry->uuid_));
882 
883  entry->FillLogicalInterfaceList(list);
884  uve.set_logical_interface_list(list);
885 
887 }
888 
890  (const UvePhysicalInterfaceAgent &uve) {
891  UvePhysicalInterfaceAgentTrace::Send(uve);
892 }
893 
895 {
897  if (entry == NULL) {
898  string status = " false";
899  if (value) {
900  status.assign(" true");
901  }
902  string msg = "Mastership update failed for " + to_string(u) + status;
903  PROUTER_UVE_TRACE(msg);
904  return;
905  }
906  if (entry->mastership_ != value) {
907  entry->mastership_ = value;
908  entry->changed_ = true;
909  }
910 }
#define kTaskDBExclude
Definition: agent.h:339
AgentDBEntry * FindActiveEntry(const DBEntry *key)
Definition: agent_db.cc:111
static const uint32_t kUveCountPerTimer
uint32_t incremental_interval() const
VrouterUveEntryBase * vrouter_uve_entry() const
uint32_t default_interval() const
Definition: agent.h:361
InterfaceTable * interface_table() const
Definition: agent.h:468
bool pbb_gateway_mode() const
Definition: agent.h:1173
const std::string & agent_name() const
Definition: agent.h:881
AgentUveBase * uve() const
Definition: agent.cc:913
bool tsn_enabled() const
Definition: agent.h:1165
bool vcpe_gateway_mode() const
Definition: agent.h:1172
PhysicalDeviceTable * physical_device_table() const
Definition: agent.h:631
bool server_gateway_mode() const
Definition: agent.h:1171
bool tor_agent_enabled() const
Definition: agent.h:1167
DBState * GetState(DBTableBase *tbl_base, ListenerId listener) const
Definition: db_entry.cc:38
void ClearState(DBTableBase *tbl_base, ListenerId listener)
Definition: db_entry.cc:74
bool IsDeleted() const
Definition: db_entry.h:49
void SetState(DBTableBase *tbl_base, ListenerId listener, DBState *state)
Definition: db_entry.cc:23
ListenerId Register(ChangeCallback callback, const std::string &name="unspecified")
Definition: db_table.cc:208
static const int kInvalidId
Definition: db_table.h:65
void Unregister(ListenerId listener)
Definition: db_table.cc:213
DBTableBase * parent()
@ VM_INTERFACE
Definition: interface.h:38
@ PHYSICAL
Definition: interface.h:32
@ REMOTE_PHYSICAL
Definition: interface.h:34
const std::string & name() const
Definition: interface.h:117
const boost::uuids::uuid & GetUuid() const
Definition: interface.h:116
Type type() const
Definition: interface.h:115
PhysicalDevice * physical_device() const
Interface * physical_interface() const
const boost::uuids::uuid & uuid() const
bool master() const
SubType subtype() const
PhysicalDevice * physical_device() const
void DeleteHandler(const PhysicalDevice *p)
boost::shared_ptr< PhyInterfaceUveEntry > PhyInterfaceUveEntryPtr
const PhysicalDevice * InterfaceToProuter(const Interface *intf)
boost::uuids::uuid pr_timer_last_visited_
ProuterUveEntry * AddHandler(const PhysicalDevice *p)
void FrameProuterMsg(ProuterUveEntry *entry, ProuterData *uve) const
void MarkDeletedPhysical(const Interface *pintf)
ProuterUveEntry * PDEntryToProuterUveEntry(const boost::uuids::uuid &u) const
void AddProuterLogicalInterface(const PhysicalDevice *p, const LogicalInterface *intf)
std::pair< boost::uuids::uuid, ProuterUveEntryPtr > UveProuterPair
bool SendProuterMsg(ProuterUveEntry *entry)
DBTableBase::ListenerId interface_listener_id_
boost::uuids::uuid li_timer_last_visited_
std::pair< std::string, PhyInterfaceUveEntryPtr > UvePhyInterfacePair
void InterfaceNotify(DBTablePartBase *partition, DBEntryBase *e)
UveProuterMap uve_prouter_map_
LogicalInterfaceMap uve_logical_interface_map_
void VmInterfaceHandler(DBTablePartBase *partition, DBEntryBase *e)
void AddUpdateLogicalInterface(const LogicalInterface *i)
boost::shared_ptr< LogicalInterfaceUveEntry > LogicalInterfaceUveEntryPtr
void SendProuterDeleteMsg(ProuterUveEntry *e)
void set_expiry_time(int time, Timer *timer)
static const uint16_t kInvalidVlanId
DBTableBase::ListenerId physical_device_listener_id_
void MarkDeletedLogical(const LogicalInterface *pintf)
ProuterUveTable(Agent *agent, uint32_t default_intvl)
boost::shared_ptr< ProuterUveEntry > ProuterUveEntryPtr
void SendLogicalInterfaceDeleteMsg(const std::string &config_name)
void SendPhysicalInterfaceMsg(const std::string &name, PhyInterfaceUveEntry *entry)
void MarkPhysicalDeviceChanged(const PhysicalDevice *pde)
virtual ~ProuterUveTable()
virtual void DispatchProuterMsg(const ProuterData &uve)
void AddLogicalToPhysical(const Interface *p, const LogicalInterface *i)
void TimerCleanup(Timer *timer)
void PhysicalDeviceNotify(DBTablePartBase *partition, DBEntryBase *e)
ProuterUveEntryPtr Allocate(const PhysicalDevice *pr)
void UpdateMastership(const boost::uuids::uuid &u, bool value)
PhyInterfaceUveEntry * NameToPhyInterfaceUveEntry(const std::string &name) const
void DeletePhysicalFromProuter(const Interface *i, const boost::uuids::uuid &u)
virtual void DispatchPhysicalInterfaceMsg(const UvePhysicalInterfaceAgent &uve)
std::pair< boost::uuids::uuid, LogicalInterfaceUveEntryPtr > LogicalInterfacePair
virtual void DispatchLogicalInterfaceMsg(const UveLogicalInterfaceAgent &u)
void SendProuterVrouterAssociation()
void SendLogicalInterfaceMsg(const boost::uuids::uuid &u, LogicalInterfaceUveEntry *entry)
std::string pi_timer_last_visited_
void VMInterfaceAdd(const VmInterface *vmi)
void DeleteLogicalFromPhysical(const std::string &name, const LogicalInterface *i)
void DeleteProuterLogicalInterface(const boost::uuids::uuid &u, const LogicalInterface *intf)
void SendProuterMsgFromPhyInterface(const Interface *pi)
UvePhyInterfaceMap uve_phy_interface_map_
void SendPhysicalInterfaceDeleteMsg(const std::string &cfg_name)
void PhysicalInterfaceHandler(const Interface *i, const boost::uuids::uuid &u)
const Interface * NameToInterface(const std::string &name) const
void VMInterfaceRemove(const boost::uuids::uuid &li, const VmInterface *vmi)
void AddUpdatePhysicalInterface(const Interface *intf)
PhysicalDevice * physical_device() const
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:307
static bool DeleteTimer(Timer *Timer)
Definition: timer.cc:222
Definition: timer.h:58
bool Cancel()
Definition: timer.cc:150
bool Start(int time, Handler handler, ErrorHandler error_handler=NULL)
Definition: timer.cc:108
bool Reschedule(int time)
Definition: timer.cc:137
int time() const
Definition: timer.h:100
uint16_t vlan() const
const boost::uuids::uuid & logical_interface() const
const std::string & cfg_name() const
void SendVrouterProuterAssociation(const std::vector< std::string > &list)
SandeshTraceBufferPtr ProuterUveTraceBuf(SandeshTraceBufferCreate("ProuterUve", 500))
#define PROUTER_UVE_TRACE(...)
boost::shared_ptr< TraceBuffer< SandeshTrace > > SandeshTraceBufferPtr
Definition: sandesh_trace.h:19
SandeshTraceBufferPtr SandeshTraceBufferCreate(const std::string &buf_name, size_t buf_size, bool trace_enable=true)
Definition: sandesh_trace.h:47
void FillVmInterfaceList(std::vector< std::string > &vmi_list) const
void Update(const LogicalInterface *li)
LogicalInterfaceUveEntry(const LogicalInterface *li)
void Update(const Interface *pintf)
PhyInterfaceUveEntry(const Interface *pintf)
void FillLogicalInterfaceList(std::vector< std::string > &list) const
bool DeleteLogicalInterface(const LogicalInterface *itf)
void AddPhysicalInterface(const Interface *itf)
ProuterUveEntry(const PhysicalDevice *p)
void AddLogicalInterface(const LogicalInterface *itf)
void DeletePhysicalInterface(const Interface *itf)
LogicalInterfaceSet logical_interface_set_
boost::uuids::uuid uuid