/
controller_init.h
158 lines (130 loc) · 5.49 KB
/
controller_init.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#ifndef __VNSW_CONTROLLER_INIT_HPP__
#define __VNSW_CONTROLLER_INIT_HPP__
#include <sandesh/sandesh_trace.h>
#include <discovery/client/discovery_client.h>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <controller/controller_cleanup_timer.h>
#include "xmpp/xmpp_channel.h"
class AgentXmppChannel;
class AgentDnsXmppChannel;
class AgentIfMapVmExport;
class BgpPeer;
class XmlBase;
class ControllerWorkQueueData {
public:
ControllerWorkQueueData() {}
virtual ~ControllerWorkQueueData() {}
private:
DISALLOW_COPY_AND_ASSIGN(ControllerWorkQueueData);
};
class ControllerDeletePeerData : public ControllerWorkQueueData {
public:
ControllerDeletePeerData(BgpPeer *bgp_peer) :
ControllerWorkQueueData(),
bgp_peer_(bgp_peer) {}
virtual ~ControllerDeletePeerData() {}
BgpPeer *bgp_peer() const {return bgp_peer_;}
private:
BgpPeer *bgp_peer_;
DISALLOW_COPY_AND_ASSIGN(ControllerDeletePeerData);
};
class ControllerXmppData : public ControllerWorkQueueData {
public:
ControllerXmppData(xmps::PeerId peer_id, xmps::PeerState peer_state,
uint8_t channel_id, std::auto_ptr<XmlBase> dom,
bool config) :
ControllerWorkQueueData(),
peer_id_(peer_id), peer_state_(peer_state), channel_id_(channel_id),
dom_(dom), config_(config) { }
virtual ~ControllerXmppData() { }
xmps::PeerId peer_id() const {return peer_id_;}
xmps::PeerState peer_state() const {return peer_state_;}
uint8_t channel_id() const {return channel_id_;}
std::auto_ptr<XmlBase> dom() {return dom_;}
bool config() const {return config_;}
private:
xmps::PeerId peer_id_;
xmps::PeerState peer_state_;
uint8_t channel_id_;
std::auto_ptr<XmlBase> dom_;
bool config_;
DISALLOW_COPY_AND_ASSIGN(ControllerXmppData);
};
class VNController {
public:
typedef boost::shared_ptr<ControllerXmppData> ControllerXmppDataType;
typedef boost::shared_ptr<ControllerDeletePeerData> ControllerDeletePeerDataType;
typedef boost::shared_ptr<ControllerWorkQueueData> ControllerWorkQueueDataType;
typedef boost::shared_ptr<BgpPeer> BgpPeerPtr;
typedef std::list<boost::shared_ptr<BgpPeer> >::iterator BgpPeerIterator;
VNController(Agent *agent);
virtual ~VNController();
void Connect();
void DisConnect();
void Cleanup();
void XmppServerConnect();
void DnsXmppServerConnect();
void XmppServerDisConnect();
void DnsXmppServerDisConnect();
void ApplyDiscoveryXmppServices(std::vector<DSResponse> resp);
void ApplyDiscoveryDnsXmppServices(std::vector<DSResponse> resp);
void DisConnectControllerIfmapServer(uint8_t idx);
void DisConnectDnsServer(uint8_t idx);
//Multicast peer identifier
void increment_multicast_sequence_number() {multicast_sequence_number_++;}
uint64_t multicast_sequence_number() {return multicast_sequence_number_;}
//Peer maintenace routines
uint8_t ActiveXmppConnectionCount();
AgentXmppChannel *GetActiveXmppChannel();
uint32_t DecommissionedPeerListSize() const {
return decommissioned_peer_list_.size();
}
void AddToDecommissionedPeerList(boost::shared_ptr<BgpPeer> peer);
//Unicast timer related routines
void StartUnicastCleanupTimer(AgentXmppChannel *agent_xmpp_channel);
void UnicastCleanupTimerExpired();
CleanupTimer &unicast_cleanup_timer() {return unicast_cleanup_timer_;}
void ControllerPeerHeadlessAgentDelDoneEnqueue(BgpPeer *peer);
bool ControllerPeerHeadlessAgentDelDone(BgpPeer *peer);
//Multicast timer
void StartMulticastCleanupTimer(AgentXmppChannel *agent_xmpp_channel);
void MulticastCleanupTimerExpired(uint64_t peer_sequence);
CleanupTimer &multicast_cleanup_timer() {return multicast_cleanup_timer_;}
AgentIfMapVmExport *agent_ifmap_vm_export() const {
return agent_ifmap_vm_export_.get();
}
void StartConfigCleanupTimer(AgentXmppChannel *agent_xmpp_channel);
CleanupTimer &config_cleanup_timer() {return config_cleanup_timer_;}
// Clear of decommissioned peer listener id for vrf specified
void DeleteVrfStateOfDecommisionedPeers(DBTablePartBase *partition,
DBEntryBase *e);
bool ControllerWorkQueueProcess(ControllerWorkQueueDataType data);
bool XmppMessageProcess(ControllerXmppDataType data);
Agent *agent() {return agent_;}
void Enqueue(ControllerWorkQueueDataType data);
private:
AgentXmppChannel *FindAgentXmppChannel(const std::string &server_ip);
AgentDnsXmppChannel *FindAgentDnsXmppChannel(const std::string &server_ip);
void DeleteConnectionInfo(const std::string &addr, bool is_dns) const;
const std::string MakeConnectionPrefix(bool is_dns) const;
bool AgentXmppServerExists(const std::string &server_ip,
std::vector<DSResponse> resp);
Agent *agent_;
uint64_t multicast_sequence_number_;
std::list<boost::shared_ptr<BgpPeer> > decommissioned_peer_list_;
boost::scoped_ptr<AgentIfMapVmExport> agent_ifmap_vm_export_;
UnicastCleanupTimer unicast_cleanup_timer_;
MulticastCleanupTimer multicast_cleanup_timer_;
ConfigCleanupTimer config_cleanup_timer_;
WorkQueue<ControllerWorkQueueDataType> work_queue_;
};
extern SandeshTraceBufferPtr ControllerTraceBuf;
#define CONTROLLER_TRACE(obj, ...)\
do {\
AgentXmpp##obj::TraceMsg(ControllerTraceBuf, __FILE__, __LINE__, __VA_ARGS__);\
} while(0);\
#endif