OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bgp_peer.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_peer.h"
6 
7 #include <algorithm>
8 #include <limits>
9 #include <map>
10 
11 #include <boost/assign/list_of.hpp>
12 #include <boost/foreach.hpp>
13 #include <boost/tuple/tuple.hpp>
14 
15 #include "base/set_util.h"
16 #include "base/task_annotations.h"
17 #include "bgp/bgp_factory.h"
18 #include "bgp/bgp_log.h"
19 #include "bgp/bgp_membership.h"
20 #include "bgp/bgp_peer_close.h"
21 #include "bgp/bgp_sandesh.h"
22 #include "bgp/bgp_server.h"
23 #include "bgp/bgp_session.h"
25 #include "bgp/bgp_peer_types.h"
26 #include "bgp/community.h"
28 #include "bgp/evpn/evpn_table.h"
29 #include "bgp/inet/inet_table.h"
30 #include "bgp/inet6/inet6_table.h"
33 #include "bgp/mvpn/mvpn_table.h"
34 #include "bgp/peer_close_manager.h"
42 using boost::assign::list_of;
43 using boost::assign::map_list_of;
44 using boost::system::error_code;
45 using boost::tie;
46 using std::copy;
47 using std::dec;
48 using std::map;
49 using std::numeric_limits;
50 using std::ostringstream;
51 using std::string;
52 using std::vector;
53 
55 public:
56  explicit PeerStats(BgpPeer *peer)
57  : peer_(peer) {
58  }
59 
60  // Used when peer flaps.
61  // Reset all counters.
62  // Socket counters are implicitly cleared because we use a new socket.
63  virtual void Clear() {
65  proto_stats_[0] = ProtoStats();
66  proto_stats_[1] = ProtoStats();
69  }
70 
71  // Printable name
72  virtual string ToString() const {
73  return peer_->ToString();
74  }
75  // Previous State of the peer
76  virtual string last_state() const {
77  return peer_->state_machine()->LastStateName();
78  }
79  virtual string last_state_change_at() const {
81  }
82  // Last error on this peer
83  virtual string last_error() const {
85  }
86  // Last Event on this peer
87  virtual string last_event() const {
88  return peer_->state_machine()->last_event();
89  }
90 
91  // When was the Last
92  virtual string last_flap() const {
93  return peer_->last_flap_at();
94  }
95 
96  // Total number of flaps
97  virtual uint64_t num_flaps() const {
98  return peer_->flap_count();
99  }
100 
101  virtual void GetRxProtoStats(ProtoStats *stats) const {
102  *stats = proto_stats_[0];
103  }
104 
105  virtual void GetTxProtoStats(ProtoStats *stats) const {
106  *stats = proto_stats_[1];
107  }
108 
109  virtual void GetRxRouteUpdateStats(UpdateStats *stats) const {
110  *stats = update_stats_[0];
111  }
112 
113  virtual void GetTxRouteUpdateStats(UpdateStats *stats) const {
114  *stats = update_stats_[1];
115  }
116 
117  virtual void GetRxSocketStats(IPeerDebugStats::SocketStats *stats) const {
118  if (peer_->session()) {
119  io::SocketStats socket_stats(peer_->session()->GetSocketStats());
120  stats->calls = socket_stats.read_calls;
121  stats->bytes = socket_stats.read_bytes;
122  }
123  }
124 
125  virtual void GetTxSocketStats(IPeerDebugStats::SocketStats *stats) const {
126  if (peer_->session()) {
127  io::SocketStats socket_stats(peer_->session()->GetSocketStats());
128  stats->calls = socket_stats.write_calls;
129  stats->bytes = socket_stats.write_bytes;
130  stats->blocked_count = socket_stats.write_blocked;
131  stats->blocked_duration_usecs =
132  socket_stats.write_blocked_duration_usecs;
133  }
134  }
135 
136  virtual void UpdateTxUnreachRoute(uint64_t count) {
137  update_stats_[1].unreach += count;
138  }
139 
140  virtual void UpdateTxReachRoute(uint64_t count) {
141  update_stats_[1].reach += count;
142  }
143 
144  // Do nothing for bgp peers.
145  virtual void GetRxErrorStats(RxErrorStats *stats) const {
146  }
147 
148  virtual void GetRxRouteStats(RxRouteStats *stats) const {
151  }
152 
153 private:
154  friend class BgpPeer;
155 
158  ProtoStats proto_stats_[2];
160 };
161 
163 public:
164  explicit DeleteActor(BgpPeer *peer)
165  : LifetimeActor(peer->server_->lifetime_manager()),
166  peer_(peer) {
167  }
168 
169  virtual bool MayDelete() const {
170  CHECK_CONCURRENCY("bgp::Config");
171  if (!peer_->close_manager_->IsQueueEmpty())
172  return false;
173  if (peer_->IsCloseInProgress())
174  return false;
175  if (!peer_->state_machine_->IsQueueEmpty())
176  return false;
178  return false;
179  return true;
180  }
181 
182  virtual void Shutdown() {
183  CHECK_CONCURRENCY("bgp::Config");
185  }
186 
187  virtual void Destroy() {
188  CHECK_CONCURRENCY("bgp::Config");
190  if (peer_->IsRouterTypeBGPaaS()) {
192  } else {
194  }
195  if (peer_->dscp_listener_id_ >= 0) {
198  peer_->dscp_listener_id_ = -1;
199  }
200  if (peer_->instance_op_ >= 0) {
202  UnregisterInstanceOpCallback(peer_->instance_op_);
203  peer_->instance_op_ = -1;
204  }
205  if (peer_->asn_listener_id_ >= 0) {
208  peer_->asn_listener_id_ = -1;
209  }
210  assert(!peer_->membership_req_pending());
211  assert(!peer_->close_manager_->IsMembershipInUse());
213  }
214 
215 private:
217 };
218 
219 //
220 // Constructor for BgpPeerFamilyAttributes.
221 //
223  const BgpNeighborConfig *config,
224  const BgpFamilyAttributesConfig &family_config) {
225  if (family_config.loop_count) {
226  loop_count = family_config.loop_count;
227  } else {
228  loop_count = config->loop_count();
229  }
230  prefix_limit = family_config.prefix_limit;
231  idle_timeout = family_config.idle_timeout;
233 
234  if (config->router_type() == "bgpaas-client") {
235  if (family_config.family == "inet") {
237  } else if (family_config.family == "inet6") {
239  }
240  }
241 }
242 
244  RibExportPolicy policy;
245  BgpPeerFamilyAttributes *family_attributes =
246  family_attributes_list_[family];
247  if (!family_attributes) {
249  as_override_, peer_close_->IsCloseLongLivedGraceful(),
251  } else {
253  as_override_, peer_close_->IsCloseLongLivedGraceful(),
254  as4_supported_, family_attributes->gateway_address,
255  -1, cluster_id_, family_attributes->default_tunnel_encap_list,
256  local_as_);
257  }
258 
259  if (private_as_action_ == "remove") {
260  policy.SetRemovePrivatePolicy(false, false, true);
261  } else if (private_as_action_ == "remove-all") {
262  policy.SetRemovePrivatePolicy(true, false, true);
263  } else if (private_as_action_ == "replace-all") {
264  policy.SetRemovePrivatePolicy(true, true, true);
265  }
266 
267  return policy;
268 }
269 
270 void BgpPeer::ReceiveEndOfRIB(Address::Family family, size_t msgsize) {
271  close_manager_->ProcessEORMarkerReceived(family);
272  eor_receive_timer_[family]->Cancel();
273 
274  // If EoR for RTarget is received, start registration for other families.
275  if (family == Address::RTARGET)
277 }
278 
280  tbb::spin_mutex::scoped_lock lock(spin_mutex_);
281 
282  // Bail if there's no session for the peer anymore.
283  if (!session_)
284  return;
285 
286  BgpProto::Update update;
287  uint16_t afi;
288  uint8_t safi;
289  tie(afi, safi) = BgpAf::FamilyToAfiSafi(family);
290  BgpMpNlri *nlri = new BgpMpNlri(BgpAttribute::MPUnreachNlri, afi, safi);
291  update.path_attributes.push_back(nlri);
292  uint8_t data[256];
293  int msgsize = BgpProto::Encode(&update, data, sizeof(data), NULL,
295  assert(msgsize > BgpProto::kMinMessageSize);
296  session_->Send(data, msgsize, NULL);
298  inc_tx_update();
299  BGP_LOG_PEER(Message, this, SandeshLevel::SYS_INFO,
301  "EndOfRib marker family " << Address::FamilyToString(family) <<
302  " size " << msgsize);
303 }
304 
306  BgpTable *table = GetRoutingInstance()->GetTable(family);
307  return server_->membership_mgr()->GetRibOutQueueDepth(this, table);
308 }
309 
312 }
313 
315  return family == Address::RTARGET ?
317 }
318 
320  return server_->IsServerStartingUp();
321 }
322 
324  return peer_close_->IsCloseGraceful();
325 }
326 
329 }
330 
332  if (!IsReady())
333  return false;
334 
335  // Send EoR if wait time has exceeded the configured maximum.
337  SendEndOfRIBActual(family);
338  return false;
339  }
340 
341  // Defer if output queue has not been fully drained yet.
342  uint32_t output_depth = GetOutputQueueDepth(family);
343  if (output_depth) {
345  BGP_LOG_PEER(Message, this, SandeshLevel::SYS_INFO,
347  "EndOfRib Send Timer rescheduled for family " <<
348  Address::FamilyToString(family) << " to fire after " <<
349  kEndOfRibSendRetryTime << " second(s) " <<
350  "due to non-empty output queue (" << output_depth << ")");
351  return true;
352  }
353 
354  // Send EoR if we are not still under [re-]starting phase.
355  if (!IsServerStartingUp()) {
356  SendEndOfRIBActual(family);
357  return false;
358  }
359 
360  // Defer if configuration processing is not complete yet.
363  BGP_LOG_PEER(Message, this, SandeshLevel::SYS_INFO,
365  "EndOfRib Send Timer rescheduled for family " <<
366  Address::FamilyToString(family) << " to fire after " <<
367  kEndOfRibSendRetryTime << " second(s) " <<
368  "as bgp (under restart) has not completed initial configuration"
369  " processing");
370  return true;
371  }
372 
373  // For all families except route-target, wait for a certain amount of time
374  // before sending eor as bgp is still in [re-]starting phase (60s).
375  if (family != Address::RTARGET) {
377  BGP_LOG_PEER(Message, this, SandeshLevel::SYS_INFO,
379  "EndOfRib Send Timer rescheduled for family " <<
380  Address::FamilyToString(family) << " to fire after " <<
381  kEndOfRibSendRetryTime << " second(s) " <<
382  "as bgp is still under [re-]starting phase");
383  return true;
384  }
385 
386  // Defer EoR if any new route-target was added to the table recently (6s).
388  0.02 * server_->GetEndOfRibSendTime()) {
390  BGP_LOG_PEER(Message, this, SandeshLevel::SYS_INFO,
392  "EndOfRib Send Timer rescheduled for family " <<
393  Address::FamilyToString(family) << " to fire after " <<
394  kEndOfRibSendRetryTime << " second(s) " <<
395  "as new route-targets are still being added to the table");
396  return true;
397  }
398 
399  // Send eor as [re-]starting phase is complete for this family.
400  SendEndOfRIBActual(family);
401  return false;
402 }
403 
406  BGP_LOG_PEER(Message, this, SandeshLevel::SYS_INFO,
408  "EndOfRib Send Timer scheduled for family " <<
409  Address::FamilyToString(family) <<
410  " to fire after " << kEndOfRibSendRetryTime << " second(s)");
412  boost::bind(&BgpPeer::EndOfRibSendTimerExpired, this, family),
413  boost::bind(&BgpPeer::EndOfRibTimerErrorHandler, this, _1, _2));
414 }
415 
416 void BgpPeer::BGPPeerInfoSend(const BgpPeerInfoData &peer_info) const {
417  assert(!peer_info.get_name().empty());
418  BGP_UVE_SEND(BGPPeerInfo, peer_info);
419 }
420 
422  return !membership_req_pending_;
423 }
424 
425 //
426 // Callback from BgpMembershipManager.
427 // Update pending membership request count and send EndOfRib for the family
428 // in question.
429 //
431  if (close_manager_->IsMembershipInUse()) {
432  close_manager_->MembershipRequestCallback();
433  return;
434  }
435 
436  assert(membership_req_pending_ > 0);
438 
439  // Resume if CloseManager is waiting to use membership manager.
441  close_manager_->IsMembershipInWait()) {
442  close_manager_->MembershipRequest();
443  }
444 
445  // Resume close if it was deferred and this is the last pending callback.
446  // Don't bother sending EndOfRib if close is deferred.
447  if (defer_close_) {
449  defer_close_ = false;
450  trigger_.Set();
451  }
452  return;
453  }
454 
455  SendEndOfRIB(table->family());
456 }
457 
459  BgpPath *path) {
460  return close_manager_->MembershipPathCallback(tpart, route, path);
461 }
462 
465  graceful_close_ = true;
466  return true;
467 }
468 
470  const BgpNeighborConfig *config)
471  : server_(server),
472  rtinstance_(instance),
473  peer_key_(config),
474  peer_port_(config->source_port()),
475  peer_name_(config->name()),
476  router_type_(config->router_type()),
477  config_(config),
478  index_(server->RegisterPeer(this)),
479  trigger_(boost::bind(&BgpPeer::ResumeClose, this),
480  TaskScheduler::GetInstance()->GetTaskId("bgp::StateMachine"),
481  GetTaskInstance()),
482  prefix_limit_idle_timer_(
483  TimerManager::CreateTimer(*server->ioservice(),
484  "BGP prefix limit idle timer",
485  TaskScheduler::GetInstance()->GetTaskId("bgp::StateMachine"),
486  GetTaskInstance())),
487  prefix_limit_trigger_(boost::bind(&BgpPeer::CheckPrefixLimits, this),
488  TaskScheduler::GetInstance()->GetTaskId("bgp::StateMachine"),
489  GetTaskInstance()),
490  buffer_capacity_(GetBufferCapacity()),
491  session_(NULL),
492  keepalive_timer_(TimerManager::CreateTimer(*server->ioservice(),
493  "BGP keepalive timer",
494  TaskScheduler::GetInstance()->GetTaskId("bgp::StateMachine"),
495  GetTaskInstance())),
496  eor_send_timer_start_time_(0),
497  send_ready_(true),
498  admin_down_(config->admin_down()),
499  passive_(config->passive()),
500  resolve_paths_(config->router_type() == "bgpaas-client"),
501  as_override_(config->as_override()),
502  cluster_id_(config->cluster_id()),
503  origin_override_(config->origin_override()),
504  defer_close_(false),
505  graceful_close_(true),
506  as4_supported_(false),
507  vpn_tables_registered_(false),
508  hold_time_(config->hold_time()),
509  local_as_(config->local_as()),
510  peer_as_(config->peer_as()),
511  local_bgp_id_(config->local_identifier()),
512  peer_bgp_id_(0),
513  family_primary_path_count_(Address::NUM_FAMILIES),
514  peer_type_((config->peer_as() == config->local_as()) ?
515  BgpProto::IBGP : BgpProto::EBGP),
516  state_machine_(BgpStaticObjectFactory::Create<StateMachine>(this)),
517  peer_close_(BgpStaticObjectFactory::Create<BgpPeerClose>(this)),
518  peer_stats_(new PeerStats(this)),
519  deleter_(new DeleteActor(this)),
520  instance_delete_ref_(this, instance ? instance->deleter() : NULL),
521  flap_count_(0),
522  total_flap_count_(0),
523  last_flap_(0),
524  dscp_listener_id_(-1),
525  inuse_authkey_type_(AuthenticationData::NIL),
526  asn_listener_id_(-1),
527  instance_op_(-1) {
528  buffer_.reserve(buffer_capacity_);
529  close_manager_.reset(
530  BgpStaticObjectFactory::Create<PeerCloseManager>(static_cast<IPeerClose*>(peer_close_.get())));
531  ostringstream oss1;
532  oss1 << peer_key_.endpoint.address();
534  oss1 << ":" << dec << peer_key_.endpoint.port();
535  to_str_ = oss1.str();
536 
537  ostringstream oss2;
538  if (rtinstance_)
539  oss2 << rtinstance_->name() << ":";
540  oss2 << server_->localname() << ":";
541  oss2 << peer_name();
542  uve_key_str_ = oss2.str();
543 
544  if (router_type_ == "control-node" ||
545  router_type_ == "external-control-node") {
546  peer_is_control_node_ = true;
547  } else {
548  peer_is_control_node_ = false;
549  }
550 
552  &BgpPeer::DSCPUpdateCallback, this, _1));
553  if (IsRouterTypeBGPaaS()) {
554  asn_listener_id_ = server->RegisterASNUpdateCallback(boost::bind(
555  &BgpPeer::ASNUpdateCallback, this, _1, _2));
557  boost::bind(&BgpPeer::RoutingInstanceCallback, this, _1, _2));
558  }
559 
561  BGP_LOG_PEER(Event, this, SandeshLevel::SYS_INFO, BGP_LOG_FLAG_ALL,
562  BGP_PEER_DIR_NA, "Created");
563 
564  if (rtinstance_ && peer_name_.find(rtinstance_->name()) == 0) {
565  peer_basename_ = peer_name_.substr(rtinstance_->name().size() + 1);
566  } else {
568  }
569 
570  for (Address::Family family = Address::UNSPEC;
571  family < Address::NUM_FAMILIES;
572  family = static_cast<Address::Family>(family + 1)) {
573  family_primary_path_count_[family] = 0;
574  eor_send_timer_[family] =
576  "BGP EoR Send timer for " + Address::FamilyToString(family),
577  TaskScheduler::GetInstance()->GetTaskId("bgp::StateMachine"),
578  GetTaskInstance());
579  eor_receive_timer_[family] =
581  "BGP EoR Receive timer for " + Address::FamilyToString(family),
582  TaskScheduler::GetInstance()->GetTaskId("bgp::StateMachine"),
583  GetTaskInstance());
584  }
585 
586  total_path_count_ = 0;
588 
589  // Check rtinstance_ to accommodate unit tests.
590  if (resolve_paths_ && rtinstance_) {
593  }
594 
595  ProcessEndpointConfig(config);
598 
599  BgpPeerInfoData peer_info;
600  peer_info.set_name(ToUVEKey());
601  peer_info.set_admin_down(admin_down_);
602  peer_info.set_passive(passive_);
603  peer_info.set_as_override(as_override_);
604  peer_info.set_origin_override(origin_override_.origin_override);
606  peer_info.set_route_origin(
608  } else {
609  peer_info.set_route_origin("-");
610  }
611  peer_info.set_router_type(router_type_);
612  peer_info.set_cluster_id(Ip4Address(cluster_id_).to_string());
613  peer_info.set_peer_type(
614  PeerType() == BgpProto::IBGP ? "internal" : "external");
615  peer_info.set_local_asn(local_as_);
616  peer_info.set_peer_asn(peer_as_);
617  peer_info.set_peer_port(peer_port_);
618  peer_info.set_hold_time(hold_time_);
619  peer_info.set_local_id(local_bgp_id_);
620  peer_info.set_configured_families(configured_families_);
621  peer_info.set_peer_address(peer_key_.endpoint.address().to_string());
622  BGPPeerInfoSend(peer_info);
623 }
624 
626  assert(!close_manager()->IsCloseInProgress());
627  assert(!IsCloseInProgress());
628  assert(GetTotalPathCount() == 0);
631  BgpPeerInfoData peer_info;
632  peer_info.set_name(ToUVEKey());
633  peer_info.set_deleted(true);
634  BGPPeerInfoSend(peer_info);
635 
636  PeerStatsData peer_stats_data;
637  peer_stats_data.set_name(ToUVEKey());
638  peer_stats_data.set_deleted(true);
639  assert(!peer_stats_data.get_name().empty());
640  BGP_UVE_SEND2(PeerStatsUve, peer_stats_data, "ObjectBgpPeer");
641 
642  PeerFlapData peer_flap_data;
643  peer_flap_data.set_name(ToUVEKey());
644  peer_flap_data.set_deleted(true);
645  assert(!peer_flap_data.get_name().empty());
646  BGP_UVE_SEND2(PeerFlap, peer_flap_data, "ObjectBgpPeer");
647 
648  BGP_LOG_PEER(Event, this, SandeshLevel::SYS_INFO, BGP_LOG_FLAG_ALL,
649  BGP_PEER_DIR_NA, "Deleted");
650 }
651 
653  if (!admin_down_)
654  state_machine_->Initialize();
655 }
656 
658  // For testing only - configure through environment variable.
659  char *buffer_capacity_str = getenv("BGP_PEER_BUFFER_SIZE");
660  if (buffer_capacity_str) {
661  size_t env_buffer_capacity = strtoul(buffer_capacity_str, NULL, 0);
662  if (env_buffer_capacity < kMinBufferCapacity)
663  env_buffer_capacity = kMinBufferCapacity;
664  if (env_buffer_capacity > kMaxBufferCapacity)
665  env_buffer_capacity = kMaxBufferCapacity;
666  return env_buffer_capacity;
667  }
668 
669  // Return internal default based on peer router-type.
670  if (IsRouterTypeBGPaaS()) {
671  return kMinBufferCapacity;
672  } else {
673  return kMaxBufferCapacity;
674  }
675 }
676 
677 bool BgpPeer::CheckSplitHorizon(uint32_t server_cluster_id,
678  uint32_t ribout_cid) const {
679  if (PeerType() == BgpProto::IBGP) {
680  // check if router is a route reflector
681  if (!server_cluster_id) return true;
682  // check if received from client or non-client by comparing the clusterId
683  // of router with that of peer from which we this route is received
684  if (server_cluster_id != cluster_id_) {
685  // If received from non-client, reflect to all the clients only
686  if (ribout_cid && ribout_cid != server_cluster_id) {
687  return true;
688  }
689  }
690  }
691  return false;
692 }
693 
696  if (!instance_mgr)
697  return NULL;
698  RoutingInstance *master = instance_mgr->GetDefaultRoutingInstance();
699  if (!master)
700  return NULL;
701  return master->GetTable(Address::RTARGET);
702 }
703 
705  BgpAttrSpec attrs;
707  attrs.push_back(&nexthop);
709  attrs.push_back(&origin);
710  return server_->attr_db()->Locate(attrs);
711 }
712 
713 // Add one route-target route to bgp.rtarget.0 table.
715  RouteTargetList::const_iterator it) {
716  const RouteTarget rtarget = *it;
717  DBRequest req;
718  RTargetPrefix rt_prefix(as, rtarget);
719  req.key.reset(new RTargetTable::RequestKey(rt_prefix, this));
720  req.data.reset(new RTargetTable::RequestData(attr, 0, 0, 0, 0));
722  table->Enqueue(&req);
723 }
724 
725 // Add import route-targets of associated routing-instance in order to attract
726 // the VN routes, if bgpaas session comes up within the instance.
728  if (!IsRouterTypeBGPaaS())
729  return;
730  assert(IsReady());
731  BgpTable *table = GetRTargetTable();
732  assert(table);
735  for (RouteTargetList::const_iterator it = rtargets_.begin();
736  it != rtargets_.end(); it++) {
737  BGPaaSAddRTarget(as, table, attr, it);
738  }
739 }
740 
741 // Delete one route-target route from bgp.rtarget.0 table.
743  RouteTargetList::const_iterator it) {
744  const RouteTarget rtarget = *it;
745  DBRequest req;
746  RTargetPrefix rt_prefix(as, rtarget);
747  req.key.reset(new RTargetTable::RequestKey(rt_prefix, this));
749  table->Enqueue(&req);
750 }
751 
752 // Delete import route-targets of associated routing-instance in order to
753 // not to attract the VN routes any more, if bgpaas session goes down within
754 // the instance.
756  if (!IsRouterTypeBGPaaS())
757  return;
758  BgpTable *table = GetRTargetTable();
759  if (!table)
760  return;
761  for (RouteTargetList::const_iterator it = rtargets_.begin();
762  it != rtargets_.end(); it++) {
763  BGPaaSDeleteRTarget(as, table, it);
764  }
765  rtargets_.clear();
766 }
767 
768 void BgpPeer::ASNUpdateCallback(as_t old_asn, as_t old_local_asn) {
769  CHECK_CONCURRENCY("bgp::Config");
770  DeleteRTargets(old_local_asn);
771  if (!IsReady())
772  return;
774 }
775 
776 // Process changes to routing-instance configuration. Specifically, we need
777 // to track all import route-targets so that they can be correctly updated
778 // when bgpaas sessions come up or go down.
779 void BgpPeer::RoutingInstanceCallback(const std::string &vrf_name, int op) {
780  assert(IsRouterTypeBGPaaS());
782  return;
783  if (vrf_name != rtinstance_->name())
784  return;
786  RoutingInstance *master = instance_mgr->GetDefaultRoutingInstance();
787  BgpTable *table = master->GetTable(Address::RTARGET);
788  assert(table);
791  boost::bind(&BgpPeer::BGPaaSAddRTarget, this,
792  server_->local_autonomous_system(), table, attr, _1),
793  boost::bind(&BgpPeer::BGPaaSDeleteRTarget, this,
794  server_->local_autonomous_system(), table, _1));
796 }
797 
798 void BgpPeer::NotifyEstablished(bool established) {
799  if (established) {
800  if (IsRouterTypeBGPaaS()) {
803  } else {
805  }
806  } else {
807  if (IsRouterTypeBGPaaS()) {
809  } else {
811  }
812  }
813 }
814 
816 }
817 
818 // Just return the first entry for now.
820  KeyType *key_type) const {
821  if (auth_data_.Empty()) {
822  return false;
823  }
824  assert(auth_key);
826  *auth_key = *iter;
827  *key_type = auth_data_.key_type();
828  return true;
829 }
830 
832  const AuthenticationData &input_auth_data = config->auth_data();
833 
834  if (auth_data_ == input_auth_data) {
835  return false;
836  }
837 
838  auth_data_ = input_auth_data;
839  return InstallAuthKeys();
840 }
841 
843  if (!PeerAddress()) {
844  return false;
845  }
846 
847  AuthenticationKey auth_key;
848  KeyType key_type;
849  bool valid = GetBestAuthKey(&auth_key, &key_type);
850  if (valid) {
851  if (key_type == AuthenticationData::MD5) {
852  LogInstallAuthKeys("Listen", "add", auth_key, key_type);
853  SetListenSocketAuthKey(auth_key, key_type);
854  SetInuseAuthKeyInfo(auth_key, key_type);
855  }
856  } else {
857  // If there are no valid available keys but an older one is currently
858  // installed, un-install it.
860  LogInstallAuthKeys("Listen", "delete", inuse_auth_key_,
863  // Resetting the key information must be done last.
865  }
866  }
867  return true;
868 }
869 
871  inuse_auth_key_ = key;
873 }
874 
878 }
879 
881  KeyType key_type) {
882  if (key_type == AuthenticationData::MD5) {
884  SetListenSocketMd5Option(PeerAddress(), auth_key.value);
885  }
886 }
887 
891  }
892 }
893 
896  assert(!inuse_auth_key_.value.empty());
897  LogInstallAuthKeys("Session", "add", inuse_auth_key_,
900  }
901 }
902 
904  uint8_t dscp_value = server_->global_qos()->control_dscp();
905 
906  if (!session->socket()) {
907  return;
908  }
909  if (dscp_value != 0xFF) {
911  }
912 }
913 
915  return inuse_auth_key_.value;
916 }
917 
918 void BgpPeer::LogInstallAuthKeys(const string &socket_name,
919  const string &oper, const AuthenticationKey &auth_key,
920  KeyType key_type) {
921  string logstr = socket_name + " socket kernel " + oper + " of key id "
922  + integerToString(auth_key.id) + ", type "
924  + ", peer " + peer_name_;
925  BGP_LOG_PEER(Config, this, SandeshLevel::SYS_INFO, BGP_LOG_FLAG_ALL,
926  BGP_PEER_DIR_NA, logstr);
927 }
928 
929 //
930 // Check if the configured prefix limit for any address family has been
931 // exceeded. If yes, clear the peer by sending a notification with a cease
932 // subcode of MaxPrefixes.
933 //
935  RetryDelete();
936  if (!IsReady())
937  return true;
938  for (size_t idx = Address::UNSPEC; idx < Address::NUM_FAMILIES; ++idx) {
939  BgpPeerFamilyAttributes *family_attributes =
941  if (!family_attributes || family_attributes->prefix_limit == 0)
942  continue;
943  if (family_primary_path_count_[idx] <= family_attributes->prefix_limit)
944  continue;
946  StartPrefixLimitIdleTimer(family_attributes->idle_timeout * 1000);
947  break;
948  }
949  return true;
950 }
951 
952 //
953 // Process family attributes configuration and update the family attributes
954 // list.
955 //
956 // Return true is there's a change, false otherwise.
957 //
959  FamilyAttributesList family_attributes_list(Address::NUM_FAMILIES);
960  BOOST_FOREACH(const BgpFamilyAttributesConfig family_config,
961  config->family_attributes_list()) {
962  Address::Family family =
963  Address::FamilyFromString(family_config.family);
964  assert(family != Address::UNSPEC);
965  BgpPeerFamilyAttributes *family_attributes =
966  new BgpPeerFamilyAttributes(config, family_config);
967  family_attributes_list[family] = family_attributes;
968  }
969 
970  int ret = STLSortedCompare(
971  family_attributes_list.begin(), family_attributes_list.end(),
975  family_attributes_list_ = family_attributes_list;
977  return (ret != 0);
978 }
979 
981  if (config->router_type() == "bgpaas-client") {
983  } else {
985  }
986 }
987 
990 }
991 
993  if (IsDeleted())
994  return;
995 
996  config_ = config;
997 
998  // During peer deletion, configuration gets completely deleted. In that
999  // case, there is no need to update the rest and flap the peer.
1000  if (!config_)
1001  return;
1002 
1003  bool clear_session = false;
1004  bool admin_down_changed = false;
1005  BgpPeerInfoData peer_info;
1006  peer_info.set_name(ToUVEKey());
1007 
1008  if (admin_down_ != config->admin_down()) {
1009  SetAdminState(config->admin_down());
1010  peer_info.set_admin_down(admin_down_);
1011  admin_down_changed = true;
1012  }
1013 
1014  if (passive_ != config->passive()) {
1015  passive_ = config->passive();
1016  peer_info.set_passive(passive_);
1017  clear_session = true;
1018  }
1019 
1020  if (as_override_ != config->as_override()) {
1021  as_override_ = config->as_override();
1022  peer_info.set_as_override(as_override_);
1023  clear_session = true;
1024  }
1025 
1026  if (cluster_id_ != config->cluster_id()) {
1027  cluster_id_ = config->cluster_id();
1028  peer_info.set_cluster_id(Ip4Address(cluster_id_).to_string());
1029  clear_session = true;
1030  }
1031 
1032  OriginOverride origin_override(config->origin_override());
1033  if (origin_override_ != origin_override) {
1034  origin_override_ = origin_override;
1035  peer_info.set_origin_override(origin_override_.origin_override);
1037  peer_info.set_route_origin(config->origin_override().origin);
1038  } else {
1039  peer_info.set_route_origin("-");
1040  }
1041  clear_session = true;
1042  }
1043 
1044  if (router_type_ != config->router_type()) {
1045  router_type_ = config->router_type();
1046  peer_info.set_router_type(router_type_);
1047  resolve_paths_ = (config->router_type() == "bgpaas-client");
1048  clear_session = true;
1049  }
1050  if (router_type_ == "control-node" ||
1051  router_type_ == "external-control-node") {
1052  peer_is_control_node_ = true;
1053  } else {
1054  peer_is_control_node_ = false;
1055  }
1056 
1057  // Check if there is any change in the peer address.
1058  // If the peer address is changing, remove the key for the older address.
1059  // Update with the new peer address and then process the key chain info
1060  // for the new peer below.
1061  BgpPeerKey key(config);
1062  if (peer_key_ != key) {
1064  peer_key_ = key;
1065  peer_info.set_peer_address(peer_key_.endpoint.address().to_string());
1066  clear_session = true;
1067  }
1068  if (ProcessAuthKeyChainConfig(config)) {
1069  clear_session = true;
1070  }
1071 
1072  if (peer_port_ != config->source_port()) {
1073  peer_port_ = config->source_port();
1074  peer_info.set_peer_port(peer_port_);
1075  clear_session = true;
1076  }
1077  ProcessEndpointConfig(config);
1078 
1079  if (local_as_ != config->local_as()) {
1080  BGP_LOG_STR(BgpConfig, SandeshLevel::SYS_DEBUG,
1082  "Updated Local Autonomous System from " <<
1083  local_as_ << " to " <<
1084  config->local_as());
1085 
1086  local_as_ = config->local_as();
1087  peer_info.set_local_asn(local_as_);
1088  clear_session = true;
1089  }
1090 
1091  if (hold_time_ != config->hold_time()) {
1092  BGP_LOG_STR(BgpConfig, SandeshLevel::SYS_DEBUG,
1094  "Updated Hold Time from " <<
1095  hold_time_ << " to " <<
1096  config->hold_time());
1097 
1098  hold_time_ = config->hold_time();
1099  peer_info.set_hold_time(hold_time_);
1100  clear_session = true;
1101  }
1102 
1103  if (peer_as_ != config->peer_as()) {
1104  BGP_LOG_STR(BgpConfig, SandeshLevel::SYS_DEBUG,
1106  "Updated Peer Autonomous System from " <<
1107  peer_as_ << " to " <<
1108  config->peer_as());
1109 
1110  peer_as_ = config->peer_as();
1111  peer_info.set_peer_asn(peer_as_);
1112  clear_session = true;
1113  }
1114 
1115  boost::system::error_code ec;
1116  uint32_t local_bgp_id = config->local_identifier();
1117  if (local_bgp_id_ != local_bgp_id) {
1118  local_bgp_id_ = local_bgp_id;
1119  peer_info.set_local_id(local_bgp_id_);
1120  clear_session = true;
1121  }
1122 
1123  BgpProto::BgpPeerType old_type = PeerType();
1125  if (old_type != PeerType()) {
1126  peer_info.set_peer_type(
1127  PeerType() == BgpProto::IBGP ? "internal" : "external");
1128  clear_session = true;
1129  }
1130 
1131  // Check if there is any change in private-as-action configuration.
1132  if (private_as_action_ != config->private_as_action()) {
1134  clear_session = true;
1135  }
1136 
1137  // Check if there is any change in the configured address families.
1138  if (ProcessFamilyAttributesConfig(config)) {
1139  peer_info.set_configured_families(configured_families_);
1140  clear_session = true;
1141  } else {
1143  }
1144 
1145  // Note that the state machine would have been stopped via SetAdminDown
1146  // if admin down was set to true above. Further, it's not necessary to
1147  // clear the peer if it's already admin down.
1148  if (!admin_down_changed && !admin_down_ && clear_session) {
1149  BGP_LOG_PEER(Config, this, SandeshLevel::SYS_INFO, BGP_LOG_FLAG_ALL,
1151  "Session cleared due to configuration change");
1153  }
1154 
1155  // Send the UVE as appropriate.
1156  if (admin_down_changed || clear_session) {
1158  BGPPeerInfoSend(peer_info);
1159  }
1160 }
1161 
1163  CHECK_CONCURRENCY("bgp::Config");
1164  config_ = NULL;
1165 }
1166 
1168  return deleter_.get();
1169 }
1170 
1171 //
1172 // Check if the given address family has been negotiated with the peer.
1173 //
1175  // Bail if the family is not configured locally.
1176  if (!LookupFamily(family))
1177  return false;
1178 
1179  // Check if the peer advertised it in his Open message.
1180  uint16_t afi;
1181  uint8_t safi;
1182  tie(afi, safi) = BgpAf::FamilyToAfiSafi(family);
1183  return MpNlriAllowed(afi, safi);
1184 }
1185 
1186 // Release resources for a peer that is going to be deleted.
1188  if (index_ != -1) {
1189  server_->UnregisterPeer(this);
1190  index_ = -1;
1191  }
1194 
1195  for (Address::Family family = Address::UNSPEC;
1196  family < Address::NUM_FAMILIES;
1197  family = static_cast<Address::Family>(family + 1)) {
1200  }
1201 }
1202 
1203 // IsReady
1204 //
1205 // Check whether this peer is up and ready
1206 //
1207 bool BgpPeer::IsReady() const {
1208  return state_machine_->get_state() == StateMachine::ESTABLISHED;
1209 }
1210 
1211 bool BgpPeer::IsXmppPeer() const {
1212  return false;
1213 }
1214 
1216  return ntohl(local_bgp_id_);
1217 }
1218 
1220  return Ip4Address(ntohl(local_bgp_id_)).to_string();
1221 }
1222 
1223 uint32_t BgpPeer::bgp_identifier() const {
1224  return ntohl(peer_bgp_id_);
1225 }
1226 
1228  return Ip4Address(ntohl(peer_bgp_id_)).to_string();
1229 }
1230 
1233  ostringstream oss;
1234  if (session_)
1235  endpoint = session_->remote_endpoint();
1236  oss << endpoint;
1237  return oss.str();
1238 }
1239 
1241  if (!family_attributes_list_[family])
1242  return string();
1243  return family_attributes_list_[family]->gateway_address.to_string();
1244 }
1245 
1246 //
1247 // Customized close routing for BgpPeers.
1248 //
1249 // Reset all stored capabilities information and cancel outstanding timers.
1250 //
1254 
1255  for (Address::Family family = Address::UNSPEC;
1256  family < Address::NUM_FAMILIES;
1257  family = static_cast<Address::Family>(family + 1)) {
1258  eor_send_timer_[family]->Cancel();
1259  eor_receive_timer_[family]->Cancel();
1260  }
1261 
1262  if (close_manager_->IsInDeleteState())
1264 }
1265 
1266 //
1267 // Close this peer by closing all of it's RIBs.
1268 //
1269 void BgpPeer::Close(bool graceful) {
1270  send_ready_ = true;
1271  if (membership_req_pending_ && !close_manager_->IsMembershipInUse()) {
1272  BGP_LOG_PEER(Event, this, SandeshLevel::SYS_INFO, BGP_LOG_FLAG_ALL,
1273  BGP_PEER_DIR_NA, "Close procedure deferred");
1274  defer_close_ = true;
1275 
1276  // Note down non-graceful closures. Once a close is non-graceful,
1277  // it shall remain as non-graceful.
1278  graceful_close_ &= graceful;
1279  return;
1280  }
1281 
1282  peer_close_->Close(graceful);
1283 }
1284 
1286  return peer_close_.get();
1287 }
1288 
1290  return peer_close_.get();
1291 }
1292 
1294  const BgpPath *old_path, uint32_t path_flags) const {
1295  peer_close()->UpdateRouteStats(family, old_path, path_flags);
1296 }
1297 
1299  return peer_stats_.get();
1300 }
1301 
1303  return peer_stats_.get();
1304 }
1305 
1306 void BgpPeer::Clear(int subcode) {
1307  CHECK_CONCURRENCY("bgp::Config", "bgp::StateMachine");
1308  state_machine_->Shutdown(subcode);
1309 }
1310 
1311 //
1312 // Check whether this peer has been marked for deletion from configuration
1313 //
1314 bool BgpPeer::IsDeleted() const {
1315  return deleter_->IsDeleted();
1316 }
1317 
1319  return close_manager_->IsInGRTimerWaitState();
1320 }
1321 
1323  CHECK_CONCURRENCY("bgp::Config", "bgp::StateMachine");
1324 
1325  // trigger is set only after defer_close is reset
1326  assert(!(defer_close_ && trigger_.IsSet()));
1327  return defer_close_ || trigger_.IsSet() ||
1328  (close_manager_->IsCloseInProgress() &&
1330 }
1331 
1333  return state_machine_->get_state();
1334 }
1335 
1336 const string BgpPeer::GetStateName() const {
1337  return state_machine_->StateName();
1338 }
1339 
1342  return NULL;
1343 
1345  if (session == NULL)
1346  return NULL;
1347 
1348  // Set valid keys, if any, in the socket.
1349  SetSessionSocketAuthKey(session);
1350 
1351  BgpSession *bgp_session = static_cast<BgpSession *>(session);
1352  BindLocalEndpoint(bgp_session);
1353  bgp_session->set_peer(this);
1354  return bgp_session;
1355 }
1356 
1357 void BgpPeer::SetAdminState(bool down, int subcode) {
1358  CHECK_CONCURRENCY("bgp::Config");
1359  if (admin_down_ == down)
1360  return;
1361  admin_down_ = down;
1362  state_machine_->SetAdminState(down, subcode);
1363  if (admin_down_) {
1364  BGP_LOG_PEER(Config, this, SandeshLevel::SYS_INFO, BGP_LOG_FLAG_ALL,
1365  BGP_PEER_DIR_NA, "Session cleared due to admin down");
1366  }
1367 }
1368 
1370  session->set_peer(this);
1371 
1372  // Set valid keys, if any, in the socket.
1373  SetSessionSocketAuthKey(session);
1374 
1375  // Set control dscp, if any
1376  SetSessionSocketOptionDscp(session);
1377 
1378  return state_machine_->PassiveOpen(session);
1379 }
1380 
1381 void BgpPeer::Register(BgpTable *table, const RibExportPolicy &policy) {
1382  // In a highly corner case scenario, GR timer could fire right after a
1383  // session comes back up. In that case, CloseManager possibly could still
1384  // be using membership manager. Instead of creating a queue of these
1385  // register requests until close manager is done processing and process
1386  // them later, we could just as well just reset the session.
1387  if (close_manager_->IsMembershipInUse()) {
1388  BGP_LOG_PEER(Config, this, SandeshLevel::SYS_NOTICE, BGP_LOG_FLAG_ALL,
1389  BGP_PEER_DIR_IN, "Session cleared due to GR not ready");
1390  Close(true);
1391  }
1392 
1393  if (close_manager_->IsMembershipInWait())
1394  assert(membership_req_pending_ > 0);
1395  BgpMembershipManager *membership_mgr = server_->membership_mgr();
1397  membership_mgr->Register(this, table, policy);
1398 
1399  // Start EndOfRib receive timer.
1401 }
1402 
1404  if (close_manager_->IsMembershipInUse()) {
1405  BGP_LOG_PEER(Config, this, SandeshLevel::SYS_NOTICE, BGP_LOG_FLAG_ALL,
1406  BGP_PEER_DIR_IN, "Session cleared due to GR not ready");
1407  Close(true);
1408  }
1409 
1410  if (close_manager_->IsMembershipInWait())
1411  assert(membership_req_pending_ > 0);
1412  BgpMembershipManager *membership_mgr = server_->membership_mgr();
1413  membership_mgr->RegisterRibIn(this, table);
1414 
1415  // Start EndOfRib receive timer.
1417 }
1418 
1419 //
1420 // Register to tables for negotiated address families.
1421 //
1422 // If the route-target family is negotiated, defer ribout registration
1423 // to VPN tables till we receive End-Of-RIB marker for the route-target
1424 // NLRI or till the EndOfRibTimer expires. This ensures that we do not
1425 // start sending VPN routes to the peer till we know what route targets
1426 // the peer is interested in.
1427 //
1428 // Note that we do ribin registration right away even if the route-target
1429 // family is negotiated. This allows received VPN routes to be processed
1430 // normally before ribout registration to VPN tables is completed.
1431 //
1433  RoutingInstance *instance = GetRoutingInstance();
1434 
1435  BGP_LOG_PEER(Event, this, SandeshLevel::SYS_INFO, BGP_LOG_FLAG_ALL,
1436  BGP_PEER_DIR_NA, "Established");
1437 
1438  vector<Address::Family> family_list = list_of
1440  BOOST_FOREACH(Address::Family family, family_list) {
1441  if (!IsFamilyNegotiated(family))
1442  continue;
1443  BgpTable *table = instance->GetTable(family);
1444  BGP_LOG_PEER_TABLE(this, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_TRACE,
1445  table, "Register peer with the table");
1446  Register(table, BuildRibExportPolicy(family));
1447  }
1448 
1449  vpn_tables_registered_ = false;
1452  return;
1453  }
1454 
1456  BgpTable *table = instance->GetTable(family);
1457  BGP_LOG_PEER_TABLE(this, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_TRACE,
1458  table, "Register peer with the table");
1459  Register(table, BuildRibExportPolicy(family));
1460 
1461  vector<Address::Family> vpn_family_list = list_of
1463  (Address::MVPN);
1464  BOOST_FOREACH(Address::Family vpn_family, vpn_family_list) {
1465  if (!IsFamilyNegotiated(vpn_family))
1466  continue;
1467  BgpTable *table = instance->GetTable(vpn_family);
1468  BGP_LOG_PEER_TABLE(this, SandeshLevel::SYS_INFO, BGP_LOG_FLAG_TRACE,
1469  table, "Register ribin for peer with the table");
1470  Register(table);
1471  }
1472 }
1473 
1474 const vector<Address::Family> BgpPeer::supported_families_ = list_of
1475  (Address::INET)
1478  (Address::EVPN)
1480  (Address::ERMVPN)
1481  (Address::MVPN)
1482  (Address::INET6)
1484 
1486  BgpProto::OpenMessage openmsg;
1487  openmsg.as_num = local_as_ > 0xffff ? AS_TRANS : local_as_;
1488  openmsg.holdtime = state_machine_->GetConfiguredHoldTime();
1489  openmsg.identifier = ntohl(local_bgp_id_);
1490  BgpProto::OpenMessage::OptParam *opt_param =
1492 
1493  static const uint8_t cap_mp[][4] = {
1494  { 0, (uint8_t) BgpAf::FamilyToAfi(supported_families_[0]), 0,
1496  { 0, (uint8_t) BgpAf::FamilyToAfi(supported_families_[1]), 0,
1498  { 0, (uint8_t) BgpAf::FamilyToAfi(supported_families_[2]), 0,
1500  { 0, (uint8_t) BgpAf::FamilyToAfi(supported_families_[3]), 0,
1502  { 0, (uint8_t) BgpAf::FamilyToAfi(supported_families_[4]), 0,
1504  { 0, (uint8_t) BgpAf::FamilyToAfi(supported_families_[5]), 0,
1506  { 0, (uint8_t) BgpAf::FamilyToAfi(supported_families_[6]), 0,
1508  { 0, (uint8_t) BgpAf::FamilyToAfi(supported_families_[7]), 0,
1510  { 0, (uint8_t) BgpAf::FamilyToAfi(supported_families_[8]), 0,
1512  };
1513 
1514  static const FamilyToCapabilityMap family_to_cap_map = map_list_of
1515  (supported_families_[0], cap_mp[0])
1516  (supported_families_[1], cap_mp[1])
1517  (supported_families_[2], cap_mp[2])
1518  (supported_families_[3], cap_mp[3])
1519  (supported_families_[4], cap_mp[4])
1520  (supported_families_[5], cap_mp[5])
1521  (supported_families_[6], cap_mp[6])
1522  (supported_families_[7], cap_mp[7])
1523  (supported_families_[8], cap_mp[8]);
1524 
1525  // Add capabilities for configured address families.
1526  BOOST_FOREACH(const FamilyToCapabilityMap::value_type &val,
1527  family_to_cap_map) {
1528  if (!LookupFamily(val.first))
1529  continue;
1533  opt_param->capabilities.push_back(cap);
1534  }
1535 
1536  if (server_->enable_4byte_as()) {
1537  uint32_t asn = ntohl(local_as_);
1541  (const uint8_t *)(&asn), 4);
1542  opt_param->capabilities.push_back(cap);
1543  }
1544  peer_close_->AddGRCapabilities(opt_param);
1545  peer_close_->AddLLGRCapabilities(opt_param);
1546 
1547  if (opt_param->capabilities.size()) {
1548  openmsg.opt_params.push_back(opt_param);
1549  } else {
1550  delete opt_param;
1551  }
1552  uint8_t data[256];
1553  int result = BgpProto::Encode(&openmsg, data, sizeof(data));
1554  assert(result > BgpProto::kMinMessageSize);
1555  BGP_LOG_PEER(Message, this, SandeshLevel::SYS_INFO, BGP_LOG_FLAG_ALL,
1556  BGP_PEER_DIR_OUT, "Open " << openmsg.ToString());
1557  session->Send(data, result, NULL);
1558  inc_tx_open();
1559 }
1560 
1561 void BgpPeer::SendKeepalive(bool from_timer) {
1562  tbb::spin_mutex::scoped_lock lock(spin_mutex_);
1563 
1564  // Bail if there's no session for the peer anymore.
1565  if (!session_)
1566  return;
1567 
1568  BgpProto::Keepalive msg;
1569  uint8_t data[BgpProto::kMinMessageSize];
1570  int result = BgpProto::Encode(&msg, data, sizeof(data));
1571  assert(result == BgpProto::kMinMessageSize);
1572  SandeshLevel::type log_level = from_timer ? Sandesh::LoggingUtLevel() :
1573  SandeshLevel::SYS_INFO;
1574  BGP_LOG_PEER(Message, this, log_level, BGP_LOG_FLAG_SYSLOG,
1575  BGP_PEER_DIR_OUT, "Keepalive");
1576  send_ready_ = session_->Send(data, result, NULL);
1577  inc_tx_keepalive();
1578 }
1579 
1580 static bool SkipUpdateSend() {
1581  static bool init_;
1582  static bool skip_;
1583 
1584  if (init_) return skip_;
1585 
1586  skip_ = getenv("BGP_SKIP_UPDATE_SEND") != NULL;
1587  init_ = true;
1588 
1589  return skip_;
1590 }
1591 
1594  : origin_override(config.origin_override),
1595  origin(BgpAttr::OriginFromString(config.origin)) {
1596 }
1597 
1599  if (origin_override != rhs.origin_override) {
1600  return true;
1601  }
1602 
1603  // compare origin only if override is set
1604  if (origin_override && origin != rhs.origin) {
1605  return true;
1606  }
1607  return false;
1608 }
1609 
1610 //
1611 // Accumulate the message in the update buffer.
1612 // Flush the existing buffer if the message can't fit.
1613 // Note that FlushUpdateUnlocked clears the buffer.
1614 //
1615 bool BgpPeer::SendUpdate(const uint8_t *msg, size_t msgsize,
1616  const string *msg_str) {
1617  tbb::spin_mutex::scoped_lock lock(spin_mutex_);
1618  bool send_ready = true;
1619  if (buffer_.size() + msgsize > buffer_capacity_) {
1620  send_ready = FlushUpdateUnlocked();
1621  assert(buffer_.empty());
1622  }
1623  buffer_.insert(buffer_.end(), msg, msg + msgsize);
1624  inc_tx_update();
1625  return send_ready;
1626 }
1627 
1629  // Bail if the update buffer is empty.
1630  if (buffer_.empty())
1631  return true;
1632 
1633  // Bail if there's no session for the peer anymore.
1634  if (!session_) {
1635  buffer_.clear();
1636  return true;
1637  }
1638 
1639  if (!SkipUpdateSend()) {
1640  send_ready_ = session_->Send(buffer_.data(), buffer_.size(), NULL);
1641  buffer_.clear();
1642  if (send_ready_) {
1644  } else {
1646  }
1647  } else {
1648  send_ready_ = true;
1649  }
1650 
1651  if (!send_ready_) {
1652  BGP_LOG_PEER(Event, this, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
1653  BGP_PEER_DIR_NA, "Send blocked");
1654  }
1655  return send_ready_;
1656 }
1657 
1659  tbb::spin_mutex::scoped_lock lock(spin_mutex_);
1660  return FlushUpdateUnlocked();
1661 }
1662 
1664  return peer_close_->gr_params().notification();
1665 }
1666 
1667 // Check if GR Helper mode sould be attempted.
1668 bool BgpPeer::AttemptGRHelperMode(int code, int subcode) const {
1669  if (!code)
1670  return true;
1671 
1672  if (code == BgpProto::Notification::Cease &&
1673  (subcode == BgpProto::Notification::HardReset ||
1675  return false;
1676  }
1677 
1678  // If Peer supports Notification (N) bit, then attempt GR-Helper for all
1679  // other notifications, not otherwise.
1680  return notification();
1681 }
1682 
1684  int code, int subcode, const string &data) {
1685  tbb::spin_mutex::scoped_lock lock(spin_mutex_);
1686  session->SendNotification(code, subcode, data);
1687  state_machine_->set_last_notification_out(code, subcode, data);
1689 }
1690 
1692  peer_bgp_id_ = htonl(msg->identifier);
1693  capabilities_.clear();
1694  vector<BgpProto::OpenMessage::OptParam *>::const_iterator it;
1695  for (it = msg->opt_params.begin(); it < msg->opt_params.end(); ++it) {
1696  capabilities_.insert(capabilities_.end(), (*it)->capabilities.begin(),
1697  (*it)->capabilities.end());
1698  (*it)->capabilities.clear();
1699  }
1700 
1701  as4_supported_ = false;
1702  if (server_->enable_4byte_as()) {
1703  vector<BgpProto::OpenMessage::Capability *>::iterator c_it;
1704  for (c_it = capabilities_.begin(); c_it < capabilities_.end(); ++c_it) {
1705  if ((*c_it)->code ==BgpProto::OpenMessage::Capability::AS4Support) {
1706  as4_supported_ = true;
1707  break;
1708  }
1709  }
1710  }
1711  BgpPeerInfoData peer_info;
1712  peer_info.set_name(ToUVEKey());
1713  peer_info.set_peer_id(peer_bgp_id_);
1714 
1715  vector<string> families;
1716  vector<BgpProto::OpenMessage::Capability *>::iterator cap_it;
1717  for (cap_it = capabilities_.begin(); cap_it < capabilities_.end();
1718  ++cap_it) {
1719  if ((*cap_it)->code != BgpProto::OpenMessage::Capability::MpExtension)
1720  continue;
1721  uint8_t *data = (*cap_it)->capability.data();
1722  uint16_t afi = get_value(data, 2);
1723  uint8_t safi = get_value(data + 3, 1);
1724  Address::Family family = BgpAf::AfiSafiToFamily(afi, safi);
1725  if (family == Address::UNSPEC) {
1726  families.push_back(BgpAf::ToString(afi, safi));
1727  } else {
1728  families.push_back(Address::FamilyToString(family));
1729  }
1730  }
1731  peer_info.set_families(families);
1732 
1733  negotiated_families_.clear();
1734  for (int idx = Address::UNSPEC; idx < Address::NUM_FAMILIES; ++idx) {
1735  if (!family_attributes_list_[idx])
1736  continue;
1737  Address::Family family = static_cast<Address::Family>(idx);
1738  uint16_t afi;
1739  uint8_t safi;
1740  tie(afi, safi) = BgpAf::FamilyToAfiSafi(family);
1741  if (!MpNlriAllowed(afi, safi))
1742  continue;
1743  negotiated_families_.push_back(Address::FamilyToString(family));
1744  }
1745  sort(negotiated_families_.begin(), negotiated_families_.end());
1746  peer_info.set_negotiated_families(negotiated_families_);
1747 
1748  // Process GR/LLGR capabilities and close non-gracefully if any ongoing GR
1749  // needs be aborted.
1750  if (!peer_close_->SetGRCapabilities(&peer_info)) {
1751  BGP_LOG_PEER(Message, this, SandeshLevel::SYS_INFO, BGP_LOG_FLAG_ALL,
1752  BGP_PEER_DIR_IN, "Close non-gracefully");
1753  Close(false);
1754  return false;
1755  }
1756  return true;
1757 }
1758 
1759 // Reset capabilities stored inside peer structure.
1760 //
1761 // When open message is processed, we directly take the capabilities off the
1762 // open message and store inside the peer structure.
1763 //
1766  BgpPeerInfoData peer_info;
1767  peer_info.set_name(ToUVEKey());
1768  vector<string> families = vector<string>();
1769  peer_info.set_families(families);
1770  vector<string> negotiated_families = vector<string>();
1771  peer_info.set_negotiated_families(negotiated_families);
1772  peer_info.set_graceful_restart_families(vector<string>());
1773  BGPPeerInfoSend(peer_info);
1774 }
1775 
1776 bool BgpPeer::MpNlriAllowed(uint16_t afi, uint8_t safi) {
1777  vector<BgpProto::OpenMessage::Capability *>::iterator it;
1778  for (it = capabilities_.begin(); it < capabilities_.end(); ++it) {
1780  continue;
1781  uint8_t *data = (*it)->capability.data();
1782  uint16_t af_value = get_value(data, 2);
1783  uint8_t safi_value = get_value(data + 3, 1);
1784  if (afi == af_value && safi == safi_value) {
1785  return true;
1786  }
1787  }
1788  return false;
1789 }
1790 
1792  return as4_supported_;
1793 }
1794 
1795 template <typename TableT, typename PrefixT>
1797  const BgpMpNlri *nlri, BgpAttrPtr attr, uint32_t flags) {
1798  TableT *table = static_cast<TableT *>(rtinstance_->GetTable(family));
1799  assert(table);
1800 
1801  for (vector<BgpProtoPrefix *>::const_iterator it = nlri->nlri.begin();
1802  it != nlri->nlri.end(); ++it) {
1803  PrefixT prefix;
1804  BgpAttrPtr new_attr(attr);
1805  uint32_t label = 0;
1806  uint32_t l3_label = 0;
1807  int result = PrefixT::FromProtoPrefix(server_, **it,
1808  (oper == DBRequest::DB_ENTRY_ADD_CHANGE ? attr.get() : NULL),
1809  family, &prefix, &new_attr, &label, &l3_label);
1810  if (result) {
1813  "MP NLRI parse error for " <<
1814  Address::FamilyToString(family) << " route");
1815  continue;
1816  }
1817 
1818  DBRequest req;
1819  req.oper = oper;
1820  if (oper == DBRequest::DB_ENTRY_ADD_CHANGE) {
1821  req.data.reset(new typename TableT::RequestData(
1822  new_attr, flags, label, l3_label, 0));
1823  }
1824  req.key.reset(new typename TableT::RequestKey(prefix, this));
1825  table->Enqueue(&req);
1826  }
1827 }
1828 
1830  const BgpAttr *attr) const {
1831  uint32_t flags = resolve_paths_ ? BgpPath::ResolveNexthop : 0;
1832 
1833  // Check for OriginatorId loop in case we are an RR client.
1834  if (peer_type_ == BgpProto::IBGP &&
1835  attr->originator_id().to_ulong() == ntohl(local_bgp_id_)) {
1836  flags |= BgpPath::OriginatorIdLooped;
1837  }
1838 
1839  // Check for ClusterList loop in case we are an RR.
1840  if (server_->cluster_id() && attr->cluster_list() &&
1842  server_->cluster_id())) {
1843  flags |= BgpPath::ClusterListLooped;
1844  }
1845 
1846  if (!attr->as_path() && !attr->aspath_4byte())
1847  return flags;
1848 
1849  // Check whether neighbor has appended its AS to the AS_PATH.
1850  if ((PeerType() == BgpProto::EBGP) &&
1851  ((attr->as_path() && !attr->as_path()->path().AsLeftMostMatch(
1852  peer_as())) || (attr->aspath_4byte() &&
1853  !attr->aspath_4byte()->path().AsLeftMostMatch(peer_as())))) {
1854  flags |= BgpPath::NoNeighborAs;
1855  }
1856 
1857  // Check for AS_PATH loop.
1858  uint8_t max_loop_count = family_attributes_list_[family]->loop_count;
1859  if (attr->IsAsPathLoop(local_as_, max_loop_count))
1860  flags |= BgpPath::AsPathLooped;
1861 
1862  return flags;
1863 }
1864 
1865 uint32_t BgpPeer::GetLocalPrefFromMed(uint32_t med) const {
1866  if (peer_type_ != BgpProto::EBGP)
1867  return 0;
1868  if (!peer_is_control_node_)
1869  return 0;
1870  if (med == 0)
1871  return 0;
1872  if (med == 100)
1873  return 200;
1874  if (med == 200)
1875  return 100;
1876  return numeric_limits<uint32_t>::max() - med;
1877 }
1878 
1879 void BgpPeer::ProcessUpdate(const BgpProto::Update *msg, size_t msgsize) {
1880  BgpAttrPtr attr = server_->attr_db()->Locate(msg->path_attributes);
1881 
1882  uint32_t local_pref = GetLocalPrefFromMed(attr->med());
1883  if (local_pref) {
1884  attr = server_->attr_db()->ReplaceLocalPreferenceAndLocate(attr.get(),
1885  local_pref);
1886  }
1887 
1888  // Check if peer is marked to override the route origin attribute
1890  attr = server_->attr_db()->ReplaceOriginAndLocate(attr.get(),
1892  }
1893 
1894  if ((router_type_ == "bgpaas-client") ||
1895  (router_type_ == "bgpaas-server")) {
1896  attr = server_->attr_db()->ReplaceSubProtocolAndLocate(attr.get(),
1898  }
1899 
1900  uint32_t reach_count = 0, unreach_count = 0;
1901  RoutingInstance *instance = GetRoutingInstance();
1902  if (msg->nlri.size() || msg->withdrawn_routes.size()) {
1903  InetTable *table =
1904  static_cast<InetTable *>(instance->GetTable(Address::INET));
1905  if (!table) {
1907  "Cannot find inet table");
1908  return;
1909  }
1910 
1911  unreach_count += msg->withdrawn_routes.size();
1912  for (vector<BgpProtoPrefix *>::const_iterator it =
1913  msg->withdrawn_routes.begin(); it != msg->withdrawn_routes.end();
1914  ++it) {
1915  Ip4Prefix prefix;
1916  int result = Ip4Prefix::FromProtoPrefix((**it), &prefix);
1917  if (result) {
1920  "Withdrawn route parse error for inet route");
1921  continue;
1922  }
1923 
1924  DBRequest req;
1926  req.data.reset(NULL);
1927  req.key.reset(new InetTable::RequestKey(prefix, this));
1928  table->Enqueue(&req);
1929  }
1930 
1931  uint32_t flags = GetPathFlags(Address::INET, attr.get());
1932  reach_count += msg->nlri.size();
1933  for (vector<BgpProtoPrefix *>::const_iterator it = msg->nlri.begin();
1934  it != msg->nlri.end(); ++it) {
1935  Ip4Prefix prefix;
1936  int result = Ip4Prefix::FromProtoPrefix((**it), &prefix);
1937  if (result) {
1940  "NLRI parse error for inet route");
1941  continue;
1942  }
1943 
1944  DBRequest req;
1946  req.data.reset(new InetTable::RequestData(attr, flags, 0, 0, 0));
1947  req.key.reset(new InetTable::RequestKey(prefix, this));
1948  table->Enqueue(&req);
1949  }
1950  }
1951 
1952  for (vector<BgpAttribute *>::const_iterator ait =
1953  msg->path_attributes.begin();
1954  ait != msg->path_attributes.end(); ++ait) {
1956  if ((*ait)->code == BgpAttribute::MPReachNlri) {
1958  } else if ((*ait)->code == BgpAttribute::MPUnreachNlri) {
1960  } else {
1961  continue;
1962  }
1963 
1964  BgpMpNlri *nlri = static_cast<BgpMpNlri *>(*ait);
1965  assert(nlri);
1966  if (oper == DBRequest::DB_ENTRY_ADD_CHANGE) {
1967  reach_count += nlri->nlri.size();
1968  } else {
1969  unreach_count += nlri->nlri.size();
1970  }
1971 
1972  Address::Family family = BgpAf::AfiSafiToFamily(nlri->afi, nlri->safi);
1973  if (!IsFamilyNegotiated(family)) {
1976  "AFI "<< nlri->afi << " SAFI " << (int) nlri->safi <<
1977  " not allowed");
1978  continue;
1979  }
1980 
1981  // Handle EndOfRib marker.
1982  if (oper == DBRequest::DB_ENTRY_DELETE && nlri->nlri.empty()) {
1984  BGP_LOG_PEER(Message, this, SandeshLevel::SYS_INFO,
1986  "EndOfRib marker family " <<
1987  Address::FamilyToString(family) <<
1988  " size " << msgsize);
1989  ReceiveEndOfRIB(family, msgsize);
1990  return;
1991  }
1992 
1993  uint32_t flags = 0;
1994  if ((*ait)->code == BgpAttribute::MPReachNlri) {
1995  flags = GetPathFlags(family, attr.get());
1996  attr = GetMpNlriNexthop(nlri, attr);
1997  }
1998 
1999  switch (family) {
2000  case Address::INET:
2001  case Address::INETMPLS:
2002  ProcessNlri<InetTable, Ip4Prefix>(
2003  family, oper, nlri, attr, flags);
2004  break;
2005  case Address::INETVPN:
2006  ProcessNlri<InetVpnTable, InetVpnPrefix>(
2007  family, oper, nlri, attr, flags);
2008  break;
2009  case Address::INET6:
2010  ProcessNlri<Inet6Table, Inet6Prefix>(
2011  family, oper, nlri, attr, flags);
2012  break;
2013  case Address::INET6VPN:
2014  ProcessNlri<Inet6VpnTable, Inet6VpnPrefix>(
2015  family, oper, nlri, attr, flags);
2016  break;
2017  case Address::EVPN:
2018  ProcessNlri<EvpnTable, EvpnPrefix>(
2019  family, oper, nlri, attr, flags);
2020  break;
2021  case Address::ERMVPN:
2022  ProcessNlri<ErmVpnTable, ErmVpnPrefix>(
2023  family, oper, nlri, attr, flags);
2024  break;
2025  case Address::MVPN:
2026  ProcessNlri<MvpnTable, MvpnPrefix>(
2027  family, oper, nlri, attr, flags);
2028  break;
2029  case Address::RTARGET:
2030  ProcessNlri<RTargetTable, RTargetPrefix>(
2031  family, oper, nlri, attr, flags);
2032  break;
2033  default:
2034  break;
2035  }
2036  }
2037 
2038  inc_rx_route_reach(reach_count);
2039  inc_rx_route_unreach(unreach_count);
2043  "Update size " << msgsize <<
2044  " reach " << reach_count << " unreach " << unreach_count);
2045  }
2046 }
2047 const std::vector<std::string> BgpPeer::GetDefaultTunnelEncap(
2048  const Address::Family family) const {
2049  if (family_attributes_list_[family] == NULL)
2050  return std::vector<std::string>();
2051  return family_attributes_list_[family]->default_tunnel_encap_list;
2052 }
2053 
2055  ExtCommunityDB *extcomm_db,
2056  const BgpTable *table) const {
2057  if (!GetDefaultTunnelEncap(table->family()).empty()) {
2058  ExtCommunityPtr ext_community = attr->ext_community();
2059  bool tunnel_encap_found = false;
2060  if (ext_community) {
2061  for (ExtCommunity::ExtCommunityList::const_iterator iter =
2062  attr->ext_community()->communities().begin();
2063  iter != attr->ext_community()->communities().end();
2064  ++iter) {
2065  if (ExtCommunity::is_tunnel_encap(*iter)) {
2066  tunnel_encap_found = true;
2067  break;
2068  }
2069  }
2070  }
2071  // Set default tunnel encap since it is not in the path
2072  if (!ext_community || !tunnel_encap_found) {
2073  ExtCommunity::ExtCommunityList encap_list;
2074  BOOST_FOREACH(const string &encap_string,
2075  GetDefaultTunnelEncap(table->family())) {
2076  TunnelEncap tunnel_encap(encap_string);
2077  encap_list.push_back(tunnel_encap.GetExtCommunity());
2078  }
2079  ext_community =
2081  ext_community ? ext_community.get() : NULL, encap_list);
2082  attr->set_ext_community(ext_community);
2083  }
2084  }
2085 }
2086 
2087 
2088 void BgpPeer::UpdatePrimaryPathCount(int count, Address::Family family) const {
2089  primary_path_count_ += count;
2090  if (family == Address::UNSPEC)
2091  return;
2092  family_primary_path_count_[family] += count;
2093  uint32_t limit = 0;
2094  if (family_attributes_list_[family])
2095  limit = family_attributes_list_[family]->prefix_limit;
2096  if (limit && family_primary_path_count_[family] > limit)
2098 }
2099 
2100 void BgpPeer::StartPrefixLimitIdleTimer(uint32_t plim_idle_time_msecs) {
2101  prefix_limit_idle_timer_->Start(plim_idle_time_msecs,
2102  boost::bind(&BgpPeer::PrefixLimitIdleTimerExpired, this),
2103  boost::bind(&BgpPeer::PrefixLimitIdleTimerErrorHandler, this, _1, _2));
2104 }
2105 
2108 }
2109 
2112 }
2113 
2115  return false;
2116 }
2117 
2119  string error_message) {
2121  "Timer error: " << error_name << " " << error_message);
2122 }
2123 
2124 void BgpPeer::EndOfRibTimerErrorHandler(string error_name,
2125  string error_message) {
2127  "Timer error: " << error_name << " " << error_message);
2128 }
2129 
2131  CHECK_CONCURRENCY("bgp::StateMachine", "bgp::RTFilter", "bgp::Config");
2132 
2134  return;
2135  vpn_tables_registered_ = true;
2136 
2137  RoutingInstance *instance = GetRoutingInstance();
2138  vector<Address::Family> vpn_family_list = list_of
2140  (Address::MVPN);
2141  BOOST_FOREACH(Address::Family vpn_family, vpn_family_list) {
2142  if (!IsFamilyNegotiated(vpn_family))
2143  continue;
2144  BgpTable *table = instance->GetTable(vpn_family);
2145  BGP_LOG_PEER_TABLE(this, SandeshLevel::SYS_INFO, BGP_LOG_FLAG_TRACE,
2146  table, "Register peer with the table");
2147  Register(table, BuildRibExportPolicy(vpn_family));
2148  }
2149 }
2150 
2152  uint32_t timeout = GetEndOfRibReceiveTime(family);
2153 
2154  BGP_LOG_PEER(Message, this, SandeshLevel::SYS_INFO,
2156  "EndOfRib Receive Timer scheduled for family " <<
2157  Address::FamilyToString(family) <<
2158  " to fire after " << timeout << " second(s)");
2159  eor_receive_timer_[family]->Start(timeout * 1000,
2160  boost::bind(&BgpPeer::EndOfRibReceiveTimerExpired, this, family),
2161  boost::bind(&BgpPeer::EndOfRibTimerErrorHandler, this, _1, _2));
2162 }
2163 
2165  string error_message) {
2167  "Timer error: " << error_name << " " << error_message);
2168 }
2169 
2171  if (family == Address::RTARGET)
2173 
2174  // Fake reception of EoRs to exit from GR states and sweep all stale routes.
2175  close_manager_->ProcessEORMarkerReceived(family);
2176  return false;
2177 }
2178 
2180  if (!IsReady())
2181  return false;
2182 
2183  SendKeepalive(true);
2184 
2185  //
2186  // Start the timer again, by returning true
2187  //
2188  return true;
2189 }
2190 
2192  int keepalive_time_msecs = state_machine_->keepalive_time_msecs();
2193  if (keepalive_time_msecs <= 0)
2194  return;
2195 
2196  keepalive_timer_->Start(keepalive_time_msecs,
2197  boost::bind(&BgpPeer::KeepaliveTimerExpired, this),
2198  boost::bind(&BgpPeer::KeepaliveTimerErrorHandler, this, _1, _2));
2199 }
2200 
2202  tbb::spin_mutex::scoped_lock lock(spin_mutex_);
2203  if (session_ && send_ready_)
2205 }
2206 
2209 }
2210 
2212  tbb::spin_mutex::scoped_lock lock(spin_mutex_);
2213  return keepalive_timer_->running();
2214 }
2215 
2217  tbb::spin_mutex::scoped_lock lock(spin_mutex_);
2218  BGP_LOG_PEER(Event, this, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
2219  BGP_PEER_DIR_NA, "Send ready");
2220  send_ready_ = true;
2221  if (session_ != NULL)
2223 }
2224 
2226  tbb::spin_mutex::scoped_lock lock(spin_mutex_);
2227  assert(session_ == NULL);
2228  session_ = session;
2229 }
2230 
2232  tbb::spin_mutex::scoped_lock lock(spin_mutex_);
2233  if (session_) {
2234  session_->clear_peer();
2235  session_->set_observer(NULL);
2236  session_->Close();
2237  }
2238  session_ = NULL;
2239 }
2240 
2242  return session_;
2243 }
2244 
2245 string BgpPeer::BytesToHexString(const u_int8_t *msg, size_t size) {
2246  ostringstream out;
2247  char buf[4];
2248 
2249  for (size_t i = 0; i < size; i ++) {
2250  if (!(i % 32)) out << "\n";
2251  if (!(i % 4)) out << " 0x";
2252  snprintf(buf, sizeof(buf), "%02X", msg[i]);
2253  out << buf;
2254  }
2255 
2256  out << "\n";
2257 
2258  return out.str();
2259 }
2260 
2261 bool BgpPeer::ReceiveMsg(BgpSession *session, const u_int8_t *msg,
2262  size_t size) {
2263  ParseErrorContext ec;
2264  BgpProto::BgpMessage *minfo = BgpProto::Decode(msg, size, &ec,
2265  Is4ByteAsSupported());
2266 
2267  if (minfo == NULL) {
2268  BGP_TRACE_PEER_PACKET(this, msg, size, SandeshLevel::SYS_WARN);
2271  "Error while parsing message at " << ec.type_name);
2272  state_machine_->OnMessageError(session, &ec);
2273  return false;
2274  }
2275 
2276  // Tracing periodic keepalive packets is not necessary.
2277  if (minfo->type != BgpProto::KEEPALIVE)
2278  BGP_TRACE_PEER_PACKET(this, msg, size, Sandesh::LoggingUtLevel());
2279 
2280  state_machine_->OnMessage(session, minfo, size);
2281  return true;
2282 }
2283 
2284 //
2285 // Extract nexthop address from BgpMpNlri if appropriate and return updated
2286 // BgpAttrPtr. The original attribute is returned for cases where there's no
2287 // nexthop attribute in the BgpMpNlri.
2288 //
2290  bool update_nh = false;
2291  IpAddress addr;
2292 
2293  if (nlri->afi == BgpAf::IPv4) {
2294  if (nlri->safi == BgpAf::Mpls || nlri->safi == BgpAf::Unicast ||
2295  nlri->safi == BgpAf::RTarget || nlri->safi == BgpAf::MVpn) {
2296  Ip4Address::bytes_type bt = { { 0 } };
2297  copy(nlri->nexthop.begin(),
2298  nlri->nexthop.begin() + sizeof(bt), bt.begin());
2299  addr = Ip4Address(bt);
2300  update_nh = true;
2301  } else if (nlri->safi == BgpAf::Vpn) {
2302  Ip4Address::bytes_type bt = { { 0 } };
2303  size_t rdsize = RouteDistinguisher::kSize;
2304  copy(nlri->nexthop.begin() + rdsize,
2305  nlri->nexthop.begin() + rdsize + sizeof(bt), bt.begin());
2306  addr = Ip4Address(bt);
2307  update_nh = true;
2308  }
2309  } else if (nlri->afi == BgpAf::L2Vpn) {
2310  if (nlri->safi == BgpAf::EVpn) {
2311  Ip4Address::bytes_type bt = { { 0 } };
2312  copy(nlri->nexthop.begin(),
2313  nlri->nexthop.begin() + sizeof(bt), bt.begin());
2314  addr = Ip4Address(bt);
2315  update_nh = true;
2316  }
2317  } else if (nlri->afi == BgpAf::IPv6) {
2318  if (nlri->safi == BgpAf::Unicast) {
2319  // There could be either 1 or 2 v6 addresses in the nexthop field.
2320  // The first one is supposed to be global and the optional second
2321  // one, if present, is link local. We will be liberal and find the
2322  // global address, whether it's first or second. Further, if the
2323  // address is a v4-mapped v6 address, we use the corresponding v4
2324  // address as the nexthop.
2325  for (int idx = 0; idx < 2; ++idx) {
2326  Ip6Address::bytes_type bt = { { 0 } };
2327  if ((idx + 1) * sizeof(bt) > nlri->nexthop.size())
2328  break;
2329  copy(nlri->nexthop.begin() + idx * sizeof(bt),
2330  nlri->nexthop.begin() + (idx + 1) * sizeof(bt), bt.begin());
2331  Ip6Address v6_addr(bt);
2332  if (v6_addr.is_v4_mapped()) {
2333  addr = Address::V4FromV4MappedV6(v6_addr);
2334  update_nh = true;
2335  break;
2336  }
2337  if (!v6_addr.is_link_local()) {
2338  addr = v6_addr;
2339  update_nh = true;
2340  break;
2341  }
2342  }
2343  } else if (nlri->safi == BgpAf::Vpn) {
2344  Ip6Address::bytes_type bt = { { 0 } };
2345  size_t rdsize = RouteDistinguisher::kSize;
2346  copy(nlri->nexthop.begin() + rdsize,
2347  nlri->nexthop.begin() + rdsize + sizeof(bt), bt.begin());
2348  Ip6Address v6_addr(bt);
2349  if (v6_addr.is_v4_mapped()) {
2350  addr = Address::V4FromV4MappedV6(v6_addr);
2351  update_nh = true;
2352  }
2353  }
2354  }
2355 
2356  // Always update the nexthop in BgpAttr with MpReachNlri->nexthop.
2357  // NOP in cases <afi,safi> doesn't carry nexthop attribute.
2358  if (update_nh) {
2359  attr = server_->attr_db()->ReplaceNexthopAndLocate(attr.get(), addr);
2360  }
2361  return attr;
2362 }
2363 
2365  if (deleter_->IsDeleted())
2366  return;
2367  BGP_LOG_PEER(Config, this, SandeshLevel::SYS_INFO, BGP_LOG_FLAG_ALL,
2368  BGP_PEER_DIR_NA, "Received request for deletion");
2369  if (IsRouterTypeBGPaaS()) {
2371  } else {
2373  }
2374  deleter_->Delete();
2375 }
2376 
2378  if (!deleter_->IsDeleted())
2379  return;
2380  deleter_->RetryDelete();
2381 }
2382 
2385 }
2386 
2387 void BgpPeer::SetDataCollectionKey(BgpPeerInfo *peer_info) const {
2388  if (rtinstance_) {
2389  peer_info->set_domain(rtinstance_->name());
2390  } else {
2391  peer_info->set_domain(BgpConfigManager::kMasterInstance);
2392  }
2393 
2394  peer_info->set_ip_address(peer_key_.endpoint.address().to_string());
2395 }
2396 
2398  PeerProtoStats *proto_stats) {
2399  proto_stats->set_open(stats.open);
2400  proto_stats->set_keepalive(stats.keepalive);
2401  proto_stats->set_close(stats.close);
2402  proto_stats->set_update(stats.update);
2403  proto_stats->set_notification(stats.notification);
2404  proto_stats->set_total(stats.open + stats.keepalive + stats.close +
2405  stats.update + stats.notification);
2406 }
2407 
2409  PeerUpdateStats *rt_stats) {
2410  rt_stats->set_reach(stats.reach);
2411  rt_stats->set_unreach(stats.unreach);
2412  rt_stats->set_end_of_rib(stats.end_of_rib);
2413  rt_stats->set_total(stats.reach + stats.unreach + stats.end_of_rib);
2414 }
2415 
2416 static void FillSocketStats(const IPeerDebugStats::SocketStats &socket_stats,
2417  PeerSocketStats *peer_socket_stats) {
2418  peer_socket_stats->set_calls(socket_stats.calls);
2419  peer_socket_stats->set_bytes(socket_stats.bytes);
2420  if (socket_stats.calls) {
2421  peer_socket_stats->set_average_bytes(
2422  socket_stats.bytes/socket_stats.calls);
2423  }
2424  peer_socket_stats->set_blocked_count(socket_stats.blocked_count);
2425  ostringstream os;
2426  os << boost::posix_time::microseconds(long(socket_stats.blocked_duration_usecs));
2427  peer_socket_stats->set_blocked_duration(os.str());
2428  if (socket_stats.blocked_count) {
2429  os.str("");
2430  os << boost::posix_time::microseconds(
2431  socket_stats.blocked_duration_usecs/socket_stats.blocked_count);
2432  peer_socket_stats->set_average_blocked_duration(os.str());
2433  }
2434 }
2435 
2436 void BgpPeer::FillCloseInfo(BgpNeighborResp *resp) const {
2437  close_manager_->FillCloseInfo(resp);
2438 }
2439 
2440 void BgpPeer::FillBgpNeighborDebugState(BgpNeighborResp *bnr,
2441  const IPeerDebugStats *peer_stats) {
2442  bnr->set_last_state(peer_stats->last_state());
2443  bnr->set_last_event(peer_stats->last_event());
2444  bnr->set_last_error(peer_stats->last_error());
2445  bnr->set_last_state_at(peer_stats->last_state_change_at());
2446  bnr->set_flap_count(peer_stats->num_flaps());
2447  bnr->set_flap_time(peer_stats->last_flap());
2448 
2450  PeerProtoStats proto_stats;
2451  peer_stats->GetRxProtoStats(&stats);
2452  FillProtoStats(stats, &proto_stats);
2453  bnr->set_rx_proto_stats(proto_stats);
2454 
2455  peer_stats->GetTxProtoStats(&stats);
2456  FillProtoStats(stats, &proto_stats);
2457  bnr->set_tx_proto_stats(proto_stats);
2458 
2459  IPeerDebugStats::UpdateStats update_stats;
2460  PeerUpdateStats rt_stats;
2461  peer_stats->GetRxRouteUpdateStats(&update_stats);
2462  FillRouteUpdateStats(update_stats, &rt_stats);
2463  bnr->set_rx_update_stats(rt_stats);
2464 
2465  peer_stats->GetTxRouteUpdateStats(&update_stats);
2466  FillRouteUpdateStats(update_stats, &rt_stats);
2467  bnr->set_tx_update_stats(rt_stats);
2468 
2469  IPeerDebugStats::SocketStats socket_stats;
2470  PeerSocketStats peer_socket_stats;
2471 
2472  peer_stats->GetRxSocketStats(&socket_stats);
2473  FillSocketStats(socket_stats, &peer_socket_stats);
2474  bnr->set_rx_socket_stats(peer_socket_stats);
2475 
2476  peer_stats->GetTxSocketStats(&socket_stats);
2477  FillSocketStats(socket_stats, &peer_socket_stats);
2478  bnr->set_tx_socket_stats(peer_socket_stats);
2479 }
2480 
2481 void BgpPeer::FillBgpNeighborFamilyAttributes(BgpNeighborResp *nbr) const {
2482  vector<ShowBgpNeighborFamily> show_family_attributes_list;
2483  for (int idx = Address::UNSPEC; idx < Address::NUM_FAMILIES; ++idx) {
2484  if (!family_attributes_list_[idx])
2485  continue;
2486  ShowBgpNeighborFamily show_family_attributes;
2487  show_family_attributes.set_family(
2488  Address::FamilyToString(static_cast<Address::Family>(idx)));
2489  show_family_attributes.set_loop_count(
2490  family_attributes_list_[idx]->loop_count);
2491  show_family_attributes.set_prefix_limit(
2492  family_attributes_list_[idx]->prefix_limit);
2493  show_family_attributes.set_idle_timeout(
2494  family_attributes_list_[idx]->idle_timeout);
2495  if (!family_attributes_list_[idx]->gateway_address.is_unspecified()) {
2496  show_family_attributes.set_gateway_address(
2497  family_attributes_list_[idx]->gateway_address.to_string());
2498  }
2499  show_family_attributes_list.push_back(show_family_attributes);
2500  }
2501  nbr->set_family_attributes_list(show_family_attributes_list);
2502 }
2503 
2505  BgpNeighborResp *bnr, bool summary) const {
2506  bnr->set_instance_name(rtinstance_->name());
2507  bnr->set_peer(peer_basename_);
2508  bnr->set_deleted(IsDeleted());
2509  bnr->set_closed_at(UTCUsecToString(deleter_->delete_time_stamp_usecs()));
2510  bnr->set_admin_down(admin_down_);
2511  bnr->set_passive(passive_);
2512  bnr->set_as_override(as_override_);
2513  bnr->set_origin_override(origin_override_.origin_override);
2515  bnr->set_route_origin(BgpAttr::OriginToString(origin_override_.origin));
2516  } else {
2517  bnr->set_route_origin("-");
2518  }
2519  bnr->set_private_as_action(private_as_action_);
2520  bnr->set_peer_address(peer_address_string());
2521  bnr->set_peer_id(bgp_identifier_string());
2522  bnr->set_peer_asn(peer_as());
2523  bnr->set_peer_port(peer_port());
2524  bnr->set_transport_address(transport_address_string());
2525  bnr->set_encoding("BGP");
2526  bnr->set_peer_type(PeerType() == BgpProto::IBGP ? "internal" : "external");
2527  bnr->set_router_type(router_type_);
2528  bnr->set_state(state_machine_->StateName());
2529  bnr->set_local_address(server_->ToString());
2530  bnr->set_local_id(Ip4Address(ntohl(local_bgp_id_)).to_string());
2531  bnr->set_local_asn(local_as());
2532  bnr->set_cluster_id(Ip4Address(cluster_id_).to_string());
2533  bnr->set_negotiated_hold_time(state_machine_->hold_time());
2534  bnr->set_primary_path_count(GetPrimaryPathCount());
2535  bnr->set_task_instance(GetTaskInstance());
2536  bnr->set_send_ready(send_ready_);
2537  bnr->set_flap_count(peer_stats_->num_flaps());
2538  bnr->set_as4_supported(Is4ByteAsSupported());
2539  bnr->set_flap_time(peer_stats_->last_flap());
2540  bnr->set_auth_type(
2542  if (bsc->test_mode()) {
2543  bnr->set_auth_keys(auth_data_.KeysToStringDetail());
2544  }
2545 
2546  if (summary)
2547  return;
2548 
2549  bnr->set_configured_address_families(configured_families_);
2550  bnr->set_negotiated_address_families(negotiated_families_);
2551 
2552  peer_close_->FillNeighborInfo(bnr);
2553 
2554  bnr->set_configured_hold_time(state_machine_->GetConfiguredHoldTime());
2558  mgr->FillPeerMembershipInfo(this, bnr);
2559  bnr->set_routing_instances(vector<BgpNeighborRoutingInstance>());
2560  FillCloseInfo(bnr);
2561 }
2562 
2564  peer_stats_->proto_stats_[0].open++;
2565 }
2566 
2568  peer_stats_->proto_stats_[1].open++;
2569 }
2570 
2572  peer_stats_->proto_stats_[0].keepalive++;
2573 }
2574 
2575 uint64_t BgpPeer::get_rx_keepalive() const {
2576  return peer_stats_->proto_stats_[0].keepalive;
2577 }
2578 
2580  peer_stats_->proto_stats_[1].keepalive++;
2581 }
2582 
2583 uint64_t BgpPeer::get_tx_keepalive() const {
2584  return peer_stats_->proto_stats_[1].keepalive;
2585 }
2586 
2588  peer_stats_->proto_stats_[0].update++;
2589 }
2590 
2591 uint64_t BgpPeer::get_rx_update() const {
2592  return peer_stats_->proto_stats_[0].update;
2593 }
2594 
2596  peer_stats_->proto_stats_[1].update++;
2597 }
2598 
2599 uint64_t BgpPeer::get_tx_update() const {
2600  return peer_stats_->proto_stats_[1].update;
2601 }
2602 
2604  peer_stats_->proto_stats_[0].notification++;
2605 }
2606 
2608  return peer_stats_->proto_stats_[0].notification;
2609 }
2610 
2612  peer_stats_->proto_stats_[1].notification++;
2613 }
2614 
2616  peer_stats_->update_stats_[0].end_of_rib++;
2617 }
2618 
2619 uint64_t BgpPeer::get_rx_end_of_rib() const {
2620  return peer_stats_->update_stats_[0].end_of_rib;
2621 }
2622 
2624  peer_stats_->update_stats_[1].end_of_rib++;
2625 }
2626 
2627 uint64_t BgpPeer::get_tx_end_of_rib() const {
2628  return peer_stats_->update_stats_[1].end_of_rib;
2629 }
2630 
2631 void BgpPeer::inc_rx_route_reach(uint64_t count) {
2632  peer_stats_->update_stats_[0].reach += count;
2633 }
2634 
2636  return peer_stats_->update_stats_[0].reach;
2637 }
2638 
2640  return peer_stats_->update_stats_[1].reach;
2641 }
2642 
2643 void BgpPeer::inc_rx_route_unreach(uint64_t count) {
2644  peer_stats_->update_stats_[0].unreach += count;
2645 }
2646 
2648  return peer_stats_->update_stats_[0].unreach;
2649 }
2650 
2652  return peer_stats_->update_stats_[1].unreach;
2653 }
2654 
2656  return peer_stats_->update_stats_[0].reach +
2657  peer_stats_->update_stats_[0].unreach +
2658  peer_stats_->update_stats_[0].end_of_rib;
2659 }
2660 
2662  return peer_stats_->update_stats_[1].reach +
2663  peer_stats_->update_stats_[1].unreach +
2664  peer_stats_->update_stats_[1].end_of_rib;
2665 }
2666 
2668  peer_stats_->error_stats_.connect_error++;
2669 }
2670 
2672  peer_stats_->error_stats_.connect_timer++;
2673 }
2674 
2676  peer_stats_->error_stats_.hold_timer++;
2677 }
2678 
2680  peer_stats_->error_stats_.open_error++;
2681 }
2682 
2684  peer_stats_->error_stats_.update_error++;
2685 }
2686 
2687 uint64_t BgpPeer::get_connect_error() const {
2688  return peer_stats_->error_stats_.connect_error;
2689 }
2690 
2692  return peer_stats_->error_stats_.connect_timer;
2693 }
2694 
2696  return peer_stats_->error_stats_.hold_timer;
2697 }
2698 
2699 uint64_t BgpPeer::get_open_error() const {
2700  return peer_stats_->error_stats_.open_error;
2701 }
2702 
2703 uint64_t BgpPeer::get_update_error() const {
2704  return peer_stats_->error_stats_.update_error;
2705 }
2706 
2707 uint64_t BgpPeer::get_socket_reads() const {
2709  peer_stats_->GetRxSocketStats(&stats);
2710  return stats.calls;
2711 }
2712 
2713 uint64_t BgpPeer::get_socket_writes() const {
2715  peer_stats_->GetTxSocketStats(&stats);
2716  return stats.calls;
2717 }
2718 
2719 string BgpPeer::last_flap_at() const {
2720  if (last_flap_) {
2722  } else {
2723  return "";
2724  }
2725 }
2726 
2728  flap_count_++;
2731 
2732  BgpPeerInfoData peer_info;
2733  peer_info.set_name(ToUVEKey());
2734  PeerFlapInfo flap_info;
2735  flap_info.set_flap_count(flap_count_);
2736  flap_info.set_flap_time(last_flap_);
2737  peer_info.set_flap_info(flap_info);
2738  BGPPeerInfoSend(peer_info);
2739 
2740  PeerFlapData peer_flap_data;
2741  peer_flap_data.set_name(ToUVEKey());
2742  peer_flap_data.set_flap_info(flap_info);
2743  assert(!peer_flap_data.get_name().empty());
2744  BGP_UVE_SEND2(PeerFlap, peer_flap_data, "ObjectBgpPeer");
2745 }
2746 
2748  flap_count_ = 0;
2749  last_flap_ = 0;
2750 
2751  BgpPeerInfoData peer_info;
2752  peer_info.set_name(ToUVEKey());
2753  PeerFlapInfo flap_info;
2754  peer_info.set_flap_info(flap_info);
2755  BGPPeerInfoSend(peer_info);
2756 
2757  PeerFlapData peer_flap_data;
2758  peer_flap_data.set_name(ToUVEKey());
2759  peer_flap_data.set_flap_info(flap_info);
2760  assert(!peer_flap_data.get_name().empty());
2761  BGP_UVE_SEND2(PeerFlap, peer_flap_data, "ObjectBgpPeer");
2762 }
2763 
2764 // Ignore if the peer is IBGP and a BGPaaS client since we do not support that
2765 // combination. i.e, allow any EBGP session or any non BGPaaS-client session.
2767  return PeerType() != BgpProto::IBGP || router_type() != "bgpaas-client";
2768 }
2769 
2770 // Update control DSCP
2771 void BgpPeer::DSCPUpdateCallback(uint8_t dscp_value) {
2772  if ((session_ != NULL) && (dscp_value != 0xFF)) {
2773  session_->SetDscpSocketOption(dscp_value);
2774  }
2775 }
OriginOverride origin_override_
Definition: bgp_peer.h:511
tbb::atomic< uint64_t > unreach
Definition: ipeer.h:107
virtual void GetRxSocketStats(SocketStats *stats) const =0
virtual bool IsInGRTimerWaitState() const
Definition: bgp_peer.cc:1318
void increment_deleting_count()
Definition: bgp_server.h:224
void inc_tx_notification()
Definition: bgp_peer.cc:2611
void Close()
Definition: tcp_session.cc:354
bool FlushUpdateUnlocked()
Definition: bgp_peer.cc:1628
virtual const std::string ToString() const
Definition: bgp_proto.cc:280
virtual bool ProcessSession() const
Definition: bgp_peer.cc:2766
const std::string & LastStateName() const
std::vector< std::string > negotiated_families_
Definition: bgp_peer.h:527
void inc_rx_update()
Definition: bgp_peer.cc:2587
void PrefixLimitIdleTimerErrorHandler(std::string error_name, std::string error_message)
Definition: bgp_peer.cc:2118
static int FromProtoPrefix(const BgpProtoPrefix &proto_prefix, Ip4Prefix *prefix)
Definition: inet_route.cc:15
virtual std::string last_event() const =0
virtual void GetRxRouteStats(RxRouteStats *stats) const
Definition: bgp_peer.cc:148
void AddRTargets(as_t as)
Definition: bgp_peer.cc:727
boost::asio::ip::tcp::endpoint Endpoint
Definition: tcp_session.h:62
static bool end_of_rib_computed()
size_t GetBufferCapacity() const
Definition: bgp_peer.cc:657
const OriginOverrideConfig & origin_override() const
Definition: bgp_config.h:273
static void UpdateStats(FlowEvent *event, FlowStats *stats)
Definition: flow_proto.cc:785
uint16_t afi
Definition: bgp_attr.h:307
const RouteTargetList & GetImportList() const
void DecrementUpBgpaasPeerCount()
Definition: bgp_server.h:258
virtual bool ReceiveMsg(BgpSession *session, const u_int8_t *msg, size_t size)
Definition: bgp_peer.cc:2261
const ClusterListSpec & cluster_list() const
Definition: bgp_attr.h:229
std::vector< BgpProtoPrefix * > nlri
Definition: bgp_attr.h:311
static void FillProtoStats(const IPeerDebugStats::ProtoStats &stats, PeerProtoStats *proto_stats)
Definition: bgp_peer.cc:2397
uint64_t flap_count() const
Definition: bgp_peer.h:249
void Initialize()
Definition: bgp_peer.cc:652
void STLDeleteValues(Container *container)
Definition: util.h:101
bool InstallAuthKeys()
Definition: bgp_peer.cc:842
BgpTable * GetTable(Address::Family fmly)
void FillBgpNeighborFamilyAttributes(BgpNeighborResp *nbr) const
Definition: bgp_peer.cc:2481
void ResetCapabilities()
Definition: bgp_peer.cc:1764
const std::string last_notification_in_error() const
tbb::atomic< int > primary_path_count_
Definition: bgp_peer.h:536
int RegisterInstanceOpCallback(RoutingInstanceCb cb)
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:178
TypePtr Locate(Type *attr)
bool admin_down() const
Definition: bgp_config.h:181
PeerManager * peer_manager()
bool KeepaliveTimerExpired()
Definition: bgp_peer.cc:2179
void inc_tx_end_of_rib()
Definition: bgp_peer.cc:2623
static void FillRouteUpdateStats(const IPeerDebugStats::UpdateStats &stats, PeerUpdateStats *rt_stats)
Definition: bgp_peer.cc:2408
PeerCloseManager * close_manager()
Definition: bgp_peer.h:355
uint64_t get_open_error() const
Definition: bgp_peer.cc:2699
const AsPathSpec & path() const
Definition: bgp_aspath.h:127
#define BGP_LOG_PEER_TABLE(peer, level, flags, tbl, arg)
Definition: bgp_log.h:205
bool ProcessAuthKeyChainConfig(const BgpNeighborConfig *config)
Definition: bgp_peer.cc:831
uint8_t control_dscp() const
Definition: bgp_config.h:704
bool AcceptSession(BgpSession *session)
Definition: bgp_peer.cc:1369
bool IsSet() const
Definition: task_trigger.h:42
BgpAttrPtr GetMpNlriNexthop(BgpMpNlri *nlri, BgpAttrPtr attr)
Definition: bgp_peer.cc:2289
uint32_t GetLocalPrefFromMed(uint32_t med) const
Definition: bgp_peer.cc:1865
bool IsServerStartingUp() const
Definition: bgp_server.cc:722
int dscp_listener_id_
Definition: bgp_peer.h:540
AuthenticationKeyChain::const_iterator const_iterator
Definition: bgp_config.h:48
bool set_synchronize(const SetType *set1, const SetType *set2, AddFunctor add_fn, DelFunctor del_fn)
Definition: set_util.h:21
virtual void UpdateTxReachRoute(uint64_t count)
Definition: bgp_peer.cc:140
void StopKeepaliveTimerUnlocked()
Definition: bgp_peer.cc:2207
std::string peer_basename_
Definition: bgp_peer.h:464
std::vector< std::string > configured_families_
Definition: bgp_peer.h:526
virtual uint32_t local_bgp_identifier() const
Definition: bgp_peer.cc:1215
void StopPrefixLimitIdleTimer()
Definition: bgp_peer.cc:2106
boost::scoped_ptr< DeleteActor > deleter_
Definition: bgp_peer.h:533
void UnregisterASNUpdateCallback(int listener)
Definition: bgp_server.cc:873
boost::scoped_ptr< StateMachine > state_machine_
Definition: bgp_peer.h:529
OriginOverride(const BgpNeighborConfig::OriginOverrideConfig &config)
Definition: bgp_peer.cc:1592
#define BGP_LOG_PEER_NOTICE(type, peer, flags, dir, arg)
Definition: bgp_log.h:170
std::vector< BgpPeerFamilyAttributes * > FamilyAttributesList
Definition: bgp_peer.h:387
static const size_t kMinBufferCapacity
Definition: bgp_peer.h:86
void inc_rx_notification()
Definition: bgp_peer.cc:2603
uint32_t peer_bgp_id_
Definition: bgp_peer.h:523
MessageType type
Definition: bgp_proto.h:53
std::vector< BgpProtoPrefix * > nlri
Definition: bgp_proto.h:436
virtual const std::vector< std::string > GetDefaultTunnelEncap(const Address::Family family) const
Definition: bgp_peer.cc:2047
std::string KeyTypeToString() const
Definition: bgp_config.cc:114
virtual void GetTxRouteUpdateStats(UpdateStats *stats) const =0
void EndOfRibTimerErrorHandler(std::string error_name, std::string error_message)
Definition: bgp_peer.cc:2124
Family
Definition: address.h:24
static const char * kMasterInstance
Definition: bgp_config.h:764
uint64_t get_rx_route_reach() const
Definition: bgp_peer.cc:2635
uint16_t peer_port() const
Definition: bgp_peer.h:165
static Family FamilyFromString(const std::string &family)
Definition: address.cc:54
boost::asio::ip::address IpAddress
Definition: address.h:13
static Address::Family AfiSafiToFamily(uint16_t afi, uint8_t safi)
Definition: bgp_af.cc:71
virtual uint64_t num_flaps() const
Definition: bgp_peer.cc:97
void BGPPeerInfoSend(const BgpPeerInfoData &peer_info) const
Definition: bgp_peer.cc:416
bool LookupFamily(Address::Family family)
Definition: bgp_peer.h:197
virtual int GetPrimaryPathCount() const
Definition: bgp_peer.h:322
boost::scoped_ptr< BgpPeerClose > peer_close_
Definition: bgp_peer.h:530
uint64_t flap_count_
Definition: bgp_peer.h:537
DeleteActor(BgpPeer *peer)
Definition: bgp_peer.cc:164
RibExportPolicy BuildRibExportPolicy(Address::Family family) const
Definition: bgp_peer.cc:243
void SetListenSocketAuthKey(const AuthenticationKey &auth_key, KeyType key_type)
Definition: bgp_peer.cc:880
std::map< Address::Family, const uint8_t * > FamilyToCapabilityMap
Definition: bgp_peer.h:386
uint64_t get_rx_update() const
Definition: bgp_peer.cc:2591
void inc_rx_keepalive()
Definition: bgp_peer.cc:2571
#define BGP_LOG_PEER_WARNING(type, peer, flags, dir, arg)
Definition: bgp_log.h:182
BgpGlobalQosConfig * global_qos()
Definition: bgp_server.h:294
void inc_connect_timer_expired()
Definition: bgp_peer.cc:2671
uint64_t get_socket_reads() const
Definition: bgp_peer.cc:2707
std::unique_ptr< DBRequestData > data
Definition: db_table.h:49
BgpAttrPtr ReplaceNexthopAndLocate(const BgpAttr *attr, const IpAddress &addr)
Definition: bgp_attr.cc:1413
bool resolve_paths_
Definition: bgp_peer.h:507
BgpAttrOrigin::OriginType origin
Definition: bgp_peer.h:383
virtual uint32_t bgp_identifier() const
Definition: bgp_peer.cc:1223
RoutingInstanceMgr * routing_instance_mgr()
Definition: bgp_server.h:102
virtual bool IsXmppPeer() const
Definition: bgp_peer.cc:1211
ProtoStats proto_stats_[2]
Definition: bgp_peer.cc:158
virtual void UpdateCloseRouteStats(Address::Family family, const BgpPath *old_path, uint32_t path_flags) const
Definition: bgp_peer.cc:1293
#define BGP_UVE_SEND(type, object)
Definition: bgp_log.h:46
bool Enqueue(DBRequest *req)
Definition: db_table.cc:194
time_t GetRTargetTableLastUpdatedTimeStamp() const
Definition: bgp_server.cc:1206
BgpServer * server_
Definition: bgp_peer.h:458
void inc_open_error()
Definition: bgp_peer.cc:2679
uint32_t local_bgp_id_
Definition: bgp_peer.h:522
static SandeshLevel::type LoggingLevel()
Definition: p/sandesh.h:221
std::vector< BgpAttribute * > BgpAttrSpec
Definition: bgp_attr.h:822
tbb::atomic< uint64_t > blocked_count
Definition: ipeer.h:119
bool IsRouterTypeBGPaaS() const
Definition: bgp_peer.h:358
const std::string & name() const
void inc_tx_open()
Definition: bgp_peer.cc:2567
void LocatePathResolver()
Definition: bgp_table.cc:1074
virtual bool CanUseMembershipManager() const
Definition: bgp_peer.cc:421
virtual IPeerClose * peer_close()
Definition: bgp_peer.cc:1285
std::string GetInuseAuthKeyValue() const
Definition: bgp_peer.cc:914
virtual bool Is4ByteAsSupported() const
Definition: bgp_peer.cc:1791
RoutingInstance * GetDefaultRoutingInstance()
virtual void SetDataCollectionKey(BgpPeerInfo *peer_info) const
Definition: bgp_peer.cc:2387
virtual string last_state_change_at() const
Definition: bgp_peer.cc:79
virtual void Register(IPeer *peer, BgpTable *table, const RibExportPolicy &policy, int instance_id=-1)
bool Empty() const
Definition: bgp_config.cc:106
as_t local_as_
Definition: bgp_peer.h:520
const Ip4Address & originator_id() const
Definition: bgp_attr.h:895
void ProcessEndpointConfig(const BgpNeighborConfig *config)
Definition: bgp_peer.cc:980
void SetRemovePrivatePolicy(bool all, bool replace, bool peer_loop_check)
void clear_session()
Definition: bgp_peer.cc:2231
const FamilyAttributesList & family_attributes_list() const
Definition: bgp_config.h:253
RoutingInstance * rtinstance_
Definition: bgp_peer.h:459
void set_peer(BgpPeer *peer)
Definition: bgp_session.cc:128
virtual BgpProto::BgpPeerType PeerType() const
Definition: bgp_peer.h:208
uint64_t get_tx_update() const
Definition: bgp_peer.cc:2599
int GetTaskInstance() const
Definition: bgp_peer.cc:2383
virtual bool send_ready() const
Definition: bgp_peer.h:229
virtual time_t GetEorSendTimerElapsedTime() const
Definition: bgp_peer.cc:310
void RetryDelete()
Definition: bgp_peer.cc:2377
void IncrementUpPeerCount()
Definition: bgp_server.h:245
AuthenticationKey inuse_auth_key_
Definition: bgp_peer.h:542
std::string router_type() const
Definition: bgp_config.h:222
virtual TcpSession * CreateSession()
virtual bool MembershipPathCallback(DBTablePartBase *tpart, BgpRoute *route, BgpPath *path)
Definition: bgp_peer.cc:458
void FillPeerMembershipInfo(const IPeer *peer, BgpNeighborResp *resp) const
uint64_t get_rx_notification() const
Definition: bgp_peer.cc:2607
int RegisterDSCPUpdateCallback(DSCPUpdateCb cb)
Definition: bgp_server.cc:902
virtual Address::Family family() const =0
virtual bool Send(const uint8_t *data, size_t size, size_t *sent)
Definition: tcp_session.cc:428
std::string private_as_action() const
Definition: bgp_config.h:190
virtual void Clear()
Definition: bgp_peer.cc:63
uint32_t as_t
Definition: bgp_common.h:21
static uint64_t get_value(const uint8_t *data, int size)
Definition: parse_object.h:39
std::string peer_name_
Definition: bgp_peer.h:463
boost::asio::ip::tcp::endpoint endpoint
Definition: bgp_peer_key.h:24
uint8_t loop_count() const
Definition: bgp_config.h:230
tbb::atomic< uint64_t > close
Definition: ipeer.h:57
bool defer_close_
Definition: bgp_peer.h:514
virtual const std::string & ToString() const
Definition: bgp_peer.h:100
bool KeepaliveTimerRunning()
Definition: bgp_peer.cc:2211
const BgpNeighborConfig * config_
Definition: bgp_peer.h:469
const std::string & last_event() const
static const int kMinMessageSize
Definition: bgp_proto.h:440
virtual std::string last_error() const =0
virtual void TriggerPrefixLimitCheck() const
Definition: bgp_peer.cc:988
static const int kEndOfRibSendRetryTime
Definition: bgp_peer.h:84
virtual bool MayDelete() const
Definition: bgp_peer.cc:169
int GetTaskId(const std::string &name)
Definition: task.cc:856
IpAddress gateway_address
Definition: bgp_peer.h:57
virtual string last_error() const
Definition: bgp_peer.cc:83
std::vector< std::string > KeysToStringDetail() const
Definition: bgp_config.cc:143
std::string type_name
Definition: parse_object.h:88
TaskTrigger prefix_limit_trigger_
Definition: bgp_peer.h:475
#define BGP_LOG_STR(obj, level, flags, arg)
Definition: bgp_log.h:89
void StartEndOfRibReceiveTimer(Address::Family family)
Definition: bgp_peer.cc:2151
void PostCloseRelease()
Definition: bgp_peer.cc:1187
void SendOpen(TcpSession *session)
Definition: bgp_peer.cc:1485
int IsAsPathLoop(as_t asn, uint8_t max_loop_count=0) const
Definition: bgp_attr.cc:1214
uint64_t get_tx_keepalive() const
Definition: bgp_peer.cc:2583
void inc_rx_route_unreach(uint64_t count)
Definition: bgp_peer.cc:2643
virtual void SetAdminState(bool down, int subcode=BgpProto::Notification::AdminShutdown)
Definition: bgp_peer.cc:1357
void ConfigUpdate(const BgpNeighborConfig *config)
Definition: bgp_peer.cc:992
std::vector< OptParam * > opt_params
Definition: bgp_proto.h:219
as_t local_autonomous_system() const
Definition: bgp_server.h:207
uint64_t get_rx_route_unreach() const
Definition: bgp_peer.cc:2647
BgpPeer(BgpServer *server, RoutingInstance *instance, const BgpNeighborConfig *config)
Definition: bgp_peer.cc:469
void set_observer(EventObserver observer)
Definition: tcp_session.cc:218
void DecrementUpPeerCount()
Definition: bgp_server.h:248
static const size_t kSize
Definition: rd.h:13
virtual BgpServer * server()
Definition: bgp_peer.h:157
tbb::atomic< uint64_t > primary_path_count
Definition: ipeer.h:94
void SetSendReady()
Definition: bgp_peer.cc:2216
BgpPeer * peer_
Definition: bgp_peer.cc:156
int hold_time() const
Definition: bgp_config.h:227
void KeepaliveTimerErrorHandler(std::string error_name, std::string error_message)
Definition: bgp_peer.cc:2164
bool IsCloseInProgress() const
Definition: bgp_peer.cc:1322
#define BGP_LOG_PEER_CRITICAL(type, peer, flags, dir, arg)
Definition: bgp_log.h:194
virtual uint64_t num_flaps() const =0
uint32_t peer_as() const
Definition: bgp_config.h:198
StateMachine * state_machine()
Definition: bgp_peer.h:326
bool EndOfRibReceiveTimerExpired(Address::Family family)
Definition: bgp_peer.cc:2170
boost::intrusive_ptr< const BgpAttr > BgpAttrPtr
Definition: bgp_attr.h:991
void reset_flap_count()
Definition: bgp_peer.cc:2747
uint16_t source_port() const
Definition: bgp_config.h:219
Timer * eor_send_timer_[Address::NUM_FAMILIES]
Definition: bgp_peer.h:502
uint32_t GetEndOfRibReceiveTime() const
Definition: bgp_server.cc:714
virtual void UpdateTxUnreachRoute(uint64_t count)
Definition: bgp_peer.cc:136
bool test_mode() const
Definition: bgp_sandesh.h:61
static BgpMessage * Decode(const uint8_t *data, size_t size, ParseErrorContext *ec=NULL, bool as4=false)
Definition: bgp_proto.cc:2087
void SetSessionSocketAuthKey(TcpSession *session)
Definition: bgp_peer.cc:894
const std::string last_state_change_at() const
virtual void GetRxSocketStats(IPeerDebugStats::SocketStats *stats) const
Definition: bgp_peer.cc:117
std::vector< std::string > default_tunnel_encap_list
Definition: bgp_config.h:99
bool IsCloseGraceful() const
Definition: bgp_peer.cc:323
void ProcessUpdate(const BgpProto::Update *msg, size_t msgsize=0)
Definition: bgp_peer.cc:1879
static Safi FamilyToSafi(Address::Family family)
Definition: bgp_af.cc:188
#define BGP_LOG_FLAG_SYSLOG
Definition: bgp_log.h:42
std::vector< BgpProtoPrefix * > withdrawn_routes
Definition: bgp_proto.h:434
uint8_t type
Definition: load_balance.h:109
as_t peer_as_
Definition: bgp_peer.h:521
static const std::string integerToString(const NumberType &num)
Definition: string_util.h:19
static bool SkipUpdateSend()
Definition: bgp_peer.cc:1580
void inc_rx_route_reach(uint64_t count)
Definition: bgp_peer.cc:2631
std::string router_type_
Definition: bgp_peer.h:465
const AsPath4Byte * aspath_4byte() const
Definition: bgp_attr.h:902
uint64_t get_rx_end_of_rib() const
Definition: bgp_peer.cc:2619
void RoutingInstanceCallback(const std::string &vrf_name, int op)
Definition: bgp_peer.cc:779
void Register(BgpTable *table, const RibExportPolicy &policy)
Definition: bgp_peer.cc:1381
uint32_t cluster_id_
Definition: bgp_peer.h:510
void RegisterAllTables()
Definition: bgp_peer.cc:1432
static int Encode(const BgpMessage *msg, uint8_t *data, size_t size, EncodeOffsets *offsets=NULL, bool as4=false)
Definition: bgp_proto.cc:2107
BgpTable * GetRTargetTable()
Definition: bgp_peer.cc:694
void SendNotification(BgpSession *, int code, int subcode=0, const std::string &data=std::string())
Definition: bgp_peer.cc:1683
const std::vector< std::string > & negotiated_families() const
Definition: bgp_peer.h:342
void increment_deleting_bgpaas_count()
Definition: bgp_server.h:232
const ClusterList * cluster_list() const
Definition: bgp_attr.h:907
tbb::atomic< uint64_t > notification
Definition: ipeer.h:55
iterator begin()
Definition: bgp_config.h:50
const ExtCommunityList & communities() const
Definition: community.h:180
static std::string OriginToString(BgpAttrOrigin::OriginType origin)
Definition: bgp_attr.cc:1095
void SetInuseAuthKeyInfo(const AuthenticationKey &key, KeyType type)
Definition: bgp_peer.cc:870
virtual bool FlushUpdate()
Definition: bgp_peer.cc:1658
bool as_override() const
Definition: bgp_config.h:187
static TaskScheduler * GetInstance()
Definition: task.cc:547
const std::string & peer_name() const
Definition: bgp_peer.h:168
Event
Definition: http_client.h:27
virtual time_t GetRTargetTableLastUpdatedTimeStamp() const
Definition: bgp_peer.cc:327
BgpSession * session_
Definition: bgp_peer.h:499
BgpSession * CreateSession()
Definition: bgp_peer.cc:1340
bool AsLeftMostMatch(as2_t as) const
Definition: bgp_aspath.cc:34
bool SetCapabilities(const BgpProto::OpenMessage *msg)
Definition: bgp_peer.cc:1691
virtual void GetTxSocketStats(SocketStats *stats) const =0
boost::intrusive_ptr< const ExtCommunity > ExtCommunityPtr
Definition: community.h:448
virtual IPeerDebugStats * peer_stats()
Definition: bgp_peer.cc:1298
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:15
void inc_tx_update()
Definition: bgp_peer.cc:2595
BgpAttrPtr ReplaceSubProtocolAndLocate(const BgpAttr *attr, const std::string &sbp)
Definition: bgp_attr.cc:1396
std::string last_flap_at() const
Definition: bgp_peer.cc:2719
void RegisterRibIn(IPeer *peer, BgpTable *table)
std::unique_ptr< DBRequestKey > key
Definition: db_table.h:48
KeyType inuse_authkey_type_
Definition: bgp_peer.h:543
bool as4_supported_
Definition: bgp_peer.h:516
virtual string ToString() const
Definition: bgp_peer.cc:72
uint64_t get_tx_route_total() const
Definition: bgp_peer.cc:2661
#define BGP_PEER_DIR_OUT
Definition: bgp_log.h:138
int RegisterASNUpdateCallback(ASNUpdateCb callback)
Definition: bgp_server.cc:857
Timer * eor_receive_timer_[Address::NUM_FAMILIES]
Definition: bgp_peer.h:501
DBOperation oper
Definition: db_table.h:42
tbb::atomic< uint64_t > reach
Definition: ipeer.h:106
BgpAttrPtr ReplaceLocalPreferenceAndLocate(const BgpAttr *attr, uint32_t local_pref)
Definition: bgp_attr.cc:1346
void LogInstallAuthKeys(const std::string &socket_name, const std::string &oper, const AuthenticationKey &auth_key, KeyType key_type)
Definition: bgp_peer.cc:918
std::string BytesToHexString(const u_int8_t *msg, size_t size)
Definition: bgp_peer.cc:2245
#define CHECK_CONCURRENCY(...)
static boost::posix_time::ptime UTCUsecToPTime(uint64_t tusec)
Definition: time_util.h:38
virtual string last_flap() const
Definition: bgp_peer.cc:92
virtual void StartKeepaliveTimerUnlocked()
Definition: bgp_peer.cc:2191
const string MatchProtocolToString(MatchProtocol::MatchProtocolType protocol)
virtual const std::string GetStateName() const
Definition: bgp_peer.cc:1336
void ResetInuseAuthKeyInfo()
Definition: bgp_peer.cc:875
as_t local_as() const
Definition: bgp_peer.h:183
RoutingInstance * GetRoutingInstance()
Definition: bgp_peer.h:202
FamilyAttributesList family_attributes_list_
Definition: bgp_peer.h:524
void set_session(BgpSession *session)
Definition: bgp_peer.cc:2225
virtual bool MpNlriAllowed(uint16_t afi, uint8_t safi)
Definition: bgp_peer.cc:1776
BgpSessionManager * session_manager()
Definition: bgp_server.h:97
boost::scoped_ptr< PeerStats > peer_stats_
Definition: bgp_peer.h:532
boost::scoped_ptr< PeerCloseManager > close_manager_
Definition: bgp_peer.h:531
void SetSessionSocketOptionDscp(TcpSession *session)
Definition: bgp_peer.cc:903
const AuthenticationData & auth_data() const
Definition: bgp_config.h:244
static std::string ToString(uint16_t afi, uint8_t safi)
Definition: bgp_af.cc:14
Timer * keepalive_timer_
Definition: bgp_peer.h:500
void ManagedDelete()
Definition: bgp_peer.cc:2364
uint64_t get_tx_route_unreach() const
Definition: bgp_peer.cc:2651
bool PrefixLimitIdleTimerRunning() const
Definition: bgp_peer.cc:2110
std::string gateway_address_string(Address::Family family) const
Definition: bgp_peer.cc:1240
virtual uint32_t GetOutputQueueDepth(Address::Family family) const
Definition: bgp_peer.cc:305
tbb::spin_mutex spin_mutex_
Definition: bgp_peer.h:496
uint32_t PeerAddress() const
Definition: bgp_peer.h:160
void NotifyEstablished(bool established)
Definition: bgp_peer.cc:798
void decrement_deleting_count()
Definition: bgp_server.h:225
virtual ~BgpPeer()
Definition: bgp_peer.cc:625
#define BGP_LOG_WARNING_STR(obj, flags, arg)
Definition: bgp_log.h:107
uint32_t local_as() const
Definition: bgp_config.h:233
BgpAttrPtr GetRouteTargetRouteAttr() const
Definition: bgp_peer.cc:704
virtual void GetTxProtoStats(ProtoStats *stats) const
Definition: bgp_peer.cc:105
void inc_tx_keepalive()
Definition: bgp_peer.cc:2579
static Timer * CreateTimer(boost::asio::io_context &service, const std::string &name, int task_id=Timer::GetTimerTaskId(), int task_instance=Timer::GetTimerInstanceId(), bool delete_on_completion=false)
Definition: timer.cc:201
tbb::atomic< uint64_t > total_path_count
Definition: ipeer.h:93
std::string router_type() const
Definition: bgp_peer.h:170
virtual void GetRxProtoStats(ProtoStats *stats) const
Definition: bgp_peer.cc:101
BgpAttrPtr ReplaceOriginAndLocate(const BgpAttr *attr, BgpAttrOrigin::OriginType origin)
Definition: bgp_attr.cc:1322
virtual const std::string & ToUVEKey() const
Definition: bgp_peer.h:101
bool AsLeftMostMatch(as_t as) const
Definition: bgp_aspath.cc:296
tbb::atomic< uint64_t > end_of_rib
Definition: ipeer.h:104
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
static std::pair< uint16_t, uint8_t > FamilyToAfiSafi(Address::Family family)
Definition: bgp_af.cc:130
const AsPath * as_path() const
Definition: bgp_attr.h:899
std::string value
Definition: bgp_config.h:35
uint32_t cluster_id() const
Definition: bgp_config.h:195
int SetListenSocketMd5Option(uint32_t peer_ip, const std::string &md5_password)
Definition: tcp_server.cc:517
bool Cancel()
Definition: timer.cc:150
virtual void SendEndOfRIB(Address::Family family)
Definition: bgp_peer.cc:404
int STLSortedCompare(InputIterator first1, InputIterator last1, InputIterator first2, InputIterator last2, CompareOp op)
Definition: util.h:78
AddressFamilyList GetAddressFamilies() const
Definition: bgp_config.cc:283
bool PrefixLimitIdleTimerExpired()
Definition: bgp_peer.cc:2114
bool ResumeClose()
Definition: bgp_peer.cc:463
Timer * prefix_limit_idle_timer_
Definition: bgp_peer.h:474
virtual string last_state() const
Definition: bgp_peer.cc:76
void UnregisterDSCPUpdateCallback(int listener)
Definition: bgp_server.cc:918
std::vector< std::string > default_tunnel_encap_list
Definition: bgp_peer.h:58
bool admin_down_
Definition: bgp_peer.h:505
static Afi FamilyToAfi(Address::Family family)
Definition: bgp_af.cc:159
virtual bool SendUpdate(const uint8_t *msg, size_t msgsize, const std::string *msg_str)
static std::string FamilyToString(Family fmly)
Definition: address.cc:63
bool passive_
Definition: bgp_peer.h:506
boost::asio::io_context * ioservice()
Definition: bgp_server.cc:682
void inc_update_error()
Definition: bgp_peer.cc:2683
uint32_t GetEndOfRibReceiveTime(Address::Family family) const
Definition: bgp_peer.cc:314
void Close(bool graceful)
Definition: bgp_peer.cc:1269
void FillNeighborInfo(const BgpSandeshContext *bsc, BgpNeighborResp *bnr, bool summary) const
Definition: bgp_peer.cc:2504
virtual void UpdateRouteStats(Address::Family family, const BgpPath *old_path, uint32_t path_flags) const =0
#define BGP_UVE_SEND2(type, object, arg)
Definition: bgp_log.h:52
StateMachine::State GetState() const
Definition: bgp_peer.cc:1332
const std::string peer_address_string() const
Definition: bgp_peer.h:161
uint32_t bgp_identifier() const
Definition: bgp_server.h:208
const io::SocketStats & GetSocketStats() const
Definition: tcp_session.h:162
void BGPaaSAddRTarget(as_t as, BgpTable *table, BgpAttrPtr attr, RouteTargetList::const_iterator it)
Definition: bgp_peer.cc:714
uint64_t get_hold_timer_expired() const
Definition: bgp_peer.cc:2695
uint32_t GetEndOfRibSendTime() const
Definition: bgp_server.cc:718
void clear_peer()
Definition: bgp_session.cc:138
void RegisterToVpnTables()
Definition: bgp_peer.cc:2130
const ExtCommunity * ext_community() const
Definition: bgp_attr.h:915
uint64_t get_rx_route_total() const
Definition: bgp_peer.cc:2655
int index_
Definition: bgp_peer.h:472
uint64_t get_rx_keepalive() const
Definition: bgp_peer.cc:2575
TaskTrigger trigger_
Definition: bgp_peer.h:473
time_t eor_send_timer_start_time_
Definition: bgp_peer.h:503
static time_t UTCTimestamp()
Definition: time_util.h:23
const IpAddress & gateway_address(Address::Family family) const
Definition: bgp_config.cc:262
#define BGP_TRACE_PEER_PACKET(peer, msg, size, level)
Definition: bgp_log.h:310
void inc_rx_end_of_rib()
Definition: bgp_peer.cc:2615
uint8_t safi
Definition: bgp_attr.h:308
const AsPath4ByteSpec & path() const
Definition: bgp_aspath.h:285
#define BGP_LOG_FLAG_TRACE
Definition: bgp_log.h:43
BgpAttrDB * attr_db()
Definition: bgp_server.h:181
virtual std::string last_flap() const =0
void inc_connect_error()
Definition: bgp_peer.cc:2667
bool peer_is_control_node_
Definition: bgp_peer.h:466
static uint64_t UTCTimestampUsec()
Definition: time_util.h:13
std::vector< tbb::atomic< uint32_t > > family_primary_path_count_
Definition: bgp_peer.h:525
virtual void Shutdown()
Definition: bgp_peer.cc:182
static void FillSocketStats(const IPeerDebugStats::SocketStats &socket_stats, PeerSocketStats *peer_socket_stats)
Definition: bgp_peer.cc:2416
void StartKeepaliveTimer()
Definition: bgp_peer.cc:2201
void UnregisterPeer(BgpPeer *peer)
Definition: bgp_server.cc:602
bool GetBestAuthKey(AuthenticationKey *auth_key, KeyType *key_type) const
Definition: bgp_peer.cc:819
void ClearListenSocketAuthKey()
Definition: bgp_peer.cc:888
UpdateStats update_stats_[2]
Definition: bgp_peer.cc:159
std::vector< uint8_t > buffer_
Definition: bgp_peer.h:498
const bytes_type & GetExtCommunity() const
Definition: tunnel_encap.h:28
std::vector< ExtCommunityValue > ExtCommunityList
Definition: community.h:153
ExtCommunityPtr ReplaceTunnelEncapsulationAndLocate(const ExtCommunity *src, const ExtCommunity::ExtCommunityList &tunnel_encaps)
Definition: community.cc:899
static const size_t kMaxBufferCapacity
Definition: bgp_peer.h:87
virtual bool IsServerStartingUp() const
Definition: bgp_peer.cc:319
virtual void GetRxRouteUpdateStats(UpdateStats *stats) const
Definition: bgp_peer.cc:109
virtual void SendEndOfRIBActual(Address::Family family)
Definition: bgp_peer.cc:279
static bool is_tunnel_encap(const ExtCommunityValue &val)
Definition: community.h:366
void inc_hold_timer_expired()
Definition: bgp_peer.cc:2675
bool Start(int time, Handler handler, ErrorHandler error_handler=NULL)
Definition: timer.cc:108
virtual int GetTotalPathCount() const
Definition: bgp_peer.h:313
std::vector< Capability * > capabilities
Definition: bgp_proto.h:217
int SetDscpSocketOption(uint8_t value)
Definition: tcp_session.cc:569
void StartPrefixLimitIdleTimer(uint32_t plim_idle_time_msecs)
Definition: bgp_peer.cc:2100
uint16_t peer_port_
Definition: bgp_peer.h:462
uint64_t get_connect_error() const
Definition: bgp_peer.cc:2687
Endpoint remote_endpoint() const
Definition: tcp_session.h:135
virtual bool IsReady() const
Definition: bgp_peer.cc:1207
void BGPaaSDeleteRTarget(as_t as, BgpTable *table, RouteTargetList::const_iterator it)
Definition: bgp_peer.cc:742
uint64_t get_connect_timer_expired() const
Definition: bgp_peer.cc:2691
void FillCloseInfo(BgpNeighborResp *resp) const
Definition: bgp_peer.cc:2436
void MembershipRequestCallback(BgpTable *table)
Definition: bgp_peer.cc:430
bool ProcessFamilyAttributesConfig(const BgpNeighborConfig *config)
Definition: bgp_peer.cc:958
std::string to_str_
Definition: bgp_peer.h:467
virtual void GetRxProtoStats(ProtoStats *stats) const =0
tbb::atomic< uint64_t > open
Definition: ipeer.h:53
uint64_t last_flap_
Definition: bgp_peer.h:539
tbb::atomic< uint64_t > keepalive
Definition: ipeer.h:54
void IncrementUpBgpaasPeerCount()
Definition: bgp_server.h:255
tbb::atomic< uint64_t > update
Definition: ipeer.h:56
void ProcessNlri(Address::Family family, DBRequest::DBOperation oper, const BgpMpNlri *nlri, BgpAttrPtr attr, uint32_t flags)
Definition: bgp_peer.cc:1796
virtual void GetTxRouteUpdateStats(UpdateStats *stats) const
Definition: bgp_peer.cc:113
bool enable_4byte_as() const
Definition: bgp_server.cc:726
virtual string last_event() const
Definition: bgp_peer.cc:87
static const std::vector< Address::Family > supported_families_
Definition: bgp_peer.h:457
as_t peer_as() const
Definition: bgp_peer.h:184
virtual std::string last_state() const =0
std::string uve_key_str_
Definition: bgp_peer.h:468
bool passive() const
Definition: bgp_config.h:184
void ReceiveEndOfRIB(Address::Family family, size_t msgsize)
Definition: bgp_peer.cc:270
static const int kDefaultPort
Definition: bgp_config.h:766
virtual void BindLocalEndpoint(BgpSession *session)
Definition: bgp_peer.cc:815
BgpMembershipManager * membership_mgr()
Definition: bgp_server.h:173
bool running() const
Definition: timer.h:86
bool as_override_
Definition: bgp_peer.h:508
bool EndOfRibSendTimerExpired(Address::Family family)
Definition: bgp_peer.cc:331
TcpSession::Endpoint endpoint_
Definition: bgp_peer.h:460
virtual std::string ToString() const
Definition: bgp_server.cc:556
tbb::atomic< int > total_path_count_
Definition: bgp_peer.h:535
static void FillBgpNeighborDebugState(BgpNeighborResp *bnr, const IPeerDebugStats *peer)
Definition: bgp_peer.cc:2440
void set_ext_community(ExtCommunityPtr extcomm)
Definition: bgp_attr.cc:1011
RouteTargetList rtargets_
Definition: bgp_peer.h:544
bool AttemptGRHelperMode(int code, int subcode) const
Definition: bgp_peer.cc:1668
bool IsFamilyNegotiated(Address::Family family)
Definition: bgp_peer.cc:1174
virtual void GetTxProtoStats(ProtoStats *stats) const =0
bool send_ready_
Definition: bgp_peer.h:504
KeyType key_type() const
Definition: bgp_config.h:70
AuthenticationData auth_data_
Definition: bgp_peer.h:541
uint64_t total_flap_count_
Definition: bgp_peer.h:538
BgpPeerKey peer_key_
Definition: bgp_peer.h:461
uint64_t get_tx_route_reach() const
Definition: bgp_peer.cc:2639
BgpProto::BgpPeerType peer_type_
Definition: bgp_peer.h:528
std::string transport_address_string() const
Definition: bgp_peer.cc:1231
bool ClusterListLoop(uint32_t cluster_id) const
Definition: bgp_attr.cc:223
std::vector< uint8_t > nexthop
Definition: bgp_attr.h:309
void ClearConfig()
Definition: bgp_peer.cc:1162
uint32_t cluster_id() const
Definition: bgp_server.h:203
uint32_t local_identifier() const
Definition: bgp_config.h:236
bool Reschedule(int time)
Definition: timer.cc:137
const BgpNeighborConfig * config() const
Definition: bgp_peer.h:213
Definition: timer.h:54
void SendNotification(int code, int subcode, const std::string &data=std::string())
Definition: bgp_session.cc:112
tbb::atomic< uint64_t > calls
Definition: ipeer.h:117
virtual std::string last_state_change_at() const =0
std::string bgp_identifier_string() const
Definition: bgp_peer.cc:1227
std::vector< BgpProto::OpenMessage::Capability * > capabilities_
Definition: bgp_peer.h:518
void DeleteRTargets(as_t as)
Definition: bgp_peer.cc:755
static SandeshLevel::type LoggingUtLevel()
Definition: p/sandesh.h:222
ErrorStats error_stats_
Definition: bgp_peer.cc:157
void decrement_deleting_bgpaas_count()
Definition: bgp_server.h:233
static Ip4Address V4FromV4MappedV6(const Ip6Address &v6_address)
Definition: address.cc:291
virtual Socket * socket() const
Definition: tcp_session.h:86
virtual bool notification() const
Definition: bgp_peer.cc:1663
uint64_t get_socket_writes() const
Definition: bgp_peer.cc:2713
bool IsDeleted() const
Definition: bgp_peer.cc:1314
virtual void ProcessPathTunnelEncapsulation(const BgpPath *path, BgpAttr *attr, ExtCommunityDB *extcomm_db, const BgpTable *table) const
Definition: bgp_peer.cc:2054
tbb::atomic< int > membership_req_pending_
Definition: bgp_peer.h:513
int SetMd5SocketOption(uint32_t peer_ip, const std::string &md5_password)
Definition: tcp_session.cc:559
void ASNUpdateCallback(as_t old_asn, as_t old_local_asn)
Definition: bgp_peer.cc:768
bool graceful_close_
Definition: bgp_peer.h:515
void DSCPUpdateCallback(uint8_t dscp_value)
Definition: bgp_peer.cc:2771
TcpSession::Endpoint endpoint() const
Definition: bgp_peer.h:171
#define AS_TRANS
Definition: bgp_common.h:23
virtual bool CheckSplitHorizon(uint32_t cluster_id=0, uint32_t ribout_cid=0) const
Definition: bgp_peer.cc:677
void CustomClose()
Definition: bgp_peer.cc:1251
uint64_t get_tx_end_of_rib() const
Definition: bgp_peer.cc:2627
bool CheckPrefixLimits()
Definition: bgp_peer.cc:934
virtual void DestroyIPeer(IPeer *ipeer)
BgpSession * session()
Definition: bgp_peer.cc:2241
uint64_t get_update_error() const
Definition: bgp_peer.cc:2703
tbb::atomic< uint64_t > blocked_duration_usecs
Definition: ipeer.h:120
uint32_t GetRibOutQueueDepth(const IPeer *peer, const BgpTable *table) const
LifetimeActor * deleter()
Definition: bgp_peer.cc:1167
int instance_op_
Definition: bgp_peer.h:546
virtual void GetRxErrorStats(RxErrorStats *stats) const
Definition: bgp_peer.cc:145
string private_as_action_
Definition: bgp_peer.h:509
uint32_t GetPathFlags(Address::Family family, const BgpAttr *attr) const
Definition: bgp_peer.cc:1829
BgpPeerFamilyAttributes(const BgpNeighborConfig *config, const BgpFamilyAttributesConfig &family_config)
Definition: bgp_peer.cc:222
bool vpn_tables_registered_
Definition: bgp_peer.h:517
int HardwareThreadCount()
Definition: task.h:276
size_t buffer_capacity_
Definition: bgp_peer.h:497
void Clear(int subcode)
Definition: bgp_peer.cc:1306
int asn_listener_id_
Definition: bgp_peer.h:545
tbb::atomic< uint64_t > bytes
Definition: ipeer.h:118
PeerStats(BgpPeer *peer)
Definition: bgp_peer.cc:56
std::vector< BgpAttribute * > path_attributes
Definition: bgp_proto.h:435
#define BGP_PEER_DIR_IN
Definition: bgp_log.h:139
void increment_flap_count()
Definition: bgp_peer.cc:2727
virtual void GetRxRouteUpdateStats(UpdateStats *stats) const =0
void inc_rx_open()
Definition: bgp_peer.cc:2563
int membership_req_pending() const
Definition: bgp_peer.h:366
virtual void Destroy()
Definition: bgp_peer.cc:187
#define BGP_LOG_FLAG_ALL
Definition: bgp_log.h:44
static bool DeleteTimer(Timer *Timer)
Definition: timer.cc:222
virtual void UpdatePrimaryPathCount(int count, Address::Family family) const
Definition: bgp_peer.cc:2088
#define BGP_LOG_PEER(type, peer, level, flags, dir, arg)
Definition: bgp_log.h:159
void SendKeepalive(bool from_timer)
Definition: bgp_peer.cc:1561
static const int kRouteTargetEndOfRibTimeSecs
Definition: bgp_peer.h:85
#define BGP_PEER_DIR_NA
Definition: bgp_log.h:140
std::string local_bgp_identifier_string() const
Definition: bgp_peer.cc:1219
uint16_t hold_time_
Definition: bgp_peer.h:519
bool operator!=(const OriginOverride &rhs) const
Definition: bgp_peer.cc:1598
const std::string & localname() const
Definition: bgp_server.cc:678
static std::string UTCUsecToString(uint64_t tstamp)
Definition: time_util.h:54
virtual void GetTxSocketStats(IPeerDebugStats::SocketStats *stats) const
Definition: bgp_peer.cc:125