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 #include <atomic>
18 
19 #include "base/lifetime.h"
20 #include "base/util.h"
21 #include "base/task_trigger.h"
22 #include "base/timer.h"
23 #include "base/address.h"
24 #include "bgp/bgp_config.h"
25 #include "bgp/bgp_debug.h"
26 #include "bgp/bgp_peer_key.h"
27 #include "bgp/bgp_proto.h"
28 #include "bgp/bgp_rib_policy.h"
29 #include "bgp/ipeer.h"
31 #include "bgp/state_machine.h"
32 #include "db/db_table.h"
33 
34 class BgpNeighborConfig;
35 class BgpPeerClose;
36 class BgpPeerInfo;
37 class BgpPeerInfoData;
38 class BgpServer;
39 class BgpSession;
40 class BgpSession;
41 class BgpNeighborResp;
42 class BgpSandeshContext;
43 class PeerCloseManager;
44 class RoutingInstance;
45 
46 //
47 // This contains per address family attributes.
48 // A BgpPeer contains a vector of pointers to this structure, with an entry
49 // for each value in Address::Family i.e. the vector can be indexed using a
50 // Address::Family value.
51 //
54  const BgpFamilyAttributesConfig &family_config);
55  uint8_t loop_count;
56  uint32_t prefix_limit;
57  uint32_t idle_timeout;
59  std::vector<std::string> default_tunnel_encap_list;
60 };
61 
62 //
63 // Comparator for BgpPeerFamilyAttributes.
64 //
67  const BgpPeerFamilyAttributes *rhs) const {
68  if (lhs && rhs) {
69  KEY_COMPARE(lhs->loop_count, rhs->loop_count);
75  } else {
76  KEY_COMPARE(lhs, rhs);
77  }
78  return 0;
79  }
80 };
81 
82 // A BGP peer along with its session and state machine.
83 class BgpPeer : public IPeer {
84 public:
85  static const int kEndOfRibSendRetryTime = 1; /* seconds */
86  static const int kRouteTargetEndOfRibTimeSecs = 30; // Seconds
87  static const size_t kMinBufferCapacity = 4096;
88  static const size_t kMaxBufferCapacity = 32768;
89 
90  typedef std::set<Address::Family> AddressFamilyList;
92  typedef std::set<RouteTarget> RouteTargetList;
93 
95  const BgpNeighborConfig *config);
96  virtual ~BgpPeer();
97 
98  // Interface methods
99 
100  // thread-safe
101  virtual const std::string &ToString() const { return to_str_; }
102  virtual const std::string &ToUVEKey() const { return uve_key_str_; }
103 
104  // Task: bgp::SendUpdate
105  // Used to send an UPDATE message on the socket.
106  virtual bool SendUpdate(const uint8_t *msg, size_t msgsize,
107  const std::string *msg_str);
108  virtual bool SendUpdate(const uint8_t *msg, size_t msgsize) {
109  return SendUpdate(msg, msgsize, NULL);
110  }
111  virtual bool FlushUpdate();
112 
113  // Task: bgp::Config
115  void ClearConfig();
116 
117  // thread: event manager thread.
118  // Invoked from BgpServer when a session is accepted.
120 
122 
123  virtual void SetAdminState(bool down,
125 
126  // Messages
127 
128  // thread: bgp::StateMachine
129  void SendOpen(TcpSession *session);
130 
131  // thread: bgp::StateMachine, KA timer handler
132  void SendKeepalive(bool from_timer);
133 
134  // thread: bgp::StateMachine, io::ReaderTask
135  void SendNotification(BgpSession *, int code, int subcode = 0,
136  const std::string &data = std::string());
137 
138  // thread: io::ReaderTask
139  void ProcessUpdate(const BgpProto::Update *msg, size_t msgsize = 0);
140 
141  // thread: io::ReaderTask
142  virtual bool ReceiveMsg(BgpSession *session, const u_int8_t *msg,
143  size_t size);
144 
145  void StartKeepaliveTimer();
146  bool KeepaliveTimerRunning();
147  bool PrefixLimitIdleTimerRunning() const;
148  void SetSendReady();
149 
150  // thread: io::ReaderTask
151  bool SetCapabilities(const BgpProto::OpenMessage *msg);
152  void ResetCapabilities();
153 
154  // Table registration.
155  void RegisterAllTables();
156 
157  // accessors
158  virtual BgpServer *server() { return server_; }
159  virtual BgpServer *server() const { return server_; }
160 
161  uint32_t PeerAddress() const { return peer_key_.address(); }
162  const std::string peer_address_string() const {
163  return peer_key_.endpoint.address().to_string();
164  }
165  const BgpPeerKey &peer_key() const { return peer_key_; }
166  uint16_t peer_port() const { return peer_port_; }
167  std::string transport_address_string() const;
168  std::string gateway_address_string(Address::Family family) const;
169  const std::string &peer_name() const { return peer_name_; }
170  const std::string &peer_basename() const { return peer_basename_; }
171  std::string router_type() const { return router_type_; }
173  virtual bool CheckSplitHorizon(uint32_t cluster_id = 0,
174  uint32_t ribout_cid = 0) const;
175 
177  virtual const std::string GetStateName() const;
178 
180  void clear_session();
181  BgpSession *session();
182 
183  uint16_t hold_time() const { return hold_time_; }
184  as_t local_as() const { return local_as_; }
185  as_t peer_as() const { return peer_as_; }
186  size_t buffer_size() const { return buffer_.size(); }
187 
188  // The BGP Identifier in host byte order.
189  virtual uint32_t local_bgp_identifier() const;
190  std::string local_bgp_identifier_string() const;
191  virtual uint32_t bgp_identifier() const;
192  std::string bgp_identifier_string() const;
193 
194  const std::vector<std::string> &configured_families() const {
195  return configured_families_;
196  }
197 
199  return (family_attributes_list_[family] != NULL);
200  }
201 
202  bool IsFamilyNegotiated(Address::Family family);
205 
206  int GetIndex() const { return index_; }
207  int GetTaskInstance() const;
208 
209  virtual BgpProto::BgpPeerType PeerType() const {
210  return peer_type_;
211  }
212  const string &private_as_action() const { return private_as_action_; }
213 
214  const BgpNeighborConfig *config() const { return config_; }
215 
216  virtual void SetDataCollectionKey(BgpPeerInfo *peer_info) const;
217  void FillNeighborInfo(const BgpSandeshContext *bsc, BgpNeighborResp *bnr,
218  bool summary) const;
219 
220  // thread-safe
221  bool IsDeleted() const;
222  bool IsAdminDown() const { return admin_down_; }
223  bool IsPassive() const { return passive_; }
224  bool IsCloseInProgress() const;
225  virtual bool IsReady() const;
226  virtual bool IsXmppPeer() const;
227  virtual bool CanUseMembershipManager() const;
228  virtual bool IsRegistrationRequired() const { return true; }
229  virtual time_t GetEorSendTimerElapsedTime() const;
230  virtual bool send_ready() const { return send_ready_; }
231 
232  void Close(bool graceful);
233  void Clear(int subcode);
234 
235  virtual IPeerClose *peer_close();
236  virtual IPeerClose *peer_close() const;
237  virtual void UpdateCloseRouteStats(Address::Family family,
238  const BgpPath *old_path, uint32_t path_flags) const;
239  virtual IPeerDebugStats *peer_stats();
240  virtual const IPeerDebugStats *peer_stats() const;
241  void ManagedDelete();
242  void RetryDelete();
244  void Initialize();
245 
246  void NotifyEstablished(bool established);
247 
248  void increment_flap_count();
249  void reset_flap_count();
250  uint64_t flap_count() const { return flap_count_; }
251  uint64_t last_flap() const { return last_flap_; }
252  uint64_t total_flap_count() const { return total_flap_count_; }
253 
254  void DSCPUpdateCallback(uint8_t dscp_value);
255 
256  std::string last_flap_at() const;
257 
258  void inc_rx_open();
259  void inc_rx_keepalive();
260  void inc_rx_update();
261  void inc_rx_notification();
262 
263  void inc_tx_open();
264  void inc_tx_keepalive();
265  void inc_tx_update();
266  void inc_tx_notification();
267 
268  void inc_rx_end_of_rib();
269  void inc_rx_route_reach(uint64_t count);
270  void inc_rx_route_unreach(uint64_t count);
271 
272  void inc_tx_end_of_rib();
273 
274  uint64_t get_rx_keepalive() const;
275  uint64_t get_rx_update() const;
276  uint64_t get_rx_notification() const;
277  uint64_t get_tx_keepalive() const;
278  uint64_t get_tx_update() const;
279 
280  uint64_t get_rx_end_of_rib() const;
281  uint64_t get_rx_route_reach() const;
282  uint64_t get_rx_route_unreach() const;
283  uint64_t get_rx_route_total() const;
284 
285  uint64_t get_tx_end_of_rib() const;
286  uint64_t get_tx_route_reach() const;
287  uint64_t get_tx_route_unreach() const;
288  uint64_t get_tx_route_total() const;
289 
290  void inc_connect_error();
292  void inc_hold_timer_expired();
293  void inc_open_error();
294  void inc_update_error();
295 
296  uint64_t get_connect_error() const;
297  uint64_t get_connect_timer_expired() const;
298  uint64_t get_hold_timer_expired() const;
299  uint64_t get_open_error() const;
300  uint64_t get_update_error() const;
301 
302  uint64_t get_socket_reads() const;
303  uint64_t get_socket_writes() const;
304 
305  static void FillBgpNeighborDebugState(BgpNeighborResp *bnr,
306  const IPeerDebugStats *peer);
307 
308  bool ResumeClose();
309  void MembershipRequestCallback(BgpTable *table);
310 
311  virtual void UpdateTotalPathCount(int count) const {
312  total_path_count_ += count;
313  }
314  virtual int GetTotalPathCount() const { return total_path_count_; }
315  virtual bool IsAs4Supported() const { return as4_supported_; }
316  virtual void ResetAs4Supported() { as4_supported_ = false; }
317  virtual void UpdatePrimaryPathCount(int count,
318  Address::Family family) const;
319  virtual void ProcessPathTunnelEncapsulation(const BgpPath *path,
320  BgpAttr *attr, ExtCommunityDB *extcomm_db, const BgpTable *table) const;
321  virtual const std::vector<std::string> GetDefaultTunnelEncap(
322  const Address::Family family) const;
323  virtual int GetPrimaryPathCount() const { return primary_path_count_; }
324 
325  void RegisterToVpnTables();
326 
328  const StateMachine *state_machine() const { return state_machine_.get(); }
329 
331  bool InstallAuthKeys();
332  std::string GetInuseAuthKeyValue() const;
333  void SetListenSocketAuthKey(const AuthenticationKey &auth_key,
334  KeyType key_type);
338  bool AttemptGRHelperMode(int code, int subcode) const;
339  void Register(BgpTable *table, const RibExportPolicy &policy);
340  void Register(BgpTable *table);
342  void CustomClose();
343  const std::vector<std::string> &negotiated_families() const {
344  return negotiated_families_;
345  }
346  void ReceiveEndOfRIB(Address::Family family, size_t msgsize);
347  const std::vector<BgpProto::OpenMessage::Capability *> &
348  capabilities() const {
349  return capabilities_;
350  }
351 
352  static const std::vector<Address::Family> &supported_families() {
353  return supported_families_;
354  }
355  virtual bool IsInGRTimerWaitState() const;
357  virtual bool IsServerStartingUp() const;
358  bool IsCloseGraceful() const;
359  bool IsRouterTypeBGPaaS() const { return router_type_ == "bgpaas-client"; }
360  virtual bool ProcessSession() const;
361  void RoutingInstanceCallback(const std::string &vrf_name, int op);
362  void ASNUpdateCallback(as_t old_asn, as_t old_local_asn);
363 
364 protected:
365  virtual void SendEndOfRIBActual(Address::Family family);
366  virtual void SendEndOfRIB(Address::Family family);
368  virtual bool notification() const;
369 
370 private:
371  friend class BgpConfigTest;
372  friend class BgpPeerTest;
373  friend class BgpServerUnitTest;
374  friend class StateMachineUnitTest;
375 
376  class DeleteActor;
377  class PeerStats;
378 
379  struct OriginOverride {
381  bool operator!=(const OriginOverride &rhs) const;
382 
385  };
386 
387  typedef std::map<Address::Family, const uint8_t *> FamilyToCapabilityMap;
388  typedef std::vector<BgpPeerFamilyAttributes *> FamilyAttributesList;
389 
390  size_t GetBufferCapacity() const;
391  bool FlushUpdateUnlocked();
392  static int Encode(const BgpMessage *msg, uint8_t *data, size_t size,
393  EncodeOffsets *offsets = NULL, bool as4 = false);
394  void KeepaliveTimerErrorHandler(std::string error_name,
395  std::string error_message);
396  virtual void StartKeepaliveTimerUnlocked();
398  bool KeepaliveTimerExpired();
399 
400  void StartPrefixLimitIdleTimer(uint32_t plim_idle_time_msecs);
403  void PrefixLimitIdleTimerErrorHandler(std::string error_name,
404  std::string error_message);
405 
409  void EndOfRibTimerErrorHandler(std::string error_name,
410  std::string error_message);
411  uint32_t GetEndOfRibReceiveTime(Address::Family family) const;
412 
413  virtual void BindLocalEndpoint(BgpSession *session);
415  void BGPPeerInfoSend(const BgpPeerInfoData &peer_info) const;
416 
417  virtual bool MembershipPathCallback(DBTablePartBase *tpart,
418  BgpRoute *route, BgpPath *path);
419  uint32_t GetPathFlags(Address::Family family, const BgpAttr *attr) const;
420  uint32_t GetLocalPrefFromMed(uint32_t med) const;
421  virtual bool MpNlriAllowed(uint16_t afi, uint8_t safi);
422  virtual bool Is4ByteAsSupported() const;
424  template <typename TableT, typename PrefixT>
426  const BgpMpNlri *nlri, BgpAttrPtr attr, uint32_t flags);
427  template <typename PrefixT>
429  const BgpMpNlri *nlri, BgpAttrPtr attr, uint32_t flags);
431  IpAddress addr, uint8_t addr_len, BgpAttrPtr attr, uint32_t flags);
432 
433  bool GetBestAuthKey(AuthenticationKey *auth_key, KeyType *key_type) const;
435  void LogInstallAuthKeys(const std::string &socket_name,
436  const std::string &oper, const AuthenticationKey &auth_key,
437  KeyType key_type);
439  void ResetInuseAuthKeyInfo();
440 
441  bool CheckPrefixLimits();
444 
445  void PostCloseRelease();
446 
447  void FillBgpNeighborFamilyAttributes(BgpNeighborResp *nbr) const;
448  void FillCloseInfo(BgpNeighborResp *resp) const;
450  void BGPaaSAddRTarget(as_t as, BgpTable *table, BgpAttrPtr attr,
451  RouteTargetList::const_iterator it);
452  void AddRTargets(as_t as);
453  void DeleteRTargets(as_t as);
454  void BGPaaSDeleteRTarget(as_t as, BgpTable *table,
455  RouteTargetList::const_iterator it);
457 
458  std::string BytesToHexString(const u_int8_t *msg, size_t size);
459  virtual uint32_t GetOutputQueueDepth(Address::Family family) const;
460  virtual time_t GetRTargetTableLastUpdatedTimeStamp() const;
461  virtual void TriggerPrefixLimitCheck() const;
462 
463  static const std::vector<Address::Family> supported_families_;
468  uint16_t peer_port_;
469  std::string peer_name_;
470  std::string peer_basename_;
471  std::string router_type_; // bgp_schema.xsd:BgpRouterType
473  mutable std::string to_str_;
474  mutable std::string uve_key_str_;
476 
477  // Global peer index
478  int index_;
482 
483  // The mutex is used to protect the session, keepalive timer and the
484  // send ready state.
485  //
486  // The session is accessed from the bgp::Send task and the keepalive
487  // timer handler and gets set/cleared from the bgp::StateMachine task.
488  //
489  // The keepalive timer can get started from the io thread (either via
490  // the SetSendReady callback or from the timer handler) or from the
491  // bgp::Send task or the bgp::StateMachine task. It can get stopped
492  // from the bgp::Send task or the bgp::StateMachine task.
493  //
494  // The send ready state gets modified from the bgp::Send task or from
495  // the io thread (either via the the SetSendReady callback or from the
496  // timer handler).
497  //
498  // Note that the mutex will not be heavily contended since we expect
499  // the bgp::Send task to lock it most frequently while all other tasks
500  // and the io thread should need to lock it once every few seconds at
501  // most. Hence we choose a spin_mutex.
502  tbb::spin_mutex spin_mutex_;
504  std::vector<uint8_t> buffer_;
512  bool passive_;
516  uint32_t cluster_id_;
518 
519  std::atomic<int> membership_req_pending_;
524  std::vector<BgpProto::OpenMessage::Capability *> capabilities_;
525  uint16_t hold_time_;
528  uint32_t local_bgp_id_; // network order
529  uint32_t peer_bgp_id_; // network order
531  mutable std::atomic<uint32_t> family_primary_path_count_[Address::NUM_FAMILIES];
532  std::vector<std::string> configured_families_;
533  std::vector<std::string> negotiated_families_;
535  boost::scoped_ptr<StateMachine> state_machine_;
536  boost::scoped_ptr<BgpPeerClose> peer_close_;
537  boost::scoped_ptr<PeerCloseManager> close_manager_;
538  boost::scoped_ptr<PeerStats> peer_stats_;
539  boost::scoped_ptr<DeleteActor> deleter_;
541  mutable std::atomic<int> total_path_count_;
542  mutable std::atomic<int> primary_path_count_;
543  uint64_t flap_count_;
545  uint64_t last_flap_;
553 
555 };
556 
557 #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:997
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:480
virtual bool IsXmppPeer() const
Definition: bgp_peer.cc:1210
bool admin_down_
Definition: bgp_peer.h:511
friend class BgpPeerTest
Definition: bgp_peer.h:372
const std::vector< BgpProto::OpenMessage::Capability * > & capabilities() const
Definition: bgp_peer.h:348
void UnregisterAllTables()
bool as4_supported_
Definition: bgp_peer.h:522
uint64_t get_rx_notification() const
Definition: bgp_peer.cc:2700
static const int kRouteTargetEndOfRibTimeSecs
Definition: bgp_peer.h:86
bool PrefixLimitIdleTimerRunning() const
Definition: bgp_peer.cc:2203
uint64_t get_tx_route_unreach() const
Definition: bgp_peer.cc:2744
static const int kEndOfRibSendRetryTime
Definition: bgp_peer.h:85
uint32_t GetEndOfRibReceiveTime(Address::Family family) const
Definition: bgp_peer.cc:314
bool InstallAuthKeys()
Definition: bgp_peer.cc:841
virtual bool CanUseMembershipManager() const
Definition: bgp_peer.cc:421
void clear_session()
Definition: bgp_peer.cc:2324
void inc_rx_route_unreach(uint64_t count)
Definition: bgp_peer.cc:2736
void RegisterToVpnTables()
Definition: bgp_peer.cc:2223
virtual bool FlushUpdate()
Definition: bgp_peer.cc:1674
static const size_t kMinBufferCapacity
Definition: bgp_peer.h:87
const std::string peer_address_string() const
Definition: bgp_peer.h:162
virtual BgpProto::BgpPeerType PeerType() const
Definition: bgp_peer.h:209
virtual bool MpNlriAllowed(uint16_t afi, uint8_t safi)
Definition: bgp_peer.cc:1792
virtual const std::string GetStateName() const
Definition: bgp_peer.cc:1335
virtual time_t GetEorSendTimerElapsedTime() const
Definition: bgp_peer.cc:310
virtual bool ProcessSession() const
Definition: bgp_peer.cc:2859
const BgpPeerKey & peer_key() const
Definition: bgp_peer.h:165
uint32_t PeerAddress() const
Definition: bgp_peer.h:161
void RoutingInstanceCallback(const std::string &vrf_name, int op)
Definition: bgp_peer.cc:778
boost::scoped_ptr< PeerStats > peer_stats_
Definition: bgp_peer.h:538
RoutingInstance * GetRoutingInstance()
Definition: bgp_peer.h:203
BgpProto::BgpPeerType peer_type_
Definition: bgp_peer.h:534
void CustomClose()
Definition: bgp_peer.cc:1250
StateMachine * state_machine()
Definition: bgp_peer.h:327
KeyType inuse_authkey_type_
Definition: bgp_peer.h:549
virtual const std::string & ToUVEKey() const
Definition: bgp_peer.h:102
virtual bool IsInGRTimerWaitState() const
Definition: bgp_peer.cc:1317
void LogInstallAuthKeys(const std::string &socket_name, const std::string &oper, const AuthenticationKey &auth_key, KeyType key_type)
Definition: bgp_peer.cc:917
const string & private_as_action() const
Definition: bgp_peer.h:212
uint64_t get_connect_error() const
Definition: bgp_peer.cc:2780
boost::scoped_ptr< StateMachine > state_machine_
Definition: bgp_peer.h:535
uint64_t last_flap_
Definition: bgp_peer.h:545
uint64_t get_rx_keepalive() const
Definition: bgp_peer.cc:2668
BgpServer * server_
Definition: bgp_peer.h:464
std::string BytesToHexString(const u_int8_t *msg, size_t size)
Definition: bgp_peer.cc:2338
uint16_t hold_time() const
Definition: bgp_peer.h:183
LifetimeRef< BgpPeer > instance_delete_ref_
Definition: bgp_peer.h:540
int GetIndex() const
Definition: bgp_peer.h:206
Timer * eor_send_timer_[Address::NUM_FAMILIES]
Definition: bgp_peer.h:508
bool as_override_
Definition: bgp_peer.h:514
void inc_tx_end_of_rib()
Definition: bgp_peer.cc:2716
bool IsRouterTypeBGPaaS() const
Definition: bgp_peer.h:359
BgpAttrPtr GetMpNlriNexthop(BgpMpNlri *nlri, BgpAttrPtr attr)
Definition: bgp_peer.cc:2382
void SetSessionSocketAuthKey(TcpSession *session)
Definition: bgp_peer.cc:893
void StopKeepaliveTimerUnlocked()
Definition: bgp_peer.cc:2300
void ClearConfig()
Definition: bgp_peer.cc:1161
void Close(bool graceful)
Definition: bgp_peer.cc:1268
virtual bool IsRegistrationRequired() const
Definition: bgp_peer.h:228
std::vector< std::string > configured_families_
Definition: bgp_peer.h:532
void DeleteRTargets(as_t as)
Definition: bgp_peer.cc:754
std::string router_type_
Definition: bgp_peer.h:471
uint32_t local_bgp_id_
Definition: bgp_peer.h:528
const BgpNeighborConfig * config_
Definition: bgp_peer.h:475
std::atomic< int > membership_req_pending_
Definition: bgp_peer.h:519
TcpSession::Endpoint endpoint() const
Definition: bgp_peer.h:172
const std::vector< std::string > & configured_families() const
Definition: bgp_peer.h:194
uint16_t hold_time_
Definition: bgp_peer.h:525
void inc_rx_update()
Definition: bgp_peer.cc:2680
void ASNUpdateCallback(as_t old_asn, as_t old_local_asn)
Definition: bgp_peer.cc:767
virtual int GetPrimaryPathCount() const
Definition: bgp_peer.h:323
bool IsCloseInProgress() const
Definition: bgp_peer.cc:1321
void inc_update_error()
Definition: bgp_peer.cc:2776
size_t GetBufferCapacity() const
Definition: bgp_peer.cc:656
void ProcessNlriBgpaas(Address::Family family, DBRequest::DBOperation oper, const BgpMpNlri *nlri, BgpAttrPtr attr, uint32_t flags)
Definition: bgp_peer.cc:1846
std::string transport_address_string() const
Definition: bgp_peer.cc:1230
void EndOfRibTimerErrorHandler(std::string error_name, std::string error_message)
Definition: bgp_peer.cc:2217
bool send_ready_
Definition: bgp_peer.h:510
void increment_flap_count()
Definition: bgp_peer.cc:2820
virtual bool IsReady() const
Definition: bgp_peer.cc:1206
bool ProcessFamilyAttributesConfig(const BgpNeighborConfig *config)
Definition: bgp_peer.cc:957
void reset_flap_count()
Definition: bgp_peer.cc:2840
bool IsDeleted() const
Definition: bgp_peer.cc:1313
uint16_t peer_port_
Definition: bgp_peer.h:468
uint64_t get_tx_keepalive() const
Definition: bgp_peer.cc:2676
std::string GetInuseAuthKeyValue() const
Definition: bgp_peer.cc:913
int membership_req_pending() const
Definition: bgp_peer.h:367
int instance_op_
Definition: bgp_peer.h:552
virtual void UpdateCloseRouteStats(Address::Family family, const BgpPath *old_path, uint32_t path_flags) const
Definition: bgp_peer.cc:1292
std::string uve_key_str_
Definition: bgp_peer.h:474
void ManagedDelete()
Definition: bgp_peer.cc:2457
std::string peer_name_
Definition: bgp_peer.h:469
virtual void ProcessPathTunnelEncapsulation(const BgpPath *path, BgpAttr *attr, ExtCommunityDB *extcomm_db, const BgpTable *table) const
Definition: bgp_peer.cc:2147
bool defer_close_
Definition: bgp_peer.h:520
std::string local_bgp_identifier_string() const
Definition: bgp_peer.cc:1218
virtual BgpServer * server()
Definition: bgp_peer.h:158
const std::string & peer_name() const
Definition: bgp_peer.h:169
void FillCloseInfo(BgpNeighborResp *resp) const
Definition: bgp_peer.cc:2529
virtual bool send_ready() const
Definition: bgp_peer.h:230
virtual void SetDataCollectionKey(BgpPeerInfo *peer_info) const
Definition: bgp_peer.cc:2480
void inc_connect_timer_expired()
Definition: bgp_peer.cc:2764
void ResetCapabilities()
Definition: bgp_peer.cc:1780
void ReceiveEndOfRIB(Address::Family family, size_t msgsize)
Definition: bgp_peer.cc:270
void inc_connect_error()
Definition: bgp_peer.cc:2760
bool EndOfRibReceiveTimerExpired(Address::Family family)
Definition: bgp_peer.cc:2263
void inc_tx_open()
Definition: bgp_peer.cc:2660
bool ProcessAuthKeyChainConfig(const BgpNeighborConfig *config)
Definition: bgp_peer.cc:830
void Clear(int subcode)
Definition: bgp_peer.cc:1305
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:371
boost::scoped_ptr< BgpPeerClose > peer_close_
Definition: bgp_peer.h:536
uint64_t get_rx_end_of_rib() const
Definition: bgp_peer.cc:2712
std::string peer_basename_
Definition: bgp_peer.h:470
uint32_t peer_bgp_id_
Definition: bgp_peer.h:529
uint64_t total_flap_count() const
Definition: bgp_peer.h:252
void SendKeepalive(bool from_timer)
Definition: bgp_peer.cc:1577
bool IsAdminDown() const
Definition: bgp_peer.h:222
std::vector< BgpProto::OpenMessage::Capability * > capabilities_
Definition: bgp_peer.h:524
void PrefixLimitIdleTimerErrorHandler(std::string error_name, std::string error_message)
Definition: bgp_peer.cc:2211
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:2724
std::atomic< int > primary_path_count_
Definition: bgp_peer.h:542
RoutingInstance * rtinstance_
Definition: bgp_peer.h:465
friend class BgpServerUnitTest
Definition: bgp_peer.h:373
void StopPrefixLimitIdleTimer()
Definition: bgp_peer.cc:2199
uint64_t get_socket_reads() const
Definition: bgp_peer.cc:2800
bool FlushUpdateUnlocked()
Definition: bgp_peer.cc:1644
virtual bool MembershipPathCallback(DBTablePartBase *tpart, BgpRoute *route, BgpPath *path)
Definition: bgp_peer.cc:458
StateMachine::State GetState() const
Definition: bgp_peer.cc:1331
const std::vector< std::string > & negotiated_families() const
Definition: bgp_peer.h:343
void KeepaliveTimerErrorHandler(std::string error_name, std::string error_message)
Definition: bgp_peer.cc:2257
BgpPeerKey peer_key_
Definition: bgp_peer.h:467
uint64_t get_tx_route_reach() const
Definition: bgp_peer.cc:2732
TaskTrigger trigger_
Definition: bgp_peer.h:479
virtual const std::string & ToString() const
Definition: bgp_peer.h:101
void BGPPeerInfoSend(const BgpPeerInfoData &peer_info) const
Definition: bgp_peer.cc:416
RouteTargetList rtargets_
Definition: bgp_peer.h:550
std::map< Address::Family, const uint8_t * > FamilyToCapabilityMap
Definition: bgp_peer.h:387
virtual int GetTotalPathCount() const
Definition: bgp_peer.h:314
bool KeepaliveTimerExpired()
Definition: bgp_peer.cc:2272
boost::scoped_ptr< DeleteActor > deleter_
Definition: bgp_peer.h:539
BgpSession * session()
Definition: bgp_peer.cc:2334
void inc_tx_notification()
Definition: bgp_peer.cc:2704
AuthenticationData auth_data_
Definition: bgp_peer.h:547
virtual bool IsServerStartingUp() const
Definition: bgp_peer.cc:319
static const size_t kMaxBufferCapacity
Definition: bgp_peer.h:88
static const std::vector< Address::Family > supported_families_
Definition: bgp_peer.h:463
virtual uint32_t bgp_identifier() const
Definition: bgp_peer.cc:1222
void BGPaaSAddRTarget(as_t as, BgpTable *table, BgpAttrPtr attr, RouteTargetList::const_iterator it)
Definition: bgp_peer.cc:713
void SendNotification(BgpSession *, int code, int subcode=0, const std::string &data=std::string())
Definition: bgp_peer.cc:1699
std::atomic< int > total_path_count_
Definition: bgp_peer.h:541
uint64_t flap_count_
Definition: bgp_peer.h:543
void set_session(BgpSession *session)
Definition: bgp_peer.cc:2318
void SendOpen(TcpSession *session)
Definition: bgp_peer.cc:1501
virtual bool ReceiveMsg(BgpSession *session, const u_int8_t *msg, size_t size)
Definition: bgp_peer.cc:2354
void MembershipRequestCallback(BgpTable *table)
Definition: bgp_peer.cc:430
void RegisterAllTables()
Definition: bgp_peer.cc:1431
std::set< RouteTarget > RouteTargetList
Definition: bgp_peer.h:92
void ProcessBgpaas(DBRequest::DBOperation oper, IpAddress addr, uint8_t addr_len, BgpAttrPtr attr, uint32_t flags)
Definition: bgp_peer.cc:1870
void inc_hold_timer_expired()
Definition: bgp_peer.cc:2768
uint64_t get_rx_route_total() const
Definition: bgp_peer.cc:2748
uint32_t cluster_id_
Definition: bgp_peer.h:516
bool GetBestAuthKeyItem(AuthenticationKey *auth_key)
boost::scoped_ptr< PeerCloseManager > close_manager_
Definition: bgp_peer.h:537
void ClearListenSocketAuthKey()
Definition: bgp_peer.cc:887
friend class StateMachineUnitTest
Definition: bgp_peer.h:374
virtual void UpdatePrimaryPathCount(int count, Address::Family family) const
Definition: bgp_peer.cc:2181
std::atomic< uint32_t > family_primary_path_count_[Address::NUM_FAMILIES]
Definition: bgp_peer.h:531
const std::string & peer_basename() const
Definition: bgp_peer.h:170
uint64_t get_open_error() const
Definition: bgp_peer.cc:2792
size_t buffer_size() const
Definition: bgp_peer.h:186
BgpSession * session_
Definition: bgp_peer.h:505
bool CheckPrefixLimits()
Definition: bgp_peer.cc:933
uint64_t get_socket_writes() const
Definition: bgp_peer.cc:2806
time_t eor_send_timer_start_time_
Definition: bgp_peer.h:509
virtual const std::vector< std::string > GetDefaultTunnelEncap(const Address::Family family) const
Definition: bgp_peer.cc:2140
virtual uint32_t local_bgp_identifier() const
Definition: bgp_peer.cc:1214
void StartPrefixLimitIdleTimer(uint32_t plim_idle_time_msecs)
Definition: bgp_peer.cc:2193
std::string gateway_address_string(Address::Family family) const
Definition: bgp_peer.cc:1239
uint64_t get_tx_update() const
Definition: bgp_peer.cc:2692
bool SetCapabilities(const BgpProto::OpenMessage *msg)
Definition: bgp_peer.cc:1707
void FillNeighborInfo(const BgpSandeshContext *bsc, BgpNeighborResp *bnr, bool summary) const
Definition: bgp_peer.cc:2597
uint64_t get_rx_route_reach() const
Definition: bgp_peer.cc:2728
const StateMachine * state_machine() const
Definition: bgp_peer.h:328
void StartKeepaliveTimer()
Definition: bgp_peer.cc:2294
OriginOverride origin_override_
Definition: bgp_peer.h:517
uint64_t get_hold_timer_expired() const
Definition: bgp_peer.cc:2788
uint32_t GetPathFlags(Address::Family family, const BgpAttr *attr) const
Definition: bgp_peer.cc:1900
void inc_rx_notification()
Definition: bgp_peer.cc:2696
std::string router_type() const
Definition: bgp_peer.h:171
bool KeepaliveTimerRunning()
Definition: bgp_peer.cc:2304
TaskTrigger prefix_limit_trigger_
Definition: bgp_peer.h:481
size_t buffer_capacity_
Definition: bgp_peer.h:503
uint64_t total_flap_count_
Definition: bgp_peer.h:544
void FillBgpNeighborFamilyAttributes(BgpNeighborResp *nbr) const
Definition: bgp_peer.cc:2574
uint64_t flap_count() const
Definition: bgp_peer.h:250
BgpSession * CreateSession()
Definition: bgp_peer.cc:1339
void RetryDelete()
Definition: bgp_peer.cc:2470
tbb::spin_mutex spin_mutex_
Definition: bgp_peer.h:502
std::string last_flap_at() const
Definition: bgp_peer.cc:2812
void ResetInuseAuthKeyInfo()
Definition: bgp_peer.cc:874
void inc_tx_update()
Definition: bgp_peer.cc:2688
int asn_listener_id_
Definition: bgp_peer.h:551
virtual void SendEndOfRIB(Address::Family family)
Definition: bgp_peer.cc:404
std::vector< std::string > negotiated_families_
Definition: bgp_peer.h:533
void inc_rx_end_of_rib()
Definition: bgp_peer.cc:2708
as_t local_as_
Definition: bgp_peer.h:526
FamilyAttributesList family_attributes_list_
Definition: bgp_peer.h:530
void SetInuseAuthKeyInfo(const AuthenticationKey &key, KeyType type)
Definition: bgp_peer.cc:869
void ProcessUpdate(const BgpProto::Update *msg, size_t msgsize=0)
Definition: bgp_peer.cc:1950
BgpTable * GetRTargetTable()
Definition: bgp_peer.cc:693
void inc_rx_keepalive()
Definition: bgp_peer.cc:2664
BgpAttrPtr GetRouteTargetRouteAttr() const
Definition: bgp_peer.cc:703
virtual void UpdateTotalPathCount(int count) const
Definition: bgp_peer.h:311
RoutingInstance * GetRoutingInstance() const
Definition: bgp_peer.h:204
uint64_t get_rx_route_unreach() const
Definition: bgp_peer.cc:2740
virtual bool notification() const
Definition: bgp_peer.cc:1679
virtual time_t GetRTargetTableLastUpdatedTimeStamp() const
Definition: bgp_peer.cc:327
AuthenticationKey inuse_auth_key_
Definition: bgp_peer.h:548
virtual ~BgpPeer()
Definition: bgp_peer.cc:624
void BGPaaSDeleteRTarget(as_t as, BgpTable *table, RouteTargetList::const_iterator it)
Definition: bgp_peer.cc:741
bool graceful_close_
Definition: bgp_peer.h:521
bool EndOfRibSendTimerExpired(Address::Family family)
Definition: bgp_peer.cc:331
bool PrefixLimitIdleTimerExpired()
Definition: bgp_peer.cc:2207
virtual void BindLocalEndpoint(BgpSession *session)
Definition: bgp_peer.cc:814
void inc_rx_open()
Definition: bgp_peer.cc:2656
uint64_t get_rx_update() const
Definition: bgp_peer.cc:2684
bool passive_
Definition: bgp_peer.h:512
virtual IPeerDebugStats * peer_stats()
Definition: bgp_peer.cc:1297
Timer * eor_receive_timer_[Address::NUM_FAMILIES]
Definition: bgp_peer.h:507
std::vector< uint8_t > buffer_
Definition: bgp_peer.h:504
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:879
virtual void ResetAs4Supported()
Definition: bgp_peer.h:316
void ProcessNlri(Address::Family family, DBRequest::DBOperation oper, const BgpMpNlri *nlri, BgpAttrPtr attr, uint32_t flags)
Definition: bgp_peer.cc:1812
void inc_open_error()
Definition: bgp_peer.cc:2772
void Initialize()
Definition: bgp_peer.cc:651
virtual bool IsAs4Supported() const
Definition: bgp_peer.h:315
uint64_t last_flap() const
Definition: bgp_peer.h:251
void DSCPUpdateCallback(uint8_t dscp_value)
Definition: bgp_peer.cc:2864
as_t peer_as() const
Definition: bgp_peer.h:185
void PostCloseRelease()
Definition: bgp_peer.cc:1186
bool AcceptSession(BgpSession *session)
Definition: bgp_peer.cc:1368
const BgpNeighborConfig * config() const
Definition: bgp_peer.h:214
void SetSendReady()
Definition: bgp_peer.cc:2309
uint64_t get_tx_route_total() const
Definition: bgp_peer.cc:2754
TcpSession::Endpoint endpoint_
Definition: bgp_peer.h:466
virtual void SendEndOfRIBActual(Address::Family family)
Definition: bgp_peer.cc:279
void ConfigUpdate(const BgpNeighborConfig *config)
Definition: bgp_peer.cc:991
uint64_t get_tx_end_of_rib() const
Definition: bgp_peer.cc:2720
Timer * keepalive_timer_
Definition: bgp_peer.h:506
std::vector< BgpPeerFamilyAttributes * > FamilyAttributesList
Definition: bgp_peer.h:388
int GetTaskInstance() const
Definition: bgp_peer.cc:2476
bool IsCloseGraceful() const
Definition: bgp_peer.cc:323
bool IsFamilyNegotiated(Address::Family family)
Definition: bgp_peer.cc:1173
virtual bool Is4ByteAsSupported() const
Definition: bgp_peer.cc:1807
void NotifyEstablished(bool established)
Definition: bgp_peer.cc:797
uint64_t get_update_error() const
Definition: bgp_peer.cc:2796
void ProcessEndpointConfig(const BgpNeighborConfig *config)
Definition: bgp_peer.cc:979
bool GetBestAuthKey(AuthenticationKey *auth_key, KeyType *key_type) const
Definition: bgp_peer.cc:818
PeerCloseManager * close_manager()
Definition: bgp_peer.h:356
uint64_t get_connect_timer_expired() const
Definition: bgp_peer.cc:2784
static const std::vector< Address::Family > & supported_families()
Definition: bgp_peer.h:352
as_t peer_as_
Definition: bgp_peer.h:527
void StartEndOfRibReceiveTimer(Address::Family family)
Definition: bgp_peer.cc:2244
int dscp_listener_id_
Definition: bgp_peer.h:546
virtual IPeerClose * peer_close()
Definition: bgp_peer.cc:1284
virtual bool CheckSplitHorizon(uint32_t cluster_id=0, uint32_t ribout_cid=0) const
Definition: bgp_peer.cc:676
virtual void StartKeepaliveTimerUnlocked()
Definition: bgp_peer.cc:2284
std::string bgp_identifier_string() const
Definition: bgp_peer.cc:1226
bool AttemptGRHelperMode(int code, int subcode) const
Definition: bgp_peer.cc:1684
AuthenticationData::KeyType KeyType
Definition: bgp_peer.h:91
string private_as_action_
Definition: bgp_peer.h:515
virtual BgpServer * server() const
Definition: bgp_peer.h:159
uint16_t peer_port() const
Definition: bgp_peer.h:166
std::set< Address::Family > AddressFamilyList
Definition: bgp_peer.h:90
bool resolve_paths_
Definition: bgp_peer.h:513
bool vpn_tables_registered_
Definition: bgp_peer.h:523
void SetSessionSocketOptionDscp(TcpSession *session)
Definition: bgp_peer.cc:902
std::string to_str_
Definition: bgp_peer.h:473
int index_
Definition: bgp_peer.h:478
void Register(BgpTable *table, const RibExportPolicy &policy)
Definition: bgp_peer.cc:1380
virtual void SetAdminState(bool down, int subcode=BgpProto::Notification::AdminShutdown)
Definition: bgp_peer.cc:1356
as_t local_as() const
Definition: bgp_peer.h:184
bool LookupFamily(Address::Family family)
Definition: bgp_peer.h:198
bool peer_is_control_node_
Definition: bgp_peer.h:472
static void FillBgpNeighborDebugState(BgpNeighborResp *bnr, const IPeerDebugStats *peer)
Definition: bgp_peer.cc:2533
virtual void TriggerPrefixLimitCheck() const
Definition: bgp_peer.cc:987
void inc_tx_keepalive()
Definition: bgp_peer.cc:2672
uint32_t GetLocalPrefFromMed(uint32_t med) const
Definition: bgp_peer.cc:1936
void AddRTargets(as_t as)
Definition: bgp_peer.cc:726
LifetimeActor * deleter()
Definition: bgp_peer.cc:1166
bool IsPassive() const
Definition: bgp_peer.h:223
virtual bool SendUpdate(const uint8_t *msg, size_t msgsize)
Definition: bgp_peer.h:108
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:58
Definition: timer.h:57
uint8_t type
Definition: load_balance.h:2
int operator()(const BgpPeerFamilyAttributes *lhs, const BgpPeerFamilyAttributes *rhs) const
Definition: bgp_peer.h:66
IpAddress gateway_address
Definition: bgp_peer.h:58
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:59
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:1608
bool operator!=(const OriginOverride &rhs) const
Definition: bgp_peer.cc:1614
BgpAttrOrigin::OriginType origin
Definition: bgp_peer.h:384
#define KEY_COMPARE(x, y)
Definition: util.h:70