OpenSDN source code
bgp_peer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef SRC_BGP_BGP_PEER_H__
6 #define SRC_BGP_BGP_PEER_H__
7 
8 #include <boost/asio/ip/tcp.hpp>
9 #include <boost/scoped_ptr.hpp>
10 #include <tbb/spin_mutex.h>
11 
12 #include <map>
13 #include <memory>
14 #include <set>
15 #include <string>
16 #include <vector>
17 
18 #include "base/lifetime.h"
19 #include "base/util.h"
20 #include "base/task_trigger.h"
21 #include "base/timer.h"
22 #include "base/address.h"
23 #include "bgp/bgp_config.h"
24 #include "bgp/bgp_debug.h"
25 #include "bgp/bgp_peer_key.h"
26 #include "bgp/bgp_proto.h"
27 #include "bgp/bgp_rib_policy.h"
28 #include "bgp/ipeer.h"
30 #include "bgp/state_machine.h"
31 #include "db/db_table.h"
32 
33 class BgpNeighborConfig;
34 class BgpPeerClose;
35 class BgpPeerInfo;
36 class BgpPeerInfoData;
37 class BgpServer;
38 class BgpSession;
39 class BgpSession;
40 class BgpNeighborResp;
41 class BgpSandeshContext;
42 class PeerCloseManager;
43 class RoutingInstance;
44 
45 //
46 // This contains per address family attributes.
47 // A BgpPeer contains a vector of pointers to this structure, with an entry
48 // for each value in Address::Family i.e. the vector can be indexed using a
49 // Address::Family value.
50 //
53  const BgpFamilyAttributesConfig &family_config);
54  uint8_t loop_count;
55  uint32_t prefix_limit;
56  uint32_t idle_timeout;
58  std::vector<std::string> default_tunnel_encap_list;
59 };
60 
61 //
62 // Comparator for BgpPeerFamilyAttributes.
63 //
66  const BgpPeerFamilyAttributes *rhs) const {
67  if (lhs && rhs) {
68  KEY_COMPARE(lhs->loop_count, rhs->loop_count);
74  } else {
75  KEY_COMPARE(lhs, rhs);
76  }
77  return 0;
78  }
79 };
80 
81 // A BGP peer along with its session and state machine.
82 class BgpPeer : public IPeer {
83 public:
84  static const int kEndOfRibSendRetryTime = 1; /* seconds */
85  static const int kRouteTargetEndOfRibTimeSecs = 30; // Seconds
86  static const size_t kMinBufferCapacity = 4096;
87  static const size_t kMaxBufferCapacity = 32768;
88 
89  typedef std::set<Address::Family> AddressFamilyList;
91  typedef std::set<RouteTarget> RouteTargetList;
92 
94  const BgpNeighborConfig *config);
95  virtual ~BgpPeer();
96 
97  // Interface methods
98 
99  // thread-safe
100  virtual const std::string &ToString() const { return to_str_; }
101  virtual const std::string &ToUVEKey() const { return uve_key_str_; }
102 
103  // Task: bgp::SendUpdate
104  // Used to send an UPDATE message on the socket.
105  virtual bool SendUpdate(const uint8_t *msg, size_t msgsize,
106  const std::string *msg_str);
107  virtual bool SendUpdate(const uint8_t *msg, size_t msgsize) {
108  return SendUpdate(msg, msgsize, NULL);
109  }
110  virtual bool FlushUpdate();
111 
112  // Task: bgp::Config
114  void ClearConfig();
115 
116  // thread: event manager thread.
117  // Invoked from BgpServer when a session is accepted.
119 
121 
122  virtual void SetAdminState(bool down,
124 
125  // Messages
126 
127  // thread: bgp::StateMachine
128  void SendOpen(TcpSession *session);
129 
130  // thread: bgp::StateMachine, KA timer handler
131  void SendKeepalive(bool from_timer);
132 
133  // thread: bgp::StateMachine, io::ReaderTask
134  void SendNotification(BgpSession *, int code, int subcode = 0,
135  const std::string &data = std::string());
136 
137  // thread: io::ReaderTask
138  void ProcessUpdate(const BgpProto::Update *msg, size_t msgsize = 0);
139 
140  // thread: io::ReaderTask
141  virtual bool ReceiveMsg(BgpSession *session, const u_int8_t *msg,
142  size_t size);
143 
144  void StartKeepaliveTimer();
145  bool KeepaliveTimerRunning();
146  bool PrefixLimitIdleTimerRunning() const;
147  void SetSendReady();
148 
149  // thread: io::ReaderTask
150  bool SetCapabilities(const BgpProto::OpenMessage *msg);
151  void ResetCapabilities();
152 
153  // Table registration.
154  void RegisterAllTables();
155 
156  // accessors
157  virtual BgpServer *server() { return server_; }
158  virtual BgpServer *server() const { return server_; }
159 
160  uint32_t PeerAddress() const { return peer_key_.address(); }
161  const std::string peer_address_string() const {
162  return peer_key_.endpoint.address().to_string();
163  }
164  const BgpPeerKey &peer_key() const { return peer_key_; }
165  uint16_t peer_port() const { return peer_port_; }
166  std::string transport_address_string() const;
167  std::string gateway_address_string(Address::Family family) const;
168  const std::string &peer_name() const { return peer_name_; }
169  const std::string &peer_basename() const { return peer_basename_; }
170  std::string router_type() const { return router_type_; }
172  virtual bool CheckSplitHorizon(uint32_t cluster_id = 0,
173  uint32_t ribout_cid = 0) const;
174 
176  virtual const std::string GetStateName() const;
177 
179  void clear_session();
180  BgpSession *session();
181 
182  uint16_t hold_time() const { return hold_time_; }
183  as_t local_as() const { return local_as_; }
184  as_t peer_as() const { return peer_as_; }
185  size_t buffer_size() const { return buffer_.size(); }
186 
187  // The BGP Identifier in host byte order.
188  virtual uint32_t local_bgp_identifier() const;
189  std::string local_bgp_identifier_string() const;
190  virtual uint32_t bgp_identifier() const;
191  std::string bgp_identifier_string() const;
192 
193  const std::vector<std::string> &configured_families() const {
194  return configured_families_;
195  }
196 
198  return (family_attributes_list_[family] != NULL);
199  }
200 
201  bool IsFamilyNegotiated(Address::Family family);
204 
205  int GetIndex() const { return index_; }
206  int GetTaskInstance() const;
207 
208  virtual BgpProto::BgpPeerType PeerType() const {
209  return peer_type_;
210  }
211  const string &private_as_action() const { return private_as_action_; }
212 
213  const BgpNeighborConfig *config() const { return config_; }
214 
215  virtual void SetDataCollectionKey(BgpPeerInfo *peer_info) const;
216  void FillNeighborInfo(const BgpSandeshContext *bsc, BgpNeighborResp *bnr,
217  bool summary) const;
218 
219  // thread-safe
220  bool IsDeleted() const;
221  bool IsAdminDown() const { return admin_down_; }
222  bool IsPassive() const { return passive_; }
223  bool IsCloseInProgress() const;
224  virtual bool IsReady() const;
225  virtual bool IsXmppPeer() const;
226  virtual bool CanUseMembershipManager() const;
227  virtual bool IsRegistrationRequired() const { return true; }
228  virtual time_t GetEorSendTimerElapsedTime() const;
229  virtual bool send_ready() const { return send_ready_; }
230 
231  void Close(bool graceful);
232  void Clear(int subcode);
233 
234  virtual IPeerClose *peer_close();
235  virtual IPeerClose *peer_close() const;
236  virtual void UpdateCloseRouteStats(Address::Family family,
237  const BgpPath *old_path, uint32_t path_flags) const;
238  virtual IPeerDebugStats *peer_stats();
239  virtual const IPeerDebugStats *peer_stats() const;
240  void ManagedDelete();
241  void RetryDelete();
243  void Initialize();
244 
245  void NotifyEstablished(bool established);
246 
247  void increment_flap_count();
248  void reset_flap_count();
249  uint64_t flap_count() const { return flap_count_; }
250  uint64_t last_flap() const { return last_flap_; }
251  uint64_t total_flap_count() const { return total_flap_count_; }
252 
253  void DSCPUpdateCallback(uint8_t dscp_value);
254 
255  std::string last_flap_at() const;
256 
257  void inc_rx_open();
258  void inc_rx_keepalive();
259  void inc_rx_update();
260  void inc_rx_notification();
261 
262  void inc_tx_open();
263  void inc_tx_keepalive();
264  void inc_tx_update();
265  void inc_tx_notification();
266 
267  void inc_rx_end_of_rib();
268  void inc_rx_route_reach(uint64_t count);
269  void inc_rx_route_unreach(uint64_t count);
270 
271  void inc_tx_end_of_rib();
272 
273  uint64_t get_rx_keepalive() const;
274  uint64_t get_rx_update() const;
275  uint64_t get_rx_notification() const;
276  uint64_t get_tx_keepalive() const;
277  uint64_t get_tx_update() const;
278 
279  uint64_t get_rx_end_of_rib() const;
280  uint64_t get_rx_route_reach() const;
281  uint64_t get_rx_route_unreach() const;
282  uint64_t get_rx_route_total() const;
283 
284  uint64_t get_tx_end_of_rib() const;
285  uint64_t get_tx_route_reach() const;
286  uint64_t get_tx_route_unreach() const;
287  uint64_t get_tx_route_total() const;
288 
289  void inc_connect_error();
291  void inc_hold_timer_expired();
292  void inc_open_error();
293  void inc_update_error();
294 
295  uint64_t get_connect_error() const;
296  uint64_t get_connect_timer_expired() const;
297  uint64_t get_hold_timer_expired() const;
298  uint64_t get_open_error() const;
299  uint64_t get_update_error() const;
300 
301  uint64_t get_socket_reads() const;
302  uint64_t get_socket_writes() const;
303 
304  static void FillBgpNeighborDebugState(BgpNeighborResp *bnr,
305  const IPeerDebugStats *peer);
306 
307  bool ResumeClose();
308  void MembershipRequestCallback(BgpTable *table);
309 
310  virtual void UpdateTotalPathCount(int count) const {
311  total_path_count_ += count;
312  }
313  virtual int GetTotalPathCount() const { return total_path_count_; }
314  virtual bool IsAs4Supported() const { return as4_supported_; }
315  virtual void ResetAs4Supported() { as4_supported_ = false; }
316  virtual void UpdatePrimaryPathCount(int count,
317  Address::Family family) const;
318  virtual void ProcessPathTunnelEncapsulation(const BgpPath *path,
319  BgpAttr *attr, ExtCommunityDB *extcomm_db, const BgpTable *table) const;
320  virtual const std::vector<std::string> GetDefaultTunnelEncap(
321  const Address::Family family) const;
322  virtual int GetPrimaryPathCount() const { return primary_path_count_; }
323 
324  void RegisterToVpnTables();
325 
327  const StateMachine *state_machine() const { return state_machine_.get(); }
328 
330  bool InstallAuthKeys();
331  std::string GetInuseAuthKeyValue() const;
332  void SetListenSocketAuthKey(const AuthenticationKey &auth_key,
333  KeyType key_type);
337  bool AttemptGRHelperMode(int code, int subcode) const;
338  void Register(BgpTable *table, const RibExportPolicy &policy);
339  void Register(BgpTable *table);
341  void CustomClose();
342  const std::vector<std::string> &negotiated_families() const {
343  return negotiated_families_;
344  }
345  void ReceiveEndOfRIB(Address::Family family, size_t msgsize);
346  const std::vector<BgpProto::OpenMessage::Capability *> &
347  capabilities() const {
348  return capabilities_;
349  }
350 
351  static const std::vector<Address::Family> &supported_families() {
352  return supported_families_;
353  }
354  virtual bool IsInGRTimerWaitState() const;
356  virtual bool IsServerStartingUp() const;
357  bool IsCloseGraceful() const;
358  bool IsRouterTypeBGPaaS() const { return router_type_ == "bgpaas-client"; }
359  virtual bool ProcessSession() const;
360  void RoutingInstanceCallback(const std::string &vrf_name, int op);
361  void ASNUpdateCallback(as_t old_asn, as_t old_local_asn);
362 
363 protected:
364  virtual void SendEndOfRIBActual(Address::Family family);
365  virtual void SendEndOfRIB(Address::Family family);
367  virtual bool notification() const;
368 
369 private:
370  friend class BgpConfigTest;
371  friend class BgpPeerTest;
372  friend class BgpServerUnitTest;
373  friend class StateMachineUnitTest;
374 
375  class DeleteActor;
376  class PeerStats;
377 
378  struct OriginOverride {
380  bool operator!=(const OriginOverride &rhs) const;
381 
384  };
385 
386  typedef std::map<Address::Family, const uint8_t *> FamilyToCapabilityMap;
387  typedef std::vector<BgpPeerFamilyAttributes *> FamilyAttributesList;
388 
389  size_t GetBufferCapacity() const;
390  bool FlushUpdateUnlocked();
391  static int Encode(const BgpMessage *msg, uint8_t *data, size_t size,
392  EncodeOffsets *offsets = NULL, bool as4 = false);
393  void KeepaliveTimerErrorHandler(std::string error_name,
394  std::string error_message);
395  virtual void StartKeepaliveTimerUnlocked();
397  bool KeepaliveTimerExpired();
398 
399  void StartPrefixLimitIdleTimer(uint32_t plim_idle_time_msecs);
402  void PrefixLimitIdleTimerErrorHandler(std::string error_name,
403  std::string error_message);
404 
408  void EndOfRibTimerErrorHandler(std::string error_name,
409  std::string error_message);
410  uint32_t GetEndOfRibReceiveTime(Address::Family family) const;
411 
412  virtual void BindLocalEndpoint(BgpSession *session);
414  void BGPPeerInfoSend(const BgpPeerInfoData &peer_info) const;
415 
416  virtual bool MembershipPathCallback(DBTablePartBase *tpart,
417  BgpRoute *route, BgpPath *path);
418  uint32_t GetPathFlags(Address::Family family, const BgpAttr *attr) const;
419  uint32_t GetLocalPrefFromMed(uint32_t med) const;
420  virtual bool MpNlriAllowed(uint16_t afi, uint8_t safi);
421  virtual bool Is4ByteAsSupported() const;
423  template <typename TableT, typename PrefixT>
425  const BgpMpNlri *nlri, BgpAttrPtr attr, uint32_t flags);
426  template <typename PrefixT>
428  const BgpMpNlri *nlri, BgpAttrPtr attr, uint32_t flags);
430  IpAddress addr, uint8_t addr_len, BgpAttrPtr attr, uint32_t flags);
431 
432  bool GetBestAuthKey(AuthenticationKey *auth_key, KeyType *key_type) const;
434  void LogInstallAuthKeys(const std::string &socket_name,
435  const std::string &oper, const AuthenticationKey &auth_key,
436  KeyType key_type);
438  void ResetInuseAuthKeyInfo();
439 
440  bool CheckPrefixLimits();
443 
444  void PostCloseRelease();
445 
446  void FillBgpNeighborFamilyAttributes(BgpNeighborResp *nbr) const;
447  void FillCloseInfo(BgpNeighborResp *resp) const;
449  void BGPaaSAddRTarget(as_t as, BgpTable *table, BgpAttrPtr attr,
450  RouteTargetList::const_iterator it);
451  void AddRTargets(as_t as);
452  void DeleteRTargets(as_t as);
453  void BGPaaSDeleteRTarget(as_t as, BgpTable *table,
454  RouteTargetList::const_iterator it);
456 
457  std::string BytesToHexString(const u_int8_t *msg, size_t size);
458  virtual uint32_t GetOutputQueueDepth(Address::Family family) const;
459  virtual time_t GetRTargetTableLastUpdatedTimeStamp() const;
460  virtual void TriggerPrefixLimitCheck() const;
461 
462  static const std::vector<Address::Family> supported_families_;
467  uint16_t peer_port_;
468  std::string peer_name_;
469  std::string peer_basename_;
470  std::string router_type_; // bgp_schema.xsd:BgpRouterType
472  mutable std::string to_str_;
473  mutable std::string uve_key_str_;
475 
476  // Global peer index
477  int index_;
481 
482  // The mutex is used to protect the session, keepalive timer and the
483  // send ready state.
484  //
485  // The session is accessed from the bgp::Send task and the keepalive
486  // timer handler and gets set/cleared from the bgp::StateMachine task.
487  //
488  // The keepalive timer can get started from the io thread (either via
489  // the SetSendReady callback or from the timer handler) or from the
490  // bgp::Send task or the bgp::StateMachine task. It can get stopped
491  // from the bgp::Send task or the bgp::StateMachine task.
492  //
493  // The send ready state gets modified from the bgp::Send task or from
494  // the io thread (either via the the SetSendReady callback or from the
495  // timer handler).
496  //
497  // Note that the mutex will not be heavily contended since we expect
498  // the bgp::Send task to lock it most frequently while all other tasks
499  // and the io thread should need to lock it once every few seconds at
500  // most. Hence we choose a spin_mutex.
501  tbb::spin_mutex spin_mutex_;
503  std::vector<uint8_t> buffer_;
511  bool passive_;
515  uint32_t cluster_id_;
517 
518  tbb::atomic<int> membership_req_pending_;
523  std::vector<BgpProto::OpenMessage::Capability *> capabilities_;
524  uint16_t hold_time_;
527  uint32_t local_bgp_id_; // network order
528  uint32_t peer_bgp_id_; // network order
530  mutable std::vector<tbb::atomic<uint32_t> > family_primary_path_count_;
531  std::vector<std::string> configured_families_;
532  std::vector<std::string> negotiated_families_;
534  boost::scoped_ptr<StateMachine> state_machine_;
535  boost::scoped_ptr<BgpPeerClose> peer_close_;
536  boost::scoped_ptr<PeerCloseManager> close_manager_;
537  boost::scoped_ptr<PeerStats> peer_stats_;
538  boost::scoped_ptr<DeleteActor> deleter_;
540  mutable tbb::atomic<int> total_path_count_;
541  mutable tbb::atomic<int> primary_path_count_;
542  uint64_t flap_count_;
544  uint64_t last_flap_;
552 
554 };
555 
556 #endif // SRC_BGP_BGP_PEER_H__
boost::asio::ip::address IpAddress
Definition: address.h:13
boost::intrusive_ptr< const BgpAttr > BgpAttrPtr
Definition: bgp_attr.h:991
uint32_t as_t
Definition: bgp_common.h:21
Family
Definition: address.h:24
@ NUM_FAMILIES
Definition: address.h:35
Timer * prefix_limit_idle_timer_
Definition: bgp_peer.h:479
virtual bool IsXmppPeer() const
Definition: bgp_peer.cc:1211
bool admin_down_
Definition: bgp_peer.h:510
friend class BgpPeerTest
Definition: bgp_peer.h:371
const std::vector< BgpProto::OpenMessage::Capability * > & capabilities() const
Definition: bgp_peer.h:347
void UnregisterAllTables()
bool as4_supported_
Definition: bgp_peer.h:521
uint64_t get_rx_notification() const
Definition: bgp_peer.cc:2701
static const int kRouteTargetEndOfRibTimeSecs
Definition: bgp_peer.h:85
bool PrefixLimitIdleTimerRunning() const
Definition: bgp_peer.cc:2204
uint64_t get_tx_route_unreach() const
Definition: bgp_peer.cc:2745
static const int kEndOfRibSendRetryTime
Definition: bgp_peer.h:84
uint32_t GetEndOfRibReceiveTime(Address::Family family) const
Definition: bgp_peer.cc:314
bool InstallAuthKeys()
Definition: bgp_peer.cc:842
virtual bool CanUseMembershipManager() const
Definition: bgp_peer.cc:421
void clear_session()
Definition: bgp_peer.cc:2325
void inc_rx_route_unreach(uint64_t count)
Definition: bgp_peer.cc:2737
void RegisterToVpnTables()
Definition: bgp_peer.cc:2224
virtual bool FlushUpdate()
Definition: bgp_peer.cc:1675
static const size_t kMinBufferCapacity
Definition: bgp_peer.h:86
const std::string peer_address_string() const
Definition: bgp_peer.h:161
virtual BgpProto::BgpPeerType PeerType() const
Definition: bgp_peer.h:208
virtual bool MpNlriAllowed(uint16_t afi, uint8_t safi)
Definition: bgp_peer.cc:1793
virtual const std::string GetStateName() const
Definition: bgp_peer.cc:1336
virtual time_t GetEorSendTimerElapsedTime() const
Definition: bgp_peer.cc:310
virtual bool ProcessSession() const
Definition: bgp_peer.cc:2860
const BgpPeerKey & peer_key() const
Definition: bgp_peer.h:164
uint32_t PeerAddress() const
Definition: bgp_peer.h:160
void RoutingInstanceCallback(const std::string &vrf_name, int op)
Definition: bgp_peer.cc:779
boost::scoped_ptr< PeerStats > peer_stats_
Definition: bgp_peer.h:537
RoutingInstance * GetRoutingInstance()
Definition: bgp_peer.h:202
BgpProto::BgpPeerType peer_type_
Definition: bgp_peer.h:533
void CustomClose()
Definition: bgp_peer.cc:1251
StateMachine * state_machine()
Definition: bgp_peer.h:326
KeyType inuse_authkey_type_
Definition: bgp_peer.h:548
virtual const std::string & ToUVEKey() const
Definition: bgp_peer.h:101
virtual bool IsInGRTimerWaitState() const
Definition: bgp_peer.cc:1318
void LogInstallAuthKeys(const std::string &socket_name, const std::string &oper, const AuthenticationKey &auth_key, KeyType key_type)
Definition: bgp_peer.cc:918
const string & private_as_action() const
Definition: bgp_peer.h:211
uint64_t get_connect_error() const
Definition: bgp_peer.cc:2781
boost::scoped_ptr< StateMachine > state_machine_
Definition: bgp_peer.h:534
uint64_t last_flap_
Definition: bgp_peer.h:544
uint64_t get_rx_keepalive() const
Definition: bgp_peer.cc:2669
BgpServer * server_
Definition: bgp_peer.h:463
std::string BytesToHexString(const u_int8_t *msg, size_t size)
Definition: bgp_peer.cc:2339
uint16_t hold_time() const
Definition: bgp_peer.h:182
LifetimeRef< BgpPeer > instance_delete_ref_
Definition: bgp_peer.h:539
int GetIndex() const
Definition: bgp_peer.h:205
Timer * eor_send_timer_[Address::NUM_FAMILIES]
Definition: bgp_peer.h:507
bool as_override_
Definition: bgp_peer.h:513
void inc_tx_end_of_rib()
Definition: bgp_peer.cc:2717
bool IsRouterTypeBGPaaS() const
Definition: bgp_peer.h:358
BgpAttrPtr GetMpNlriNexthop(BgpMpNlri *nlri, BgpAttrPtr attr)
Definition: bgp_peer.cc:2383
void SetSessionSocketAuthKey(TcpSession *session)
Definition: bgp_peer.cc:894
void StopKeepaliveTimerUnlocked()
Definition: bgp_peer.cc:2301
void ClearConfig()
Definition: bgp_peer.cc:1162
void Close(bool graceful)
Definition: bgp_peer.cc:1269
virtual bool IsRegistrationRequired() const
Definition: bgp_peer.h:227
std::vector< std::string > configured_families_
Definition: bgp_peer.h:531
void DeleteRTargets(as_t as)
Definition: bgp_peer.cc:755
std::string router_type_
Definition: bgp_peer.h:470
uint32_t local_bgp_id_
Definition: bgp_peer.h:527
const BgpNeighborConfig * config_
Definition: bgp_peer.h:474
TcpSession::Endpoint endpoint() const
Definition: bgp_peer.h:171
const std::vector< std::string > & configured_families() const
Definition: bgp_peer.h:193
uint16_t hold_time_
Definition: bgp_peer.h:524
void inc_rx_update()
Definition: bgp_peer.cc:2681
void ASNUpdateCallback(as_t old_asn, as_t old_local_asn)
Definition: bgp_peer.cc:768
virtual int GetPrimaryPathCount() const
Definition: bgp_peer.h:322
bool IsCloseInProgress() const
Definition: bgp_peer.cc:1322
void inc_update_error()
Definition: bgp_peer.cc:2777
size_t GetBufferCapacity() const
Definition: bgp_peer.cc:657
void ProcessNlriBgpaas(Address::Family family, DBRequest::DBOperation oper, const BgpMpNlri *nlri, BgpAttrPtr attr, uint32_t flags)
Definition: bgp_peer.cc:1847
std::string transport_address_string() const
Definition: bgp_peer.cc:1231
void EndOfRibTimerErrorHandler(std::string error_name, std::string error_message)
Definition: bgp_peer.cc:2218
bool send_ready_
Definition: bgp_peer.h:509
void increment_flap_count()
Definition: bgp_peer.cc:2821
virtual bool IsReady() const
Definition: bgp_peer.cc:1207
bool ProcessFamilyAttributesConfig(const BgpNeighborConfig *config)
Definition: bgp_peer.cc:958
void reset_flap_count()
Definition: bgp_peer.cc:2841
bool IsDeleted() const
Definition: bgp_peer.cc:1314
uint16_t peer_port_
Definition: bgp_peer.h:467
uint64_t get_tx_keepalive() const
Definition: bgp_peer.cc:2677
tbb::atomic< int > primary_path_count_
Definition: bgp_peer.h:541
std::string GetInuseAuthKeyValue() const
Definition: bgp_peer.cc:914
int membership_req_pending() const
Definition: bgp_peer.h:366
int instance_op_
Definition: bgp_peer.h:551
virtual void UpdateCloseRouteStats(Address::Family family, const BgpPath *old_path, uint32_t path_flags) const
Definition: bgp_peer.cc:1293
std::string uve_key_str_
Definition: bgp_peer.h:473
void ManagedDelete()
Definition: bgp_peer.cc:2458
std::string peer_name_
Definition: bgp_peer.h:468
virtual void ProcessPathTunnelEncapsulation(const BgpPath *path, BgpAttr *attr, ExtCommunityDB *extcomm_db, const BgpTable *table) const
Definition: bgp_peer.cc:2148
bool defer_close_
Definition: bgp_peer.h:519
std::string local_bgp_identifier_string() const
Definition: bgp_peer.cc:1219
virtual BgpServer * server()
Definition: bgp_peer.h:157
const std::string & peer_name() const
Definition: bgp_peer.h:168
void FillCloseInfo(BgpNeighborResp *resp) const
Definition: bgp_peer.cc:2530
virtual bool send_ready() const
Definition: bgp_peer.h:229
virtual void SetDataCollectionKey(BgpPeerInfo *peer_info) const
Definition: bgp_peer.cc:2481
void inc_connect_timer_expired()
Definition: bgp_peer.cc:2765
void ResetCapabilities()
Definition: bgp_peer.cc:1781
void ReceiveEndOfRIB(Address::Family family, size_t msgsize)
Definition: bgp_peer.cc:270
void inc_connect_error()
Definition: bgp_peer.cc:2761
bool EndOfRibReceiveTimerExpired(Address::Family family)
Definition: bgp_peer.cc:2264
void inc_tx_open()
Definition: bgp_peer.cc:2661
bool ProcessAuthKeyChainConfig(const BgpNeighborConfig *config)
Definition: bgp_peer.cc:831
void Clear(int subcode)
Definition: bgp_peer.cc:1306
DISALLOW_COPY_AND_ASSIGN(BgpPeer)
RibExportPolicy BuildRibExportPolicy(Address::Family family) const
Definition: bgp_peer.cc:243
bool ResumeClose()
Definition: bgp_peer.cc:463
static int Encode(const BgpMessage *msg, uint8_t *data, size_t size, EncodeOffsets *offsets=NULL, bool as4=false)
friend class BgpConfigTest
Definition: bgp_peer.h:370
boost::scoped_ptr< BgpPeerClose > peer_close_
Definition: bgp_peer.h:535
uint64_t get_rx_end_of_rib() const
Definition: bgp_peer.cc:2713
std::string peer_basename_
Definition: bgp_peer.h:469
uint32_t peer_bgp_id_
Definition: bgp_peer.h:528
uint64_t total_flap_count() const
Definition: bgp_peer.h:251
void SendKeepalive(bool from_timer)
Definition: bgp_peer.cc:1578
bool IsAdminDown() const
Definition: bgp_peer.h:221
std::vector< BgpProto::OpenMessage::Capability * > capabilities_
Definition: bgp_peer.h:523
void PrefixLimitIdleTimerErrorHandler(std::string error_name, std::string error_message)
Definition: bgp_peer.cc:2212
virtual bool SendUpdate(const uint8_t *msg, size_t msgsize, const std::string *msg_str)
void inc_rx_route_reach(uint64_t count)
Definition: bgp_peer.cc:2725
RoutingInstance * rtinstance_
Definition: bgp_peer.h:464
friend class BgpServerUnitTest
Definition: bgp_peer.h:372
void StopPrefixLimitIdleTimer()
Definition: bgp_peer.cc:2200
uint64_t get_socket_reads() const
Definition: bgp_peer.cc:2801
bool FlushUpdateUnlocked()
Definition: bgp_peer.cc:1645
virtual bool MembershipPathCallback(DBTablePartBase *tpart, BgpRoute *route, BgpPath *path)
Definition: bgp_peer.cc:458
StateMachine::State GetState() const
Definition: bgp_peer.cc:1332
const std::vector< std::string > & negotiated_families() const
Definition: bgp_peer.h:342
void KeepaliveTimerErrorHandler(std::string error_name, std::string error_message)
Definition: bgp_peer.cc:2258
BgpPeerKey peer_key_
Definition: bgp_peer.h:466
uint64_t get_tx_route_reach() const
Definition: bgp_peer.cc:2733
std::vector< tbb::atomic< uint32_t > > family_primary_path_count_
Definition: bgp_peer.h:530
TaskTrigger trigger_
Definition: bgp_peer.h:478
virtual const std::string & ToString() const
Definition: bgp_peer.h:100
void BGPPeerInfoSend(const BgpPeerInfoData &peer_info) const
Definition: bgp_peer.cc:416
RouteTargetList rtargets_
Definition: bgp_peer.h:549
std::map< Address::Family, const uint8_t * > FamilyToCapabilityMap
Definition: bgp_peer.h:386
virtual int GetTotalPathCount() const
Definition: bgp_peer.h:313
bool KeepaliveTimerExpired()
Definition: bgp_peer.cc:2273
tbb::atomic< int > total_path_count_
Definition: bgp_peer.h:540
boost::scoped_ptr< DeleteActor > deleter_
Definition: bgp_peer.h:538
BgpSession * session()
Definition: bgp_peer.cc:2335
void inc_tx_notification()
Definition: bgp_peer.cc:2705
AuthenticationData auth_data_
Definition: bgp_peer.h:546
virtual bool IsServerStartingUp() const
Definition: bgp_peer.cc:319
static const size_t kMaxBufferCapacity
Definition: bgp_peer.h:87
static const std::vector< Address::Family > supported_families_
Definition: bgp_peer.h:462
virtual uint32_t bgp_identifier() const
Definition: bgp_peer.cc:1223
void BGPaaSAddRTarget(as_t as, BgpTable *table, BgpAttrPtr attr, RouteTargetList::const_iterator it)
Definition: bgp_peer.cc:714
void SendNotification(BgpSession *, int code, int subcode=0, const std::string &data=std::string())
Definition: bgp_peer.cc:1700
uint64_t flap_count_
Definition: bgp_peer.h:542
void set_session(BgpSession *session)
Definition: bgp_peer.cc:2319
void SendOpen(TcpSession *session)
Definition: bgp_peer.cc:1502
virtual bool ReceiveMsg(BgpSession *session, const u_int8_t *msg, size_t size)
Definition: bgp_peer.cc:2355
void MembershipRequestCallback(BgpTable *table)
Definition: bgp_peer.cc:430
void RegisterAllTables()
Definition: bgp_peer.cc:1432
std::set< RouteTarget > RouteTargetList
Definition: bgp_peer.h:91
void ProcessBgpaas(DBRequest::DBOperation oper, IpAddress addr, uint8_t addr_len, BgpAttrPtr attr, uint32_t flags)
Definition: bgp_peer.cc:1871
void inc_hold_timer_expired()
Definition: bgp_peer.cc:2769
uint64_t get_rx_route_total() const
Definition: bgp_peer.cc:2749
uint32_t cluster_id_
Definition: bgp_peer.h:515
bool GetBestAuthKeyItem(AuthenticationKey *auth_key)
boost::scoped_ptr< PeerCloseManager > close_manager_
Definition: bgp_peer.h:536
void ClearListenSocketAuthKey()
Definition: bgp_peer.cc:888
friend class StateMachineUnitTest
Definition: bgp_peer.h:373
virtual void UpdatePrimaryPathCount(int count, Address::Family family) const
Definition: bgp_peer.cc:2182
const std::string & peer_basename() const
Definition: bgp_peer.h:169
uint64_t get_open_error() const
Definition: bgp_peer.cc:2793
size_t buffer_size() const
Definition: bgp_peer.h:185
BgpSession * session_
Definition: bgp_peer.h:504
bool CheckPrefixLimits()
Definition: bgp_peer.cc:934
uint64_t get_socket_writes() const
Definition: bgp_peer.cc:2807
time_t eor_send_timer_start_time_
Definition: bgp_peer.h:508
virtual const std::vector< std::string > GetDefaultTunnelEncap(const Address::Family family) const
Definition: bgp_peer.cc:2141
virtual uint32_t local_bgp_identifier() const
Definition: bgp_peer.cc:1215
void StartPrefixLimitIdleTimer(uint32_t plim_idle_time_msecs)
Definition: bgp_peer.cc:2194
std::string gateway_address_string(Address::Family family) const
Definition: bgp_peer.cc:1240
uint64_t get_tx_update() const
Definition: bgp_peer.cc:2693
bool SetCapabilities(const BgpProto::OpenMessage *msg)
Definition: bgp_peer.cc:1708
void FillNeighborInfo(const BgpSandeshContext *bsc, BgpNeighborResp *bnr, bool summary) const
Definition: bgp_peer.cc:2598
uint64_t get_rx_route_reach() const
Definition: bgp_peer.cc:2729
const StateMachine * state_machine() const
Definition: bgp_peer.h:327
void StartKeepaliveTimer()
Definition: bgp_peer.cc:2295
OriginOverride origin_override_
Definition: bgp_peer.h:516
uint64_t get_hold_timer_expired() const
Definition: bgp_peer.cc:2789
uint32_t GetPathFlags(Address::Family family, const BgpAttr *attr) const
Definition: bgp_peer.cc:1901
void inc_rx_notification()
Definition: bgp_peer.cc:2697
std::string router_type() const
Definition: bgp_peer.h:170
bool KeepaliveTimerRunning()
Definition: bgp_peer.cc:2305
TaskTrigger prefix_limit_trigger_
Definition: bgp_peer.h:480
size_t buffer_capacity_
Definition: bgp_peer.h:502
uint64_t total_flap_count_
Definition: bgp_peer.h:543
void FillBgpNeighborFamilyAttributes(BgpNeighborResp *nbr) const
Definition: bgp_peer.cc:2575
uint64_t flap_count() const
Definition: bgp_peer.h:249
BgpSession * CreateSession()
Definition: bgp_peer.cc:1340
void RetryDelete()
Definition: bgp_peer.cc:2471
tbb::spin_mutex spin_mutex_
Definition: bgp_peer.h:501
std::string last_flap_at() const
Definition: bgp_peer.cc:2813
void ResetInuseAuthKeyInfo()
Definition: bgp_peer.cc:875
void inc_tx_update()
Definition: bgp_peer.cc:2689
int asn_listener_id_
Definition: bgp_peer.h:550
virtual void SendEndOfRIB(Address::Family family)
Definition: bgp_peer.cc:404
std::vector< std::string > negotiated_families_
Definition: bgp_peer.h:532
void inc_rx_end_of_rib()
Definition: bgp_peer.cc:2709
as_t local_as_
Definition: bgp_peer.h:525
FamilyAttributesList family_attributes_list_
Definition: bgp_peer.h:529
void SetInuseAuthKeyInfo(const AuthenticationKey &key, KeyType type)
Definition: bgp_peer.cc:870
void ProcessUpdate(const BgpProto::Update *msg, size_t msgsize=0)
Definition: bgp_peer.cc:1951
BgpTable * GetRTargetTable()
Definition: bgp_peer.cc:694
void inc_rx_keepalive()
Definition: bgp_peer.cc:2665
BgpAttrPtr GetRouteTargetRouteAttr() const
Definition: bgp_peer.cc:704
virtual void UpdateTotalPathCount(int count) const
Definition: bgp_peer.h:310
RoutingInstance * GetRoutingInstance() const
Definition: bgp_peer.h:203
uint64_t get_rx_route_unreach() const
Definition: bgp_peer.cc:2741
virtual bool notification() const
Definition: bgp_peer.cc:1680
virtual time_t GetRTargetTableLastUpdatedTimeStamp() const
Definition: bgp_peer.cc:327
AuthenticationKey inuse_auth_key_
Definition: bgp_peer.h:547
virtual ~BgpPeer()
Definition: bgp_peer.cc:625
void BGPaaSDeleteRTarget(as_t as, BgpTable *table, RouteTargetList::const_iterator it)
Definition: bgp_peer.cc:742
bool graceful_close_
Definition: bgp_peer.h:520
bool EndOfRibSendTimerExpired(Address::Family family)
Definition: bgp_peer.cc:331
bool PrefixLimitIdleTimerExpired()
Definition: bgp_peer.cc:2208
virtual void BindLocalEndpoint(BgpSession *session)
Definition: bgp_peer.cc:815
void inc_rx_open()
Definition: bgp_peer.cc:2657
uint64_t get_rx_update() const
Definition: bgp_peer.cc:2685
bool passive_
Definition: bgp_peer.h:511
virtual IPeerDebugStats * peer_stats()
Definition: bgp_peer.cc:1298
Timer * eor_receive_timer_[Address::NUM_FAMILIES]
Definition: bgp_peer.h:506
std::vector< uint8_t > buffer_
Definition: bgp_peer.h:503
virtual uint32_t GetOutputQueueDepth(Address::Family family) const
Definition: bgp_peer.cc:305
void SetListenSocketAuthKey(const AuthenticationKey &auth_key, KeyType key_type)
Definition: bgp_peer.cc:880
virtual void ResetAs4Supported()
Definition: bgp_peer.h:315
void ProcessNlri(Address::Family family, DBRequest::DBOperation oper, const BgpMpNlri *nlri, BgpAttrPtr attr, uint32_t flags)
Definition: bgp_peer.cc:1813
void inc_open_error()
Definition: bgp_peer.cc:2773
void Initialize()
Definition: bgp_peer.cc:652
virtual bool IsAs4Supported() const
Definition: bgp_peer.h:314
uint64_t last_flap() const
Definition: bgp_peer.h:250
void DSCPUpdateCallback(uint8_t dscp_value)
Definition: bgp_peer.cc:2865
as_t peer_as() const
Definition: bgp_peer.h:184
void PostCloseRelease()
Definition: bgp_peer.cc:1187
bool AcceptSession(BgpSession *session)
Definition: bgp_peer.cc:1369
const BgpNeighborConfig * config() const
Definition: bgp_peer.h:213
void SetSendReady()
Definition: bgp_peer.cc:2310
uint64_t get_tx_route_total() const
Definition: bgp_peer.cc:2755
TcpSession::Endpoint endpoint_
Definition: bgp_peer.h:465
virtual void SendEndOfRIBActual(Address::Family family)
Definition: bgp_peer.cc:279
void ConfigUpdate(const BgpNeighborConfig *config)
Definition: bgp_peer.cc:992
uint64_t get_tx_end_of_rib() const
Definition: bgp_peer.cc:2721
Timer * keepalive_timer_
Definition: bgp_peer.h:505
std::vector< BgpPeerFamilyAttributes * > FamilyAttributesList
Definition: bgp_peer.h:387
int GetTaskInstance() const
Definition: bgp_peer.cc:2477
bool IsCloseGraceful() const
Definition: bgp_peer.cc:323
bool IsFamilyNegotiated(Address::Family family)
Definition: bgp_peer.cc:1174
virtual bool Is4ByteAsSupported() const
Definition: bgp_peer.cc:1808
void NotifyEstablished(bool established)
Definition: bgp_peer.cc:798
uint64_t get_update_error() const
Definition: bgp_peer.cc:2797
void ProcessEndpointConfig(const BgpNeighborConfig *config)
Definition: bgp_peer.cc:980
bool GetBestAuthKey(AuthenticationKey *auth_key, KeyType *key_type) const
Definition: bgp_peer.cc:819
PeerCloseManager * close_manager()
Definition: bgp_peer.h:355
uint64_t get_connect_timer_expired() const
Definition: bgp_peer.cc:2785
static const std::vector< Address::Family > & supported_families()
Definition: bgp_peer.h:351
as_t peer_as_
Definition: bgp_peer.h:526
void StartEndOfRibReceiveTimer(Address::Family family)
Definition: bgp_peer.cc:2245
int dscp_listener_id_
Definition: bgp_peer.h:545
virtual IPeerClose * peer_close()
Definition: bgp_peer.cc:1285
virtual bool CheckSplitHorizon(uint32_t cluster_id=0, uint32_t ribout_cid=0) const
Definition: bgp_peer.cc:677
virtual void StartKeepaliveTimerUnlocked()
Definition: bgp_peer.cc:2285
std::string bgp_identifier_string() const
Definition: bgp_peer.cc:1227
tbb::atomic< int > membership_req_pending_
Definition: bgp_peer.h:518
bool AttemptGRHelperMode(int code, int subcode) const
Definition: bgp_peer.cc:1685
AuthenticationData::KeyType KeyType
Definition: bgp_peer.h:90
string private_as_action_
Definition: bgp_peer.h:514
virtual BgpServer * server() const
Definition: bgp_peer.h:158
uint16_t peer_port() const
Definition: bgp_peer.h:165
std::set< Address::Family > AddressFamilyList
Definition: bgp_peer.h:89
bool resolve_paths_
Definition: bgp_peer.h:512
bool vpn_tables_registered_
Definition: bgp_peer.h:522
void SetSessionSocketOptionDscp(TcpSession *session)
Definition: bgp_peer.cc:903
std::string to_str_
Definition: bgp_peer.h:472
int index_
Definition: bgp_peer.h:477
void Register(BgpTable *table, const RibExportPolicy &policy)
Definition: bgp_peer.cc:1381
virtual void SetAdminState(bool down, int subcode=BgpProto::Notification::AdminShutdown)
Definition: bgp_peer.cc:1357
as_t local_as() const
Definition: bgp_peer.h:183
bool LookupFamily(Address::Family family)
Definition: bgp_peer.h:197
bool peer_is_control_node_
Definition: bgp_peer.h:471
static void FillBgpNeighborDebugState(BgpNeighborResp *bnr, const IPeerDebugStats *peer)
Definition: bgp_peer.cc:2534
virtual void TriggerPrefixLimitCheck() const
Definition: bgp_peer.cc:988
void inc_tx_keepalive()
Definition: bgp_peer.cc:2673
uint32_t GetLocalPrefFromMed(uint32_t med) const
Definition: bgp_peer.cc:1937
void AddRTargets(as_t as)
Definition: bgp_peer.cc:727
LifetimeActor * deleter()
Definition: bgp_peer.cc:1167
bool IsPassive() const
Definition: bgp_peer.h:222
virtual bool SendUpdate(const uint8_t *msg, size_t msgsize)
Definition: bgp_peer.h:107
BgpPeer(BgpServer *server, RoutingInstance *instance, const BgpNeighborConfig *config)
Definition: bgp_peer.cc:469
Definition: ipeer.h:186
boost::asio::ip::tcp::endpoint Endpoint
Definition: tcp_session.h:62
Definition: timer.h:54
uint8_t type
Definition: load_balance.h:2
int operator()(const BgpPeerFamilyAttributes *lhs, const BgpPeerFamilyAttributes *rhs) const
Definition: bgp_peer.h:65
IpAddress gateway_address
Definition: bgp_peer.h:57
BgpPeerFamilyAttributes(const BgpNeighborConfig *config, const BgpFamilyAttributesConfig &family_config)
Definition: bgp_peer.cc:222
std::vector< std::string > default_tunnel_encap_list
Definition: bgp_peer.h:58
uint32_t address() const
Definition: bgp_peer_key.h:22
boost::asio::ip::tcp::endpoint endpoint
Definition: bgp_peer_key.h:24
OriginOverride(const BgpNeighborConfig::OriginOverrideConfig &config)
Definition: bgp_peer.cc:1609
bool operator!=(const OriginOverride &rhs) const
Definition: bgp_peer.cc:1615
BgpAttrOrigin::OriginType origin
Definition: bgp_peer.h:383
#define KEY_COMPARE(x, y)
Definition: util.h:70