OpenSDN source code
bgp_config_ifmap.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include "bgp/bgp_config_ifmap.h"
6 
7 #include <boost/foreach.hpp>
8 
9 #include <algorithm>
10 
11 #include "base/string_util.h"
12 #include "base/task_annotations.h"
13 #include "bgp/bgp_common.h"
15 #include "bgp/bgp_log.h"
17 #include "ifmap/ifmap_node.h"
18 #include "ifmap/ifmap_table.h"
19 
20 #include "schema/bgp_schema_types.h"
21 #include "schema/vnc_cfg_types.h"
22 
23 using std::unique_ptr;
24 using std::find;
25 using std::make_pair;
26 using std::pair;
27 using std::set;
28 using std::sort;
29 using std::string;
30 using std::vector;
31 using boost::iequals;
32 
34 
36 
38  default_addr_family_list.push_back("inet");
39  default_addr_family_list.push_back("inet-vpn");
40 }
41 
43 
44 static string IdentifierParent(const string &identifier) {
45  string parent;
46  size_t last;
47  last = identifier.rfind(':');
48  if (last == 0 || last == string::npos) {
49  return parent;
50  }
51  parent = identifier.substr(0, last);
52  return parent;
53 }
54 
55 static uint32_t IpAddressToBgpIdentifier(const IpAddress &address) {
56  return htonl(address.to_v4().to_ulong());
57 }
58 
59 static string BgpIdentifierToString(uint32_t identifier) {
60  Ip4Address addr(ntohl(identifier));
61  return addr.to_string();
62 }
63 
65  : instance_(instance) {
66 }
67 
70 }
71 
73  if (proxy != NULL) {
74  node_proxy_.Swap(proxy);
75  name_ = node_proxy_.node()->name();
76  }
77 }
78 
81  instance_(rti), policy_(rtp) {
82 }
83 
85 }
86 
88  if (proxy != NULL) {
89  node_proxy_.Swap(proxy);
90  name_ = node_proxy_.node()->name();
91  }
92 }
93 
95  DBGraph *graph, IFMapNode *node, pair<IFMapNode *, IFMapNode *> *pair) {
96  IFMapNode *routing_instance = NULL;
97  IFMapNode *routing_policy = NULL;
98 
99  for (DBGraphVertex::adjacency_iterator iter = node->begin(graph);
100  iter != node->end(graph); ++iter) {
101  IFMapNode *adj = static_cast<IFMapNode *>(iter.operator->());
102  if (strcmp(adj->table()->Typename(), "routing-instance") == 0)
103  routing_instance = adj;
104  if (strcmp(adj->table()->Typename(), "routing-policy") == 0)
105  routing_policy = adj;
106  }
107  if (routing_policy == NULL || routing_instance == NULL) {
108  return false;
109  }
110 
111  pair->first = routing_instance;
112  pair->second = routing_policy;
113  return true;
114 }
115 
117  const autogen::RoutingPolicyRoutingInstance *ri_rp) {
118  ri_rp_link_.reset(ri_rp);
119 }
120 
122  ri_rp_link_.reset();
123 }
124 
125 static AuthenticationData::KeyType KeyChainType(const string &value) {
126  // Case-insensitive comparison
127  if (boost::iequals(value, "md5")) {
129  }
131 }
132 
133 static void BuildKeyChain(BgpNeighborConfig *neighbor,
134  const autogen::AuthenticationData &values) {
135  AuthenticationData keydata;
136  keydata.set_key_type(KeyChainType(values.key_type));
137 
138  AuthenticationKey key;
139  for (vector<autogen::AuthenticationKeyItem>::const_iterator iter =
140  values.key_items.begin(); iter != values.key_items.end(); ++iter) {
141  key.id = iter->key_id;
142  key.value = iter->key;
143  key.start_time = 0;
144  keydata.AddKeyToKeyChain(key);
145  }
146  neighbor->set_keydata(keydata);
147 }
148 
149 //
150 // Check if the family is allowed to be configured for BgpNeighborConfig.
151 // Only families inet and inet6 are allowed on non-master instances.
152 //
154  const string &family) {
156  return true;
157  return (family == "inet" || family == "inet6");
158 }
159 
160 //
161 // Build list of BgpFamilyAttributesConfig elements from the list of address
162 // families. This is provided for backward compatibility with configurations
163 // that represent each family with a simple string.
164 //
166  const BgpNeighborConfig::AddressFamilyList &family_list,
167  const vector<string> &remote_family_list) {
168  BgpNeighborConfig::FamilyAttributesList family_attributes_list;
169  BOOST_FOREACH(const string &family, family_list) {
170  // Skip families that are not valid/supported for the neighbor.
171  if (!AddressFamilyIsValid(neighbor, family))
172  continue;
173 
174  // Skip families that are not configured on remote bgp-router.
175  if (!remote_family_list.empty()) {
176  vector<string>::const_iterator it = find(
177  remote_family_list.begin(), remote_family_list.end(), family);
178  if (it == remote_family_list.end())
179  continue;
180  }
181 
182  BgpFamilyAttributesConfig family_attributes(family);
183  family_attributes_list.push_back(family_attributes);
184  }
185 
186  neighbor->set_family_attributes_list(family_attributes_list);
187 }
188 
189 //
190 // Build list of BgpFamilyAttributesConfig elements from BgpFamilyAttributes
191 // list in BgpSessionAttributes.
192 //
193 // Implement backward compatibility by also adding BgpFamilyAttributesConfig
194 // elements for families that are not in BgpFamilyAttributes list but are in
195 // the address_families list.
196 //
198  const autogen::BgpSessionAttributes *attributes) {
199  set<string> family_set;
200  BgpNeighborConfig::FamilyAttributesList family_attributes_list;
201  BOOST_FOREACH(const autogen::BgpFamilyAttributes &family_config,
202  attributes->family_attributes) {
203  if (!AddressFamilyIsValid(neighbor, family_config.address_family))
204  continue;
205  BgpFamilyAttributesConfig family_attributes(
206  family_config.address_family);
207  family_attributes.loop_count = family_config.loop_count;
208  family_attributes.prefix_limit = family_config.prefix_limit.maximum;
209  family_attributes.idle_timeout =
210  family_config.prefix_limit.idle_timeout;
211  family_attributes.default_tunnel_encap_list =
212  family_config.default_tunnel_encap;
213  family_attributes_list.push_back(family_attributes);
214  family_set.insert(family_config.address_family);
215  }
216 
217  BOOST_FOREACH(const string &family, attributes->address_families.family) {
218  if (family_set.find(family) != family_set.end())
219  continue;
220  BgpFamilyAttributesConfig family_attributes(family);
221  family_attributes_list.push_back(family_attributes);
222  }
223 
224  neighbor->set_family_attributes_list(family_attributes_list);
225 }
226 
227 //
228 // Set the autogen::BgpSessionAttributes for this BgpNeighborConfig.
229 //
230 // The autogen::BgpSession will have up to 3 session attributes - one that
231 // applies to the local router, one that applies the remote router and one
232 // that applies to both.
233 //
235  BgpNeighborConfig *neighbor, const string &localname,
236  const autogen::BgpSession *session) {
237  typedef vector<autogen::BgpSessionAttributes> AttributeVec;
238  const autogen::BgpSessionAttributes *common = NULL;
239  const autogen::BgpSessionAttributes *local = NULL;
240  for (AttributeVec::const_iterator iter = session->attributes.begin();
241  iter != session->attributes.end(); ++iter) {
242  const autogen::BgpSessionAttributes *attr = iter.operator->();
243  if (attr->bgp_router.empty()) {
244  common = attr;
245  } else if (neighbor->router_type() != "bgpaas-client" &&
246  attr->bgp_router == localname) {
247  local = attr;
248  } else if (neighbor->router_type() == "bgpaas-client" &&
249  attr->bgp_router == "bgpaas-server") {
250  local = attr;
251  }
252  }
253 
254  // TODO(nsheth): local should override rather than replace common.
255  const autogen::BgpSessionAttributes *attributes = NULL;
256  if (common != NULL) {
257  attributes = common;
258  } else if (local != NULL) {
259  attributes = local;
260  }
261  if (attributes != NULL) {
262  neighbor->set_passive(attributes->passive);
263  neighbor->set_as_override(attributes->as_override);
264  neighbor->set_private_as_action(attributes->private_as_action);
265  neighbor->set_loop_count(attributes->loop_count);
266  if (attributes->admin_down) {
267  neighbor->set_admin_down(true);
268  }
269  if (attributes->local_autonomous_system) {
270  neighbor->set_local_as(attributes->local_autonomous_system);
271  }
272  if (attributes->hold_time) {
273  neighbor->set_hold_time(attributes->hold_time);
274  }
275  BuildFamilyAttributesList(neighbor, attributes);
276  BuildKeyChain(neighbor, attributes->auth_data);
277  const autogen::RouteOriginOverride &origin_override =
278  attributes->route_origin_override;
279  neighbor->SetOriginOverride(origin_override.origin_override,
280  origin_override.origin);
281  }
282 }
283 
285  const BgpIfmapInstanceConfig *instance,
286  const BgpIfmapInstanceConfig *master_instance,
287  const string &local_name,
288  const string &remote_name,
289  const autogen::BgpRouter *local_router,
290  const autogen::BgpRouter *remote_router,
291  const autogen::BgpSession *session) {
292  BgpNeighborConfig *neighbor = new BgpNeighborConfig();
293 
294  neighbor->set_instance_name(instance->name());
295 
296  // If the autogen::BgpSession has a uuid, we append it to the remote
297  // bgp-router's name to make the BgpNeighborConfig's name unique.
298  if (session && !session->uuid.empty()) {
299  neighbor->set_uuid(session->uuid);
300  neighbor->set_name(remote_name + ":" + session->uuid);
301  } else {
302  neighbor->set_name(remote_name);
303  }
304 
305  // Store a copy of the remote bgp-router's autogen::BgpRouterParams and
306  // derive the autogen::BgpSessionAttributes for the session.
307  const autogen::BgpRouterParams &params = remote_router->parameters();
308  neighbor->set_router_type(params.router_type);
309  if (params.admin_down) {
310  neighbor->set_admin_down(true);
311  }
312  if (params.local_autonomous_system) {
313  neighbor->set_peer_as(params.local_autonomous_system);
314  } else {
315  neighbor->set_peer_as(params.autonomous_system);
316  }
317  boost::system::error_code err;
318  neighbor->set_peer_address(
319  IpAddress::from_string(params.address, err));
320  if (err) {
322  "Invalid peer address " << params.address <<
323  " for neighbor " << neighbor->name());
324  }
325 
326  Ip4Address identifier = Ip4Address::from_string(params.identifier, err);
327  if (err) {
329  "Invalid peer identifier " << params.identifier <<
330  " for neighbor " << neighbor->name());
331  }
332  neighbor->set_peer_identifier(IpAddressToBgpIdentifier(identifier));
333 
334  if (params.router_type == "bgpaas-client") {
335  IpAddress inet_gw_address =
336  Ip4Address::from_string(params.gateway_address, err);
337  if (!params.gateway_address.empty() && err) {
339  "Invalid gateway address " <<
340  params.gateway_address <<
341  " for neighbor " << neighbor->name());
342  } else {
343  neighbor->set_gateway_address(Address::INET, inet_gw_address);
344  }
345 
346  IpAddress inet6_gw_address =
347  Ip6Address::from_string(params.ipv6_gateway_address, err);
348  if (!params.ipv6_gateway_address.empty() && err) {
350  "Invalid ipv6 gateway address " <<
351  params.ipv6_gateway_address <<
352  " for neighbor " << neighbor->name());
353  } else {
354  neighbor->set_gateway_address(Address::INET6, inet6_gw_address);
355  }
356  }
357 
358  neighbor->set_port(params.port);
359  neighbor->set_source_port(params.source_port);
360  neighbor->set_hold_time(params.hold_time);
361 
362  if (session != NULL) {
363  NeighborSetSessionAttributes(neighbor, local_name, session);
364  }
365 
366  // Get the local identifier and local as from the master protocol config.
367  const BgpIfmapProtocolConfig *master_protocol =
368  master_instance->protocol_config();
369  if (master_protocol && master_protocol->bgp_router()) {
370  const autogen::BgpRouterParams &master_params =
371  master_protocol->router_params();
372  if (master_params.admin_down) {
373  neighbor->set_admin_down(true);
374  }
375  Ip4Address localid =
376  Ip4Address::from_string(master_params.identifier, err);
377  if (!err) {
379  }
380  if (!neighbor->local_as()) {
381  if (master_params.local_autonomous_system) {
382  neighbor->set_local_as(master_params.local_autonomous_system);
383  } else {
384  neighbor->set_local_as(master_params.autonomous_system);
385  }
386  }
387  if (instance != master_instance) {
388  neighbor->set_passive(true);
389  }
390  }
391 
392  // Get other parameters from the instance protocol config.
393  // Note that there's no instance protocol config for non-master instances.
394  const BgpIfmapProtocolConfig *protocol = instance->protocol_config();
395  if (protocol && protocol->bgp_router()) {
396  const autogen::BgpRouterParams &protocol_params =
397  protocol->router_params();
398  if (neighbor->family_attributes_list().empty()) {
399  BuildFamilyAttributesList(neighbor,
400  protocol_params.address_families.family,
401  params.address_families.family);
402  }
403  if (neighbor->auth_data().Empty()) {
404  const autogen::BgpRouterParams &local_params =
405  local_router->parameters();
406  BuildKeyChain(neighbor, local_params.auth_data);
407  }
408  }
409 
410  if (neighbor->family_attributes_list().empty()) {
412  params.address_families.family);
413  }
414 
415  return neighbor;
416 }
417 
418 //
419 // Build map of BgpNeighborConfigs based on the data in autogen::BgpPeering.
420 //
422  const autogen::BgpRouter *local_rt_config,
423  const string &peername, const autogen::BgpRouter *remote_rt_config,
424  const autogen::BgpPeering *peering, NeighborMap *map) {
425  const BgpIfmapInstanceConfig *master_instance =
427 
428  // If there are one or more autogen::BgpSessions for the peering, use
429  // those to create the BgpNeighborConfigs.
430  const autogen::BgpPeeringAttributes &attr = peering->data();
431  for (autogen::BgpPeeringAttributes::const_iterator iter = attr.begin();
432  iter != attr.end(); ++iter) {
434  instance_, master_instance, manager->localname(), peername,
435  local_rt_config, remote_rt_config, iter.operator->());
436  map->insert(make_pair(neighbor->name(), neighbor));
437  }
438 
439  // When no sessions are present, create a single BgpNeighborConfig with
440  // no per-session configuration.
441  if (map->empty()) {
443  instance_, master_instance, manager->localname(), peername,
444  local_rt_config, remote_rt_config, NULL);
445  map->insert(make_pair(neighbor->name(), neighbor));
446  }
447 }
448 
449 //
450 // Update BgpIfmapPeeringConfig based on updated autogen::BgpPeering.
451 //
452 // This mainly involves building future BgpNeighborConfigs and doing a diff of
453 // the current and future BgpNeighborConfigs. Note that BgpIfmapInstanceConfig
454 // also has references to BgpNeighborConfigs, so it also needs to be updated as
455 // part of the process.
456 //
458  const autogen::BgpPeering *peering) {
460  assert(node != NULL);
461  bgp_peering_.reset(peering);
462 
463  // Build the future NeighborMap. The future map should be empty if the
464  // bgp-peering is deleted or if the parameters for the remote bgp-router
465  // are not available.
466  NeighborMap future;
467  pair<IFMapNode *, IFMapNode *> routers;
468  if (!node->IsDeleted() &&
469  GetRouterPair(manager->graph(), manager->localname(), node, &routers)) {
470  const autogen::BgpRouter *local_rt_config =
471  static_cast<const autogen::BgpRouter *>(
472  routers.first->GetObject());
473  const autogen::BgpRouter *remote_rt_config =
474  static_cast<const autogen::BgpRouter *>(
475  routers.second->GetObject());
476  if (local_rt_config &&
477  local_rt_config->IsPropertySet(autogen::BgpRouter::PARAMETERS) &&
478  remote_rt_config &&
479  remote_rt_config->IsPropertySet(autogen::BgpRouter::PARAMETERS)) {
480  BuildNeighbors(manager, local_rt_config, routers.second->name(),
481  remote_rt_config, peering, &future);
482  }
483  }
484 
485  // Swap out the NeighborMap in preparation for doing a diff.
486  NeighborMap current;
487  current.swap(neighbors_);
488 
489  // Do a diff on the current and future BgpNeighborConfigs, making sure
490  // that the BgpIfmapInstanceConfig is updated accordingly. We add any new
491  // BgpNeighborConfigs to our NeighborMap.
492  NeighborMap::iterator it1 = current.begin();
493  NeighborMap::iterator it2 = future.begin();
494  while (it1 != current.end() && it2 != future.end()) {
495  if (it1->first < it2->first) {
496  BgpNeighborConfig *prev = it1->second;
497  instance_->DeleteNeighbor(manager, prev);
498  ++it1;
499  } else if (it1->first > it2->first) {
500  BgpNeighborConfig *neighbor = it2->second;
501  instance_->AddNeighbor(manager, neighbor);
502  neighbors_.insert(*it2);
503  it2->second = NULL;
504  ++it2;
505  } else {
506  BgpNeighborConfig *neighbor = it1->second;
507  BgpNeighborConfig *update = it2->second;
508  if (*neighbor != *update) {
509  instance_->ChangeNeighbor(manager, update);
510  neighbors_.insert(*it2);
511  it2->second = NULL;
512  } else {
513  neighbors_.insert(*it1);
514  it1->second = NULL;
515  }
516  ++it1;
517  ++it2;
518  }
519  }
520  for (; it1 != current.end(); ++it1) {
521  BgpNeighborConfig *prev = it1->second;
522  instance_->DeleteNeighbor(manager, prev);
523  }
524  for (; it2 != future.end(); ++it2) {
525  BgpNeighborConfig *neighbor = it2->second;
526  instance_->AddNeighbor(manager, neighbor);
527  neighbors_.insert(*it2);
528  it2->second = NULL;
529  }
530 
531  // Get rid of the current and future NeighborMaps and destroy any mapped
532  // BgpNeighborConfigs. Note that we have carefully reset mapped values to
533  // NULL above when we don't want a BgpNeighborConfig to get destroyed.
534  STLDeleteElements(&current);
535  STLDeleteElements(&future);
536 }
537 
538 //
539 // Delete all state for the given BgpPeeringConfig.
540 //
541 // This mainly involves getting rid of BgpNeighborConfigs in the NeighborMap.
542 //
544  NeighborMap current;
545  current.swap(neighbors_);
546  for (NeighborMap::iterator iter = current.begin();
547  iter != current.end(); ++iter) {
548  instance_->DeleteNeighbor(manager, iter->second);
549  }
550  STLDeleteElements(&current);
551  bgp_peering_.reset();
552 }
553 
554 //
555 // Find the IFMapNodes for a bgp-peering.
556 //
557 // The "node" is the IFMapNode for the bgp-peering link. The bgp-peering is
558 // interesting only if one of the bgp-routers is the local node.
559 //
560 // Return true if both bgp-routers for the bgp-peering exist and one of them
561 // is the local one. Also fill in the local and remote IFMapNode pointers if
562 // we return true.
563 //
565  const string &localname, IFMapNode *node,
566  pair<IFMapNode *, IFMapNode *> *pair) {
567  IFMapNode *local = NULL;
568  IFMapNode *remote = NULL;
569  string local_router_type;
570  string remote_router_type;
571  string local_instance;
572  string remote_instance;
573 
574  for (DBGraphVertex::adjacency_iterator iter = node->begin(db_graph);
575  iter != node->end(db_graph); ++iter) {
576  IFMapNode *adj = static_cast<IFMapNode *>(iter.operator->());
577  if (strcmp(adj->table()->Typename(), "bgp-router") != 0)
578  continue;
579  autogen::BgpRouter *router =
580  static_cast<autogen::BgpRouter *>(adj->GetObject());
581  if (!router)
582  continue;
583  const autogen::BgpRouterParams &params = router->parameters();
584  string instance_name(IdentifierParent(adj->name()));
585  string name = adj->name().substr(instance_name.size() + 1);
586  if (name == localname && params.router_type != "bgpaas-client") {
587  local = adj;
588  local_router_type = params.router_type;
589  local_instance = instance_name;
590  } else if (instance_name != BgpConfigManager::kMasterInstance &&
591  params.router_type == "bgpaas-server") {
592  local = adj;
593  local_router_type = params.router_type;
594  local_instance = instance_name;
595  } else {
596  remote = adj;
597  remote_router_type = params.router_type;
598  remote_instance = instance_name;
599  }
600  }
601 
602  if ((local == NULL || remote == NULL) || (local_router_type ==
603  "bgpaas-server" && remote_router_type != "bgpaas-client") ||
604  (local_router_type != "bgpaas-server" && remote_router_type ==
605  "bgpaas-client") || (local_instance != remote_instance)) {
606  BGP_LOG_STR(BgpConfig, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_SYSLOG,
607  "localname: " << localname <<
608  ((local == NULL) ? " Local node not present" :
609  " Local node present") <<
610  ((remote == NULL) ? " Remote node not present" :
611  " Remote node present") <<
612  " local_router_type: " << local_router_type <<
613  " remote_router_type: " << remote_router_type <<
614  " local instance: " << local_instance <<
615  " remote instance: " << remote_instance);
616  return false;
617  }
618 
619  pair->first = local;
620  pair->second = remote;
621  return true;
622 }
623 
624 //
625 // Constructor for BgpIfmapProtocolConfig.
626 //
628  : instance_(instance),
629  data_(instance->name()) {
630 }
631 
632 //
633 // Destructor for BgpIfmapProtocolConfig.
634 //
636 }
637 
638 const autogen::BgpRouterParams &BgpIfmapProtocolConfig::router_params() const {
639  return bgp_router_->parameters();
640 }
641 
642 //
643 // Set the IFMapNodeProxy for the BgpIfmapProtocolConfig.
644 //
646  if (proxy != NULL) {
647  node_proxy_.Swap(proxy);
648  }
649 }
650 
651 //
652 // Update autogen::BgpRouter object for this BgpIfmapProtocolConfig.
653 //
655  const autogen::BgpRouter *router) {
656  bgp_router_.reset(router);
657  const autogen::BgpRouterParams &params = router->parameters();
658  data_.set_admin_down(params.admin_down);
659  data_.set_cluster_id(params.cluster_id);
660  data_.set_autonomous_system(params.autonomous_system);
661  data_.set_local_autonomous_system(params.local_autonomous_system);
663  boost::system::error_code err;
664  IpAddress identifier = IpAddress::from_string(params.identifier, err);
665  if (!err) {
667  }
668  data_.set_hold_time(params.hold_time);
669 
670  // reset subcluster name and id,
671  // will be set again if mapping is found in schema
674  // get subcluster name this router is associated with
676  if (!node)
677  return;
678  DBGraph *graph = manager->graph();
679  for (DBGraphVertex::adjacency_iterator iter = node->begin(graph);
680  iter != node->end(graph); ++iter) {
681  IFMapNode *adj = static_cast<IFMapNode *>(iter.operator->());
682  if (strcmp(adj->table()->Typename(), "sub-cluster") == 0) {
684  const autogen::SubCluster *sc =
685  static_cast<autogen::SubCluster *>(adj->GetObject());
686  if (sc) {
687  data_.set_subcluster_id(sc->id());
688  }
689  break;
690  }
691  }
692 }
693 
694 //
695 // Delete autogen::BgpRouter object for this BgpIfmapProtocolConfig.
696 //
699  bgp_router_.reset();
700 }
701 
703  return instance_->name();
704 }
705 
706 //
707 // Constructor for BgpIfmapInstanceConfig.
708 //
710  : name_(name),
711  data_(name),
712  index_(-1),
713  protocol_(NULL) {
714 }
715 
716 //
717 // Destructor for BgpIfmapInstanceConfig.
718 //
720 }
721 
722 //
723 // Set the IFMapNodeProxy for the BgpIfmapInstanceConfig.
724 //
726  if (proxy != NULL) {
727  node_proxy_.Swap(proxy);
728  }
729 }
730 
731 //
732 // Get the BgpIfmapProtocolConfig for this BgpIfmapInstanceConfig, create
733 // it if needed.
734 //
736  if (protocol_.get() == NULL) {
737  protocol_.reset(new BgpIfmapProtocolConfig(this));
738  }
739  return protocol_.get();
740 }
741 
742 //
743 // Delete the BgpIfmapProtocolConfig for this BgpIfmapInstanceConfig.
744 //
746  protocol_.reset();
747 }
748 
749 //
750 // Get the route-target for an instance-target. The input IFMapNode is the
751 // midnode that represents the instance-target link. We traverse the graph
752 // the graph edges till we find the adjacency to the route-target.
753 //
754 // Return true and fill in the target string if we find the route-target.
755 //
757  string *target) {
758  for (DBGraphVertex::adjacency_iterator iter = node->begin(graph);
759  iter != node->end(graph); ++iter) {
760  IFMapNode *adj = static_cast<IFMapNode *>(iter.operator->());
761  if (strcmp(adj->table()->Typename(), "route-target") == 0) {
762  *target = adj->name();
763  return true;
764  }
765  }
766  return false;
767 }
768 
769 //
770 // Fill in all the export route targets for a routing-instance. The input
771 // IFMapNode represents the routing-instance. We traverse the graph edges
772 // and look for instance-target adjacencies. If the instance-target is an
773 // export and import target, add it to the vector.
774 //
775 // Note that we purposely skip adding export only targets to the vector.
776 // Reasoning is that export only targets are manually configured by users
777 // and hence should not be imported based on policy.
778 //
780  vector<string> *target_list) {
781  for (DBGraphVertex::adjacency_iterator iter = node->begin(graph);
782  iter != node->end(graph); ++iter) {
783  IFMapNode *adj = static_cast<IFMapNode *>(iter.operator->());
784  string target;
785  if ((strcmp(adj->table()->Typename(), "instance-target") == 0) &&
786  (GetInstanceTargetRouteTarget(graph, adj, &target))) {
787  const autogen::InstanceTarget *itarget =
788  dynamic_cast<autogen::InstanceTarget *>(adj->GetObject());
789  if (!itarget)
790  continue;
791  const autogen::InstanceTargetType &itt = itarget->data();
792  if (itt.import_export.empty())
793  target_list->push_back(target);
794  }
795  }
796 }
797 
798 //
799 // Fill in all the export route targets of the routing-instance at the other
800 // end of a connection. The src_node is the routing-instance from which we
801 // reached the connection node. The name of the source routing-instance is
802 // src_instance.
803 //
804 // If the connection is unidirectional and the destination-instance for the
805 // connection is not the routing-instance from which we started, we should
806 // not get any targets from this connection. This is what a unidirectional
807 // connection means.
808 //
809 static void GetConnectionExportTargets(DBGraph *graph, IFMapNode *src_node,
810  const string &src_instance, IFMapNode *node,
811  vector<string> *target_list) {
812  const autogen::Connection *conn =
813  dynamic_cast<autogen::Connection *>(node->GetObject());
814  if (!conn)
815  return;
816  const autogen::ConnectionType &conn_type = conn->data();
817  if (!conn_type.destination_instance.empty() &&
818  conn_type.destination_instance != src_instance)
819  return;
820  for (DBGraphVertex::adjacency_iterator iter = node->begin(graph);
821  iter != node->end(graph); ++iter) {
822  IFMapNode *adj = static_cast<IFMapNode *>(iter.operator->());
823  if (adj == src_node)
824  continue;
825  if (strcmp(adj->table()->Typename(), "routing-instance") != 0)
826  continue;
827  GetRoutingInstanceExportTargets(graph, adj, target_list);
828  }
829 }
830 
831 //
832 // Fill in all the routing-policies for a routing-instance. The input
833 // IFMapNode represents the routing-policy-routing-instance. We traverse to
834 // graph edges and look for routing-policy adjacency
835 //
837  RoutingPolicyAttachInfo *ri_rp_link) {
838  string sequence;
839  const autogen::RoutingPolicyRoutingInstance *policy =
840  static_cast<autogen::RoutingPolicyRoutingInstance *>(node->GetObject());
841  const autogen::RoutingPolicyType &attach_info = policy->data();
842 
843  ri_rp_link->sequence_ = attach_info.sequence;
844 
845  for (DBGraphVertex::adjacency_iterator iter = node->begin(graph);
846  iter != node->end(graph); ++iter) {
847  IFMapNode *adj = static_cast<IFMapNode *>(iter.operator->());
848  if (strcmp(adj->table()->Typename(), "routing-policy") == 0) {
849  ri_rp_link->routing_policy_ = adj->name();
850  return true;
851  }
852  }
853  return false;
854 }
855 
856 //
857 // Fill in all the route-aggregation for a routing-instance.
858 //
859 static bool GetRouteAggregateConfig(DBGraph *graph, IFMapNode *node,
862  const autogen::RouteAggregate *ra =
863  static_cast<autogen::RouteAggregate *>(node->GetObject());
864  if (ra == NULL) return false;
865 
866  boost::system::error_code ec;
867  IpAddress nexthop =
868  IpAddress::from_string(ra->aggregate_route_nexthop(), ec);
869  if (ec.failed()) return false;
870 
871  BOOST_FOREACH(const string &route, ra->aggregate_route_entries()) {
872  AggregateRouteConfig aggregate;
873  aggregate.nexthop = nexthop;
874 
875  Ip4Address address;
876  ec = Ip4SubnetParse(route, &address, &aggregate.prefix_length);
877  if (!ec) {
878  if (!nexthop.is_v4()) continue;
879  aggregate.aggregate = address;
880  inet_list->push_back(aggregate);
881  } else {
882  if (!nexthop.is_v6()) continue;
883  Ip6Address address;
884  ec = Inet6SubnetParse(route, &address, &aggregate.prefix_length);
885  if (ec.failed()) continue;
886  aggregate.aggregate = address;
887  inet6_list->push_back(aggregate);
888  }
889  }
890 
891  return true;
892 }
893 
894 //
895 // Get the network id for a virtual-network. The input IFMapNode represents
896 // the virtual-network.
897 //
898 static int GetVirtualNetworkIndex(DBGraph *graph, IFMapNode *node) {
899  const autogen::VirtualNetwork *vn =
900  static_cast<autogen::VirtualNetwork *>(node->GetObject());
901  if (vn && vn->IsPropertySet(autogen::VirtualNetwork::NETWORK_ID))
902  return vn->network_id();
903  if (vn && vn->IsPropertySet(autogen::VirtualNetwork::PROPERTIES))
904  return vn->properties().network_id;
905  return 0;
906 }
907 
908 //
909 // Check if a virtual-network allows transit. The input IFMapNode represents
910 // the virtual-network.
911 //
912 static bool GetVirtualNetworkAllowTransit(DBGraph *graph, IFMapNode *node) {
913  const autogen::VirtualNetwork *vn =
914  static_cast<autogen::VirtualNetwork *>(node->GetObject());
915  if (vn && vn->IsPropertySet(autogen::VirtualNetwork::PROPERTIES))
916  return vn->properties().allow_transit;
917  return false;
918 }
919 
920 
921 //
922 // Check if a virtual-network has pbb-evpn enabled.
923 // The input IFMapNode represents the virtual-network.
924 //
926  const autogen::VirtualNetwork *vn =
927  static_cast<autogen::VirtualNetwork *>(node->GetObject());
928  if (vn && vn->IsPropertySet(autogen::VirtualNetwork::PBB_EVPN_ENABLE))
929  return vn->pbb_evpn_enable();
930  return false;
931 }
932 
933 
934 //
935 // Get the vxlan id for a virtual-network. The input IFMapNode represents
936 // the virtual-network.
937 //
938 // The vxlan_network_identifier is 0 when automatic mode is in use. In that
939 // case, the network_id is used as vxlan id.
940 //
941 static int GetVirtualNetworkVxlanId(DBGraph *graph, IFMapNode *node) {
942  const autogen::VirtualNetwork *vn =
943  static_cast<autogen::VirtualNetwork *>(node->GetObject());
944  if (vn && vn->IsPropertySet(autogen::VirtualNetwork::PROPERTIES)) {
945  if (vn->properties().vxlan_network_identifier) {
946  return vn->properties().vxlan_network_identifier;
947  } else {
948  return vn->properties().network_id;
949  }
950  }
951  return 0;
952 }
953 
955  const autogen::RoutingInstance *config) {
958  BOOST_FOREACH(const autogen::StaticRouteType &route,
959  config->static_route_entries()) {
960  boost::system::error_code ec;
961  StaticRouteConfig item;
962  item.nexthop = IpAddress::from_string(route.next_hop, ec);
963  if (ec.failed())
964  continue;
965 
966  item.route_targets = route.route_target;
967  item.communities = route.community;
968  if (item.nexthop.is_v4()) {
969  Ip4Address address;
970  ec = Ip4SubnetParse(route.prefix, &address, &item.prefix_length);
971  if (ec.failed())
972  continue;
973  item.address = address;
974  std::pair<BgpInstanceConfig::StaticRouteList::iterator, bool> ret =
975  inet_list.insert(item);
976  if (!ret.second) {
978  "Duplicate static route prefix " << route.prefix <<
979  " with nexthop " << route.next_hop <<
980  " for routing instance " << rti->name());
981  }
982  } else {
983  Ip6Address address;
984  ec = Inet6SubnetParse(route.prefix, &address, &item.prefix_length);
985  if (ec.failed())
986  continue;
987  item.address = address;
988  std::pair<BgpInstanceConfig::StaticRouteList::iterator, bool> ret =
989  inet6_list.insert(item);
990  if (!ret.second) {
992  "Duplicate static route prefix " << route.prefix <<
993  " with nexthop " << route.next_hop <<
994  " for routing instance " << rti->name());
995  }
996  }
997  }
998  rti->swap_static_routes(Address::INET, &inet_list);
999  rti->swap_static_routes(Address::INET6, &inet6_list);
1000 }
1001 
1003  const autogen::RoutingInstance *config) {
1005  const autogen::ServiceChainInfo &inet_chain =
1006  config->service_chain_information();
1007  if (config->IsPropertySet(
1008  autogen::RoutingInstance::SERVICE_CHAIN_INFORMATION)) {
1009  ServiceChainConfig item = {
1011  inet_chain.routing_instance,
1012  inet_chain.prefix,
1013  inet_chain.service_chain_address,
1014  inet_chain.service_instance,
1015  inet_chain.source_routing_instance,
1016  inet_chain.service_chain_id,
1017  inet_chain.sc_head,
1018  inet_chain.retain_as_path,
1019  };
1020  list.push_back(item);
1021  }
1022 
1023  const autogen::ServiceChainInfo &inet6_chain =
1024  config->ipv6_service_chain_information();
1025  if (config->IsPropertySet(
1026  autogen::RoutingInstance::IPV6_SERVICE_CHAIN_INFORMATION)) {
1027  ServiceChainConfig item = {
1029  inet6_chain.routing_instance,
1030  inet6_chain.prefix,
1031  inet6_chain.service_chain_address,
1032  inet6_chain.service_instance,
1033  inet6_chain.source_routing_instance,
1034  inet6_chain.service_chain_id,
1035  inet6_chain.sc_head,
1036  inet6_chain.retain_as_path,
1037  };
1038  list.push_back(item);
1039  }
1040 
1041  const autogen::ServiceChainInfo &evpn_chain =
1042  config->evpn_service_chain_information();
1043  if (config->IsPropertySet(
1044  autogen::RoutingInstance::EVPN_SERVICE_CHAIN_INFORMATION)) {
1045  ServiceChainConfig item = {
1047  evpn_chain.routing_instance,
1048  evpn_chain.prefix,
1049  evpn_chain.service_chain_address,
1050  evpn_chain.service_instance,
1051  evpn_chain.source_routing_instance,
1052  evpn_chain.service_chain_id,
1053  evpn_chain.sc_head,
1054  evpn_chain.retain_as_path,
1055  };
1056  list.push_back(item);
1057  }
1058 
1059  const autogen::ServiceChainInfo &evpnv6_chain =
1060  config->evpn_ipv6_service_chain_information();
1061  if (config->IsPropertySet(
1062  autogen::RoutingInstance::EVPN_IPV6_SERVICE_CHAIN_INFORMATION)) {
1063  ServiceChainConfig item = {
1065  evpnv6_chain.routing_instance,
1066  evpnv6_chain.prefix,
1067  evpnv6_chain.service_chain_address,
1068  evpnv6_chain.service_instance,
1069  evpnv6_chain.source_routing_instance,
1070  evpnv6_chain.service_chain_id,
1071  evpnv6_chain.sc_head,
1072  evpnv6_chain.retain_as_path,
1073  };
1074  list.push_back(item);
1075  }
1076 
1077  rti->swap_service_chain_list(&list);
1078 }
1079 
1080 // Get name of vxlan RI for bridge RI
1081 
1082 static string GetConnectedVxlanRiVn(DBGraph *graph, IFMapNode *node) {
1083  const autogen::VirtualNetwork *vn_vxlan =
1084  static_cast<autogen::VirtualNetwork *>(node->GetObject());
1085  if (!vn_vxlan)
1086  return "";
1087  for (DBGraphVertex::adjacency_iterator iter_ri = node->begin(graph);
1088  iter_ri != node->end(graph); ++iter_ri) {
1089  IFMapNode *adj_ri = static_cast<IFMapNode *>(iter_ri.operator->());
1090  if (strcmp(adj_ri->table()->Typename(), "routing-instance") == 0) {
1091  const autogen::RoutingInstance *iri =
1092  dynamic_cast<autogen::RoutingInstance *>(adj_ri->GetObject());
1093  if (!iri)
1094  continue;
1095  return adj_ri->name();
1096  }
1097  }
1098  return "";
1099 }
1100 
1101 static string GetConnectedVxlanRiLr(DBGraph *graph, IFMapNode *node) {
1102  std::string ri_name = "";
1103  for (DBGraphVertex::adjacency_iterator iter_lr = node->begin(graph);
1104  iter_lr != node->end(graph); ++iter_lr) {
1105  IFMapNode *adj_lr = static_cast<IFMapNode *>(iter_lr.operator->());
1106  if (strcmp(adj_lr->table()->Typename(),
1107  "logical-router-virtual-network") == 0) {
1108  for (DBGraphVertex::adjacency_iterator iter_vn = adj_lr->begin(graph);
1109  iter_vn != adj_lr->end(graph); ++iter_vn) {
1110  IFMapNode *adj_vn = static_cast<IFMapNode *>(iter_vn.operator->());
1111  if (strcmp(adj_vn->table()->Typename(), "virtual-network") == 0) {
1112  ri_name = GetConnectedVxlanRiVn(graph, adj_vn);
1113  if (ri_name != "") {
1114  return ri_name;
1115  }
1116  }
1117  }
1118  }
1119  }
1120  return "";
1121 }
1122 
1123 
1124 static string GetConnectedVxlanRi(DBGraph *graph, IFMapNode *node) {
1125  std::string ri_name = "";
1126  const autogen::VirtualNetwork *vn =
1127  static_cast<autogen::VirtualNetwork *>(node->GetObject());
1128  if (!vn) {
1129  return "";
1130  }
1131  for (DBGraphVertex::adjacency_iterator iter_vmi = node->begin(graph);
1132  iter_vmi != node->end(graph); ++iter_vmi) {
1133  IFMapNode *adj_vmi = static_cast<IFMapNode *>(iter_vmi.operator->());
1134  if (strcmp(adj_vmi->table()->Typename(),
1135  "virtual-machine-interface") == 0) {
1136  for (DBGraphVertex::adjacency_iterator iter_lr = adj_vmi->begin(graph);
1137  iter_lr != adj_vmi->end(graph); ++iter_lr) {
1138  IFMapNode *adj_lr = static_cast<IFMapNode *>(iter_lr.operator->());
1139  if (strcmp(adj_lr->table()->Typename(), "logical-router") == 0) {
1140  ri_name = GetConnectedVxlanRiLr(graph, adj_lr);
1141  if (ri_name != "") {
1142  return ri_name;
1143  }
1144  }
1145  }
1146  }
1147  }
1148  return "";
1149 }
1150 
1151 
1153  const BgpConfigDelta &delta) {
1154  CHECK_CONCURRENCY("bgp::Config");
1155 
1157  = config_->FindRoutingPolicyLink(delta.id_name);
1158  if (ri_rp_link == NULL) {
1159  IFMapNodeProxy *proxy = delta.node.get();
1160  if (proxy == NULL) {
1161  return;
1162  }
1163  IFMapNode *node = proxy->node();
1164  if (node == NULL || delta.obj.get() == NULL) {
1165  return;
1166  }
1167 
1168  pair<IFMapNode *, IFMapNode *> ri_rp_pair;
1170  node, &ri_rp_pair)) {
1171  return;
1172  }
1173 
1174  string instance_name = ri_rp_pair.first->name();
1175  string policy_name = ri_rp_pair.second->name();
1176 
1177  BgpIfmapInstanceConfig *rti =
1178  config_->FindInstance(instance_name);
1180  config_->FindRoutingPolicy(policy_name);
1181  if (!rti || !rtp) {
1182  return;
1183  }
1184 
1185  ri_rp_link = config_->CreateRoutingPolicyLink(rti, rtp, proxy);
1186  } else {
1187  const IFMapNode *node = ri_rp_link->node();
1188  assert(node != NULL);
1189  if (delta.obj.get() == NULL) {
1190  BgpIfmapRoutingPolicyConfig *rtp = ri_rp_link->policy();
1191  BgpIfmapInstanceConfig *rti = ri_rp_link->instance();
1192  config_->DeleteRoutingPolicyLink(ri_rp_link);
1193  if (rtp->DeleteIfEmpty(this)) {
1194  config_->DeleteRoutingPolicy(rtp);
1195  }
1196  if (rti->DeleteIfEmpty(this)) {
1197  BGP_CONFIG_LOG_INSTANCE(Delete, server(), rti,
1198  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL);
1199  config_->DeleteInstance(rti);
1200  }
1201  return;
1202  }
1203  }
1204 
1205  autogen::RoutingPolicyRoutingInstance *ri_rp_link_cfg =
1206  static_cast<autogen::RoutingPolicyRoutingInstance *>(delta.obj.get());
1207 
1208  ri_rp_link->Update(this, ri_rp_link_cfg);
1209 }
1210 
1212  const RoutingPolicyAttachInfo &rhs) {
1213  return (lhs.sequence_ < rhs.sequence_);
1214 }
1215 
1217  uint32_t old_id) {
1219  if (old_id > 0) {
1220  string old_vit = "target:" + GetVitFromId(ntohl(old_id));
1221  import_list.erase(old_vit);
1222  }
1223  if (new_id > 0) {
1224  string new_vit = "target:" + GetVitFromId(ntohl(new_id));
1225  import_list.insert(new_vit);
1226  }
1228 }
1229 
1230 void BgpIfmapInstanceConfig::ProcessASUpdate(uint32_t new_as, uint32_t old_as) {
1232  if (old_as > 0) {
1233  string old_es_rtarget = "target:" + GetESRouteTarget(old_as);
1234  import_list.erase(old_es_rtarget);
1235  }
1236  if (new_as > 0) {
1237  string new_es_rtarget = "target:" + GetESRouteTarget(new_as);
1238  import_list.insert(new_es_rtarget);
1239  }
1241 }
1242 
1243 string BgpIfmapInstanceConfig::GetVitFromId(uint32_t identifier) const {
1244  if (identifier == 0)
1245  return "";
1246  return Ip4Address(identifier).to_string() + ":" + integerToString(index());
1247 }
1248 
1249 string BgpIfmapInstanceConfig::GetESRouteTarget(uint32_t as) const {
1250  if (as == 0)
1251  return "";
1252  if (as > 0xffFF)
1253  return integerToString(as) + ":" +
1255  return integerToString(as) + ":" +
1257 }
1258 
1259 // Populate vrf import route-target (used for MVPN) and ES route target in
1260 // import list.
1262  BgpIfmapConfigManager *mgr,
1263  BgpInstanceConfig::RouteTargetList& import_list) {
1264  const BgpIfmapInstanceConfig *master_instance =
1266  uint32_t bgp_identifier = 0;
1267  uint32_t as = 0;
1268  if (master_instance) {
1269  const BgpIfmapProtocolConfig *master_protocol =
1270  master_instance->protocol_config();
1271  if (master_protocol) {
1272  if (master_protocol->protocol_config()) {
1273  bgp_identifier =
1274  master_protocol->protocol_config()->identifier();
1275  as = master_protocol->protocol_config()->autonomous_system();
1276  }
1277  }
1278  }
1279  if (bgp_identifier > 0)
1280  import_list.insert("target:" + GetVitFromId(ntohl(bgp_identifier)));
1281  if (as > 0)
1282  import_list.insert("target:" + GetESRouteTarget(as));
1283 }
1284 
1285 //
1286 // Update BgpIfmapInstanceConfig based on a new autogen::RoutingInstance object.
1287 //
1288 // Rebuild the import and export route target lists and update the virtual
1289 // network information.
1290 //
1291 // Targets that are configured on this routing-instance (which corresponds
1292 // to all adjacencies to instance-target) are added to the import list or
1293 // export list or both depending on the import_export attribute.
1294 //
1295 // Export targets for all other routing-instances that we are connected to
1296 // are added to our import list.
1297 //
1299  const autogen::RoutingInstance *config) {
1301  BgpInstanceConfig::AggregateRouteList inet6_aggregate_list;
1302  BgpInstanceConfig::AggregateRouteList inet_aggregate_list;
1303  RoutingPolicyConfigList policy_list;
1304  data_.Clear();
1305 
1306  DBGraph *graph = manager->graph();
1308  for (DBGraphVertex::adjacency_iterator iter = node->begin(graph);
1309  iter != node->end(graph); ++iter) {
1310  IFMapNode *adj = static_cast<IFMapNode *>(iter.operator->());
1311  if (strcmp(adj->table()->Typename(), "instance-target") == 0) {
1312  string target;
1313  if (GetInstanceTargetRouteTarget(graph, adj, &target)) {
1314  const autogen::InstanceTarget *itarget =
1315  dynamic_cast<autogen::InstanceTarget *>(adj->GetObject());
1316  if (!itarget)
1317  continue;
1318  const autogen::InstanceTargetType &itt = itarget->data();
1319  if (itt.import_export == "import") {
1320  import_list.insert(target);
1321  } else if (itt.import_export == "export") {
1322  export_list.insert(target);
1323  } else {
1324  import_list.insert(target);
1325  export_list.insert(target);
1326  }
1327  }
1328  } else if (strcmp(adj->table()->Typename(),
1329  "routing-policy-routing-instance") == 0) {
1330  RoutingPolicyAttachInfo policy_info;
1331  if (GetRoutingInstanceRoutingPolicy(graph, adj, &policy_info)) {
1332  policy_list.push_back(policy_info);
1333  }
1334  } else if (strcmp(adj->table()->Typename(), "route-aggregate") == 0) {
1335  GetRouteAggregateConfig(graph, adj, &inet_aggregate_list,
1336  &inet6_aggregate_list);
1337  } else if (strcmp(adj->table()->Typename(), "connection") == 0) {
1338  vector<string> target_list;
1339  GetConnectionExportTargets(graph, node, name_, adj, &target_list);
1340  BOOST_FOREACH(string target, target_list) {
1341  import_list.insert(target);
1342  }
1343  } else if (strcmp(adj->table()->Typename(), "virtual-network") == 0) {
1344  data_.set_virtual_network(adj->name());
1347  GetVirtualNetworkAllowTransit(graph, adj));
1350  GetVirtualNetworkPbbEvpnEnable(graph, adj));
1352  }
1353  }
1354 
1358 
1359  sort(policy_list.begin(), policy_list.end(), CompareRoutingPolicyOrder);
1360  data_.swap_routing_policy_list(&policy_list);
1361  data_.swap_aggregate_routes(Address::INET, &inet_aggregate_list);
1362  data_.swap_aggregate_routes(Address::INET6, &inet6_aggregate_list);
1363 
1364  if (config) {
1365  data_.set_has_pnf(config->has_pnf());
1366  SetStaticRouteConfig(&data_, config);
1367  SetServiceChainConfig(&data_, config);
1368  }
1369 }
1370 
1371 //
1372 // Reset IFMap related state in the BgpIfmapInstanceConfig.
1373 //
1375  node_proxy_.Clear();
1376 }
1377 
1378 //
1379 // Return true if the BgpIfmapInstanceConfig is ready to be deleted. The
1380 // caller is responsible for actually deleting it.
1381 //
1384  return false;
1385  }
1386  if (node() != NULL || protocol_.get() != NULL) {
1387  return false;
1388  }
1389  if (!neighbors_.empty() || !peerings_.empty() ||
1390  !routing_policies_.empty()) {
1391  return false;
1392  }
1393 
1395  return true;
1396 }
1397 
1398 //
1399 // Add a BgpNeighborConfig to this BgpIfmapInstanceConfig.
1400 //
1401 // The BgpNeighborConfig is added to the NeighborMap and the BgpConfigManager
1402 // is notified.
1403 //
1405  BgpNeighborConfig *neighbor) {
1407  Create, manager->server(), neighbor, SandeshLevel::SYS_DEBUG,
1409  neighbor->admin_down(),
1410  neighbor->passive(),
1412  neighbor->local_as(),
1413  neighbor->peer_address().to_string(), neighbor->peer_as(),
1414  neighbor->GetAddressFamilies(), neighbor->AuthKeyTypeToString(),
1415  neighbor->AuthKeysToString());
1416  neighbors_.insert(make_pair(neighbor->name(), neighbor));
1417  data_.add_neighbor(neighbor->name());
1418  manager->Notify(neighbor, BgpConfigManager::CFG_ADD);
1419 }
1420 
1421 //
1422 // Change a BgpNeighborConfig that's already in this BgpIfmapInstanceConfig.
1423 //
1425  BgpNeighborConfig *neighbor) {
1426  NeighborMap::iterator loc = neighbors_.find(neighbor->name());
1427  assert(loc != neighbors_.end());
1428  loc->second = neighbor;
1429 
1431  Update, manager->server(), neighbor,
1432  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
1433  neighbor->admin_down(),
1434  neighbor->passive(),
1436  neighbor->local_as(),
1437  neighbor->peer_address().to_string(), neighbor->peer_as(),
1438  neighbor->GetAddressFamilies(), neighbor->AuthKeyTypeToString(),
1439  neighbor->AuthKeysToString());
1440  manager->Notify(neighbor, BgpConfigManager::CFG_CHANGE);
1441 }
1442 
1443 //
1444 // Delete a BgpNeighborConfig from this BgpIfmapInstanceConfig.
1445 //
1446 // The BgpConfigManager is notified and BgpNeighborConfig is removed from the
1447 // NeighborMap. Note that the caller is responsible for actually deleting the
1448 // BgpNeighborConfig object.
1449 //
1451  BgpNeighborConfig *neighbor) {
1452  BGP_CONFIG_LOG_NEIGHBOR(Delete, manager->server(), neighbor,
1453  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL);
1454  manager->Notify(neighbor, BgpConfigManager::CFG_DELETE);
1455  neighbors_.erase(neighbor->name());
1456  data_.delete_neighbor(neighbor->name());
1457 }
1458 
1459 //
1460 // Find the BgpNeighborConfig by name in this BgpIfmapInstanceConfig.
1461 //
1463  const string &name) const {
1464  NeighborMap::const_iterator loc;
1465 
1466  if (name.find(name_) == string::npos) {
1467  string fqn(name_);
1468  fqn += ":";
1469  fqn += name;
1470  loc = neighbors_.find(fqn);
1471  } else {
1472  loc = neighbors_.find(name);
1473  }
1474 
1475  return loc != neighbors_.end() ? loc->second : NULL;
1476 }
1477 
1478 //
1479 // Add a BgpPeeringConfig to this BgpIfmapInstanceConfig.
1480 //
1482  peerings_.insert(make_pair(peering->name(), peering));
1483 }
1484 
1485 //
1486 // Delete a BgpPeeringConfig from this BgpIfmapInstanceConfig.
1487 //
1489  peerings_.erase(peering->name());
1490 }
1491 
1492 //
1493 // Add a BgpIfmapRoutingPolicyConfig to this BgpIfmapInstanceConfig.
1494 //
1497  routing_policies_.insert(make_pair(rtp->name(), rtp));
1498 }
1499 
1500 //
1501 // Delete a BgpIfmapRoutingPolicyConfig from this BgpIfmapInstanceConfig.
1502 //
1505  routing_policies_.erase(rtp->name());
1506 }
1507 
1509  BgpIfmapConfigManager* manager,
1510  uint32_t new_id, uint32_t old_id,
1511  uint32_t new_as, uint32_t old_as) {
1512  assert(new_id != old_id || new_as != old_as);
1513  for (unsigned int i = 0; i < instances_.size(); i++) {
1514  BgpIfmapInstanceConfig * ifmap_config = instances_.At(i);
1515  if (!ifmap_config)
1516  continue;
1517  if (new_id != old_id)
1518  ifmap_config->ProcessIdentifierUpdate(new_id, old_id);
1519  if (new_as != old_as)
1520  ifmap_config->ProcessASUpdate(new_as, old_as);
1521  manager->UpdateInstanceConfig(ifmap_config,
1523  }
1524 }
1525 
1526 //
1527 // Constructor for BgpIfmapConfigData.
1528 //
1530  // Reserve bit 0 for master instance
1532 }
1533 
1534 //
1535 // Destructor for BgpConfigData.
1536 //
1538  instances_.clear();
1542 }
1543 
1544 //
1545 // Locate the BgpIfmapInstanceConfig by name, create it if not found. The newly
1546 // created BgpIfmapInstanceConfig gets added to the IfmapInstanceMap.
1547 //
1548 // Note that we do not have the IFMapNode representing the routing-instance
1549 // at this point.
1550 //
1552  BgpIfmapInstanceConfig *rti = FindInstance(name);
1553  if (rti != NULL) {
1554  return rti;
1555  }
1556  rti = new BgpIfmapInstanceConfig(name);
1557  int index = -1;
1558  if (name == BgpConfigManager::kMasterInstance) {
1559  index = 0;
1560  }
1561  index = instances_.Insert(name, rti, index);
1562  rti->set_index(index);
1563  pair<BgpInstanceMap::iterator, bool> result2 =
1564  instance_config_map_.insert(
1565  make_pair(name, rti->instance_config()));
1566  assert(result2.second);
1567  return rti;
1568 }
1569 
1570 //
1571 // Remove the given BgpIfmapInstanceConfig from the IfmapInstanceMap
1572 // and delete it.
1573 //
1575  BgpInstanceMap::iterator loc2 = instance_config_map_.find(rti->name());
1576  assert(loc2 != instance_config_map_.end());
1577  instance_config_map_.erase(loc2);
1578  instances_.Remove(rti->name(), rti->index(), false);
1579 }
1580 
1581 //
1582 // Find the BgpIfmapInstanceConfig by name.
1583 //
1585  return instances_.Find(name);
1586 }
1587 
1588 //
1589 // Find the BgpIfmapInstanceConfig by name.
1590 // Const version.
1591 //
1593  const string &name) const {
1594  return instances_.Find(name);
1595 }
1596 
1599  return make_pair(neighbors_.begin(), neighbors_.end());
1600 }
1601 
1602 //
1603 // Create a new BgpIfmapRoutingPolicyLinkConfig.
1604 //
1605 // The IFMapNodeProxy is a proxy for the IFMapNode which is the midnode that
1606 // represents the routing-policy-routing-instance. The newly created
1607 // BgpIfmapRoutingPolicyLinkConfig gets added to the IfmapRoutingPolicyLinkMap.
1608 //
1611  IFMapNodeProxy *proxy) {
1612  BgpIfmapRoutingPolicyLinkConfig *ri_rp_link =
1613  new BgpIfmapRoutingPolicyLinkConfig(rti, rtp);
1614  ri_rp_link->SetNodeProxy(proxy);
1615  pair<IfmapRoutingPolicyLinkMap::iterator, bool> result =
1616  ri_rp_links_.insert(make_pair(ri_rp_link->node()->name(), ri_rp_link));
1617  assert(result.second);
1618  ri_rp_link->instance()->AddRoutingPolicy(rtp);
1619  ri_rp_link->policy()->AddInstance(rti);
1620  return ri_rp_link;
1621 }
1622 
1623 //
1624 // Delete a BgpIfmapRoutingPolicyLinkConfig.
1625 //
1626 // The BgpIfmapRoutingPolicyLinkConfig is erased from IfmapRoutingPolicyLinkMap
1627 // and then deleted.
1628 // Note that the reference to the IFMapNode for routing-policy-routing-instance
1629 // gets released via the destructor when the IFMapNodeProxy is destroyed.
1630 //
1632  BgpIfmapRoutingPolicyLinkConfig *ri_rp_link) {
1633  ri_rp_links_.erase(ri_rp_link->node()->name());
1634  ri_rp_link->instance()->DeleteRoutingPolicy(ri_rp_link->policy());
1635  ri_rp_link->policy()->RemoveInstance(ri_rp_link->instance());
1636  delete ri_rp_link;
1637 }
1638 
1639 //
1640 // Find the BgpIfmapRoutingPolicyLinkConfig by name.
1641 //
1643  const string &name) {
1644  IfmapRoutingPolicyLinkMap::iterator loc = ri_rp_links_.find(name);
1645  if (loc != ri_rp_links_.end()) {
1646  return loc->second;
1647  }
1648  return NULL;
1649 }
1650 
1651 //
1652 // Find the BgpIfmapRoutingPolicyLinkConfig by name.
1653 // Const version.
1654 //
1656 BgpIfmapConfigData::FindRoutingPolicyLink(const string &name) const {
1657  IfmapRoutingPolicyLinkMap::const_iterator loc = ri_rp_links_.find(name);
1658  if (loc != ri_rp_links_.end()) {
1659  return loc->second;
1660  }
1661  return NULL;
1662 }
1663 
1664 //
1665 // Create a new BgpIfmapPeeringConfig.
1666 //
1667 // The IFMapNodeProxy is a proxy for the IFMapNode which is the
1668 // midnode that represents the bgp-peering. The newly created
1669 // BgpIfmapPeeringConfig gets added to the IfmapPeeringMap.
1670 //
1672  BgpIfmapInstanceConfig *rti, IFMapNodeProxy *proxy) {
1673  BgpIfmapPeeringConfig *peering = new BgpIfmapPeeringConfig(rti);
1674  peering->SetNodeProxy(proxy);
1675  pair<IfmapPeeringMap::iterator, bool> result =
1676  peerings_.insert(make_pair(peering->node()->name(), peering));
1677  assert(result.second);
1678  peering->instance()->AddPeering(peering);
1679  BGP_LOG_STR(BgpConfig, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_SYSLOG,
1680  "Creating BgpIfmapPeering " << peering->node()->name());
1681  return peering;
1682 }
1683 
1684 //
1685 // Delete a BgpPeeringConfig.
1686 //
1687 // The BgpPeeringConfig is removed from the IfmapPeeringMap and then deleted.
1688 // Note that the reference to the IFMapNode for the bgp-peering gets released
1689 // via the destructor when the IFMapNodeProxy is destroyed.
1690 //
1692  BGP_LOG_STR(BgpConfig, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_SYSLOG,
1693  "Deleting BgpIfmapPeering " << peering->node()->name());
1694  peering->instance()->DeletePeering(peering);
1695  peerings_.erase(peering->node()->name());
1696  delete peering;
1697 }
1698 
1699 //
1700 // Find the BgpPeeringConfig by name.
1701 //
1703  IfmapPeeringMap::iterator loc = peerings_.find(name);
1704  if (loc != peerings_.end()) {
1705  return loc->second;
1706  }
1707  return NULL;
1708 }
1709 
1710 //
1711 // Find the BgpPeeringConfig by name.
1712 // Const version.
1713 //
1715  const string &name) const {
1716  IfmapPeeringMap::const_iterator loc = peerings_.find(name);
1717  if (loc != peerings_.end()) {
1718  return loc->second;
1719  }
1720  return NULL;
1721 }
1722 
1724 BgpIfmapConfigData::InstanceMapItems(const string &start_name) const {
1725  return make_pair(instance_config_map_.lower_bound(start_name),
1726  instance_config_map_.end());
1727 }
1728 
1730 BgpIfmapConfigData::RoutingPolicyMapItems(const string &start_name) const {
1731  return make_pair(routing_policy_config_map_.lower_bound(start_name),
1733 }
1734 
1735 //
1736 // Locate the BgpIfmapRoutingPolicyConfig by name, create it if not found.
1737 // The newly created BgpIfmapRoutingPolicyConfig gets added to the
1738 // IfmapRoutingPolicyMap.
1739 //
1741  const string &name) {
1743  if (rtp != NULL) {
1744  return rtp;
1745  }
1746  rtp = new BgpIfmapRoutingPolicyConfig(name);
1747  pair<IfmapRoutingPolicyMap::iterator, bool> result =
1748  routing_policies_.insert(make_pair(name, rtp));
1749  assert(result.second);
1750  pair<BgpRoutingPolicyMap::iterator, bool> result2 =
1752  make_pair(name, rtp->routing_policy_config()));
1753  assert(result2.second);
1754  return rtp;
1755 }
1756 
1757 //
1758 // Remove the given BgpIfmapRoutingPolicyConfig from the IfmapRoutingPolicyMap
1759 // and delete it.
1760 //
1762  IfmapRoutingPolicyMap::iterator loc = routing_policies_.find(rtp->name());
1763  assert(loc != routing_policies_.end());
1764  routing_policies_.erase(loc);
1765  BgpRoutingPolicyMap::iterator loc2 =
1766  routing_policy_config_map_.find(rtp->name());
1767  assert(loc2 != routing_policy_config_map_.end());
1768  routing_policy_config_map_.erase(loc2);
1769  delete rtp;
1770 }
1771 
1773  const string &name) {
1774  IfmapRoutingPolicyMap::iterator loc = routing_policies_.find(name);
1775  if (loc != routing_policies_.end()) {
1776  return loc->second;
1777  }
1778  return NULL;
1779 }
1780 
1782  const string &name) const {
1783  IfmapRoutingPolicyMap::const_iterator loc = routing_policies_.find(name);
1784  if (loc != routing_policies_.end()) {
1785  return loc->second;
1786  }
1787  return NULL;
1788 }
1789 
1790 //
1791 // Constructor for BgpIfmapConfigManager.
1792 //
1794  : BgpConfigManager(server),
1795  db_(NULL),
1796  db_graph_(NULL),
1797  trigger_(boost::bind(&BgpIfmapConfigManager::ConfigHandler, this),
1798  TaskScheduler::GetInstance()->GetTaskId("bgp::Config"),
1799  kConfigTaskInstanceId),
1800  listener_(new BgpConfigListener(this)),
1801  config_(new BgpIfmapConfigData()) {
1803 }
1804 
1805 //
1806 // Destructor for BgpIfmapConfigManager.
1807 //
1809 }
1810 
1811 //
1812 // Initialize the BgpConfigManager.
1813 //
1815  const string &localname) {
1816  db_ = db;
1817  db_graph_ = db_graph;
1819  listener_->Initialize();
1820  DefaultConfig();
1821 }
1822 
1823 //
1824 // Used to trigger a build and subsequent evaluation of the ChangeList.
1825 //
1827  CHECK_CONCURRENCY("db::IFMapTable");
1828  trigger_.Set();
1829 }
1830 
1832 BgpIfmapConfigManager::InstanceMapItems(const string &start_name) const {
1833  return config_->InstanceMapItems(start_name);
1834 }
1835 
1837 BgpIfmapConfigManager::RoutingPolicyMapItems(const string &start_name) const {
1838  return config_->RoutingPolicyMapItems(start_name);
1839 }
1840 
1843  const string &instance_name) const {
1844  static BgpConfigManager::NeighborMap nilMap;
1845  BgpIfmapInstanceConfig *rti = config_->FindInstance(instance_name);
1846  if (rti == NULL) {
1847  return make_pair(nilMap.begin(), nilMap.end());
1848  }
1849  return rti->NeighborMapItems();
1850 }
1851 
1853  config()->instances().ResetBit(index);
1854 }
1855 
1857  const string &instance_name) const {
1858  BgpIfmapInstanceConfig *rti = config_->FindInstance(instance_name);
1859  if (rti == NULL) {
1860  return 0;
1861  }
1862  return rti->neighbors().size();
1863 }
1864 
1865 //
1866 // Constructor for BgpIfmapRoutingPolicyConfig.
1867 //
1869  const string &name)
1870  : name_(name),
1871  data_(name) {
1872 }
1873 
1874 //
1875 // Destructor for BgpIfmapRoutingPolicyConfig.
1876 //
1878 }
1879 
1880 //
1881 // Set the IFMapNodeProxy for the BgpIfmapRoutingPolicyConfig.
1882 //
1884  if (proxy != NULL) {
1885  node_proxy_.Swap(proxy);
1886  }
1887 }
1888 
1891  routing_policy_.reset();
1892 }
1893 
1894 //
1895 // Return true if the BgpIfmapRoutingPolicyConfig is ready to be deleted.
1896 // The caller is responsible for actually deleting it.
1897 //
1899  if (node() != NULL) {
1900  return false;
1901  }
1902  if (!instances_.empty()) {
1903  return false;
1904  }
1905 
1906  Delete(manager);
1907  return true;
1908 }
1909 
1910 //
1911 // Add a BgpIfmapInstanceConfig to BgpIfmapRoutingPolicyConfig.
1912 //
1914  instances_.insert(make_pair(rti->name(), rti));
1915 }
1916 
1917 //
1918 // Remove a BgpIfmapInstanceConfig to BgpIfmapRoutingPolicyConfig.
1919 //
1921  instances_.erase(rti->name());
1922 }
1923 
1924 
1925 static void BuildPolicyTermConfig(autogen::PolicyTermType cfg_term,
1926  RoutingPolicyTermConfig *term) {
1927  term->match.protocols_match = cfg_term.term_match_condition.protocol;
1928  BOOST_FOREACH(const autogen::PrefixMatchType &prefix_match,
1929  cfg_term.term_match_condition.prefix) {
1930  string prefix_type(prefix_match.prefix_type);
1931  PrefixMatchConfig match(prefix_match.prefix,
1932  prefix_type.empty() ? "exact" : prefix_type);
1933  term->match.prefixes_to_match.push_back(match);
1934  }
1935  term->match.community_match_all =
1936  cfg_term.term_match_condition.community_match_all;
1937  if (!cfg_term.term_match_condition.community_list.empty()) {
1938  term->match.community_match =
1939  cfg_term.term_match_condition.community_list;
1940  }
1941  if (!cfg_term.term_match_condition.community.empty()) {
1942  term->match.community_match.push_back(
1943  cfg_term.term_match_condition.community);
1944  }
1946  cfg_term.term_match_condition.extcommunity_match_all;
1947  if (!cfg_term.term_match_condition.extcommunity_list.empty()) {
1948  term->match.ext_community_match =
1949  cfg_term.term_match_condition.extcommunity_list;
1950  }
1951 
1952  BOOST_FOREACH(uint32_t asn,
1953  cfg_term.term_action_list.update.as_path.expand.asn_list) {
1954  term->action.update.aspath_expand.push_back(asn);
1955  }
1956  BOOST_FOREACH(const string community,
1957  cfg_term.term_action_list.update.community.add.community) {
1958  term->action.update.community_add.push_back(community);
1959  }
1960  BOOST_FOREACH(const string community,
1961  cfg_term.term_action_list.update.community.remove.community) {
1962  term->action.update.community_remove.push_back(community);
1963  }
1964  BOOST_FOREACH(const string community,
1965  cfg_term.term_action_list.update.community.set.community) {
1966  term->action.update.community_set.push_back(community);
1967  }
1968  BOOST_FOREACH(const string community,
1969  cfg_term.term_action_list.update.extcommunity.add.community) {
1970  term->action.update.ext_community_add.push_back(community);
1971  }
1972  BOOST_FOREACH(const string community,
1973  cfg_term.term_action_list.update.extcommunity.remove.community) {
1974  term->action.update.ext_community_remove.push_back(community);
1975  }
1976  BOOST_FOREACH(const string community,
1977  cfg_term.term_action_list.update.extcommunity.set.community) {
1978  term->action.update.ext_community_set.push_back(community);
1979  }
1980  term->action.update.local_pref =
1981  cfg_term.term_action_list.update.local_pref;
1982  term->action.update.med = cfg_term.term_action_list.update.med;
1983 
1985  if (strcmp(cfg_term.term_action_list.action.c_str(), "reject") == 0) {
1987  } else if (
1988  strcmp(cfg_term.term_action_list.action.c_str(), "accept") == 0) {
1990  }
1991 }
1992 
1994  const autogen::RoutingPolicy *policy) {
1995  vector<autogen::PolicyTermType> terms = policy->entries();
1996  BOOST_FOREACH(autogen::PolicyTermType cfg_term, terms) {
1997  RoutingPolicyTermConfig policy_term_cfg;
1998  BuildPolicyTermConfig(cfg_term, &policy_term_cfg);
1999  policy_cfg->add_term(policy_term_cfg);
2000  }
2001 }
2002 
2004  const autogen::RoutingPolicy *policy) {
2005  routing_policy_.reset(policy);
2006  data_.Clear();
2007  if (policy) {
2008  BuildPolicyTermsConfig(&data_, policy);
2009  }
2010 }
2011 
2012 //
2013 // Reset IFMap related state in the BgpIfmapRoutingPolicyConfig.
2014 //
2016  node_proxy_.Clear();
2017 }
2018 
2020  const string &name) const {
2021  BgpIfmapRoutingPolicyConfig *rtp = config_->FindRoutingPolicy(name);
2022  if (rtp == NULL) {
2023  return NULL;
2024  }
2025  return rtp->routing_policy_config();
2026 }
2027 
2029  const string &name) const {
2030  BgpIfmapInstanceConfig *rti = config_->FindInstance(name);
2031  if (rti == NULL) {
2032  return NULL;
2033  }
2034  return rti->instance_config();
2035 }
2036 
2038  const string &instance_name) const {
2039  BgpIfmapInstanceConfig *rti = config_->FindInstance(instance_name);
2040  if (rti == NULL) {
2041  return NULL;
2042  }
2043  const BgpIfmapProtocolConfig *proto = rti->protocol_config();
2044  if (proto == NULL) {
2045  return NULL;
2046  }
2047  return proto->protocol_config();
2048 }
2049 
2051  const string &instance_name, const string &name) const {
2052  BgpIfmapInstanceConfig *rti = config_->FindInstance(instance_name);
2053  if (rti == NULL) {
2054  return NULL;
2055  }
2056  return rti->FindNeighbor(name);
2057 }
2058 
2059 //
2060 // Initialize autogen::BgpRouterParams with default values.
2061 //
2063  autogen::BgpRouterParams *param) {
2064  param->Clear();
2065  param->autonomous_system = BgpConfigManager::kDefaultAutonomousSystem;
2066  param->port = BgpConfigManager::kDefaultPort;
2067 }
2068 
2069 //
2070 // Create BgpInsatnceConfig for master routing-instance. This
2071 // includes the BgpIfmapProtocolConfig for the local bgp-router in the
2072 // master routing-instance.
2073 //
2075  BgpIfmapInstanceConfig *rti = config_->LocateInstance(kMasterInstance);
2076  unique_ptr<autogen::BgpRouter> router(new autogen::BgpRouter());
2077  autogen::BgpRouterParams param;
2078  DefaultBgpRouterParams(&param);
2079  router->SetProperty("bgp-router-parameters", &param);
2080  BgpIfmapProtocolConfig *protocol = rti->LocateProtocol();
2081  protocol->Update(this, router.release());
2083 
2084  vector<string> import_list;
2085  vector<string> export_list;
2087  Create, server(), rti, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
2088  import_list, export_list,
2089  rti->virtual_network(), rti->virtual_network_index());
2090 
2092  Create, server(), protocol,
2093  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
2094  protocol->router_params().admin_down,
2095  protocol->router_params().autonomous_system,
2096  protocol->router_params().identifier,
2097  protocol->router_params().address,
2098  protocol->router_params().hold_time,
2099  vector<string>());
2100 }
2101 
2103  const autogen::GlobalSystemConfig *system) {
2104  bool changed = false;
2105 
2106  if (data_.gr_enable() != system->graceful_restart_parameters().enable) {
2107  data_.set_gr_enable(system->graceful_restart_parameters().enable);
2108  changed |= true;
2109  }
2110 
2111  if (data_.gr_time() != system->graceful_restart_parameters().restart_time) {
2112  data_.set_gr_time(system->graceful_restart_parameters().restart_time);
2113  changed |= true;
2114  }
2115 
2116  if (data_.llgr_time() != static_cast<uint32_t>(
2117  system->graceful_restart_parameters().long_lived_restart_time)) {
2119  system->graceful_restart_parameters().long_lived_restart_time);
2120  changed |= true;
2121  }
2122 
2123  if (data_.end_of_rib_timeout() !=
2124  system->graceful_restart_parameters().end_of_rib_timeout) {
2126  system->graceful_restart_parameters().end_of_rib_timeout);
2127  changed |= true;
2128  }
2129 
2130  if (data_.gr_bgp_helper() !=
2131  system->graceful_restart_parameters().bgp_helper_enable) {
2133  system->graceful_restart_parameters().bgp_helper_enable);
2134  changed |= true;
2135  }
2136 
2137  if (data_.gr_xmpp_helper() !=
2138  system->graceful_restart_parameters().xmpp_helper_enable) {
2140  system->graceful_restart_parameters().xmpp_helper_enable);
2141  changed |= true;
2142  }
2143 
2144  if (data_.enable_4byte_as() != system->enable_4byte_as()) {
2145  data_.set_enable_4byte_as(system->enable_4byte_as());
2146  changed |= true;
2147  }
2148 
2149  if (data_.always_compare_med() != system->bgp_always_compare_med()) {
2150  data_.set_always_compare_med(system->bgp_always_compare_med());
2151  changed |= true;
2152  }
2153 
2154  if (data_.rd_cluster_seed() != system->rd_cluster_seed()) {
2155  data_.set_rd_cluster_seed(system->rd_cluster_seed());
2156  changed |= true;
2157  }
2158 
2159  if (data_.xmpp_hold_time() !=
2160  system->fast_convergence_parameters().xmpp_hold_time) {
2162  system->fast_convergence_parameters().xmpp_hold_time);
2163  changed |= true;
2164  }
2165 
2166  if (data_.bgpaas_port_start() != system->bgpaas_parameters().port_start) {
2167  data_.set_bgpaas_port_start(system->bgpaas_parameters().port_start);
2168  changed |= true;
2169  }
2170 
2171  if (data_.bgpaas_port_end() != system->bgpaas_parameters().port_end) {
2172  data_.set_bgpaas_port_end(system->bgpaas_parameters().port_end);
2173  changed |= true;
2174  }
2175 
2176  if (data_.fc_enabled() != system->fast_convergence_parameters().enable) {
2177  data_.set_fc_enabled(system->fast_convergence_parameters().enable);
2178  changed |= true;
2179  }
2180 
2181  if (data_.nh_check_enabled() !=
2182  system->fast_convergence_parameters().nh_reachability_check) {
2184  system->fast_convergence_parameters().nh_reachability_check);
2185  changed |= true;
2186  }
2187 
2188  if (data_.all_tags_are_global() != system->bgp_all_tags_are_global()) {
2189  data_.set_all_tags_are_global(system->bgp_all_tags_are_global());
2190  changed |= true;
2191  }
2192 
2193  return changed;
2194 }
2195 
2197  const autogen::GlobalQosConfig *qos) {
2198  bool changed = false;
2199  const autogen::ControlTrafficDscpType &dscp = qos->control_traffic_dscp();
2200 
2201  if (data_.control_dscp() != dscp.control) {
2202  data_.set_control_dscp(dscp.control);
2203  Sandesh::SetDscpValue(dscp.control);
2204  changed = true;
2205  }
2206  if (data_.analytics_dscp() != dscp.analytics) {
2207  data_.set_analytics_dscp(dscp.analytics);
2208  changed = true;
2209  }
2210  return changed;
2211 }
2212 
2213 //
2214 // Initialize IdentifierMap with handlers for interesting identifier types.
2215 //
2216 // The IdentifierMap is used when processing BgpConfigDeltas generated by
2217 // the BgpConfigListener.
2218 //
2220  id_map_.insert(make_pair("routing-instance",
2222  this, _1)));
2223  id_map_.insert(make_pair("routing-policy",
2224  boost::bind(&BgpIfmapConfigManager::ProcessRoutingPolicy, this, _1)));
2225  id_map_.insert(make_pair("routing-policy-routing-instance",
2227  _1)));
2228  id_map_.insert(make_pair("bgp-router",
2229  boost::bind(&BgpIfmapConfigManager::ProcessBgpRouter, this, _1)));
2230  id_map_.insert(make_pair("bgp-peering",
2231  boost::bind(&BgpIfmapConfigManager::ProcessBgpPeering, this, _1)));
2232  id_map_.insert(make_pair("global-system-config",
2234  _1)));
2235  id_map_.insert(make_pair("global-qos-config",
2237  _1)));
2238 }
2239 
2242  if (!rti) {
2243  return;
2244  }
2245 
2246  // in case of id change, update import list and call subsequent code
2247  Notify(rti->instance_config(), event);
2248 
2249  vector<string> import_rt(rti->import_list().begin(),
2250  rti->import_list().end());
2251  vector<string> export_rt(rti->export_list().begin(),
2252  rti->export_list().end());
2253  if (event == BgpConfigManager::CFG_ADD) {
2254  BGP_CONFIG_LOG_INSTANCE(Create, server(), rti,
2255  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
2256  import_rt, export_rt,
2257  rti->virtual_network(), rti->virtual_network_index());
2258  } else {
2259  BGP_CONFIG_LOG_INSTANCE(Update, server(), rti,
2260  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
2261  import_rt, export_rt,
2262  rti->virtual_network(), rti->virtual_network_index());
2263  }
2264 }
2265 
2266 //
2267 // Handler for routing-instance objects.
2268 //
2269 // Note that BgpIfmapInstanceConfig object for the master instance is created
2270 // before we have received any configuration for it i.e. there's no IFMapNode
2271 // or autogen::RoutingInstance for it. However, we will eventually receive a
2272 // delta for the master. The IFMapNodeProxy and autogen::RoutingInstance are
2273 // set at that time.
2274 //
2275 // For other routing-instances BgpIfmapConfigInstance can get created before we
2276 // see the IFMapNode for the routing-instance if we see the IFMapNode for the
2277 // local bgp-router in the routing-instance. In this case, the IFMapNodeProxy
2278 // and autogen::RoutingInstance are set when we later see the IFMapNode for the
2279 // routing-instance.
2280 //
2281 // In all other cases, BgpIfmapConfigInstance is created when we see IFMapNode
2282 // for the routing-instance. The IFMapNodeProxy and autogen::RoutingInstance
2283 // are set right away.
2284 //
2285 // References to the IFMapNode and the autogen::RoutingInstance are
2286 // released when the IFMapNode is marked deleted. However the
2287 // BgpIfmapInstanceConfig does not get deleted till the NeighborMap is
2288 // empty and the BgpIfmapProtocolConfig is gone.
2289 //
2291  const BgpConfigDelta &delta) {
2292  CHECK_CONCURRENCY("bgp::Config");
2293 
2295  string instance_name = delta.id_name;
2296  BgpIfmapInstanceConfig *rti = config_->FindInstance(instance_name);
2297  if (rti == NULL) {
2298  IFMapNodeProxy *proxy = delta.node.get();
2299  if (proxy == NULL) {
2300  return;
2301  }
2302  IFMapNode *node = proxy->node();
2303  if (node == NULL || node->IsDeleted()) {
2304  return;
2305  }
2306  event = BgpConfigManager::CFG_ADD;
2307  rti = config_->LocateInstance(instance_name);
2308  rti->SetNodeProxy(proxy);
2309  } else {
2310  IFMapNode *node = rti->node();
2311  if (node == NULL) {
2312  IFMapNodeProxy *proxy = delta.node.get();
2313  if (proxy == NULL) {
2314  return;
2315  }
2316  rti->SetNodeProxy(proxy);
2317  } else if (node->IsDeleted()) {
2318  rti->ResetConfig();
2319  if (rti->DeleteIfEmpty(this)) {
2321  Delete, server(), rti,
2322  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL);
2323  config_->DeleteInstance(rti);
2324  }
2325  return;
2326  }
2327  }
2328 
2329  autogen::RoutingInstance *rti_config =
2330  static_cast<autogen::RoutingInstance *>(delta.obj.get());
2331  if (rti->index() != -1)
2332  rti->instance_config()->set_index(rti->index());
2333  rti->Update(this, rti_config);
2334  UpdateInstanceConfig(rti, event);
2335 }
2336 
2337 //
2338 // Handler for bgp protocol config.
2339 //
2340 // Note that there's no underlying IFMap object for the bgp protocol config.
2341 // This is called by the handler for bgp-router objects. The BgpConfigDelta
2342 // is a delta for the bgp-router object.
2343 //
2345  CHECK_CONCURRENCY("bgp::Config");
2346 
2348  string instance_name(IdentifierParent(delta.id_name));
2349  BgpIfmapInstanceConfig *rti = config_->FindInstance(instance_name);
2350  BgpIfmapProtocolConfig *protocol = NULL;
2351  if (rti != NULL) {
2352  protocol = rti->protocol_config_mutable();
2353  }
2354 
2355  if (protocol == NULL) {
2356  IFMapNodeProxy *proxy = delta.node.get();
2357  if (proxy == NULL) {
2358  return;
2359  }
2360  // ignore identifier with no properties
2361  if (delta.obj.get() == NULL) {
2362  return;
2363  }
2364  IFMapNode *node = proxy->node();
2365  if (node == NULL || node->IsDeleted()) {
2366  return;
2367  }
2368  event = BgpConfigManager::CFG_ADD;
2369  if (rti == NULL) {
2370  rti = config_->LocateInstance(instance_name);
2371  UpdateInstanceConfig(rti, event);
2372  }
2373  protocol = rti->LocateProtocol();
2374  protocol->SetNodeProxy(proxy);
2375  } else {
2376  IFMapNode *node = protocol->node();
2377  if (node == NULL) {
2378  // The master instance creates a BgpRouter node internally. Ignore
2379  // an update that doesn't specify any content.
2380  if (delta.obj.get() == NULL) {
2381  return;
2382  }
2383  protocol->SetNodeProxy(delta.node.get());
2384  } else if (delta.obj.get() == NULL) {
2385  BGP_CONFIG_LOG_PROTOCOL(Delete, server(), protocol,
2386  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL);
2387  protocol->Delete(this);
2388  rti->ResetProtocol();
2389  if (rti->DeleteIfEmpty(this)) {
2390  BGP_CONFIG_LOG_INSTANCE(Delete, server(), rti,
2391  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL);
2392  config_->DeleteInstance(rti);
2393  }
2394  return;
2395  }
2396  }
2397 
2398  autogen::BgpRouter *rt_config =
2399  static_cast<autogen::BgpRouter *>(delta.obj.get());
2400  uint32_t old_id = protocol->protocol_config()->identifier();
2401  uint32_t old_as = protocol->protocol_config()->autonomous_system();
2402  protocol->Update(this, rt_config);
2403  uint32_t new_id = protocol->protocol_config()->identifier();
2404  uint32_t new_as = protocol->protocol_config()->autonomous_system();
2405  if (new_id != old_id || new_as != old_as) {
2406  config_->ProcessIdentifierAndASUpdate(this, new_id, old_id, new_as,
2407  old_as);
2408  }
2409  Notify(protocol->protocol_config(), event);
2410 
2411  if (!rt_config) {
2412  return;
2413  }
2414 
2415  vector<string> families(
2416  protocol->router_params().address_families.begin(),
2417  protocol->router_params().address_families.end());
2418  if (event == BgpConfigManager::CFG_ADD) {
2419  BGP_CONFIG_LOG_PROTOCOL(Create, server(), protocol,
2420  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
2421  protocol->router_params().admin_down,
2422  protocol->router_params().autonomous_system,
2423  protocol->router_params().identifier,
2424  protocol->router_params().address,
2425  protocol->router_params().hold_time,
2426  families);
2427  } else {
2428  BGP_CONFIG_LOG_PROTOCOL(Update, server(), protocol,
2429  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
2430  protocol->router_params().admin_down,
2431  protocol->router_params().autonomous_system,
2432  protocol->router_params().identifier,
2433  protocol->router_params().address,
2434  protocol->router_params().hold_time,
2435  families);
2436  }
2437 }
2438 
2439 //
2440 // Handler for routing policy objects.
2441 //
2442 // BgpConfigListener::DependencyTracker ensures associated routing instances
2443 // are present in the change list.
2444 //
2446  CHECK_CONCURRENCY("bgp::Config");
2447 
2449  string policy_name = delta.id_name;
2450  BgpIfmapRoutingPolicyConfig *rtp = config_->FindRoutingPolicy(policy_name);
2451  if (rtp == NULL) {
2452  IFMapNodeProxy *proxy = delta.node.get();
2453  if (proxy == NULL) {
2454  return;
2455  }
2456  IFMapNode *node = proxy->node();
2457  if (node == NULL || node->IsDeleted()) {
2458  return;
2459  }
2460  event = BgpConfigManager::CFG_ADD;
2461  rtp = config_->LocateRoutingPolicy(policy_name);
2462  rtp->SetNodeProxy(proxy);
2463  } else {
2464  IFMapNode *node = rtp->node();
2465  if (node == NULL) {
2466  IFMapNodeProxy *proxy = delta.node.get();
2467  if (proxy == NULL) {
2468  return;
2469  }
2470  rtp->SetNodeProxy(proxy);
2471  } else if (node->IsDeleted()) {
2472  rtp->ResetConfig();
2473  if (rtp->DeleteIfEmpty(this)) {
2474  config_->DeleteRoutingPolicy(rtp);
2475  }
2476  return;
2477  }
2478  }
2479 
2480  autogen::RoutingPolicy *rtp_config =
2481  static_cast<autogen::RoutingPolicy *>(delta.obj.get());
2482  rtp->Update(this, rtp_config);
2483  Notify(rtp->routing_policy_config(), event);
2484 }
2485 
2486 
2487 //
2488 // Handler for bgp-router objects.
2489 //
2491  CHECK_CONCURRENCY("bgp::Config");
2492 
2493  string instance_name(IdentifierParent(delta.id_name));
2494  if (instance_name.empty() ||
2495  instance_name != BgpConfigManager::kMasterInstance) {
2496  return;
2497  }
2498 
2499  // Ignore if this change is not for the local router.
2500  string name = delta.id_name.substr(instance_name.size() + 1);
2501  if (name != localname_) {
2502  return;
2503  }
2504 
2505  ProcessBgpProtocol(delta);
2506 
2507  // Update all peerings since we use local asn and identifier from master
2508  // instance for all neighbors, including those in non-master instances.
2509  BOOST_FOREACH(const BgpIfmapConfigData::IfmapPeeringMap::value_type &value,
2510  config_->peerings()) {
2511  BgpIfmapPeeringConfig *peering = value.second;
2512  peering->Update(this, peering->bgp_peering());
2513  }
2514 }
2515 
2516 //
2517 // Handler for bgp-peering objects.
2518 //
2519 // We are only interested in this bgp-peering if it is adjacent to the local
2520 // router node.
2521 //
2522 // The BgpPeeringConfig is created the first time we see the bgp-peering. It
2523 // is updated on subsequent changes and is deleted when the IFMapNode midnode
2524 // for the bgp-peering is deleted.
2525 //
2526 // Note that we are guaranteed that the IFMapNodes for the 2
2527 // bgp-routers for the bgp-peering already exist when we see the
2528 // bgp-peering. IFMap creates the nodes for the bgp-routers before
2529 // creating the midnode. This in turn guarantees that the
2530 // BgpIfmapInstanceConfig for the routing-instance also exists since we
2531 // create the BgpIfmapInstanceConfig before creating the
2532 // BgpIfmapProtocolConfig for a local bgp-router.
2533 //
2535  CHECK_CONCURRENCY("bgp::Config");
2536 
2538  BgpIfmapPeeringConfig *peering = config_->FindPeering(delta.id_name);
2539  if (peering == NULL) {
2540  IFMapNodeProxy *proxy = delta.node.get();
2541  if (proxy == NULL) {
2542  BGP_LOG_STR(BgpConfig, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_SYSLOG,
2543  "ProcessBgpPeering failed. Cannot find proxy " <<
2544  delta.id_name);
2545  return;
2546  }
2547  IFMapNode *node = proxy->node();
2548  if (node == NULL || delta.obj.get() == NULL) {
2549  BGP_LOG_STR(BgpConfig, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_SYSLOG,
2550  "ProcessBgpPeering failed. Cannot find node/obj " <<
2551  delta.id_name);
2552  return;
2553  }
2554 
2555  pair<IFMapNode *, IFMapNode *> routers;
2557  &routers)) {
2558  return;
2559  }
2560 
2561  string instance_name(IdentifierParent(routers.first->name()));
2562  BgpIfmapInstanceConfig *rti = config_->FindInstance(instance_name);
2563  event = BgpConfigManager::CFG_ADD;
2564  // Create rti if not present.
2565  if (rti == NULL) {
2566  rti = config_->LocateInstance(instance_name);
2567  UpdateInstanceConfig(rti, event);
2568  }
2569  peering = config_->CreatePeering(rti, proxy);
2570  } else {
2571  const IFMapNode *node = peering->node();
2572  assert(node != NULL);
2573  if (delta.obj.get() == NULL) {
2574  BGP_CONFIG_LOG_PEERING(Delete, server(), peering,
2575  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL);
2576  BgpIfmapInstanceConfig *rti = peering->instance();
2577  peering->Delete(this);
2578  config_->DeletePeering(peering);
2579  if (rti->DeleteIfEmpty(this)) {
2580  BGP_CONFIG_LOG_INSTANCE(Delete, server(), rti,
2581  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL);
2582  config_->DeleteInstance(rti);
2583  }
2584  return;
2585  }
2586  }
2587 
2588  if (event == BgpConfigManager::CFG_ADD) {
2589  BGP_CONFIG_LOG_PEERING(Create, server(), peering,
2590  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL);
2591  } else {
2592  BGP_CONFIG_LOG_PEERING(Update, server(), peering,
2593  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL);
2594  }
2595  autogen::BgpPeering *peering_config =
2596  static_cast<autogen::BgpPeering *>(delta.obj.get());
2597  peering->Update(this, peering_config);
2598 }
2599 
2601  const BgpConfigDelta &delta) {
2602  IFMapNodeProxy *proxy = delta.node.get();
2603  if (proxy == NULL)
2604  return;
2605 
2606  IFMapNode *node = proxy->node();
2607  autogen::GlobalSystemConfig *config, default_config;
2608  if (node == NULL || node->IsDeleted() || delta.obj.get() == NULL) {
2609  config = &default_config;
2610  } else {
2611  config = static_cast<autogen::GlobalSystemConfig *>(delta.obj.get());
2612  }
2613 
2614  if (config_->global_config()->Update(this, config))
2615  Notify(config_->global_config()->config(), BgpConfigManager::CFG_ADD);
2616 }
2617 
2619  const BgpConfigDelta &delta) {
2620  IFMapNodeProxy *proxy = delta.node.get();
2621  if (proxy == NULL)
2622  return;
2623 
2624  IFMapNode *node = proxy->node();
2625  autogen::GlobalQosConfig *config, default_config;
2626  if (node == NULL || node->IsDeleted() || delta.obj.get() == NULL) {
2627  config = &default_config;
2628  } else {
2629  config = static_cast<autogen::GlobalQosConfig *>(delta.obj.get());
2630  }
2631 
2632  if (config_->global_qos()->Update(this, config))
2633  Notify(config_->global_qos()->config(), BgpConfigManager::CFG_ADD);
2634 }
2635 
2636 //
2637 // Process the BgpConfigDeltas on the change list. We simply call the handler
2638 // for each delta based on the object's identifier type.
2639 //
2641  CHECK_CONCURRENCY("bgp::Config");
2642 
2643  for (ChangeList::const_iterator iter = change_list.begin();
2644  iter != change_list.end(); ++iter) {
2645  IdentifierMap::iterator loc = id_map_.find(iter->id_type);
2646  if (loc != id_map_.end()) {
2647  (loc->second)(*iter);
2648  }
2649  }
2650 }
2651 
2652 //
2653 // Build and process the change list of BgpConfigDeltas. The logic to build
2654 // the list is in BgpConfigListener and BgpConfigListener::DependencyTracker.
2655 //
2657  CHECK_CONCURRENCY("bgp::Config");
2658 
2659  BgpConfigListener::ChangeList change_list;
2660  listener_->GetChangeList(&change_list);
2661  ProcessChanges(change_list);
2662  return true;
2663 }
2664 
2665 //
2666 // Terminate the BgpConfigManager.
2667 //
2669  listener_->Terminate();
2670  config_.reset();
2671 }
boost::system::error_code Ip4SubnetParse(const string &str, Ip4Address *addr, int *plen)
Definition: address.cc:131
boost::system::error_code Inet6SubnetParse(const string &str, Ip6Address *addr, int *plen)
Definition: address.cc:162
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:15
boost::asio::ip::address IpAddress
Definition: address.h:13
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
std::vector< RoutingPolicyAttachInfo > RoutingPolicyConfigList
Definition: bgp_common.h:40
static bool GetRoutingInstanceRoutingPolicy(DBGraph *graph, IFMapNode *node, RoutingPolicyAttachInfo *ri_rp_link)
static string GetConnectedVxlanRiLr(DBGraph *graph, IFMapNode *node)
void DefaultAddressFamilyInit()
static void SetServiceChainConfig(BgpInstanceConfig *rti, const autogen::RoutingInstance *config)
static void BuildKeyChain(BgpNeighborConfig *neighbor, const autogen::AuthenticationData &values)
static string BgpIdentifierToString(uint32_t identifier)
static bool GetInstanceTargetRouteTarget(DBGraph *graph, IFMapNode *node, string *target)
static uint32_t IpAddressToBgpIdentifier(const IpAddress &address)
static bool GetVirtualNetworkAllowTransit(DBGraph *graph, IFMapNode *node)
static string GetConnectedVxlanRi(DBGraph *graph, IFMapNode *node)
static BgpNeighborConfig::AddressFamilyList default_addr_family_list
static string GetConnectedVxlanRiVn(DBGraph *graph, IFMapNode *node)
static void BuildPolicyTermsConfig(BgpRoutingPolicyConfig *policy_cfg, const autogen::RoutingPolicy *policy)
static bool GetVirtualNetworkPbbEvpnEnable(DBGraph *graph, IFMapNode *node)
static BgpNeighborConfig * MakeBgpNeighborConfig(const BgpIfmapInstanceConfig *instance, const BgpIfmapInstanceConfig *master_instance, const string &local_name, const string &remote_name, const autogen::BgpRouter *local_router, const autogen::BgpRouter *remote_router, const autogen::BgpSession *session)
static bool CompareRoutingPolicyOrder(const RoutingPolicyAttachInfo &lhs, const RoutingPolicyAttachInfo &rhs)
static AuthenticationData::KeyType KeyChainType(const string &value)
static bool AddressFamilyIsValid(BgpNeighborConfig *neighbor, const string &family)
static string IdentifierParent(const string &identifier)
static void GetConnectionExportTargets(DBGraph *graph, IFMapNode *src_node, const string &src_instance, IFMapNode *node, vector< string > *target_list)
static void BuildPolicyTermConfig(autogen::PolicyTermType cfg_term, RoutingPolicyTermConfig *term)
static void NeighborSetSessionAttributes(BgpNeighborConfig *neighbor, const string &localname, const autogen::BgpSession *session)
MODULE_INITIALIZER(DefaultAddressFamilyInit)
static void BuildFamilyAttributesList(BgpNeighborConfig *neighbor, const BgpNeighborConfig::AddressFamilyList &family_list, const vector< string > &remote_family_list)
static void SetStaticRouteConfig(BgpInstanceConfig *rti, const autogen::RoutingInstance *config)
static bool GetRouteAggregateConfig(DBGraph *graph, IFMapNode *node, BgpInstanceConfig::AggregateRouteList *inet_list, BgpInstanceConfig::AggregateRouteList *inet6_list)
static int GetVirtualNetworkVxlanId(DBGraph *graph, IFMapNode *node)
static void GetRoutingInstanceExportTargets(DBGraph *graph, IFMapNode *node, vector< string > *target_list)
static int GetVirtualNetworkIndex(DBGraph *graph, IFMapNode *node)
#define EVPN_ES_IMPORT_ROUTE_TARGET_AS2
#define EVPN_ES_IMPORT_ROUTE_TARGET_AS4
#define BGP_LOG_FLAG_ALL
Definition: bgp_log.h:44
#define BGP_CONFIG_LOG_INSTANCE(type, server, rtinstance, level, flags,...)
Definition: bgp_log.h:284
#define BGP_CONFIG_LOG_PEERING(type, server, peering, level, flags,...)
Definition: bgp_log.h:292
#define BGP_LOG_FLAG_SYSLOG
Definition: bgp_log.h:42
#define BGP_LOG_WARNING_STR(obj, flags, arg)
Definition: bgp_log.h:107
#define BGP_CONFIG_LOG_PROTOCOL(type, server, protocol, level, flags,...)
Definition: bgp_log.h:296
#define BGP_CONFIG_LOG_NEIGHBOR(type, server, neighbor, level, flags,...)
Definition: bgp_log.h:288
#define BGP_LOG_STR(obj, level, flags, arg)
Definition: bgp_log.h:89
@ INET
Definition: address.h:26
@ INET6
Definition: address.h:27
bool Empty() const
Definition: bgp_config.cc:106
void set_key_type(KeyType in_type)
Definition: bgp_config.h:71
void AddKeyToKeyChain(const AuthenticationKey &key)
Definition: bgp_config.cc:91
static const int kDefaultPort
Definition: bgp_config.h:780
std::map< std::string, BgpNeighborConfig * > NeighborMap
Definition: bgp_config.h:773
void Notify(const BgpConfigObject *, EventType)
std::pair< NeighborMap::const_iterator, NeighborMap::const_iterator > NeighborMapRange
Definition: bgp_config.h:775
static const uint32_t kDefaultAutonomousSystem
Definition: bgp_config.h:781
const BgpServer * server()
Definition: bgp_config.h:814
static const char * kMasterInstance
Definition: bgp_config.h:778
std::pair< InstanceMap::const_iterator, InstanceMap::const_iterator > InstanceMapRange
Definition: bgp_config.h:772
std::pair< RoutingPolicyMap::const_iterator, RoutingPolicyMap::const_iterator > RoutingPolicyMapRange
Definition: bgp_config.h:769
uint8_t analytics_dscp() const
Definition: bgp_config.h:720
void set_control_dscp(uint8_t value)
Definition: bgp_config.h:719
uint8_t control_dscp() const
Definition: bgp_config.h:718
void set_analytics_dscp(uint8_t value)
Definition: bgp_config.h:721
bool all_tags_are_global() const
Definition: bgp_config.h:684
void set_xmpp_hold_time(uint8_t hold_time)
Definition: bgp_config.h:667
void set_all_tags_are_global(bool all_tags_are_global)
Definition: bgp_config.h:685
void set_end_of_rib_timeout(uint16_t time)
Definition: bgp_config.h:639
uint16_t bgpaas_port_start() const
Definition: bgp_config.h:676
uint16_t end_of_rib_timeout() const
Definition: bgp_config.h:638
uint16_t bgpaas_port_end() const
Definition: bgp_config.h:680
void set_rd_cluster_seed(uint16_t seed)
Definition: bgp_config.h:673
bool gr_bgp_helper() const
Definition: bgp_config.h:640
void set_always_compare_med(bool always_compare_med)
Definition: bgp_config.h:661
uint16_t rd_cluster_seed() const
Definition: bgp_config.h:670
uint32_t llgr_time() const
Definition: bgp_config.h:634
bool enable_4byte_as() const
Definition: bgp_config.h:646
bool gr_enable() const
Definition: bgp_config.h:644
void set_gr_time(uint16_t gr_time)
Definition: bgp_config.h:633
void set_fc_enabled(bool enable)
Definition: bgp_config.h:651
void set_llgr_time(uint64_t llgr_time)
Definition: bgp_config.h:635
bool always_compare_med() const
Definition: bgp_config.h:660
void set_gr_bgp_helper(bool helper)
Definition: bgp_config.h:641
void set_nh_check_enabled(bool enable)
Definition: bgp_config.h:657
void set_bgpaas_port_end(uint16_t bgpaas_port_end)
Definition: bgp_config.h:681
bool fc_enabled() const
Definition: bgp_config.h:648
void set_bgpaas_port_start(uint16_t bgpaas_port_start)
Definition: bgp_config.h:677
uint8_t xmpp_hold_time() const
Definition: bgp_config.h:664
void set_gr_xmpp_helper(bool helper)
Definition: bgp_config.h:643
bool gr_xmpp_helper() const
Definition: bgp_config.h:642
bool nh_check_enabled() const
Definition: bgp_config.h:654
uint16_t gr_time() const
Definition: bgp_config.h:632
void set_gr_enable(bool enable)
Definition: bgp_config.h:645
void set_enable_4byte_as(bool as_4byte)
Definition: bgp_config.h:647
BgpIfmapInstanceConfig * FindInstance(const std::string &name)
BgpConfigManager::RoutingPolicyMapRange RoutingPolicyMapItems(const std::string &start_name=std::string()) const
IfmapPeeringMap peerings_
BgpIfmapRoutingPolicyConfig * FindRoutingPolicy(const std::string &name)
BgpConfigManager::InstanceMapRange InstanceMapItems(const std::string &start_name=std::string()) const
BgpInstanceMap instance_config_map_
void DeletePeering(BgpIfmapPeeringConfig *peer)
BgpIfmapRoutingPolicyLinkConfig * FindRoutingPolicyLink(const std::string &name)
IfmapRoutingPolicyMap routing_policies_
void DeleteInstance(BgpIfmapInstanceConfig *rti)
BgpIfmapInstanceConfig * LocateInstance(const std::string &name)
BgpIfmapPeeringConfig * CreatePeering(BgpIfmapInstanceConfig *rti, IFMapNodeProxy *proxy)
BgpIfmapRoutingPolicyLinkConfig * CreateRoutingPolicyLink(BgpIfmapInstanceConfig *rti, BgpIfmapRoutingPolicyConfig *rtp, IFMapNodeProxy *proxy)
BgpIfmapPeeringConfig * FindPeering(const std::string &name)
BgpIfmapRoutingPolicyConfig * LocateRoutingPolicy(const std::string &name)
IfmapRoutingPolicyLinkMap ri_rp_links_
BgpRoutingPolicyMap routing_policy_config_map_
IfmapInstanceMap instances_
void DeleteRoutingPolicy(BgpIfmapRoutingPolicyConfig *rtp)
void ProcessIdentifierAndASUpdate(BgpIfmapConfigManager *manager, uint32_t new_id, uint32_t old_id, uint32_t new_as, uint32_t old_as)
IfmapInstanceMap & instances()
void DeleteRoutingPolicyLink(BgpIfmapRoutingPolicyLinkConfig *ri_rp_link)
boost::scoped_ptr< BgpIfmapConfigData > config_
void ProcessBgpProtocol(const BgpConfigDelta &change)
void ProcessGlobalSystemConfig(const BgpConfigDelta &delta)
virtual NeighborMapRange NeighborMapItems(const std::string &instance_name) const
void ProcessRoutingInstance(const BgpConfigDelta &change)
virtual const BgpRoutingPolicyConfig * FindRoutingPolicy(const std::string &name) const
void ProcessBgpRouter(const BgpConfigDelta &change)
void Initialize(DB *db, DBGraph *db_graph, const std::string &localname)
BgpIfmapConfigManager(BgpServer *server)
boost::scoped_ptr< BgpConfigListener > listener_
static const int kConfigTaskInstanceId
virtual const BgpProtocolConfig * GetProtocolConfig(const std::string &instance_name) const
virtual int NeighborCount(const std::string &instance_name) const
void ProcessRoutingPolicy(const BgpConfigDelta &change)
virtual void ResetRoutingInstanceIndexBit(int index)
void ProcessRoutingPolicyLink(const BgpConfigDelta &change)
void ProcessGlobalQosConfig(const BgpConfigDelta &delta)
virtual const std::string & localname() const
virtual RoutingPolicyMapRange RoutingPolicyMapItems(const std::string &start_name=std::string()) const
virtual InstanceMapRange InstanceMapItems(const std::string &start_name=std::string()) const
void DefaultBgpRouterParams(autogen::BgpRouterParams *param)
void ProcessBgpPeering(const BgpConfigDelta &change)
const BgpIfmapConfigData * config() const
void UpdateInstanceConfig(BgpIfmapInstanceConfig *rti, BgpConfigManager::EventType event)
virtual const BgpInstanceConfig * FindInstance(const std::string &name) const
virtual const BgpNeighborConfig * FindNeighbor(const std::string &instance_name, const std::string &name) const
void ProcessChanges(const ChangeList &change_list)
std::vector< BgpConfigDelta > ChangeList
bool Update(BgpIfmapConfigManager *manager, const autogen::GlobalQosConfig *qos)
BgpGlobalQosConfig data_
BgpGlobalSystemConfig data_
bool Update(BgpIfmapConfigManager *manager, const autogen::GlobalSystemConfig *system)
std::string GetESRouteTarget(uint32_t as) const
void ProcessASUpdate(uint32_t new_as, uint32_t old_as)
const BgpNeighborConfig * FindNeighbor(const std::string &name) const
void ProcessIdentifierUpdate(uint32_t new_id, uint32_t old_id)
IFMapNodeProxy node_proxy_
const std::string & virtual_network() const
void SetNodeProxy(IFMapNodeProxy *proxy)
std::string GetVitFromId(uint32_t identifier) const
boost::scoped_ptr< BgpIfmapProtocolConfig > protocol_
void DeletePeering(BgpIfmapPeeringConfig *peering)
void set_index(int index)
BgpIfmapInstanceConfig(const std::string &name)
BgpIfmapProtocolConfig * protocol_config_mutable()
const RouteTargetList & import_list() const
const NeighborMap & neighbors() const
BgpIfmapProtocolConfig * LocateProtocol()
void DeleteNeighbor(BgpConfigManager *manager, BgpNeighborConfig *neighbor)
void AddPeering(BgpIfmapPeeringConfig *peering)
void AddRoutingPolicy(BgpIfmapRoutingPolicyConfig *rtp)
void ChangeNeighbor(BgpConfigManager *manager, BgpNeighborConfig *neighbor)
BgpConfigManager::NeighborMapRange NeighborMapItems() const
const RouteTargetList & export_list() const
void AddNeighbor(BgpConfigManager *manager, BgpNeighborConfig *neighbor)
BgpInstanceConfig * instance_config()
bool DeleteIfEmpty(BgpConfigManager *manager)
void Update(BgpIfmapConfigManager *manager, const autogen::RoutingInstance *config)
BgpInstanceConfig data_
const std::string & name() const
RouitngPolicyMap routing_policies_
void DeleteRoutingPolicy(BgpIfmapRoutingPolicyConfig *rtp)
void InsertVitAndESRTargetInImportList(BgpIfmapConfigManager *manager, BgpInstanceConfig::RouteTargetList &import_list)
int virtual_network_index() const
const BgpIfmapProtocolConfig * protocol_config() const
BgpIfmapInstanceConfig * instance_
void SetNodeProxy(IFMapNodeProxy *proxy)
const IFMapNode * node() const
void Delete(BgpIfmapConfigManager *manager)
void Update(BgpIfmapConfigManager *manager, const autogen::BgpPeering *peering)
std::map< std::string, BgpNeighborConfig * > NeighborMap
void BuildNeighbors(BgpIfmapConfigManager *manager, const autogen::BgpRouter *local_rt_config, const std::string &peername, const autogen::BgpRouter *remote_rt_config, const autogen::BgpPeering *peering, NeighborMap *map)
const autogen::BgpPeering * bgp_peering() const
BgpIfmapPeeringConfig(BgpIfmapInstanceConfig *instance)
std::string name() const
static bool GetRouterPair(DBGraph *db_graph, const std::string &localname, IFMapNode *node, std::pair< IFMapNode *, IFMapNode * > *pair)
BgpIfmapInstanceConfig * instance()
IFMapNodeProxy node_proxy_
boost::intrusive_ptr< const autogen::BgpPeering > bgp_peering_
const autogen::BgpRouterParams & router_params() const
const autogen::BgpRouter * bgp_router() const
BgpIfmapProtocolConfig(BgpIfmapInstanceConfig *instance)
BgpIfmapInstanceConfig * instance_
const BgpProtocolConfig * protocol_config() const
IFMapNodeProxy node_proxy_
BgpProtocolConfig data_
void SetNodeProxy(IFMapNodeProxy *proxy)
void Update(BgpIfmapConfigManager *manager, const autogen::BgpRouter *router)
boost::intrusive_ptr< const autogen::BgpRouter > bgp_router_
void Delete(BgpIfmapConfigManager *manager)
const std::string & InstanceName() const
void AddInstance(BgpIfmapInstanceConfig *rti)
void Delete(BgpConfigManager *manager)
BgpRoutingPolicyConfig * routing_policy_config()
BgpRoutingPolicyConfig data_
void SetNodeProxy(IFMapNodeProxy *proxy)
bool DeleteIfEmpty(BgpConfigManager *manager)
const std::string & name() const
void Update(BgpIfmapConfigManager *manager, const autogen::RoutingPolicy *policy)
BgpIfmapRoutingPolicyConfig(const std::string &name)
void RemoveInstance(BgpIfmapInstanceConfig *rti)
boost::intrusive_ptr< const autogen::RoutingPolicy > routing_policy_
BgpIfmapInstanceConfig * instance()
const IFMapNode * node() const
boost::intrusive_ptr< const autogen::RoutingPolicyRoutingInstance > ri_rp_link_
static bool GetInstancePolicyPair(DBGraph *graph, IFMapNode *node, std::pair< IFMapNode *, IFMapNode * > *pair)
void SetNodeProxy(IFMapNodeProxy *proxy)
BgpIfmapRoutingPolicyConfig * policy()
void Update(BgpIfmapConfigManager *manager, const autogen::RoutingPolicyRoutingInstance *ri_rp)
void Delete(BgpIfmapConfigManager *manager)
BgpIfmapRoutingPolicyLinkConfig(BgpIfmapInstanceConfig *rti, BgpIfmapRoutingPolicyConfig *rtp)
void set_index(int index)
Definition: bgp_config.h:508
void set_virtual_network_allow_transit(bool allow_transit)
Definition: bgp_config.h:467
std::vector< AggregateRouteConfig > AggregateRouteList
Definition: bgp_config.h:427
void set_import_list(const RouteTargetList &import_list)
Definition: bgp_config.h:443
std::set< std::string > RouteTargetList
Definition: bgp_config.h:424
void set_virtual_network_pbb_evpn_enable(bool pbb_evpn)
Definition: bgp_config.h:474
void set_virtual_network(const std::string &virtual_network)
Definition: bgp_config.h:455
const RouteTargetList & import_list() const
Definition: bgp_config.h:442
const std::string & name() const
Definition: bgp_config.h:432
void swap_routing_policy_list(RoutingPolicyConfigList *list)
Definition: bgp_config.h:500
void swap_service_chain_list(ServiceChainList *list)
Definition: bgp_config.h:491
void swap_static_routes(Address::Family family, StaticRouteList *list)
Definition: bgp_config.cc:369
void add_neighbor(const std::string &neighbor)
Definition: bgp_config.h:435
void delete_neighbor(const std::string &neighbor)
Definition: bgp_config.h:438
void set_vxlan_id(int vxlan_id)
Definition: bgp_config.h:480
void set_has_pnf(bool has_pnf)
Definition: bgp_config.h:452
void set_virtual_network_index(int virtual_network_index)
Definition: bgp_config.h:460
void swap_aggregate_routes(Address::Family family, AggregateRouteList *list)
Definition: bgp_config.cc:399
void set_export_list(const RouteTargetList &export_list)
Definition: bgp_config.h:447
void set_routing_instance_vxlan(const std::string &routing_instance_vxlan)
Definition: bgp_config.h:514
std::vector< ServiceChainConfig > ServiceChainList
Definition: bgp_config.h:426
std::set< StaticRouteConfig > StaticRouteList
Definition: bgp_config.h:425
AddressFamilyList GetAddressFamilies() const
Definition: bgp_config.cc:283
const std::string & instance_name() const
Definition: bgp_config.h:168
std::string AuthKeyTypeToString() const
Definition: bgp_config.cc:292
void set_peer_as(uint32_t peer_as)
Definition: bgp_config.h:199
const AuthenticationData & auth_data() const
Definition: bgp_config.h:244
uint32_t local_identifier() const
Definition: bgp_config.h:236
void set_keydata(const AuthenticationData &in_auth_data)
Definition: bgp_config.h:247
void set_hold_time(int hold_time)
Definition: bgp_config.h:228
std::vector< std::string > AuthKeysToString() const
Definition: bgp_config.cc:297
void set_port(uint16_t port)
Definition: bgp_config.h:217
void set_router_type(const std::string &router_type)
Definition: bgp_config.h:223
std::string router_type() const
Definition: bgp_config.h:222
void set_passive(bool passive)
Definition: bgp_config.h:185
const std::string & name() const
Definition: bgp_config.h:162
std::vector< std::string > AddressFamilyList
Definition: bgp_config.h:141
void set_peer_address(const IpAddress &address)
Definition: bgp_config.h:202
uint32_t peer_as() const
Definition: bgp_config.h:198
std::vector< BgpFamilyAttributesConfig > FamilyAttributesList
Definition: bgp_config.h:142
void set_gateway_address(Address::Family family, const IpAddress &address)
Definition: bgp_config.cc:272
bool admin_down() const
Definition: bgp_config.h:181
void set_private_as_action(const std::string &private_as_action)
Definition: bgp_config.h:191
void set_local_as(uint32_t local_as)
Definition: bgp_config.h:234
void set_family_attributes_list(const FamilyAttributesList &family_attributes_list)
Definition: bgp_config.h:257
void set_instance_name(const std::string &instance_name)
Definition: bgp_config.h:169
void set_as_override(bool as_override)
Definition: bgp_config.h:188
void set_source_port(uint16_t source_port)
Definition: bgp_config.h:220
const IpAddress & peer_address() const
Definition: bgp_config.h:201
void set_loop_count(uint8_t loop_count)
Definition: bgp_config.h:231
void SetOriginOverride(bool origin_override, std::string origin)
Definition: bgp_config.cc:256
const FamilyAttributesList & family_attributes_list() const
Definition: bgp_config.h:253
uint32_t local_as() const
Definition: bgp_config.h:233
void set_peer_identifier(uint32_t identifier)
Definition: bgp_config.h:206
bool passive() const
Definition: bgp_config.h:184
void set_uuid(const std::string &uuid)
Definition: bgp_config.h:166
void set_local_identifier(uint32_t identifier)
Definition: bgp_config.h:237
void set_name(const std::string &name)
Definition: bgp_config.h:163
void set_admin_down(bool admin_down)
Definition: bgp_config.h:182
void set_port(int port)
Definition: bgp_config.h:588
void set_hold_time(uint32_t hold_time)
Definition: bgp_config.h:591
void set_cluster_id(uint32_t cluster_id)
Definition: bgp_config.h:558
void reset_subcluster_name()
Definition: bgp_config.h:567
void set_subcluster_name(const std::string &name)
Definition: bgp_config.h:564
void reset_subcluster_id()
Definition: bgp_config.h:573
void set_admin_down(bool admin_down)
Definition: bgp_config.h:555
uint32_t autonomous_system() const
Definition: bgp_config.h:575
void set_autonomous_system(uint32_t autonomous_system)
Definition: bgp_config.h:576
void set_local_autonomous_system(uint32_t local_autonomous_system)
Definition: bgp_config.h:583
void set_identifier(uint32_t identifier)
Definition: bgp_config.h:561
void set_subcluster_id(uint32_t id)
Definition: bgp_config.h:570
uint32_t identifier() const
Definition: bgp_config.h:560
void add_term(const RoutingPolicyTermConfig &term)
Definition: bgp_config.h:407
bool IsDeleted() const
Definition: db_entry.h:49
adjacency_iterator end(DBGraph *graph)
adjacency_iterator begin(DBGraph *graph)
Definition: db.h:24
std::vector< ConfigDelta > ChangeList
IFMapNode * node()
void Swap(IFMapNodeProxy *rhs)
IFMapTable * table()
Definition: ifmap_node.h:29
const std::string & name() const
Definition: ifmap_node.h:48
IFMapObject * GetObject()
Definition: ifmap_node.cc:63
virtual const char * Typename() const =0
ValueType * At(int index) const
Definition: index_map.h:31
void clear()
Definition: index_map.h:104
size_t Insert(const KeyType &key, ValueType *value, int index=-1)
Definition: index_map.h:50
size_t size() const
Definition: index_map.h:100
void Remove(const KeyType &key, int index, bool clear_bit=true)
Definition: index_map.h:69
void ReserveBit(int index)
Definition: index_map.h:42
ValueType * Find(const KeyType &key) const
Definition: index_map.h:34
void ResetBit(int index)
Definition: index_map.h:78
static void SetDscpValue(uint8_t value)
Definition: sandesh.cc:334
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:178
static const std::string integerToString(const NumberType &num)
Definition: string_util.h:19
CommunityList ext_community_set
Definition: bgp_config.h:375
CommunityList ext_community_add
Definition: bgp_config.h:376
CommunityList community_set
Definition: bgp_config.h:372
uint32_t local_pref
Definition: bgp_config.h:378
CommunityList community_remove
Definition: bgp_config.h:374
AsnList aspath_expand
Definition: bgp_config.h:371
CommunityList ext_community_remove
Definition: bgp_config.h:377
uint32_t med
Definition: bgp_config.h:379
CommunityList community_add
Definition: bgp_config.h:373
std::string value
Definition: bgp_config.h:35
std::vector< std::string > default_tunnel_encap_list
Definition: bgp_config.h:99
std::string routing_policy_
Definition: bgp_common.h:37
std::string sequence_
Definition: bgp_common.h:36
ProtocolList protocols_match
Definition: bgp_config.h:361
CommunityList community_match
Definition: bgp_config.h:363
PrefixMatchConfigList prefixes_to_match
Definition: bgp_config.h:362
CommunityList ext_community_match
Definition: bgp_config.h:365
RoutingPolicyMatchConfig match
Definition: bgp_config.h:394
RoutingPolicyActionConfig action
Definition: bgp_config.h:395
IpAddress nexthop
Definition: bgp_config.h:341
IpAddress address
Definition: bgp_config.h:339
std::vector< std::string > route_targets
Definition: bgp_config.h:342
std::vector< std::string > communities
Definition: bgp_config.h:343
#define CHECK_CONCURRENCY(...)
void STLDeleteElements(Container *container)
Definition: util.h:114