OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
1081  const BgpConfigDelta &delta) {
1082  CHECK_CONCURRENCY("bgp::Config");
1083 
1085  = config_->FindRoutingPolicyLink(delta.id_name);
1086  if (ri_rp_link == NULL) {
1087  IFMapNodeProxy *proxy = delta.node.get();
1088  if (proxy == NULL) {
1089  return;
1090  }
1091  IFMapNode *node = proxy->node();
1092  if (node == NULL || delta.obj.get() == NULL) {
1093  return;
1094  }
1095 
1096  pair<IFMapNode *, IFMapNode *> ri_rp_pair;
1098  node, &ri_rp_pair)) {
1099  return;
1100  }
1101 
1102  string instance_name = ri_rp_pair.first->name();
1103  string policy_name = ri_rp_pair.second->name();
1104 
1105  BgpIfmapInstanceConfig *rti =
1106  config_->FindInstance(instance_name);
1108  config_->FindRoutingPolicy(policy_name);
1109  if (!rti || !rtp) {
1110  return;
1111  }
1112 
1113  ri_rp_link = config_->CreateRoutingPolicyLink(rti, rtp, proxy);
1114  } else {
1115  const IFMapNode *node = ri_rp_link->node();
1116  assert(node != NULL);
1117  if (delta.obj.get() == NULL) {
1118  BgpIfmapRoutingPolicyConfig *rtp = ri_rp_link->policy();
1119  BgpIfmapInstanceConfig *rti = ri_rp_link->instance();
1120  config_->DeleteRoutingPolicyLink(ri_rp_link);
1121  if (rtp->DeleteIfEmpty(this)) {
1122  config_->DeleteRoutingPolicy(rtp);
1123  }
1124  if (rti->DeleteIfEmpty(this)) {
1125  BGP_CONFIG_LOG_INSTANCE(Delete, server(), rti,
1126  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL);
1127  config_->DeleteInstance(rti);
1128  }
1129  return;
1130  }
1131  }
1132 
1133  autogen::RoutingPolicyRoutingInstance *ri_rp_link_cfg =
1134  static_cast<autogen::RoutingPolicyRoutingInstance *>(delta.obj.get());
1135 
1136  ri_rp_link->Update(this, ri_rp_link_cfg);
1137 }
1138 
1140  const RoutingPolicyAttachInfo &rhs) {
1141  return (lhs.sequence_ < rhs.sequence_);
1142 }
1143 
1145  uint32_t old_id) {
1147  if (old_id > 0) {
1148  string old_vit = "target:" + GetVitFromId(ntohl(old_id));
1149  import_list.erase(old_vit);
1150  }
1151  if (new_id > 0) {
1152  string new_vit = "target:" + GetVitFromId(ntohl(new_id));
1153  import_list.insert(new_vit);
1154  }
1155  data_.set_import_list(import_list);
1156 }
1157 
1158 void BgpIfmapInstanceConfig::ProcessASUpdate(uint32_t new_as, uint32_t old_as) {
1160  if (old_as > 0) {
1161  string old_es_rtarget = "target:" + GetESRouteTarget(old_as);
1162  import_list.erase(old_es_rtarget);
1163  }
1164  if (new_as > 0) {
1165  string new_es_rtarget = "target:" + GetESRouteTarget(new_as);
1166  import_list.insert(new_es_rtarget);
1167  }
1168  data_.set_import_list(import_list);
1169 }
1170 
1171 string BgpIfmapInstanceConfig::GetVitFromId(uint32_t identifier) const {
1172  if (identifier == 0)
1173  return "";
1174  return Ip4Address(identifier).to_string() + ":" + integerToString(index());
1175 }
1176 
1177 string BgpIfmapInstanceConfig::GetESRouteTarget(uint32_t as) const {
1178  if (as == 0)
1179  return "";
1180  if (as > 0xffFF)
1181  return integerToString(as) + ":" +
1183  return integerToString(as) + ":" +
1185 }
1186 
1187 // Populate vrf import route-target (used for MVPN) and ES route target in
1188 // import list.
1190  BgpIfmapConfigManager *mgr,
1191  BgpInstanceConfig::RouteTargetList& import_list) {
1192  const BgpIfmapInstanceConfig *master_instance =
1194  uint32_t bgp_identifier = 0;
1195  uint32_t as = 0;
1196  if (master_instance) {
1197  const BgpIfmapProtocolConfig *master_protocol =
1198  master_instance->protocol_config();
1199  if (master_protocol) {
1200  if (master_protocol->protocol_config()) {
1201  bgp_identifier =
1202  master_protocol->protocol_config()->identifier();
1203  as = master_protocol->protocol_config()->autonomous_system();
1204  }
1205  }
1206  }
1207  if (bgp_identifier > 0)
1208  import_list.insert("target:" + GetVitFromId(ntohl(bgp_identifier)));
1209  if (as > 0)
1210  import_list.insert("target:" + GetESRouteTarget(as));
1211 }
1212 
1213 //
1214 // Update BgpIfmapInstanceConfig based on a new autogen::RoutingInstance object.
1215 //
1216 // Rebuild the import and export route target lists and update the virtual
1217 // network information.
1218 //
1219 // Targets that are configured on this routing-instance (which corresponds
1220 // to all adjacencies to instance-target) are added to the import list or
1221 // export list or both depending on the import_export attribute.
1222 //
1223 // Export targets for all other routing-instances that we are connected to
1224 // are added to our import list.
1225 //
1227  const autogen::RoutingInstance *config) {
1229  BgpInstanceConfig::AggregateRouteList inet6_aggregate_list;
1230  BgpInstanceConfig::AggregateRouteList inet_aggregate_list;
1231  RoutingPolicyConfigList policy_list;
1232  data_.Clear();
1233 
1234  DBGraph *graph = manager->graph();
1236  for (DBGraphVertex::adjacency_iterator iter = node->begin(graph);
1237  iter != node->end(graph); ++iter) {
1238  IFMapNode *adj = static_cast<IFMapNode *>(iter.operator->());
1239  if (strcmp(adj->table()->Typename(), "instance-target") == 0) {
1240  string target;
1241  if (GetInstanceTargetRouteTarget(graph, adj, &target)) {
1242  const autogen::InstanceTarget *itarget =
1243  dynamic_cast<autogen::InstanceTarget *>(adj->GetObject());
1244  if (!itarget)
1245  continue;
1246  const autogen::InstanceTargetType &itt = itarget->data();
1247  if (itt.import_export == "import") {
1248  import_list.insert(target);
1249  } else if (itt.import_export == "export") {
1250  export_list.insert(target);
1251  } else {
1252  import_list.insert(target);
1253  export_list.insert(target);
1254  }
1255  }
1256  } else if (strcmp(adj->table()->Typename(),
1257  "routing-policy-routing-instance") == 0) {
1258  RoutingPolicyAttachInfo policy_info;
1259  if (GetRoutingInstanceRoutingPolicy(graph, adj, &policy_info)) {
1260  policy_list.push_back(policy_info);
1261  }
1262  } else if (strcmp(adj->table()->Typename(), "route-aggregate") == 0) {
1263  GetRouteAggregateConfig(graph, adj, &inet_aggregate_list,
1264  &inet6_aggregate_list);
1265  } else if (strcmp(adj->table()->Typename(), "connection") == 0) {
1266  vector<string> target_list;
1267  GetConnectionExportTargets(graph, node, name_, adj, &target_list);
1268  BOOST_FOREACH(string target, target_list) {
1269  import_list.insert(target);
1270  }
1271  } else if (strcmp(adj->table()->Typename(), "virtual-network") == 0) {
1272  data_.set_virtual_network(adj->name());
1275  GetVirtualNetworkAllowTransit(graph, adj));
1278  GetVirtualNetworkPbbEvpnEnable(graph, adj));
1279  }
1280  }
1281 
1282  InsertVitAndESRTargetInImportList(manager, import_list);
1283  data_.set_import_list(import_list);
1284  data_.set_export_list(export_list);
1285 
1286  sort(policy_list.begin(), policy_list.end(), CompareRoutingPolicyOrder);
1287  data_.swap_routing_policy_list(&policy_list);
1288  data_.swap_aggregate_routes(Address::INET, &inet_aggregate_list);
1289  data_.swap_aggregate_routes(Address::INET6, &inet6_aggregate_list);
1290 
1291  if (config) {
1292  data_.set_has_pnf(config->has_pnf());
1293  SetStaticRouteConfig(&data_, config);
1294  SetServiceChainConfig(&data_, config);
1295  }
1296 }
1297 
1298 //
1299 // Reset IFMap related state in the BgpIfmapInstanceConfig.
1300 //
1302  node_proxy_.Clear();
1303 }
1304 
1305 //
1306 // Return true if the BgpIfmapInstanceConfig is ready to be deleted. The
1307 // caller is responsible for actually deleting it.
1308 //
1311  return false;
1312  }
1313  if (node() != NULL || protocol_.get() != NULL) {
1314  return false;
1315  }
1316  if (!neighbors_.empty() || !peerings_.empty() ||
1317  !routing_policies_.empty()) {
1318  return false;
1319  }
1320 
1322  return true;
1323 }
1324 
1325 //
1326 // Add a BgpNeighborConfig to this BgpIfmapInstanceConfig.
1327 //
1328 // The BgpNeighborConfig is added to the NeighborMap and the BgpConfigManager
1329 // is notified.
1330 //
1332  BgpNeighborConfig *neighbor) {
1334  Create, manager->server(), neighbor, SandeshLevel::SYS_DEBUG,
1336  neighbor->admin_down(),
1337  neighbor->passive(),
1339  neighbor->local_as(),
1340  neighbor->peer_address().to_string(), neighbor->peer_as(),
1341  neighbor->GetAddressFamilies(), neighbor->AuthKeyTypeToString(),
1342  neighbor->AuthKeysToString());
1343  neighbors_.insert(make_pair(neighbor->name(), neighbor));
1344  data_.add_neighbor(neighbor->name());
1345  manager->Notify(neighbor, BgpConfigManager::CFG_ADD);
1346 }
1347 
1348 //
1349 // Change a BgpNeighborConfig that's already in this BgpIfmapInstanceConfig.
1350 //
1352  BgpNeighborConfig *neighbor) {
1353  NeighborMap::iterator loc = neighbors_.find(neighbor->name());
1354  assert(loc != neighbors_.end());
1355  loc->second = neighbor;
1356 
1358  Update, manager->server(), neighbor,
1359  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
1360  neighbor->admin_down(),
1361  neighbor->passive(),
1363  neighbor->local_as(),
1364  neighbor->peer_address().to_string(), neighbor->peer_as(),
1365  neighbor->GetAddressFamilies(), neighbor->AuthKeyTypeToString(),
1366  neighbor->AuthKeysToString());
1367  manager->Notify(neighbor, BgpConfigManager::CFG_CHANGE);
1368 }
1369 
1370 //
1371 // Delete a BgpNeighborConfig from this BgpIfmapInstanceConfig.
1372 //
1373 // The BgpConfigManager is notified and BgpNeighborConfig is removed from the
1374 // NeighborMap. Note that the caller is responsible for actually deleting the
1375 // BgpNeighborConfig object.
1376 //
1378  BgpNeighborConfig *neighbor) {
1379  BGP_CONFIG_LOG_NEIGHBOR(Delete, manager->server(), neighbor,
1380  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL);
1381  manager->Notify(neighbor, BgpConfigManager::CFG_DELETE);
1382  neighbors_.erase(neighbor->name());
1383  data_.delete_neighbor(neighbor->name());
1384 }
1385 
1386 //
1387 // Find the BgpNeighborConfig by name in this BgpIfmapInstanceConfig.
1388 //
1390  const string &name) const {
1391  NeighborMap::const_iterator loc;
1392 
1393  if (name.find(name_) == string::npos) {
1394  string fqn(name_);
1395  fqn += ":";
1396  fqn += name;
1397  loc = neighbors_.find(fqn);
1398  } else {
1399  loc = neighbors_.find(name);
1400  }
1401 
1402  return loc != neighbors_.end() ? loc->second : NULL;
1403 }
1404 
1405 //
1406 // Add a BgpPeeringConfig to this BgpIfmapInstanceConfig.
1407 //
1409  peerings_.insert(make_pair(peering->name(), peering));
1410 }
1411 
1412 //
1413 // Delete a BgpPeeringConfig from this BgpIfmapInstanceConfig.
1414 //
1416  peerings_.erase(peering->name());
1417 }
1418 
1419 //
1420 // Add a BgpIfmapRoutingPolicyConfig to this BgpIfmapInstanceConfig.
1421 //
1424  routing_policies_.insert(make_pair(rtp->name(), rtp));
1425 }
1426 
1427 //
1428 // Delete a BgpIfmapRoutingPolicyConfig from this BgpIfmapInstanceConfig.
1429 //
1432  routing_policies_.erase(rtp->name());
1433 }
1434 
1436  BgpIfmapConfigManager* manager,
1437  uint32_t new_id, uint32_t old_id,
1438  uint32_t new_as, uint32_t old_as) {
1439  assert(new_id != old_id || new_as != old_as);
1440  for (unsigned int i = 0; i < instances_.size(); i++) {
1441  BgpIfmapInstanceConfig * ifmap_config = instances_.At(i);
1442  if (!ifmap_config)
1443  continue;
1444  if (new_id != old_id)
1445  ifmap_config->ProcessIdentifierUpdate(new_id, old_id);
1446  if (new_as != old_as)
1447  ifmap_config->ProcessASUpdate(new_as, old_as);
1448  manager->UpdateInstanceConfig(ifmap_config,
1450  }
1451 }
1452 
1453 //
1454 // Constructor for BgpIfmapConfigData.
1455 //
1457  // Reserve bit 0 for master instance
1459 }
1460 
1461 //
1462 // Destructor for BgpConfigData.
1463 //
1465  instances_.clear();
1469 }
1470 
1471 //
1472 // Locate the BgpIfmapInstanceConfig by name, create it if not found. The newly
1473 // created BgpIfmapInstanceConfig gets added to the IfmapInstanceMap.
1474 //
1475 // Note that we do not have the IFMapNode representing the routing-instance
1476 // at this point.
1477 //
1479  BgpIfmapInstanceConfig *rti = FindInstance(name);
1480  if (rti != NULL) {
1481  return rti;
1482  }
1483  rti = new BgpIfmapInstanceConfig(name);
1484  int index = -1;
1485  if (name == BgpConfigManager::kMasterInstance) {
1486  index = 0;
1487  }
1488  index = instances_.Insert(name, rti, index);
1489  rti->set_index(index);
1490  pair<BgpInstanceMap::iterator, bool> result2 =
1491  instance_config_map_.insert(
1492  make_pair(name, rti->instance_config()));
1493  assert(result2.second);
1494  return rti;
1495 }
1496 
1497 //
1498 // Remove the given BgpIfmapInstanceConfig from the IfmapInstanceMap
1499 // and delete it.
1500 //
1502  BgpInstanceMap::iterator loc2 = instance_config_map_.find(rti->name());
1503  assert(loc2 != instance_config_map_.end());
1504  instance_config_map_.erase(loc2);
1505  instances_.Remove(rti->name(), rti->index(), false);
1506 }
1507 
1508 //
1509 // Find the BgpIfmapInstanceConfig by name.
1510 //
1512  return instances_.Find(name);
1513 }
1514 
1515 //
1516 // Find the BgpIfmapInstanceConfig by name.
1517 // Const version.
1518 //
1520  const string &name) const {
1521  return instances_.Find(name);
1522 }
1523 
1526  return make_pair(neighbors_.begin(), neighbors_.end());
1527 }
1528 
1529 //
1530 // Create a new BgpIfmapRoutingPolicyLinkConfig.
1531 //
1532 // The IFMapNodeProxy is a proxy for the IFMapNode which is the midnode that
1533 // represents the routing-policy-routing-instance. The newly created
1534 // BgpIfmapRoutingPolicyLinkConfig gets added to the IfmapRoutingPolicyLinkMap.
1535 //
1538  IFMapNodeProxy *proxy) {
1539  BgpIfmapRoutingPolicyLinkConfig *ri_rp_link =
1540  new BgpIfmapRoutingPolicyLinkConfig(rti, rtp);
1541  ri_rp_link->SetNodeProxy(proxy);
1542  pair<IfmapRoutingPolicyLinkMap::iterator, bool> result =
1543  ri_rp_links_.insert(make_pair(ri_rp_link->node()->name(), ri_rp_link));
1544  assert(result.second);
1545  ri_rp_link->instance()->AddRoutingPolicy(rtp);
1546  ri_rp_link->policy()->AddInstance(rti);
1547  return ri_rp_link;
1548 }
1549 
1550 //
1551 // Delete a BgpIfmapRoutingPolicyLinkConfig.
1552 //
1553 // The BgpIfmapRoutingPolicyLinkConfig is erased from IfmapRoutingPolicyLinkMap
1554 // and then deleted.
1555 // Note that the reference to the IFMapNode for routing-policy-routing-instance
1556 // gets released via the destructor when the IFMapNodeProxy is destroyed.
1557 //
1559  BgpIfmapRoutingPolicyLinkConfig *ri_rp_link) {
1560  ri_rp_links_.erase(ri_rp_link->node()->name());
1561  ri_rp_link->instance()->DeleteRoutingPolicy(ri_rp_link->policy());
1562  ri_rp_link->policy()->RemoveInstance(ri_rp_link->instance());
1563  delete ri_rp_link;
1564 }
1565 
1566 //
1567 // Find the BgpIfmapRoutingPolicyLinkConfig by name.
1568 //
1570  const string &name) {
1571  IfmapRoutingPolicyLinkMap::iterator loc = ri_rp_links_.find(name);
1572  if (loc != ri_rp_links_.end()) {
1573  return loc->second;
1574  }
1575  return NULL;
1576 }
1577 
1578 //
1579 // Find the BgpIfmapRoutingPolicyLinkConfig by name.
1580 // Const version.
1581 //
1583 BgpIfmapConfigData::FindRoutingPolicyLink(const string &name) const {
1584  IfmapRoutingPolicyLinkMap::const_iterator loc = ri_rp_links_.find(name);
1585  if (loc != ri_rp_links_.end()) {
1586  return loc->second;
1587  }
1588  return NULL;
1589 }
1590 
1591 //
1592 // Create a new BgpIfmapPeeringConfig.
1593 //
1594 // The IFMapNodeProxy is a proxy for the IFMapNode which is the
1595 // midnode that represents the bgp-peering. The newly created
1596 // BgpIfmapPeeringConfig gets added to the IfmapPeeringMap.
1597 //
1599  BgpIfmapInstanceConfig *rti, IFMapNodeProxy *proxy) {
1600  BgpIfmapPeeringConfig *peering = new BgpIfmapPeeringConfig(rti);
1601  peering->SetNodeProxy(proxy);
1602  pair<IfmapPeeringMap::iterator, bool> result =
1603  peerings_.insert(make_pair(peering->node()->name(), peering));
1604  assert(result.second);
1605  peering->instance()->AddPeering(peering);
1606  BGP_LOG_STR(BgpConfig, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_SYSLOG,
1607  "Creating BgpIfmapPeering " << peering->node()->name());
1608  return peering;
1609 }
1610 
1611 //
1612 // Delete a BgpPeeringConfig.
1613 //
1614 // The BgpPeeringConfig is removed from the IfmapPeeringMap and then deleted.
1615 // Note that the reference to the IFMapNode for the bgp-peering gets released
1616 // via the destructor when the IFMapNodeProxy is destroyed.
1617 //
1619  BGP_LOG_STR(BgpConfig, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_SYSLOG,
1620  "Deleting BgpIfmapPeering " << peering->node()->name());
1621  peering->instance()->DeletePeering(peering);
1622  peerings_.erase(peering->node()->name());
1623  delete peering;
1624 }
1625 
1626 //
1627 // Find the BgpPeeringConfig by name.
1628 //
1630  IfmapPeeringMap::iterator loc = peerings_.find(name);
1631  if (loc != peerings_.end()) {
1632  return loc->second;
1633  }
1634  return NULL;
1635 }
1636 
1637 //
1638 // Find the BgpPeeringConfig by name.
1639 // Const version.
1640 //
1642  const string &name) const {
1643  IfmapPeeringMap::const_iterator loc = peerings_.find(name);
1644  if (loc != peerings_.end()) {
1645  return loc->second;
1646  }
1647  return NULL;
1648 }
1649 
1651 BgpIfmapConfigData::InstanceMapItems(const string &start_name) const {
1652  return make_pair(instance_config_map_.lower_bound(start_name),
1653  instance_config_map_.end());
1654 }
1655 
1657 BgpIfmapConfigData::RoutingPolicyMapItems(const string &start_name) const {
1658  return make_pair(routing_policy_config_map_.lower_bound(start_name),
1660 }
1661 
1662 //
1663 // Locate the BgpIfmapRoutingPolicyConfig by name, create it if not found.
1664 // The newly created BgpIfmapRoutingPolicyConfig gets added to the
1665 // IfmapRoutingPolicyMap.
1666 //
1668  const string &name) {
1670  if (rtp != NULL) {
1671  return rtp;
1672  }
1673  rtp = new BgpIfmapRoutingPolicyConfig(name);
1674  pair<IfmapRoutingPolicyMap::iterator, bool> result =
1675  routing_policies_.insert(make_pair(name, rtp));
1676  assert(result.second);
1677  pair<BgpRoutingPolicyMap::iterator, bool> result2 =
1679  make_pair(name, rtp->routing_policy_config()));
1680  assert(result2.second);
1681  return rtp;
1682 }
1683 
1684 //
1685 // Remove the given BgpIfmapRoutingPolicyConfig from the IfmapRoutingPolicyMap
1686 // and delete it.
1687 //
1689  IfmapRoutingPolicyMap::iterator loc = routing_policies_.find(rtp->name());
1690  assert(loc != routing_policies_.end());
1691  routing_policies_.erase(loc);
1692  BgpRoutingPolicyMap::iterator loc2 =
1693  routing_policy_config_map_.find(rtp->name());
1694  assert(loc2 != routing_policy_config_map_.end());
1695  routing_policy_config_map_.erase(loc2);
1696  delete rtp;
1697 }
1698 
1700  const string &name) {
1701  IfmapRoutingPolicyMap::iterator loc = routing_policies_.find(name);
1702  if (loc != routing_policies_.end()) {
1703  return loc->second;
1704  }
1705  return NULL;
1706 }
1707 
1709  const string &name) const {
1710  IfmapRoutingPolicyMap::const_iterator loc = routing_policies_.find(name);
1711  if (loc != routing_policies_.end()) {
1712  return loc->second;
1713  }
1714  return NULL;
1715 }
1716 
1717 //
1718 // Constructor for BgpIfmapConfigManager.
1719 //
1721  : BgpConfigManager(server),
1722  db_(NULL),
1723  db_graph_(NULL),
1724  trigger_(boost::bind(&BgpIfmapConfigManager::ConfigHandler, this),
1725  TaskScheduler::GetInstance()->GetTaskId("bgp::Config"),
1726  kConfigTaskInstanceId),
1727  listener_(new BgpConfigListener(this)),
1728  config_(new BgpIfmapConfigData()) {
1730 }
1731 
1732 //
1733 // Destructor for BgpIfmapConfigManager.
1734 //
1736 }
1737 
1738 //
1739 // Initialize the BgpConfigManager.
1740 //
1742  const string &localname) {
1743  db_ = db;
1744  db_graph_ = db_graph;
1746  listener_->Initialize();
1747  DefaultConfig();
1748 }
1749 
1750 //
1751 // Used to trigger a build and subsequent evaluation of the ChangeList.
1752 //
1754  CHECK_CONCURRENCY("db::IFMapTable");
1755  trigger_.Set();
1756 }
1757 
1759 BgpIfmapConfigManager::InstanceMapItems(const string &start_name) const {
1760  return config_->InstanceMapItems(start_name);
1761 }
1762 
1764 BgpIfmapConfigManager::RoutingPolicyMapItems(const string &start_name) const {
1765  return config_->RoutingPolicyMapItems(start_name);
1766 }
1767 
1770  const string &instance_name) const {
1771  static BgpConfigManager::NeighborMap nilMap;
1772  BgpIfmapInstanceConfig *rti = config_->FindInstance(instance_name);
1773  if (rti == NULL) {
1774  return make_pair(nilMap.begin(), nilMap.end());
1775  }
1776  return rti->NeighborMapItems();
1777 }
1778 
1780  config()->instances().ResetBit(index);
1781 }
1782 
1784  const string &instance_name) const {
1785  BgpIfmapInstanceConfig *rti = config_->FindInstance(instance_name);
1786  if (rti == NULL) {
1787  return 0;
1788  }
1789  return rti->neighbors().size();
1790 }
1791 
1792 //
1793 // Constructor for BgpIfmapRoutingPolicyConfig.
1794 //
1796  const string &name)
1797  : name_(name),
1798  data_(name) {
1799 }
1800 
1801 //
1802 // Destructor for BgpIfmapRoutingPolicyConfig.
1803 //
1805 }
1806 
1807 //
1808 // Set the IFMapNodeProxy for the BgpIfmapRoutingPolicyConfig.
1809 //
1811  if (proxy != NULL) {
1812  node_proxy_.Swap(proxy);
1813  }
1814 }
1815 
1818  routing_policy_.reset();
1819 }
1820 
1821 //
1822 // Return true if the BgpIfmapRoutingPolicyConfig is ready to be deleted.
1823 // The caller is responsible for actually deleting it.
1824 //
1826  if (node() != NULL) {
1827  return false;
1828  }
1829  if (!instances_.empty()) {
1830  return false;
1831  }
1832 
1833  Delete(manager);
1834  return true;
1835 }
1836 
1837 //
1838 // Add a BgpIfmapInstanceConfig to BgpIfmapRoutingPolicyConfig.
1839 //
1841  instances_.insert(make_pair(rti->name(), rti));
1842 }
1843 
1844 //
1845 // Remove a BgpIfmapInstanceConfig to BgpIfmapRoutingPolicyConfig.
1846 //
1848  instances_.erase(rti->name());
1849 }
1850 
1851 
1852 static void BuildPolicyTermConfig(autogen::PolicyTermType cfg_term,
1853  RoutingPolicyTermConfig *term) {
1854  term->match.protocols_match = cfg_term.term_match_condition.protocol;
1855  BOOST_FOREACH(const autogen::PrefixMatchType &prefix_match,
1856  cfg_term.term_match_condition.prefix) {
1857  string prefix_type(prefix_match.prefix_type);
1858  PrefixMatchConfig match(prefix_match.prefix,
1859  prefix_type.empty() ? "exact" : prefix_type);
1860  term->match.prefixes_to_match.push_back(match);
1861  }
1862  term->match.community_match_all =
1863  cfg_term.term_match_condition.community_match_all;
1864  if (!cfg_term.term_match_condition.community_list.empty()) {
1865  term->match.community_match =
1866  cfg_term.term_match_condition.community_list;
1867  }
1868  if (!cfg_term.term_match_condition.community.empty()) {
1869  term->match.community_match.push_back(
1870  cfg_term.term_match_condition.community);
1871  }
1873  cfg_term.term_match_condition.extcommunity_match_all;
1874  if (!cfg_term.term_match_condition.extcommunity_list.empty()) {
1875  term->match.ext_community_match =
1876  cfg_term.term_match_condition.extcommunity_list;
1877  }
1878 
1879  BOOST_FOREACH(uint32_t asn,
1880  cfg_term.term_action_list.update.as_path.expand.asn_list) {
1881  term->action.update.aspath_expand.push_back(asn);
1882  }
1883  BOOST_FOREACH(const string community,
1884  cfg_term.term_action_list.update.community.add.community) {
1885  term->action.update.community_add.push_back(community);
1886  }
1887  BOOST_FOREACH(const string community,
1888  cfg_term.term_action_list.update.community.remove.community) {
1889  term->action.update.community_remove.push_back(community);
1890  }
1891  BOOST_FOREACH(const string community,
1892  cfg_term.term_action_list.update.community.set.community) {
1893  term->action.update.community_set.push_back(community);
1894  }
1895  BOOST_FOREACH(const string community,
1896  cfg_term.term_action_list.update.extcommunity.add.community) {
1897  term->action.update.ext_community_add.push_back(community);
1898  }
1899  BOOST_FOREACH(const string community,
1900  cfg_term.term_action_list.update.extcommunity.remove.community) {
1901  term->action.update.ext_community_remove.push_back(community);
1902  }
1903  BOOST_FOREACH(const string community,
1904  cfg_term.term_action_list.update.extcommunity.set.community) {
1905  term->action.update.ext_community_set.push_back(community);
1906  }
1907  term->action.update.local_pref =
1908  cfg_term.term_action_list.update.local_pref;
1909  term->action.update.med = cfg_term.term_action_list.update.med;
1910 
1912  if (strcmp(cfg_term.term_action_list.action.c_str(), "reject") == 0) {
1914  } else if (
1915  strcmp(cfg_term.term_action_list.action.c_str(), "accept") == 0) {
1917  }
1918 }
1919 
1921  const autogen::RoutingPolicy *policy) {
1922  vector<autogen::PolicyTermType> terms = policy->entries();
1923  BOOST_FOREACH(autogen::PolicyTermType cfg_term, terms) {
1924  RoutingPolicyTermConfig policy_term_cfg;
1925  BuildPolicyTermConfig(cfg_term, &policy_term_cfg);
1926  policy_cfg->add_term(policy_term_cfg);
1927  }
1928 }
1929 
1931  const autogen::RoutingPolicy *policy) {
1932  routing_policy_.reset(policy);
1933  data_.Clear();
1934  if (policy) {
1935  BuildPolicyTermsConfig(&data_, policy);
1936  }
1937 }
1938 
1939 //
1940 // Reset IFMap related state in the BgpIfmapRoutingPolicyConfig.
1941 //
1943  node_proxy_.Clear();
1944 }
1945 
1947  const string &name) const {
1948  BgpIfmapRoutingPolicyConfig *rtp = config_->FindRoutingPolicy(name);
1949  if (rtp == NULL) {
1950  return NULL;
1951  }
1952  return rtp->routing_policy_config();
1953 }
1954 
1956  const string &name) const {
1957  BgpIfmapInstanceConfig *rti = config_->FindInstance(name);
1958  if (rti == NULL) {
1959  return NULL;
1960  }
1961  return rti->instance_config();
1962 }
1963 
1965  const string &instance_name) const {
1966  BgpIfmapInstanceConfig *rti = config_->FindInstance(instance_name);
1967  if (rti == NULL) {
1968  return NULL;
1969  }
1970  const BgpIfmapProtocolConfig *proto = rti->protocol_config();
1971  if (proto == NULL) {
1972  return NULL;
1973  }
1974  return proto->protocol_config();
1975 }
1976 
1978  const string &instance_name, const string &name) const {
1979  BgpIfmapInstanceConfig *rti = config_->FindInstance(instance_name);
1980  if (rti == NULL) {
1981  return NULL;
1982  }
1983  return rti->FindNeighbor(name);
1984 }
1985 
1986 //
1987 // Initialize autogen::BgpRouterParams with default values.
1988 //
1990  autogen::BgpRouterParams *param) {
1991  param->Clear();
1992  param->autonomous_system = BgpConfigManager::kDefaultAutonomousSystem;
1993  param->port = BgpConfigManager::kDefaultPort;
1994 }
1995 
1996 //
1997 // Create BgpInsatnceConfig for master routing-instance. This
1998 // includes the BgpIfmapProtocolConfig for the local bgp-router in the
1999 // master routing-instance.
2000 //
2002  BgpIfmapInstanceConfig *rti = config_->LocateInstance(kMasterInstance);
2003  unique_ptr<autogen::BgpRouter> router(new autogen::BgpRouter());
2004  autogen::BgpRouterParams param;
2005  DefaultBgpRouterParams(&param);
2006  router->SetProperty("bgp-router-parameters", &param);
2007  BgpIfmapProtocolConfig *protocol = rti->LocateProtocol();
2008  protocol->Update(this, router.release());
2010 
2011  vector<string> import_list;
2012  vector<string> export_list;
2014  Create, server(), rti, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
2015  import_list, export_list,
2016  rti->virtual_network(), rti->virtual_network_index());
2017 
2019  Create, server(), protocol,
2020  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
2021  protocol->router_params().admin_down,
2022  protocol->router_params().autonomous_system,
2023  protocol->router_params().identifier,
2024  protocol->router_params().address,
2025  protocol->router_params().hold_time,
2026  vector<string>());
2027 }
2028 
2030  const autogen::GlobalSystemConfig *system) {
2031  bool changed = false;
2032 
2033  if (data_.gr_enable() != system->graceful_restart_parameters().enable) {
2034  data_.set_gr_enable(system->graceful_restart_parameters().enable);
2035  changed |= true;
2036  }
2037 
2038  if (data_.gr_time() != system->graceful_restart_parameters().restart_time) {
2039  data_.set_gr_time(system->graceful_restart_parameters().restart_time);
2040  changed |= true;
2041  }
2042 
2043  if (data_.llgr_time() != static_cast<uint32_t>(
2044  system->graceful_restart_parameters().long_lived_restart_time)) {
2046  system->graceful_restart_parameters().long_lived_restart_time);
2047  changed |= true;
2048  }
2049 
2050  if (data_.end_of_rib_timeout() !=
2051  system->graceful_restart_parameters().end_of_rib_timeout) {
2053  system->graceful_restart_parameters().end_of_rib_timeout);
2054  changed |= true;
2055  }
2056 
2057  if (data_.gr_bgp_helper() !=
2058  system->graceful_restart_parameters().bgp_helper_enable) {
2060  system->graceful_restart_parameters().bgp_helper_enable);
2061  changed |= true;
2062  }
2063 
2064  if (data_.gr_xmpp_helper() !=
2065  system->graceful_restart_parameters().xmpp_helper_enable) {
2067  system->graceful_restart_parameters().xmpp_helper_enable);
2068  changed |= true;
2069  }
2070 
2071  if (data_.enable_4byte_as() != system->enable_4byte_as()) {
2072  data_.set_enable_4byte_as(system->enable_4byte_as());
2073  changed |= true;
2074  }
2075 
2076  if (data_.always_compare_med() != system->bgp_always_compare_med()) {
2077  data_.set_always_compare_med(system->bgp_always_compare_med());
2078  changed |= true;
2079  }
2080 
2081  if (data_.rd_cluster_seed() != system->rd_cluster_seed()) {
2082  data_.set_rd_cluster_seed(system->rd_cluster_seed());
2083  changed |= true;
2084  }
2085 
2086  if (data_.xmpp_hold_time() !=
2087  system->fast_convergence_parameters().xmpp_hold_time) {
2089  system->fast_convergence_parameters().xmpp_hold_time);
2090  changed |= true;
2091  }
2092 
2093  if (data_.bgpaas_port_start() != system->bgpaas_parameters().port_start) {
2094  data_.set_bgpaas_port_start(system->bgpaas_parameters().port_start);
2095  changed |= true;
2096  }
2097 
2098  if (data_.bgpaas_port_end() != system->bgpaas_parameters().port_end) {
2099  data_.set_bgpaas_port_end(system->bgpaas_parameters().port_end);
2100  changed |= true;
2101  }
2102 
2103  if (data_.fc_enabled() != system->fast_convergence_parameters().enable) {
2104  data_.set_fc_enabled(system->fast_convergence_parameters().enable);
2105  changed |= true;
2106  }
2107 
2108  if (data_.nh_check_enabled() !=
2109  system->fast_convergence_parameters().nh_reachability_check) {
2111  system->fast_convergence_parameters().nh_reachability_check);
2112  changed |= true;
2113  }
2114 
2115  return changed;
2116 }
2117 
2119  const autogen::GlobalQosConfig *qos) {
2120  bool changed = false;
2121  const autogen::ControlTrafficDscpType &dscp = qos->control_traffic_dscp();
2122 
2123  if (data_.control_dscp() != dscp.control) {
2124  data_.set_control_dscp(dscp.control);
2125  Sandesh::SetDscpValue(dscp.control);
2126  changed = true;
2127  }
2128  if (data_.analytics_dscp() != dscp.analytics) {
2129  data_.set_analytics_dscp(dscp.analytics);
2130  changed = true;
2131  }
2132  return changed;
2133 }
2134 
2135 //
2136 // Initialize IdentifierMap with handlers for interesting identifier types.
2137 //
2138 // The IdentifierMap is used when processing BgpConfigDeltas generated by
2139 // the BgpConfigListener.
2140 //
2142  id_map_.insert(make_pair("routing-instance",
2144  this, _1)));
2145  id_map_.insert(make_pair("routing-policy",
2146  boost::bind(&BgpIfmapConfigManager::ProcessRoutingPolicy, this, _1)));
2147  id_map_.insert(make_pair("routing-policy-routing-instance",
2149  _1)));
2150  id_map_.insert(make_pair("bgp-router",
2151  boost::bind(&BgpIfmapConfigManager::ProcessBgpRouter, this, _1)));
2152  id_map_.insert(make_pair("bgp-peering",
2153  boost::bind(&BgpIfmapConfigManager::ProcessBgpPeering, this, _1)));
2154  id_map_.insert(make_pair("global-system-config",
2156  _1)));
2157  id_map_.insert(make_pair("global-qos-config",
2159  _1)));
2160 }
2161 
2164  if (!rti) {
2165  return;
2166  }
2167 
2168  // in case of id change, update import list and call subsequent code
2169  Notify(rti->instance_config(), event);
2170 
2171  vector<string> import_rt(rti->import_list().begin(),
2172  rti->import_list().end());
2173  vector<string> export_rt(rti->export_list().begin(),
2174  rti->export_list().end());
2175  if (event == BgpConfigManager::CFG_ADD) {
2176  BGP_CONFIG_LOG_INSTANCE(Create, server(), rti,
2177  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
2178  import_rt, export_rt,
2179  rti->virtual_network(), rti->virtual_network_index());
2180  } else {
2181  BGP_CONFIG_LOG_INSTANCE(Update, server(), rti,
2182  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
2183  import_rt, export_rt,
2184  rti->virtual_network(), rti->virtual_network_index());
2185  }
2186 }
2187 
2188 //
2189 // Handler for routing-instance objects.
2190 //
2191 // Note that BgpIfmapInstanceConfig object for the master instance is created
2192 // before we have received any configuration for it i.e. there's no IFMapNode
2193 // or autogen::RoutingInstance for it. However, we will eventually receive a
2194 // delta for the master. The IFMapNodeProxy and autogen::RoutingInstance are
2195 // set at that time.
2196 //
2197 // For other routing-instances BgpIfmapConfigInstance can get created before we
2198 // see the IFMapNode for the routing-instance if we see the IFMapNode for the
2199 // local bgp-router in the routing-instance. In this case, the IFMapNodeProxy
2200 // and autogen::RoutingInstance are set when we later see the IFMapNode for the
2201 // routing-instance.
2202 //
2203 // In all other cases, BgpIfmapConfigInstance is created when we see IFMapNode
2204 // for the routing-instance. The IFMapNodeProxy and autogen::RoutingInstance
2205 // are set right away.
2206 //
2207 // References to the IFMapNode and the autogen::RoutingInstance are
2208 // released when the IFMapNode is marked deleted. However the
2209 // BgpIfmapInstanceConfig does not get deleted till the NeighborMap is
2210 // empty and the BgpIfmapProtocolConfig is gone.
2211 //
2213  const BgpConfigDelta &delta) {
2214  CHECK_CONCURRENCY("bgp::Config");
2215 
2217  string instance_name = delta.id_name;
2218  BgpIfmapInstanceConfig *rti = config_->FindInstance(instance_name);
2219  if (rti == NULL) {
2220  IFMapNodeProxy *proxy = delta.node.get();
2221  if (proxy == NULL) {
2222  return;
2223  }
2224  IFMapNode *node = proxy->node();
2225  if (node == NULL || node->IsDeleted()) {
2226  return;
2227  }
2228  event = BgpConfigManager::CFG_ADD;
2229  rti = config_->LocateInstance(instance_name);
2230  rti->SetNodeProxy(proxy);
2231  } else {
2232  IFMapNode *node = rti->node();
2233  if (node == NULL) {
2234  IFMapNodeProxy *proxy = delta.node.get();
2235  if (proxy == NULL) {
2236  return;
2237  }
2238  rti->SetNodeProxy(proxy);
2239  } else if (node->IsDeleted()) {
2240  rti->ResetConfig();
2241  if (rti->DeleteIfEmpty(this)) {
2243  Delete, server(), rti,
2244  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL);
2245  config_->DeleteInstance(rti);
2246  }
2247  return;
2248  }
2249  }
2250 
2251  autogen::RoutingInstance *rti_config =
2252  static_cast<autogen::RoutingInstance *>(delta.obj.get());
2253  if (rti->index() != -1)
2254  rti->instance_config()->set_index(rti->index());
2255  rti->Update(this, rti_config);
2256  UpdateInstanceConfig(rti, event);
2257 }
2258 
2259 //
2260 // Handler for bgp protocol config.
2261 //
2262 // Note that there's no underlying IFMap object for the bgp protocol config.
2263 // This is called by the handler for bgp-router objects. The BgpConfigDelta
2264 // is a delta for the bgp-router object.
2265 //
2267  CHECK_CONCURRENCY("bgp::Config");
2268 
2270  string instance_name(IdentifierParent(delta.id_name));
2271  BgpIfmapInstanceConfig *rti = config_->FindInstance(instance_name);
2272  BgpIfmapProtocolConfig *protocol = NULL;
2273  if (rti != NULL) {
2274  protocol = rti->protocol_config_mutable();
2275  }
2276 
2277  if (protocol == NULL) {
2278  IFMapNodeProxy *proxy = delta.node.get();
2279  if (proxy == NULL) {
2280  return;
2281  }
2282  // ignore identifier with no properties
2283  if (delta.obj.get() == NULL) {
2284  return;
2285  }
2286  IFMapNode *node = proxy->node();
2287  if (node == NULL || node->IsDeleted()) {
2288  return;
2289  }
2290  event = BgpConfigManager::CFG_ADD;
2291  if (rti == NULL) {
2292  rti = config_->LocateInstance(instance_name);
2293  UpdateInstanceConfig(rti, event);
2294  }
2295  protocol = rti->LocateProtocol();
2296  protocol->SetNodeProxy(proxy);
2297  } else {
2298  IFMapNode *node = protocol->node();
2299  if (node == NULL) {
2300  // The master instance creates a BgpRouter node internally. Ignore
2301  // an update that doesn't specify any content.
2302  if (delta.obj.get() == NULL) {
2303  return;
2304  }
2305  protocol->SetNodeProxy(delta.node.get());
2306  } else if (delta.obj.get() == NULL) {
2307  BGP_CONFIG_LOG_PROTOCOL(Delete, server(), protocol,
2308  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL);
2309  protocol->Delete(this);
2310  rti->ResetProtocol();
2311  if (rti->DeleteIfEmpty(this)) {
2312  BGP_CONFIG_LOG_INSTANCE(Delete, server(), rti,
2313  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL);
2314  config_->DeleteInstance(rti);
2315  }
2316  return;
2317  }
2318  }
2319 
2320  autogen::BgpRouter *rt_config =
2321  static_cast<autogen::BgpRouter *>(delta.obj.get());
2322  uint32_t old_id = protocol->protocol_config()->identifier();
2323  uint32_t old_as = protocol->protocol_config()->autonomous_system();
2324  protocol->Update(this, rt_config);
2325  uint32_t new_id = protocol->protocol_config()->identifier();
2326  uint32_t new_as = protocol->protocol_config()->autonomous_system();
2327  if (new_id != old_id || new_as != old_as) {
2328  config_->ProcessIdentifierAndASUpdate(this, new_id, old_id, new_as,
2329  old_as);
2330  }
2331  Notify(protocol->protocol_config(), event);
2332 
2333  if (!rt_config) {
2334  return;
2335  }
2336 
2337  vector<string> families(
2338  protocol->router_params().address_families.begin(),
2339  protocol->router_params().address_families.end());
2340  if (event == BgpConfigManager::CFG_ADD) {
2341  BGP_CONFIG_LOG_PROTOCOL(Create, server(), protocol,
2342  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
2343  protocol->router_params().admin_down,
2344  protocol->router_params().autonomous_system,
2345  protocol->router_params().identifier,
2346  protocol->router_params().address,
2347  protocol->router_params().hold_time,
2348  families);
2349  } else {
2350  BGP_CONFIG_LOG_PROTOCOL(Update, server(), protocol,
2351  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
2352  protocol->router_params().admin_down,
2353  protocol->router_params().autonomous_system,
2354  protocol->router_params().identifier,
2355  protocol->router_params().address,
2356  protocol->router_params().hold_time,
2357  families);
2358  }
2359 }
2360 
2361 //
2362 // Handler for routing policy objects.
2363 //
2364 // BgpConfigListener::DependencyTracker ensures associated routing instances
2365 // are present in the change list.
2366 //
2368  CHECK_CONCURRENCY("bgp::Config");
2369 
2371  string policy_name = delta.id_name;
2372  BgpIfmapRoutingPolicyConfig *rtp = config_->FindRoutingPolicy(policy_name);
2373  if (rtp == NULL) {
2374  IFMapNodeProxy *proxy = delta.node.get();
2375  if (proxy == NULL) {
2376  return;
2377  }
2378  IFMapNode *node = proxy->node();
2379  if (node == NULL || node->IsDeleted()) {
2380  return;
2381  }
2382  event = BgpConfigManager::CFG_ADD;
2383  rtp = config_->LocateRoutingPolicy(policy_name);
2384  rtp->SetNodeProxy(proxy);
2385  } else {
2386  IFMapNode *node = rtp->node();
2387  if (node == NULL) {
2388  IFMapNodeProxy *proxy = delta.node.get();
2389  if (proxy == NULL) {
2390  return;
2391  }
2392  rtp->SetNodeProxy(proxy);
2393  } else if (node->IsDeleted()) {
2394  rtp->ResetConfig();
2395  if (rtp->DeleteIfEmpty(this)) {
2396  config_->DeleteRoutingPolicy(rtp);
2397  }
2398  return;
2399  }
2400  }
2401 
2402  autogen::RoutingPolicy *rtp_config =
2403  static_cast<autogen::RoutingPolicy *>(delta.obj.get());
2404  rtp->Update(this, rtp_config);
2405  Notify(rtp->routing_policy_config(), event);
2406 }
2407 
2408 
2409 //
2410 // Handler for bgp-router objects.
2411 //
2413  CHECK_CONCURRENCY("bgp::Config");
2414 
2415  string instance_name(IdentifierParent(delta.id_name));
2416  if (instance_name.empty() ||
2417  instance_name != BgpConfigManager::kMasterInstance) {
2418  return;
2419  }
2420 
2421  // Ignore if this change is not for the local router.
2422  string name = delta.id_name.substr(instance_name.size() + 1);
2423  if (name != localname_) {
2424  return;
2425  }
2426 
2427  ProcessBgpProtocol(delta);
2428 
2429  // Update all peerings since we use local asn and identifier from master
2430  // instance for all neighbors, including those in non-master instances.
2431  BOOST_FOREACH(const BgpIfmapConfigData::IfmapPeeringMap::value_type &value,
2432  config_->peerings()) {
2433  BgpIfmapPeeringConfig *peering = value.second;
2434  peering->Update(this, peering->bgp_peering());
2435  }
2436 }
2437 
2438 //
2439 // Handler for bgp-peering objects.
2440 //
2441 // We are only interested in this bgp-peering if it is adjacent to the local
2442 // router node.
2443 //
2444 // The BgpPeeringConfig is created the first time we see the bgp-peering. It
2445 // is updated on subsequent changes and is deleted when the IFMapNode midnode
2446 // for the bgp-peering is deleted.
2447 //
2448 // Note that we are guaranteed that the IFMapNodes for the 2
2449 // bgp-routers for the bgp-peering already exist when we see the
2450 // bgp-peering. IFMap creates the nodes for the bgp-routers before
2451 // creating the midnode. This in turn guarantees that the
2452 // BgpIfmapInstanceConfig for the routing-instance also exists since we
2453 // create the BgpIfmapInstanceConfig before creating the
2454 // BgpIfmapProtocolConfig for a local bgp-router.
2455 //
2457  CHECK_CONCURRENCY("bgp::Config");
2458 
2460  BgpIfmapPeeringConfig *peering = config_->FindPeering(delta.id_name);
2461  if (peering == NULL) {
2462  IFMapNodeProxy *proxy = delta.node.get();
2463  if (proxy == NULL) {
2464  BGP_LOG_STR(BgpConfig, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_SYSLOG,
2465  "ProcessBgpPeering failed. Cannot find proxy " <<
2466  delta.id_name);
2467  return;
2468  }
2469  IFMapNode *node = proxy->node();
2470  if (node == NULL || delta.obj.get() == NULL) {
2471  BGP_LOG_STR(BgpConfig, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_SYSLOG,
2472  "ProcessBgpPeering failed. Cannot find node/obj " <<
2473  delta.id_name);
2474  return;
2475  }
2476 
2477  pair<IFMapNode *, IFMapNode *> routers;
2479  &routers)) {
2480  return;
2481  }
2482 
2483  string instance_name(IdentifierParent(routers.first->name()));
2484  BgpIfmapInstanceConfig *rti = config_->FindInstance(instance_name);
2485  event = BgpConfigManager::CFG_ADD;
2486  // Create rti if not present.
2487  if (rti == NULL) {
2488  rti = config_->LocateInstance(instance_name);
2489  UpdateInstanceConfig(rti, event);
2490  }
2491  peering = config_->CreatePeering(rti, proxy);
2492  } else {
2493  const IFMapNode *node = peering->node();
2494  assert(node != NULL);
2495  if (delta.obj.get() == NULL) {
2496  BGP_CONFIG_LOG_PEERING(Delete, server(), peering,
2497  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL);
2498  BgpIfmapInstanceConfig *rti = peering->instance();
2499  peering->Delete(this);
2500  config_->DeletePeering(peering);
2501  if (rti->DeleteIfEmpty(this)) {
2502  BGP_CONFIG_LOG_INSTANCE(Delete, server(), rti,
2503  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL);
2504  config_->DeleteInstance(rti);
2505  }
2506  return;
2507  }
2508  }
2509 
2510  if (event == BgpConfigManager::CFG_ADD) {
2511  BGP_CONFIG_LOG_PEERING(Create, server(), peering,
2512  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL);
2513  } else {
2514  BGP_CONFIG_LOG_PEERING(Update, server(), peering,
2515  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL);
2516  }
2517  autogen::BgpPeering *peering_config =
2518  static_cast<autogen::BgpPeering *>(delta.obj.get());
2519  peering->Update(this, peering_config);
2520 }
2521 
2523  const BgpConfigDelta &delta) {
2524  IFMapNodeProxy *proxy = delta.node.get();
2525  if (proxy == NULL)
2526  return;
2527 
2528  IFMapNode *node = proxy->node();
2529  autogen::GlobalSystemConfig *config, default_config;
2530  if (node == NULL || node->IsDeleted() || delta.obj.get() == NULL) {
2531  config = &default_config;
2532  } else {
2533  config = static_cast<autogen::GlobalSystemConfig *>(delta.obj.get());
2534  }
2535 
2536  if (config_->global_config()->Update(this, config))
2537  Notify(config_->global_config()->config(), BgpConfigManager::CFG_ADD);
2538 }
2539 
2541  const BgpConfigDelta &delta) {
2542  IFMapNodeProxy *proxy = delta.node.get();
2543  if (proxy == NULL)
2544  return;
2545 
2546  IFMapNode *node = proxy->node();
2547  autogen::GlobalQosConfig *config, default_config;
2548  if (node == NULL || node->IsDeleted() || delta.obj.get() == NULL) {
2549  config = &default_config;
2550  } else {
2551  config = static_cast<autogen::GlobalQosConfig *>(delta.obj.get());
2552  }
2553 
2554  if (config_->global_qos()->Update(this, config))
2555  Notify(config_->global_qos()->config(), BgpConfigManager::CFG_ADD);
2556 }
2557 
2558 //
2559 // Process the BgpConfigDeltas on the change list. We simply call the handler
2560 // for each delta based on the object's identifier type.
2561 //
2563  CHECK_CONCURRENCY("bgp::Config");
2564 
2565  for (ChangeList::const_iterator iter = change_list.begin();
2566  iter != change_list.end(); ++iter) {
2567  IdentifierMap::iterator loc = id_map_.find(iter->id_type);
2568  if (loc != id_map_.end()) {
2569  (loc->second)(*iter);
2570  }
2571  }
2572 }
2573 
2574 //
2575 // Build and process the change list of BgpConfigDeltas. The logic to build
2576 // the list is in BgpConfigListener and BgpConfigListener::DependencyTracker.
2577 //
2579  CHECK_CONCURRENCY("bgp::Config");
2580 
2581  BgpConfigListener::ChangeList change_list;
2582  listener_->GetChangeList(&change_list);
2583  ProcessChanges(change_list);
2584  return true;
2585 }
2586 
2587 //
2588 // Terminate the BgpConfigManager.
2589 //
2591  listener_->Terminate();
2592  config_.reset();
2593 }
#define BGP_CONFIG_LOG_PROTOCOL(type, server, protocol, level, flags,...)
Definition: bgp_log.h:296
virtual const BgpNeighborConfig * FindNeighbor(const std::string &instance_name, const std::string &name) const
void ProcessGlobalSystemConfig(const BgpConfigDelta &delta)
std::vector< std::string > route_targets
Definition: bgp_config.h:342
void set_peer_address(const IpAddress &address)
Definition: bgp_config.h:202
void ProcessRoutingPolicy(const BgpConfigDelta &change)
uint32_t local_pref
Definition: bgp_config.h:378
const RouteTargetList & export_list() const
BgpIfmapPeeringConfig * FindPeering(const std::string &name)
const RouteTargetList & import_list() const
Definition: bgp_config.h:442
bool nh_check_enabled() const
Definition: bgp_config.h:645
void delete_neighbor(const std::string &neighbor)
Definition: bgp_config.h:438
void Update(BgpIfmapConfigManager *manager, const autogen::BgpRouter *router)
const BgpNeighborConfig * FindNeighbor(const std::string &name) const
std::vector< std::string > AddressFamilyList
Definition: bgp_config.h:141
void DeleteRoutingPolicyLink(BgpIfmapRoutingPolicyLinkConfig *ri_rp_link)
void AddPeering(BgpIfmapPeeringConfig *peering)
BgpIfmapInstanceConfig * instance()
void set_cluster_id(uint32_t cluster_id)
Definition: bgp_config.h:550
void set_subcluster_name(const std::string &name)
Definition: bgp_config.h:556
IFMapNodeProxy node_proxy_
void add_term(const RoutingPolicyTermConfig &term)
Definition: bgp_config.h:407
void AddInstance(BgpIfmapInstanceConfig *rti)
const IFMapNode * node() const
void ProcessBgpPeering(const BgpConfigDelta &change)
boost::intrusive_ptr< const autogen::BgpPeering > bgp_peering_
void set_virtual_network_index(int virtual_network_index)
Definition: bgp_config.h:460
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:178
IpAddress address
Definition: bgp_config.h:339
void Update(BgpIfmapConfigManager *manager, const autogen::RoutingPolicy *policy)
bool admin_down() const
Definition: bgp_config.h:181
IFMapNodeProxy node_proxy_
void ReserveBit(int index)
Definition: index_map.h:42
static void SetStaticRouteConfig(BgpInstanceConfig *rti, const autogen::RoutingInstance *config)
void set_virtual_network_pbb_evpn_enable(bool pbb_evpn)
Definition: bgp_config.h:474
static bool GetRouteAggregateConfig(DBGraph *graph, IFMapNode *node, BgpInstanceConfig::AggregateRouteList *inet_list, BgpInstanceConfig::AggregateRouteList *inet6_list)
BgpConfigManager::RoutingPolicyMapRange RoutingPolicyMapItems(const std::string &start_name=std::string()) const
void set_gateway_address(Address::Family family, const IpAddress &address)
Definition: bgp_config.cc:272
static void BuildFamilyAttributesList(BgpNeighborConfig *neighbor, const BgpNeighborConfig::AddressFamilyList &family_list, const vector< string > &remote_family_list)
const RouteTargetList & import_list() const
uint8_t control_dscp() const
Definition: bgp_config.h:704
BgpIfmapPeeringConfig * CreatePeering(BgpIfmapInstanceConfig *rti, IFMapNodeProxy *proxy)
BgpIfmapConfigManager(BgpServer *server)
std::pair< RoutingPolicyMap::const_iterator, RoutingPolicyMap::const_iterator > RoutingPolicyMapRange
Definition: bgp_config.h:755
BgpGlobalQosConfig data_
void set_name(const std::string &name)
Definition: bgp_config.h:163
const BgpIfmapConfigData * config() const
void set_virtual_network_allow_transit(bool allow_transit)
Definition: bgp_config.h:467
const std::string & name() const
Definition: bgp_config.h:162
std::pair< InstanceMap::const_iterator, InstanceMap::const_iterator > InstanceMapRange
Definition: bgp_config.h:758
void Update(BgpIfmapConfigManager *manager, const autogen::RoutingInstance *config)
void set_gr_time(uint16_t gr_time)
Definition: bgp_config.h:624
void Update(BgpIfmapConfigManager *manager, const autogen::RoutingPolicyRoutingInstance *ri_rp)
void set_identifier(uint32_t identifier)
Definition: bgp_config.h:553
bool Update(BgpIfmapConfigManager *manager, const autogen::GlobalSystemConfig *system)
const std::string & instance_name() const
Definition: bgp_config.h:168
#define EVPN_ES_IMPORT_ROUTE_TARGET_AS2
uint32_t autonomous_system() const
Definition: bgp_config.h:567
void set_virtual_network(const std::string &virtual_network)
Definition: bgp_config.h:455
bool gr_bgp_helper() const
Definition: bgp_config.h:631
void SetNodeProxy(IFMapNodeProxy *proxy)
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)
void set_always_compare_med(bool always_compare_med)
Definition: bgp_config.h:652
static const char * kMasterInstance
Definition: bgp_config.h:764
bool IsDeleted() const
Definition: db_entry.h:49
void reset_subcluster_id()
Definition: bgp_config.h:565
BgpIfmapProtocolConfig * protocol_config_mutable()
void swap_aggregate_routes(Address::Family family, AggregateRouteList *list)
Definition: bgp_config.cc:399
void Notify(const BgpConfigObject *, EventType)
boost::asio::ip::address IpAddress
Definition: address.h:13
PrefixMatchConfigList prefixes_to_match
Definition: bgp_config.h:362
uint16_t rd_cluster_seed() const
Definition: bgp_config.h:661
static string BgpIdentifierToString(uint32_t identifier)
void set_local_as(uint32_t local_as)
Definition: bgp_config.h:234
void set_subcluster_id(uint32_t id)
Definition: bgp_config.h:562
void ProcessIdentifierAndASUpdate(BgpIfmapConfigManager *manager, uint32_t new_id, uint32_t old_id, uint32_t new_as, uint32_t old_as)
CommunityList community_match
Definition: bgp_config.h:363
BgpGlobalSystemConfig data_
void set_vxlan_id(int vxlan_id)
Definition: bgp_config.h:480
virtual const BgpRoutingPolicyConfig * FindRoutingPolicy(const std::string &name) const
void Delete(BgpIfmapConfigManager *manager)
BgpIfmapRoutingPolicyConfig * LocateRoutingPolicy(const std::string &name)
void swap_routing_policy_list(RoutingPolicyConfigList *list)
Definition: bgp_config.h:500
virtual const char * Typename() const =0
std::vector< AggregateRouteConfig > AggregateRouteList
Definition: bgp_config.h:427
void set_private_as_action(const std::string &private_as_action)
Definition: bgp_config.h:191
BgpIfmapRoutingPolicyLinkConfig * CreateRoutingPolicyLink(BgpIfmapInstanceConfig *rti, BgpIfmapRoutingPolicyConfig *rtp, IFMapNodeProxy *proxy)
void set_peer_identifier(uint32_t identifier)
Definition: bgp_config.h:206
void set_index(int index)
void set_import_list(const RouteTargetList &import_list)
Definition: bgp_config.h:443
std::set< std::string > RouteTargetList
Definition: bgp_config.h:424
static void BuildPolicyTermConfig(autogen::PolicyTermType cfg_term, RoutingPolicyTermConfig *term)
void DeletePeering(BgpIfmapPeeringConfig *peering)
void set_loop_count(uint8_t loop_count)
Definition: bgp_config.h:231
IpAddress nexthop
Definition: bgp_config.h:341
BgpInstanceMap instance_config_map_
static void SetDscpValue(uint8_t value)
Definition: sandesh.cc:334
adjacency_iterator end(DBGraph *graph)
bool Empty() const
Definition: bgp_config.cc:106
void set_hold_time(int hold_time)
Definition: bgp_config.h:228
const FamilyAttributesList & family_attributes_list() const
Definition: bgp_config.h:253
IfmapInstanceMap instances_
IFMapTable * table()
Definition: ifmap_node.h:29
void DefaultAddressFamilyInit()
std::set< StaticRouteConfig > StaticRouteList
Definition: bgp_config.h:425
std::vector< std::string > communities
Definition: bgp_config.h:343
static bool GetVirtualNetworkPbbEvpnEnable(DBGraph *graph, IFMapNode *node)
void SetNodeProxy(IFMapNodeProxy *proxy)
std::string router_type() const
Definition: bgp_config.h:222
static bool AddressFamilyIsValid(BgpNeighborConfig *neighbor, const string &family)
void AddNeighbor(BgpConfigManager *manager, BgpNeighborConfig *neighbor)
ValueType * At(int index) const
Definition: index_map.h:31
#define BGP_CONFIG_LOG_NEIGHBOR(type, server, neighbor, level, flags,...)
Definition: bgp_log.h:288
void set_source_port(uint16_t source_port)
Definition: bgp_config.h:220
CommunityList ext_community_remove
Definition: bgp_config.h:377
boost::scoped_ptr< BgpIfmapConfigData > config_
void ProcessBgpProtocol(const BgpConfigDelta &change)
ProtocolList protocols_match
Definition: bgp_config.h:361
#define EVPN_ES_IMPORT_ROUTE_TARGET_AS4
void DeleteNeighbor(BgpConfigManager *manager, BgpNeighborConfig *neighbor)
void Initialize(DB *db, DBGraph *db_graph, const std::string &localname)
#define BGP_LOG_STR(obj, level, flags, arg)
Definition: bgp_log.h:89
CommunityList community_remove
Definition: bgp_config.h:374
RoutingPolicyActionConfig action
Definition: bgp_config.h:395
void DeletePeering(BgpIfmapPeeringConfig *peer)
BgpRoutingPolicyConfig data_
bool gr_xmpp_helper() const
Definition: bgp_config.h:633
Definition: db.h:24
void set_local_autonomous_system(uint32_t local_autonomous_system)
Definition: bgp_config.h:575
void Delete(BgpIfmapConfigManager *manager)
static uint32_t IpAddressToBgpIdentifier(const IpAddress &address)
uint32_t peer_as() const
Definition: bgp_config.h:198
virtual const std::string & localname() const
void Swap(IFMapNodeProxy *rhs)
BgpIfmapRoutingPolicyConfig * policy()
bool Update(BgpIfmapConfigManager *manager, const autogen::GlobalQosConfig *qos)
bool always_compare_med() const
Definition: bgp_config.h:651
void SetOriginOverride(bool origin_override, std::string origin)
Definition: bgp_config.cc:256
const NeighborMap & neighbors() const
BgpIfmapRoutingPolicyLinkConfig * FindRoutingPolicyLink(const std::string &name)
std::string name() const
std::vector< std::string > default_tunnel_encap_list
Definition: bgp_config.h:99
uint16_t gr_time() const
Definition: bgp_config.h:623
IfmapPeeringMap peerings_
void set_hold_time(uint32_t hold_time)
Definition: bgp_config.h:583
boost::intrusive_ptr< const autogen::BgpRouter > bgp_router_
void set_key_type(KeyType in_type)
Definition: bgp_config.h:71
void DeleteRoutingPolicy(BgpIfmapRoutingPolicyConfig *rtp)
static bool GetRouterPair(DBGraph *db_graph, const std::string &localname, IFMapNode *node, std::pair< IFMapNode *, IFMapNode * > *pair)
#define BGP_LOG_FLAG_SYSLOG
Definition: bgp_log.h:42
const autogen::BgpRouterParams & router_params() const
const std::string & name() const
static const std::string integerToString(const NumberType &num)
Definition: string_util.h:19
BgpProtocolConfig data_
void set_router_type(const std::string &router_type)
Definition: bgp_config.h:223
bool fc_enabled() const
Definition: bgp_config.h:639
void Remove(const KeyType &key, int index, bool clear_bit=true)
Definition: index_map.h:69
#define BGP_CONFIG_LOG_INSTANCE(type, server, rtinstance, level, flags,...)
Definition: bgp_log.h:284
uint32_t identifier() const
Definition: bgp_config.h:552
static BgpNeighborConfig::AddressFamilyList default_addr_family_list
std::string sequence_
Definition: bgp_common.h:36
std::vector< ConfigDelta > ChangeList
void swap_service_chain_list(ServiceChainList *list)
Definition: bgp_config.h:491
IfmapRoutingPolicyMap routing_policies_
void InsertVitAndESRTargetInImportList(BgpIfmapConfigManager *manager, BgpInstanceConfig::RouteTargetList &import_list)
virtual int NeighborCount(const std::string &instance_name) const
static AuthenticationData::KeyType KeyChainType(const string &value)
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:15
void swap_static_routes(Address::Family family, StaticRouteList *list)
Definition: bgp_config.cc:369
std::pair< NeighborMap::const_iterator, NeighborMap::const_iterator > NeighborMapRange
Definition: bgp_config.h:761
static void GetRoutingInstanceExportTargets(DBGraph *graph, IFMapNode *node, vector< string > *target_list)
void STLDeleteElements(Container *container)
Definition: util.h:114
BgpIfmapInstanceConfig * LocateInstance(const std::string &name)
#define CHECK_CONCURRENCY(...)
std::vector< RoutingPolicyAttachInfo > RoutingPolicyConfigList
Definition: bgp_common.h:40
virtual RoutingPolicyMapRange RoutingPolicyMapItems(const std::string &start_name=std::string()) const
void set_analytics_dscp(uint8_t value)
Definition: bgp_config.h:707
const std::string & virtual_network() const
BgpIfmapInstanceConfig * instance_
static void SetServiceChainConfig(BgpInstanceConfig *rti, const autogen::RoutingInstance *config)
bool DeleteIfEmpty(BgpConfigManager *manager)
std::vector< std::string > AuthKeysToString() const
Definition: bgp_config.cc:297
void set_family_attributes_list(const FamilyAttributesList &family_attributes_list)
Definition: bgp_config.h:257
void DeleteRoutingPolicy(BgpIfmapRoutingPolicyConfig *rtp)
std::string GetESRouteTarget(uint32_t as) const
virtual const BgpProtocolConfig * GetProtocolConfig(const std::string &instance_name) const
bool DeleteIfEmpty(BgpConfigManager *manager)
uint16_t end_of_rib_timeout() const
Definition: bgp_config.h:629
CommunityList community_add
Definition: bgp_config.h:373
const AuthenticationData & auth_data() const
Definition: bgp_config.h:244
uint32_t med
Definition: bgp_config.h:379
RoutingPolicyMatchConfig match
Definition: bgp_config.h:394
RouitngPolicyMap routing_policies_
void set_local_identifier(uint32_t identifier)
Definition: bgp_config.h:237
static const int kConfigTaskInstanceId
void set_enable_4byte_as(bool as_4byte)
Definition: bgp_config.h:638
void ProcessIdentifierUpdate(uint32_t new_id, uint32_t old_id)
virtual InstanceMapRange InstanceMapItems(const std::string &start_name=std::string()) const
void SetNodeProxy(IFMapNodeProxy *proxy)
BgpIfmapInstanceConfig * instance()
std::string AuthKeyTypeToString() const
Definition: bgp_config.cc:292
CommunityList ext_community_set
Definition: bgp_config.h:375
#define BGP_LOG_WARNING_STR(obj, flags, arg)
Definition: bgp_log.h:107
void UpdateInstanceConfig(BgpIfmapInstanceConfig *rti, BgpConfigManager::EventType event)
BgpIfmapPeeringConfig(BgpIfmapInstanceConfig *instance)
uint32_t local_as() const
Definition: bgp_config.h:233
const std::string & name() const
Definition: ifmap_node.h:48
void set_gr_xmpp_helper(bool helper)
Definition: bgp_config.h:634
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
boost::system::error_code Ip4SubnetParse(const string &str, Ip4Address *addr, int *plen)
Definition: address.cc:131
std::string value
Definition: bgp_config.h:35
uint16_t bgpaas_port_start() const
Definition: bgp_config.h:667
boost::intrusive_ptr< const autogen::RoutingPolicy > routing_policy_
void AddRoutingPolicy(BgpIfmapRoutingPolicyConfig *rtp)
AddressFamilyList GetAddressFamilies() const
Definition: bgp_config.cc:283
static void GetConnectionExportTargets(DBGraph *graph, IFMapNode *src_node, const string &src_instance, IFMapNode *node, vector< string > *target_list)
std::vector< BgpFamilyAttributesConfig > FamilyAttributesList
Definition: bgp_config.h:142
void ProcessASUpdate(uint32_t new_as, uint32_t old_as)
std::vector< ServiceChainConfig > ServiceChainList
Definition: bgp_config.h:426
void clear()
Definition: index_map.h:104
void set_llgr_time(uint64_t llgr_time)
Definition: bgp_config.h:626
IFMapObject * GetObject()
Definition: ifmap_node.cc:63
void set_keydata(const AuthenticationData &in_auth_data)
Definition: bgp_config.h:247
uint8_t analytics_dscp() const
Definition: bgp_config.h:706
void ProcessBgpRouter(const BgpConfigDelta &change)
const std::string & InstanceName() const
BgpRoutingPolicyMap routing_policy_config_map_
virtual const BgpInstanceConfig * FindInstance(const std::string &name) const
uint8_t xmpp_hold_time() const
Definition: bgp_config.h:655
void set_fc_enabled(bool enable)
Definition: bgp_config.h:642
IfmapRoutingPolicyLinkMap ri_rp_links_
const std::string & name() const
uint16_t bgpaas_port_end() const
Definition: bgp_config.h:671
BgpIfmapProtocolConfig(BgpIfmapInstanceConfig *instance)
static int GetVirtualNetworkIndex(DBGraph *graph, IFMapNode *node)
BgpIfmapInstanceConfig * instance_
static void BuildPolicyTermsConfig(BgpRoutingPolicyConfig *policy_cfg, const autogen::RoutingPolicy *policy)
void set_rd_cluster_seed(uint16_t seed)
Definition: bgp_config.h:664
void set_gr_bgp_helper(bool helper)
Definition: bgp_config.h:632
static int GetVirtualNetworkVxlanId(DBGraph *graph, IFMapNode *node)
void DeleteInstance(BgpIfmapInstanceConfig *rti)
std::string GetVitFromId(uint32_t identifier) const
static bool GetRoutingInstanceRoutingPolicy(DBGraph *graph, IFMapNode *node, RoutingPolicyAttachInfo *ri_rp_link)
size_t size() const
Definition: index_map.h:100
const autogen::BgpPeering * bgp_peering() const
const BgpIfmapProtocolConfig * protocol_config() const
void set_bgpaas_port_start(uint16_t bgpaas_port_start)
Definition: bgp_config.h:668
void RemoveInstance(BgpIfmapInstanceConfig *rti)
void set_admin_down(bool admin_down)
Definition: bgp_config.h:182
void set_export_list(const RouteTargetList &export_list)
Definition: bgp_config.h:447
void Delete(BgpConfigManager *manager)
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)
BgpIfmapRoutingPolicyConfig(const std::string &name)
void set_admin_down(bool admin_down)
Definition: bgp_config.h:547
void ProcessChanges(const ChangeList &change_list)
IFMapNodeProxy node_proxy_
std::map< std::string, BgpNeighborConfig * > NeighborMap
void set_gr_enable(bool enable)
Definition: bgp_config.h:636
CommunityList ext_community_match
Definition: bgp_config.h:365
boost::scoped_ptr< BgpIfmapProtocolConfig > protocol_
IFMapNode * node()
void ProcessGlobalQosConfig(const BgpConfigDelta &delta)
static void NeighborSetSessionAttributes(BgpNeighborConfig *neighbor, const string &localname, const autogen::BgpSession *session)
void SetNodeProxy(IFMapNodeProxy *proxy)
std::vector< BgpConfigDelta > ChangeList
void set_has_pnf(bool has_pnf)
Definition: bgp_config.h:452
void set_instance_name(const std::string &instance_name)
Definition: bgp_config.h:169
static bool GetInstanceTargetRouteTarget(DBGraph *graph, IFMapNode *node, string *target)
bool passive() const
Definition: bgp_config.h:184
static const int kDefaultPort
Definition: bgp_config.h:766
bool enable_4byte_as() const
Definition: bgp_config.h:637
std::map< std::string, BgpNeighborConfig * > NeighborMap
Definition: bgp_config.h:759
static string IdentifierParent(const string &identifier)
void ChangeNeighbor(BgpConfigManager *manager, BgpNeighborConfig *neighbor)
void ProcessRoutingInstance(const BgpConfigDelta &change)
void set_passive(bool passive)
Definition: bgp_config.h:185
void add_neighbor(const std::string &neighbor)
Definition: bgp_config.h:435
void set_xmpp_hold_time(uint8_t hold_time)
Definition: bgp_config.h:658
void set_autonomous_system(uint32_t autonomous_system)
Definition: bgp_config.h:568
BgpIfmapProtocolConfig * LocateProtocol()
boost::scoped_ptr< BgpConfigListener > listener_
void SetNodeProxy(IFMapNodeProxy *proxy)
static void BuildKeyChain(BgpNeighborConfig *neighbor, const autogen::AuthenticationData &values)
static bool GetVirtualNetworkAllowTransit(DBGraph *graph, IFMapNode *node)
void set_port(int port)
Definition: bgp_config.h:580
void set_index(int index)
Definition: bgp_config.h:508
void set_peer_as(uint32_t peer_as)
Definition: bgp_config.h:199
uint32_t local_identifier() const
Definition: bgp_config.h:236
BgpConfigManager::NeighborMapRange NeighborMapItems() const
void set_port(uint16_t port)
Definition: bgp_config.h:217
void AddKeyToKeyChain(const AuthenticationKey &key)
Definition: bgp_config.cc:91
void Update(BgpIfmapConfigManager *manager, const autogen::BgpPeering *peering)
BgpInstanceConfig * instance_config()
void Delete(BgpIfmapConfigManager *manager)
void set_as_override(bool as_override)
Definition: bgp_config.h:188
const std::string & name() const
Definition: bgp_config.h:432
BgpIfmapRoutingPolicyLinkConfig(BgpIfmapInstanceConfig *rti, BgpIfmapRoutingPolicyConfig *rtp)
virtual void ResetRoutingInstanceIndexBit(int index)
IfmapInstanceMap & instances()
adjacency_iterator begin(DBGraph *graph)
CommunityList community_set
Definition: bgp_config.h:372
uint32_t llgr_time() const
Definition: bgp_config.h:625
BgpIfmapInstanceConfig * FindInstance(const std::string &name)
CommunityList ext_community_add
Definition: bgp_config.h:376
const IpAddress & peer_address() const
Definition: bgp_config.h:201
BgpIfmapInstanceConfig(const std::string &name)
const BgpServer * server()
Definition: bgp_config.h:800
BgpConfigManager::InstanceMapRange InstanceMapItems(const std::string &start_name=std::string()) const
void set_end_of_rib_timeout(uint16_t time)
Definition: bgp_config.h:630
const BgpProtocolConfig * protocol_config() const
BgpInstanceConfig data_
bool gr_enable() const
Definition: bgp_config.h:635
const IFMapNode * node() const
boost::intrusive_ptr< const autogen::RoutingPolicyRoutingInstance > ri_rp_link_
static bool CompareRoutingPolicyOrder(const RoutingPolicyAttachInfo &lhs, const RoutingPolicyAttachInfo &rhs)
AsnList aspath_expand
Definition: bgp_config.h:371
virtual NeighborMapRange NeighborMapItems(const std::string &instance_name) const
BgpRoutingPolicyConfig * routing_policy_config()
void reset_subcluster_name()
Definition: bgp_config.h:559
ValueType * Find(const KeyType &key) const
Definition: index_map.h:34
#define MODULE_INITIALIZER(Func)
Definition: util.h:61
#define BGP_CONFIG_LOG_PEERING(type, server, peering, level, flags,...)
Definition: bgp_log.h:292
size_t Insert(const KeyType &key, ValueType *value, int index=-1)
Definition: index_map.h:50
void ResetBit(int index)
Definition: index_map.h:78
BgpIfmapRoutingPolicyConfig * FindRoutingPolicy(const std::string &name)
void set_uuid(const std::string &uuid)
Definition: bgp_config.h:166
const autogen::BgpRouter * bgp_router() const
void DefaultBgpRouterParams(autogen::BgpRouterParams *param)
static bool GetInstancePolicyPair(DBGraph *graph, IFMapNode *node, std::pair< IFMapNode *, IFMapNode * > *pair)
void set_bgpaas_port_end(uint16_t bgpaas_port_end)
Definition: bgp_config.h:672
boost::system::error_code Inet6SubnetParse(const string &str, Ip6Address *addr, int *plen)
Definition: address.cc:162
std::string routing_policy_
Definition: bgp_common.h:37
void ProcessRoutingPolicyLink(const BgpConfigDelta &change)
int virtual_network_index() const
#define BGP_LOG_FLAG_ALL
Definition: bgp_log.h:44
static const uint32_t kDefaultAutonomousSystem
Definition: bgp_config.h:767
void set_nh_check_enabled(bool enable)
Definition: bgp_config.h:648
void set_control_dscp(uint8_t value)
Definition: bgp_config.h:705