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