Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef SRC_BGP_ROUTING_INSTANCE_PEER_MANAGER_H_ 6 : #define SRC_BGP_ROUTING_INSTANCE_PEER_MANAGER_H_ 7 : 8 : #include <boost/asio/ip/tcp.hpp> 9 : 10 : #include <map> 11 : #include <string> 12 : #include <vector> 13 : 14 : #include "bgp/bgp_peer_key.h" 15 : #include "bgp/ipeer.h" 16 : #include "io/tcp_session.h" 17 : 18 : class BgpPeer; 19 : class BgpServer; 20 : class RoutingInstance; 21 : class BgpNeighborResp; 22 : class BgpSandeshContext; 23 : 24 : class PeerManager { 25 : public: 26 : typedef std::multimap<BgpPeerKey, BgpPeer *> BgpPeerKeyMap; 27 : typedef std::map<std::string, BgpPeer *> BgpPeerNameMap; 28 : 29 8351 : explicit PeerManager(RoutingInstance *instance) : instance_(instance) { } 30 10466 : virtual ~PeerManager() { } 31 : 32 : virtual BgpPeer *PeerFind(std::string address) const; 33 : virtual BgpPeer *PeerLookup(std::string name) const; 34 : virtual BgpPeer *PeerLookup(TcpSession::Endpoint remote_endpoint) const; 35 : virtual BgpPeer *PeerLocate(BgpServer *server, 36 : const BgpNeighborConfig *config); 37 : void PeerResurrect(std::string name); 38 : BgpPeer *TriggerPeerDeletion(const BgpNeighborConfig *config); 39 : virtual void DestroyIPeer(IPeer *ipeer); 40 : void ClearAllPeers(); 41 : void ClearAllInternalPeers(); 42 : 43 : const BgpPeer *NextPeer(const BgpPeerKey &key) const; 44 : size_t GetNeighborCount(std::string up_or_down); 45 : 46 34 : size_t size() { return peers_by_key_.size(); } 47 : const std::string &name() const; 48 : const RoutingInstance *instance() const { return instance_; } 49 9571 : RoutingInstance *instance() { return instance_; } 50 : BgpServer *server() const; 51 : 52 : const BgpPeerKeyMap &peer_map() const { return peers_by_key_; } 53 17192 : BgpPeerKeyMap *peer_map_mutable() { return &peers_by_key_; } 54 : 55 : private: 56 : friend class PeerManagerTest; 57 : friend class BgpServerTest; 58 : 59 : void InsertPeerByKey(BgpPeerKey key, BgpPeer *peer); 60 : void RemovePeerByKey(BgpPeerKey key, BgpPeer *peer); 61 : void InsertPeerByName(const std::string name, BgpPeer *peer); 62 : void RemovePeerByName(const std::string name, BgpPeer *peer); 63 : 64 : BgpPeerKeyMap peers_by_key_; 65 : BgpPeerNameMap peers_by_name_; 66 : RoutingInstance *instance_; 67 : }; 68 : 69 : #endif // SRC_BGP_ROUTING_INSTANCE_PEER_MANAGER_H_