OpenSDN source code
controller_route_path.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef controller_route_path_hpp
7 #define controller_route_path_hpp
8 
9 #include <cmn/agent_cmn.h>
10 #include <cmn/agent.h>
11 #include <oper/route_common.h>
12 #include <xmpp_enet_types.h>
13 #include <xmpp_unicast_types.h>
14 
15 //Forward declaration
16 class AgentXmppChannel;
17 struct AgentRouteData;
18 class EcmpLoadBalance;
19 class Peer;
20 class BgpPeer;
21 class TunnelNHKey;
22 class TunnelNHData;
23 class TunnelType;
24 class ControllerVmRoute;
25 class LocalVmRoute;
26 class InetInterfaceRoute;
27 class VlanNhRoute;
28 class VNController;
29 class ClonedLocalPath;
30 class EcmpData;
31 
32 /*
33  * Contains all Controller Route data definition.
34  * Currently there are four kind of routes added from controller:
35  * - Remote - Native to controller, derived from ControllerPeerPath
36  * - Local - Derived from LocalVmRoute of agent_path
37  * - Vlan - Derived from VlanNHRoute from agent_path
38  * - Inet Interface - Derived from InetInterfaceRoute from agent_path.
39  *
40  */
41 
43 public:
44  static const uint64_t kInvalidPeerIdentifier = 0xFFFFFFFFFFFFFFFFLL;
45  ControllerPeerPath(const BgpPeer *peer);
47 
48  virtual bool UpdateRoute(AgentRoute *route) {return false;}
49 
50 private:
51  const BgpPeer *peer_;
52 };
53 
54 /*
55  * Implementation for adding remote route data.
56  */
58 public:
59  ControllerVmRoute(const BgpPeer *peer, const string &vrf_name,
60  const Ip4Address &addr, uint32_t label,
61  const VnListType &dest_vn_list, int bmap,
63  const TagList &tag_list,
64  const PathPreference &path_preference,
65  DBRequest &req, bool ecmp_suppressed,
66  const EcmpLoadBalance &ecmp_load_balance,
67  bool etree_leaf,
68  const MacAddress &rewrite_dmac = MacAddress()) :
69  ControllerPeerPath(peer), server_vrf_(vrf_name), tunnel_dest_(addr),
70  tunnel_bmap_(bmap), label_(label), dest_vn_list_(dest_vn_list),
72  ecmp_suppressed_(ecmp_suppressed), ecmp_load_balance_(ecmp_load_balance),
73  etree_leaf_(etree_leaf), rewrite_dmac_(rewrite_dmac)
74  {
75  nh_req_.Swap(&req);
76  tunnel_dest_list_.push_back(addr);
77  label_list_.push_back(label);
78  }
79  // Data passed in case of delete from BGP peer, to validate
80  // the request at time of processing.
81  ControllerVmRoute(const BgpPeer *peer) : ControllerPeerPath(peer) { }
82  virtual ~ControllerVmRoute() { }
83 
84  virtual bool AddChangePathExtended(Agent *agent, AgentPath *path,
85  const AgentRoute *rt);
86  virtual bool UpdateRoute(AgentRoute *route);
87  virtual string ToString() const {return "remote VM";}
88  const SecurityGroupList &sg_list() const {return sg_list_;}
89  const TagList &tag_list() const {return tag_list_;}
91  const string &default_vrf,
92  const Ip4Address &router_id,
93  const string &vrf_name,
94  const Ip4Address &tunnel_dest,
96  uint32_t label,
97  MacAddress rewrite_dmac,
98  const VnListType &dest_vn_list,
100  const TagList &tag_list,
101  const PathPreference &path_preference,
102  bool ecmp_suppressed,
103  const EcmpLoadBalance &ecmp_load_balance,
104  bool etree_leaf);
105 
106 private:
107  string server_vrf_;
110  uint32_t label_;
120  std::vector<IpAddress> tunnel_dest_list_;
121  std::vector<uint32_t> label_list_;
123 };
124 
126 public:
127  ControllerMplsRoute(const BgpPeer *peer, const string &vrf_name,
128  const Ip4Address &addr, uint32_t label,
129  const VnListType &dest_vn_list, int bmap,
130  const SecurityGroupList &sg_list,
131  const TagList &tag_list,
132  const PathPreference &path_preference,
133  DBRequest &req, bool ecmp_suppressed,
134  const EcmpLoadBalance &ecmp_load_balance,
135  bool etree_leaf,
136  const MacAddress &rewrite_dmac = MacAddress()) :
137  ControllerPeerPath(peer), server_vrf_(vrf_name), tunnel_dest_(addr),
138  tunnel_bmap_(bmap), label_(label), dest_vn_list_(dest_vn_list),
139  sg_list_(sg_list),tag_list_(tag_list), path_preference_(path_preference),
140  ecmp_suppressed_(ecmp_suppressed), ecmp_load_balance_(ecmp_load_balance),
141  etree_leaf_(etree_leaf), rewrite_dmac_(rewrite_dmac)
142  {nh_req_.Swap(&req);}
143  // Data passed in case of delete from BGP peer, to validate
144  // the request at time of processing.
146  virtual ~ControllerMplsRoute() { }
147 
148  virtual bool AddChangePathExtended(Agent *agent, AgentPath *path,
149  const AgentRoute *rt);
150  //virtual bool UpdateRoute(AgentRoute *route);
151  virtual string ToString() const {return "remote PE";}
152  const SecurityGroupList &sg_list() const {return sg_list_;}
153  const TagList &tag_list() const {return tag_list_;}
155  const string &default_vrf,
156  const Ip4Address &router_id,
157  const string &vrf_name,
158  const Ip4Address &tunnel_dest,
160  uint32_t label,
161  MacAddress rewrite_dmac,
162  const VnListType &dest_vn_list,
163  const SecurityGroupList &sg_list,
164  const TagList &tag_list,
165  const PathPreference &path_preference,
166  bool ecmp_suppressed,
167  const EcmpLoadBalance &ecmp_load_balance,
168  bool etree_leaf);
169 
170 private:
171  string server_vrf_;
174  uint32_t label_;
185 };
187 public:
188  static const uint32_t maximum_ecmp_paths = 128;
189  typedef std::list<ClonedLocalPath *> ClonedLocalPathList;
190  typedef ClonedLocalPathList::iterator ClonedLocalPathListIter;
191  //Uses Item to build attributes
192  template <typename TYPE>
193  ControllerEcmpRoute(const BgpPeer *peer,
194  const VnListType &vn_list,
195  const EcmpLoadBalance &ecmp_load_balance,
196  const TagList &tag_list,
197  const TYPE *item,
198  const AgentRouteTable *rt_table,
199  const std::string &prefix_str);
200  //Non item based constructor (Used by UT)
201  ControllerEcmpRoute(const BgpPeer *peer,
202  const VnListType &vn_list,
203  const EcmpLoadBalance &ecmp_load_balance,
204  const TagList &tag_list,
205  const SecurityGroupList &sg_list,
206  const PathPreference &path_pref,
207  TunnelType::TypeBmap tunnel_bmap,
208  DBRequest &nh_req,
209  const std::string &prefix_str,
210  const std::string vrf_name = "");
211  ControllerEcmpRoute(const BgpPeer *peer,
212  const VnListType &vn_list,
213  const EcmpLoadBalance &ecmp_load_balance,
214  const TagList &tag_list,
215  const SecurityGroupList &sg_list,
216  const PathPreference &path_pref,
217  TunnelType::TypeBmap tunnel_bmap,
218  std::vector<IpAddress> &tunnel_dest_list,
219  std::vector<uint32_t> &label_list,
220  const std::string &prefix_str,
221  const std::string &vrf_name);
222  virtual ~ControllerEcmpRoute() { }
223  virtual bool AddChangePathExtended(Agent *agent, AgentPath *path,
224  const AgentRoute *rt);
225  virtual string ToString() const {return "inet4 ecmp";}
226  bool CopyToPath(AgentPath *path);
227  void BuildNhReq(const string &vrf_name, const autogen::ItemType *item_type,
228  const VnListType &vn_list);
230  return cloned_data_list_;
231  }
232 
233  void set_copy_local_path(bool copy_local_path) {
234  copy_local_path_ = copy_local_path;
235  }
236 
238  return nh_req_;
239  }
240 
241  friend class AgentXmppChannel;
242 private:
253  std::vector<IpAddress>tunnel_dest_list_;
254  std::vector<uint32_t>label_list_;
255  string vrf_name_;
256  uint32_t vxlan_id_;
258 };
259 
260 /*
261  * ClonedLocalPath would be used to pick nexthop from the
262  * local peer, instead of nexthop pointed by mpls label.
263  * Currently it gets used in gateway interface. In case of
264  * gateway interface, label exported by agent would point
265  * to table nexthop, and the prefix route of gateway
266  * interface would point resolve nexthop, so that ARP resolution
267  * can be triggered when packet hits the subnet route.
268  */
270 public:
271  ClonedLocalPath(uint32_t label, const VnListType &vn_list,
272  const SecurityGroupList &sg_list,
273  const TagList &tag_list,
274  uint64_t sequence_number):
276  mpls_label_(label), vn_list_(vn_list),
277  sg_list_(sg_list), tag_list_(tag_list) {}
278  virtual ~ClonedLocalPath() {}
279  virtual bool AddChangePathExtended(Agent *agent, AgentPath *path,
280  const AgentRoute *rt);
281  virtual std::string ToString() const {
282  return "Nexthop cloned from local path";
283  }
284 private:
285  uint32_t mpls_label_;
290 };
291 
292 /*
293  * stale path is created when no CN server is present.
294  * Last peer going down marks its path as stale and keep route alive, till
295  * anothe CN takes over.
296  * There can be only one stale path as multiple does not make any sense.
297  * (Stale path is to keep traffic flowing).
298  */
300 public:
303  sequence_number) { }
304  virtual ~StalePathData() { }
305  virtual bool AddChangePathExtended(Agent *agent, AgentPath *path,
306  const AgentRoute *rt);
307  virtual bool CanDeletePath(Agent *agent, AgentPath *path,
308  const AgentRoute *rt) const;
309  virtual std::string ToString() const {
310  return "Stale path marking(healdess mode)";
311  }
312 
313 private:
315 };
316 #endif //controller_route_path_hpp
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
std::vector< uint64_t > TagList
Definition: agent.h:203
std::vector< int > SecurityGroupList
Definition: agent.h:202
std::set< std::string > VnListType
Definition: agent.h:213
Agent supports multiple route tables - Inet-unicast (IPv4/IPv6), Inet-multicast, bridge,...
Definition: agent_route.h:110
Base class for all Route entries in agent.
Definition: agent_route.h:225
Definition: agent.h:361
virtual bool AddChangePathExtended(Agent *agent, AgentPath *path, const AgentRoute *rt)
const VnListType vn_list_
const SecurityGroupList sg_list_
DISALLOW_COPY_AND_ASSIGN(ClonedLocalPath)
ClonedLocalPath(uint32_t label, const VnListType &vn_list, const SecurityGroupList &sg_list, const TagList &tag_list, uint64_t sequence_number)
virtual std::string ToString() const
ClonedLocalPathList cloned_data_list_
std::list< ClonedLocalPath * > ClonedLocalPathList
ControllerEcmpRoute(const BgpPeer *peer, const VnListType &vn_list, const EcmpLoadBalance &ecmp_load_balance, const TagList &tag_list, const TYPE *item, const AgentRouteTable *rt_table, const std::string &prefix_str)
DISALLOW_COPY_AND_ASSIGN(ControllerEcmpRoute)
virtual bool AddChangePathExtended(Agent *agent, AgentPath *path, const AgentRoute *rt)
SecurityGroupList sg_list_
virtual string ToString() const
ClonedLocalPathList::iterator ClonedLocalPathListIter
std::vector< IpAddress > tunnel_dest_list_
TunnelType::TypeBmap tunnel_bmap_
void set_copy_local_path(bool copy_local_path)
EcmpLoadBalance ecmp_load_balance_
static const uint32_t maximum_ecmp_paths
void BuildNhReq(const string &vrf_name, const autogen::ItemType *item_type, const VnListType &vn_list)
bool CopyToPath(AgentPath *path)
std::vector< uint32_t > label_list_
PathPreference path_preference_
ClonedLocalPathList & cloned_local_path_list()
EcmpLoadBalance ecmp_load_balance_
PathPreference path_preference_
const SecurityGroupList & sg_list() const
virtual string ToString() const
DISALLOW_COPY_AND_ASSIGN(ControllerMplsRoute)
static ControllerMplsRoute * MakeControllerMplsRoute(const BgpPeer *peer, const string &default_vrf, const Ip4Address &router_id, const string &vrf_name, const Ip4Address &tunnel_dest, TunnelType::TypeBmap bmap, uint32_t label, MacAddress rewrite_dmac, const VnListType &dest_vn_list, const SecurityGroupList &sg_list, const TagList &tag_list, const PathPreference &path_preference, bool ecmp_suppressed, const EcmpLoadBalance &ecmp_load_balance, bool etree_leaf)
const TagList & tag_list() const
SecurityGroupList sg_list_
ControllerMplsRoute(const BgpPeer *peer)
TunnelType::TypeBmap tunnel_bmap_
virtual bool AddChangePathExtended(Agent *agent, AgentPath *path, const AgentRoute *rt)
ControllerMplsRoute(const BgpPeer *peer, const string &vrf_name, const Ip4Address &addr, uint32_t label, const VnListType &dest_vn_list, int bmap, const SecurityGroupList &sg_list, const TagList &tag_list, const PathPreference &path_preference, DBRequest &req, bool ecmp_suppressed, const EcmpLoadBalance &ecmp_load_balance, bool etree_leaf, const MacAddress &rewrite_dmac=MacAddress())
ControllerPeerPath(const BgpPeer *peer)
static const uint64_t kInvalidPeerIdentifier
virtual bool UpdateRoute(AgentRoute *route)
PathPreference path_preference_
ControllerVmRoute(const BgpPeer *peer)
EcmpLoadBalance ecmp_load_balance_
std::vector< IpAddress > tunnel_dest_list_
virtual bool AddChangePathExtended(Agent *agent, AgentPath *path, const AgentRoute *rt)
const SecurityGroupList & sg_list() const
const TagList & tag_list() const
SecurityGroupList sg_list_
virtual bool UpdateRoute(AgentRoute *route)
TunnelType::TypeBmap tunnel_bmap_
static ControllerVmRoute * MakeControllerVmRoute(const BgpPeer *peer, const string &default_vrf, const Ip4Address &router_id, const string &vrf_name, const Ip4Address &tunnel_dest, TunnelType::TypeBmap bmap, uint32_t label, MacAddress rewrite_dmac, const VnListType &dest_vn_list, const SecurityGroupList &sg_list, const TagList &tag_list, const PathPreference &path_preference, bool ecmp_suppressed, const EcmpLoadBalance &ecmp_load_balance, bool etree_leaf)
DISALLOW_COPY_AND_ASSIGN(ControllerVmRoute)
ControllerVmRoute(const BgpPeer *peer, const string &vrf_name, const Ip4Address &addr, uint32_t label, const VnListType &dest_vn_list, int bmap, const SecurityGroupList &sg_list, const TagList &tag_list, const PathPreference &path_preference, DBRequest &req, bool ecmp_suppressed, const EcmpLoadBalance &ecmp_load_balance, bool etree_leaf, const MacAddress &rewrite_dmac=MacAddress())
std::vector< uint32_t > label_list_
virtual string ToString() const
Definition: ecmp.h:16
Definition: peer.h:45
virtual bool AddChangePathExtended(Agent *agent, AgentPath *path, const AgentRoute *rt)
DISALLOW_COPY_AND_ASSIGN(StalePathData)
virtual std::string ToString() const
virtual bool CanDeletePath(Agent *agent, AgentPath *path, const AgentRoute *rt) const
StalePathData(uint64_t sequence_number)
uint32_t TypeBmap
Definition: nexthop.h:249
uint64_t sequence_number() const
Definition: agent_route.h:79
void Swap(DBRequest *rhs)
Definition: db_table.cc:46