OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
329  bool GetBestAuthKeyItem(AuthenticationKey *auth_key);
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);
413  void UnregisterAllTables();
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 
427  bool GetBestAuthKey(AuthenticationKey *auth_key, KeyType *key_type) const;
429  void LogInstallAuthKeys(const std::string &socket_name,
430  const std::string &oper, const AuthenticationKey &auth_key,
431  KeyType key_type);
433  void ResetInuseAuthKeyInfo();
434 
435  bool CheckPrefixLimits();
438 
439  void PostCloseRelease();
440 
441  void FillBgpNeighborFamilyAttributes(BgpNeighborResp *nbr) const;
442  void FillCloseInfo(BgpNeighborResp *resp) const;
444  void BGPaaSAddRTarget(as_t as, BgpTable *table, BgpAttrPtr attr,
445  RouteTargetList::const_iterator it);
446  void AddRTargets(as_t as);
447  void DeleteRTargets(as_t as);
448  void BGPaaSDeleteRTarget(as_t as, BgpTable *table,
449  RouteTargetList::const_iterator it);
451 
452  std::string BytesToHexString(const u_int8_t *msg, size_t size);
453  virtual uint32_t GetOutputQueueDepth(Address::Family family) const;
454  virtual time_t GetRTargetTableLastUpdatedTimeStamp() const;
455  virtual void TriggerPrefixLimitCheck() const;
456 
457  static const std::vector<Address::Family> supported_families_;
462  uint16_t peer_port_;
463  std::string peer_name_;
464  std::string peer_basename_;
465  std::string router_type_; // bgp_schema.xsd:BgpRouterType
467  mutable std::string to_str_;
468  mutable std::string uve_key_str_;
470 
471  // Global peer index
472  int index_;
476 
477  // The mutex is used to protect the session, keepalive timer and the
478  // send ready state.
479  //
480  // The session is accessed from the bgp::Send task and the keepalive
481  // timer handler and gets set/cleared from the bgp::StateMachine task.
482  //
483  // The keepalive timer can get started from the io thread (either via
484  // the SetSendReady callback or from the timer handler) or from the
485  // bgp::Send task or the bgp::StateMachine task. It can get stopped
486  // from the bgp::Send task or the bgp::StateMachine task.
487  //
488  // The send ready state gets modified from the bgp::Send task or from
489  // the io thread (either via the the SetSendReady callback or from the
490  // timer handler).
491  //
492  // Note that the mutex will not be heavily contended since we expect
493  // the bgp::Send task to lock it most frequently while all other tasks
494  // and the io thread should need to lock it once every few seconds at
495  // most. Hence we choose a spin_mutex.
496  tbb::spin_mutex spin_mutex_;
498  std::vector<uint8_t> buffer_;
506  bool passive_;
510  uint32_t cluster_id_;
512 
513  tbb::atomic<int> membership_req_pending_;
518  std::vector<BgpProto::OpenMessage::Capability *> capabilities_;
519  uint16_t hold_time_;
522  uint32_t local_bgp_id_; // network order
523  uint32_t peer_bgp_id_; // network order
525  mutable std::vector<tbb::atomic<uint32_t> > family_primary_path_count_;
526  std::vector<std::string> configured_families_;
527  std::vector<std::string> negotiated_families_;
529  boost::scoped_ptr<StateMachine> state_machine_;
530  boost::scoped_ptr<BgpPeerClose> peer_close_;
531  boost::scoped_ptr<PeerCloseManager> close_manager_;
532  boost::scoped_ptr<PeerStats> peer_stats_;
533  boost::scoped_ptr<DeleteActor> deleter_;
535  mutable tbb::atomic<int> total_path_count_;
536  mutable tbb::atomic<int> primary_path_count_;
537  uint64_t flap_count_;
539  uint64_t last_flap_;
547 
549 };
550 
551 #endif // SRC_BGP_BGP_PEER_H__
OriginOverride origin_override_
Definition: bgp_peer.h:511
virtual bool IsInGRTimerWaitState() const
Definition: bgp_peer.cc:1318
void inc_tx_notification()
Definition: bgp_peer.cc:2611
bool FlushUpdateUnlocked()
Definition: bgp_peer.cc:1628
virtual bool ProcessSession() const
Definition: bgp_peer.cc:2766
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
virtual void ResetAs4Supported()
Definition: bgp_peer.h:315
void AddRTargets(as_t as)
Definition: bgp_peer.cc:727
boost::asio::ip::tcp::endpoint Endpoint
Definition: tcp_session.h:62
size_t GetBufferCapacity() const
Definition: bgp_peer.cc:657
virtual bool ReceiveMsg(BgpSession *session, const u_int8_t *msg, size_t size)
Definition: bgp_peer.cc:2261
uint64_t flap_count() const
Definition: bgp_peer.h:249
void Initialize()
Definition: bgp_peer.cc:652
uint32_t address() const
Definition: bgp_peer_key.h:22
bool InstallAuthKeys()
Definition: bgp_peer.cc:842
size_t buffer_size() const
Definition: bgp_peer.h:185
void FillBgpNeighborFamilyAttributes(BgpNeighborResp *nbr) const
Definition: bgp_peer.cc:2481
void ResetCapabilities()
Definition: bgp_peer.cc:1764
tbb::atomic< int > primary_path_count_
Definition: bgp_peer.h:536
bool KeepaliveTimerExpired()
Definition: bgp_peer.cc:2179
void inc_tx_end_of_rib()
Definition: bgp_peer.cc:2623
PeerCloseManager * close_manager()
Definition: bgp_peer.h:355
uint64_t get_open_error() const
Definition: bgp_peer.cc:2699
bool ProcessAuthKeyChainConfig(const BgpNeighborConfig *config)
Definition: bgp_peer.cc:831
bool AcceptSession(BgpSession *session)
Definition: bgp_peer.cc:1369
BgpAttrPtr GetMpNlriNexthop(BgpMpNlri *nlri, BgpAttrPtr attr)
Definition: bgp_peer.cc:2289
uint32_t GetLocalPrefFromMed(uint32_t med) const
Definition: bgp_peer.cc:1865
int dscp_listener_id_
Definition: bgp_peer.h:540
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
void UnregisterAllTables()
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
friend class BgpConfigTest
Definition: bgp_peer.h:370
boost::scoped_ptr< StateMachine > state_machine_
Definition: bgp_peer.h:529
OriginOverride(const BgpNeighborConfig::OriginOverrideConfig &config)
Definition: bgp_peer.cc:1592
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
virtual const std::vector< std::string > GetDefaultTunnelEncap(const Address::Family family) const
Definition: bgp_peer.cc:2047
void EndOfRibTimerErrorHandler(std::string error_name, std::string error_message)
Definition: bgp_peer.cc:2124
Family
Definition: address.h:24
#define KEY_COMPARE(x, y)
Definition: util.h:70
uint64_t get_rx_route_reach() const
Definition: bgp_peer.cc:2635
uint16_t peer_port() const
Definition: bgp_peer.h:165
boost::asio::ip::address IpAddress
Definition: address.h:13
void BGPPeerInfoSend(const BgpPeerInfoData &peer_info) const
Definition: bgp_peer.cc:416
bool LookupFamily(Address::Family family)
Definition: bgp_peer.h:197
bool IsPassive() const
Definition: bgp_peer.h:222
virtual int GetPrimaryPathCount() const
Definition: bgp_peer.h:322
boost::scoped_ptr< BgpPeerClose > peer_close_
Definition: bgp_peer.h:530
virtual void UpdateTotalPathCount(int count) const
Definition: bgp_peer.h:310
uint64_t flap_count_
Definition: bgp_peer.h:537
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
void inc_connect_timer_expired()
Definition: bgp_peer.cc:2671
uint64_t get_socket_reads() const
Definition: bgp_peer.cc:2707
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
virtual bool IsXmppPeer() const
Definition: bgp_peer.cc:1211
virtual void UpdateCloseRouteStats(Address::Family family, const BgpPath *old_path, uint32_t path_flags) const
Definition: bgp_peer.cc:1293
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
std::set< RouteTarget > RouteTargetList
Definition: bgp_peer.h:91
bool IsRouterTypeBGPaaS() const
Definition: bgp_peer.h:358
void inc_tx_open()
Definition: bgp_peer.cc:2567
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
uint16_t hold_time() const
Definition: bgp_peer.h:182
virtual bool Is4ByteAsSupported() const
Definition: bgp_peer.cc:1791
virtual void SetDataCollectionKey(BgpPeerInfo *peer_info) const
Definition: bgp_peer.cc:2387
bool IsAdminDown() const
Definition: bgp_peer.h:221
as_t local_as_
Definition: bgp_peer.h:520
void ProcessEndpointConfig(const BgpNeighborConfig *config)
Definition: bgp_peer.cc:980
void clear_session()
Definition: bgp_peer.cc:2231
RoutingInstance * rtinstance_
Definition: bgp_peer.h:459
virtual BgpProto::BgpPeerType PeerType() const
Definition: bgp_peer.h:208
uint64_t get_tx_update() const
Definition: bgp_peer.cc:2599
uint64_t total_flap_count() const
Definition: bgp_peer.h:251
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
AuthenticationKey inuse_auth_key_
Definition: bgp_peer.h:542
virtual bool MembershipPathCallback(DBTablePartBase *tpart, BgpRoute *route, BgpPath *path)
Definition: bgp_peer.cc:458
uint64_t get_rx_notification() const
Definition: bgp_peer.cc:2607
uint32_t as_t
Definition: bgp_common.h:21
Definition: ipeer.h:186
std::string peer_name_
Definition: bgp_peer.h:463
boost::asio::ip::tcp::endpoint endpoint
Definition: bgp_peer_key.h:24
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
virtual void TriggerPrefixLimitCheck() const
Definition: bgp_peer.cc:988
static const int kEndOfRibSendRetryTime
Definition: bgp_peer.h:84
IpAddress gateway_address
Definition: bgp_peer.h:57
TaskTrigger prefix_limit_trigger_
Definition: bgp_peer.h:475
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
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
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
virtual BgpServer * server()
Definition: bgp_peer.h:157
void SetSendReady()
Definition: bgp_peer.cc:2216
void KeepaliveTimerErrorHandler(std::string error_name, std::string error_message)
Definition: bgp_peer.cc:2164
bool IsCloseInProgress() const
Definition: bgp_peer.cc:1322
friend class BgpPeerTest
Definition: bgp_peer.h:371
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
Timer * eor_send_timer_[Address::NUM_FAMILIES]
Definition: bgp_peer.h:502
const BgpPeerKey & peer_key() const
Definition: bgp_peer.h:164
const std::vector< std::string > & configured_families() const
Definition: bgp_peer.h:193
void SetSessionSocketAuthKey(TcpSession *session)
Definition: bgp_peer.cc:894
bool IsCloseGraceful() const
Definition: bgp_peer.cc:323
void ProcessUpdate(const BgpProto::Update *msg, size_t msgsize=0)
Definition: bgp_peer.cc:1879
static int Encode(const BgpMessage *msg, uint8_t *data, size_t size, EncodeOffsets *offsets=NULL, bool as4=false)
uint8_t type
Definition: load_balance.h:109
as_t peer_as_
Definition: bgp_peer.h:521
void inc_rx_route_reach(uint64_t count)
Definition: bgp_peer.cc:2631
std::string router_type_
Definition: bgp_peer.h:465
void RoutingInstanceCallback(const std::string &vrf_name, int op)
Definition: bgp_peer.cc:779
uint64_t get_rx_end_of_rib() const
Definition: bgp_peer.cc:2619
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
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
RoutingInstance * GetRoutingInstance() const
Definition: bgp_peer.h:203
void SetInuseAuthKeyInfo(const AuthenticationKey &key, KeyType type)
Definition: bgp_peer.cc:870
virtual bool FlushUpdate()
Definition: bgp_peer.cc:1658
const std::string & peer_name() const
Definition: bgp_peer.h:168
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 SetCapabilities(const BgpProto::OpenMessage *msg)
Definition: bgp_peer.cc:1691
virtual IPeerDebugStats * peer_stats()
Definition: bgp_peer.cc:1298
virtual bool IsAs4Supported() const
Definition: bgp_peer.h:314
void inc_tx_update()
Definition: bgp_peer.cc:2595
std::string last_flap_at() const
Definition: bgp_peer.cc:2719
KeyType inuse_authkey_type_
Definition: bgp_peer.h:543
virtual bool IsRegistrationRequired() const
Definition: bgp_peer.h:227
bool as4_supported_
Definition: bgp_peer.h:516
uint64_t get_tx_route_total() const
Definition: bgp_peer.cc:2661
Timer * eor_receive_timer_[Address::NUM_FAMILIES]
Definition: bgp_peer.h:501
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
virtual void StartKeepaliveTimerUnlocked()
Definition: bgp_peer.cc:2191
friend class BgpServerUnitTest
Definition: bgp_peer.h:372
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
LifetimeRef< BgpPeer > instance_delete_ref_
Definition: bgp_peer.h:534
virtual bool MpNlriAllowed(uint16_t afi, uint8_t safi)
Definition: bgp_peer.cc:1776
AuthenticationData::KeyType KeyType
Definition: bgp_peer.h:90
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
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
virtual ~BgpPeer()
Definition: bgp_peer.cc:625
BgpAttrPtr GetRouteTargetRouteAttr() const
Definition: bgp_peer.cc:704
void inc_tx_keepalive()
Definition: bgp_peer.cc:2579
std::string router_type() const
Definition: bgp_peer.h:170
virtual const std::string & ToUVEKey() const
Definition: bgp_peer.h:101
virtual void SendEndOfRIB(Address::Family family)
Definition: bgp_peer.cc:404
bool PrefixLimitIdleTimerExpired()
Definition: bgp_peer.cc:2114
bool ResumeClose()
Definition: bgp_peer.cc:463
Timer * prefix_limit_idle_timer_
Definition: bgp_peer.h:474
const std::string & peer_basename() const
Definition: bgp_peer.h:169
std::vector< std::string > default_tunnel_encap_list
Definition: bgp_peer.h:58
bool admin_down_
Definition: bgp_peer.h:505
virtual bool SendUpdate(const uint8_t *msg, size_t msgsize, const std::string *msg_str)
bool passive_
Definition: bgp_peer.h:506
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
const std::vector< BgpProto::OpenMessage::Capability * > & capabilities() const
Definition: bgp_peer.h:347
StateMachine::State GetState() const
Definition: bgp_peer.cc:1332
const std::string peer_address_string() const
Definition: bgp_peer.h:161
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
void RegisterToVpnTables()
Definition: bgp_peer.cc:2130
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
DISALLOW_COPY_AND_ASSIGN(BgpPeer)
void inc_rx_end_of_rib()
Definition: bgp_peer.cc:2615
virtual BgpServer * server() const
Definition: bgp_peer.h:158
void inc_connect_error()
Definition: bgp_peer.cc:2667
int operator()(const BgpPeerFamilyAttributes *lhs, const BgpPeerFamilyAttributes *rhs) const
Definition: bgp_peer.h:65
bool peer_is_control_node_
Definition: bgp_peer.h:466
std::vector< tbb::atomic< uint32_t > > family_primary_path_count_
Definition: bgp_peer.h:525
void StartKeepaliveTimer()
Definition: bgp_peer.cc:2201
bool GetBestAuthKey(AuthenticationKey *auth_key, KeyType *key_type) const
Definition: bgp_peer.cc:819
void ClearListenSocketAuthKey()
Definition: bgp_peer.cc:888
std::vector< uint8_t > buffer_
Definition: bgp_peer.h:498
static const size_t kMaxBufferCapacity
Definition: bgp_peer.h:87
virtual bool IsServerStartingUp() const
Definition: bgp_peer.cc:319
virtual void SendEndOfRIBActual(Address::Family family)
Definition: bgp_peer.cc:279
void inc_hold_timer_expired()
Definition: bgp_peer.cc:2675
virtual int GetTotalPathCount() const
Definition: bgp_peer.h:313
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
virtual bool IsReady() const
Definition: bgp_peer.cc:1207
static const std::vector< Address::Family > & supported_families()
Definition: bgp_peer.h:351
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
uint64_t last_flap_
Definition: bgp_peer.h:539
void ProcessNlri(Address::Family family, DBRequest::DBOperation oper, const BgpMpNlri *nlri, BgpAttrPtr attr, uint32_t flags)
Definition: bgp_peer.cc:1796
static const std::vector< Address::Family > supported_families_
Definition: bgp_peer.h:457
as_t peer_as() const
Definition: bgp_peer.h:184
std::set< Address::Family > AddressFamilyList
Definition: bgp_peer.h:89
std::string uve_key_str_
Definition: bgp_peer.h:468
void ReceiveEndOfRIB(Address::Family family, size_t msgsize)
Definition: bgp_peer.cc:270
virtual void BindLocalEndpoint(BgpSession *session)
Definition: bgp_peer.cc:815
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
tbb::atomic< int > total_path_count_
Definition: bgp_peer.h:535
static void FillBgpNeighborDebugState(BgpNeighborResp *bnr, const IPeerDebugStats *peer)
Definition: bgp_peer.cc:2440
const string & private_as_action() const
Definition: bgp_peer.h:211
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
bool send_ready_
Definition: bgp_peer.h:504
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
void ClearConfig()
Definition: bgp_peer.cc:1162
const BgpNeighborConfig * config() const
Definition: bgp_peer.h:213
Definition: timer.h:54
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
uint64_t last_flap() const
Definition: bgp_peer.h:250
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
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
int GetIndex() const
Definition: bgp_peer.h:205
TcpSession::Endpoint endpoint() const
Definition: bgp_peer.h:171
friend class StateMachineUnitTest
Definition: bgp_peer.h:373
virtual bool CheckSplitHorizon(uint32_t cluster_id=0, uint32_t ribout_cid=0) const
Definition: bgp_peer.cc:677
virtual bool SendUpdate(const uint8_t *msg, size_t msgsize)
Definition: bgp_peer.h:107
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
BgpSession * session()
Definition: bgp_peer.cc:2241
uint64_t get_update_error() const
Definition: bgp_peer.cc:2703
bool GetBestAuthKeyItem(AuthenticationKey *auth_key)
LifetimeActor * deleter()
Definition: bgp_peer.cc:1167
int instance_op_
Definition: bgp_peer.h:546
string private_as_action_
Definition: bgp_peer.h:509
uint32_t GetPathFlags(Address::Family family, const BgpAttr *attr) const
Definition: bgp_peer.cc:1829
const StateMachine * state_machine() const
Definition: bgp_peer.h:327
BgpPeerFamilyAttributes(const BgpNeighborConfig *config, const BgpFamilyAttributesConfig &family_config)
Definition: bgp_peer.cc:222
bool vpn_tables_registered_
Definition: bgp_peer.h:517
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
void increment_flap_count()
Definition: bgp_peer.cc:2727
void inc_rx_open()
Definition: bgp_peer.cc:2563
int membership_req_pending() const
Definition: bgp_peer.h:366
virtual void UpdatePrimaryPathCount(int count, Address::Family family) const
Definition: bgp_peer.cc:2088
void SendKeepalive(bool from_timer)
Definition: bgp_peer.cc:1561
static const int kRouteTargetEndOfRibTimeSecs
Definition: bgp_peer.h:85
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