OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
controller_init.h
Go to the documentation of this file.
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>
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;
20 class AgentIfMapVmExport;
21 class XmlBase;
22 class XmppChannelConfig;
23 
25 public:
28 
29 private:
31 };
32 
34 public:
36  bool retry_xmpp_server, bool retry_dns_xmpp_server) :
38  retry_xmpp_server_(retry_xmpp_server),
39  retry_dns_xmpp_server_(retry_dns_xmpp_server) {}
41 
42  bool connect_xmpp_server() const {return retry_xmpp_server_;}
44 
45 private:
49 };
50 
52 public:
54  uint8_t channel_id, std::unique_ptr<XmlBase> dom,
55  bool config) :
57  peer_id_(peer_id), peer_state_(peer_state), channel_id_(channel_id),
58  dom_(std::move(dom)), config_(config) { }
59  virtual ~ControllerXmppData() { }
60 
61  xmps::PeerId peer_id() const {return peer_id_;}
63  uint8_t channel_id() const {return channel_id_;}
64  std::unique_ptr<XmlBase> dom() {return std::move(dom_);}
65  bool config() const {return config_;}
66 
67 private:
70  uint8_t channel_id_;
71  std::unique_ptr<XmlBase> dom_;
72  bool config_;
74 };
75 
77 public:
79  const boost::uuids::uuid &vm_uuid) :
80  del_(del), vmi_uuid_(vmi_uuid), vm_uuid_(vm_uuid) { }
82 
83  bool del_;
86 };
87 
89 public:
90  ControllerReConfigData(std::string service_name, std::vector<string> server_list);
92 
93  std::string service_name_;
94  std::vector<string> server_list_;
96 };
97 
99 public:
103  return channel_;
104  }
105 
106 private:
109 };
110 
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 
129 
130  uint32_t start;
131  uint32_t end;
133  };
134 
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();
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
159 
160  //Peer maintenace routines
161  uint8_t ActiveXmppConnectionCount();
163 
165  return agent_ifmap_vm_export_.get();
166  }
167 
168  //Start/stop eor processors
169  void StartEndOfRibTxTimer();
170  void StopEndOfRibTx();
171 
174  Agent *agent() {return agent_;}
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;
182  return fabric_multicast_label_range_[idx];
183  }
185  xmpp_channel_down_cb_ = xmpp_channel_down_cb;
186  }
187  void FlushTimedOutChannels(uint8_t index);
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
203  (const autogen::EnetTunnelEncapsulationListType &encap);
205  (const autogen::TunnelEncapsulationListType &encap);
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;
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 
229  boost::scoped_ptr<AgentIfMapVmExport> agent_ifmap_vm_export_;
238 };
239 
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
AgentIfMapVmExport * agent_ifmap_vm_export() const
uint32_t TypeBmap
Definition: nexthop.h:248
boost::shared_ptr< ControllerDelPeerData > ControllerDelPeerDataType
SandeshTraceBufferPtr ControllerInfoTraceBuf
DISALLOW_COPY_AND_ASSIGN(ControllerXmppData)
xmps::PeerId peer_id_
std::list< PeerPtr >::iterator BgpPeerIterator
DISALLOW_COPY_AND_ASSIGN(ControllerDelPeerData)
xmps::PeerState peer_state() const
void DelPeerWalkDoneProcess(AgentXmppChannel *ch)
SandeshTraceBufferPtr ControllerTxConfigTraceBuf1
void EnableWorkQueue()
bool VerifyXmppServerTimeout(uint32_t to)
std::unique_ptr< XmlBase > dom_
void SetAgentMcastLabelRange(uint8_t idx)
uint8_t ActiveXmppConnectionCount()
SandeshTraceBufferPtr ControllerRxConfigMessageTraceBuf1
VNController(Agent *agent)
boost::shared_ptr< ControllerReConfigData > ControllerReConfigDataType
void DnsXmppServerConnect()
DISALLOW_COPY_AND_ASSIGN(ControllerWorkQueueData)
const FabricMulticastLabelRange & fabric_multicast_label_range(uint8_t idx) const
boost::shared_ptr< ControllerXmppData > ControllerXmppDataType
SandeshTraceBufferPtr ControllerTxMessageTraceBuf1
boost::uuids::uuid uuid
void SetDscpConfig(XmppChannelConfig *xmpp_cfg) const
bool connect_xmpp_server() const
DISALLOW_COPY_AND_ASSIGN(ControllerReConfigData)
WorkQueue< ControllerWorkQueueDataType > work_queue_
bool config() const
bool connect_dns_xmpp_server() const
void RegisterControllerChangeCallback(XmppChannelDownCb xmpp_channel_down_cb)
boost::shared_ptr< TraceBuffer< SandeshTrace > > SandeshTraceBufferPtr
Definition: sandesh_trace.h:18
void StartDelPeerWalk(AgentXmppChannelPtr ch)
std::vector< AgentXmppChannelPtr > AgentXmppChannelList
void Enqueue(ControllerWorkQueueDataType data)
uint64_t multicast_sequence_number()
virtual ~ControllerReConfigData()
std::list< PeerPtr > BgpPeerList
uint8_t channel_id() const
void StartEndOfRibTxTimer()
void DisConnectDnsServer(uint8_t idx)
void DeleteAgentXmppChannel(uint8_t idx)
SandeshTraceBufferPtr ControllerTraceBuf
void DeleteConnectionInfo(const std::string &addr, bool is_dns) const
boost::uuids::uuid vm_uuid_
MacAddress GetTunnelMac(const autogen::EnetNextHopType &nh)
std::unique_ptr< XmlBase > dom()
xmps::PeerId peer_id() const
TunnelType::TypeBmap GetTypeBitmap(const autogen::EnetTunnelEncapsulationListType &encap)
std::vector< string > server_list_
Definition: agent.h:358
virtual ~ControllerDelPeerData()
AgentXmppChannelList delpeer_walks_
ControllerDelPeerData(AgentXmppChannel *ch)
ControllerVmiSubscribeData(bool del, const boost::uuids::uuid &vmi_uuid, const boost::uuids::uuid &vm_uuid)
void DelPeerWalkDone(AgentXmppChannel *ch)
boost::function< void(uint8_t)> XmppChannelDownCb
SandeshTraceBufferPtr ControllerTxMessageTraceBuf2
bool ApplyControllerReConfigInternal(std::vector< string >service_list)
xmps::PeerState peer_state_
FabricMulticastLabelRange fabric_multicast_label_range_[MAX_XMPP_SERVERS]
AgentXmppChannel * channel()
ControllerConnectRetryData(bool retry_xmpp_server, bool retry_dns_xmpp_server)
const std::string MakeConnectionPrefix(bool is_dns) const
void GracefulRestartConfigListener()
SandeshTraceBufferPtr ControllerRxRouteMessageTraceBuf2
boost::scoped_ptr< AgentIfMapVmExport > agent_ifmap_vm_export_
bool RxXmppMessageTrace(uint8_t peer_index, const std::string &to_address, int port, int size, const std::string &msg, const XmppStanza::XmppMessage *xmpp_msg)
SandeshTraceBufferPtr ControllerTxConfigTraceBuf2
bool IsWorkQueueEmpty() const
uint32_t controller_list_chksum_
boost::shared_ptr< ControllerConnectRetryData > ControllerConnectRetryDataType
boost::uuids::uuid vmi_uuid_
AgentXmppChannelList timed_out_channels_[MAX_XMPP_SERVERS]
virtual ~VNController()
#define MAX_XMPP_SERVERS
Definition: agent.h:291
void set_disable(bool disabled)
Definition: queue_task.h:319
boost::shared_ptr< ControllerWorkQueueData > ControllerWorkQueueDataType
virtual ~ControllerWorkQueueData()
void DisConnectControllerIfmapServer(uint8_t idx)
AgentXmppChannel * GetActiveXmppChannel()
boost::shared_ptr< AgentXmppChannel > AgentXmppChannelPtr
void FlushTimedOutChannels(uint8_t index)
BgpPeerList::const_iterator BgpPeerConstIterator
void XmppServerDisConnect()
AgentXmppChannelList::iterator AgentXmppChannelListIter
SandeshTraceBufferPtr ControllerRxRouteMessageTraceBuf1
XmppChannelDownCb xmpp_channel_down_cb_
bool TxXmppMessageTrace(uint8_t peer_index, const std::string &to_address, int port, int size, const std::string &msg, const XmppStanza::XmppMessage *xmpp_msg)
ControllerXmppData(xmps::PeerId peer_id, xmps::PeerState peer_state, uint8_t channel_id, std::unique_ptr< XmlBase > dom, bool config)
void XmppServerConnect()
Agent * agent()
void XmppServerUpdate(uint8_t time_out)
AgentXmppChannel * channel_
uint32_t dns_list_chksum_
ControllerReConfigData(std::string service_name, std::vector< string > server_list)
void DnsXmppServerDisConnect()
SandeshTraceBufferPtr ControllerRouteWalkerTraceBuf
uint64_t multicast_sequence_number_
bool AgentReConfigXmppServerConnectedExists(const std::string &server_ip, std::vector< std::string > resp)
bool ControllerWorkQueueProcess(ControllerWorkQueueDataType data)
void increment_multicast_sequence_number()
virtual ~ControllerXmppData()
AgentXmppChannel * FindAgentXmppChannel(const std::string &server_ip)
void ReConnectDnsServer()
void ReConnectXmppServer()
DISALLOW_COPY_AND_ASSIGN(ControllerConnectRetryData)
bool XmppMessageProcess(ControllerXmppDataType data)
void FillMcastLabelRange(uint32_t *star_idx, uint32_t *end_idx, uint8_t idx) const
AgentDnsXmppChannel * FindAgentDnsXmppChannel(const std::string &server_ip)
bool ApplyDnsReConfigInternal(std::vector< string >service_list)
SandeshTraceBufferPtr ControllerRxConfigMessageTraceBuf2