OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
controller_peer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef __CONTROLLER_PEER_H__
6 #define __CONTROLLER_PEER_H__
7 
8 #include <map>
9 #include <string>
10 
11 #include <boost/function.hpp>
12 #include <boost/system/error_code.hpp>
13 #include <boost/scoped_ptr.hpp>
14 #include <boost/shared_ptr.hpp>
15 #include <cmn/agent.h>
16 #include <oper/peer.h>
17 #include <pugixml/pugixml.hpp>
18 #include <xmpp_enet_types.h>
19 #include <xmpp_unicast_types.h>
20 #include <xmpp/xmpp_channel.h>
21 
22 class AgentRoute;
23 class Peer;
24 class BgpPeer;
25 class VrfEntry;
26 class XmlPugi;
27 class PathPreference;
28 class AgentPath;
29 class EcmpLoadBalance;
30 struct ControllerTimer;
31 struct EndOfRibTxTimer;
32 struct EndOfRibRxTimer;
33 struct LlgrStaleTimer;
35 
36 class XmlWriter : public pugi::xml_writer {
37 public:
38  explicit XmlWriter(std::string *repr) : repr_(repr) { }
39  virtual void write(const void *data, size_t size) {
40  repr_->append(static_cast<const char*>(data), size);
41  }
42 private:
43  std::string *repr_;
44 };
45 
47 public:
49  const std::string &xmpp_server,
50  const std::string &label_range, uint8_t xs_idx);
51  virtual ~AgentXmppChannel();
52 
53  virtual std::string ToString() const;
54  virtual bool SendUpdate(const uint8_t *msg, size_t msgsize);
55  virtual void ReceiveUpdate(const XmppStanza::XmppMessage *msg);
56  virtual void ReceiveEvpnUpdate(XmlPugi *pugi);
57  virtual void ReceiveMulticastUpdate(XmlPugi *pugi);
58  virtual void ReceiveMvpnUpdate(XmlPugi *pugi);
59  virtual void ReceiveV4V6Update(XmlPugi *pugi);
60  virtual void ReceiveInet4MplsUpdate(XmlPugi *pugi);
62  void ReceiveBgpMessage(std::unique_ptr<XmlBase> impl);
63 
64  //Helper to identify if specified peer has active BGP peer attached
65  static bool IsXmppChannelActive(const Agent *agent, AgentXmppChannel *peer);
66  static bool IsBgpPeerActive(const Agent *agent, AgentXmppChannel *peer);
67  static bool SetConfigPeer(AgentXmppChannel *peer);
68  static void SetMulticastPeer(AgentXmppChannel *old_peer,
69  AgentXmppChannel *new_peer);
70  static void CleanConfigStale(AgentXmppChannel *agent_xmpp_channel);
71  static void XmppClientChannelEvent(AgentXmppChannel *peer,
72  xmps::PeerState state);
74  xmps::PeerState state);
77  const boost::uuids::uuid &vm_id, bool subscribe);
78  static bool ControllerSendSubscribe(AgentXmppChannel *peer,
79  VrfEntry *vrf,
80  bool subscribe);
81  static bool ControllerSendRouteAdd(AgentXmppChannel *peer,
82  AgentRoute *route,
83  const Ip4Address *nexthop_ip,
84  const VnListType &vn_list,
85  uint32_t label,
86  uint32_t tunnel_bmap,
87  const SecurityGroupList *sg_list,
88  const TagList *tag_list,
89  const CommunityList *communities,
91  const PathPreference &path_preference,
92  const EcmpLoadBalance &ecmp_load_balance,
93  uint32_t native_vrf_id);
95  AgentRoute *route,
96  const Ip4Address *nexthop_ip,
97  std::string vn,
98  uint32_t mpls_label,
99  uint32_t tunnel_bmap,
100  const SecurityGroupList *sg_list,
101  const TagList *tag_list,
102  const CommunityList *communities,
103  const std::string &destination,
104  const std::string &source,
105  const PathPreference &path_preference);
107  AgentRoute *route);
108  //Deletes to control node
110  AgentRoute *route,
111  const VnListType &vn_list,
112  uint32_t label,
113  uint32_t tunnel_bmap,
114  const SecurityGroupList *sg_list,
115  const TagList *tag_list,
116  const CommunityList *communities,
118  const PathPreference &path_preference);
120  AgentRoute *route,
121  std::string vn,
122  uint32_t mpls_label,
123  const std::string &destination,
124  const std::string &source,
125  uint32_t tunnel_bmap);
127  AgentRoute *route);
128  //Channel event handlers
129  void Ready();
130  void NotReady();
131  void TimedOut();
132 
133  //End of rib rx/tx
134  void StartEndOfRibTxWalker();
135  void StopEndOfRibTxWalker();
136  void EndOfRibTx();
137  void EndOfRibRx();
138 
139  // Routines for BGP peer manipulations, lifecycle of bgp peer in xmpp
140  // channel is as follows:
141  // 1) Created whenever channel is xmps::READY
142  // 2) When channel moves out of READY state, bgp peer moves to decommisioned
143  // list. Once moved there it can never go back to active peer and can only
144  // get deleted later.
145  // 3) On arrival of some other active peer(i.e. channel is READY) cleanup
146  // timers are started, expiration of which triggers removal of
147  // decommissioned peer and eventually gets destroyed.
148  void CreateBgpPeer();
149  void RegisterXmppChannel(XmppChannel *channel);
150 
151  std::string GetXmppServer() { return xmpp_server_; }
152  uint8_t GetXmppServerIdx() { return xs_idx_; }
153  std::string GetMcastLabelRange() { return label_range_; }
154 
155  Agent *agent() const {return agent_;}
157  return static_cast<BgpPeer *>(bgp_peer_id_.get());
158  }
160  std::string GetBgpPeerName() const;
163  const Ip4Address *nexthop_ip,
164  std::string vn,
165  const SecurityGroupList *sg_list,
166  const TagList *tag_list,
167  const CommunityList *communities,
168  uint32_t mpls_label,
169  uint32_t tunnel_bmap,
170  const std::string &destination,
171  const std::string &source,
172  const PathPreference &path_preference,
173  bool associate);
175  bool associate);
176  bool ControllerSendIPMcastRouteCommon(AgentRoute *route, bool associate);
177  bool ControllerSendMvpnRouteCommon(AgentRoute *route, bool associate);
178  bool BuildEvpnMulticastMessage(autogen::EnetItemType &item,
179  std::stringstream &node_id,
180  AgentRoute *route,
181  const Ip4Address *nh_ip,
182  const std::string &vn,
183  const SecurityGroupList *sg_list,
184  const TagList *tag_list,
185  const CommunityList *communities,
186  uint32_t label,
187  uint32_t tunnel_bmap,
188  bool associate,
189  const AgentPath *path,
190  bool assisted_replication);
191  void AddMulticastEvpnRoute(const std::string &vrf_name,
192  const IpAddress &source,
193  const IpAddress &group,
194  autogen::EnetItemType *item);
195  void AddEvpnRoute(const std::string &vrf_name, std::string mac_addr,
196  const IpAddress &ip, uint32_t plen,
197  autogen::EnetItemType *item);
198  void AddEvpnEcmpRoute(std::string vrf_name, const MacAddress &mac,
199  const IpAddress &ip, uint32_t plen,
200  autogen::EnetItemType *item,
201  const VnListType &vn_list);
202  template <typename TYPE>
203  void BuildTagList(const TYPE *item, TagList *tag_list);
204  uint64_t route_published_time() const {return route_published_time_;}
208  //Sequence number for this channel
209  uint64_t sequence_number() const;
210  void Unregister();
211 
212 protected:
213  virtual void WriteReadyCb(const boost::system::error_code &ec);
214 
215 private:
216  void AddFabricVrfRoute(const Ip4Address &prefix_addr,
217  uint32_t prefix_len,
218  const Ip4Address &addr,
219  const VnListType &vn_list,
220  const SecurityGroupList &sg_list,
221  const TagList &tag_list);
222  void PeerIsNotConfig();
223  InetUnicastAgentRouteTable *PrefixToRouteTable(const std::string &vrf_name,
224  const IpAddress &prefix_addr);
225  InetUnicastAgentRouteTable *PrefixToRouteMplsTable(const std::string &vrf_name,
226  const IpAddress &prefix_addr);
227  void ReceiveInternal(const XmppStanza::XmppMessage *msg);
228  void AddRoute(std::string vrf_name, IpAddress ip, uint32_t plen,
229  autogen::ItemType *item);
230  void AddMplsRoute(std::string vrf_name, IpAddress ip, uint32_t plen,
231  autogen::ItemType *item);
232  void AddMulticastEvpnRoute(const std::string &vrf_name,
233  const MacAddress &mac,
234  autogen::EnetItemType *item);
235  void AddRemoteMplsRoute(std::string vrf_name, IpAddress ip, uint32_t plen,
236  autogen::ItemType *item,
237  const VnListType &vn_list);
238  void AddRemoteRoute(std::string vrf_name, IpAddress prefix_addr,
239  uint32_t prefix_len, autogen::ItemType *item,
240  const VnListType &vn_list);
241  void AddInetEcmpRoute(std::string vrf_name, IpAddress ip, uint32_t plen,
242  autogen::ItemType *item,
243  const VnListType &vn_list);
244  void AddInetMplsEcmpRoute(std::string vrf_name, IpAddress ip, uint32_t plen,
245  autogen::ItemType *item,
246  const VnListType &vn_list);
247  template <typename TYPE>
249  const VnListType &vn_list,
250  const EcmpLoadBalance &ecmp_load_balance,
251  const AgentRouteTable *rt_table,
252  const std::string &prefix_str);
253  //Common helpers
255  const VnListType &vn_list,
256  const SecurityGroupList *sg_list,
257  const TagList *tag_list,
258  const CommunityList *communities,
259  uint32_t mpls_label,
260  uint32_t tunnel_bmap,
261  const PathPreference &path_preference,
262  bool associate,
264  const EcmpLoadBalance &ecmp_load_balance,
265  uint32_t native_vrf_id);
266  bool BuildTorMulticastMessage(autogen::EnetItemType &item,
267  std::stringstream &node_id,
268  AgentRoute *route,
269  const Ip4Address *nh_ip,
270  const std::string &vn,
271  const SecurityGroupList *sg_list,
272  const TagList *tag_list,
273  const CommunityList *communities,
274  uint32_t label,
275  uint32_t tunnel_bmap,
276  const std::string &destination,
277  const std::string &source,
278  bool associate);
279  bool BuildEvpnUnicastMessage(autogen::EnetItemType &item,
280  std::stringstream &node_id,
281  AgentRoute *route,
282  const Ip4Address *nh_ip,
283  const std::string &vn,
284  const SecurityGroupList *sg_list,
285  const TagList *tag_list,
286  const CommunityList *communities,
287  uint32_t label,
288  uint32_t tunnel_bmap,
289  const PathPreference &path_prefernce,
290  bool associate);
291  bool BuildAndSendEvpnDom(autogen::EnetItemType &item,
292  std::stringstream &ss_node,
293  const AgentRoute *route,
294  bool associate);
295  template <typename TYPE> bool IsEcmp(const TYPE &nexthops);
296  template <typename TYPE> void GetVnList(const TYPE &nexthops,
297  VnListType *vn_list);
298 
300  std::string channel_str_;
301  std::string xmpp_server_;
302  std::string label_range_;
303  uint8_t xs_idx_;
306  boost::scoped_ptr<EndOfRibTxTimer> end_of_rib_tx_timer_;
307  boost::scoped_ptr<EndOfRibRxTimer> end_of_rib_rx_timer_;
308  boost::scoped_ptr<LlgrStaleTimer> llgr_stale_timer_;
310 };
311 
312 #endif // __CONTROLLER_PEER_H__
XmppChannel * GetXmppChannel()
bool BuildAndSendEvpnDom(autogen::EnetItemType &item, std::stringstream &ss_node, const AgentRoute *route, bool associate)
virtual std::string ToString() const
void AddRoute(std::string vrf_name, IpAddress ip, uint32_t plen, autogen::ItemType *item)
Definition: vrf.h:86
uint64_t route_published_time() const
std::string GetMcastLabelRange()
Agent supports multiple route tables - Inet-unicast (IPv4/IPv6), Inet-multicast, bridge, EVPN (Type2/Type5). This base class contains common code for all types of route tables.
Definition: agent_route.h:109
virtual void ReceiveInet4MplsUpdate(XmlPugi *pugi)
void GetVnList(const TYPE &nexthops, VnListType *vn_list)
bool IsEcmp(const TYPE &nexthops)
void ReceiveInternal(const XmppStanza::XmppMessage *msg)
boost::asio::ip::address IpAddress
Definition: address.h:13
static bool ControllerSendRouteAdd(AgentXmppChannel *peer, AgentRoute *route, const Ip4Address *nexthop_ip, const VnListType &vn_list, uint32_t label, uint32_t tunnel_bmap, const SecurityGroupList *sg_list, const TagList *tag_list, const CommunityList *communities, Agent::RouteTableType type, const PathPreference &path_preference, const EcmpLoadBalance &ecmp_load_balance, uint32_t native_vrf_id)
EndOfRibTxTimer * end_of_rib_tx_timer()
InetUnicastAgentRouteTable * PrefixToRouteMplsTable(const std::string &vrf_name, const IpAddress &prefix_addr)
void AddMplsRoute(std::string vrf_name, IpAddress ip, uint32_t plen, autogen::ItemType *item)
std::vector< int > SecurityGroupList
Definition: agent.h:201
EndOfRibRxTimer * end_of_rib_rx_timer()
void AddRemoteMplsRoute(std::string vrf_name, IpAddress ip, uint32_t plen, autogen::ItemType *item, const VnListType &vn_list)
boost::intrusive_ptr< Peer > PeerPtr
Definition: peer.h:42
boost::uuids::uuid uuid
void UpdateConnectionInfo(xmps::PeerState state)
boost::scoped_ptr< EndOfRibRxTimer > end_of_rib_rx_timer_
bool ControllerSendMvpnRouteCommon(AgentRoute *route, bool associate)
boost::scoped_ptr< LlgrStaleTimer > llgr_stale_timer_
virtual void write(const void *data, size_t size)
static bool ControllerSendVmCfgSubscribe(AgentXmppChannel *peer, const boost::uuids::uuid &vm_id, bool subscribe)
static void SetMulticastPeer(AgentXmppChannel *old_peer, AgentXmppChannel *new_peer)
Base class for all Route entries in agent.
Definition: agent_route.h:224
static bool ControllerSendMcastRouteAdd(AgentXmppChannel *peer, AgentRoute *route)
static void HandleAgentXmppClientChannelEvent(AgentXmppChannel *peer, xmps::PeerState state)
void ReceiveBgpMessage(std::unique_ptr< XmlBase > impl)
ControllerEcmpRoute * BuildEcmpData(TYPE *item, const VnListType &vn_list, const EcmpLoadBalance &ecmp_load_balance, const AgentRouteTable *rt_table, const std::string &prefix_str)
virtual void ReceiveV4V6Update(XmlPugi *pugi)
bool ControllerSendV4V6UnicastRouteCommon(AgentRoute *route, const VnListType &vn_list, const SecurityGroupList *sg_list, const TagList *tag_list, const CommunityList *communities, uint32_t mpls_label, uint32_t tunnel_bmap, const PathPreference &path_preference, bool associate, Agent::RouteTableType type, const EcmpLoadBalance &ecmp_load_balance, uint32_t native_vrf_id)
void AddInetEcmpRoute(std::string vrf_name, IpAddress ip, uint32_t plen, autogen::ItemType *item, const VnListType &vn_list)
uint8_t type
Definition: load_balance.h:109
Definition: agent.h:358
static bool IsXmppChannelActive(const Agent *agent, AgentXmppChannel *peer)
LlgrStaleTimer * llgr_stale_timer()
uint64_t sequence_number() const
bool ControllerSendMcastRouteCommon(AgentRoute *route, bool associate)
std::string * repr_
virtual void ReceiveMvpnUpdate(XmlPugi *pugi)
uint64_t route_published_time_
AgentXmppChannel(Agent *agent, const std::string &xmpp_server, const std::string &label_range, uint8_t xs_idx)
static void CleanConfigStale(AgentXmppChannel *agent_xmpp_channel)
XmlWriter(std::string *repr)
PeerPtr bgp_peer_id_ref()
std::vector< std::string > CommunityList
Definition: bgp_config.h:347
uint8_t GetXmppServerIdx()
static void XmppClientChannelEvent(AgentXmppChannel *peer, xmps::PeerState state)
InetUnicastAgentRouteTable * PrefixToRouteTable(const std::string &vrf_name, const IpAddress &prefix_addr)
bool ControllerSendIPMcastRouteCommon(AgentRoute *route, bool associate)
Definition: peer.h:44
static bool ControllerSendCfgSubscribe(AgentXmppChannel *peer)
std::set< std::string > VnListType
Definition: agent.h:212
virtual void ReceiveUpdate(const XmppStanza::XmppMessage *msg)
std::string label_range_
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
std::string GetXmppServer()
virtual ~AgentXmppChannel()
void AddFabricVrfRoute(const Ip4Address &prefix_addr, uint32_t prefix_len, const Ip4Address &addr, const VnListType &vn_list, const SecurityGroupList &sg_list, const TagList &tag_list)
void AddEvpnRoute(const std::string &vrf_name, std::string mac_addr, const IpAddress &ip, uint32_t plen, autogen::EnetItemType *item)
bool BuildEvpnUnicastMessage(autogen::EnetItemType &item, std::stringstream &node_id, AgentRoute *route, const Ip4Address *nh_ip, const std::string &vn, const SecurityGroupList *sg_list, const TagList *tag_list, const CommunityList *communities, uint32_t label, uint32_t tunnel_bmap, const PathPreference &path_prefernce, bool associate)
boost::scoped_ptr< EndOfRibTxTimer > end_of_rib_tx_timer_
std::string xmpp_server_
void AddEvpnEcmpRoute(std::string vrf_name, const MacAddress &mac, const IpAddress &ip, uint32_t plen, autogen::EnetItemType *item, const VnListType &vn_list)
void AddMulticastEvpnRoute(const std::string &vrf_name, const IpAddress &source, const IpAddress &group, autogen::EnetItemType *item)
bool BuildTorMulticastMessage(autogen::EnetItemType &item, std::stringstream &node_id, AgentRoute *route, const Ip4Address *nh_ip, const std::string &vn, const SecurityGroupList *sg_list, const TagList *tag_list, const CommunityList *communities, uint32_t label, uint32_t tunnel_bmap, const std::string &destination, const std::string &source, bool associate)
static bool ControllerSendRouteDelete(AgentXmppChannel *peer, AgentRoute *route, const VnListType &vn_list, uint32_t label, uint32_t tunnel_bmap, const SecurityGroupList *sg_list, const TagList *tag_list, const CommunityList *communities, Agent::RouteTableType type, const PathPreference &path_preference)
void RegisterXmppChannel(XmppChannel *channel)
void BuildTagList(const TYPE *item, TagList *tag_list)
XmppChannel * channel_
static bool ControllerSendMcastRouteDelete(AgentXmppChannel *peer, AgentRoute *route)
BgpPeer * bgp_peer_id()
virtual void ReceiveMulticastUpdate(XmlPugi *pugi)
static bool SetConfigPeer(AgentXmppChannel *peer)
RouteTableType
Definition: agent.h:415
static bool ControllerSendEvpnRouteAdd(AgentXmppChannel *peer, AgentRoute *route, const Ip4Address *nexthop_ip, std::string vn, uint32_t mpls_label, uint32_t tunnel_bmap, const SecurityGroupList *sg_list, const TagList *tag_list, const CommunityList *communities, const std::string &destination, const std::string &source, const PathPreference &path_preference)
std::string channel_str_
bool BuildEvpnMulticastMessage(autogen::EnetItemType &item, std::stringstream &node_id, AgentRoute *route, const Ip4Address *nh_ip, const std::string &vn, const SecurityGroupList *sg_list, const TagList *tag_list, const CommunityList *communities, uint32_t label, uint32_t tunnel_bmap, bool associate, const AgentPath *path, bool assisted_replication)
virtual void ReceiveEvpnUpdate(XmlPugi *pugi)
Agent * agent() const
void AddInetMplsEcmpRoute(std::string vrf_name, IpAddress ip, uint32_t plen, autogen::ItemType *item, const VnListType &vn_list)
virtual void WriteReadyCb(const boost::system::error_code &ec)
static bool ControllerSendSubscribe(AgentXmppChannel *peer, VrfEntry *vrf, bool subscribe)
virtual bool SendUpdate(const uint8_t *msg, size_t msgsize)
static bool ControllerSendEvpnRouteDelete(AgentXmppChannel *peer, AgentRoute *route, std::string vn, uint32_t mpls_label, const std::string &destination, const std::string &source, uint32_t tunnel_bmap)
bool ControllerSendEvpnRouteCommon(AgentRoute *route, const Ip4Address *nexthop_ip, std::string vn, const SecurityGroupList *sg_list, const TagList *tag_list, const CommunityList *communities, uint32_t mpls_label, uint32_t tunnel_bmap, const std::string &destination, const std::string &source, const PathPreference &path_preference, bool associate)
static bool IsBgpPeerActive(const Agent *agent, AgentXmppChannel *peer)
std::vector< int > TagList
Definition: agent.h:202
std::string GetBgpPeerName() const
void AddRemoteRoute(std::string vrf_name, IpAddress prefix_addr, uint32_t prefix_len, autogen::ItemType *item, const VnListType &vn_list)