OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vxlan_xmpp_routes.cc
Go to the documentation of this file.
1 #include <oper/operdb_init.h>
2 #include <oper/route_common.h>
3 #include <oper/vrf.h>
4 #include <oper/bridge_route.h>
6 #include <oper/evpn_route.h>
7 #include <oper/agent_route.h>
8 #include <oper/vn.h>
9 #include <oper/vrf.h>
12 #include <oper/tunnel_nh.h>
13 
14 template<class RouteTable, class RouteEntry>
15 static const AgentPath *LocalVmExportInterface(Agent* agent,
16  RouteTable *table, RouteEntry *route);
17 
19  const IpAddress& dip, const MacAddress& dmac) const {
20 
21  const Ip4Address rtr_dip = dip.to_v4();
22 
23  const std::vector<IpAddress> nh_addresses(1, dip);
24  bool is_zero_mac = dmac.IsZero();
25 
26  MacAddress rtr_dmac;
27  if (!is_zero_mac) {
28  rtr_dmac = dmac;
29  } else {
30  rtr_dmac = NbComputeMac(rtr_dip, agent_);
31  }
32 
33  TunnelNHKey *tun_nh_key = new TunnelNHKey(agent_->fabric_vrf_name(),
34  agent_->router_id(),
35  rtr_dip,
36  false,
38  rtr_dmac);
39  return tun_nh_key;
40 }
41 
43 const int prefix_len, uint32_t vxlan_id, const std::string vrf_name,
44 const RouteParameters& params, const Peer *bgp_peer) {
45  VrfEntry* vrf = agent_->vrf_table()->FindVrfFromName(vrf_name);
46  EvpnAgentRouteTable *evpn_table =
47  dynamic_cast<EvpnAgentRouteTable*>(vrf->GetEvpnRouteTable());
48  if (evpn_table == NULL) {
49  return;
50  }
51 
52  // If route is a tunnel
53  if (agent_->router_id() != params.nh_addr_.to_v4()) {
54  XmppAdvertiseEvpnTunnel(evpn_table,
55  prefix_ip, prefix_len, vxlan_id, vrf_name, params, bgp_peer);
56  return;
57  }
58 
59  // Or this is an interface
60  XmppAdvertiseEvpnInterface(evpn_table,
61  prefix_ip, prefix_len, vxlan_id, vrf_name, params, bgp_peer);
62 }
63 
65  const int prefix_len, const std::string vrf_name,
66  const AgentPath* path) {
67 
68  VrfEntry* vrf = agent_->vrf_table()->FindVrfFromName(vrf_name);
69  InetUnicastAgentRouteTable *inet_table =
70  vrf->GetInetUnicastRouteTable(prefix_ip);
71 
72  if (path->nexthop() && path->nexthop()->GetType() ==
74  XmppAdvertiseInetTunnel(inet_table,
75  prefix_ip, prefix_len, vrf_name, path);
76  return;
77  }
78 
79  if (path->nexthop() &&
80  (path->nexthop()->GetType() == NextHop::INTERFACE ||
81  path->nexthop()->GetType() == NextHop::COMPOSITE)) {
83  prefix_ip, prefix_len, vrf_name, path);
84  }
85 }
86 
88  EvpnAgentRouteTable *evpn_table, const IpAddress& prefix_ip,
89  const int prefix_len, uint32_t vxlan_id, const std::string vrf_name,
90  const RouteParameters& params, const Peer *peer
91 ) {
92  const BgpPeer *bgp_peer = dynamic_cast<const BgpPeer*>(peer);
93  if (bgp_peer == NULL) {
94  return;
95  }
97  std::unique_ptr<TunnelNHKey> tun_nh_key (AllocateTunnelNextHopKey(
98  params.nh_addr_, params.nh_mac_));
99 
100  ControllerVmRoute *data =
101  ControllerVmRoute::MakeControllerVmRoute(dynamic_cast<const BgpPeer*>(bgp_peer),
103  agent_->router_id(),
104  vrf_name,
105  tun_nh_key->dip(),
107  vxlan_id,
108  tun_nh_key->rewrite_dmac(),
109  params.vn_list_,
110  params.sg_list_,
111  params.tag_list_,
112  params.path_preference_,
113  true,
114  EcmpLoadBalance(),
115  false);
116  evpn_table->AddRemoteVmRouteReq(bgp_peer,
117  vrf_name,
118  MacAddress(),
119  prefix_ip,
120  prefix_len,
121  0, // ethernet_tag is zero for Type5
122  data);
123 }
124 
126  EvpnAgentRouteTable *evpn_table, const IpAddress& prefix_ip,
127  const int prefix_len, uint32_t vxlan_id, const std::string vrf_name,
128  const RouteParameters& params, const Peer *bgp_peer
129 ) {
130  EvpnRouteEntry *route = evpn_table->FindRoute(MacAddress(),
131  prefix_ip, prefix_len, 0);
132  if (RoutePrefixIsEqualTo(route, prefix_ip, prefix_len) == false) {
133  return;
134  }
135  const AgentPath * path =
136  LocalVmExportInterface(agent_, evpn_table, route);
137 
139  prefix_ip,
140  prefix_len,
141  bgp_peer,
142  RouteParameters(IpAddress(), // NH address, not needed here
143  MacAddress(),
144  params.vn_list_,
145  params.sg_list_,
146  params.communities_,
147  params.tag_list_,
148  params.path_preference_,
149  params.ecmp_load_balance_,
150  params.sequence_number_),
151  evpn_table);
152 }
153 
155  InetUnicastAgentRouteTable *inet_table, const IpAddress& prefix_ip,
156  const int prefix_len, const std::string vrf_name,
157  const AgentPath* path) {
158 
160  TunnelNH *tun_nh = dynamic_cast<TunnelNH*>(path->nexthop());
161 
162  TunnelNHKey *tun_nh_key = AllocateTunnelNextHopKey(*(tun_nh->GetDip()),
163  tun_nh->rewrite_dmac());
164  std::string origin_vn = "";
165 
166  nh_req.key.reset(tun_nh_key);
167  nh_req.data.reset(new TunnelNHData);
168 
169  inet_table->AddEvpnRoutingRoute(prefix_ip,
170  prefix_len,
171  inet_table->vrf_entry(),
173  path->sg_list(),
174  path->communities(),
175  path->path_preference(),
176  path->ecmp_load_balance(),
177  path->tag_list(),
178  nh_req,
179  path->vxlan_id(),
180  path->dest_vn_list(),
181  origin_vn);
182 }
183 
185  InetUnicastAgentRouteTable *inet_table, const IpAddress& prefix_ip,
186  const int prefix_len, const std::string vrf_name,
187  const AgentPath* path) {
188 
189  CopyPathToInetTable(path,
190  prefix_ip,
191  prefix_len,
194  MacAddress(),
195  path->dest_vn_list(),
196  path->sg_list(),
197  path->communities(),
198  path->tag_list(),
199  path->path_preference(),
200  path->ecmp_load_balance(),
201  path->peer_sequence_number()),
202  inet_table);
203 }
204 
205 template<class RouteTable, class RouteEntry>
207  RouteTable *table, RouteEntry *route) {
208  if (table == NULL || agent == NULL || route == NULL) {
209  return NULL;
210  }
211 
212  const AgentPath *tm_path = NULL;
213  const AgentPath *rt_path = NULL;
214 
215  for (Route::PathList::const_iterator it =
216  route->GetPathList().begin();
217  it != route->GetPathList().end(); it++) {
218  tm_path =
219  static_cast<const AgentPath *>(it.operator->());
220  if (tm_path == NULL || tm_path->peer() == NULL) {
221  continue;
222  }
223  if (tm_path->peer()->GetType() ==
224  agent->local_vm_export_peer()->GetType()) {
225  if (tm_path->nexthop() &&
226  tm_path->nexthop()->GetType() == NextHop::INTERFACE) {
227  rt_path = tm_path;
228  } else if (tm_path->nexthop() &&
229  tm_path->nexthop()->GetType() == NextHop::COMPOSITE) {
230  return tm_path;
231  }
232  }
233  }
234  return rt_path;
235 }
236 
237 //
238 //END-OF-FILE
239 //
240 
void XmppAdvertiseEvpnTunnel(EvpnAgentRouteTable *inet_table, const IpAddress &prefix_ip, const int prefix_len, uint32_t vxlan_id, const std::string vrf_name, const RouteParameters &params, const Peer *bgp_peer)
Advertises in the EVPN table a tunnel route that arrived via XMPP channel. Must be called only from X...
EvpnRouteEntry * FindRoute(const MacAddress &mac, const IpAddress &ip_addr, uint32_t plen, uint32_t ethernet_tag)
const TagList & tag_list_
A list of tags.
const VnListType & dest_vn_list() const
Definition: agent_path.h:258
const Peer * local_vm_export_peer() const
Definition: agent.h:1040
Definition: vrf.h:86
const TagList & tag_list() const
Definition: agent_path.h:249
const PathPreference & path_preference() const
Definition: agent_path.h:329
AgentRouteTable * GetEvpnRouteTable() const
Definition: vrf.cc:330
VrfEntry * FindVrfFromName(const string &name)
Definition: vrf.cc:873
static MacAddress NbComputeMac(const Ip4Address &compute_ip, const Agent *agent)
Returns the MAC address for the IP of a given neighbouring compute.
boost::asio::ip::address IpAddress
Definition: address.h:13
std::unique_ptr< DBRequestData > data
Definition: db_table.h:49
const Ip4Address * GetDip() const
Definition: tunnel_nh.h:37
A structure to hold path parameters during the transfer (routes leaking) of data between VRF instance...
uint64_t sequence_number_
An ID of sequence.
Type GetType() const
Definition: nexthop.h:405
const SecurityGroupList & sg_list_
A list of security groups.
void XmppAdvertiseInetTunnel(InetUnicastAgentRouteTable *inet_table, const IpAddress &prefix_ip, const int prefix_len, uint32_t vxlan_id, const std::string vrf_name, const RouteParameters &params, const Peer *bgp_peer)
Advertises in the Inet table a tunnel route that arrived via XMPP channel. Must be called only from X...
const std::string & fabric_vrf_name() const
Definition: agent.h:903
static bool RoutePrefixIsEqualTo(const EvpnRouteEntry *route, const IpAddress &prefix_ip, const uint32_t prefix_len)
Determines whether route prefix in the EVPN route is equal to the given pair of prefix IP address and...
const Type GetType() const
Definition: peer.h:87
void CopyPathToInetTable(const AgentPath *path, const IpAddress &prefix_ip, const uint32_t plen, const Peer *peer, const RouteParameters &params, InetUnicastAgentRouteTable *inet_table)
Copies the path to the prefix address into the EVPN table with the given Peer. The function is used d...
NextHop * nexthop() const
Definition: agent_path.cc:87
VrfEntry * vrf_entry() const
Definition: agent_route.cc:459
Agent * agent_
A pointer to the Agent instance.
void AddEvpnRoutingRoute(const IpAddress &ip_addr, uint8_t plen, const VrfEntry *vrf, const Peer *peer, const SecurityGroupList &sg_list, const CommunityList &communities, const PathPreference &path_preference, const EcmpLoadBalance &ecmp_load_balance, const TagList &tag_list, DBRequest &nh_req, uint32_t vxlan_id, const VnListType &vn_list, const std::string &origin_vn="")
bool IsZero() const
Definition: mac_address.cc:29
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)
const VnListType & vn_list_
A list of path destination virtual networks used in policy lookups.
Definition: agent.h:358
InetUnicastAgentRouteTable * GetInetUnicastRouteTable(const IpAddress &addr) const
Definition: vrf.cc:575
Ip4Address router_id() const
Definition: agent.h:666
std::unique_ptr< DBRequestKey > key
Definition: db_table.h:48
const Peer * peer() const
Definition: agent_path.h:263
const IpAddress & nh_addr_
A nexthop IP address of the tunnel. Contains first IP address of nh_addresses_ in case of a composite...
Definition: peer.h:44
void XmppAdvertiseEvpnInterface(EvpnAgentRouteTable *inet_table, const IpAddress &prefix_ip, const int prefix_len, uint32_t vxlan_id, const std::string vrf_name, const RouteParameters &params, const Peer *bgp_peer)
Advertises in the EVPN table an interface route that arrived via XMPP channel. Must be called only fr...
static const AgentPath * LocalVmExportInterface(Agent *agent, RouteTable *table, RouteEntry *route)
uint64_t peer_sequence_number() const
Definition: agent_path.h:415
const MacAddress & rewrite_dmac() const
Definition: tunnel_nh.h:41
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
const PathPreference & path_preference_
A reference to the PathPreference of the path.
VrfTable * vrf_table() const
Definition: agent.h:485
static void CopyInterfacePathToEvpnTable(const AgentPath *path, const IpAddress &prefix_ip, const uint32_t plen, const Peer *peer, const RouteParameters &params, EvpnAgentRouteTable *evpn_table)
Copies the path to the prefix address into the EVPN table with the given Peer. The function is used d...
const MacAddress & nh_mac_
A nexthop MAC address (usually it is a MAC of the router).
const CommunityList & communities_
A list of communities.
void XmppAdvertiseEvpnRoute(const IpAddress &prefix_ip, const int prefix_len, uint32_t vxlan_id, const std::string vrf_name, const RouteParameters &params, const Peer *bgp_peer)
Advertises an EVPN route received using XMPP channel.
void XmppAdvertiseInetInterfaceOrComposite(InetUnicastAgentRouteTable *inet_table, const IpAddress &prefix_ip, const int prefix_len, const std::string vrf_name, const AgentPath *path)
Advertises in the Inet table an interface route that arrived via XMPP channel. Must be called only fr...
const CommunityList & communities() const
Definition: agent_path.h:250
const EcmpLoadBalance & ecmp_load_balance_
A reference to EcmpLoadBalance of the path.
TunnelNHKey * AllocateTunnelNextHopKey(const IpAddress &dip, const MacAddress &dmac) const
XMPP Advertising functions.
static const Peer * routing_vrf_vxlan_bgp_peer_
A pointer to the Peer where all BGP routes are stored.
static TypeBmap VxlanType()
Definition: nexthop.h:311
void XmppAdvertiseInetRoute(const IpAddress &prefix_ip, const int prefix_len, uint32_t vxlan_id, const std::string vrf_name, const RouteParameters &params, const Peer *bgp_peer)
Advertises an Inet route received using XMPP channel.
const SecurityGroupList & sg_list() const
Definition: agent_path.h:248
uint32_t vxlan_id() const
Definition: agent_path.h:265
const EcmpLoadBalance & ecmp_load_balance() const
Definition: agent_path.h:365
static void AddRemoteVmRouteReq(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, const IpAddress &ip_addr, uint32_t plen, uint32_t ethernet_tag, AgentRouteData *data)