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