OpenSDN source code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vrf.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include <cmn/agent_cmn.h>
6 
7 #include <base/lifetime.h>
8 #include <base/parse_object.h>
9 #include <ifmap/ifmap_link.h>
10 #include <ifmap/ifmap_table.h>
11 
12 #include <bgp_schema_types.h>
13 #include <vnc_cfg_types.h>
14 
15 #include <init/agent_init.h>
16 #include <cfg/cfg_init.h>
17 #include <route/route.h>
18 #include <oper/route_common.h>
19 #include <oper/vn.h>
20 #include <oper/vrf.h>
21 #include <oper/peer.h>
22 #include <oper/mirror_table.h>
26 #include <oper/agent_sandesh.h>
27 #include <oper/nexthop.h>
28 #include <oper/config_manager.h>
33 
34 #define MAX_VRF_DELETE_TIMEOUT_RETRY_COUNT 10
35 
36 using namespace std;
37 using namespace autogen;
38 
40 
42  public:
44  LifetimeActor((static_cast<VrfTable *>(vrf->get_table()))->
45  agent()->lifetime_manager()), table_(vrf, this) {
46  }
47  virtual ~DeleteActor() {
48  }
49  virtual bool MayDelete() const {
50  //No table present, then this VRF can be deleted
51  return table_->AllRouteTableDeleted();
52  }
53  virtual void Shutdown() {
54  }
55  virtual void Destroy() {
56  table_->SendObjectLog(AgentLogEvent::DEL);
57  table_ = NULL;
58  }
59 
60  private:
62 };
63 
64 VrfEntry::VrfEntry(const string &name, uint32_t flags, Agent *agent) :
65  name_(name), id_(kInvalidIndex), flags_(flags),
66  walkid_(DBTableWalker::kInvalidWalkerId), deleter_(NULL),
67  rt_table_db_(), delete_timeout_timer_(NULL),
68  table_label_(MplsTable::kInvalidLabel),
69  vxlan_id_(VxLanTable::kInvalidvxlan_id),
70  rt_table_delete_bmap_(0),
71  route_resync_walker_(NULL), allow_route_add_on_deleted_vrf_(false),
72  layer2_control_word_(false),
73  rd_(0), routing_vrf_(false), retries_(0),
74  hbf_rintf_(Interface::kInvalidIndex),
75  hbf_lintf_(Interface::kInvalidIndex), deleted_(false) {
76  nh_.reset();
77 }
78 
80  if (id_ != kInvalidIndex) {
81  VrfTable *table = static_cast<VrfTable *>(get_table());
82  SetNotify();
83 
84  //In case of PBB VRF is implictly created, hence upon
85  //delete get the bmac VRF and trigger a notify,
86  //so that if bridge domain is reused it can be recreated
88  table->VrfReuse(bmac_vrf_name_);
89  }
90  table->FreeVrfId(id_);
91  table->VrfReuse(GetName());
92  vrf_node_ptr_ = NULL;
93  }
94  //Delete timer
97 }
98 
99 bool VrfEntry::IsLess(const DBEntry &rhs) const {
100  const VrfEntry &a = static_cast<const VrfEntry &>(rhs);
101  return (name_ < a.name_);
102 }
103 
104 string VrfEntry::ToString() const {
105  return "VRF";
106 }
107 
108 bool VrfEntry::UpdateVxlanId(Agent *agent, uint32_t new_vxlan_id) {
109  bool ret = false;
110  if (new_vxlan_id == vxlan_id_) {
111  return ret;
112  }
113 
114  vxlan_id_ = new_vxlan_id;
115  return ret;
116 }
117 
118 void VrfEntry::CreateTableLabel(bool learning_enabled, bool l2,
119  bool flood_unknown_unicast,
120  bool layer2_control_word) {
121  l2_ = l2;
122  VrfTable *table = static_cast<VrfTable *>(get_table());
123  Agent *agent = table->agent();
124 
125  // Create VrfNH and assign label from it
126  DBRequest nh_req;
128  VrfNHKey *vrf_nh_key = new VrfNHKey(name_, false, l2);
129  nh_req.key.reset(vrf_nh_key);
130  nh_req.data.reset(new VrfNHData(flood_unknown_unicast, learning_enabled,
131  layer2_control_word));
132  agent->nexthop_table()->Process(nh_req);
133 
134  // Get label from nh
135  NextHop *nh = static_cast<NextHop *>(
136  agent->nexthop_table()->FindActiveEntry(vrf_nh_key));
137  nh_ = nh;
138  set_table_label(nh->mpls_label()->label());
139 }
140 
142  DB *db = get_table()->database();
143  VrfTable *table = static_cast<VrfTable *>(get_table());
144 
145  for (uint8_t type = (Agent::INVALID + 1); type < Agent::ROUTE_TABLE_MAX; type++) {
146  rt_table_db_[type] = static_cast<AgentRouteTable *>
147  (db->CreateTable(name_ +
149  rt_table_db_[type]->SetVrf(this);
151  }
152 }
153 
155  for (int table_type = (Agent::INVALID + 1);
156  table_type < Agent::ROUTE_TABLE_MAX; table_type++) {
157  VrfTable *vrf_table = ((VrfTable *) get_table());
158  AgentRouteTable *route_table =
159  vrf_table->GetRouteTable(name_, table_type);
160  if (route_table) {
161  vrf_table->DeleteFromDbTree(table_type, name_);
162  vrf_table->database()->RemoveTable(route_table);
163  delete route_table;
164  }
165  }
166 }
167 
169  VrfTable *table = static_cast<VrfTable *>(get_table());
170  Agent *agent = table->agent();
171  // get_table() would return NULL in Add(), so move dependent functions and
172  // initialization to PostAdd
173  deleter_.reset(new DeleteActor(this));
174  if (route_resync_walker_.get() == NULL) {
175  route_resync_walker_ = new AgentRouteResync("VrfRouteResyncWalker",
176  agent);
177  agent->oper_db()->agent_route_walk_manager()->
178  RegisterWalker(static_cast<AgentRouteWalker *>
179  (route_resync_walker_.get()));
180  }
181  // Create the route-tables and insert them into dbtree_
183 
185  if (vn_) {
186  vxlan_id = vn_->GetVxLanId();
187  }
188  UpdateVxlanId(agent, vxlan_id);
189 
190  // Add the L2 Receive routes for VRRP mac
191  BridgeAgentRouteTable *l2_table = static_cast<BridgeAgentRouteTable *>
193  l2_table->AddBridgeReceiveRoute(agent->local_vm_peer(), name_, 0,
194  agent->vrrp_mac(), "");
195  l2_table->AddBridgeReceiveRoute(agent->local_peer(), name_,
196  agent->left_si_mac(), "", "pkt0", true);
197  l2_table->AddBridgeReceiveRoute(agent->local_peer(), name_,
198  agent->right_si_mac(), "", "pkt0", true);
199 
200  // Add the L2 Receive routes for xconnect interface to vhost
201  // Note, vhost is not created when fabric VRF is created. We only need
202  // VRRP MAC on fabric vrf. So, we are good for now
203  const VmInterface *vhost = dynamic_cast<const VmInterface *>
204  (agent->vhost_interface());
205  if (vhost && vhost->parent_list().empty() == false) {
206  for (size_t i = 0; i < vhost->parent_list().size(); i++) {
207  l2_table->AddBridgeReceiveRoute(agent->local_vm_peer(), name_, 0,
208  vhost->parent_list()[i]->mac(), "");
209  }
210  }
211 
212  //Add receive route for vmware physical interface mac, so
213  //that packets hitting this mac gets routed(inter-vn traffic)
214  if (agent->isVmwareMode()) {
216  Interface *intf = static_cast<Interface *>
217  (agent->interface_table()->FindActiveEntry(&key));
218  if (intf) {
219  l2_table->AddBridgeReceiveRoute(agent->local_vm_peer(), name_, 0,
220  intf->mac(), "");
221  }
222  }
223 
224  SendObjectLog(AgentLogEvent::ADD);
225 }
226 
228  VrfKey *key = new VrfKey(name_);
229  return DBEntryBase::KeyPtr(key);
230 }
231 
232 void VrfEntry::SetKey(const DBRequestKey *key) {
233  const VrfKey *k = static_cast<const VrfKey *>(key);
234  name_ = k->name_;
235 }
236 
238  InetUnicastAgentRouteTable *table = NULL;
239  if (addr.is_v4()) {
240  table = GetInet4UnicastRouteTable();
241  } else if (addr.is_v6()) {
242  table = GetInet6UnicastRouteTable();
243  }
244  if (table == NULL)
245  return NULL;
246 
247  return table->FindLPM(addr);
248 }
249 
251  InetUnicastAgentRouteTable *table = NULL;
252 
253  if (rt_key.prefix_address().is_v4()) {
254  table = GetInet4UnicastRouteTable();
255  } else if (rt_key.prefix_address().is_v6()) {
256  table = GetInet6UnicastRouteTable();
257  }
258  if (table == NULL)
259  return NULL;
260 
261  return table->FindLPM(rt_key);
262 }
263 
265  return deleter_.get();
266 }
267 
269  for (int i = Agent::INET4_UNICAST; i < Agent::ROUTE_TABLE_MAX; i++) {
270  if ((rt_table_delete_bmap_ & (1 << i)) == 0)
271  return false;
272  }
273 
274  return true;
275 }
276 
277 bool VrfEntry::RouteTableDeleted(uint8_t table_type) const {
278  return (rt_table_delete_bmap_ & (1 << table_type));
279 }
280 
281 void VrfEntry::SetRouteTableDeleted(uint8_t table_type) {
282  rt_table_delete_bmap_ |= (1 << table_type);
283 }
284 
285 AgentRouteTable *VrfEntry::GetRouteTable(uint8_t table_type) const {
286  return (RouteTableDeleted(table_type) ? NULL : rt_table_db_[table_type]);
287 }
288 
289 const std::string VrfEntry::GetTableTypeString(uint8_t table_type) const {
290  switch (table_type) {
291  case Agent::INET4_UNICAST: {
292  return "inet4_unicast";
293  break;
294  }
295  case Agent::INET4_MPLS: {
296  return "inet4_mpls";
297  break;
298  }
299  case Agent::INET6_UNICAST: {
300  return "inet6_unicast";
301  break;
302  }
303  case Agent::INET4_MULTICAST: {
304  return "inet4_multicast";
305  break;
306  }
307  case Agent::BRIDGE: {
308  return "bridge";
309  break;
310  }
311  case Agent::EVPN: {
312  return "evpn";
313  break;
314  }
315  }
316  return "None";
317 }
318 
321 }
322 
325 }
328 }
329 
331  return GetRouteTable(Agent::EVPN);
332 }
333 
336 }
337 
340 }
341 
342 bool VrfEntry::DBEntrySandesh(Sandesh *sresp, std::string &name) const {
343  VrfListResp *resp = static_cast<VrfListResp *>(sresp);
344 
345  if (name.empty() || GetName().find(name) != string::npos) {
346  VrfSandeshData data;
347  data.set_name(GetName());
348  data.set_ucindex(vrf_id());
349  data.set_mcindex(vrf_id());
350  data.set_evpnindex(vrf_id());
351  data.set_l2index(vrf_id());
352  data.set_brindex(vrf_id());
353  data.set_uc6index(vrf_id());
354  std::string vrf_flags;
355  if (flags() & VrfData::ConfigVrf)
356  vrf_flags += "Config; ";
357  if (flags() & VrfData::GwVrf)
358  vrf_flags += "Gateway; ";
359  if (flags() & VrfData::PbbVrf)
360  vrf_flags += "PBB C-Vrf";
361  data.set_source(vrf_flags);
362  if (vn_.get()) {
363  data.set_vn(vn_->GetName());
364  } else {
365  data.set_vn("N/A");
366  }
367  data.set_table_label(table_label());
368  VrfTable *table = static_cast<VrfTable *>(get_table());
369  stringstream rd;
370  rd << table->agent()->compute_node_ip().to_string() << ":" <<
371  RDInstanceId(table->agent()->tor_agent_enabled());
372  data.set_RD(rd.str());
373 
374  std::vector<VrfSandeshData> &list =
375  const_cast<std::vector<VrfSandeshData>&>(resp->get_vrf_list());
376  data.set_vxlan_id(vxlan_id_);
377  data.set_mac_aging_time(mac_aging_time_);
378  data.set_layer2_control_word(layer2_control_word_);
379  if (forwarding_vrf_.get()) {
380  data.set_forwarding_vrf(forwarding_vrf_->name_);
381  }
382  data.set_hbf_rintf(hbf_rintf());
383  data.set_hbf_lintf(hbf_lintf());
384  list.push_back(data);
385  return true;
386  }
387 
388  return false;
389 }
390 
392  VrfObjectLogInfo vrf;
393  string str;
394  switch (event) {
395  case AgentLogEvent::ADD:
396  str.assign("Addition ");
397  break;
398  case AgentLogEvent::DEL:
399  str.assign("Deletion ");
400  break;
401  case AgentLogEvent::CHANGE:
402  str.assign("Modification ");
403  break;
404  case AgentLogEvent::DELETE_TRIGGER:
405  str.assign("Deletion Triggered ");
406  break;
407  default:
408  str.assign("");
409  break;
410  }
411  vrf.set_event(str);
412  vrf.set_name(name_);
413  vrf.set_index(id_);
414  VRF_OBJECT_LOG_LOG("AgentVrf", SandeshLevel::SYS_INFO, vrf);
415 }
416 
418  uint32_t num_routes = 0;
419  for (uint8_t type = (Agent::INVALID + 1);
421  type++) {
422  num_routes += rt_table_db_[type]->Size();
423  }
424  if (num_routes) {
425  std::ostringstream str;
426  str << "Unicast routes: " << rt_table_db_[Agent::INET4_UNICAST]->Size();
427  str << "Unicast MPLS routes: " << rt_table_db_[Agent::INET4_MPLS]->Size();
428  str << " Mutlicast routes: " << rt_table_db_[Agent::INET4_MULTICAST]->Size();
429  str << " EVPN routes: " << rt_table_db_[Agent::EVPN]->Size();
430  str << " Bridge routes: " << rt_table_db_[Agent::BRIDGE]->Size();
431  str << "Unicast v6 routes: " << rt_table_db_[Agent::INET6_UNICAST]->Size();
432  str << " Reference: " << GetRefCount();
433  OPER_TRACE_ENTRY(Vrf, static_cast<const AgentDBTable *>(get_table()),
434  "VRF delete failed, " + str.str(), name_);
435  assert(0);
436  return false;
437  }
438 
439  // if number of routes is 0, and VRF ref count is non zero
440  // then only reschedule delete timout
442  OPER_TRACE_ENTRY(Vrf, static_cast<const AgentDBTable *>(get_table()),
443  "VRF delete failed with max retries", name_);
444  assert(0);
445  return false;
446  }
447  retries_ = retries_+1;
448  return true;
449 }
450 
452  Agent *agent = (static_cast<VrfTable *>(get_table()))->agent();
454  *(agent->event_manager())->io_service(),
455  "VrfDeleteTimer");
457  boost::bind(&VrfEntry::DeleteTimeout,
458  this));
459 }
460 
463 }
464 
466  delete_reuse_mutex_.lock();
467  if (deleted_ == true) {
468  delete_reuse_mutex_.unlock();
469  return false;
470  }
471  if (AllRouteTablesEmpty()) {
472  if (!AllRouteTableDeleted() ||
473  deleter_->HasRefcount() ||
474  deleter_->HasDependents()) {
475  delete_reuse_mutex_.unlock();
476  return false;
477  }
478  if (route_resync_walker_.get() != NULL) {
479  if (route_resync_walker_.get()->refcount() > 1 ||
480  route_resync_walker_.get()->IsValidDeleteWalkRef() ||
481  route_resync_walker_.get()->IsValidVrfWalkRef() ||
482  route_resync_walker_.get()->IsDeregisterDone() == false) {
483  delete_reuse_mutex_.unlock();
484  return false;
485  }
486  }
487  ClearDelete();
488  delete_reuse_mutex_.unlock();
492  deleter_.reset(new DeleteActor(this));
494  VrfTable *table = static_cast<VrfTable *>(get_table());
495  Agent *agent = table->agent();
496  route_resync_walker_.reset(new AgentRouteResync("VrfRouteResyncWalker",
497  agent));
498  agent->oper_db()->agent_route_walk_manager()->
499  RegisterWalker(static_cast<AgentRouteWalker *>
500  (route_resync_walker_.get()));
501  SetNotify();
502  table->VrfReuse(GetName());
503  vrf_node_ptr_ = NULL;
504  retries_ = 0;
507 
508  OPER_TRACE_ENTRY(Vrf, static_cast<const AgentDBTable *>(get_table()),
509  "Reset Vrf Deletion", GetName());
510  return true;
511  }
512  delete_reuse_mutex_.unlock();
513  return false;
514 }
515 
517  (static_cast<AgentRouteResync *>(route_resync_walker_.get()))->
518  UpdateRoutesInVrf(this);
519 }
520 
521 // Used to decide RD to be sent to CN for this VRF.
522 // In non tor-agent case vrf-id generated is used.
523 // However in tor-agent vn id(network-id) is used. This is because both active
524 // and backup TA can publish same route which will be sent to BGP router peered
525 // to CN. If both these TA end up generating different vrf-id for same Vrf, then
526 // RD using vrf_id will be different. Hence BGP router will get same route with
527 // two different RD causing undefined behavior.
528 // To avoid this both TA should generate same RD. As VN id is generated by config
529 // it is unique and common across both TA so same can be used.
530 int VrfEntry::RDInstanceId(bool tor_agent_enabled) const {
531  if (tor_agent_enabled == false) {
532  return id_;
533  }
534 
535  if (vn() == NULL)
536  return kInvalidIndex;
537 
538  if (vn()->vnid() == 0)
539  return kInvalidIndex;
540 
541  return vn()->vnid();
542 }
543 
545  if (AllRouteTablesEmpty() == false)
546  return;
547 
548  // Enqueue a DB Request to notify the entry, entry should always be
549  // notified in db::DBTable task context
551  req.key = GetDBRequestKey();
552  (static_cast<VrfTable *>(get_table()))->Enqueue(&req);
553 }
554 
556  for (uint8_t type = (Agent::INVALID + 1);
558  type++) {
559  if (rt_table_db_[type]->empty() == false) {
560  return false;
561  }
562  }
563  return true;
564 }
565 
567  if (route_resync_walker_.get() != NULL) {
568  VrfTable *table = static_cast<VrfTable *>(get_table());
569  table->agent()->oper_db()->agent_route_walk_manager()->
571  }
572 }
573 
576  if (addr.is_v4())
577  return static_cast<InetUnicastAgentRouteTable *>
579  return static_cast<InetUnicastAgentRouteTable *>
581 }
582 
584  VrfTable *table = static_cast<VrfTable *>(get_table());
585  if (vrf_node_ptr_) {
586  IFMapDependencyManager *dep = table->agent()->
587  oper_db()->dependency_manager();
588  IFMapNodeState *state = vrf_node_ptr_.get();
589  dep->SetNotify(state->node(), true);
590  }
591 }
592 
594 public:
595  VrfDeleteWalker(const std::string &name, Agent *agent) :
596  AgentRouteWalker(name, agent) {
597  }
598 
600 
601  //Override vrf notification
604  req.key = e->GetDBRequestKey();
605  (static_cast<VrfTable *>(e->get_table()))->Process(req);
606  return true;
607  }
608 
609  //Override route notification
611  assert(0);
612  return false;
613  }
614 
615  static void WalkDone(VrfDeleteWalker *walker) {
616  walker->mgr()->ReleaseWalker(walker);
617  walker->agent()->vrf_table()->reset_vrf_delete_walker();
618  }
619 
620 private:
621 };
622 
623 void VrfTable::FreeVrfId(size_t index) {
625  index_table_.Remove(index);
626 };
628  if (route_delete_walker_.get())
631  if (vrf_delete_walker_.get() != NULL)
634 }
635 
636 std::unique_ptr<DBEntry> VrfTable::AllocEntry(const DBRequestKey *k) const {
637  const VrfKey *key = static_cast<const VrfKey *>(k);
638  VrfEntry *vrf = new VrfEntry(key->name_, 0, agent());
639  return std::unique_ptr<DBEntry>(static_cast<DBEntry *>(vrf));
640 }
641 
643 }
644 
646  VrfKey *key = static_cast<VrfKey *>(req->key.get());
647  VrfData *data = static_cast<VrfData *>(req->data.get());
648  VrfEntry *vrf = new VrfEntry(key->name_, data->flags_, agent());
649 
650  // Add VRF into name based tree
651  if (FindVrfFromName(key->name_)) {
652  delete vrf;
653  assert(0);
654  return NULL;
655  }
656  if (vrf) {
658  agent()->resource_manager(), key->name_));
659  vrf->id_ = static_cast<IndexResourceData *>(agent()->resource_manager()->
660  Allocate(rkey).get())->index();
661  index_table_.InsertAtIndex(vrf->id_, vrf);
662  }
663  name_tree_.insert( VrfNamePair(key->name_, vrf));
664 
665  vrf->vn_.reset(agent()->vn_table()->Find(data->vn_uuid_));
666  if (vrf->vn_) {
667  vrf->set_routing_vrf(vrf->vn_->vxlan_routing_vn());
668  }
669 
670  vrf->si_vn_ref_.reset(agent()->vn_table()->Find(data->si_vn_ref_uuid_));
671 
672  vrf->isid_ = data->isid_;
673  vrf->bmac_vrf_name_ = data->bmac_vrf_name_;
675  vrf->mac_aging_time_ = data->mac_aging_time_;
676  vrf->set_hbf_rintf(data->hbf_rintf_);
677  vrf->set_hbf_lintf(data->hbf_lintf_);
678  if (vrf->vn_.get()) {
679  vrf->layer2_control_word_ = vrf->vn_->layer2_control_word();
680  }
681  vrf->set_rd(vrf->RDInstanceId(agent()->tor_agent_enabled()));
682  if (data->forwarding_vrf_name_ != Agent::NullString()) {
684  }
685  return vrf;
686 }
687 
688 bool VrfTable::OperDBOnChange(DBEntry *entry, const DBRequest *req) {
689  bool ret = false;
690  VrfEntry *vrf = static_cast<VrfEntry *>(entry);
691  VrfData *data = static_cast<VrfData *>(req->data.get());
692  vrf->set_flags(data->flags_);
693 
694  if (vrf->are_flags_set(VrfData::PbbVrf)) {
695  if (FindVrfFromName(vrf->bmac_vrf_name_) == NULL) {
696  assert(0);
697  }
698  }
699 
700  VnEntry *vn = agent()->vn_table()->Find(data->vn_uuid_);
701  bool resync_routes = false;
702 
703  if (vn != vrf->vn_.get()) {
704  resync_routes = true;
705  vrf->vn_.reset(vn);
706  ret = true;
707  }
708 
709  VnEntry *si_vn_ref = agent()->vn_table()->Find(data->si_vn_ref_uuid_);
710  if (si_vn_ref != vrf->si_vn_ref_.get()) {
711  vrf->si_vn_ref_.reset(si_vn_ref);
712  }
713 
714  if (data->ifmap_node() && vrf->ifmap_node() != data->ifmap_node()) {
715  ret = true;
716  }
717 
718  bool layer2_control_word = false;
719  if (vn) {
720  layer2_control_word = vn->layer2_control_word();
721  }
722 
723  if (vrf->layer2_control_word_ != layer2_control_word) {
724  vrf->layer2_control_word_ = layer2_control_word;
725  vrf->ResyncRoutes();
726  ret = true;
727  }
728 
729  if (vrf->learning_enabled_ != data->learning_enabled_) {
731  ret = true;
732  }
733 
734  if (vrf->isid_ != data->isid_) {
735  vrf->isid_ = data->isid_;
736  ret = true;
737  }
738 
739  if (vrf->rd() != vrf->RDInstanceId(agent()->tor_agent_enabled())) {
740  resync_routes = true;
741  vrf->set_rd(vrf->RDInstanceId(agent()->tor_agent_enabled()));
742  ret = true;
743  }
744 
745  if (resync_routes) {
746  vrf->ResyncRoutes();
747  }
748 
749  uint32_t vxlan_id = VxLanTable::kInvalidvxlan_id;
750  if (vn) {
751  vxlan_id = vn->GetVxLanId();
752  }
753  vrf->UpdateVxlanId(agent(), vxlan_id);
754 
755  if (data && vrf->mac_aging_time_ != data->mac_aging_time_) {
756  vrf->mac_aging_time_ = data->mac_aging_time_;
757  }
758 
759  VrfEntry *forwarding_vrf = NULL;
760  if (data->forwarding_vrf_name_ != Agent::NullString()) {
761  forwarding_vrf = FindVrfFromName(data->forwarding_vrf_name_);
762  }
763 
764  if (forwarding_vrf != vrf->forwarding_vrf_) {
765  vrf->forwarding_vrf_ = forwarding_vrf;
766  ret = true;
767  }
768 
769  if (vrf->hbf_rintf() != data->hbf_rintf_) {
770  vrf->set_hbf_rintf(data->hbf_rintf_);
771  ret = true;
772  }
773  if (vrf->hbf_lintf() != data->hbf_lintf_) {
774  vrf->set_hbf_lintf(data->hbf_lintf_);
775  ret = true;
776  }
777 
778  return ret;
779 }
780 
781 bool VrfTable::OperDBDelete(DBEntry *entry, const DBRequest *req) {
782  VrfEntry *vrf = static_cast<VrfEntry *>(entry);
783  VrfData *data = static_cast<VrfData *>(req->data.get());
784 
785  // VRF can be created by both config and VGW. VRF cannot be deleted till
786  // both config and VGW delete it.
787  // We want to retain flags like PbbVrf, hence mask only flags which
788  // are needed to delete the VRF
789  vrf->flags_ &= ~(data->flags_ & data->ConfigFlags());
790  if ((vrf->flags_ & data->ConfigFlags()) != 0)
791  return false;
792 
793  // Delete the L2 Receive routes added by default
794  BridgeAgentRouteTable *l2_table = static_cast<BridgeAgentRouteTable *>
795  (vrf->rt_table_db_[Agent::BRIDGE]);
796  l2_table->Delete(agent()->local_vm_peer(), vrf->GetName(),
797  agent()->vrrp_mac(), 0);
798  l2_table->Delete(agent()->local_peer(), vrf->GetName(),
799  agent()->left_si_mac(), -1);
800  l2_table->Delete(agent()->local_peer(), vrf->GetName(),
801  agent()->right_si_mac(), -1);
802  const VmInterface *vhost = dynamic_cast<const VmInterface *>
803  (agent()->vhost_interface());
804  if (vhost && vhost->parent_list().empty() == false) {
805  for (size_t i = 0; i < vhost->parent_list().size(); i++) {
806  l2_table->Delete(agent()->local_vm_peer(), vrf->GetName(),
807  vhost->parent_list()[i]->mac(), 0);
808  }
809  }
810 
811  if (agent()->isVmwareMode()) {
812  PhysicalInterfaceKey key(agent()->params()->vmware_physical_port());
813  Interface *intf = static_cast<Interface *>
814  (agent()->interface_table()->FindActiveEntry(&key));
815  if (intf) {
816  l2_table->Delete(agent()->local_vm_peer(), vrf->GetName(),
817  intf->mac(), 0);
818  }
819  }
820 
822  vrf->vn_.reset(NULL);
823  if (vrf->table_label() != MplsTable::kInvalidLabel) {
824  vrf->nh_.reset();
826  }
827  vrf->deleter_->Delete();
828  vrf->StartDeleteTimer();
829  vrf->SendObjectLog(AgentLogEvent::DELETE_TRIGGER);
830 
831 
832  if (vrf->ifmap_node()) {
834  vrf->vrf_node_ptr_ = dep->SetState(vrf->ifmap_node());
835  dep->SetNotify(vrf->ifmap_node(), false);
836  }
837  vrf->ReleaseWalker();
838 
839  return true;
840 }
841 
842 void VrfTable::VrfReuse(const std::string name) {
843  IFMapTable::RequestKey req_key;
844  req_key.id_type = "routing-instance";
845  req_key.id_name = name;
847 
848  if (!node || node->IsDeleted()) {
849  return;
850  }
851 
852  OPER_TRACE(Vrf, "Resyncing configuration for VRF: ", name);
853  agent()->config_manager()->NodeResync(node);
854 }
855 
857  VrfEntry *vrf = static_cast<VrfEntry *>(e);
858  tbb::mutex::scoped_lock lock(vrf->delete_reuse_mutex_);
859  if (e->IsDeleted()) {
860  vrf->DeleteRouteTables();
861  name_tree_.erase(vrf->GetName());
862  vrf->CancelDeleteTimer();
863  vrf->deleted_ = true;
864  }
865 }
866 
867 DBTableBase *VrfTable::CreateTable(DB *db, const std::string &name) {
868  vrf_table_ = new VrfTable(db, name);
869  vrf_table_->Init();
870  return vrf_table_;
871 };
872 
873 VrfEntry *VrfTable::FindVrfFromName(const string &name) {
874  VrfNameTree::const_iterator it;
875 
876  it = name_tree_.find(name);
877  if (it == name_tree_.end()) {
878  return NULL;
879  }
880 
881  return static_cast<VrfEntry *>(it->second);
882 }
883 
885  VrfEntry *vrf = index_table_.At(index);
886  if (vrf && vrf->IsDeleted() == false) {
887  return vrf;
888  }
889  return NULL;
890 }
891 
893  VrfEntry *vrf = index_table_.At(index);
894  return vrf;
895 }
896 
898  (const string &vrf_name) {
899  return static_cast<InetUnicastAgentRouteTable *>
900  (GetRouteTable(vrf_name, Agent::INET4_UNICAST));
901 }
902 
904  (const string &vrf_name) {
905  return static_cast<InetUnicastAgentRouteTable *>
906  (GetRouteTable(vrf_name, Agent::INET4_MPLS));
907 }
908 
910  return GetRouteTable(vrf_name, Agent::INET4_MULTICAST);
911 }
912 
914  return GetRouteTable(vrf_name, Agent::EVPN);
915 }
916 
918  return GetRouteTable(vrf_name, Agent::BRIDGE);
919 }
920 
922  (const string &vrf_name) {
923  return static_cast<InetUnicastAgentRouteTable *>
924  (GetRouteTable(vrf_name, Agent::INET6_UNICAST));
925 }
926 
927 AgentRouteTable *VrfTable::GetRouteTable(const string &vrf_name,
928  uint8_t table_type) {
929  VrfDbTree::const_iterator it;
930 
931  it = dbtree_[table_type].find(vrf_name);
932  if (it == dbtree_[table_type].end()) {
933  return NULL;
934  }
935 
936  return static_cast<AgentRouteTable *>(it->second);
937 }
938 
939 void VrfTable::CreateVrfReq(const string &name, uint32_t flags) {
941  req.key.reset(new VrfKey(name));
942  req.data.reset(new VrfData(agent(), NULL, flags, boost::uuids::nil_uuid(),
943  0, "", 0, false));
944  Enqueue(&req);
945 }
946 
947 void VrfTable::CreateVrfReq(const string &name,
948  const boost::uuids::uuid &vn_uuid,
949  uint32_t flags) {
951  req.key.reset(new VrfKey(name));
952  req.data.reset(new VrfData(agent(), NULL, flags, vn_uuid,
953  0, "", 0, false));
954  Enqueue(&req);
955 }
956 
957 void VrfTable::CreateVrf(const string &name, const boost::uuids::uuid &vn_uuid,
958  uint32_t flags, uint32_t isid,
959  const std::string &bmac_vrf_name,
960  uint32_t aging_timeout,
961  bool learning_enabled) {
963  req.key.reset(new VrfKey(name));
964  req.data.reset(new VrfData(agent(), NULL, flags, vn_uuid, isid,
965  bmac_vrf_name, aging_timeout,
966  learning_enabled));
967  Process(req);
968 }
969 
970 void VrfTable::CreateVrf(const string &name,
971  const boost::uuids::uuid &vn_uuid,
972  uint32_t flags) {
974  req.key.reset(new VrfKey(name));
975  req.data.reset(new VrfData(agent(), NULL, flags, vn_uuid, 0,
976  "", 0, false));
977  Process(req);
978 }
979 void VrfTable::DeleteVrfReq(const string &name, uint32_t flags) {
981  req.key.reset(new VrfKey(name));
982  req.data.reset(new VrfData(agent(), NULL, flags, boost::uuids::nil_uuid(),
983  0, "", 0, false));
984  Enqueue(&req);
985 }
986 
987 void VrfTable::DeleteVrf(const string &name, uint32_t flags) {
989  req.key.reset(new VrfKey(name));
990  req.data.reset(new VrfData(agent(), NULL, flags, boost::uuids::nil_uuid(),
991  0, "", 0, false));
992  Process(req);
993 }
994 
995 void VrfTable::CreateStaticVrf(const string &name) {
996  static_vrf_set_.insert(name);
997  CreateVrf(name, boost::uuids::nil_uuid(), VrfData::ConfigVrf);
998 }
999 
1000 void VrfTable::CreateFabricPolicyVrf(const string &name) {
1001  static_vrf_set_.insert(name);
1003  req.key.reset(new VrfKey(name));
1004  VrfData *data = new VrfData(agent(), NULL, VrfData::ConfigVrf,
1005  boost::uuids::nil_uuid(), 0, "", 0, false);
1007  req.data.reset(data);
1008  Process(req);
1009 }
1010 
1011 void VrfTable::DeleteStaticVrf(const string &name) {
1012  static_vrf_set_.erase(name);
1013  DeleteVrfReq(name);
1014 }
1015 
1016 void VrfTable::DeleteFromDbTree(int table_type, const std::string &vrf_name) {
1017  dbtree_[table_type].erase(vrf_name);
1018 }
1019 
1020 void VrfTable::Input(DBTablePartition *partition, DBClient *client,
1021  DBRequest *req) {
1022 
1023  VrfKey *key = static_cast<VrfKey *>(req->key.get());
1024  VrfEntry *entry = static_cast<VrfEntry *>(partition->Find(key));
1025 
1026  if (entry && entry->IsDeleted()) {
1027  if (req->oper != DBRequest::DB_ENTRY_NOTIFY) {
1028  OPER_TRACE(Vrf, "VRF pending delete, Ignoring DB operation for ",
1029  entry->GetName());
1030  return;
1031  } else {
1032  // Allow DB Operation for DB Entry Notify, along with
1033  // validation for sub op as ADD_DEL_CHANGE
1034  AgentKey *key = static_cast<AgentKey *>(req->key.get());
1035  assert(key->sub_op_ == AgentKey::ADD_DEL_CHANGE);
1036  }
1037  }
1038 
1039  AgentDBTable::Input(partition, client, req);
1040  return;
1041 }
1042 
1043 static void FindHbfInterfacesFromHBS(Agent* agent, IFMapNode *node,
1044  uint32_t &hbf_rintf, uint32_t &hbf_lintf) {
1045  IFMapAgentTable *table = static_cast<IFMapAgentTable *>(node->table());
1046  DBGraph *graph = table->GetGraph();
1047 
1048  for (DBGraphVertex::edge_iterator iter = node->edge_list_begin(graph);
1049  iter != node->edge_list_end(graph); ++iter) {
1050  if (iter->IsDeleted()) {
1051  continue;
1052  }
1053  IFMapNode *adj_node = static_cast<IFMapNode *>(iter.target());
1054 
1055  if (!strcmp(adj_node->table()->Typename(),
1056  "host-based-service-virtual-network")) {
1057  autogen::HostBasedServiceVirtualNetwork *hbsvn =
1058  static_cast<HostBasedServiceVirtualNetwork *>
1059  (adj_node->GetObject());
1060  ServiceVirtualNetworkType type = hbsvn->data();
1061 
1063  adj_node->begin(graph);
1064  iter != node->end(graph); ++iter) {
1065  IFMapNode *hbsvn_adj_node =
1066  static_cast<IFMapNode *>(iter.operator->());
1067  if (!strcmp(hbsvn_adj_node->table()->Typename(),
1068  "virtual-network")) {
1070  hbsvn_adj_node->begin(graph);
1071  iter != node->end(graph); ++iter) {
1072  if (iter->IsDeleted()) {
1073  continue;
1074  }
1075  IFMapNode *vmi_node =
1076  static_cast<IFMapNode *>(iter.operator->());
1077  if (!strcmp(vmi_node->table()->Typename(),
1078  "virtual-machine-interface")) {
1079  VirtualMachineInterface *cfg =
1080  static_cast <VirtualMachineInterface *>
1081  (vmi_node->GetObject());
1082  autogen::IdPermsType id_perms = cfg->id_perms();
1084  CfgUuidSet(id_perms.uuid.uuid_mslong,
1085  id_perms.uuid.uuid_lslong, u);
1086  InterfaceConstRef intf =
1087  agent->interface_table()->FindVmi(u);
1088  if (!intf) {
1089  continue;
1090  }
1091  if (!strcmp(type.virtual_network_type.c_str(),
1092  "right")) {
1093  hbf_rintf = intf->id();
1094  } else if (!strcmp(
1095  type.virtual_network_type.c_str(), "left")) {
1096  hbf_lintf = intf->id();
1097  }
1098  }
1099  }
1100  }
1101  }
1102  }
1103  }
1104 }
1105 
1107  uint32_t &hbf_rintf, uint32_t &hbf_lintf) {
1108  IFMapAgentTable *table = static_cast<IFMapAgentTable *>(node->table());
1109  DBGraph *graph = table->GetGraph();
1110 
1111  for (DBGraphVertex::adjacency_iterator iter = node->begin(graph);
1112  iter != node->end(graph); ++iter) {
1113  if (iter->IsDeleted()) {
1114  continue;
1115  }
1116  IFMapNode *adj_node =
1117  static_cast<IFMapNode *>(iter.operator->());
1118 
1119  if (strcmp(adj_node->table()->Typename(), "host-based-service") == 0) {
1120  FindHbfInterfacesFromHBS(agent, adj_node, hbf_rintf, hbf_lintf);
1121  break;
1122  }
1123  }
1124 }
1125 
1126 static void FindHbfInterfacesFromVmi(Agent* agent, IFMapNode *node,
1127  uint32_t &hbf_rintf, uint32_t &hbf_lintf) {
1128  IFMapAgentTable *table = static_cast<IFMapAgentTable *>(node->table());
1129  DBGraph *graph = table->GetGraph();
1130 
1131  for (DBGraphVertex::adjacency_iterator iter = node->begin(graph);
1132  iter != node->end(graph); ++iter) {
1133  if (iter->IsDeleted()) {
1134  continue;
1135  }
1136  IFMapNode *adj_node =
1137  static_cast<IFMapNode *>(iter.operator->());
1138 
1139  if (strcmp(adj_node->table()->Typename(), "project") == 0) {
1140  FindHbfInterfacesFromProject(agent, adj_node, hbf_rintf, hbf_lintf);
1141  break;
1142  }
1143  }
1144 }
1145 
1146 static void FindHbfInterfaces(Agent *agent, IFMapNode *vn_node,
1147  uint32_t &hbf_rintf, uint32_t &hbf_lintf) {
1148  IFMapAgentTable *table = static_cast<IFMapAgentTable *>(vn_node->table());
1149  DBGraph *graph = table->GetGraph();
1150 
1151  for (DBGraphVertex::adjacency_iterator iter = vn_node->begin(graph);
1152  iter != vn_node->end(graph); ++iter) {
1153  if (iter->IsDeleted()) {
1154  continue;
1155  }
1156  IFMapNode *adj_node =
1157  static_cast<IFMapNode *>(iter.operator->());
1158 
1159  if (strcmp(adj_node->table()->Typename(),
1160  "virtual-machine-interface") == 0) {
1161  FindHbfInterfacesFromVmi(agent, adj_node, hbf_rintf, hbf_lintf);
1162  break;
1163  }
1164  }
1165 }
1166 
1167 static void BuildForwardingVrf(Agent *agent, IFMapNode *vn_node,
1168  std::string &forwarding_vrf_name) {
1169  IFMapAgentTable *table = static_cast<IFMapAgentTable *>(vn_node->table());
1170  DBGraph *graph = table->GetGraph();
1171  for (DBGraphVertex::adjacency_iterator iter = vn_node->begin(graph);
1172  iter != vn_node->end(graph); ++iter) {
1173  IFMapNode *adj_node =
1174  static_cast<IFMapNode *>(iter.operator->());
1175  if (iter->IsDeleted() ||
1176  (adj_node->table() != agent->cfg()->cfg_vn_table())) {
1177  continue;
1178  }
1179 
1180  VirtualNetwork *cfg =
1181  static_cast <VirtualNetwork *> (adj_node->GetObject());
1182  if (cfg == NULL) {
1183  continue;
1184  }
1185 
1186  if (adj_node->name() == agent->fabric_vn_name()) {
1187  forwarding_vrf_name = agent->fabric_vrf_name();
1188  }
1189  }
1190 }
1191 
1192 static VrfData *BuildData(Agent *agent, IFMapNode *node) {
1193  boost::uuids::uuid vn_uuid = boost::uuids::nil_uuid();
1194  boost::uuids::uuid si_vn_uuid = boost::uuids::nil_uuid();
1195  IFMapAgentTable *table = static_cast<IFMapAgentTable *>(node->table());
1196  DBGraph *graph = table->GetGraph();
1197  bool learning_enabled = false;
1198  std::string forwarding_vrf = "";
1199  uint32_t hbf_rintf = Interface::kInvalidIndex;
1200  uint32_t hbf_lintf = Interface::kInvalidIndex;
1201 
1202  uint32_t aging_timeout = 0;
1203  for (DBGraphVertex::adjacency_iterator iter = node->begin(graph);
1204  iter != node->end(graph); ++iter) {
1205  IFMapNode *adj_node =
1206  static_cast<IFMapNode *>(iter.operator->());
1207 
1208  if (iter->IsDeleted() ||
1209  (adj_node->table() != agent->cfg()->cfg_vn_table())) {
1210  continue;
1211  }
1212 
1213  VirtualNetwork *cfg =
1214  static_cast <VirtualNetwork *> (adj_node->GetObject());
1215  if (cfg == NULL) {
1216  continue;
1217  }
1218 
1219  BuildForwardingVrf(agent, adj_node, forwarding_vrf);
1220 
1221  FindHbfInterfaces(agent, adj_node, hbf_rintf, hbf_lintf);
1222 
1223  if (!IsVRFServiceChainingInstance(adj_node->name(), node->name())) {
1224  autogen::IdPermsType id_perms = cfg->id_perms();
1225  CfgUuidSet(id_perms.uuid.uuid_mslong, id_perms.uuid.uuid_lslong,
1226  vn_uuid);
1227  aging_timeout = cfg->mac_aging_time();
1228  break;
1229  } else {
1230  autogen::IdPermsType id_perms = cfg->id_perms();
1231  CfgUuidSet(id_perms.uuid.uuid_mslong, id_perms.uuid.uuid_lslong,
1232  si_vn_uuid);
1233  break;
1234  }
1235  }
1236 
1237  VrfData *vrf_data = new VrfData(agent, node, VrfData::ConfigVrf,
1238  vn_uuid, 0, "",
1239  aging_timeout, learning_enabled,
1240  hbf_rintf, hbf_lintf);
1241  if (node->name() == agent->fabric_policy_vrf_name()) {
1242  vrf_data->forwarding_vrf_name_ = agent->fabric_vrf_name();
1243  } else {
1244  vrf_data->forwarding_vrf_name_ = forwarding_vrf;
1245  }
1246 
1247  vrf_data->si_vn_ref_uuid_ = si_vn_uuid;
1248 
1249  return vrf_data;
1250 }
1251 
1253  const boost::uuids::uuid &u) {
1254  //Trigger add or delete only for non fabric VRF
1255  if ((req.oper == DBRequest::DB_ENTRY_DELETE) || node->IsDeleted()) {
1256  req.key.reset(new VrfKey(node->name()));
1257  if (IsStaticVrf(node->name())) {
1258  //Fabric and link-local VRF will not be deleted,
1259  //upon config delete
1261  } else {
1263  }
1264 
1265  VrfData *data = new VrfData(agent(), node, VrfData::ConfigVrf,
1266  boost::uuids::nil_uuid(), 0, "", 0, false);
1267  if (node->name() == agent()->fabric_policy_vrf_name()) {
1269  }
1270  req.data.reset(data);
1271  Enqueue(&req);
1272  return false;
1273  }
1274 
1275  agent()->config_manager()->AddVrfNode(node);
1276  return false;
1277 }
1278 
1280  const boost::uuids::uuid &u) {
1281  req.key.reset(new VrfKey(node->name()));
1282 
1283  //Trigger add or delete only for non fabric VRF
1284  if (node->IsDeleted()) {
1285  if (IsStaticVrf(node->name())) {
1286  //Fabric and link-local VRF will not be deleted,
1287  //upon config delete
1289  } else {
1291  }
1292 
1293  VrfData *data = new VrfData(agent(), node, VrfData::ConfigVrf,
1294  boost::uuids::nil_uuid(), 0, "", 0, false,
1297  if (node->name() == agent()->fabric_policy_vrf_name()) {
1299  }
1300  req.data.reset(data);
1301  } else {
1303  req.data.reset(BuildData(agent(), node));
1304  }
1305 
1306  //When VRF config delete comes, first enqueue VRF delete
1307  //so that when link evaluation happens, all point to deleted VRF
1308  Enqueue(&req);
1309  return false;
1310 }
1311 
1312 void VrfListReq::HandleRequest() const {
1313  AgentSandeshPtr sand(new AgentVrfSandesh(context(), get_name()));
1314  sand->DoSandesh(sand);
1315 }
1316 
1318  const std::string &context) {
1319  return AgentSandeshPtr(new AgentVrfSandesh(context,
1320  args->GetString("name")));
1321 }
1322 
1324 public:
1325  RouteDeleteWalker(const std::string &name, Agent *agent) :
1326  AgentRouteWalker(name, agent) {
1327  }
1328 
1330 
1331  //Override route notification
1333  AgentRoute *rt = static_cast<AgentRoute *>(e);
1334  for(Route::PathList::const_iterator it = rt->GetPathList().begin();
1335  it != rt->GetPathList().end(); ) {
1336  const AgentPath *path =
1337  static_cast<const AgentPath *>(it.operator->());
1338  Route::PathList::const_iterator next = ++it;
1339 
1341  req.key = e->GetDBRequestKey();
1342  AgentRouteKey *key = static_cast<AgentRouteKey *>(req.key.get());
1343  key->peer_ = path->peer();
1344  (static_cast<AgentRouteTable *>(e->get_table()))->Process(req);
1345  it = next;
1346  }
1347 
1348  return true;
1349  }
1350 
1351  static void WalkDone(RouteDeleteWalker *walker) {
1352  walk_done_++;
1353  walker->mgr()->ReleaseWalker(walker);
1354  walker->agent()->vrf_table()->reset_route_delete_walker();
1355  }
1356 
1357  static uint32_t walk_start_;
1358  static uint32_t walk_done_;
1359 };
1362 
1364  if (route_delete_walker_.get() == NULL) {
1365  route_delete_walker_ = new RouteDeleteWalker("RouteDeleteWalker",
1366  agent());
1368  RegisterWalker(static_cast<AgentRouteWalker *>
1369  (route_delete_walker_.get()));
1370  }
1371  route_delete_walker_->WalkDoneCallback
1372  (boost::bind(&RouteDeleteWalker::WalkDone,
1373  static_cast<RouteDeleteWalker *>(route_delete_walker_.get())));
1374  route_delete_walker_->StartVrfWalk();
1375 }
1376 
1378  if (vrf_delete_walker_.get() == NULL) {
1379  vrf_delete_walker_ = new VrfDeleteWalker("VrfDeleteWalker",
1380  agent());
1382  RegisterWalker(static_cast<AgentRouteWalker *>
1383  (vrf_delete_walker_.get()));
1384  }
1385  vrf_delete_walker_.get()->WalkDoneCallback(boost::bind
1387  static_cast<VrfDeleteWalker *>( vrf_delete_walker_.get())));
1388  vrf_delete_walker_.get()->StartVrfWalk();
1389 }
int GetVxLanId() const
Definition: vn.cc:727
EntryType At(size_t index) const
Definition: index_vector.h:32
virtual void Destroy()
Definition: vrf.cc:55
static const std::string & GetSuffix(Agent::RouteTableType type)
Definition: agent_route.cc:99
static VrfTable * vrf_table_
Definition: vrf.h:362
uint32_t isid_
Definition: vrf.h:252
bool isVmwareMode() const
Definition: agent.cc:1033
uint32_t rt_table_delete_bmap_
Definition: vrf.h:247
bool UpdateVxlanId(Agent *agent, uint32_t new_vxlan_id)
Definition: vrf.cc:108
boost::uuids::uuid si_vn_ref_uuid_
Definition: vrf.h:76
void VrfReuse(std::string name)
Definition: vrf.cc:842
uint32_t label() const
Definition: mpls.h:79
bool IsVRFServiceChainingInstance(const string &vn_name, const string &vrf_name)
Definition: vn.cc:860
void CreateVrfReq(const string &name, uint32_t flags=VrfData::ConfigVrf)
Definition: vrf.cc:939
uint32_t mac_aging_time_
Definition: vrf.h:79
Agent * agent() const
static void CfgUuidSet(uint64_t ms_long, uint64_t ls_long, boost::uuids::uuid &u)
Definition: agent_cmn.h:67
Definition: vrf.h:86
virtual void Input(DBTablePartition *root, DBClient *client, DBRequest *req)
Definition: vrf.cc:1020
static void Delete(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, uint32_t ethernet_tag)
void CreateVrf(const string &name, const boost::uuids::uuid &vn_uuid, uint32_t flags)
Definition: vrf.cc:970
void CreateFabricPolicyVrf(const string &name)
Definition: vrf.cc:1000
InetUnicastRouteEntry * FindLPM(const IpAddress &ip)
virtual bool MayDelete() const
Definition: vrf.cc:49
AgentRouteTable * GetInet4MulticastRouteTable() const
Definition: vrf.cc:326
boost::uuids::uuid vn_uuid_
Definition: vrf.h:75
static void WalkDone(RouteDeleteWalker *walker)
Definition: vrf.cc:1351
AgentRouteTable * GetEvpnRouteTable() const
Definition: vrf.cc:330
Ip4Address compute_node_ip() const
Definition: agent.h:681
VrfEntry * FindVrfFromIdIncludingDeletedVrf(size_t index)
Definition: vrf.cc:892
Definition: vrf.h:268
virtual bool OperDBDelete(DBEntry *entry, const DBRequest *req)
Definition: vrf.cc:781
bool tor_agent_enabled() const
Definition: agent.h:1164
std::string GetString(const std::string &key) const
static void FindHbfInterfaces(Agent *agent, IFMapNode *vn_node, uint32_t &hbf_rintf, uint32_t &hbf_lintf)
Definition: vrf.cc:1146
VrfEntry * FindVrfFromName(const string &name)
Definition: vrf.cc:873
NextHopTable * nexthop_table() const
Definition: agent.h:475
#define OPER_TRACE(obj,...)
Definition: agent_db.h:229
DBTableBase * get_table() const
Definition: db_entry.cc:119
virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
Definition: vrf.cc:1252
const std::string & vmware_physical_port() const
Definition: agent_param.h:332
AgentRouteTable * GetEvpnRouteTable(const std::string &vrf_name)
Definition: vrf.cc:913
VrfEntryRef forwarding_vrf_
Definition: vrf.h:258
DBEntry * Find(const DBEntry *entry)
Agent supports multiple route tables - Inet-unicast (IPv4/IPv6), Inet-multicast, bridge, EVPN (Type2/Type5). This base class contains common code for all types of route tables.
Definition: agent_route.h:109
virtual ~DeleteActor()
Definition: vrf.cc:47
void DeleteRoutes()
Definition: vrf.cc:1363
virtual std::unique_ptr< DBEntry > AllocEntry(const DBRequestKey *k) const
Definition: vrf.cc:636
bool layer2_control_word_
Definition: vrf.h:256
DBTableBase * CreateTable(const std::string &name)
Definition: db.cc:99
void Release(KeyPtr key)
uint32_t table_label() const
Definition: vrf.h:117
bool DeleteTimeout()
Definition: vrf.cc:417
const Interface * vhost_interface() const
Definition: agent.h:935
DeleteActor(VrfEntry *vrf)
Definition: vrf.cc:43
static uint32_t walk_start_
Definition: vrf.cc:1357
void DeleteVrf(const string &name, uint32_t flags=VrfData::ConfigVrf)
Definition: vrf.cc:987
bool IsDeleted() const
Definition: db_entry.h:49
bool RouteTableDeleted(uint8_t table_type) const
Definition: vrf.cc:277
void AddVrfNode(IFMapNode *node)
ConfigManager * config_manager() const
Definition: agent.cc:889
bool learning_enabled_
Definition: vrf.h:80
bool deleted_
Definition: vrf.h:264
boost::asio::ip::address IpAddress
Definition: address.h:13
static const MacAddress & vrrp_mac()
Definition: agent.h:439
uint8_t sub_op_
Definition: agent_db.h:106
static void FindHbfInterfacesFromHBS(Agent *agent, IFMapNode *node, uint32_t &hbf_rintf, uint32_t &hbf_lintf)
Definition: vrf.cc:1043
void set_flags(uint32_t flags)
Definition: vrf.h:109
uint32_t retries_
Definition: vrf.h:261
Agent * agent() const
Definition: agent_db.h:213
VrfNameTree name_tree_
Definition: vrf.h:364
static void BuildForwardingVrf(Agent *agent, IFMapNode *vn_node, std::string &forwarding_vrf_name)
Definition: vrf.cc:1167
bool l2_
Definition: vrf.h:257
static VrfData * BuildData(Agent *agent, IFMapNode *node)
Definition: vrf.cc:1192
std::unique_ptr< DBRequestData > data
Definition: db_table.h:49
boost::shared_ptr< ResourceKey > KeyPtr
virtual const char * Typename() const =0
virtual void OnZeroRefcount(AgentDBEntry *e)
Definition: vrf.cc:856
InetUnicastAgentRouteTable * GetInet4UnicastRouteTable() const
Definition: vrf.cc:319
AgentDBEntry * FindActiveEntry(const DBEntry *key)
Definition: agent_db.cc:110
InterfaceTable * interface_table() const
Definition: agent.h:465
bool Enqueue(DBRequest *req)
Definition: db_table.cc:194
boost::uuids::uuid uuid
VnTable * vn_table() const
Definition: agent.h:495
InetUnicastAgentRouteTable * GetInet4MplsUnicastRouteTable() const
Definition: vrf.cc:323
void reset_route_delete_walker()
Definition: vrf.h:355
Definition: vrf.h:41
adjacency_iterator end(DBGraph *graph)
IFMapNode * ifmap_node() const
Definition: oper_db.h:79
InetUnicastAgentRouteTable * GetInet6UnicastRouteTable() const
Definition: vrf.cc:338
const string & GetName() const
Definition: vrf.h:100
const MacAddress & mac() const
Definition: interface.h:131
VrfEntryRef table_
Definition: vrf.cc:61
bool RouteWalkNotify(DBTablePartBase *partition, DBEntryBase *e)
Definition: vrf.cc:1332
IFMapTable * table()
Definition: ifmap_node.h:29
DB * database()
Definition: db_table.h:107
static const MacAddress & left_si_mac()
Definition: agent.h:442
virtual DBEntry * OperDBAdd(const DBRequest *req)
Definition: vrf.cc:645
void DeleteStaticVrf(const string &name)
Definition: vrf.cc:1011
uint32_t id_
Definition: vrf.h:235
static const uint32_t kDeleteTimeout
Definition: vrf.h:89
virtual ~VrfTable()
Definition: vrf.cc:642
bool DBEntrySandesh(Sandesh *sresp, std::string &name) const
Definition: vrf.cc:342
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
virtual void RetryDelete()
Definition: vrf.cc:544
void RemoveTable(DBTableBase *tbl_base)
Definition: db.cc:87
Base class for all Route entries in agent.
Definition: agent_route.h:224
uint32_t GetRefCount() const
Definition: vrf.h:104
const std::string GetTableTypeString(uint8_t table_type) const
Definition: vrf.cc:289
AgentRouteWalkerPtr vrf_delete_walker_
Definition: vrf.h:369
void ReleaseWalker(DBTableWalkRef &walk)
Definition: db_table.cc:619
OperDB * oper_db() const
Definition: agent.cc:1013
InetUnicastAgentRouteTable * GetInet4UnicastRouteTable(const std::string &vrf_name)
Definition: vrf.cc:898
IndexVector< VrfEntry * > index_table_
Definition: vrf.h:363
string bmac_vrf_name_
Definition: vrf.h:251
InterfaceConstRef FindVmi(const boost::uuids::uuid &u)
Definition: interface.cc:419
IFMapDependencyManager * dependency_manager()
Definition: operdb_init.h:61
const uint32_t hbf_rintf() const
Definition: vrf.h:143
const DBGraph * GetGraph() const
void Remove(size_t index)
Definition: index_vector.h:78
const std::string & fabric_vrf_name() const
Definition: agent.h:903
Definition: db.h:24
void PostAdd()
Definition: vrf.cc:168
AgentRouteWalkerPtr route_delete_walker_
Definition: vrf.h:368
virtual size_t Size() const
Definition: db_table.cc:507
void Init()
Definition: db_table.cc:387
void SetRouteTableDeleted(uint8_t table_type)
Definition: vrf.cc:281
virtual bool OperDBOnChange(DBEntry *entry, const DBRequest *req)
Definition: vrf.cc:688
string name_
Definition: vrf.h:38
uint32_t isid_
Definition: vrf.h:77
VrfDbTree dbtree_[Agent::ROUTE_TABLE_MAX]
Definition: vrf.h:365
AgentRouteTable * rt_table_db_[Agent::ROUTE_TABLE_MAX]
Definition: vrf.h:243
VrfEntry * FindVrfFromId(size_t index)
Definition: vrf.cc:884
string name_
Definition: vrf.h:233
static const uint32_t kInvalidvxlan_id
Definition: vxlan.h:141
uint8_t type
Definition: load_balance.h:109
int RDInstanceId(bool tor_agent_enabled) const
Definition: vrf.cc:530
Definition: agent.h:358
virtual void Shutdown()
Definition: vrf.cc:53
std::string bmac_vrf_name_
Definition: vrf.h:78
AgentRouteWalkerManager * agent_route_walk_manager() const
Definition: operdb_init.h:91
Definition: vrf.h:22
InetUnicastAgentRouteTable * GetInetUnicastRouteTable(const IpAddress &addr) const
Definition: vrf.cc:575
void StartDeleteTimer()
Definition: vrf.cc:451
virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, const std::string &context)
Definition: vrf.cc:1317
bool ResetVrfDelete()
Definition: vrf.cc:465
bool are_flags_set(const VrfData::VrfEntryFlags &flags) const
Definition: vrf.h:110
static uint32_t walk_done_
Definition: vrf.cc:1358
InetUnicastAgentRouteTable * GetInet4MplsUnicastRouteTable(const std::string &vrf_name)
Definition: vrf.cc:904
std::unique_ptr< DBRequestKey > key
Definition: db_table.h:48
EventManager * event_manager() const
Definition: agent.h:1103
DBOperation oper
Definition: db_table.h:42
AgentRouteTable * GetBridgeRouteTable(const std::string &vrf_name)
Definition: vrf.cc:917
int vnid() const
Definition: vn.h:208
static const std::string & NullString()
Definition: agent.h:437
const Peer * peer() const
Definition: agent_path.h:263
boost::intrusive_ptr< const Interface > InterfaceConstRef
Definition: agent.h:51
void CreateRouteTables()
Definition: vrf.cc:141
AgentRouteWalkerPtr route_resync_walker_
Definition: vrf.h:249
AgentRouteTable * GetBridgeRouteTable() const
Definition: vrf.cc:334
VrfEntry(const string &name, uint32_t flags, Agent *agent)
Definition: vrf.cc:64
const Peer * local_peer() const
Definition: agent.h:1022
VrfTable(DB *db, const std::string &name)
Definition: vrf.h:283
virtual bool IsLess(const DBEntry &rhs) const
Definition: vrf.cc:99
#define OPER_TRACE_ENTRY(obj, table,...)
Definition: agent_db.h:234
void CreateTableLabel(bool learning_enabled, bool l2, bool flod_unknown_unicast, bool layer2_control_word)
Definition: vrf.cc:118
class boost::shared_ptr< AgentSandesh > AgentSandeshPtr
Definition: agent_db.h:18
AgentRouteWalkerManager * mgr()
const std::string & name() const
Definition: db_table.h:110
AgentDBEntry * Find(const DBEntry *key, bool ret_del)
Definition: agent_db.cc:134
#define MAX_VRF_DELETE_TIMEOUT_RETRY_COUNT
Definition: vrf.cc:34
static DBTableBase * CreateTable(DB *db, const std::string &name)
Definition: vrf.cc:867
virtual ~VrfEntry()
Definition: vrf.cc:79
PeerConstPtr peer_
Definition: agent_route.h:50
void CreateStaticVrf(const string &name)
Definition: vrf.cc:995
virtual void Process(DBRequest &req)
Definition: agent_db.cc:231
AgentParam * params() const
Definition: agent.h:1218
void ClearDelete()
Definition: db_entry.h:48
const uint32_t vrf_id() const
Definition: vrf.h:99
VnEntry * Find(const boost::uuids::uuid &vn_uuid)
Definition: vn.cc:759
virtual KeyPtr GetDBRequestKey() const
Definition: vrf.cc:227
static Timer * CreateTimer(boost::asio::io_context &service, const std::string &name, int task_id=Timer::GetTimerTaskId(), int task_instance=Timer::GetTimerInstanceId(), bool delete_on_completion=false)
Definition: timer.cc:201
const std::string & name() const
Definition: ifmap_node.h:48
VnEntryRef vn_
Definition: vrf.h:237
virtual KeyPtr GetDBRequestKey() const =0
virtual const PrefixType & prefix_address() const
Returns the value of a stored prefix address (IPv4, IPv6 or MAC address)
Definition: agent_route.h:375
bool VrfWalkNotify(DBTablePartBase *partition, DBEntryBase *e)
Definition: vrf.cc:602
IFMapNodePtr SetState(IFMapNode *node)
bool Cancel()
Definition: timer.cc:150
Definition: vn.h:151
IFMapNode * ifmap_node() const
Definition: oper_db.h:59
static const uint32_t kInvalidLabel
Definition: mpls.h:101
VrfTable * vrf_table() const
Definition: agent.h:485
virtual void Clear()
Definition: vrf.cc:627
uint32_t ConfigFlags()
Definition: vrf.h:70
void set_rd(int rd)
Definition: vrf.h:221
IFMapObject * GetObject()
Definition: ifmap_node.cc:63
void reset_vrf_delete_walker()
Definition: vrf.h:356
Definition: mpls.h:99
void ReleaseWalker(AgentRouteWalker *walker)
NextHopRef nh_
Definition: vrf.h:240
~RouteDeleteWalker()
Definition: vrf.cc:1329
void CancelDeleteTimer()
Definition: vrf.cc:461
void DeleteRouteTables()
Definition: vrf.cc:154
static const MacAddress & right_si_mac()
Definition: agent.h:443
boost::scoped_ptr< DeleteActor > deleter_
Definition: vrf.h:242
virtual void SetKey(const DBRequestKey *key)
Definition: vrf.cc:232
uint32_t vxlan_id() const
Definition: vrf.h:165
uint32_t flags_
Definition: vrf.h:74
void FreeVrfId(size_t index)
Definition: vrf.cc:623
static void WalkDone(VrfDeleteWalker *walker)
Definition: vrf.cc:615
LifetimeActor * deleter()
Definition: vrf.cc:264
void Process(DBRequest &req)
Definition: nexthop.cc:367
static const uint32_t kInvalidIndex
Definition: interface.h:70
tbb::atomic< uint32_t > mac_aging_time_
Definition: vrf.h:253
bool learning_enabled_
Definition: vrf.h:255
void DeleteFromDbTree(int table_type, const std::string &vrf_name)
Definition: vrf.cc:1016
bool Start(int time, Handler handler, ErrorHandler error_handler=NULL)
Definition: timer.cc:108
void ReleaseWalker()
Definition: vrf.cc:566
VnEntry * vn() const
Definition: vrf.h:101
RouteDeleteWalker(const std::string &name, Agent *agent)
Definition: vrf.cc:1325
void SendObjectLog(AgentLogEvent::type event) const
Definition: vrf.cc:391
AgentRouteTable * GetInet4MulticastRouteTable(const std::string &vrf_name)
Definition: vrf.cc:909
static void AddBridgeReceiveRoute(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, const std::string &vn_name, const std::string &interface, bool policy)
static IFMapNode * TableEntryLookup(DB *db, RequestKey *key)
static const uint32_t kInvalidIndex
Definition: vrf.h:88
AgentRouteTable * GetRouteTable(uint8_t table_type) const
Definition: vrf.cc:285
edge_iterator edge_list_end(DBGraph *graph)
void DeleteVrfReq(const string &name, uint32_t flags=VrfData::ConfigVrf)
Definition: vrf.cc:979
void SetNotify(IFMapNode *node, bool notfiy_flag)
void Shutdown()
Definition: vrf.cc:1377
bool IsStaticVrf(const std::string &vrf_name) const
Definition: vrf.h:345
bool RouteWalkNotify(DBTablePartBase *partition, DBEntryBase *e)
Definition: vrf.cc:610
const Peer * local_vm_peer() const
Definition: agent.h:1023
IFMapDependencyManager::IFMapNodePtr vrf_node_ptr_
Definition: vrf.h:248
bool layer2_control_word() const
Definition: vn.h:218
IFMapAgentTable * cfg_vn_table() const
Definition: cfg_init.h:26
void ResyncRoutes()
Definition: vrf.cc:516
std::string forwarding_vrf_name_
Definition: vrf.h:81
static void FindHbfInterfacesFromVmi(Agent *agent, IFMapNode *node, uint32_t &hbf_rintf, uint32_t &hbf_lintf)
Definition: vrf.cc:1126
bool AllRouteTablesEmpty() const
Definition: vrf.cc:555
int rd() const
Definition: vrf.h:220
void set_hbf_lintf(uint32_t idx)
Definition: vrf.h:225
void SetNotify()
Definition: vrf.cc:583
pair< string, RouteTable * > VrfDbPair
Definition: vrf.h:281
RouteTableType
Definition: agent.h:415
AgentConfig * cfg() const
Definition: agent.cc:865
VrfDeleteWalker(const std::string &name, Agent *agent)
Definition: vrf.cc:595
tbb::mutex delete_reuse_mutex_
Definition: vrf.h:254
pair< string, VrfEntry * > VrfNamePair
Definition: vrf.h:273
static void FindHbfInterfacesFromProject(Agent *agent, IFMapNode *node, uint32_t &hbf_rintf, uint32_t &hbf_lintf)
Definition: vrf.cc:1106
uint32_t vxlan_id_
Definition: vrf.h:246
friend class VrfEntry
Definition: vrf.h:359
const std::string & fabric_vn_name() const
Definition: agent.h:901
AgentRouteTable * GetRouteTable(const string &vrf_name, uint8_t table_type)
Definition: vrf.cc:927
InetUnicastRouteEntry * GetUcRoute(const IpAddress &addr) const
Definition: vrf.cc:237
void set_table_label(uint32_t label)
Definition: vrf.h:114
uint32_t flags() const
Definition: vrf.h:108
void NodeResync(IFMapNode *node)
adjacency_iterator begin(DBGraph *graph)
InetUnicastAgentRouteTable * GetInet6UnicastRouteTable(const std::string &vrf_name)
Definition: vrf.cc:922
std::set< std::string > static_vrf_set_
Definition: vrf.h:367
Timer * delete_timeout_timer_
Definition: vrf.h:244
~VrfDeleteWalker()
Definition: vrf.cc:599
virtual void Input(DBTablePartition *root, DBClient *client, DBRequest *req)
Definition: agent_db.cc:188
void set_hbf_rintf(uint32_t idx)
Definition: vrf.h:224
InterfaceList parent_list() const
VnEntryRef si_vn_ref_
Definition: vrf.h:239
uint32_t hbf_lintf_
Definition: vrf.h:83
boost::function< void()> WalkDone
virtual string ToString() const
Definition: vrf.cc:104
bool AllRouteTableDeleted() const
Definition: vrf.cc:268
ResourceManager * resource_manager() const
Definition: agent.cc:1021
void set_routing_vrf(bool val)
Definition: vrf.h:222
void SetVrf(VrfEntry *vrf)
Definition: agent_route.cc:126
const uint32_t hbf_lintf() const
Definition: vrf.h:144
edge_iterator edge_list_begin(DBGraph *graph)
static bool DeleteTimer(Timer *Timer)
Definition: timer.cc:222
uint32_t hbf_rintf_
Definition: vrf.h:82
bool ProcessConfig(IFMapNode *node, DBRequest &req, const boost::uuids::uuid &u)
Definition: vrf.cc:1279
size_t InsertAtIndex(uint32_t index, EntryType entry)
Definition: index_vector.h:54
const PathList & GetPathList() const
Definition: route.h:46
uint32_t flags_
Definition: vrf.h:236
const MplsLabel * mpls_label() const
Definition: nexthop.h:434
const std::string & fabric_policy_vrf_name() const
Definition: agent.h:908