Line data Source code
1 : /*
2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3 : */
4 :
5 : #ifndef __VNSW_CONTROLLER_INIT_HPP__
6 : #define __VNSW_CONTROLLER_INIT_HPP__
7 :
8 : #include <sandesh/sandesh_trace.h>
9 : #include <boost/scoped_ptr.hpp>
10 : #include <boost/shared_ptr.hpp>
11 : #include <controller/controller_timer.h>
12 : #include "xmpp/xmpp_channel.h"
13 : #include <xmpp_enet_types.h>
14 : #include <xmpp_unicast_types.h>
15 : #include <xmpp_multicast_types.h>
16 : #include <oper/route_common.h>
17 :
18 : class AgentXmppChannel;
19 : class AgentDnsXmppChannel;
20 : class AgentIfMapVmExport;
21 : class XmlBase;
22 : class XmppChannelConfig;
23 :
24 : class ControllerWorkQueueData {
25 : public:
26 27 : ControllerWorkQueueData() {}
27 27 : virtual ~ControllerWorkQueueData() {}
28 :
29 : private:
30 : DISALLOW_COPY_AND_ASSIGN(ControllerWorkQueueData);
31 : };
32 :
33 : class ControllerConnectRetryData : public ControllerWorkQueueData {
34 : public:
35 0 : ControllerConnectRetryData(
36 0 : bool retry_xmpp_server, bool retry_dns_xmpp_server) :
37 : ControllerWorkQueueData(),
38 0 : retry_xmpp_server_(retry_xmpp_server),
39 0 : retry_dns_xmpp_server_(retry_dns_xmpp_server) {}
40 0 : virtual ~ControllerConnectRetryData() {}
41 :
42 0 : bool connect_xmpp_server() const {return retry_xmpp_server_;}
43 0 : bool connect_dns_xmpp_server() const {return retry_dns_xmpp_server_;}
44 :
45 : private:
46 : bool retry_xmpp_server_;
47 : bool retry_dns_xmpp_server_;
48 : DISALLOW_COPY_AND_ASSIGN(ControllerConnectRetryData);
49 : };
50 :
51 : class ControllerXmppData : public ControllerWorkQueueData {
52 : public:
53 0 : ControllerXmppData(xmps::PeerId peer_id, xmps::PeerState peer_state,
54 : uint8_t channel_id, std::unique_ptr<XmlBase> dom,
55 0 : bool config) :
56 : ControllerWorkQueueData(),
57 0 : peer_id_(peer_id), peer_state_(peer_state), channel_id_(channel_id),
58 0 : dom_(std::move(dom)), config_(config) { }
59 0 : virtual ~ControllerXmppData() { }
60 :
61 0 : xmps::PeerId peer_id() const {return peer_id_;}
62 0 : xmps::PeerState peer_state() const {return peer_state_;}
63 0 : uint8_t channel_id() const {return channel_id_;}
64 0 : std::unique_ptr<XmlBase> dom() {return std::move(dom_);}
65 0 : bool config() const {return config_;}
66 :
67 : private:
68 : xmps::PeerId peer_id_;
69 : xmps::PeerState peer_state_;
70 : uint8_t channel_id_;
71 : std::unique_ptr<XmlBase> dom_;
72 : bool config_;
73 : DISALLOW_COPY_AND_ASSIGN(ControllerXmppData);
74 : };
75 :
76 : class ControllerVmiSubscribeData : public ControllerWorkQueueData {
77 : public:
78 24 : ControllerVmiSubscribeData(bool del, const boost::uuids::uuid &vmi_uuid,
79 24 : const boost::uuids::uuid &vm_uuid) :
80 24 : del_(del), vmi_uuid_(vmi_uuid), vm_uuid_(vm_uuid) { }
81 48 : virtual ~ControllerVmiSubscribeData() {}
82 :
83 : bool del_;
84 : boost::uuids::uuid vmi_uuid_;
85 : boost::uuids::uuid vm_uuid_;
86 : };
87 :
88 : class ControllerReConfigData : public ControllerWorkQueueData {
89 : public:
90 : ControllerReConfigData(std::string service_name, std::vector<string> server_list);
91 0 : virtual ~ControllerReConfigData() {}
92 :
93 : std::string service_name_;
94 : std::vector<string> server_list_;
95 : DISALLOW_COPY_AND_ASSIGN(ControllerReConfigData);
96 : };
97 :
98 : class ControllerDelPeerData : public ControllerWorkQueueData {
99 : public:
100 : ControllerDelPeerData(AgentXmppChannel *ch);
101 4 : virtual ~ControllerDelPeerData() {}
102 2 : AgentXmppChannel *channel() {
103 2 : return channel_;
104 : }
105 :
106 : private:
107 : AgentXmppChannel *channel_;
108 : DISALLOW_COPY_AND_ASSIGN(ControllerDelPeerData);
109 : };
110 :
111 : class VNController {
112 : public:
113 : typedef boost::function<void(uint8_t)> XmppChannelDownCb;
114 : typedef boost::shared_ptr<ControllerXmppData> ControllerXmppDataType;
115 : typedef boost::shared_ptr<ControllerConnectRetryData> ControllerConnectRetryDataType;
116 : typedef boost::shared_ptr<ControllerWorkQueueData> ControllerWorkQueueDataType;
117 : typedef boost::shared_ptr<ControllerReConfigData> ControllerReConfigDataType;
118 : typedef boost::shared_ptr<ControllerDelPeerData> ControllerDelPeerDataType;
119 : typedef std::list<PeerPtr> BgpPeerList;
120 : typedef BgpPeerList::const_iterator BgpPeerConstIterator;
121 : typedef std::list<PeerPtr>::iterator BgpPeerIterator;
122 : typedef boost::shared_ptr<AgentXmppChannel> AgentXmppChannelPtr;
123 : typedef std::vector<AgentXmppChannelPtr> AgentXmppChannelList;
124 : typedef AgentXmppChannelList::iterator AgentXmppChannelListIter;
125 :
126 : struct FabricMulticastLabelRange {
127 2 : FabricMulticastLabelRange() : start(), end(), fabric_multicast_label_range_str() {};
128 2 : ~FabricMulticastLabelRange() {};
129 :
130 : uint32_t start;
131 : uint32_t end;
132 : std::string fabric_multicast_label_range_str;
133 : };
134 :
135 : VNController(Agent *agent);
136 : virtual ~VNController();
137 : void Connect();
138 : void DisConnect();
139 : void ReConnect();
140 : void ReConnectXmppServer();
141 : void ReConnectDnsServer();
142 :
143 : void Cleanup();
144 :
145 : void XmppServerConnect();
146 : void DnsXmppServerConnect();
147 :
148 : void XmppServerDisConnect();
149 : void DnsXmppServerDisConnect();
150 : void XmppServerUpdate(uint8_t time_out);
151 : bool VerifyXmppServerTimeout(uint32_t to);
152 :
153 : void DisConnectControllerIfmapServer(uint8_t idx);
154 : void DisConnectDnsServer(uint8_t idx);
155 :
156 : //Multicast peer identifier
157 5 : void increment_multicast_sequence_number() {multicast_sequence_number_++;}
158 1 : uint64_t multicast_sequence_number() {return multicast_sequence_number_;}
159 :
160 : //Peer maintenace routines
161 : uint8_t ActiveXmppConnectionCount();
162 : AgentXmppChannel *GetActiveXmppChannel();
163 :
164 1 : AgentIfMapVmExport *agent_ifmap_vm_export() const {
165 1 : return agent_ifmap_vm_export_.get();
166 : }
167 :
168 : //Start/stop eor processors
169 : void StartEndOfRibTxTimer();
170 : void StopEndOfRibTx();
171 :
172 : bool ControllerWorkQueueProcess(ControllerWorkQueueDataType data);
173 : bool XmppMessageProcess(ControllerXmppDataType data);
174 : Agent *agent() {return agent_;}
175 : void Enqueue(ControllerWorkQueueDataType data);
176 : void DeleteAgentXmppChannel(uint8_t idx);
177 : void SetAgentMcastLabelRange(uint8_t idx);
178 : void FillMcastLabelRange(uint32_t *star_idx,
179 : uint32_t *end_idx,
180 : uint8_t idx) const;
181 1 : const FabricMulticastLabelRange &fabric_multicast_label_range(uint8_t idx) const {
182 1 : return fabric_multicast_label_range_[idx];
183 : }
184 1 : void RegisterControllerChangeCallback(XmppChannelDownCb xmpp_channel_down_cb) {
185 1 : xmpp_channel_down_cb_ = xmpp_channel_down_cb;
186 1 : }
187 : void FlushTimedOutChannels(uint8_t index);
188 : void DelPeerWalkDone(AgentXmppChannel *ch);
189 : void DelPeerWalkDoneProcess(AgentXmppChannel *ch);
190 : void StartDelPeerWalk(AgentXmppChannelPtr ch);
191 : bool RxXmppMessageTrace(uint8_t peer_index,
192 : const std::string &to_address,
193 : int port, int size,
194 : const std::string &msg,
195 : const XmppStanza::XmppMessage *xmpp_msg);
196 : bool TxXmppMessageTrace(uint8_t peer_index,
197 : const std::string &to_address,
198 : int port, int size,
199 : const std::string &msg,
200 : const XmppStanza::XmppMessage *xmpp_msg);
201 : //Tunnel type helpers
202 : TunnelType::TypeBmap GetTypeBitmap
203 : (const autogen::EnetTunnelEncapsulationListType &encap);
204 : TunnelType::TypeBmap GetTypeBitmap
205 : (const autogen::TunnelEncapsulationListType &encap);
206 : TunnelType::TypeBmap GetTypeBitmap
207 : (const autogen::McastTunnelEncapsulationListType &encap);
208 : //Tunnel Mac helpers
209 : MacAddress GetTunnelMac(const autogen::EnetNextHopType &nh);
210 : MacAddress GetTunnelMac(const autogen::NextHopType &nh);
211 : //Unit test helpers
212 : bool IsWorkQueueEmpty() const;
213 1 : void EnableWorkQueue() { work_queue_.set_disable(false); }
214 : void GracefulRestartConfigListener();
215 :
216 : private:
217 : void SetDscpConfig(XmppChannelConfig *xmpp_cfg) const;
218 : AgentXmppChannel *FindAgentXmppChannel(const std::string &server_ip);
219 : AgentDnsXmppChannel *FindAgentDnsXmppChannel(const std::string &server_ip);
220 : void DeleteConnectionInfo(const std::string &addr, bool is_dns) const;
221 : const std::string MakeConnectionPrefix(bool is_dns) const;
222 : bool AgentReConfigXmppServerConnectedExists(const std::string &server_ip,
223 : std::vector<std::string> resp);
224 : bool ApplyControllerReConfigInternal(std::vector<string>service_list);
225 : bool ApplyDnsReConfigInternal(std::vector<string>service_list);
226 :
227 : Agent *agent_;
228 : uint64_t multicast_sequence_number_;
229 : boost::scoped_ptr<AgentIfMapVmExport> agent_ifmap_vm_export_;
230 : WorkQueue<ControllerWorkQueueDataType> work_queue_;
231 : FabricMulticastLabelRange fabric_multicast_label_range_[MAX_XMPP_SERVERS];
232 : XmppChannelDownCb xmpp_channel_down_cb_;
233 : uint32_t controller_list_chksum_;
234 : uint32_t dns_list_chksum_;
235 : AgentXmppChannelList timed_out_channels_[MAX_XMPP_SERVERS];
236 : AgentXmppChannelList delpeer_walks_;
237 : bool disconnect_;
238 : };
239 :
240 : extern SandeshTraceBufferPtr ControllerInfoTraceBuf;
241 : extern SandeshTraceBufferPtr ControllerTxConfigTraceBuf1;
242 : extern SandeshTraceBufferPtr ControllerTxConfigTraceBuf2;
243 : extern SandeshTraceBufferPtr ControllerRouteWalkerTraceBuf;
244 : extern SandeshTraceBufferPtr ControllerTraceBuf;
245 : extern SandeshTraceBufferPtr ControllerRxRouteMessageTraceBuf1;
246 : extern SandeshTraceBufferPtr ControllerRxConfigMessageTraceBuf1;
247 : extern SandeshTraceBufferPtr ControllerRxRouteMessageTraceBuf2;
248 : extern SandeshTraceBufferPtr ControllerRxConfigMessageTraceBuf2;
249 : extern SandeshTraceBufferPtr ControllerTxMessageTraceBuf1;
250 : extern SandeshTraceBufferPtr ControllerTxMessageTraceBuf2;
251 :
252 : #define CONTROLLER_RX_ROUTE_MESSAGE_TRACE(obj, index, ...)\
253 : do {\
254 : if (index == 0) { \
255 : AgentXmpp##obj::TraceMsg(ControllerRxRouteMessageTraceBuf1, __FILE__, \
256 : __LINE__, __VA_ARGS__);\
257 : } else { \
258 : AgentXmpp##obj::TraceMsg(ControllerRxRouteMessageTraceBuf2, __FILE__, \
259 : __LINE__, __VA_ARGS__);\
260 : } \
261 : } while (false)
262 :
263 : #define CONTROLLER_RX_CONFIG_MESSAGE_TRACE(obj, index, ...)\
264 : do {\
265 : if (index == 0) { \
266 : AgentXmpp##obj::TraceMsg(ControllerRxConfigMessageTraceBuf1, __FILE__, \
267 : __LINE__, __VA_ARGS__);\
268 : } else { \
269 : AgentXmpp##obj::TraceMsg(ControllerRxConfigMessageTraceBuf2, __FILE__, \
270 : __LINE__, __VA_ARGS__);\
271 : } \
272 : } while (false)
273 :
274 : #define CONTROLLER_INFO_TRACE(obj, ...)\
275 : do {\
276 : AgentXmpp##obj::TraceMsg(ControllerInfoTraceBuf, __FILE__, __LINE__, __VA_ARGS__);\
277 : } while (false)
278 :
279 : #define CONTROLLER_TX_CONFIG_TRACE(obj, index, ...)\
280 : do {\
281 : if (index == 0) { \
282 : AgentXmpp##obj::TraceMsg(ControllerTxConfigTraceBuf1, __FILE__, __LINE__, __VA_ARGS__);\
283 : } else { \
284 : AgentXmpp##obj::TraceMsg(ControllerTxConfigTraceBuf2, __FILE__, __LINE__, __VA_ARGS__);\
285 : } \
286 : } while (false)
287 :
288 : #define CONTROLLER_ROUTE_WALKER_TRACE(obj, ...)\
289 : do {\
290 : AgentXmpp##obj::TraceMsg(ControllerRouteWalkerTraceBuf, __FILE__, __LINE__, __VA_ARGS__);\
291 : } while (false)
292 :
293 : #define CONTROLLER_CONNECTIONS_TRACE(obj, ...)\
294 : do {\
295 : AgentXmpp##obj::TraceMsg(ControllerConnectionsTraceBuf, __FILE__, __LINE__, __VA_ARGS__);\
296 : } while (false)
297 :
298 : #define CONTROLLER_TRACE(obj, ...)\
299 : do {\
300 : AgentXmpp##obj::TraceMsg(ControllerTraceBuf, __FILE__, __LINE__, __VA_ARGS__);\
301 : } while (false)
302 :
303 : #define CONTROLLER_TX_MESSAGE_TRACE(obj, index, ...)\
304 : do {\
305 : if (index == 0) { \
306 : AgentXmpp##obj::TraceMsg(ControllerTxMessageTraceBuf1, __FILE__, \
307 : __LINE__, __VA_ARGS__);\
308 : } else { \
309 : AgentXmpp##obj::TraceMsg(ControllerTxMessageTraceBuf2, __FILE__, \
310 : __LINE__, __VA_ARGS__);\
311 : } \
312 : } while (false)
313 :
314 : #endif
|