blob: 19ca81b9cfe4d1052ccf529fd0f06e6a4752740e [file] [log] [blame]
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001#!/usr/bin/env python
2
Paul Vinciguerraa279d9c2019-02-28 09:00:09 -08003from socket import AF_INET, AF_INET6
Neale Rannsbc27d1b2018-02-05 01:13:38 -08004import unittest
Neale Rannsbc27d1b2018-02-05 01:13:38 -08005
Neale Rannsbc27d1b2018-02-05 01:13:38 -08006from scapy.packet import Raw
Neale Rannsc29c0af2018-11-07 04:21:12 -08007from scapy.layers.l2 import Ether, ARP, Dot1Q
Neale Ranns36abbf12019-03-12 02:34:07 -07008from scapy.layers.inet import IP, UDP, ICMP
Filip Vargaf4749ca2019-04-25 14:55:32 +02009from scapy.layers.inet6 import IPv6, ICMPv6ND_NS, ICMPv6NDOptSrcLLAddr, \
Klement Sekerab9ef2732018-06-24 22:49:33 +020010 ICMPv6ND_NA
Neale Ranns25b04942018-04-04 09:34:50 -070011from scapy.utils6 import in6_getnsma, in6_getnsmac
Neale Ranns93cc3ee2018-10-10 07:22:51 -070012from scapy.layers.vxlan import VXLAN
Mohsin Kazmife52dea2019-04-18 15:54:58 +020013from scapy.data import ETH_P_IP, ETH_P_IPV6, ETH_P_ARP
Neale Ranns25b04942018-04-04 09:34:50 -070014from scapy.utils import inet_pton, inet_ntop
Paul Vinciguerraa279d9c2019-02-28 09:00:09 -080015
16from framework import VppTestCase, VppTestRunner
17from vpp_object import VppObject
18from vpp_interface import VppInterface
19from vpp_ip_route import VppIpRoute, VppRoutePath, VppIpTable, \
20 VppIpInterfaceAddress, VppIpInterfaceBind, find_route
21from vpp_l2 import VppBridgeDomain, VppBridgeDomainPort, \
Neale Ranns36abbf12019-03-12 02:34:07 -070022 VppBridgeDomainArpEntry, VppL2FibEntry, find_bridge_domain_port, VppL2Vtr
Paul Vinciguerra95c0ca42019-03-28 13:07:00 -070023from vpp_sub_interface import L2_VTR_OP, VppDot1QSubint
Paul Vinciguerraa279d9c2019-02-28 09:00:09 -080024from vpp_ip import VppIpAddress, VppIpPrefix
25from vpp_papi import VppEnum, MACAddress
Paul Vinciguerraa279d9c2019-02-28 09:00:09 -080026from vpp_vxlan_gbp_tunnel import find_vxlan_gbp_tunnel, INDEX_INVALID, \
27 VppVxlanGbpTunnel
Neale Ranns4dd4cf42019-03-27 05:06:47 -070028from vpp_neighbor import VppNeighbor
Neale Rannsbc27d1b2018-02-05 01:13:38 -080029
Paul Vinciguerra4271c972019-05-14 13:25:49 -040030NUM_PKTS = 67
31
Neale Rannsbc27d1b2018-02-05 01:13:38 -080032
Neale Ranns93cc3ee2018-10-10 07:22:51 -070033def find_gbp_endpoint(test, sw_if_index=None, ip=None, mac=None):
34 if ip:
35 vip = VppIpAddress(ip)
36 if mac:
Ole Troan8006c6a2018-12-17 12:02:26 +010037 vmac = MACAddress(mac)
Neale Rannsc0a93142018-09-05 15:42:26 -070038
39 eps = test.vapi.gbp_endpoint_dump()
Neale Ranns93cc3ee2018-10-10 07:22:51 -070040
Neale Rannsc0a93142018-09-05 15:42:26 -070041 for ep in eps:
Neale Ranns93cc3ee2018-10-10 07:22:51 -070042 if sw_if_index:
43 if ep.endpoint.sw_if_index != sw_if_index:
44 continue
45 if ip:
46 for eip in ep.endpoint.ips:
47 if vip == eip:
48 return True
49 if mac:
Ole Troan8006c6a2018-12-17 12:02:26 +010050 if vmac.packed == ep.endpoint.mac:
Neale Rannsc0a93142018-09-05 15:42:26 -070051 return True
52 return False
53
54
Neale Ranns93cc3ee2018-10-10 07:22:51 -070055def find_gbp_vxlan(test, vni):
56 ts = test.vapi.gbp_vxlan_tunnel_dump()
57 for t in ts:
58 if t.tunnel.vni == vni:
59 return True
60 return False
61
62
Neale Rannsbc27d1b2018-02-05 01:13:38 -080063class VppGbpEndpoint(VppObject):
64 """
Mohsin Kazmi22b3b842018-04-17 19:35:42 +020065 GBP Endpoint
Neale Rannsbc27d1b2018-02-05 01:13:38 -080066 """
67
Neale Ranns25b04942018-04-04 09:34:50 -070068 @property
Neale Ranns93cc3ee2018-10-10 07:22:51 -070069 def mac(self):
Ole Troan8006c6a2018-12-17 12:02:26 +010070 return str(self.vmac)
Neale Ranns25b04942018-04-04 09:34:50 -070071
72 @property
Neale Rannsc0a93142018-09-05 15:42:26 -070073 def ip4(self):
74 return self._ip4
75
76 @property
77 def fip4(self):
78 return self._fip4
79
80 @property
81 def ip6(self):
82 return self._ip6
83
84 @property
85 def fip6(self):
86 return self._fip6
87
88 @property
89 def ips(self):
90 return [self.ip4, self.ip6]
91
92 @property
93 def fips(self):
94 return [self.fip4, self.fip6]
95
Neale Ranns93cc3ee2018-10-10 07:22:51 -070096 def __init__(self, test, itf, epg, recirc, ip4, fip4, ip6, fip6,
97 flags=0,
98 tun_src="0.0.0.0",
99 tun_dst="0.0.0.0",
100 mac=True):
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800101 self._test = test
Neale Ranns25b04942018-04-04 09:34:50 -0700102 self.itf = itf
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800103 self.epg = epg
Neale Ranns25b04942018-04-04 09:34:50 -0700104 self.recirc = recirc
Neale Rannsc0a93142018-09-05 15:42:26 -0700105
106 self._ip4 = VppIpAddress(ip4)
107 self._fip4 = VppIpAddress(fip4)
108 self._ip6 = VppIpAddress(ip6)
109 self._fip6 = VppIpAddress(fip6)
110
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700111 if mac:
Ole Troan8006c6a2018-12-17 12:02:26 +0100112 self.vmac = MACAddress(self.itf.remote_mac)
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700113 else:
Ole Troan8006c6a2018-12-17 12:02:26 +0100114 self.vmac = MACAddress("00:00:00:00:00:00")
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700115
116 self.flags = flags
117 self.tun_src = VppIpAddress(tun_src)
118 self.tun_dst = VppIpAddress(tun_dst)
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800119
120 def add_vpp_config(self):
Neale Rannsc0a93142018-09-05 15:42:26 -0700121 res = self._test.vapi.gbp_endpoint_add(
Neale Ranns25b04942018-04-04 09:34:50 -0700122 self.itf.sw_if_index,
Neale Rannsc0a93142018-09-05 15:42:26 -0700123 [self.ip4.encode(), self.ip6.encode()],
Ole Troan8006c6a2018-12-17 12:02:26 +0100124 self.vmac.packed,
Neale Ranns4ba67722019-02-28 11:11:39 +0000125 self.epg.sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700126 self.flags,
127 self.tun_src.encode(),
128 self.tun_dst.encode())
Neale Rannsc0a93142018-09-05 15:42:26 -0700129 self.handle = res.handle
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800130 self._test.registry.register(self, self._test.logger)
131
132 def remove_vpp_config(self):
Neale Rannsc0a93142018-09-05 15:42:26 -0700133 self._test.vapi.gbp_endpoint_del(self.handle)
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800134
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800135 def object_id(self):
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700136 return "gbp-endpoint:[%d==%d:%s:%d]" % (self.handle,
137 self.itf.sw_if_index,
138 self.ip4.address,
Neale Ranns4ba67722019-02-28 11:11:39 +0000139 self.epg.sclass)
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800140
141 def query_vpp_config(self):
Neale Rannsc0a93142018-09-05 15:42:26 -0700142 return find_gbp_endpoint(self._test,
143 self.itf.sw_if_index,
144 self.ip4.address)
Neale Ranns25b04942018-04-04 09:34:50 -0700145
146
147class VppGbpRecirc(VppObject):
148 """
Mohsin Kazmi22b3b842018-04-17 19:35:42 +0200149 GBP Recirculation Interface
Neale Ranns25b04942018-04-04 09:34:50 -0700150 """
151
152 def __init__(self, test, epg, recirc, is_ext=False):
153 self._test = test
154 self.recirc = recirc
155 self.epg = epg
156 self.is_ext = is_ext
157
158 def add_vpp_config(self):
159 self._test.vapi.gbp_recirc_add_del(
160 1,
161 self.recirc.sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +0000162 self.epg.sclass,
Neale Ranns25b04942018-04-04 09:34:50 -0700163 self.is_ext)
164 self._test.registry.register(self, self._test.logger)
165
166 def remove_vpp_config(self):
167 self._test.vapi.gbp_recirc_add_del(
168 0,
169 self.recirc.sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +0000170 self.epg.sclass,
Neale Ranns25b04942018-04-04 09:34:50 -0700171 self.is_ext)
172
Neale Ranns25b04942018-04-04 09:34:50 -0700173 def object_id(self):
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700174 return "gbp-recirc:[%d]" % (self.recirc.sw_if_index)
Neale Ranns25b04942018-04-04 09:34:50 -0700175
176 def query_vpp_config(self):
177 rs = self._test.vapi.gbp_recirc_dump()
178 for r in rs:
179 if r.recirc.sw_if_index == self.recirc.sw_if_index:
180 return True
181 return False
182
183
Neale Rannsb6a47952018-11-21 05:44:35 -0800184class VppGbpExtItf(VppObject):
185 """
186 GBP ExtItfulation Interface
187 """
188
189 def __init__(self, test, itf, bd, rd):
190 self._test = test
191 self.itf = itf
192 self.bd = bd
193 self.rd = rd
194
195 def add_vpp_config(self):
196 self._test.vapi.gbp_ext_itf_add_del(
197 1,
198 self.itf.sw_if_index,
199 self.bd.bd_id,
200 self.rd.rd_id)
201 self._test.registry.register(self, self._test.logger)
202
203 def remove_vpp_config(self):
204 self._test.vapi.gbp_ext_itf_add_del(
205 0,
206 self.itf.sw_if_index,
207 self.bd.bd_id,
208 self.rd.rd_id)
209
Neale Rannsb6a47952018-11-21 05:44:35 -0800210 def object_id(self):
211 return "gbp-ext-itf:[%d]" % (self.itf.sw_if_index)
212
213 def query_vpp_config(self):
214 rs = self._test.vapi.gbp_ext_itf_dump()
215 for r in rs:
216 if r.ext_itf.sw_if_index == self.itf.sw_if_index:
217 return True
218 return False
219
220
Neale Ranns25b04942018-04-04 09:34:50 -0700221class VppGbpSubnet(VppObject):
222 """
Mohsin Kazmi22b3b842018-04-17 19:35:42 +0200223 GBP Subnet
Neale Ranns25b04942018-04-04 09:34:50 -0700224 """
Filip Vargaf4749ca2019-04-25 14:55:32 +0200225
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700226 def __init__(self, test, rd, address, address_len,
Neale Ranns4dd4cf42019-03-27 05:06:47 -0700227 type, sw_if_index=None, sclass=None):
Neale Ranns25b04942018-04-04 09:34:50 -0700228 self._test = test
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700229 self.rd_id = rd.rd_id
Ole Troana26373b2018-10-22 14:11:45 +0200230 self.prefix = VppIpPrefix(address, address_len)
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700231 self.type = type
Neale Ranns25b04942018-04-04 09:34:50 -0700232 self.sw_if_index = sw_if_index
Neale Ranns4dd4cf42019-03-27 05:06:47 -0700233 self.sclass = sclass
Neale Ranns25b04942018-04-04 09:34:50 -0700234
235 def add_vpp_config(self):
236 self._test.vapi.gbp_subnet_add_del(
237 1,
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700238 self.rd_id,
Ole Troana26373b2018-10-22 14:11:45 +0200239 self.prefix.encode(),
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700240 self.type,
Neale Ranns25b04942018-04-04 09:34:50 -0700241 sw_if_index=self.sw_if_index if self.sw_if_index else 0xffffffff,
Neale Ranns4dd4cf42019-03-27 05:06:47 -0700242 sclass=self.sclass if self.sclass else 0xffff)
Neale Ranns25b04942018-04-04 09:34:50 -0700243 self._test.registry.register(self, self._test.logger)
244
245 def remove_vpp_config(self):
246 self._test.vapi.gbp_subnet_add_del(
247 0,
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700248 self.rd_id,
249 self.prefix.encode(),
250 self.type)
Neale Ranns25b04942018-04-04 09:34:50 -0700251
Neale Ranns25b04942018-04-04 09:34:50 -0700252 def object_id(self):
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700253 return "gbp-subnet:[%d-%s]" % (self.rd_id, self.prefix)
Neale Ranns25b04942018-04-04 09:34:50 -0700254
255 def query_vpp_config(self):
256 ss = self._test.vapi.gbp_subnet_dump()
257 for s in ss:
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700258 if s.subnet.rd_id == self.rd_id and \
Filip Vargaf4749ca2019-04-25 14:55:32 +0200259 s.subnet.type == self.type and \
260 s.subnet.prefix == self.prefix:
Neale Rannsc0a93142018-09-05 15:42:26 -0700261 return True
Neale Ranns25b04942018-04-04 09:34:50 -0700262 return False
263
264
Neale Ranns32f6d8e2019-03-05 04:22:08 -0800265class VppGbpEndpointRetention(object):
266 def __init__(self, remote_ep_timeout=0xffffffff):
267 self.remote_ep_timeout = remote_ep_timeout
268
269 def encode(self):
270 return {'remote_ep_timeout': self.remote_ep_timeout}
271
272
Neale Ranns25b04942018-04-04 09:34:50 -0700273class VppGbpEndpointGroup(VppObject):
274 """
Mohsin Kazmi22b3b842018-04-17 19:35:42 +0200275 GBP Endpoint Group
Neale Ranns25b04942018-04-04 09:34:50 -0700276 """
277
Neale Ranns4ba67722019-02-28 11:11:39 +0000278 def __init__(self, test, vnid, sclass, rd, bd, uplink,
Neale Ranns32f6d8e2019-03-05 04:22:08 -0800279 bvi, bvi_ip4, bvi_ip6=None,
280 retention=VppGbpEndpointRetention()):
Neale Ranns25b04942018-04-04 09:34:50 -0700281 self._test = test
282 self.uplink = uplink
283 self.bvi = bvi
Neale Ranns4d5b9172018-10-24 02:57:49 -0700284 self.bvi_ip4 = VppIpAddress(bvi_ip4)
285 self.bvi_ip6 = VppIpAddress(bvi_ip6)
Neale Ranns4ba67722019-02-28 11:11:39 +0000286 self.vnid = vnid
Neale Ranns25b04942018-04-04 09:34:50 -0700287 self.bd = bd
288 self.rd = rd
Neale Ranns879d11c2019-01-21 23:34:18 -0800289 self.sclass = sclass
290 if 0 == self.sclass:
291 self.sclass = 0xffff
Neale Ranns32f6d8e2019-03-05 04:22:08 -0800292 self.retention = retention
Neale Ranns25b04942018-04-04 09:34:50 -0700293
294 def add_vpp_config(self):
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700295 self._test.vapi.gbp_endpoint_group_add(
Neale Ranns4ba67722019-02-28 11:11:39 +0000296 self.vnid,
Neale Ranns879d11c2019-01-21 23:34:18 -0800297 self.sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700298 self.bd.bd.bd_id,
299 self.rd.rd_id,
Neale Ranns32f6d8e2019-03-05 04:22:08 -0800300 self.uplink.sw_if_index if self.uplink else INDEX_INVALID,
301 self.retention.encode())
Neale Ranns25b04942018-04-04 09:34:50 -0700302 self._test.registry.register(self, self._test.logger)
303
304 def remove_vpp_config(self):
Neale Ranns4ba67722019-02-28 11:11:39 +0000305 self._test.vapi.gbp_endpoint_group_del(self.sclass)
Neale Ranns25b04942018-04-04 09:34:50 -0700306
Neale Ranns25b04942018-04-04 09:34:50 -0700307 def object_id(self):
Neale Ranns4ba67722019-02-28 11:11:39 +0000308 return "gbp-endpoint-group:[%d]" % (self.vnid)
Neale Ranns25b04942018-04-04 09:34:50 -0700309
310 def query_vpp_config(self):
311 epgs = self._test.vapi.gbp_endpoint_group_dump()
312 for epg in epgs:
Neale Ranns4ba67722019-02-28 11:11:39 +0000313 if epg.epg.vnid == self.vnid:
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800314 return True
315 return False
316
317
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700318class VppGbpBridgeDomain(VppObject):
319 """
320 GBP Bridge Domain
321 """
322
Neale Ranns879d11c2019-01-21 23:34:18 -0800323 def __init__(self, test, bd, bvi, uu_fwd=None,
Mohsin Kazmi8ea109e2019-03-22 15:13:31 +0100324 bm_flood=None, learn=True, uu_drop=False, bm_drop=False):
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700325 self._test = test
326 self.bvi = bvi
Neale Ranns879d11c2019-01-21 23:34:18 -0800327 self.uu_fwd = uu_fwd
328 self.bm_flood = bm_flood
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700329 self.bd = bd
330
Neale Rannsc29c0af2018-11-07 04:21:12 -0800331 e = VppEnum.vl_api_gbp_bridge_domain_flags_t
332 if (learn):
333 self.learn = e.GBP_BD_API_FLAG_NONE
334 else:
335 self.learn = e.GBP_BD_API_FLAG_DO_NOT_LEARN
Mohsin Kazmi8ea109e2019-03-22 15:13:31 +0100336 if (uu_drop):
337 self.learn |= e.GBP_BD_API_FLAG_UU_FWD_DROP
338 if (bm_drop):
339 self.learn |= e.GBP_BD_API_FLAG_MCAST_DROP
Neale Rannsc29c0af2018-11-07 04:21:12 -0800340
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700341 def add_vpp_config(self):
342 self._test.vapi.gbp_bridge_domain_add(
343 self.bd.bd_id,
Neale Rannsc29c0af2018-11-07 04:21:12 -0800344 self.learn,
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700345 self.bvi.sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -0800346 self.uu_fwd.sw_if_index if self.uu_fwd else INDEX_INVALID,
347 self.bm_flood.sw_if_index if self.bm_flood else INDEX_INVALID)
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700348 self._test.registry.register(self, self._test.logger)
349
350 def remove_vpp_config(self):
351 self._test.vapi.gbp_bridge_domain_del(self.bd.bd_id)
352
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700353 def object_id(self):
354 return "gbp-bridge-domain:[%d]" % (self.bd.bd_id)
355
356 def query_vpp_config(self):
357 bds = self._test.vapi.gbp_bridge_domain_dump()
358 for bd in bds:
359 if bd.bd.bd_id == self.bd.bd_id:
360 return True
361 return False
362
363
364class VppGbpRouteDomain(VppObject):
365 """
366 GBP Route Domain
367 """
368
369 def __init__(self, test, rd_id, t4, t6, ip4_uu=None, ip6_uu=None):
370 self._test = test
371 self.rd_id = rd_id
372 self.t4 = t4
373 self.t6 = t6
374 self.ip4_uu = ip4_uu
375 self.ip6_uu = ip6_uu
376
377 def add_vpp_config(self):
378 self._test.vapi.gbp_route_domain_add(
379 self.rd_id,
380 self.t4.table_id,
381 self.t6.table_id,
382 self.ip4_uu.sw_if_index if self.ip4_uu else INDEX_INVALID,
383 self.ip6_uu.sw_if_index if self.ip6_uu else INDEX_INVALID)
384 self._test.registry.register(self, self._test.logger)
385
386 def remove_vpp_config(self):
387 self._test.vapi.gbp_route_domain_del(self.rd_id)
388
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700389 def object_id(self):
390 return "gbp-route-domain:[%d]" % (self.rd_id)
391
392 def query_vpp_config(self):
393 rds = self._test.vapi.gbp_route_domain_dump()
394 for rd in rds:
395 if rd.rd.rd_id == self.rd_id:
396 return True
397 return False
398
399
Neale Ranns13a08cc2018-11-07 09:25:54 -0800400class VppGbpContractNextHop():
401 def __init__(self, mac, bd, ip, rd):
402 self.mac = mac
403 self.ip = ip
404 self.bd = bd
405 self.rd = rd
406
407 def encode(self):
408 return {'ip': self.ip.encode(),
Ole Troan8006c6a2018-12-17 12:02:26 +0100409 'mac': self.mac.packed,
Neale Ranns13a08cc2018-11-07 09:25:54 -0800410 'bd_id': self.bd.bd.bd_id,
411 'rd_id': self.rd.rd_id}
412
413
414class VppGbpContractRule():
Mohsin Kazmid40c3e62018-11-21 10:46:57 +0100415 def __init__(self, action, hash_mode, nhs=[]):
Neale Ranns13a08cc2018-11-07 09:25:54 -0800416 self.action = action
Mohsin Kazmid40c3e62018-11-21 10:46:57 +0100417 self.hash_mode = hash_mode
Neale Ranns13a08cc2018-11-07 09:25:54 -0800418 self.nhs = nhs
Neale Ranns13a08cc2018-11-07 09:25:54 -0800419
420 def encode(self):
421 nhs = []
422 for nh in self.nhs:
423 nhs.append(nh.encode())
424 while len(nhs) < 8:
425 nhs.append({})
426 return {'action': self.action,
427 'nh_set': {
428 'hash_mode': self.hash_mode,
429 'n_nhs': len(self.nhs),
430 'nhs': nhs}}
431
432
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800433class VppGbpContract(VppObject):
434 """
Mohsin Kazmi22b3b842018-04-17 19:35:42 +0200435 GBP Contract
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800436 """
437
Neale Ranns4dd4cf42019-03-27 05:06:47 -0700438 def __init__(self, test, sclass, dclass, acl_index,
Neale Ranns1c17e2e2018-12-20 12:03:59 -0800439 rules, allowed_ethertypes):
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800440 self._test = test
441 self.acl_index = acl_index
Neale Ranns4dd4cf42019-03-27 05:06:47 -0700442 self.sclass = sclass
443 self.dclass = dclass
Neale Ranns13a08cc2018-11-07 09:25:54 -0800444 self.rules = rules
Neale Ranns1c17e2e2018-12-20 12:03:59 -0800445 self.allowed_ethertypes = allowed_ethertypes
Neale Rannsfa0ac2c2019-03-12 04:34:53 -0700446 while (len(self.allowed_ethertypes) < 16):
447 self.allowed_ethertypes.append(0)
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800448
449 def add_vpp_config(self):
Neale Ranns13a08cc2018-11-07 09:25:54 -0800450 rules = []
451 for r in self.rules:
452 rules.append(r.encode())
Neale Ranns796c84b2019-03-28 07:56:23 -0700453 r = self._test.vapi.gbp_contract_add_del(
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800454 1,
Neale Ranns4dd4cf42019-03-27 05:06:47 -0700455 self.sclass,
456 self.dclass,
Neale Ranns13a08cc2018-11-07 09:25:54 -0800457 self.acl_index,
Neale Ranns1c17e2e2018-12-20 12:03:59 -0800458 rules,
459 self.allowed_ethertypes)
Neale Ranns796c84b2019-03-28 07:56:23 -0700460 self.stats_index = r.stats_index
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800461 self._test.registry.register(self, self._test.logger)
462
463 def remove_vpp_config(self):
464 self._test.vapi.gbp_contract_add_del(
465 0,
Neale Ranns4dd4cf42019-03-27 05:06:47 -0700466 self.sclass,
467 self.dclass,
Neale Ranns13a08cc2018-11-07 09:25:54 -0800468 self.acl_index,
Neale Rannsfa0ac2c2019-03-12 04:34:53 -0700469 [],
470 self.allowed_ethertypes)
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800471
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800472 def object_id(self):
Neale Ranns4dd4cf42019-03-27 05:06:47 -0700473 return "gbp-contract:[%d:%s:%d]" % (self.sclass,
474 self.dclass,
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800475 self.acl_index)
476
477 def query_vpp_config(self):
Neale Ranns25b04942018-04-04 09:34:50 -0700478 cs = self._test.vapi.gbp_contract_dump()
479 for c in cs:
Neale Ranns4dd4cf42019-03-27 05:06:47 -0700480 if c.contract.sclass == self.sclass \
Filip Vargaf4749ca2019-04-25 14:55:32 +0200481 and c.contract.dclass == self.dclass:
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800482 return True
483 return False
484
Neale Ranns796c84b2019-03-28 07:56:23 -0700485 def get_drop_stats(self):
486 c = self._test.statistics.get_counter("/net/gbp/contract/drop")
487 return c[0][self.stats_index]
488
489 def get_permit_stats(self):
490 c = self._test.statistics.get_counter("/net/gbp/contract/permit")
491 return c[0][self.stats_index]
492
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800493
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700494class VppGbpVxlanTunnel(VppInterface):
495 """
496 GBP VXLAN tunnel
497 """
498
Neale Ranns8da9fc62019-03-04 14:08:11 -0800499 def __init__(self, test, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700500 super(VppGbpVxlanTunnel, self).__init__(test)
501 self._test = test
502 self.vni = vni
503 self.bd_rd_id = bd_rd_id
504 self.mode = mode
Neale Ranns8da9fc62019-03-04 14:08:11 -0800505 self.src = src
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700506
507 def add_vpp_config(self):
508 r = self._test.vapi.gbp_vxlan_tunnel_add(
509 self.vni,
510 self.bd_rd_id,
Neale Ranns8da9fc62019-03-04 14:08:11 -0800511 self.mode,
512 self.src)
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700513 self.set_sw_if_index(r.sw_if_index)
514 self._test.registry.register(self, self._test.logger)
515
516 def remove_vpp_config(self):
517 self._test.vapi.gbp_vxlan_tunnel_del(self.vni)
518
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700519 def object_id(self):
Neale Ranns8da9fc62019-03-04 14:08:11 -0800520 return "gbp-vxlan:%d" % (self.sw_if_index)
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700521
522 def query_vpp_config(self):
523 return find_gbp_vxlan(self._test, self.vni)
524
525
Mohsin Kazmi22b3b842018-04-17 19:35:42 +0200526class VppGbpAcl(VppObject):
527 """
528 GBP Acl
529 """
530
531 def __init__(self, test):
532 self._test = test
533 self.acl_index = 4294967295
534
535 def create_rule(self, is_ipv6=0, permit_deny=0, proto=-1,
Paul Vinciguerra22ab6f72019-03-07 17:55:33 -0800536 s_prefix=0, s_ip=b'\x00\x00\x00\x00', sport_from=0,
537 sport_to=65535, d_prefix=0, d_ip=b'\x00\x00\x00\x00',
Mohsin Kazmi22b3b842018-04-17 19:35:42 +0200538 dport_from=0, dport_to=65535):
539 if proto == -1 or proto == 0:
540 sport_to = 0
541 dport_to = sport_to
542 elif proto == 1 or proto == 58:
543 sport_to = 255
544 dport_to = sport_to
545 rule = ({'is_permit': permit_deny, 'is_ipv6': is_ipv6, 'proto': proto,
546 'srcport_or_icmptype_first': sport_from,
547 'srcport_or_icmptype_last': sport_to,
548 'src_ip_prefix_len': s_prefix,
549 'src_ip_addr': s_ip,
550 'dstport_or_icmpcode_first': dport_from,
551 'dstport_or_icmpcode_last': dport_to,
552 'dst_ip_prefix_len': d_prefix,
553 'dst_ip_addr': d_ip})
554 return rule
555
556 def add_vpp_config(self, rules):
557
558 reply = self._test.vapi.acl_add_replace(self.acl_index,
559 r=rules,
Paul Vinciguerra22ab6f72019-03-07 17:55:33 -0800560 tag=b'GBPTest')
Mohsin Kazmi22b3b842018-04-17 19:35:42 +0200561 self.acl_index = reply.acl_index
562 return self.acl_index
563
564 def remove_vpp_config(self):
565 self._test.vapi.acl_del(self.acl_index)
566
Mohsin Kazmi22b3b842018-04-17 19:35:42 +0200567 def object_id(self):
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700568 return "gbp-acl:[%d]" % (self.acl_index)
Mohsin Kazmi22b3b842018-04-17 19:35:42 +0200569
570 def query_vpp_config(self):
571 cs = self._test.vapi.acl_dump()
572 for c in cs:
573 if c.acl_index == self.acl_index:
574 return True
575 return False
576
577
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800578class TestGBP(VppTestCase):
579 """ GBP Test Case """
580
Filip Vargadd1e3e72019-04-15 18:52:43 +0200581 @property
582 def config_flags(self):
583 return VppEnum.vl_api_nat_config_flags_t
584
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700585 @classmethod
586 def setUpClass(cls):
587 super(TestGBP, cls).setUpClass()
588
589 @classmethod
590 def tearDownClass(cls):
591 super(TestGBP, cls).tearDownClass()
592
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800593 def setUp(self):
594 super(TestGBP, self).setUp()
595
Neale Ranns25b04942018-04-04 09:34:50 -0700596 self.create_pg_interfaces(range(9))
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700597 self.create_loopback_interfaces(8)
Neale Ranns25b04942018-04-04 09:34:50 -0700598
Ole Troan8006c6a2018-12-17 12:02:26 +0100599 self.router_mac = MACAddress("00:11:22:33:44:55")
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800600
601 for i in self.pg_interfaces:
602 i.admin_up()
Neale Ranns25b04942018-04-04 09:34:50 -0700603 for i in self.lo_interfaces:
604 i.admin_up()
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800605
606 def tearDown(self):
607 for i in self.pg_interfaces:
Neale Ranns25b04942018-04-04 09:34:50 -0700608 i.admin_down()
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800609
610 super(TestGBP, self).tearDown()
611
Neale Ranns25b04942018-04-04 09:34:50 -0700612 def send_and_expect_bridged(self, src, tx, dst):
613 rx = self.send_and_expect(src, tx, dst)
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800614
Neale Ranns25b04942018-04-04 09:34:50 -0700615 for r in rx:
616 self.assertEqual(r[Ether].src, tx[0][Ether].src)
617 self.assertEqual(r[Ether].dst, tx[0][Ether].dst)
618 self.assertEqual(r[IP].src, tx[0][IP].src)
619 self.assertEqual(r[IP].dst, tx[0][IP].dst)
620 return rx
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800621
Neale Ranns25b04942018-04-04 09:34:50 -0700622 def send_and_expect_bridged6(self, src, tx, dst):
623 rx = self.send_and_expect(src, tx, dst)
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800624
Neale Ranns25b04942018-04-04 09:34:50 -0700625 for r in rx:
626 self.assertEqual(r[Ether].src, tx[0][Ether].src)
627 self.assertEqual(r[Ether].dst, tx[0][Ether].dst)
628 self.assertEqual(r[IPv6].src, tx[0][IPv6].src)
629 self.assertEqual(r[IPv6].dst, tx[0][IPv6].dst)
630 return rx
631
632 def send_and_expect_routed(self, src, tx, dst, src_mac):
633 rx = self.send_and_expect(src, tx, dst)
634
635 for r in rx:
636 self.assertEqual(r[Ether].src, src_mac)
637 self.assertEqual(r[Ether].dst, dst.remote_mac)
638 self.assertEqual(r[IP].src, tx[0][IP].src)
639 self.assertEqual(r[IP].dst, tx[0][IP].dst)
640 return rx
641
642 def send_and_expect_natted(self, src, tx, dst, src_ip):
643 rx = self.send_and_expect(src, tx, dst)
644
645 for r in rx:
646 self.assertEqual(r[Ether].src, tx[0][Ether].src)
647 self.assertEqual(r[Ether].dst, tx[0][Ether].dst)
648 self.assertEqual(r[IP].src, src_ip)
649 self.assertEqual(r[IP].dst, tx[0][IP].dst)
650 return rx
651
Neale Ranns4a6d0232018-04-24 07:45:33 -0700652 def send_and_expect_natted6(self, src, tx, dst, src_ip):
653 rx = self.send_and_expect(src, tx, dst)
654
655 for r in rx:
656 self.assertEqual(r[Ether].src, tx[0][Ether].src)
657 self.assertEqual(r[Ether].dst, tx[0][Ether].dst)
658 self.assertEqual(r[IPv6].src, src_ip)
659 self.assertEqual(r[IPv6].dst, tx[0][IPv6].dst)
660 return rx
661
Neale Ranns25b04942018-04-04 09:34:50 -0700662 def send_and_expect_unnatted(self, src, tx, dst, dst_ip):
663 rx = self.send_and_expect(src, tx, dst)
664
665 for r in rx:
666 self.assertEqual(r[Ether].src, tx[0][Ether].src)
667 self.assertEqual(r[Ether].dst, tx[0][Ether].dst)
668 self.assertEqual(r[IP].dst, dst_ip)
669 self.assertEqual(r[IP].src, tx[0][IP].src)
670 return rx
671
Neale Ranns4a6d0232018-04-24 07:45:33 -0700672 def send_and_expect_unnatted6(self, src, tx, dst, dst_ip):
673 rx = self.send_and_expect(src, tx, dst)
674
675 for r in rx:
676 self.assertEqual(r[Ether].src, tx[0][Ether].src)
677 self.assertEqual(r[Ether].dst, tx[0][Ether].dst)
678 self.assertEqual(r[IPv6].dst, dst_ip)
679 self.assertEqual(r[IPv6].src, tx[0][IPv6].src)
680 return rx
681
Neale Ranns25b04942018-04-04 09:34:50 -0700682 def send_and_expect_double_natted(self, src, tx, dst, src_ip, dst_ip):
683 rx = self.send_and_expect(src, tx, dst)
684
685 for r in rx:
Ole Troan8006c6a2018-12-17 12:02:26 +0100686 self.assertEqual(r[Ether].src, str(self.router_mac))
Neale Ranns25b04942018-04-04 09:34:50 -0700687 self.assertEqual(r[Ether].dst, dst.remote_mac)
688 self.assertEqual(r[IP].dst, dst_ip)
689 self.assertEqual(r[IP].src, src_ip)
690 return rx
691
Neale Ranns4a6d0232018-04-24 07:45:33 -0700692 def send_and_expect_double_natted6(self, src, tx, dst, src_ip, dst_ip):
693 rx = self.send_and_expect(src, tx, dst)
694
695 for r in rx:
Ole Troan8006c6a2018-12-17 12:02:26 +0100696 self.assertEqual(r[Ether].src, str(self.router_mac))
Neale Ranns4a6d0232018-04-24 07:45:33 -0700697 self.assertEqual(r[Ether].dst, dst.remote_mac)
698 self.assertEqual(r[IPv6].dst, dst_ip)
699 self.assertEqual(r[IPv6].src, src_ip)
700 return rx
701
Mohsin Kazmife52dea2019-04-18 15:54:58 +0200702 def send_and_expect_no_arp(self, src, tx, dst):
703 self.pg_send(src, tx)
704 dst.get_capture(0, timeout=1)
705 dst.assert_nothing_captured(remark="")
706 timeout = 0.1
707
708 def send_and_expect_arp(self, src, tx, dst):
709 rx = self.send_and_expect(src, tx, dst)
710
711 for r in rx:
712 self.assertEqual(r[Ether].src, tx[0][Ether].src)
713 self.assertEqual(r[Ether].dst, tx[0][Ether].dst)
714 self.assertEqual(r[ARP].psrc, tx[0][ARP].psrc)
715 self.assertEqual(r[ARP].pdst, tx[0][ARP].pdst)
716 self.assertEqual(r[ARP].hwsrc, tx[0][ARP].hwsrc)
717 self.assertEqual(r[ARP].hwdst, tx[0][ARP].hwdst)
718 return rx
719
Neale Ranns25b04942018-04-04 09:34:50 -0700720 def test_gbp(self):
721 """ Group Based Policy """
722
Neale Rannsb6a47952018-11-21 05:44:35 -0800723 ep_flags = VppEnum.vl_api_gbp_endpoint_flags_t
724
Neale Rannsbc27d1b2018-02-05 01:13:38 -0800725 #
Neale Ranns25b04942018-04-04 09:34:50 -0700726 # Bridge Domains
727 #
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700728 bd1 = VppBridgeDomain(self, 1)
729 bd2 = VppBridgeDomain(self, 2)
730 bd20 = VppBridgeDomain(self, 20)
731
732 bd1.add_vpp_config()
733 bd2.add_vpp_config()
734 bd20.add_vpp_config()
735
736 gbd1 = VppGbpBridgeDomain(self, bd1, self.loop0)
737 gbd2 = VppGbpBridgeDomain(self, bd2, self.loop1)
738 gbd20 = VppGbpBridgeDomain(self, bd20, self.loop2)
739
740 gbd1.add_vpp_config()
741 gbd2.add_vpp_config()
742 gbd20.add_vpp_config()
743
744 #
745 # Route Domains
746 #
747 gt4 = VppIpTable(self, 0)
748 gt4.add_vpp_config()
749 gt6 = VppIpTable(self, 0, is_ip6=True)
750 gt6.add_vpp_config()
751 nt4 = VppIpTable(self, 20)
752 nt4.add_vpp_config()
753 nt6 = VppIpTable(self, 20, is_ip6=True)
754 nt6.add_vpp_config()
755
756 rd0 = VppGbpRouteDomain(self, 0, gt4, gt6, None, None)
757 rd20 = VppGbpRouteDomain(self, 20, nt4, nt6, None, None)
758
759 rd0.add_vpp_config()
760 rd20.add_vpp_config()
Neale Ranns25b04942018-04-04 09:34:50 -0700761
762 #
763 # 3 EPGs, 2 of which share a BD.
Neale Ranns25b04942018-04-04 09:34:50 -0700764 # 2 NAT EPGs, one for floating-IP subnets, the other for internet
765 #
Neale Ranns4ba67722019-02-28 11:11:39 +0000766 epgs = [VppGbpEndpointGroup(self, 220, 1220, rd0, gbd1,
767 self.pg4, self.loop0,
768 "10.0.0.128", "2001:10::128"),
769 VppGbpEndpointGroup(self, 221, 1221, rd0, gbd1,
770 self.pg5, self.loop0,
771 "10.0.1.128", "2001:10:1::128"),
772 VppGbpEndpointGroup(self, 222, 1222, rd0, gbd2,
773 self.pg6, self.loop1,
774 "10.0.2.128", "2001:10:2::128"),
775 VppGbpEndpointGroup(self, 333, 1333, rd20, gbd20,
776 self.pg7, self.loop2,
777 "11.0.0.128", "3001::128"),
778 VppGbpEndpointGroup(self, 444, 1444, rd20, gbd20,
779 self.pg8, self.loop2,
780 "11.0.0.129", "3001::129")]
781 recircs = [VppGbpRecirc(self, epgs[0], self.loop3),
782 VppGbpRecirc(self, epgs[1], self.loop4),
783 VppGbpRecirc(self, epgs[2], self.loop5),
784 VppGbpRecirc(self, epgs[3], self.loop6, is_ext=True),
785 VppGbpRecirc(self, epgs[4], self.loop7, is_ext=True)]
Neale Ranns25b04942018-04-04 09:34:50 -0700786
787 epg_nat = epgs[3]
788 recirc_nat = recircs[3]
789
790 #
791 # 4 end-points, 2 in the same subnet, 3 in the same BD
792 #
Neale Rannsc0a93142018-09-05 15:42:26 -0700793 eps = [VppGbpEndpoint(self, self.pg0,
794 epgs[0], recircs[0],
795 "10.0.0.1", "11.0.0.1",
796 "2001:10::1", "3001::1"),
797 VppGbpEndpoint(self, self.pg1,
798 epgs[0], recircs[0],
799 "10.0.0.2", "11.0.0.2",
800 "2001:10::2", "3001::2"),
801 VppGbpEndpoint(self, self.pg2,
802 epgs[1], recircs[1],
803 "10.0.1.1", "11.0.0.3",
804 "2001:10:1::1", "3001::3"),
805 VppGbpEndpoint(self, self.pg3,
806 epgs[2], recircs[2],
807 "10.0.2.1", "11.0.0.4",
808 "2001:10:2::1", "3001::4")]
Neale Ranns25b04942018-04-04 09:34:50 -0700809
810 #
811 # Config related to each of the EPGs
812 #
813 for epg in epgs:
814 # IP config on the BVI interfaces
815 if epg != epgs[1] and epg != epgs[4]:
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700816 VppIpInterfaceBind(self, epg.bvi, epg.rd.t4).add_vpp_config()
817 VppIpInterfaceBind(self, epg.bvi, epg.rd.t6).add_vpp_config()
818 self.vapi.sw_interface_set_mac_address(
819 epg.bvi.sw_if_index,
Ole Troan8006c6a2018-12-17 12:02:26 +0100820 self.router_mac.packed)
Neale Ranns25b04942018-04-04 09:34:50 -0700821
822 # The BVIs are NAT inside interfaces
Filip Vargadd1e3e72019-04-15 18:52:43 +0200823 flags = self.config_flags.NAT_IS_INSIDE
Filip Vargaf4749ca2019-04-25 14:55:32 +0200824 self.vapi.nat44_interface_add_del_feature(
825 sw_if_index=epg.bvi.sw_if_index,
826 flags=flags, is_add=1)
827 self.vapi.nat66_add_del_interface(
828 is_add=1, flags=flags,
829 sw_if_index=epg.bvi.sw_if_index)
Neale Ranns25b04942018-04-04 09:34:50 -0700830
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700831 if_ip4 = VppIpInterfaceAddress(self, epg.bvi, epg.bvi_ip4, 32)
832 if_ip6 = VppIpInterfaceAddress(self, epg.bvi, epg.bvi_ip6, 128)
833 if_ip4.add_vpp_config()
834 if_ip6.add_vpp_config()
Neale Ranns25b04942018-04-04 09:34:50 -0700835
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700836 # EPG uplink interfaces in the RD
837 VppIpInterfaceBind(self, epg.uplink, epg.rd.t4).add_vpp_config()
838 VppIpInterfaceBind(self, epg.uplink, epg.rd.t6).add_vpp_config()
Neale Ranns25b04942018-04-04 09:34:50 -0700839
840 # add the BD ARP termination entry for BVI IP
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700841 epg.bd_arp_ip4 = VppBridgeDomainArpEntry(self, epg.bd.bd,
Ole Troan8006c6a2018-12-17 12:02:26 +0100842 str(self.router_mac),
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700843 epg.bvi_ip4)
844 epg.bd_arp_ip6 = VppBridgeDomainArpEntry(self, epg.bd.bd,
Ole Troan8006c6a2018-12-17 12:02:26 +0100845 str(self.router_mac),
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700846 epg.bvi_ip6)
847 epg.bd_arp_ip4.add_vpp_config()
848 epg.bd_arp_ip6.add_vpp_config()
Neale Ranns25b04942018-04-04 09:34:50 -0700849
850 # EPG in VPP
851 epg.add_vpp_config()
852
853 for recirc in recircs:
854 # EPG's ingress recirculation interface maps to its RD
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700855 VppIpInterfaceBind(self, recirc.recirc,
856 recirc.epg.rd.t4).add_vpp_config()
857 VppIpInterfaceBind(self, recirc.recirc,
858 recirc.epg.rd.t6).add_vpp_config()
Neale Ranns25b04942018-04-04 09:34:50 -0700859
Neale Ranns4a6d0232018-04-24 07:45:33 -0700860 self.vapi.nat44_interface_add_del_feature(
Filip Vargaf4749ca2019-04-25 14:55:32 +0200861 sw_if_index=recirc.recirc.sw_if_index, is_add=1)
Neale Ranns4a6d0232018-04-24 07:45:33 -0700862 self.vapi.nat66_add_del_interface(
Filip Vargaf4749ca2019-04-25 14:55:32 +0200863 is_add=1,
864 sw_if_index=recirc.recirc.sw_if_index)
Neale Ranns25b04942018-04-04 09:34:50 -0700865
866 recirc.add_vpp_config()
867
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700868 for recirc in recircs:
869 self.assertTrue(find_bridge_domain_port(self,
870 recirc.epg.bd.bd.bd_id,
871 recirc.recirc.sw_if_index))
872
Neale Ranns25b04942018-04-04 09:34:50 -0700873 for ep in eps:
874 self.pg_enable_capture(self.pg_interfaces)
875 self.pg_start()
876 #
877 # routes to the endpoints. We need these since there are no
878 # adj-fibs due to the fact the the BVI address has /32 and
879 # the subnet is not attached.
880 #
Neale Rannsc0a93142018-09-05 15:42:26 -0700881 for (ip, fip) in zip(ep.ips, ep.fips):
Neale Rannsc0a93142018-09-05 15:42:26 -0700882 # Add static mappings for each EP from the 10/8 to 11/8 network
883 if ip.af == AF_INET:
Filip Vargadd1e3e72019-04-15 18:52:43 +0200884 flags = self.config_flags.NAT_IS_ADDR_ONLY
Filip Vargaf4749ca2019-04-25 14:55:32 +0200885 self.vapi.nat44_add_del_static_mapping(
886 is_add=1,
887 local_ip_address=ip.bytes,
888 external_ip_address=fip.bytes,
889 external_sw_if_index=0xFFFFFFFF,
890 vrf_id=0,
891 flags=flags)
Neale Rannsc0a93142018-09-05 15:42:26 -0700892 else:
Filip Vargaf4749ca2019-04-25 14:55:32 +0200893 self.vapi.nat66_add_del_static_mapping(
894 local_ip_address=ip.bytes,
895 external_ip_address=fip.bytes,
896 vrf_id=0, is_add=1)
Neale Ranns25b04942018-04-04 09:34:50 -0700897
Neale Ranns25b04942018-04-04 09:34:50 -0700898 # VPP EP create ...
899 ep.add_vpp_config()
900
Neale Rannsc0a93142018-09-05 15:42:26 -0700901 self.logger.info(self.vapi.cli("sh gbp endpoint"))
Neale Ranns25b04942018-04-04 09:34:50 -0700902
Neale Rannsc0a93142018-09-05 15:42:26 -0700903 # ... results in a Gratuitous ARP/ND on the EPG's uplink
904 rx = ep.epg.uplink.get_capture(len(ep.ips), timeout=0.2)
905
906 for ii, ip in enumerate(ep.ips):
907 p = rx[ii]
908
909 if ip.is_ip6:
910 self.assertTrue(p.haslayer(ICMPv6ND_NA))
911 self.assertEqual(p[ICMPv6ND_NA].tgt, ip.address)
912 else:
913 self.assertTrue(p.haslayer(ARP))
914 self.assertEqual(p[ARP].psrc, ip.address)
915 self.assertEqual(p[ARP].pdst, ip.address)
Neale Ranns25b04942018-04-04 09:34:50 -0700916
917 # add the BD ARP termination entry for floating IP
Neale Rannsc0a93142018-09-05 15:42:26 -0700918 for fip in ep.fips:
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700919 ba = VppBridgeDomainArpEntry(self, epg_nat.bd.bd, ep.mac, fip)
920 ba.add_vpp_config()
Neale Ranns25b04942018-04-04 09:34:50 -0700921
Neale Rannsc0a93142018-09-05 15:42:26 -0700922 # floating IPs route via EPG recirc
923 r = VppIpRoute(self, fip.address, fip.length,
924 [VppRoutePath(fip.address,
925 ep.recirc.recirc.sw_if_index,
926 is_dvr=1,
927 proto=fip.dpo_proto)],
928 table_id=20,
929 is_ip6=fip.is_ip6)
930 r.add_vpp_config()
Neale Ranns25b04942018-04-04 09:34:50 -0700931
932 # L2 FIB entries in the NAT EPG BD to bridge the packets from
933 # the outside direct to the internal EPG
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700934 lf = VppL2FibEntry(self, epg_nat.bd.bd, ep.mac,
935 ep.recirc.recirc, bvi_mac=0)
936 lf.add_vpp_config()
Neale Ranns25b04942018-04-04 09:34:50 -0700937
938 #
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700939 # ARP packets for unknown IP are sent to the EPG uplink
Neale Ranns25b04942018-04-04 09:34:50 -0700940 #
941 pkt_arp = (Ether(dst="ff:ff:ff:ff:ff:ff",
942 src=self.pg0.remote_mac) /
943 ARP(op="who-has",
944 hwdst="ff:ff:ff:ff:ff:ff",
945 hwsrc=self.pg0.remote_mac,
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700946 pdst="10.0.0.88",
947 psrc="10.0.0.99"))
Neale Ranns25b04942018-04-04 09:34:50 -0700948
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700949 self.vapi.cli("clear trace")
950 self.pg0.add_stream(pkt_arp)
951
952 self.pg_enable_capture(self.pg_interfaces)
953 self.pg_start()
954
955 rxd = epgs[0].uplink.get_capture(1)
Neale Ranns25b04942018-04-04 09:34:50 -0700956
957 #
958 # ARP/ND packets get a response
959 #
960 pkt_arp = (Ether(dst="ff:ff:ff:ff:ff:ff",
961 src=self.pg0.remote_mac) /
962 ARP(op="who-has",
963 hwdst="ff:ff:ff:ff:ff:ff",
964 hwsrc=self.pg0.remote_mac,
Neale Ranns4d5b9172018-10-24 02:57:49 -0700965 pdst=epgs[0].bvi_ip4.address,
Neale Rannsc0a93142018-09-05 15:42:26 -0700966 psrc=eps[0].ip4.address))
Neale Ranns25b04942018-04-04 09:34:50 -0700967
968 self.send_and_expect(self.pg0, [pkt_arp], self.pg0)
969
Neale Rannsc0a93142018-09-05 15:42:26 -0700970 nsma = in6_getnsma(inet_pton(AF_INET6, eps[0].ip6.address))
Neale Ranns25b04942018-04-04 09:34:50 -0700971 d = inet_ntop(AF_INET6, nsma)
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700972 pkt_nd = (Ether(dst=in6_getnsmac(nsma),
973 src=self.pg0.remote_mac) /
Neale Rannsc0a93142018-09-05 15:42:26 -0700974 IPv6(dst=d, src=eps[0].ip6.address) /
Neale Ranns4d5b9172018-10-24 02:57:49 -0700975 ICMPv6ND_NS(tgt=epgs[0].bvi_ip6.address) /
Neale Ranns25b04942018-04-04 09:34:50 -0700976 ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac))
977 self.send_and_expect(self.pg0, [pkt_nd], self.pg0)
978
979 #
980 # broadcast packets are flooded
981 #
982 pkt_bcast = (Ether(dst="ff:ff:ff:ff:ff:ff",
983 src=self.pg0.remote_mac) /
Neale Rannsc0a93142018-09-05 15:42:26 -0700984 IP(src=eps[0].ip4.address, dst="232.1.1.1") /
Neale Ranns25b04942018-04-04 09:34:50 -0700985 UDP(sport=1234, dport=1234) /
986 Raw('\xa5' * 100))
987
988 self.vapi.cli("clear trace")
989 self.pg0.add_stream(pkt_bcast)
990
991 self.pg_enable_capture(self.pg_interfaces)
992 self.pg_start()
993
994 rxd = eps[1].itf.get_capture(1)
995 self.assertEqual(rxd[0][Ether].dst, pkt_bcast[Ether].dst)
996 rxd = epgs[0].uplink.get_capture(1)
997 self.assertEqual(rxd[0][Ether].dst, pkt_bcast[Ether].dst)
998
999 #
1000 # packets to non-local L3 destinations dropped
1001 #
1002 pkt_intra_epg_220_ip4 = (Ether(src=self.pg0.remote_mac,
Ole Troan8006c6a2018-12-17 12:02:26 +01001003 dst=str(self.router_mac)) /
Neale Rannsc0a93142018-09-05 15:42:26 -07001004 IP(src=eps[0].ip4.address,
1005 dst="10.0.0.99") /
Neale Ranns25b04942018-04-04 09:34:50 -07001006 UDP(sport=1234, dport=1234) /
1007 Raw('\xa5' * 100))
1008 pkt_inter_epg_222_ip4 = (Ether(src=self.pg0.remote_mac,
Ole Troan8006c6a2018-12-17 12:02:26 +01001009 dst=str(self.router_mac)) /
Neale Rannsc0a93142018-09-05 15:42:26 -07001010 IP(src=eps[0].ip4.address,
1011 dst="10.0.1.99") /
Neale Ranns25b04942018-04-04 09:34:50 -07001012 UDP(sport=1234, dport=1234) /
1013 Raw('\xa5' * 100))
1014
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001015 self.send_and_assert_no_replies(self.pg0,
1016 pkt_intra_epg_220_ip4 * NUM_PKTS)
Neale Ranns25b04942018-04-04 09:34:50 -07001017
1018 pkt_inter_epg_222_ip6 = (Ether(src=self.pg0.remote_mac,
Ole Troan8006c6a2018-12-17 12:02:26 +01001019 dst=str(self.router_mac)) /
Neale Rannsc0a93142018-09-05 15:42:26 -07001020 IPv6(src=eps[0].ip6.address,
1021 dst="2001:10::99") /
Neale Ranns25b04942018-04-04 09:34:50 -07001022 UDP(sport=1234, dport=1234) /
1023 Raw('\xa5' * 100))
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001024 self.send_and_assert_no_replies(self.pg0,
1025 pkt_inter_epg_222_ip6 * NUM_PKTS)
Neale Ranns25b04942018-04-04 09:34:50 -07001026
1027 #
1028 # Add the subnet routes
1029 #
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001030 s41 = VppGbpSubnet(
1031 self, rd0, "10.0.0.0", 24,
1032 VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_INTERNAL)
1033 s42 = VppGbpSubnet(
1034 self, rd0, "10.0.1.0", 24,
1035 VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_INTERNAL)
1036 s43 = VppGbpSubnet(
1037 self, rd0, "10.0.2.0", 24,
1038 VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_INTERNAL)
1039 s61 = VppGbpSubnet(
1040 self, rd0, "2001:10::1", 64,
1041 VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_INTERNAL)
1042 s62 = VppGbpSubnet(
1043 self, rd0, "2001:10:1::1", 64,
1044 VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_INTERNAL)
1045 s63 = VppGbpSubnet(
1046 self, rd0, "2001:10:2::1", 64,
1047 VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_INTERNAL)
Neale Ranns25b04942018-04-04 09:34:50 -07001048 s41.add_vpp_config()
1049 s42.add_vpp_config()
1050 s43.add_vpp_config()
Neale Ranns25b04942018-04-04 09:34:50 -07001051 s61.add_vpp_config()
1052 s62.add_vpp_config()
1053 s63.add_vpp_config()
1054
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001055 self.send_and_expect_bridged(eps[0].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001056 pkt_intra_epg_220_ip4 * NUM_PKTS,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001057 eps[0].epg.uplink)
1058 self.send_and_expect_bridged(eps[0].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001059 pkt_inter_epg_222_ip4 * NUM_PKTS,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001060 eps[0].epg.uplink)
1061 self.send_and_expect_bridged6(eps[0].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001062 pkt_inter_epg_222_ip6 * NUM_PKTS,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001063 eps[0].epg.uplink)
Neale Ranns25b04942018-04-04 09:34:50 -07001064
1065 self.logger.info(self.vapi.cli("sh ip fib 11.0.0.2"))
1066 self.logger.info(self.vapi.cli("sh gbp endpoint-group"))
1067 self.logger.info(self.vapi.cli("sh gbp endpoint"))
1068 self.logger.info(self.vapi.cli("sh gbp recirc"))
1069 self.logger.info(self.vapi.cli("sh int"))
1070 self.logger.info(self.vapi.cli("sh int addr"))
1071 self.logger.info(self.vapi.cli("sh int feat loop6"))
1072 self.logger.info(self.vapi.cli("sh vlib graph ip4-gbp-src-classify"))
1073 self.logger.info(self.vapi.cli("sh int feat loop3"))
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001074 self.logger.info(self.vapi.cli("sh int feat pg0"))
Neale Ranns25b04942018-04-04 09:34:50 -07001075
1076 #
1077 # Packet destined to unknown unicast is sent on the epg uplink ...
1078 #
1079 pkt_intra_epg_220_to_uplink = (Ether(src=self.pg0.remote_mac,
1080 dst="00:00:00:33:44:55") /
Neale Rannsc0a93142018-09-05 15:42:26 -07001081 IP(src=eps[0].ip4.address,
1082 dst="10.0.0.99") /
Neale Ranns25b04942018-04-04 09:34:50 -07001083 UDP(sport=1234, dport=1234) /
1084 Raw('\xa5' * 100))
1085
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001086 self.send_and_expect_bridged(eps[0].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001087 pkt_intra_epg_220_to_uplink * NUM_PKTS,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001088 eps[0].epg.uplink)
Neale Ranns25b04942018-04-04 09:34:50 -07001089 # ... and nowhere else
1090 self.pg1.get_capture(0, timeout=0.1)
1091 self.pg1.assert_nothing_captured(remark="Flood onto other VMS")
1092
1093 pkt_intra_epg_221_to_uplink = (Ether(src=self.pg2.remote_mac,
1094 dst="00:00:00:33:44:66") /
Neale Rannsc0a93142018-09-05 15:42:26 -07001095 IP(src=eps[0].ip4.address,
1096 dst="10.0.0.99") /
Neale Ranns25b04942018-04-04 09:34:50 -07001097 UDP(sport=1234, dport=1234) /
1098 Raw('\xa5' * 100))
1099
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001100 self.send_and_expect_bridged(eps[2].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001101 pkt_intra_epg_221_to_uplink * NUM_PKTS,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001102 eps[2].epg.uplink)
Neale Ranns25b04942018-04-04 09:34:50 -07001103
1104 #
1105 # Packets from the uplink are forwarded in the absence of a contract
1106 #
1107 pkt_intra_epg_220_from_uplink = (Ether(src="00:00:00:33:44:55",
1108 dst=self.pg0.remote_mac) /
Neale Rannsc0a93142018-09-05 15:42:26 -07001109 IP(src=eps[0].ip4.address,
1110 dst="10.0.0.99") /
Neale Ranns25b04942018-04-04 09:34:50 -07001111 UDP(sport=1234, dport=1234) /
1112 Raw('\xa5' * 100))
1113
1114 self.send_and_expect_bridged(self.pg4,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001115 pkt_intra_epg_220_from_uplink * NUM_PKTS,
Neale Ranns25b04942018-04-04 09:34:50 -07001116 self.pg0)
1117
1118 #
1119 # in the absence of policy, endpoints in the same EPG
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001120 # can communicate
1121 #
1122 pkt_intra_epg = (Ether(src=self.pg0.remote_mac,
Neale Ranns25b04942018-04-04 09:34:50 -07001123 dst=self.pg1.remote_mac) /
Neale Rannsc0a93142018-09-05 15:42:26 -07001124 IP(src=eps[0].ip4.address,
1125 dst=eps[1].ip4.address) /
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001126 UDP(sport=1234, dport=1234) /
1127 Raw('\xa5' * 100))
1128
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001129 self.send_and_expect_bridged(self.pg0,
1130 pkt_intra_epg * NUM_PKTS,
1131 self.pg1)
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001132
1133 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001134 # in the absence of policy, endpoints in the different EPG
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001135 # cannot communicate
1136 #
1137 pkt_inter_epg_220_to_221 = (Ether(src=self.pg0.remote_mac,
Neale Ranns25b04942018-04-04 09:34:50 -07001138 dst=self.pg2.remote_mac) /
Neale Rannsc0a93142018-09-05 15:42:26 -07001139 IP(src=eps[0].ip4.address,
1140 dst=eps[2].ip4.address) /
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001141 UDP(sport=1234, dport=1234) /
1142 Raw('\xa5' * 100))
1143 pkt_inter_epg_221_to_220 = (Ether(src=self.pg2.remote_mac,
Neale Ranns25b04942018-04-04 09:34:50 -07001144 dst=self.pg0.remote_mac) /
Neale Rannsc0a93142018-09-05 15:42:26 -07001145 IP(src=eps[2].ip4.address,
1146 dst=eps[0].ip4.address) /
Neale Ranns25b04942018-04-04 09:34:50 -07001147 UDP(sport=1234, dport=1234) /
1148 Raw('\xa5' * 100))
1149 pkt_inter_epg_220_to_222 = (Ether(src=self.pg0.remote_mac,
Ole Troan8006c6a2018-12-17 12:02:26 +01001150 dst=str(self.router_mac)) /
Neale Rannsc0a93142018-09-05 15:42:26 -07001151 IP(src=eps[0].ip4.address,
1152 dst=eps[3].ip4.address) /
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001153 UDP(sport=1234, dport=1234) /
1154 Raw('\xa5' * 100))
1155
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001156 self.send_and_assert_no_replies(eps[0].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001157 pkt_inter_epg_220_to_221 * NUM_PKTS)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001158 self.send_and_assert_no_replies(eps[0].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001159 pkt_inter_epg_220_to_222 * NUM_PKTS)
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001160
1161 #
1162 # A uni-directional contract from EPG 220 -> 221
1163 #
Mohsin Kazmi22b3b842018-04-17 19:35:42 +02001164 acl = VppGbpAcl(self)
1165 rule = acl.create_rule(permit_deny=1, proto=17)
1166 rule2 = acl.create_rule(is_ipv6=1, permit_deny=1, proto=17)
1167 acl_index = acl.add_vpp_config([rule, rule2])
Neale Ranns13a08cc2018-11-07 09:25:54 -08001168 c1 = VppGbpContract(
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001169 self, epgs[0].sclass, epgs[1].sclass, acl_index,
Neale Ranns13a08cc2018-11-07 09:25:54 -08001170 [VppGbpContractRule(
1171 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
1172 []),
Filip Vargaf4749ca2019-04-25 14:55:32 +02001173 VppGbpContractRule(
1174 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
1175 [])],
Neale Ranns1c17e2e2018-12-20 12:03:59 -08001176 [ETH_P_IP, ETH_P_IPV6])
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001177 c1.add_vpp_config()
1178
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001179 self.send_and_expect_bridged(eps[0].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001180 pkt_inter_epg_220_to_221 * NUM_PKTS,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001181 eps[2].itf)
1182 self.send_and_assert_no_replies(eps[0].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001183 pkt_inter_epg_220_to_222 * NUM_PKTS)
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001184
1185 #
1186 # contract for the return direction
1187 #
Neale Ranns13a08cc2018-11-07 09:25:54 -08001188 c2 = VppGbpContract(
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001189 self, epgs[1].sclass, epgs[0].sclass, acl_index,
Neale Ranns13a08cc2018-11-07 09:25:54 -08001190 [VppGbpContractRule(
1191 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
1192 []),
Filip Vargaf4749ca2019-04-25 14:55:32 +02001193 VppGbpContractRule(
1194 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
1195 [])],
Neale Ranns1c17e2e2018-12-20 12:03:59 -08001196 [ETH_P_IP, ETH_P_IPV6])
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001197 c2.add_vpp_config()
1198
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001199 self.send_and_expect_bridged(eps[0].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001200 pkt_inter_epg_220_to_221 * NUM_PKTS,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001201 eps[2].itf)
1202 self.send_and_expect_bridged(eps[2].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001203 pkt_inter_epg_221_to_220 * NUM_PKTS,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001204 eps[0].itf)
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001205
Neale Ranns796c84b2019-03-28 07:56:23 -07001206 ds = c2.get_drop_stats()
1207 self.assertEqual(ds['packets'], 0)
1208 ps = c2.get_permit_stats()
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001209 self.assertEqual(ps['packets'], NUM_PKTS)
Neale Ranns796c84b2019-03-28 07:56:23 -07001210
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001211 #
Neale Ranns1c17e2e2018-12-20 12:03:59 -08001212 # the contract does not allow non-IP
1213 #
1214 pkt_non_ip_inter_epg_220_to_221 = (Ether(src=self.pg0.remote_mac,
1215 dst=self.pg2.remote_mac) /
1216 ARP())
1217 self.send_and_assert_no_replies(eps[0].itf,
1218 pkt_non_ip_inter_epg_220_to_221 * 17)
1219
1220 #
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001221 # check that inter group is still disabled for the groups
1222 # not in the contract.
1223 #
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001224 self.send_and_assert_no_replies(eps[0].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001225 pkt_inter_epg_220_to_222 * NUM_PKTS)
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001226
Neale Ranns25b04942018-04-04 09:34:50 -07001227 #
1228 # A uni-directional contract from EPG 220 -> 222 'L3 routed'
1229 #
Neale Ranns13a08cc2018-11-07 09:25:54 -08001230 c3 = VppGbpContract(
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001231 self, epgs[0].sclass, epgs[2].sclass, acl_index,
Neale Ranns13a08cc2018-11-07 09:25:54 -08001232 [VppGbpContractRule(
1233 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
1234 []),
Filip Vargaf4749ca2019-04-25 14:55:32 +02001235 VppGbpContractRule(
1236 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
1237 [])],
Neale Ranns1c17e2e2018-12-20 12:03:59 -08001238 [ETH_P_IP, ETH_P_IPV6])
Neale Ranns25b04942018-04-04 09:34:50 -07001239 c3.add_vpp_config()
1240
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001241 self.logger.info(self.vapi.cli("sh gbp contract"))
1242
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001243 self.send_and_expect_routed(eps[0].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001244 pkt_inter_epg_220_to_222 * NUM_PKTS,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001245 eps[3].itf,
Ole Troan8006c6a2018-12-17 12:02:26 +01001246 str(self.router_mac))
Neale Ranns25b04942018-04-04 09:34:50 -07001247
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001248 #
1249 # remove both contracts, traffic stops in both directions
1250 #
1251 c2.remove_vpp_config()
1252 c1.remove_vpp_config()
Neale Ranns25b04942018-04-04 09:34:50 -07001253 c3.remove_vpp_config()
Mohsin Kazmi22b3b842018-04-17 19:35:42 +02001254 acl.remove_vpp_config()
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001255
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001256 self.send_and_assert_no_replies(eps[2].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001257 pkt_inter_epg_221_to_220 * NUM_PKTS)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001258 self.send_and_assert_no_replies(eps[0].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001259 pkt_inter_epg_220_to_221 * NUM_PKTS)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001260 self.send_and_expect_bridged(eps[0].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001261 pkt_intra_epg * NUM_PKTS,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001262 eps[1].itf)
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001263
1264 #
Neale Ranns25b04942018-04-04 09:34:50 -07001265 # EPs to the outside world
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001266 #
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001267
Neale Ranns25b04942018-04-04 09:34:50 -07001268 # in the EP's RD an external subnet via the NAT EPG's recirc
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001269 se1 = VppGbpSubnet(
1270 self, rd0, "0.0.0.0", 0,
1271 VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_EXTERNAL,
1272 sw_if_index=recirc_nat.recirc.sw_if_index,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001273 sclass=epg_nat.sclass)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001274 se2 = VppGbpSubnet(
1275 self, rd0, "11.0.0.0", 8,
1276 VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_EXTERNAL,
1277 sw_if_index=recirc_nat.recirc.sw_if_index,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001278 sclass=epg_nat.sclass)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001279 se16 = VppGbpSubnet(
1280 self, rd0, "::", 0,
1281 VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_EXTERNAL,
1282 sw_if_index=recirc_nat.recirc.sw_if_index,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001283 sclass=epg_nat.sclass)
Neale Ranns25b04942018-04-04 09:34:50 -07001284 # in the NAT RD an external subnet via the NAT EPG's uplink
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001285 se3 = VppGbpSubnet(
1286 self, rd20, "0.0.0.0", 0,
1287 VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_EXTERNAL,
1288 sw_if_index=epg_nat.uplink.sw_if_index,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001289 sclass=epg_nat.sclass)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001290 se36 = VppGbpSubnet(
1291 self, rd20, "::", 0,
1292 VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_EXTERNAL,
1293 sw_if_index=epg_nat.uplink.sw_if_index,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001294 sclass=epg_nat.sclass)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001295 se4 = VppGbpSubnet(
1296 self, rd20, "11.0.0.0", 8,
1297 VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_EXTERNAL,
1298 sw_if_index=epg_nat.uplink.sw_if_index,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001299 sclass=epg_nat.sclass)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001300 se1.add_vpp_config()
1301 se2.add_vpp_config()
1302 se16.add_vpp_config()
Neale Ranns25b04942018-04-04 09:34:50 -07001303 se3.add_vpp_config()
Neale Ranns4a6d0232018-04-24 07:45:33 -07001304 se36.add_vpp_config()
Neale Ranns25b04942018-04-04 09:34:50 -07001305 se4.add_vpp_config()
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001306
Neale Ranns25b04942018-04-04 09:34:50 -07001307 self.logger.info(self.vapi.cli("sh ip fib 0.0.0.0/0"))
1308 self.logger.info(self.vapi.cli("sh ip fib 11.0.0.1"))
Neale Ranns4a6d0232018-04-24 07:45:33 -07001309 self.logger.info(self.vapi.cli("sh ip6 fib ::/0"))
1310 self.logger.info(self.vapi.cli("sh ip6 fib %s" %
Neale Rannsc0a93142018-09-05 15:42:26 -07001311 eps[0].fip6))
Neale Ranns25b04942018-04-04 09:34:50 -07001312
Neale Ranns4a6d0232018-04-24 07:45:33 -07001313 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001314 # From an EP to an outside address: IN2OUT
Neale Ranns4a6d0232018-04-24 07:45:33 -07001315 #
Neale Ranns25b04942018-04-04 09:34:50 -07001316 pkt_inter_epg_220_to_global = (Ether(src=self.pg0.remote_mac,
Ole Troan8006c6a2018-12-17 12:02:26 +01001317 dst=str(self.router_mac)) /
Neale Rannsc0a93142018-09-05 15:42:26 -07001318 IP(src=eps[0].ip4.address,
1319 dst="1.1.1.1") /
Neale Ranns25b04942018-04-04 09:34:50 -07001320 UDP(sport=1234, dport=1234) /
1321 Raw('\xa5' * 100))
1322
1323 # no policy yet
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001324 self.send_and_assert_no_replies(eps[0].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001325 pkt_inter_epg_220_to_global * NUM_PKTS)
Neale Ranns25b04942018-04-04 09:34:50 -07001326
Mohsin Kazmi22b3b842018-04-17 19:35:42 +02001327 acl2 = VppGbpAcl(self)
1328 rule = acl2.create_rule(permit_deny=1, proto=17, sport_from=1234,
1329 sport_to=1234, dport_from=1234, dport_to=1234)
1330 rule2 = acl2.create_rule(is_ipv6=1, permit_deny=1, proto=17,
1331 sport_from=1234, sport_to=1234,
1332 dport_from=1234, dport_to=1234)
1333
1334 acl_index2 = acl2.add_vpp_config([rule, rule2])
Neale Ranns13a08cc2018-11-07 09:25:54 -08001335 c4 = VppGbpContract(
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001336 self, epgs[0].sclass, epgs[3].sclass, acl_index2,
Neale Ranns13a08cc2018-11-07 09:25:54 -08001337 [VppGbpContractRule(
1338 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
1339 []),
Filip Vargaf4749ca2019-04-25 14:55:32 +02001340 VppGbpContractRule(
1341 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
1342 [])],
Neale Ranns1c17e2e2018-12-20 12:03:59 -08001343 [ETH_P_IP, ETH_P_IPV6])
Neale Ranns25b04942018-04-04 09:34:50 -07001344 c4.add_vpp_config()
1345
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001346 self.send_and_expect_natted(eps[0].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001347 pkt_inter_epg_220_to_global * NUM_PKTS,
Neale Ranns25b04942018-04-04 09:34:50 -07001348 self.pg7,
Neale Rannsc0a93142018-09-05 15:42:26 -07001349 eps[0].fip4.address)
Neale Ranns25b04942018-04-04 09:34:50 -07001350
Neale Ranns4a6d0232018-04-24 07:45:33 -07001351 pkt_inter_epg_220_to_global = (Ether(src=self.pg0.remote_mac,
Ole Troan8006c6a2018-12-17 12:02:26 +01001352 dst=str(self.router_mac)) /
Neale Rannsc0a93142018-09-05 15:42:26 -07001353 IPv6(src=eps[0].ip6.address,
1354 dst="6001::1") /
Neale Ranns4a6d0232018-04-24 07:45:33 -07001355 UDP(sport=1234, dport=1234) /
1356 Raw('\xa5' * 100))
1357
1358 self.send_and_expect_natted6(self.pg0,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001359 pkt_inter_epg_220_to_global * NUM_PKTS,
Neale Ranns4a6d0232018-04-24 07:45:33 -07001360 self.pg7,
Neale Rannsc0a93142018-09-05 15:42:26 -07001361 eps[0].fip6.address)
Neale Ranns4a6d0232018-04-24 07:45:33 -07001362
1363 #
1364 # From a global address to an EP: OUT2IN
1365 #
Ole Troan8006c6a2018-12-17 12:02:26 +01001366 pkt_inter_epg_220_from_global = (Ether(src=str(self.router_mac),
Neale Ranns25b04942018-04-04 09:34:50 -07001367 dst=self.pg0.remote_mac) /
Neale Rannsc0a93142018-09-05 15:42:26 -07001368 IP(dst=eps[0].fip4.address,
Neale Ranns25b04942018-04-04 09:34:50 -07001369 src="1.1.1.1") /
1370 UDP(sport=1234, dport=1234) /
1371 Raw('\xa5' * 100))
1372
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001373 self.send_and_assert_no_replies(
1374 self.pg7, pkt_inter_epg_220_from_global * NUM_PKTS)
Neale Ranns25b04942018-04-04 09:34:50 -07001375
Neale Ranns13a08cc2018-11-07 09:25:54 -08001376 c5 = VppGbpContract(
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001377 self, epgs[3].sclass, epgs[0].sclass, acl_index2,
Neale Ranns13a08cc2018-11-07 09:25:54 -08001378 [VppGbpContractRule(
1379 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
1380 []),
Filip Vargaf4749ca2019-04-25 14:55:32 +02001381 VppGbpContractRule(
1382 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
1383 [])],
Neale Ranns1c17e2e2018-12-20 12:03:59 -08001384 [ETH_P_IP, ETH_P_IPV6])
Neale Ranns25b04942018-04-04 09:34:50 -07001385 c5.add_vpp_config()
1386
1387 self.send_and_expect_unnatted(self.pg7,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001388 pkt_inter_epg_220_from_global * NUM_PKTS,
Neale Ranns4a6d0232018-04-24 07:45:33 -07001389 eps[0].itf,
Neale Rannsc0a93142018-09-05 15:42:26 -07001390 eps[0].ip4.address)
Neale Ranns25b04942018-04-04 09:34:50 -07001391
Ole Troan8006c6a2018-12-17 12:02:26 +01001392 pkt_inter_epg_220_from_global = (Ether(src=str(self.router_mac),
Neale Ranns4a6d0232018-04-24 07:45:33 -07001393 dst=self.pg0.remote_mac) /
Neale Rannsc0a93142018-09-05 15:42:26 -07001394 IPv6(dst=eps[0].fip6.address,
Neale Ranns4a6d0232018-04-24 07:45:33 -07001395 src="6001::1") /
1396 UDP(sport=1234, dport=1234) /
1397 Raw('\xa5' * 100))
1398
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001399 self.send_and_expect_unnatted6(
1400 self.pg7,
1401 pkt_inter_epg_220_from_global * NUM_PKTS,
1402 eps[0].itf,
1403 eps[0].ip6.address)
Neale Ranns4a6d0232018-04-24 07:45:33 -07001404
1405 #
1406 # From a local VM to another local VM using resp. public addresses:
1407 # IN2OUT2IN
1408 #
Neale Ranns25b04942018-04-04 09:34:50 -07001409 pkt_intra_epg_220_global = (Ether(src=self.pg0.remote_mac,
Ole Troan8006c6a2018-12-17 12:02:26 +01001410 dst=str(self.router_mac)) /
Neale Rannsc0a93142018-09-05 15:42:26 -07001411 IP(src=eps[0].ip4.address,
1412 dst=eps[1].fip4.address) /
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001413 UDP(sport=1234, dport=1234) /
1414 Raw('\xa5' * 100))
1415
Neale Ranns4a6d0232018-04-24 07:45:33 -07001416 self.send_and_expect_double_natted(eps[0].itf,
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001417 pkt_intra_epg_220_global * NUM_PKTS,
Neale Ranns4a6d0232018-04-24 07:45:33 -07001418 eps[1].itf,
Neale Rannsc0a93142018-09-05 15:42:26 -07001419 eps[0].fip4.address,
1420 eps[1].ip4.address)
Neale Ranns4a6d0232018-04-24 07:45:33 -07001421
Neale Rannsc0a93142018-09-05 15:42:26 -07001422 pkt_intra_epg_220_global = (Ether(src=self.pg0.remote_mac,
Ole Troan8006c6a2018-12-17 12:02:26 +01001423 dst=str(self.router_mac)) /
Neale Rannsc0a93142018-09-05 15:42:26 -07001424 IPv6(src=eps[0].ip6.address,
1425 dst=eps[1].fip6.address) /
Neale Ranns4a6d0232018-04-24 07:45:33 -07001426 UDP(sport=1234, dport=1234) /
1427 Raw('\xa5' * 100))
1428
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001429 self.send_and_expect_double_natted6(
1430 eps[0].itf,
1431 pkt_intra_epg_220_global * NUM_PKTS,
1432 eps[1].itf,
1433 eps[0].fip6.address,
1434 eps[1].ip6.address)
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001435
1436 #
Neale Ranns25b04942018-04-04 09:34:50 -07001437 # cleanup
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001438 #
Neale Ranns25b04942018-04-04 09:34:50 -07001439 for ep in eps:
1440 # del static mappings for each EP from the 10/8 to 11/8 network
Filip Vargadd1e3e72019-04-15 18:52:43 +02001441 flags = self.config_flags.NAT_IS_ADDR_ONLY
Filip Vargaf4749ca2019-04-25 14:55:32 +02001442 self.vapi.nat44_add_del_static_mapping(
1443 is_add=0,
1444 local_ip_address=ep.ip4.bytes,
1445 external_ip_address=ep.fip4.bytes,
1446 external_sw_if_index=0xFFFFFFFF,
1447 vrf_id=0,
1448 flags=flags)
1449 self.vapi.nat66_add_del_static_mapping(
1450 local_ip_address=ep.ip6.bytes,
1451 external_ip_address=ep.fip6.bytes,
1452 vrf_id=0, is_add=0)
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001453
Neale Ranns25b04942018-04-04 09:34:50 -07001454 for epg in epgs:
1455 # IP config on the BVI interfaces
Neale Ranns25b04942018-04-04 09:34:50 -07001456 if epg != epgs[0] and epg != epgs[3]:
Filip Vargadd1e3e72019-04-15 18:52:43 +02001457 flags = self.config_flags.NAT_IS_INSIDE
Filip Vargaf4749ca2019-04-25 14:55:32 +02001458 self.vapi.nat44_interface_add_del_feature(
1459 sw_if_index=epg.bvi.sw_if_index,
1460 flags=flags,
1461 is_add=0)
1462 self.vapi.nat66_add_del_interface(
1463 is_add=0, flags=flags,
1464 sw_if_index=epg.bvi.sw_if_index)
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001465
Neale Ranns25b04942018-04-04 09:34:50 -07001466 for recirc in recircs:
Neale Ranns4a6d0232018-04-24 07:45:33 -07001467 self.vapi.nat44_interface_add_del_feature(
Filip Vargaf4749ca2019-04-25 14:55:32 +02001468 sw_if_index=recirc.recirc.sw_if_index,
Neale Ranns4a6d0232018-04-24 07:45:33 -07001469 is_add=0)
1470 self.vapi.nat66_add_del_interface(
Filip Vargaf4749ca2019-04-25 14:55:32 +02001471 is_add=0,
1472 sw_if_index=recirc.recirc.sw_if_index)
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001473
Neale Ranns774356a2018-11-29 12:02:16 +00001474 def wait_for_ep_timeout(self, sw_if_index=None, ip=None, mac=None,
1475 n_tries=100, s_time=1):
1476 while (n_tries):
1477 if not find_gbp_endpoint(self, sw_if_index, ip, mac):
1478 return True
1479 n_tries = n_tries - 1
1480 self.sleep(s_time)
1481 self.assertFalse(find_gbp_endpoint(self, sw_if_index, ip, mac))
1482 return False
1483
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001484 def test_gbp_learn_l2(self):
1485 """ GBP L2 Endpoint Learning """
1486
Neale Ranns796c84b2019-03-28 07:56:23 -07001487 self.vapi.cli("clear errors")
1488
Neale Rannsb6a47952018-11-21 05:44:35 -08001489 ep_flags = VppEnum.vl_api_gbp_endpoint_flags_t
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001490 learnt = [{'mac': '00:00:11:11:11:01',
1491 'ip': '10.0.0.1',
1492 'ip6': '2001:10::2'},
1493 {'mac': '00:00:11:11:11:02',
1494 'ip': '10.0.0.2',
1495 'ip6': '2001:10::3'}]
1496
1497 #
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001498 # IP tables
1499 #
1500 gt4 = VppIpTable(self, 1)
1501 gt4.add_vpp_config()
1502 gt6 = VppIpTable(self, 1, is_ip6=True)
1503 gt6.add_vpp_config()
1504
1505 rd1 = VppGbpRouteDomain(self, 1, gt4, gt6)
1506 rd1.add_vpp_config()
1507
1508 #
1509 # Pg2 hosts the vxlan tunnel, hosts on pg2 to act as TEPs
1510 # Pg3 hosts the IP4 UU-flood VXLAN tunnel
1511 # Pg4 hosts the IP6 UU-flood VXLAN tunnel
1512 #
1513 self.pg2.config_ip4()
1514 self.pg2.resolve_arp()
1515 self.pg2.generate_remote_hosts(4)
1516 self.pg2.configure_ipv4_neighbors()
1517 self.pg3.config_ip4()
1518 self.pg3.resolve_arp()
1519 self.pg4.config_ip4()
1520 self.pg4.resolve_arp()
1521
1522 #
Neale Ranns879d11c2019-01-21 23:34:18 -08001523 # Add a mcast destination VXLAN-GBP tunnel for B&M traffic
1524 #
1525 tun_bm = VppVxlanGbpTunnel(self, self.pg4.local_ip4,
1526 "239.1.1.1", 88,
1527 mcast_itf=self.pg4)
1528 tun_bm.add_vpp_config()
1529
1530 #
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001531 # a GBP bridge domain with a BVI and a UU-flood interface
1532 #
1533 bd1 = VppBridgeDomain(self, 1)
1534 bd1.add_vpp_config()
Neale Ranns879d11c2019-01-21 23:34:18 -08001535 gbd1 = VppGbpBridgeDomain(self, bd1, self.loop0, self.pg3, tun_bm)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001536 gbd1.add_vpp_config()
1537
1538 self.logger.info(self.vapi.cli("sh bridge 1 detail"))
1539 self.logger.info(self.vapi.cli("sh gbp bridge"))
1540
1541 # ... and has a /32 applied
1542 ip_addr = VppIpInterfaceAddress(self, gbd1.bvi, "10.0.0.128", 32)
1543 ip_addr.add_vpp_config()
1544
1545 #
1546 # The Endpoint-group in which we are learning endpoints
1547 #
Neale Ranns879d11c2019-01-21 23:34:18 -08001548 epg_220 = VppGbpEndpointGroup(self, 220, 112, rd1, gbd1,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001549 None, self.loop0,
1550 "10.0.0.128",
Neale Ranns32f6d8e2019-03-05 04:22:08 -08001551 "2001:10::128",
1552 VppGbpEndpointRetention(2))
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001553 epg_220.add_vpp_config()
Neale Ranns879d11c2019-01-21 23:34:18 -08001554 epg_330 = VppGbpEndpointGroup(self, 330, 113, rd1, gbd1,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001555 None, self.loop1,
1556 "10.0.1.128",
Neale Ranns32f6d8e2019-03-05 04:22:08 -08001557 "2001:11::128",
1558 VppGbpEndpointRetention(2))
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001559 epg_330.add_vpp_config()
1560
1561 #
1562 # The VXLAN GBP tunnel is a bridge-port and has L2 endpoint
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001563 # learning enabled
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001564 #
1565 vx_tun_l2_1 = VppGbpVxlanTunnel(
1566 self, 99, bd1.bd_id,
Neale Ranns8da9fc62019-03-04 14:08:11 -08001567 VppEnum.vl_api_gbp_vxlan_tunnel_mode_t.GBP_VXLAN_TUNNEL_MODE_L2,
1568 self.pg2.local_ip4)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001569 vx_tun_l2_1.add_vpp_config()
1570
1571 #
1572 # A static endpoint that the learnt endpoints are trying to
1573 # talk to
1574 #
1575 ep = VppGbpEndpoint(self, self.pg0,
1576 epg_220, None,
1577 "10.0.0.127", "11.0.0.127",
1578 "2001:10::1", "3001::1")
1579 ep.add_vpp_config()
1580
1581 self.assertTrue(find_route(self, ep.ip4.address, 32, table_id=1))
1582
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001583 # a packet with an sclass from an unknown EPG
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001584 p = (Ether(src=self.pg2.remote_mac,
1585 dst=self.pg2.local_mac) /
1586 IP(src=self.pg2.remote_hosts[0].ip4,
1587 dst=self.pg2.local_ip4) /
1588 UDP(sport=1234, dport=48879) /
1589 VXLAN(vni=99, gpid=88, flags=0x88) /
1590 Ether(src=learnt[0]["mac"], dst=ep.mac) /
1591 IP(src=learnt[0]["ip"], dst=ep.ip4.address) /
1592 UDP(sport=1234, dport=1234) /
1593 Raw('\xa5' * 100))
1594
1595 self.send_and_assert_no_replies(self.pg2, p)
1596
Neale Ranns796c84b2019-03-28 07:56:23 -07001597 self.logger.info(self.vapi.cli("sh error"))
1598 # self.assert_packet_counter_equal(
1599 # '/err/gbp-policy-port/drop-no-contract', 1)
1600
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001601 #
1602 # we should not have learnt a new tunnel endpoint, since
1603 # the EPG was not learnt.
1604 #
1605 self.assertEqual(INDEX_INVALID,
1606 find_vxlan_gbp_tunnel(self,
1607 self.pg2.local_ip4,
1608 self.pg2.remote_hosts[0].ip4,
1609 99))
1610
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001611 # epg is not learnt, because the EPG is unknown
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001612 self.assertEqual(len(self.vapi.gbp_endpoint_dump()), 1)
1613
Neale Ranns8da9fc62019-03-04 14:08:11 -08001614 #
1615 # Learn new EPs from IP packets
1616 #
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001617 for ii, l in enumerate(learnt):
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001618 # a packet with an sclass from a known EPG
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001619 # arriving on an unknown TEP
1620 p = (Ether(src=self.pg2.remote_mac,
1621 dst=self.pg2.local_mac) /
1622 IP(src=self.pg2.remote_hosts[1].ip4,
1623 dst=self.pg2.local_ip4) /
1624 UDP(sport=1234, dport=48879) /
Neale Ranns879d11c2019-01-21 23:34:18 -08001625 VXLAN(vni=99, gpid=112, flags=0x88) /
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001626 Ether(src=l['mac'], dst=ep.mac) /
1627 IP(src=l['ip'], dst=ep.ip4.address) /
1628 UDP(sport=1234, dport=1234) /
1629 Raw('\xa5' * 100))
1630
1631 rx = self.send_and_expect(self.pg2, [p], self.pg0)
1632
1633 # the new TEP
1634 tep1_sw_if_index = find_vxlan_gbp_tunnel(
1635 self,
1636 self.pg2.local_ip4,
1637 self.pg2.remote_hosts[1].ip4,
1638 99)
1639 self.assertNotEqual(INDEX_INVALID, tep1_sw_if_index)
1640
1641 #
1642 # the EP is learnt via the learnt TEP
1643 # both from its MAC and its IP
1644 #
1645 self.assertTrue(find_gbp_endpoint(self,
1646 vx_tun_l2_1.sw_if_index,
1647 mac=l['mac']))
1648 self.assertTrue(find_gbp_endpoint(self,
1649 vx_tun_l2_1.sw_if_index,
1650 ip=l['ip']))
1651
Neale Ranns796c84b2019-03-28 07:56:23 -07001652 # self.assert_packet_counter_equal(
1653 # '/err/gbp-policy-port/allow-intra-sclass', 2)
1654
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001655 self.logger.info(self.vapi.cli("show gbp endpoint"))
1656 self.logger.info(self.vapi.cli("show gbp vxlan"))
Neale Ranns8da9fc62019-03-04 14:08:11 -08001657 self.logger.info(self.vapi.cli("show ip mfib"))
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001658
1659 #
1660 # If we sleep for the threshold time, the learnt endpoints should
1661 # age out
1662 #
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001663 for l in learnt:
Neale Ranns774356a2018-11-29 12:02:16 +00001664 self.wait_for_ep_timeout(vx_tun_l2_1.sw_if_index,
1665 mac=l['mac'])
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001666
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001667 #
Neale Ranns8da9fc62019-03-04 14:08:11 -08001668 # Learn new EPs from GARP packets received on the BD's mcast tunnel
1669 #
1670 for ii, l in enumerate(learnt):
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001671 # a packet with an sclass from a known EPG
Neale Ranns8da9fc62019-03-04 14:08:11 -08001672 # arriving on an unknown TEP
1673 p = (Ether(src=self.pg2.remote_mac,
1674 dst=self.pg2.local_mac) /
1675 IP(src=self.pg2.remote_hosts[1].ip4,
1676 dst="239.1.1.1") /
1677 UDP(sport=1234, dport=48879) /
1678 VXLAN(vni=88, gpid=112, flags=0x88) /
1679 Ether(src=l['mac'], dst="ff:ff:ff:ff:ff:ff") /
1680 ARP(op="who-has",
1681 psrc=l['ip'], pdst=l['ip'],
1682 hwsrc=l['mac'], hwdst="ff:ff:ff:ff:ff:ff"))
1683
1684 rx = self.send_and_expect(self.pg4, [p], self.pg0)
1685
1686 # the new TEP
1687 tep1_sw_if_index = find_vxlan_gbp_tunnel(
1688 self,
1689 self.pg2.local_ip4,
1690 self.pg2.remote_hosts[1].ip4,
1691 99)
1692 self.assertNotEqual(INDEX_INVALID, tep1_sw_if_index)
1693
1694 #
1695 # the EP is learnt via the learnt TEP
1696 # both from its MAC and its IP
1697 #
1698 self.assertTrue(find_gbp_endpoint(self,
1699 vx_tun_l2_1.sw_if_index,
1700 mac=l['mac']))
1701 self.assertTrue(find_gbp_endpoint(self,
1702 vx_tun_l2_1.sw_if_index,
1703 ip=l['ip']))
1704
1705 #
1706 # wait for the learnt endpoints to age out
1707 #
1708 for l in learnt:
1709 self.wait_for_ep_timeout(vx_tun_l2_1.sw_if_index,
1710 mac=l['mac'])
1711
1712 #
1713 # Learn new EPs from L2 packets
1714 #
1715 for ii, l in enumerate(learnt):
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001716 # a packet with an sclass from a known EPG
Neale Ranns8da9fc62019-03-04 14:08:11 -08001717 # arriving on an unknown TEP
1718 p = (Ether(src=self.pg2.remote_mac,
1719 dst=self.pg2.local_mac) /
1720 IP(src=self.pg2.remote_hosts[1].ip4,
1721 dst=self.pg2.local_ip4) /
1722 UDP(sport=1234, dport=48879) /
1723 VXLAN(vni=99, gpid=112, flags=0x88) /
1724 Ether(src=l['mac'], dst=ep.mac) /
1725 Raw('\xa5' * 100))
1726
1727 rx = self.send_and_expect(self.pg2, [p], self.pg0)
1728
1729 # the new TEP
1730 tep1_sw_if_index = find_vxlan_gbp_tunnel(
1731 self,
1732 self.pg2.local_ip4,
1733 self.pg2.remote_hosts[1].ip4,
1734 99)
1735 self.assertNotEqual(INDEX_INVALID, tep1_sw_if_index)
1736
1737 #
1738 # the EP is learnt via the learnt TEP
1739 # both from its MAC and its IP
1740 #
1741 self.assertTrue(find_gbp_endpoint(self,
1742 vx_tun_l2_1.sw_if_index,
1743 mac=l['mac']))
1744
1745 self.logger.info(self.vapi.cli("show gbp endpoint"))
1746 self.logger.info(self.vapi.cli("show gbp vxlan"))
1747 self.logger.info(self.vapi.cli("show vxlan-gbp tunnel"))
1748
1749 #
1750 # wait for the learnt endpoints to age out
1751 #
1752 for l in learnt:
1753 self.wait_for_ep_timeout(vx_tun_l2_1.sw_if_index,
1754 mac=l['mac'])
1755
1756 #
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001757 # repeat. the do not learn bit is set so the EPs are not learnt
1758 #
1759 for l in learnt:
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001760 # a packet with an sclass from a known EPG
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001761 p = (Ether(src=self.pg2.remote_mac,
1762 dst=self.pg2.local_mac) /
1763 IP(src=self.pg2.remote_hosts[1].ip4,
1764 dst=self.pg2.local_ip4) /
1765 UDP(sport=1234, dport=48879) /
Neale Ranns879d11c2019-01-21 23:34:18 -08001766 VXLAN(vni=99, gpid=112, flags=0x88, gpflags="D") /
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001767 Ether(src=l['mac'], dst=ep.mac) /
1768 IP(src=l['ip'], dst=ep.ip4.address) /
1769 UDP(sport=1234, dport=1234) /
1770 Raw('\xa5' * 100))
1771
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001772 rx = self.send_and_expect(self.pg2, p * NUM_PKTS, self.pg0)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001773
1774 for l in learnt:
1775 self.assertFalse(find_gbp_endpoint(self,
1776 vx_tun_l2_1.sw_if_index,
1777 mac=l['mac']))
1778
1779 #
1780 # repeat
1781 #
1782 for l in learnt:
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001783 # a packet with an sclass from a known EPG
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001784 p = (Ether(src=self.pg2.remote_mac,
1785 dst=self.pg2.local_mac) /
1786 IP(src=self.pg2.remote_hosts[1].ip4,
1787 dst=self.pg2.local_ip4) /
1788 UDP(sport=1234, dport=48879) /
Neale Ranns879d11c2019-01-21 23:34:18 -08001789 VXLAN(vni=99, gpid=112, flags=0x88) /
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001790 Ether(src=l['mac'], dst=ep.mac) /
1791 IP(src=l['ip'], dst=ep.ip4.address) /
1792 UDP(sport=1234, dport=1234) /
1793 Raw('\xa5' * 100))
1794
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001795 rx = self.send_and_expect(self.pg2, p * NUM_PKTS, self.pg0)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001796
1797 self.assertTrue(find_gbp_endpoint(self,
1798 vx_tun_l2_1.sw_if_index,
1799 mac=l['mac']))
1800
1801 #
1802 # Static EP replies to dynamics
1803 #
1804 self.logger.info(self.vapi.cli("sh l2fib bd_id 1"))
1805 for l in learnt:
1806 p = (Ether(src=ep.mac, dst=l['mac']) /
1807 IP(dst=l['ip'], src=ep.ip4.address) /
1808 UDP(sport=1234, dport=1234) /
1809 Raw('\xa5' * 100))
1810
1811 rxs = self.send_and_expect(self.pg0, p * 17, self.pg2)
1812
1813 for rx in rxs:
1814 self.assertEqual(rx[IP].src, self.pg2.local_ip4)
1815 self.assertEqual(rx[IP].dst, self.pg2.remote_hosts[1].ip4)
1816 self.assertEqual(rx[UDP].dport, 48879)
1817 # the UDP source port is a random value for hashing
Neale Ranns879d11c2019-01-21 23:34:18 -08001818 self.assertEqual(rx[VXLAN].gpid, 112)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001819 self.assertEqual(rx[VXLAN].vni, 99)
1820 self.assertTrue(rx[VXLAN].flags.G)
1821 self.assertTrue(rx[VXLAN].flags.Instance)
1822 self.assertTrue(rx[VXLAN].gpflags.A)
1823 self.assertFalse(rx[VXLAN].gpflags.D)
1824
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001825 for l in learnt:
Neale Ranns774356a2018-11-29 12:02:16 +00001826 self.wait_for_ep_timeout(vx_tun_l2_1.sw_if_index,
1827 mac=l['mac'])
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001828
1829 #
1830 # repeat in the other EPG
1831 # there's no contract between 220 and 330, but the A-bit is set
1832 # so the packet is cleared for delivery
1833 #
1834 for l in learnt:
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001835 # a packet with an sclass from a known EPG
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001836 p = (Ether(src=self.pg2.remote_mac,
1837 dst=self.pg2.local_mac) /
1838 IP(src=self.pg2.remote_hosts[1].ip4,
1839 dst=self.pg2.local_ip4) /
1840 UDP(sport=1234, dport=48879) /
Neale Ranns879d11c2019-01-21 23:34:18 -08001841 VXLAN(vni=99, gpid=113, flags=0x88, gpflags='A') /
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001842 Ether(src=l['mac'], dst=ep.mac) /
1843 IP(src=l['ip'], dst=ep.ip4.address) /
1844 UDP(sport=1234, dport=1234) /
1845 Raw('\xa5' * 100))
1846
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001847 rx = self.send_and_expect(self.pg2, p * NUM_PKTS, self.pg0)
Mohsin Kazmie60dfd72019-04-16 15:15:07 +02001848
1849 self.assertTrue(find_gbp_endpoint(self,
1850 vx_tun_l2_1.sw_if_index,
1851 mac=l['mac']))
1852
1853 #
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001854 # static EP cannot reach the learnt EPs since there is no contract
Neale Ranns13a08cc2018-11-07 09:25:54 -08001855 # only test 1 EP as the others could timeout
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001856 #
Neale Ranns13a08cc2018-11-07 09:25:54 -08001857 p = (Ether(src=ep.mac, dst=l['mac']) /
1858 IP(dst=learnt[0]['ip'], src=ep.ip4.address) /
1859 UDP(sport=1234, dport=1234) /
1860 Raw('\xa5' * 100))
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001861
Neale Ranns13a08cc2018-11-07 09:25:54 -08001862 self.send_and_assert_no_replies(self.pg0, [p])
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001863
1864 #
1865 # refresh the entries after the check for no replies above
1866 #
1867 for l in learnt:
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001868 # a packet with an sclass from a known EPG
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001869 p = (Ether(src=self.pg2.remote_mac,
1870 dst=self.pg2.local_mac) /
1871 IP(src=self.pg2.remote_hosts[1].ip4,
1872 dst=self.pg2.local_ip4) /
1873 UDP(sport=1234, dport=48879) /
Neale Ranns879d11c2019-01-21 23:34:18 -08001874 VXLAN(vni=99, gpid=113, flags=0x88, gpflags='A') /
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001875 Ether(src=l['mac'], dst=ep.mac) /
1876 IP(src=l['ip'], dst=ep.ip4.address) /
1877 UDP(sport=1234, dport=1234) /
1878 Raw('\xa5' * 100))
1879
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001880 rx = self.send_and_expect(self.pg2, p * NUM_PKTS, self.pg0)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001881
1882 self.assertTrue(find_gbp_endpoint(self,
1883 vx_tun_l2_1.sw_if_index,
1884 mac=l['mac']))
1885
1886 #
1887 # Add the contract so they can talk
1888 #
1889 acl = VppGbpAcl(self)
1890 rule = acl.create_rule(permit_deny=1, proto=17)
1891 rule2 = acl.create_rule(is_ipv6=1, permit_deny=1, proto=17)
1892 acl_index = acl.add_vpp_config([rule, rule2])
Neale Ranns13a08cc2018-11-07 09:25:54 -08001893 c1 = VppGbpContract(
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001894 self, epg_220.sclass, epg_330.sclass, acl_index,
Neale Ranns13a08cc2018-11-07 09:25:54 -08001895 [VppGbpContractRule(
1896 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
1897 []),
Filip Vargaf4749ca2019-04-25 14:55:32 +02001898 VppGbpContractRule(
1899 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
1900 [])],
Neale Ranns1c17e2e2018-12-20 12:03:59 -08001901 [ETH_P_IP, ETH_P_IPV6])
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001902 c1.add_vpp_config()
1903
1904 for l in learnt:
1905 p = (Ether(src=ep.mac, dst=l['mac']) /
1906 IP(dst=l['ip'], src=ep.ip4.address) /
1907 UDP(sport=1234, dport=1234) /
1908 Raw('\xa5' * 100))
1909
1910 self.send_and_expect(self.pg0, [p], self.pg2)
1911
1912 #
1913 # send UU packets from the local EP
1914 #
1915 self.logger.info(self.vapi.cli("sh bridge 1 detail"))
1916 self.logger.info(self.vapi.cli("sh gbp bridge"))
1917 p_uu = (Ether(src=ep.mac, dst="00:11:11:11:11:11") /
1918 IP(dst="10.0.0.133", src=ep.ip4.address) /
1919 UDP(sport=1234, dport=1234) /
1920 Raw('\xa5' * 100))
Neale Ranns879d11c2019-01-21 23:34:18 -08001921 rxs = self.send_and_expect(ep.itf, [p_uu], gbd1.uu_fwd)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001922
1923 self.logger.info(self.vapi.cli("sh bridge 1 detail"))
1924
1925 p_bm = (Ether(src=ep.mac, dst="ff:ff:ff:ff:ff:ff") /
1926 IP(dst="10.0.0.133", src=ep.ip4.address) /
1927 UDP(sport=1234, dport=1234) /
1928 Raw('\xa5' * 100))
1929 rxs = self.send_and_expect_only(ep.itf, [p_bm], tun_bm.mcast_itf)
1930
Neale Ranns879d11c2019-01-21 23:34:18 -08001931 for rx in rxs:
1932 self.assertEqual(rx[IP].src, self.pg4.local_ip4)
1933 self.assertEqual(rx[IP].dst, "239.1.1.1")
1934 self.assertEqual(rx[UDP].dport, 48879)
1935 # the UDP source port is a random value for hashing
1936 self.assertEqual(rx[VXLAN].gpid, 112)
1937 self.assertEqual(rx[VXLAN].vni, 88)
1938 self.assertTrue(rx[VXLAN].flags.G)
1939 self.assertTrue(rx[VXLAN].flags.Instance)
1940 self.assertFalse(rx[VXLAN].gpflags.A)
1941 self.assertFalse(rx[VXLAN].gpflags.D)
1942
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001943 #
1944 # Check v6 Endpoints
1945 #
1946 for l in learnt:
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001947 # a packet with an sclass from a known EPG
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001948 p = (Ether(src=self.pg2.remote_mac,
1949 dst=self.pg2.local_mac) /
1950 IP(src=self.pg2.remote_hosts[1].ip4,
1951 dst=self.pg2.local_ip4) /
1952 UDP(sport=1234, dport=48879) /
Neale Ranns879d11c2019-01-21 23:34:18 -08001953 VXLAN(vni=99, gpid=113, flags=0x88, gpflags='A') /
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001954 Ether(src=l['mac'], dst=ep.mac) /
1955 IPv6(src=l['ip6'], dst=ep.ip6.address) /
1956 UDP(sport=1234, dport=1234) /
1957 Raw('\xa5' * 100))
1958
Paul Vinciguerra4271c972019-05-14 13:25:49 -04001959 rx = self.send_and_expect(self.pg2, p * NUM_PKTS, self.pg0)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001960
1961 self.assertTrue(find_gbp_endpoint(self,
1962 vx_tun_l2_1.sw_if_index,
1963 mac=l['mac']))
1964
1965 #
1966 # L3 Endpoint Learning
1967 # - configured on the bridge's BVI
1968 #
1969
1970 #
1971 # clean up
1972 #
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001973 for l in learnt:
Neale Ranns774356a2018-11-29 12:02:16 +00001974 self.wait_for_ep_timeout(vx_tun_l2_1.sw_if_index,
1975 mac=l['mac'])
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001976 self.pg2.unconfig_ip4()
1977 self.pg3.unconfig_ip4()
1978 self.pg4.unconfig_ip4()
1979
1980 self.logger.info(self.vapi.cli("sh int"))
1981 self.logger.info(self.vapi.cli("sh gbp vxlan"))
1982
Mohsin Kazmife52dea2019-04-18 15:54:58 +02001983 def test_gbp_contract(self):
1984 """ GBP CONTRACTS """
1985
1986 #
1987 # Bridge Domains
1988 #
1989 bd1 = VppBridgeDomain(self, 1, arp_term=0)
1990 bd2 = VppBridgeDomain(self, 2, arp_term=0)
1991
1992 bd1.add_vpp_config()
1993 bd2.add_vpp_config()
1994
1995 gbd1 = VppGbpBridgeDomain(self, bd1, self.loop0)
1996 gbd2 = VppGbpBridgeDomain(self, bd2, self.loop1)
1997
1998 gbd1.add_vpp_config()
1999 gbd2.add_vpp_config()
2000
2001 #
2002 # Route Domains
2003 #
2004 gt4 = VppIpTable(self, 0)
2005 gt4.add_vpp_config()
2006 gt6 = VppIpTable(self, 0, is_ip6=True)
2007 gt6.add_vpp_config()
2008
2009 rd0 = VppGbpRouteDomain(self, 0, gt4, gt6, None, None)
2010
2011 rd0.add_vpp_config()
2012
2013 #
2014 # 3 EPGs, 2 of which share a BD.
2015 #
2016 epgs = [VppGbpEndpointGroup(self, 220, 1220, rd0, gbd1,
2017 None, self.loop0,
2018 "10.0.0.128", "2001:10::128"),
2019 VppGbpEndpointGroup(self, 221, 1221, rd0, gbd1,
2020 None, self.loop0,
2021 "10.0.1.128", "2001:10:1::128"),
2022 VppGbpEndpointGroup(self, 222, 1222, rd0, gbd2,
2023 None, self.loop1,
2024 "10.0.2.128", "2001:10:2::128")]
2025 #
2026 # 4 end-points, 2 in the same subnet, 3 in the same BD
2027 #
2028 eps = [VppGbpEndpoint(self, self.pg0,
2029 epgs[0], None,
2030 "10.0.0.1", "11.0.0.1",
2031 "2001:10::1", "3001::1"),
2032 VppGbpEndpoint(self, self.pg1,
2033 epgs[0], None,
2034 "10.0.0.2", "11.0.0.2",
2035 "2001:10::2", "3001::2"),
2036 VppGbpEndpoint(self, self.pg2,
2037 epgs[1], None,
2038 "10.0.1.1", "11.0.0.3",
2039 "2001:10:1::1", "3001::3"),
2040 VppGbpEndpoint(self, self.pg3,
2041 epgs[2], None,
2042 "10.0.2.1", "11.0.0.4",
2043 "2001:10:2::1", "3001::4")]
2044
2045 #
2046 # Config related to each of the EPGs
2047 #
2048 for epg in epgs:
2049 # IP config on the BVI interfaces
2050 if epg != epgs[1]:
2051 VppIpInterfaceBind(self, epg.bvi, epg.rd.t4).add_vpp_config()
2052 VppIpInterfaceBind(self, epg.bvi, epg.rd.t6).add_vpp_config()
2053 self.vapi.sw_interface_set_mac_address(
2054 epg.bvi.sw_if_index,
2055 self.router_mac.packed)
2056
2057 if_ip4 = VppIpInterfaceAddress(self, epg.bvi, epg.bvi_ip4, 32)
2058 if_ip6 = VppIpInterfaceAddress(self, epg.bvi, epg.bvi_ip6, 128)
2059 if_ip4.add_vpp_config()
2060 if_ip6.add_vpp_config()
2061
2062 # add the BD ARP termination entry for BVI IP
2063 epg.bd_arp_ip4 = VppBridgeDomainArpEntry(self, epg.bd.bd,
2064 str(self.router_mac),
2065 epg.bvi_ip4)
2066 epg.bd_arp_ip4.add_vpp_config()
2067
2068 # EPG in VPP
2069 epg.add_vpp_config()
2070
2071 #
2072 # config ep
2073 #
2074 for ep in eps:
2075 ep.add_vpp_config()
2076
2077 self.logger.info(self.vapi.cli("show gbp endpoint"))
2078 self.logger.info(self.vapi.cli("show interface"))
2079 self.logger.info(self.vapi.cli("show br"))
2080
2081 #
2082 # Intra epg allowed without contract
2083 #
2084 pkt_intra_epg_220_to_220 = (Ether(src=self.pg0.remote_mac,
2085 dst=self.pg1.remote_mac) /
2086 IP(src=eps[0].ip4.address,
2087 dst=eps[1].ip4.address) /
2088 UDP(sport=1234, dport=1234) /
2089 Raw('\xa5' * 100))
2090
2091 self.send_and_expect_bridged(self.pg0,
2092 pkt_intra_epg_220_to_220 * 65,
2093 self.pg1)
2094
2095 #
2096 # Inter epg denied without contract
2097 #
2098 pkt_inter_epg_220_to_221 = (Ether(src=self.pg0.remote_mac,
2099 dst=self.pg2.remote_mac) /
2100 IP(src=eps[0].ip4.address,
2101 dst=eps[2].ip4.address) /
2102 UDP(sport=1234, dport=1234) /
2103 Raw('\xa5' * 100))
2104
2105 self.send_and_assert_no_replies(self.pg0, pkt_inter_epg_220_to_221)
2106
2107 #
2108 # A uni-directional contract from EPG 220 -> 221
2109 #
2110 acl = VppGbpAcl(self)
2111 rule = acl.create_rule(permit_deny=1, proto=17)
2112 rule2 = acl.create_rule(is_ipv6=1, permit_deny=1, proto=17)
2113 acl_index = acl.add_vpp_config([rule, rule2])
2114 c1 = VppGbpContract(
2115 self, epgs[0].sclass, epgs[1].sclass, acl_index,
2116 [VppGbpContractRule(
2117 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
2118 []),
2119 VppGbpContractRule(
2120 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
2121 [])],
2122 [ETH_P_IP, ETH_P_IPV6])
2123 c1.add_vpp_config()
2124
2125 self.send_and_expect_bridged(eps[0].itf,
2126 pkt_inter_epg_220_to_221 * 65,
2127 eps[2].itf)
2128
2129 pkt_inter_epg_220_to_222 = (Ether(src=self.pg0.remote_mac,
2130 dst=str(self.router_mac)) /
2131 IP(src=eps[0].ip4.address,
2132 dst=eps[3].ip4.address) /
2133 UDP(sport=1234, dport=1234) /
2134 Raw('\xa5' * 100))
2135 self.send_and_assert_no_replies(eps[0].itf,
2136 pkt_inter_epg_220_to_222 * 65)
2137
2138 #
2139 # contract for the return direction
2140 #
2141 c2 = VppGbpContract(
2142 self, epgs[1].sclass, epgs[0].sclass, acl_index,
2143 [VppGbpContractRule(
2144 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
2145 []),
2146 VppGbpContractRule(
2147 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
2148 [])],
2149 [ETH_P_IP, ETH_P_IPV6])
2150 c2.add_vpp_config()
2151
2152 self.send_and_expect_bridged(eps[0].itf,
2153 pkt_inter_epg_220_to_221 * 65,
2154 eps[2].itf)
2155 pkt_inter_epg_221_to_220 = (Ether(src=self.pg2.remote_mac,
2156 dst=self.pg0.remote_mac) /
2157 IP(src=eps[2].ip4.address,
2158 dst=eps[0].ip4.address) /
2159 UDP(sport=1234, dport=1234) /
2160 Raw('\xa5' * 100))
2161 self.send_and_expect_bridged(eps[2].itf,
2162 pkt_inter_epg_221_to_220 * 65,
2163 eps[0].itf)
2164
2165 #
2166 # contract between 220 and 222 uni-direction
2167 #
2168 c3 = VppGbpContract(
2169 self, epgs[0].sclass, epgs[2].sclass, acl_index,
2170 [VppGbpContractRule(
2171 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
2172 []),
2173 VppGbpContractRule(
2174 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
2175 [])],
2176 [ETH_P_IP, ETH_P_IPV6])
2177 c3.add_vpp_config()
2178
2179 self.send_and_expect(eps[0].itf,
2180 pkt_inter_epg_220_to_222 * 65,
2181 eps[3].itf)
2182
2183 c3.remove_vpp_config()
2184 c1.remove_vpp_config()
2185 c2.remove_vpp_config()
2186 acl.remove_vpp_config()
2187
Mohsin Kazmi7363d472019-04-04 13:22:15 +02002188 def test_gbp_bd_flags(self):
2189 """ GBP BD FLAGS """
2190
2191 #
2192 # IP tables
2193 #
2194 gt4 = VppIpTable(self, 1)
2195 gt4.add_vpp_config()
2196 gt6 = VppIpTable(self, 1, is_ip6=True)
2197 gt6.add_vpp_config()
2198
2199 rd1 = VppGbpRouteDomain(self, 1, gt4, gt6)
2200 rd1.add_vpp_config()
2201
2202 #
2203 # Pg3 hosts the IP4 UU-flood VXLAN tunnel
2204 # Pg4 hosts the IP6 UU-flood VXLAN tunnel
2205 #
2206 self.pg3.config_ip4()
2207 self.pg3.resolve_arp()
2208 self.pg4.config_ip4()
2209 self.pg4.resolve_arp()
2210
2211 #
2212 # Add a mcast destination VXLAN-GBP tunnel for B&M traffic
2213 #
2214 tun_bm = VppVxlanGbpTunnel(self, self.pg4.local_ip4,
2215 "239.1.1.1", 88,
2216 mcast_itf=self.pg4)
2217 tun_bm.add_vpp_config()
2218
2219 #
2220 # a GBP bridge domain with a BVI and a UU-flood interface
2221 #
2222 bd1 = VppBridgeDomain(self, 1)
2223 bd1.add_vpp_config()
2224
2225 gbd1 = VppGbpBridgeDomain(self, bd1, self.loop0, self.pg3, tun_bm,
2226 uu_drop=True, bm_drop=True)
2227 gbd1.add_vpp_config()
2228
2229 self.logger.info(self.vapi.cli("sh bridge 1 detail"))
2230 self.logger.info(self.vapi.cli("sh gbp bridge"))
2231
2232 # ... and has a /32 applied
2233 ip_addr = VppIpInterfaceAddress(self, gbd1.bvi, "10.0.0.128", 32)
2234 ip_addr.add_vpp_config()
2235
2236 #
2237 # The Endpoint-group
2238 #
2239 epg_220 = VppGbpEndpointGroup(self, 220, 112, rd1, gbd1,
2240 None, self.loop0,
2241 "10.0.0.128",
2242 "2001:10::128",
2243 VppGbpEndpointRetention(2))
2244 epg_220.add_vpp_config()
2245
2246 ep = VppGbpEndpoint(self, self.pg0,
2247 epg_220, None,
2248 "10.0.0.127", "11.0.0.127",
2249 "2001:10::1", "3001::1")
2250 ep.add_vpp_config()
2251 #
2252 # send UU/BM packet from the local EP with UU drop and BM drop enabled
2253 # in bd
2254 #
2255 self.logger.info(self.vapi.cli("sh bridge 1 detail"))
2256 self.logger.info(self.vapi.cli("sh gbp bridge"))
2257 p_uu = (Ether(src=ep.mac, dst="00:11:11:11:11:11") /
2258 IP(dst="10.0.0.133", src=ep.ip4.address) /
2259 UDP(sport=1234, dport=1234) /
2260 Raw('\xa5' * 100))
2261 self.send_and_assert_no_replies(ep.itf, [p_uu])
2262
2263 p_bm = (Ether(src=ep.mac, dst="ff:ff:ff:ff:ff:ff") /
2264 IP(dst="10.0.0.133", src=ep.ip4.address) /
2265 UDP(sport=1234, dport=1234) /
2266 Raw('\xa5' * 100))
2267 self.send_and_assert_no_replies(ep.itf, [p_bm])
2268
2269 self.pg3.unconfig_ip4()
2270 self.pg4.unconfig_ip4()
2271
2272 self.logger.info(self.vapi.cli("sh int"))
2273
Neale Rannsc29c0af2018-11-07 04:21:12 -08002274 def test_gbp_learn_vlan_l2(self):
2275 """ GBP L2 Endpoint w/ VLANs"""
2276
Neale Rannsb6a47952018-11-21 05:44:35 -08002277 ep_flags = VppEnum.vl_api_gbp_endpoint_flags_t
Neale Rannsc29c0af2018-11-07 04:21:12 -08002278 learnt = [{'mac': '00:00:11:11:11:01',
2279 'ip': '10.0.0.1',
2280 'ip6': '2001:10::2'},
2281 {'mac': '00:00:11:11:11:02',
2282 'ip': '10.0.0.2',
2283 'ip6': '2001:10::3'}]
2284
2285 #
Neale Rannsc29c0af2018-11-07 04:21:12 -08002286 # IP tables
2287 #
2288 gt4 = VppIpTable(self, 1)
2289 gt4.add_vpp_config()
2290 gt6 = VppIpTable(self, 1, is_ip6=True)
2291 gt6.add_vpp_config()
2292
2293 rd1 = VppGbpRouteDomain(self, 1, gt4, gt6)
2294 rd1.add_vpp_config()
2295
2296 #
2297 # Pg2 hosts the vxlan tunnel, hosts on pg2 to act as TEPs
2298 #
2299 self.pg2.config_ip4()
2300 self.pg2.resolve_arp()
2301 self.pg2.generate_remote_hosts(4)
2302 self.pg2.configure_ipv4_neighbors()
2303 self.pg3.config_ip4()
2304 self.pg3.resolve_arp()
2305
2306 #
2307 # The EP will be on a vlan sub-interface
2308 #
2309 vlan_11 = VppDot1QSubint(self, self.pg0, 11)
2310 vlan_11.admin_up()
Ole Troana5b2eec2019-03-11 19:23:25 +01002311 self.vapi.l2_interface_vlan_tag_rewrite(
2312 sw_if_index=vlan_11.sw_if_index, vtr_op=L2_VTR_OP.L2_POP_1,
2313 push_dot1q=11)
Neale Rannsc29c0af2018-11-07 04:21:12 -08002314
2315 bd_uu_fwd = VppVxlanGbpTunnel(self, self.pg3.local_ip4,
2316 self.pg3.remote_ip4, 116)
2317 bd_uu_fwd.add_vpp_config()
2318
2319 #
2320 # a GBP bridge domain with a BVI and a UU-flood interface
2321 # The BD is marked as do not learn, so no endpoints are ever
2322 # learnt in this BD.
2323 #
2324 bd1 = VppBridgeDomain(self, 1)
2325 bd1.add_vpp_config()
2326 gbd1 = VppGbpBridgeDomain(self, bd1, self.loop0, bd_uu_fwd,
2327 learn=False)
2328 gbd1.add_vpp_config()
2329
2330 self.logger.info(self.vapi.cli("sh bridge 1 detail"))
2331 self.logger.info(self.vapi.cli("sh gbp bridge"))
2332
2333 # ... and has a /32 applied
2334 ip_addr = VppIpInterfaceAddress(self, gbd1.bvi, "10.0.0.128", 32)
2335 ip_addr.add_vpp_config()
2336
2337 #
2338 # The Endpoint-group in which we are learning endpoints
2339 #
Neale Ranns879d11c2019-01-21 23:34:18 -08002340 epg_220 = VppGbpEndpointGroup(self, 220, 441, rd1, gbd1,
Neale Rannsc29c0af2018-11-07 04:21:12 -08002341 None, self.loop0,
2342 "10.0.0.128",
Neale Ranns32f6d8e2019-03-05 04:22:08 -08002343 "2001:10::128",
2344 VppGbpEndpointRetention(2))
Neale Rannsc29c0af2018-11-07 04:21:12 -08002345 epg_220.add_vpp_config()
2346
2347 #
2348 # The VXLAN GBP tunnel is a bridge-port and has L2 endpoint
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002349 # learning enabled
Neale Rannsc29c0af2018-11-07 04:21:12 -08002350 #
2351 vx_tun_l2_1 = VppGbpVxlanTunnel(
2352 self, 99, bd1.bd_id,
Neale Ranns8da9fc62019-03-04 14:08:11 -08002353 VppEnum.vl_api_gbp_vxlan_tunnel_mode_t.GBP_VXLAN_TUNNEL_MODE_L2,
2354 self.pg2.local_ip4)
Neale Rannsc29c0af2018-11-07 04:21:12 -08002355 vx_tun_l2_1.add_vpp_config()
2356
2357 #
2358 # A static endpoint that the learnt endpoints are trying to
2359 # talk to
2360 #
2361 ep = VppGbpEndpoint(self, vlan_11,
2362 epg_220, None,
2363 "10.0.0.127", "11.0.0.127",
2364 "2001:10::1", "3001::1")
2365 ep.add_vpp_config()
2366
2367 self.assertTrue(find_route(self, ep.ip4.address, 32, table_id=1))
2368
2369 #
2370 # Send to the static EP
2371 #
2372 for ii, l in enumerate(learnt):
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002373 # a packet with an sclass from a known EPG
Neale Rannsc29c0af2018-11-07 04:21:12 -08002374 # arriving on an unknown TEP
2375 p = (Ether(src=self.pg2.remote_mac,
2376 dst=self.pg2.local_mac) /
2377 IP(src=self.pg2.remote_hosts[1].ip4,
2378 dst=self.pg2.local_ip4) /
2379 UDP(sport=1234, dport=48879) /
Neale Ranns879d11c2019-01-21 23:34:18 -08002380 VXLAN(vni=99, gpid=441, flags=0x88) /
Neale Rannsc29c0af2018-11-07 04:21:12 -08002381 Ether(src=l['mac'], dst=ep.mac) /
2382 IP(src=l['ip'], dst=ep.ip4.address) /
2383 UDP(sport=1234, dport=1234) /
2384 Raw('\xa5' * 100))
2385
2386 rxs = self.send_and_expect(self.pg2, [p], self.pg0)
2387
2388 #
2389 # packet to EP has the EP's vlan tag
2390 #
2391 for rx in rxs:
2392 self.assertEqual(rx[Dot1Q].vlan, 11)
2393
2394 #
2395 # the EP is not learnt since the BD setting prevents it
2396 # also no TEP too
2397 #
2398 self.assertFalse(find_gbp_endpoint(self,
2399 vx_tun_l2_1.sw_if_index,
2400 mac=l['mac']))
2401 self.assertEqual(INDEX_INVALID,
2402 find_vxlan_gbp_tunnel(
2403 self,
2404 self.pg2.local_ip4,
2405 self.pg2.remote_hosts[1].ip4,
2406 99))
2407
2408 self.assertEqual(len(self.vapi.gbp_endpoint_dump()), 1)
2409
2410 #
2411 # static to remotes
2412 # we didn't learn the remotes so they are sent to the UU-fwd
2413 #
2414 for l in learnt:
2415 p = (Ether(src=ep.mac, dst=l['mac']) /
2416 Dot1Q(vlan=11) /
2417 IP(dst=l['ip'], src=ep.ip4.address) /
2418 UDP(sport=1234, dport=1234) /
2419 Raw('\xa5' * 100))
2420
2421 rxs = self.send_and_expect(self.pg0, p * 17, self.pg3)
2422
2423 for rx in rxs:
2424 self.assertEqual(rx[IP].src, self.pg3.local_ip4)
2425 self.assertEqual(rx[IP].dst, self.pg3.remote_ip4)
2426 self.assertEqual(rx[UDP].dport, 48879)
2427 # the UDP source port is a random value for hashing
Neale Ranns879d11c2019-01-21 23:34:18 -08002428 self.assertEqual(rx[VXLAN].gpid, 441)
Neale Rannsc29c0af2018-11-07 04:21:12 -08002429 self.assertEqual(rx[VXLAN].vni, 116)
2430 self.assertTrue(rx[VXLAN].flags.G)
2431 self.assertTrue(rx[VXLAN].flags.Instance)
2432 self.assertFalse(rx[VXLAN].gpflags.A)
2433 self.assertFalse(rx[VXLAN].gpflags.D)
2434
2435 self.pg2.unconfig_ip4()
2436 self.pg3.unconfig_ip4()
2437
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002438 def test_gbp_learn_l3(self):
2439 """ GBP L3 Endpoint Learning """
2440
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -04002441 self.vapi.cli("set logging class gbp level debug")
Neale Ranns13a08cc2018-11-07 09:25:54 -08002442
Neale Rannsb6a47952018-11-21 05:44:35 -08002443 ep_flags = VppEnum.vl_api_gbp_endpoint_flags_t
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002444 routed_dst_mac = "00:0c:0c:0c:0c:0c"
2445 routed_src_mac = "00:22:bd:f8:19:ff"
2446
2447 learnt = [{'mac': '00:00:11:11:11:02',
2448 'ip': '10.0.1.2',
2449 'ip6': '2001:10::2'},
2450 {'mac': '00:00:11:11:11:03',
2451 'ip': '10.0.1.3',
2452 'ip6': '2001:10::3'}]
2453
2454 #
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002455 # IP tables
2456 #
2457 t4 = VppIpTable(self, 1)
2458 t4.add_vpp_config()
2459 t6 = VppIpTable(self, 1, True)
2460 t6.add_vpp_config()
2461
2462 tun_ip4_uu = VppVxlanGbpTunnel(self, self.pg4.local_ip4,
2463 self.pg4.remote_ip4, 114)
2464 tun_ip6_uu = VppVxlanGbpTunnel(self, self.pg4.local_ip4,
2465 self.pg4.remote_ip4, 116)
2466 tun_ip4_uu.add_vpp_config()
2467 tun_ip6_uu.add_vpp_config()
2468
2469 rd1 = VppGbpRouteDomain(self, 2, t4, t6, tun_ip4_uu, tun_ip6_uu)
2470 rd1.add_vpp_config()
2471
Ole Troan8006c6a2018-12-17 12:02:26 +01002472 self.loop0.set_mac(self.router_mac)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002473
2474 #
2475 # Bind the BVI to the RD
2476 #
2477 VppIpInterfaceBind(self, self.loop0, t4).add_vpp_config()
2478 VppIpInterfaceBind(self, self.loop0, t6).add_vpp_config()
2479
2480 #
2481 # Pg2 hosts the vxlan tunnel
2482 # hosts on pg2 to act as TEPs
2483 # pg3 is BD uu-fwd
2484 # pg4 is RD uu-fwd
2485 #
2486 self.pg2.config_ip4()
2487 self.pg2.resolve_arp()
2488 self.pg2.generate_remote_hosts(4)
2489 self.pg2.configure_ipv4_neighbors()
2490 self.pg3.config_ip4()
2491 self.pg3.resolve_arp()
2492 self.pg4.config_ip4()
2493 self.pg4.resolve_arp()
2494
2495 #
2496 # a GBP bridge domain with a BVI and a UU-flood interface
2497 #
2498 bd1 = VppBridgeDomain(self, 1)
2499 bd1.add_vpp_config()
2500 gbd1 = VppGbpBridgeDomain(self, bd1, self.loop0, self.pg3)
2501 gbd1.add_vpp_config()
2502
2503 self.logger.info(self.vapi.cli("sh bridge 1 detail"))
2504 self.logger.info(self.vapi.cli("sh gbp bridge"))
2505 self.logger.info(self.vapi.cli("sh gbp route"))
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002506
2507 # ... and has a /32 and /128 applied
2508 ip4_addr = VppIpInterfaceAddress(self, gbd1.bvi, "10.0.0.128", 32)
2509 ip4_addr.add_vpp_config()
2510 ip6_addr = VppIpInterfaceAddress(self, gbd1.bvi, "2001:10::128", 128)
2511 ip6_addr.add_vpp_config()
2512
2513 #
2514 # The Endpoint-group in which we are learning endpoints
2515 #
Neale Ranns879d11c2019-01-21 23:34:18 -08002516 epg_220 = VppGbpEndpointGroup(self, 220, 441, rd1, gbd1,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002517 None, self.loop0,
2518 "10.0.0.128",
Neale Ranns32f6d8e2019-03-05 04:22:08 -08002519 "2001:10::128",
2520 VppGbpEndpointRetention(2))
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002521 epg_220.add_vpp_config()
2522
2523 #
2524 # The VXLAN GBP tunnel is a bridge-port and has L2 endpoint
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002525 # learning enabled
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002526 #
2527 vx_tun_l3 = VppGbpVxlanTunnel(
2528 self, 101, rd1.rd_id,
Neale Ranns8da9fc62019-03-04 14:08:11 -08002529 VppEnum.vl_api_gbp_vxlan_tunnel_mode_t.GBP_VXLAN_TUNNEL_MODE_L3,
2530 self.pg2.local_ip4)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002531 vx_tun_l3.add_vpp_config()
2532
2533 #
2534 # A static endpoint that the learnt endpoints are trying to
2535 # talk to
2536 #
2537 ep = VppGbpEndpoint(self, self.pg0,
2538 epg_220, None,
2539 "10.0.0.127", "11.0.0.127",
2540 "2001:10::1", "3001::1")
2541 ep.add_vpp_config()
2542
2543 #
2544 # learn some remote IPv4 EPs
2545 #
2546 for ii, l in enumerate(learnt):
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002547 # a packet with an sclass from a known EPG
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002548 # arriving on an unknown TEP
2549 p = (Ether(src=self.pg2.remote_mac,
2550 dst=self.pg2.local_mac) /
2551 IP(src=self.pg2.remote_hosts[1].ip4,
2552 dst=self.pg2.local_ip4) /
2553 UDP(sport=1234, dport=48879) /
Neale Ranns879d11c2019-01-21 23:34:18 -08002554 VXLAN(vni=101, gpid=441, flags=0x88) /
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002555 Ether(src=l['mac'], dst="00:00:00:11:11:11") /
2556 IP(src=l['ip'], dst=ep.ip4.address) /
2557 UDP(sport=1234, dport=1234) /
2558 Raw('\xa5' * 100))
2559
2560 rx = self.send_and_expect(self.pg2, [p], self.pg0)
2561
2562 # the new TEP
2563 tep1_sw_if_index = find_vxlan_gbp_tunnel(
2564 self,
2565 self.pg2.local_ip4,
2566 self.pg2.remote_hosts[1].ip4,
2567 vx_tun_l3.vni)
2568 self.assertNotEqual(INDEX_INVALID, tep1_sw_if_index)
2569
2570 # endpoint learnt via the parent GBP-vxlan interface
2571 self.assertTrue(find_gbp_endpoint(self,
2572 vx_tun_l3._sw_if_index,
2573 ip=l['ip']))
2574
2575 #
2576 # Static IPv4 EP replies to learnt
2577 #
2578 for l in learnt:
2579 p = (Ether(src=ep.mac, dst=self.loop0.local_mac) /
2580 IP(dst=l['ip'], src=ep.ip4.address) /
2581 UDP(sport=1234, dport=1234) /
2582 Raw('\xa5' * 100))
2583
Filip Vargaf4749ca2019-04-25 14:55:32 +02002584 rxs = self.send_and_expect(self.pg0, p * 1, self.pg2)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002585
2586 for rx in rxs:
2587 self.assertEqual(rx[IP].src, self.pg2.local_ip4)
2588 self.assertEqual(rx[IP].dst, self.pg2.remote_hosts[1].ip4)
2589 self.assertEqual(rx[UDP].dport, 48879)
2590 # the UDP source port is a random value for hashing
Neale Ranns879d11c2019-01-21 23:34:18 -08002591 self.assertEqual(rx[VXLAN].gpid, 441)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002592 self.assertEqual(rx[VXLAN].vni, 101)
2593 self.assertTrue(rx[VXLAN].flags.G)
2594 self.assertTrue(rx[VXLAN].flags.Instance)
2595 self.assertTrue(rx[VXLAN].gpflags.A)
2596 self.assertFalse(rx[VXLAN].gpflags.D)
2597
2598 inner = rx[VXLAN].payload
2599
2600 self.assertEqual(inner[Ether].src, routed_src_mac)
2601 self.assertEqual(inner[Ether].dst, routed_dst_mac)
2602 self.assertEqual(inner[IP].src, ep.ip4.address)
2603 self.assertEqual(inner[IP].dst, l['ip'])
2604
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002605 for l in learnt:
2606 self.assertFalse(find_gbp_endpoint(self,
2607 tep1_sw_if_index,
2608 ip=l['ip']))
2609
2610 #
2611 # learn some remote IPv6 EPs
2612 #
2613 for ii, l in enumerate(learnt):
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002614 # a packet with an sclass from a known EPG
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002615 # arriving on an unknown TEP
2616 p = (Ether(src=self.pg2.remote_mac,
2617 dst=self.pg2.local_mac) /
2618 IP(src=self.pg2.remote_hosts[1].ip4,
2619 dst=self.pg2.local_ip4) /
2620 UDP(sport=1234, dport=48879) /
Neale Ranns879d11c2019-01-21 23:34:18 -08002621 VXLAN(vni=101, gpid=441, flags=0x88) /
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002622 Ether(src=l['mac'], dst="00:00:00:11:11:11") /
2623 IPv6(src=l['ip6'], dst=ep.ip6.address) /
2624 UDP(sport=1234, dport=1234) /
2625 Raw('\xa5' * 100))
2626
2627 rx = self.send_and_expect(self.pg2, [p], self.pg0)
2628
2629 # the new TEP
2630 tep1_sw_if_index = find_vxlan_gbp_tunnel(
2631 self,
2632 self.pg2.local_ip4,
2633 self.pg2.remote_hosts[1].ip4,
2634 vx_tun_l3.vni)
2635 self.assertNotEqual(INDEX_INVALID, tep1_sw_if_index)
2636
2637 self.logger.info(self.vapi.cli("show gbp bridge"))
2638 self.logger.info(self.vapi.cli("show vxlan-gbp tunnel"))
2639 self.logger.info(self.vapi.cli("show gbp vxlan"))
2640 self.logger.info(self.vapi.cli("show int addr"))
2641
2642 # endpoint learnt via the TEP
2643 self.assertTrue(find_gbp_endpoint(self, ip=l['ip6']))
2644
2645 self.logger.info(self.vapi.cli("show gbp endpoint"))
2646 self.logger.info(self.vapi.cli("show ip fib index 1 %s" % l['ip']))
2647
2648 #
2649 # Static EP replies to learnt
2650 #
2651 for l in learnt:
2652 p = (Ether(src=ep.mac, dst=self.loop0.local_mac) /
2653 IPv6(dst=l['ip6'], src=ep.ip6.address) /
2654 UDP(sport=1234, dport=1234) /
2655 Raw('\xa5' * 100))
2656
Paul Vinciguerra4271c972019-05-14 13:25:49 -04002657 rxs = self.send_and_expect(self.pg0, p * NUM_PKTS, self.pg2)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002658
2659 for rx in rxs:
2660 self.assertEqual(rx[IP].src, self.pg2.local_ip4)
2661 self.assertEqual(rx[IP].dst, self.pg2.remote_hosts[1].ip4)
2662 self.assertEqual(rx[UDP].dport, 48879)
2663 # the UDP source port is a random value for hashing
Neale Ranns879d11c2019-01-21 23:34:18 -08002664 self.assertEqual(rx[VXLAN].gpid, 441)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002665 self.assertEqual(rx[VXLAN].vni, 101)
2666 self.assertTrue(rx[VXLAN].flags.G)
2667 self.assertTrue(rx[VXLAN].flags.Instance)
2668 self.assertTrue(rx[VXLAN].gpflags.A)
2669 self.assertFalse(rx[VXLAN].gpflags.D)
2670
2671 inner = rx[VXLAN].payload
2672
2673 self.assertEqual(inner[Ether].src, routed_src_mac)
2674 self.assertEqual(inner[Ether].dst, routed_dst_mac)
2675 self.assertEqual(inner[IPv6].src, ep.ip6.address)
2676 self.assertEqual(inner[IPv6].dst, l['ip6'])
2677
2678 self.logger.info(self.vapi.cli("sh gbp endpoint"))
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002679 for l in learnt:
Neale Ranns774356a2018-11-29 12:02:16 +00002680 self.wait_for_ep_timeout(ip=l['ip'])
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002681
2682 #
2683 # Static sends to unknown EP with no route
2684 #
2685 p = (Ether(src=ep.mac, dst=self.loop0.local_mac) /
2686 IP(dst="10.0.0.99", src=ep.ip4.address) /
2687 UDP(sport=1234, dport=1234) /
2688 Raw('\xa5' * 100))
2689
2690 self.send_and_assert_no_replies(self.pg0, [p])
2691
2692 #
2693 # Add a route to static EP's v4 and v6 subnet
Neale Rannsb6a47952018-11-21 05:44:35 -08002694 # packets should be sent on the v4/v6 uu=fwd interface resp.
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002695 #
2696 se_10_24 = VppGbpSubnet(
2697 self, rd1, "10.0.0.0", 24,
2698 VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_TRANSPORT)
2699 se_10_24.add_vpp_config()
2700
2701 p = (Ether(src=ep.mac, dst=self.loop0.local_mac) /
2702 IP(dst="10.0.0.99", src=ep.ip4.address) /
2703 UDP(sport=1234, dport=1234) /
2704 Raw('\xa5' * 100))
2705
2706 rxs = self.send_and_expect(self.pg0, [p], self.pg4)
2707 for rx in rxs:
2708 self.assertEqual(rx[IP].src, self.pg4.local_ip4)
2709 self.assertEqual(rx[IP].dst, self.pg4.remote_ip4)
2710 self.assertEqual(rx[UDP].dport, 48879)
2711 # the UDP source port is a random value for hashing
Neale Ranns879d11c2019-01-21 23:34:18 -08002712 self.assertEqual(rx[VXLAN].gpid, 441)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002713 self.assertEqual(rx[VXLAN].vni, 114)
2714 self.assertTrue(rx[VXLAN].flags.G)
2715 self.assertTrue(rx[VXLAN].flags.Instance)
2716 # policy is not applied to packets sent to the uu-fwd interfaces
2717 self.assertFalse(rx[VXLAN].gpflags.A)
2718 self.assertFalse(rx[VXLAN].gpflags.D)
2719
2720 #
2721 # learn some remote IPv4 EPs
2722 #
2723 for ii, l in enumerate(learnt):
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002724 # a packet with an sclass from a known EPG
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002725 # arriving on an unknown TEP
2726 p = (Ether(src=self.pg2.remote_mac,
2727 dst=self.pg2.local_mac) /
Neale Ranns879d11c2019-01-21 23:34:18 -08002728 IP(src=self.pg2.remote_hosts[2].ip4,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002729 dst=self.pg2.local_ip4) /
2730 UDP(sport=1234, dport=48879) /
Neale Ranns879d11c2019-01-21 23:34:18 -08002731 VXLAN(vni=101, gpid=441, flags=0x88) /
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002732 Ether(src=l['mac'], dst="00:00:00:11:11:11") /
2733 IP(src=l['ip'], dst=ep.ip4.address) /
2734 UDP(sport=1234, dport=1234) /
2735 Raw('\xa5' * 100))
2736
2737 rx = self.send_and_expect(self.pg2, [p], self.pg0)
2738
2739 # the new TEP
2740 tep1_sw_if_index = find_vxlan_gbp_tunnel(
2741 self,
2742 self.pg2.local_ip4,
Neale Ranns879d11c2019-01-21 23:34:18 -08002743 self.pg2.remote_hosts[2].ip4,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002744 vx_tun_l3.vni)
2745 self.assertNotEqual(INDEX_INVALID, tep1_sw_if_index)
2746
2747 # endpoint learnt via the parent GBP-vxlan interface
2748 self.assertTrue(find_gbp_endpoint(self,
2749 vx_tun_l3._sw_if_index,
2750 ip=l['ip']))
2751
2752 #
2753 # Add a remote endpoint from the API
2754 #
2755 rep_88 = VppGbpEndpoint(self, vx_tun_l3,
2756 epg_220, None,
2757 "10.0.0.88", "11.0.0.88",
2758 "2001:10::88", "3001::88",
Neale Rannsb6a47952018-11-21 05:44:35 -08002759 ep_flags.GBP_API_ENDPOINT_FLAG_REMOTE,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002760 self.pg2.local_ip4,
2761 self.pg2.remote_hosts[1].ip4,
2762 mac=None)
2763 rep_88.add_vpp_config()
2764
2765 #
2766 # Add a remote endpoint from the API that matches an existing one
2767 #
2768 rep_2 = VppGbpEndpoint(self, vx_tun_l3,
2769 epg_220, None,
2770 learnt[0]['ip'], "11.0.0.101",
2771 learnt[0]['ip6'], "3001::101",
Neale Rannsb6a47952018-11-21 05:44:35 -08002772 ep_flags.GBP_API_ENDPOINT_FLAG_REMOTE,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002773 self.pg2.local_ip4,
2774 self.pg2.remote_hosts[1].ip4,
2775 mac=None)
2776 rep_2.add_vpp_config()
2777
2778 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002779 # Add a route to the learned EP's v4 subnet
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002780 # packets should be send on the v4/v6 uu=fwd interface resp.
2781 #
2782 se_10_1_24 = VppGbpSubnet(
2783 self, rd1, "10.0.1.0", 24,
2784 VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_TRANSPORT)
2785 se_10_1_24.add_vpp_config()
2786
2787 self.logger.info(self.vapi.cli("show gbp endpoint"))
2788
2789 ips = ["10.0.0.88", learnt[0]['ip']]
2790 for ip in ips:
2791 p = (Ether(src=ep.mac, dst=self.loop0.local_mac) /
2792 IP(dst=ip, src=ep.ip4.address) /
2793 UDP(sport=1234, dport=1234) /
2794 Raw('\xa5' * 100))
2795
Paul Vinciguerra4271c972019-05-14 13:25:49 -04002796 rxs = self.send_and_expect(self.pg0, p * NUM_PKTS, self.pg2)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002797
2798 for rx in rxs:
2799 self.assertEqual(rx[IP].src, self.pg2.local_ip4)
2800 self.assertEqual(rx[IP].dst, self.pg2.remote_hosts[1].ip4)
2801 self.assertEqual(rx[UDP].dport, 48879)
2802 # the UDP source port is a random value for hashing
Neale Ranns879d11c2019-01-21 23:34:18 -08002803 self.assertEqual(rx[VXLAN].gpid, 441)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002804 self.assertEqual(rx[VXLAN].vni, 101)
2805 self.assertTrue(rx[VXLAN].flags.G)
2806 self.assertTrue(rx[VXLAN].flags.Instance)
2807 self.assertTrue(rx[VXLAN].gpflags.A)
2808 self.assertFalse(rx[VXLAN].gpflags.D)
2809
2810 inner = rx[VXLAN].payload
2811
2812 self.assertEqual(inner[Ether].src, routed_src_mac)
2813 self.assertEqual(inner[Ether].dst, routed_dst_mac)
2814 self.assertEqual(inner[IP].src, ep.ip4.address)
2815 self.assertEqual(inner[IP].dst, ip)
2816
2817 #
Neale Ranns13a08cc2018-11-07 09:25:54 -08002818 # remove the API remote EPs, only API sourced is gone, the DP
2819 # learnt one remains
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002820 #
2821 rep_88.remove_vpp_config()
2822 rep_2.remove_vpp_config()
2823
Neale Ranns00a469d2018-12-20 06:12:19 -08002824 self.assertTrue(find_gbp_endpoint(self, ip=rep_2.ip4.address))
2825
2826 p = (Ether(src=ep.mac, dst=self.loop0.local_mac) /
2827 IP(src=ep.ip4.address, dst=rep_2.ip4.address) /
2828 UDP(sport=1234, dport=1234) /
2829 Raw('\xa5' * 100))
2830 rxs = self.send_and_expect(self.pg0, [p], self.pg2)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002831
Neale Ranns13a08cc2018-11-07 09:25:54 -08002832 self.assertFalse(find_gbp_endpoint(self, ip=rep_88.ip4.address))
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002833
Neale Ranns13a08cc2018-11-07 09:25:54 -08002834 p = (Ether(src=ep.mac, dst=self.loop0.local_mac) /
2835 IP(src=ep.ip4.address, dst=rep_88.ip4.address) /
2836 UDP(sport=1234, dport=1234) /
2837 Raw('\xa5' * 100))
2838 rxs = self.send_and_expect(self.pg0, [p], self.pg4)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002839
Neale Ranns13a08cc2018-11-07 09:25:54 -08002840 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07002841 # to appease the testcase we cannot have the registered EP still
Neale Ranns13a08cc2018-11-07 09:25:54 -08002842 # present (because it's DP learnt) when the TC ends so wait until
2843 # it is removed
2844 #
Neale Ranns00a469d2018-12-20 06:12:19 -08002845 self.wait_for_ep_timeout(ip=rep_88.ip4.address)
2846 self.wait_for_ep_timeout(ip=rep_2.ip4.address)
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002847
2848 #
2849 # shutdown with learnt endpoint present
2850 #
Neale Ranns13a08cc2018-11-07 09:25:54 -08002851 p = (Ether(src=self.pg2.remote_mac,
2852 dst=self.pg2.local_mac) /
2853 IP(src=self.pg2.remote_hosts[1].ip4,
2854 dst=self.pg2.local_ip4) /
2855 UDP(sport=1234, dport=48879) /
Neale Ranns879d11c2019-01-21 23:34:18 -08002856 VXLAN(vni=101, gpid=441, flags=0x88) /
Neale Ranns13a08cc2018-11-07 09:25:54 -08002857 Ether(src=l['mac'], dst="00:00:00:11:11:11") /
2858 IP(src=learnt[1]['ip'], dst=ep.ip4.address) /
2859 UDP(sport=1234, dport=1234) /
2860 Raw('\xa5' * 100))
2861
2862 rx = self.send_and_expect(self.pg2, [p], self.pg0)
2863
2864 # endpoint learnt via the parent GBP-vxlan interface
2865 self.assertTrue(find_gbp_endpoint(self,
2866 vx_tun_l3._sw_if_index,
2867 ip=l['ip']))
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002868
2869 #
2870 # TODO
2871 # remote endpoint becomes local
2872 #
2873 self.pg2.unconfig_ip4()
2874 self.pg3.unconfig_ip4()
2875 self.pg4.unconfig_ip4()
2876
Neale Ranns13a08cc2018-11-07 09:25:54 -08002877 def test_gbp_redirect(self):
2878 """ GBP Endpoint Redirect """
2879
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -04002880 self.vapi.cli("set logging class gbp level debug")
Neale Ranns13a08cc2018-11-07 09:25:54 -08002881
Neale Rannsb6a47952018-11-21 05:44:35 -08002882 ep_flags = VppEnum.vl_api_gbp_endpoint_flags_t
Neale Ranns13a08cc2018-11-07 09:25:54 -08002883 routed_dst_mac = "00:0c:0c:0c:0c:0c"
2884 routed_src_mac = "00:22:bd:f8:19:ff"
2885
2886 learnt = [{'mac': '00:00:11:11:11:02',
2887 'ip': '10.0.1.2',
2888 'ip6': '2001:10::2'},
2889 {'mac': '00:00:11:11:11:03',
2890 'ip': '10.0.1.3',
2891 'ip6': '2001:10::3'}]
2892
2893 #
Neale Ranns13a08cc2018-11-07 09:25:54 -08002894 # IP tables
2895 #
2896 t4 = VppIpTable(self, 1)
2897 t4.add_vpp_config()
2898 t6 = VppIpTable(self, 1, True)
2899 t6.add_vpp_config()
2900
2901 rd1 = VppGbpRouteDomain(self, 2, t4, t6)
2902 rd1.add_vpp_config()
2903
Ole Troan8006c6a2018-12-17 12:02:26 +01002904 self.loop0.set_mac(self.router_mac)
Neale Ranns13a08cc2018-11-07 09:25:54 -08002905
2906 #
2907 # Bind the BVI to the RD
2908 #
2909 VppIpInterfaceBind(self, self.loop0, t4).add_vpp_config()
2910 VppIpInterfaceBind(self, self.loop0, t6).add_vpp_config()
2911
2912 #
2913 # Pg7 hosts a BD's UU-fwd
2914 #
2915 self.pg7.config_ip4()
2916 self.pg7.resolve_arp()
2917
2918 #
2919 # a GBP bridge domains for the EPs
2920 #
2921 bd1 = VppBridgeDomain(self, 1)
2922 bd1.add_vpp_config()
2923 gbd1 = VppGbpBridgeDomain(self, bd1, self.loop0)
2924 gbd1.add_vpp_config()
2925
2926 bd2 = VppBridgeDomain(self, 2)
2927 bd2.add_vpp_config()
2928 gbd2 = VppGbpBridgeDomain(self, bd2, self.loop1)
2929 gbd2.add_vpp_config()
2930
2931 # ... and has a /32 and /128 applied
2932 ip4_addr = VppIpInterfaceAddress(self, gbd1.bvi, "10.0.0.128", 32)
2933 ip4_addr.add_vpp_config()
2934 ip6_addr = VppIpInterfaceAddress(self, gbd1.bvi, "2001:10::128", 128)
2935 ip6_addr.add_vpp_config()
2936 ip4_addr = VppIpInterfaceAddress(self, gbd2.bvi, "10.0.1.128", 32)
2937 ip4_addr.add_vpp_config()
2938 ip6_addr = VppIpInterfaceAddress(self, gbd2.bvi, "2001:11::128", 128)
2939 ip6_addr.add_vpp_config()
2940
2941 #
2942 # The Endpoint-groups in which we are learning endpoints
2943 #
Neale Ranns879d11c2019-01-21 23:34:18 -08002944 epg_220 = VppGbpEndpointGroup(self, 220, 440, rd1, gbd1,
Neale Ranns13a08cc2018-11-07 09:25:54 -08002945 None, gbd1.bvi,
2946 "10.0.0.128",
Neale Ranns32f6d8e2019-03-05 04:22:08 -08002947 "2001:10::128",
2948 VppGbpEndpointRetention(2))
Neale Ranns13a08cc2018-11-07 09:25:54 -08002949 epg_220.add_vpp_config()
Neale Ranns879d11c2019-01-21 23:34:18 -08002950 epg_221 = VppGbpEndpointGroup(self, 221, 441, rd1, gbd2,
Neale Ranns13a08cc2018-11-07 09:25:54 -08002951 None, gbd2.bvi,
2952 "10.0.1.128",
Neale Ranns32f6d8e2019-03-05 04:22:08 -08002953 "2001:11::128",
2954 VppGbpEndpointRetention(2))
Neale Ranns13a08cc2018-11-07 09:25:54 -08002955 epg_221.add_vpp_config()
Neale Ranns879d11c2019-01-21 23:34:18 -08002956 epg_222 = VppGbpEndpointGroup(self, 222, 442, rd1, gbd1,
Neale Ranns13a08cc2018-11-07 09:25:54 -08002957 None, gbd1.bvi,
2958 "10.0.2.128",
Neale Ranns32f6d8e2019-03-05 04:22:08 -08002959 "2001:12::128",
2960 VppGbpEndpointRetention(2))
Neale Ranns13a08cc2018-11-07 09:25:54 -08002961 epg_222.add_vpp_config()
2962
2963 #
2964 # a GBP bridge domains for the SEPs
2965 #
2966 bd_uu1 = VppVxlanGbpTunnel(self, self.pg7.local_ip4,
2967 self.pg7.remote_ip4, 116)
2968 bd_uu1.add_vpp_config()
2969 bd_uu2 = VppVxlanGbpTunnel(self, self.pg7.local_ip4,
2970 self.pg7.remote_ip4, 117)
2971 bd_uu2.add_vpp_config()
2972
2973 bd3 = VppBridgeDomain(self, 3)
2974 bd3.add_vpp_config()
2975 gbd3 = VppGbpBridgeDomain(self, bd3, self.loop2, bd_uu1, learn=False)
2976 gbd3.add_vpp_config()
2977 bd4 = VppBridgeDomain(self, 4)
2978 bd4.add_vpp_config()
2979 gbd4 = VppGbpBridgeDomain(self, bd4, self.loop3, bd_uu2, learn=False)
2980 gbd4.add_vpp_config()
2981
2982 #
2983 # EPGs in which the service endpoints exist
2984 #
Neale Ranns879d11c2019-01-21 23:34:18 -08002985 epg_320 = VppGbpEndpointGroup(self, 320, 550, rd1, gbd3,
Neale Ranns13a08cc2018-11-07 09:25:54 -08002986 None, gbd1.bvi,
2987 "12.0.0.128",
Neale Ranns32f6d8e2019-03-05 04:22:08 -08002988 "4001:10::128",
2989 VppGbpEndpointRetention(2))
Neale Ranns13a08cc2018-11-07 09:25:54 -08002990 epg_320.add_vpp_config()
Neale Ranns879d11c2019-01-21 23:34:18 -08002991 epg_321 = VppGbpEndpointGroup(self, 321, 551, rd1, gbd4,
Neale Ranns13a08cc2018-11-07 09:25:54 -08002992 None, gbd2.bvi,
2993 "12.0.1.128",
Neale Ranns32f6d8e2019-03-05 04:22:08 -08002994 "4001:11::128",
2995 VppGbpEndpointRetention(2))
Neale Ranns13a08cc2018-11-07 09:25:54 -08002996 epg_321.add_vpp_config()
2997
2998 #
2999 # three local endpoints
3000 #
3001 ep1 = VppGbpEndpoint(self, self.pg0,
3002 epg_220, None,
3003 "10.0.0.1", "11.0.0.1",
3004 "2001:10::1", "3001:10::1")
3005 ep1.add_vpp_config()
3006 ep2 = VppGbpEndpoint(self, self.pg1,
3007 epg_221, None,
3008 "10.0.1.1", "11.0.1.1",
3009 "2001:11::1", "3001:11::1")
3010 ep2.add_vpp_config()
3011 ep3 = VppGbpEndpoint(self, self.pg2,
3012 epg_222, None,
3013 "10.0.2.2", "11.0.2.2",
3014 "2001:12::1", "3001:12::1")
3015 ep3.add_vpp_config()
3016
3017 #
3018 # service endpoints
3019 #
3020 sep1 = VppGbpEndpoint(self, self.pg3,
3021 epg_320, None,
3022 "12.0.0.1", "13.0.0.1",
3023 "4001:10::1", "5001:10::1")
3024 sep1.add_vpp_config()
3025 sep2 = VppGbpEndpoint(self, self.pg4,
3026 epg_320, None,
3027 "12.0.0.2", "13.0.0.2",
3028 "4001:10::2", "5001:10::2")
3029 sep2.add_vpp_config()
3030 sep3 = VppGbpEndpoint(self, self.pg5,
3031 epg_321, None,
3032 "12.0.1.1", "13.0.1.1",
3033 "4001:11::1", "5001:11::1")
3034 sep3.add_vpp_config()
3035 # this EP is not installed immediately
3036 sep4 = VppGbpEndpoint(self, self.pg6,
3037 epg_321, None,
3038 "12.0.1.2", "13.0.1.2",
3039 "4001:11::2", "5001:11::2")
3040
3041 #
3042 # an L2 switch packet between local EPs in different EPGs
3043 # different dest ports on each so the are LB hashed differently
3044 #
3045 p4 = [(Ether(src=ep1.mac, dst=ep3.mac) /
3046 IP(src=ep1.ip4.address, dst=ep3.ip4.address) /
3047 UDP(sport=1234, dport=1234) /
3048 Raw('\xa5' * 100)),
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003049 (Ether(src=ep3.mac, dst=ep1.mac) /
3050 IP(src=ep3.ip4.address, dst=ep1.ip4.address) /
3051 UDP(sport=1234, dport=1234) /
Neale Ranns13a08cc2018-11-07 09:25:54 -08003052 Raw('\xa5' * 100))]
3053 p6 = [(Ether(src=ep1.mac, dst=ep3.mac) /
3054 IPv6(src=ep1.ip6.address, dst=ep3.ip6.address) /
3055 UDP(sport=1234, dport=1234) /
3056 Raw('\xa5' * 100)),
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003057 (Ether(src=ep3.mac, dst=ep1.mac) /
3058 IPv6(src=ep3.ip6.address, dst=ep1.ip6.address) /
Neale Ranns13a08cc2018-11-07 09:25:54 -08003059 UDP(sport=1234, dport=1230) /
3060 Raw('\xa5' * 100))]
3061
3062 # should be dropped since no contract yet
3063 self.send_and_assert_no_replies(self.pg0, [p4[0]])
3064 self.send_and_assert_no_replies(self.pg0, [p6[0]])
3065
3066 #
3067 # Add a contract with a rule to load-balance redirect via SEP1 and SEP2
3068 # one of the next-hops is via an EP that is not known
3069 #
3070 acl = VppGbpAcl(self)
3071 rule4 = acl.create_rule(permit_deny=1, proto=17)
3072 rule6 = acl.create_rule(is_ipv6=1, permit_deny=1, proto=17)
3073 acl_index = acl.add_vpp_config([rule4, rule6])
3074
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003075 #
3076 # test the src-ip hash mode
3077 #
Neale Ranns13a08cc2018-11-07 09:25:54 -08003078 c1 = VppGbpContract(
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003079 self, epg_220.sclass, epg_222.sclass, acl_index,
Neale Ranns13a08cc2018-11-07 09:25:54 -08003080 [VppGbpContractRule(
3081 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT,
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003082 VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP,
Neale Ranns13a08cc2018-11-07 09:25:54 -08003083 [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd,
3084 sep1.ip4, sep1.epg.rd),
3085 VppGbpContractNextHop(sep2.vmac, sep2.epg.bd,
3086 sep2.ip4, sep2.epg.rd)]),
Filip Vargaf4749ca2019-04-25 14:55:32 +02003087 VppGbpContractRule(
3088 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT,
3089 VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP,
3090 [VppGbpContractNextHop(sep3.vmac, sep3.epg.bd,
3091 sep3.ip6, sep3.epg.rd),
3092 VppGbpContractNextHop(sep4.vmac, sep4.epg.bd,
3093 sep4.ip6, sep4.epg.rd)])],
Neale Ranns1c17e2e2018-12-20 12:03:59 -08003094 [ETH_P_IP, ETH_P_IPV6])
Neale Ranns13a08cc2018-11-07 09:25:54 -08003095 c1.add_vpp_config()
3096
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003097 c2 = VppGbpContract(
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003098 self, epg_222.sclass, epg_220.sclass, acl_index,
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003099 [VppGbpContractRule(
3100 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT,
3101 VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP,
3102 [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd,
3103 sep1.ip4, sep1.epg.rd),
3104 VppGbpContractNextHop(sep2.vmac, sep2.epg.bd,
3105 sep2.ip4, sep2.epg.rd)]),
Filip Vargaf4749ca2019-04-25 14:55:32 +02003106 VppGbpContractRule(
3107 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT,
3108 VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP,
3109 [VppGbpContractNextHop(sep3.vmac, sep3.epg.bd,
3110 sep3.ip6, sep3.epg.rd),
3111 VppGbpContractNextHop(sep4.vmac, sep4.epg.bd,
3112 sep4.ip6, sep4.epg.rd)])],
Neale Ranns1c17e2e2018-12-20 12:03:59 -08003113 [ETH_P_IP, ETH_P_IPV6])
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003114 c2.add_vpp_config()
3115
Neale Ranns13a08cc2018-11-07 09:25:54 -08003116 #
3117 # send again with the contract preset, now packets arrive
3118 # at SEP1 or SEP2 depending on the hashing
3119 #
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003120 rxs = self.send_and_expect(self.pg0, p4[0] * 17, sep1.itf)
Neale Ranns13a08cc2018-11-07 09:25:54 -08003121
3122 for rx in rxs:
3123 self.assertEqual(rx[Ether].src, routed_src_mac)
3124 self.assertEqual(rx[Ether].dst, sep1.mac)
3125 self.assertEqual(rx[IP].src, ep1.ip4.address)
3126 self.assertEqual(rx[IP].dst, ep3.ip4.address)
3127
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003128 rxs = self.send_and_expect(self.pg2, p4[1] * 17, sep2.itf)
3129
3130 for rx in rxs:
3131 self.assertEqual(rx[Ether].src, routed_src_mac)
3132 self.assertEqual(rx[Ether].dst, sep2.mac)
3133 self.assertEqual(rx[IP].src, ep3.ip4.address)
3134 self.assertEqual(rx[IP].dst, ep1.ip4.address)
3135
Neale Ranns13a08cc2018-11-07 09:25:54 -08003136 rxs = self.send_and_expect(self.pg0, p6[0] * 17, self.pg7)
3137
3138 for rx in rxs:
3139 self.assertEqual(rx[Ether].src, self.pg7.local_mac)
3140 self.assertEqual(rx[Ether].dst, self.pg7.remote_mac)
3141 self.assertEqual(rx[IP].src, self.pg7.local_ip4)
3142 self.assertEqual(rx[IP].dst, self.pg7.remote_ip4)
3143 self.assertEqual(rx[VXLAN].vni, 117)
3144 self.assertTrue(rx[VXLAN].flags.G)
3145 self.assertTrue(rx[VXLAN].flags.Instance)
3146 # redirect policy has been applied
3147 self.assertTrue(rx[VXLAN].gpflags.A)
3148 self.assertFalse(rx[VXLAN].gpflags.D)
3149
3150 inner = rx[VXLAN].payload
3151
3152 self.assertEqual(inner[Ether].src, routed_src_mac)
3153 self.assertEqual(inner[Ether].dst, sep4.mac)
3154 self.assertEqual(inner[IPv6].src, ep1.ip6.address)
3155 self.assertEqual(inner[IPv6].dst, ep3.ip6.address)
3156
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003157 rxs = self.send_and_expect(self.pg2, p6[1] * 17, sep3.itf)
Neale Ranns13a08cc2018-11-07 09:25:54 -08003158
3159 for rx in rxs:
3160 self.assertEqual(rx[Ether].src, routed_src_mac)
3161 self.assertEqual(rx[Ether].dst, sep3.mac)
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003162 self.assertEqual(rx[IPv6].src, ep3.ip6.address)
3163 self.assertEqual(rx[IPv6].dst, ep1.ip6.address)
Neale Ranns13a08cc2018-11-07 09:25:54 -08003164
3165 #
3166 # programme the unknown EP
3167 #
3168 sep4.add_vpp_config()
3169
3170 rxs = self.send_and_expect(self.pg0, p6[0] * 17, sep4.itf)
3171
3172 for rx in rxs:
3173 self.assertEqual(rx[Ether].src, routed_src_mac)
3174 self.assertEqual(rx[Ether].dst, sep4.mac)
3175 self.assertEqual(rx[IPv6].src, ep1.ip6.address)
3176 self.assertEqual(rx[IPv6].dst, ep3.ip6.address)
3177
3178 #
3179 # and revert back to unprogrammed
3180 #
3181 sep4.remove_vpp_config()
3182
3183 rxs = self.send_and_expect(self.pg0, p6[0] * 17, self.pg7)
3184
3185 for rx in rxs:
3186 self.assertEqual(rx[Ether].src, self.pg7.local_mac)
3187 self.assertEqual(rx[Ether].dst, self.pg7.remote_mac)
3188 self.assertEqual(rx[IP].src, self.pg7.local_ip4)
3189 self.assertEqual(rx[IP].dst, self.pg7.remote_ip4)
3190 self.assertEqual(rx[VXLAN].vni, 117)
3191 self.assertTrue(rx[VXLAN].flags.G)
3192 self.assertTrue(rx[VXLAN].flags.Instance)
3193 # redirect policy has been applied
3194 self.assertTrue(rx[VXLAN].gpflags.A)
3195 self.assertFalse(rx[VXLAN].gpflags.D)
3196
3197 inner = rx[VXLAN].payload
3198
3199 self.assertEqual(inner[Ether].src, routed_src_mac)
3200 self.assertEqual(inner[Ether].dst, sep4.mac)
3201 self.assertEqual(inner[IPv6].src, ep1.ip6.address)
3202 self.assertEqual(inner[IPv6].dst, ep3.ip6.address)
3203
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003204 c1.remove_vpp_config()
3205 c2.remove_vpp_config()
3206
3207 #
3208 # test the symmetric hash mode
3209 #
3210 c1 = VppGbpContract(
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003211 self, epg_220.sclass, epg_222.sclass, acl_index,
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003212 [VppGbpContractRule(
3213 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT,
3214 VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SYMMETRIC,
3215 [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd,
3216 sep1.ip4, sep1.epg.rd),
3217 VppGbpContractNextHop(sep2.vmac, sep2.epg.bd,
3218 sep2.ip4, sep2.epg.rd)]),
Filip Vargaf4749ca2019-04-25 14:55:32 +02003219 VppGbpContractRule(
3220 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT,
3221 VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SYMMETRIC,
3222 [VppGbpContractNextHop(sep3.vmac, sep3.epg.bd,
3223 sep3.ip6, sep3.epg.rd),
3224 VppGbpContractNextHop(sep4.vmac, sep4.epg.bd,
3225 sep4.ip6, sep4.epg.rd)])],
Neale Ranns1c17e2e2018-12-20 12:03:59 -08003226 [ETH_P_IP, ETH_P_IPV6])
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003227 c1.add_vpp_config()
3228
3229 c2 = VppGbpContract(
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003230 self, epg_222.sclass, epg_220.sclass, acl_index,
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003231 [VppGbpContractRule(
3232 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT,
3233 VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SYMMETRIC,
3234 [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd,
3235 sep1.ip4, sep1.epg.rd),
3236 VppGbpContractNextHop(sep2.vmac, sep2.epg.bd,
3237 sep2.ip4, sep2.epg.rd)]),
Filip Vargaf4749ca2019-04-25 14:55:32 +02003238 VppGbpContractRule(
3239 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT,
3240 VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SYMMETRIC,
3241 [VppGbpContractNextHop(sep3.vmac, sep3.epg.bd,
3242 sep3.ip6, sep3.epg.rd),
3243 VppGbpContractNextHop(sep4.vmac, sep4.epg.bd,
3244 sep4.ip6, sep4.epg.rd)])],
Neale Ranns1c17e2e2018-12-20 12:03:59 -08003245 [ETH_P_IP, ETH_P_IPV6])
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003246 c2.add_vpp_config()
3247
3248 #
3249 # send again with the contract preset, now packets arrive
3250 # at SEP1 for both directions
3251 #
3252 rxs = self.send_and_expect(self.pg0, p4[0] * 17, sep1.itf)
3253
3254 for rx in rxs:
3255 self.assertEqual(rx[Ether].src, routed_src_mac)
3256 self.assertEqual(rx[Ether].dst, sep1.mac)
3257 self.assertEqual(rx[IP].src, ep1.ip4.address)
3258 self.assertEqual(rx[IP].dst, ep3.ip4.address)
3259
3260 rxs = self.send_and_expect(self.pg2, p4[1] * 17, sep1.itf)
3261
3262 for rx in rxs:
3263 self.assertEqual(rx[Ether].src, routed_src_mac)
3264 self.assertEqual(rx[Ether].dst, sep1.mac)
3265 self.assertEqual(rx[IP].src, ep3.ip4.address)
3266 self.assertEqual(rx[IP].dst, ep1.ip4.address)
3267
Neale Ranns13a08cc2018-11-07 09:25:54 -08003268 #
3269 # programme the unknown EP for the L3 tests
3270 #
3271 sep4.add_vpp_config()
3272
3273 #
3274 # an L3 switch packet between local EPs in different EPGs
3275 # different dest ports on each so the are LB hashed differently
3276 #
Ole Troan8006c6a2018-12-17 12:02:26 +01003277 p4 = [(Ether(src=ep1.mac, dst=str(self.router_mac)) /
Neale Ranns13a08cc2018-11-07 09:25:54 -08003278 IP(src=ep1.ip4.address, dst=ep2.ip4.address) /
3279 UDP(sport=1234, dport=1234) /
3280 Raw('\xa5' * 100)),
Ole Troan8006c6a2018-12-17 12:02:26 +01003281 (Ether(src=ep2.mac, dst=str(self.router_mac)) /
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003282 IP(src=ep2.ip4.address, dst=ep1.ip4.address) /
3283 UDP(sport=1234, dport=1234) /
Neale Ranns13a08cc2018-11-07 09:25:54 -08003284 Raw('\xa5' * 100))]
Ole Troan8006c6a2018-12-17 12:02:26 +01003285 p6 = [(Ether(src=ep1.mac, dst=str(self.router_mac)) /
Neale Ranns13a08cc2018-11-07 09:25:54 -08003286 IPv6(src=ep1.ip6.address, dst=ep2.ip6.address) /
3287 UDP(sport=1234, dport=1234) /
3288 Raw('\xa5' * 100)),
Ole Troan8006c6a2018-12-17 12:02:26 +01003289 (Ether(src=ep2.mac, dst=str(self.router_mac)) /
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003290 IPv6(src=ep2.ip6.address, dst=ep1.ip6.address) /
3291 UDP(sport=1234, dport=1234) /
Neale Ranns13a08cc2018-11-07 09:25:54 -08003292 Raw('\xa5' * 100))]
3293
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003294 c3 = VppGbpContract(
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003295 self, epg_220.sclass, epg_221.sclass, acl_index,
Neale Ranns1c17e2e2018-12-20 12:03:59 -08003296 [VppGbpContractRule(
3297 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT,
3298 VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SYMMETRIC,
3299 [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd,
3300 sep1.ip4, sep1.epg.rd),
3301 VppGbpContractNextHop(sep2.vmac, sep2.epg.bd,
3302 sep2.ip4, sep2.epg.rd)]),
Filip Vargaf4749ca2019-04-25 14:55:32 +02003303 VppGbpContractRule(
3304 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT,
3305 VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SYMMETRIC,
3306 [VppGbpContractNextHop(sep3.vmac, sep3.epg.bd,
3307 sep3.ip6, sep3.epg.rd),
3308 VppGbpContractNextHop(sep4.vmac, sep4.epg.bd,
3309 sep4.ip6, sep4.epg.rd)])],
Neale Ranns1c17e2e2018-12-20 12:03:59 -08003310 [ETH_P_IP, ETH_P_IPV6])
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003311 c3.add_vpp_config()
Neale Ranns13a08cc2018-11-07 09:25:54 -08003312
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003313 rxs = self.send_and_expect(self.pg0, p4[0] * 17, sep1.itf)
Neale Ranns13a08cc2018-11-07 09:25:54 -08003314
3315 for rx in rxs:
3316 self.assertEqual(rx[Ether].src, routed_src_mac)
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003317 self.assertEqual(rx[Ether].dst, sep1.mac)
Neale Ranns13a08cc2018-11-07 09:25:54 -08003318 self.assertEqual(rx[IP].src, ep1.ip4.address)
3319 self.assertEqual(rx[IP].dst, ep2.ip4.address)
3320
3321 #
3322 # learn a remote EP in EPG 221
3323 #
3324 vx_tun_l3 = VppGbpVxlanTunnel(
3325 self, 444, rd1.rd_id,
Neale Ranns8da9fc62019-03-04 14:08:11 -08003326 VppEnum.vl_api_gbp_vxlan_tunnel_mode_t.GBP_VXLAN_TUNNEL_MODE_L3,
3327 self.pg2.local_ip4)
Neale Ranns13a08cc2018-11-07 09:25:54 -08003328 vx_tun_l3.add_vpp_config()
3329
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003330 c4 = VppGbpContract(
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003331 self, epg_221.sclass, epg_220.sclass, acl_index,
Neale Ranns13a08cc2018-11-07 09:25:54 -08003332 [VppGbpContractRule(
3333 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
3334 []),
Filip Vargaf4749ca2019-04-25 14:55:32 +02003335 VppGbpContractRule(
3336 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
3337 [])],
Neale Ranns1c17e2e2018-12-20 12:03:59 -08003338 [ETH_P_IP, ETH_P_IPV6])
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003339 c4.add_vpp_config()
Neale Ranns13a08cc2018-11-07 09:25:54 -08003340
3341 p = (Ether(src=self.pg7.remote_mac,
3342 dst=self.pg7.local_mac) /
3343 IP(src=self.pg7.remote_ip4,
3344 dst=self.pg7.local_ip4) /
3345 UDP(sport=1234, dport=48879) /
Neale Ranns879d11c2019-01-21 23:34:18 -08003346 VXLAN(vni=444, gpid=441, flags=0x88) /
Ole Troan8006c6a2018-12-17 12:02:26 +01003347 Ether(src="00:22:22:22:22:33", dst=str(self.router_mac)) /
Neale Ranns13a08cc2018-11-07 09:25:54 -08003348 IP(src="10.0.0.88", dst=ep1.ip4.address) /
3349 UDP(sport=1234, dport=1234) /
3350 Raw('\xa5' * 100))
3351
3352 rx = self.send_and_expect(self.pg7, [p], self.pg0)
3353
3354 # endpoint learnt via the parent GBP-vxlan interface
3355 self.assertTrue(find_gbp_endpoint(self,
3356 vx_tun_l3._sw_if_index,
3357 ip="10.0.0.88"))
3358
3359 p = (Ether(src=self.pg7.remote_mac,
3360 dst=self.pg7.local_mac) /
3361 IP(src=self.pg7.remote_ip4,
3362 dst=self.pg7.local_ip4) /
3363 UDP(sport=1234, dport=48879) /
Neale Ranns879d11c2019-01-21 23:34:18 -08003364 VXLAN(vni=444, gpid=441, flags=0x88) /
Ole Troan8006c6a2018-12-17 12:02:26 +01003365 Ether(src="00:22:22:22:22:33", dst=str(self.router_mac)) /
Neale Ranns13a08cc2018-11-07 09:25:54 -08003366 IPv6(src="2001:10::88", dst=ep1.ip6.address) /
3367 UDP(sport=1234, dport=1234) /
3368 Raw('\xa5' * 100))
3369
3370 rx = self.send_and_expect(self.pg7, [p], self.pg0)
3371
3372 # endpoint learnt via the parent GBP-vxlan interface
3373 self.assertTrue(find_gbp_endpoint(self,
3374 vx_tun_l3._sw_if_index,
3375 ip="2001:10::88"))
3376
3377 #
3378 # L3 switch from local to remote EP
3379 #
Ole Troan8006c6a2018-12-17 12:02:26 +01003380 p4 = [(Ether(src=ep1.mac, dst=str(self.router_mac)) /
Neale Ranns13a08cc2018-11-07 09:25:54 -08003381 IP(src=ep1.ip4.address, dst="10.0.0.88") /
3382 UDP(sport=1234, dport=1234) /
Neale Ranns13a08cc2018-11-07 09:25:54 -08003383 Raw('\xa5' * 100))]
Ole Troan8006c6a2018-12-17 12:02:26 +01003384 p6 = [(Ether(src=ep1.mac, dst=str(self.router_mac)) /
Neale Ranns13a08cc2018-11-07 09:25:54 -08003385 IPv6(src=ep1.ip6.address, dst="2001:10::88") /
3386 UDP(sport=1234, dport=1234) /
Neale Ranns13a08cc2018-11-07 09:25:54 -08003387 Raw('\xa5' * 100))]
3388
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003389 rxs = self.send_and_expect(self.pg0, p4[0] * 17, sep1.itf)
Neale Ranns13a08cc2018-11-07 09:25:54 -08003390
3391 for rx in rxs:
3392 self.assertEqual(rx[Ether].src, routed_src_mac)
3393 self.assertEqual(rx[Ether].dst, sep1.mac)
3394 self.assertEqual(rx[IP].src, ep1.ip4.address)
3395 self.assertEqual(rx[IP].dst, "10.0.0.88")
3396
3397 rxs = self.send_and_expect(self.pg0, p6[0] * 17, sep4.itf)
3398
3399 for rx in rxs:
3400 self.assertEqual(rx[Ether].src, routed_src_mac)
3401 self.assertEqual(rx[Ether].dst, sep4.mac)
3402 self.assertEqual(rx[IPv6].src, ep1.ip6.address)
3403 self.assertEqual(rx[IPv6].dst, "2001:10::88")
3404
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003405 #
3406 # test the dst-ip hash mode
3407 #
3408 c5 = VppGbpContract(
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003409 self, epg_220.sclass, epg_221.sclass, acl_index,
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003410 [VppGbpContractRule(
3411 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT,
3412 VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_DST_IP,
3413 [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd,
3414 sep1.ip4, sep1.epg.rd),
3415 VppGbpContractNextHop(sep2.vmac, sep2.epg.bd,
3416 sep2.ip4, sep2.epg.rd)]),
Filip Vargaf4749ca2019-04-25 14:55:32 +02003417 VppGbpContractRule(
3418 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT,
3419 VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_DST_IP,
3420 [VppGbpContractNextHop(sep3.vmac, sep3.epg.bd,
3421 sep3.ip6, sep3.epg.rd),
3422 VppGbpContractNextHop(sep4.vmac, sep4.epg.bd,
3423 sep4.ip6, sep4.epg.rd)])],
Neale Ranns1c17e2e2018-12-20 12:03:59 -08003424 [ETH_P_IP, ETH_P_IPV6])
Mohsin Kazmid40c3e62018-11-21 10:46:57 +01003425 c5.add_vpp_config()
3426
3427 rxs = self.send_and_expect(self.pg0, p4[0] * 17, sep1.itf)
3428
3429 for rx in rxs:
3430 self.assertEqual(rx[Ether].src, routed_src_mac)
3431 self.assertEqual(rx[Ether].dst, sep1.mac)
3432 self.assertEqual(rx[IP].src, ep1.ip4.address)
3433 self.assertEqual(rx[IP].dst, "10.0.0.88")
3434
3435 rxs = self.send_and_expect(self.pg0, p6[0] * 17, sep3.itf)
Neale Ranns13a08cc2018-11-07 09:25:54 -08003436
3437 for rx in rxs:
3438 self.assertEqual(rx[Ether].src, routed_src_mac)
3439 self.assertEqual(rx[Ether].dst, sep3.mac)
3440 self.assertEqual(rx[IPv6].src, ep1.ip6.address)
3441 self.assertEqual(rx[IPv6].dst, "2001:10::88")
3442
Neale Rannsb6a47952018-11-21 05:44:35 -08003443 #
3444 # cleanup
3445 #
3446 self.pg7.unconfig_ip4()
3447
3448 def test_gbp_l3_out(self):
3449 """ GBP L3 Out """
3450
3451 ep_flags = VppEnum.vl_api_gbp_endpoint_flags_t
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -04003452 self.vapi.cli("set logging class gbp level debug")
Neale Rannsb6a47952018-11-21 05:44:35 -08003453
3454 routed_dst_mac = "00:0c:0c:0c:0c:0c"
3455 routed_src_mac = "00:22:bd:f8:19:ff"
3456
3457 #
3458 # IP tables
3459 #
3460 t4 = VppIpTable(self, 1)
3461 t4.add_vpp_config()
3462 t6 = VppIpTable(self, 1, True)
3463 t6.add_vpp_config()
3464
3465 rd1 = VppGbpRouteDomain(self, 2, t4, t6)
3466 rd1.add_vpp_config()
3467
Ole Troan8006c6a2018-12-17 12:02:26 +01003468 self.loop0.set_mac(self.router_mac)
Neale Rannsb6a47952018-11-21 05:44:35 -08003469
3470 #
3471 # Bind the BVI to the RD
3472 #
3473 VppIpInterfaceBind(self, self.loop0, t4).add_vpp_config()
3474 VppIpInterfaceBind(self, self.loop0, t6).add_vpp_config()
3475
3476 #
3477 # Pg7 hosts a BD's BUM
3478 # Pg1 some other l3 interface
3479 #
3480 self.pg7.config_ip4()
3481 self.pg7.resolve_arp()
3482
3483 #
Neale Ranns879d11c2019-01-21 23:34:18 -08003484 # a multicast vxlan-gbp tunnel for broadcast in the BD
3485 #
3486 tun_bm = VppVxlanGbpTunnel(self, self.pg7.local_ip4,
3487 "239.1.1.1", 88,
3488 mcast_itf=self.pg7)
3489 tun_bm.add_vpp_config()
3490
3491 #
Neale Rannsb6a47952018-11-21 05:44:35 -08003492 # a GBP external bridge domains for the EPs
3493 #
3494 bd1 = VppBridgeDomain(self, 1)
3495 bd1.add_vpp_config()
Neale Ranns879d11c2019-01-21 23:34:18 -08003496 gbd1 = VppGbpBridgeDomain(self, bd1, self.loop0, None, tun_bm)
Neale Rannsb6a47952018-11-21 05:44:35 -08003497 gbd1.add_vpp_config()
3498
3499 #
3500 # The Endpoint-groups in which the external endpoints exist
3501 #
Neale Ranns879d11c2019-01-21 23:34:18 -08003502 epg_220 = VppGbpEndpointGroup(self, 220, 113, rd1, gbd1,
Neale Rannsb6a47952018-11-21 05:44:35 -08003503 None, gbd1.bvi,
3504 "10.0.0.128",
Neale Ranns32f6d8e2019-03-05 04:22:08 -08003505 "2001:10::128",
3506 VppGbpEndpointRetention(2))
Neale Rannsb6a47952018-11-21 05:44:35 -08003507 epg_220.add_vpp_config()
3508
3509 # the BVIs have the subnets applied ...
3510 ip4_addr = VppIpInterfaceAddress(self, gbd1.bvi, "10.0.0.128", 24)
3511 ip4_addr.add_vpp_config()
3512 ip6_addr = VppIpInterfaceAddress(self, gbd1.bvi, "2001:10::128", 64)
3513 ip6_addr.add_vpp_config()
3514
3515 # ... which are L3-out subnets
3516 l3o_1 = VppGbpSubnet(
3517 self, rd1, "10.0.0.0", 24,
3518 VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003519 sclass=113)
Neale Rannsb6a47952018-11-21 05:44:35 -08003520 l3o_1.add_vpp_config()
3521
3522 #
3523 # an external interface attached to the outside world and the
3524 # external BD
3525 #
3526 vlan_100 = VppDot1QSubint(self, self.pg0, 100)
3527 vlan_100.admin_up()
Neale Ranns36abbf12019-03-12 02:34:07 -07003528 VppL2Vtr(self, vlan_100, L2_VTR_OP.L2_POP_1).add_vpp_config()
3529 vlan_101 = VppDot1QSubint(self, self.pg0, 101)
3530 vlan_101.admin_up()
3531 VppL2Vtr(self, vlan_101, L2_VTR_OP.L2_POP_1).add_vpp_config()
Benoît Ganne286921e2019-06-05 19:08:40 +02003532 # vlan_102 is not poped
3533 vlan_102 = VppDot1QSubint(self, self.pg0, 102)
3534 vlan_102.admin_up()
Neale Ranns36abbf12019-03-12 02:34:07 -07003535
3536 ext_itf = VppGbpExtItf(self, self.loop0, bd1, rd1)
Neale Rannsb6a47952018-11-21 05:44:35 -08003537 ext_itf.add_vpp_config()
3538
3539 #
Neale Ranns879d11c2019-01-21 23:34:18 -08003540 # an unicast vxlan-gbp for inter-RD traffic
Neale Rannsb6a47952018-11-21 05:44:35 -08003541 #
3542 vx_tun_l3 = VppGbpVxlanTunnel(
3543 self, 444, rd1.rd_id,
Neale Ranns8da9fc62019-03-04 14:08:11 -08003544 VppEnum.vl_api_gbp_vxlan_tunnel_mode_t.GBP_VXLAN_TUNNEL_MODE_L3,
3545 self.pg2.local_ip4)
Neale Rannsb6a47952018-11-21 05:44:35 -08003546 vx_tun_l3.add_vpp_config()
3547
3548 #
Neale Ranns36abbf12019-03-12 02:34:07 -07003549 # External Endpoints
3550 #
3551 eep1 = VppGbpEndpoint(self, vlan_100,
3552 epg_220, None,
3553 "10.0.0.1", "11.0.0.1",
3554 "2001:10::1", "3001::1",
3555 ep_flags.GBP_API_ENDPOINT_FLAG_EXTERNAL)
3556 eep1.add_vpp_config()
3557 eep2 = VppGbpEndpoint(self, vlan_101,
3558 epg_220, None,
3559 "10.0.0.2", "11.0.0.2",
3560 "2001:10::2", "3001::2",
3561 ep_flags.GBP_API_ENDPOINT_FLAG_EXTERNAL)
3562 eep2.add_vpp_config()
Benoît Ganne286921e2019-06-05 19:08:40 +02003563 eep3 = VppGbpEndpoint(self, vlan_102,
3564 epg_220, None,
3565 "10.0.0.3", "11.0.0.3",
3566 "2001:10::3", "3001::3",
3567 ep_flags.GBP_API_ENDPOINT_FLAG_EXTERNAL)
3568 eep3.add_vpp_config()
Neale Ranns36abbf12019-03-12 02:34:07 -07003569
3570 #
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003571 # A remote external endpoint
Neale Ranns36abbf12019-03-12 02:34:07 -07003572 #
3573 rep = VppGbpEndpoint(self, vx_tun_l3,
3574 epg_220, None,
3575 "10.0.0.101", "11.0.0.101",
3576 "2001:10::101", "3001::101",
3577 ep_flags.GBP_API_ENDPOINT_FLAG_REMOTE,
3578 self.pg7.local_ip4,
3579 self.pg7.remote_ip4,
3580 mac=None)
3581 rep.add_vpp_config()
3582
3583 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07003584 # ARP packet from External EPs are accepted and replied to
Neale Ranns4c2bff02019-03-14 02:52:27 -07003585 #
3586 p_arp = (Ether(src=eep1.mac, dst="ff:ff:ff:ff:ff:ff") /
3587 Dot1Q(vlan=100) /
3588 ARP(op="who-has",
3589 psrc=eep1.ip4.address, pdst="10.0.0.128",
3590 hwsrc=eep1.mac, hwdst="ff:ff:ff:ff:ff:ff"))
3591 rxs = self.send_and_expect(self.pg0, p_arp * 1, self.pg0)
3592
3593 #
Benoît Ganne286921e2019-06-05 19:08:40 +02003594 # ARP packet from host in remote subnet are accepted and replied to
3595 #
3596 p_arp = (Ether(src=vlan_102.remote_mac, dst="ff:ff:ff:ff:ff:ff") /
3597 Dot1Q(vlan=102) /
3598 ARP(op="who-has",
3599 psrc="10.0.0.17", pdst="10.0.0.128",
3600 hwsrc=vlan_102.remote_mac, hwdst="ff:ff:ff:ff:ff:ff"))
3601 rxs = self.send_and_expect(self.pg0, p_arp * 1, self.pg0)
3602
3603 #
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -07003604 # packets destined to unknown addresses in the BVI's subnet
Neale Rannsb6a47952018-11-21 05:44:35 -08003605 # are ARP'd for
3606 #
Neale Ranns36abbf12019-03-12 02:34:07 -07003607 p4 = (Ether(src=eep1.mac, dst=str(self.router_mac)) /
Neale Rannsb6a47952018-11-21 05:44:35 -08003608 Dot1Q(vlan=100) /
3609 IP(src="10.0.0.1", dst="10.0.0.88") /
3610 UDP(sport=1234, dport=1234) /
3611 Raw('\xa5' * 100))
Neale Ranns36abbf12019-03-12 02:34:07 -07003612 p6 = (Ether(src=eep1.mac, dst=str(self.router_mac)) /
Neale Rannsb6a47952018-11-21 05:44:35 -08003613 Dot1Q(vlan=100) /
3614 IPv6(src="2001:10::1", dst="2001:10::88") /
3615 UDP(sport=1234, dport=1234) /
3616 Raw('\xa5' * 100))
3617
3618 rxs = self.send_and_expect(self.pg0, p4 * 1, self.pg7)
3619
3620 for rx in rxs:
3621 self.assertEqual(rx[Ether].src, self.pg7.local_mac)
3622 # self.assertEqual(rx[Ether].dst, self.pg7.remote_mac)
3623 self.assertEqual(rx[IP].src, self.pg7.local_ip4)
3624 self.assertEqual(rx[IP].dst, "239.1.1.1")
3625 self.assertEqual(rx[VXLAN].vni, 88)
3626 self.assertTrue(rx[VXLAN].flags.G)
3627 self.assertTrue(rx[VXLAN].flags.Instance)
Neale Ranns45db8852019-01-09 00:04:04 -08003628 # policy was applied to the original IP packet
Neale Ranns879d11c2019-01-21 23:34:18 -08003629 self.assertEqual(rx[VXLAN].gpid, 113)
Neale Ranns45db8852019-01-09 00:04:04 -08003630 self.assertTrue(rx[VXLAN].gpflags.A)
Neale Rannsb6a47952018-11-21 05:44:35 -08003631 self.assertFalse(rx[VXLAN].gpflags.D)
3632
3633 inner = rx[VXLAN].payload
3634
3635 self.assertTrue(inner.haslayer(ARP))
3636
3637 #
Neale Rannsb6a47952018-11-21 05:44:35 -08003638 # remote to external
3639 #
3640 p = (Ether(src=self.pg7.remote_mac,
3641 dst=self.pg7.local_mac) /
3642 IP(src=self.pg7.remote_ip4,
3643 dst=self.pg7.local_ip4) /
3644 UDP(sport=1234, dport=48879) /
Neale Ranns879d11c2019-01-21 23:34:18 -08003645 VXLAN(vni=444, gpid=113, flags=0x88) /
Ole Troan8006c6a2018-12-17 12:02:26 +01003646 Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) /
Neale Rannsb6a47952018-11-21 05:44:35 -08003647 IP(src="10.0.0.101", dst="10.0.0.1") /
3648 UDP(sport=1234, dport=1234) /
3649 Raw('\xa5' * 100))
3650
3651 rxs = self.send_and_expect(self.pg7, p * 1, self.pg0)
3652
3653 #
Neale Ranns36abbf12019-03-12 02:34:07 -07003654 # local EP pings router
3655 #
3656 p = (Ether(src=eep1.mac, dst=str(self.router_mac)) /
3657 Dot1Q(vlan=100) /
3658 IP(src=eep1.ip4.address, dst="10.0.0.128") /
3659 ICMP(type='echo-request'))
3660
3661 rxs = self.send_and_expect(self.pg0, p * 1, self.pg0)
3662
3663 for rx in rxs:
3664 self.assertEqual(rx[Ether].src, str(self.router_mac))
3665 self.assertEqual(rx[Ether].dst, eep1.mac)
3666 self.assertEqual(rx[Dot1Q].vlan, 100)
3667
3668 #
3669 # local EP pings other local EP
3670 #
3671 p = (Ether(src=eep1.mac, dst=eep2.mac) /
3672 Dot1Q(vlan=100) /
3673 IP(src=eep1.ip4.address, dst=eep2.ip4.address) /
3674 ICMP(type='echo-request'))
3675
3676 rxs = self.send_and_expect(self.pg0, p * 1, self.pg0)
3677
3678 for rx in rxs:
3679 self.assertEqual(rx[Ether].src, eep1.mac)
3680 self.assertEqual(rx[Ether].dst, eep2.mac)
3681 self.assertEqual(rx[Dot1Q].vlan, 101)
3682
3683 #
Benoît Ganne286921e2019-06-05 19:08:40 +02003684 # local EP pings router w/o vlan tag poped
3685 #
3686 p = (Ether(src=eep3.mac, dst=str(self.router_mac)) /
3687 Dot1Q(vlan=102) /
3688 IP(src=eep3.ip4.address, dst="10.0.0.128") /
3689 ICMP(type='echo-request'))
3690
3691 rxs = self.send_and_expect(self.pg0, p * 1, self.pg0)
3692
3693 for rx in rxs:
3694 self.assertEqual(rx[Ether].src, str(self.router_mac))
3695 self.assertEqual(rx[Ether].dst, vlan_102.remote_mac)
3696
3697 #
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003698 # A subnet reachable through the external EP1
Neale Rannsb6a47952018-11-21 05:44:35 -08003699 #
3700 ip_220 = VppIpRoute(self, "10.220.0.0", 24,
Neale Ranns36abbf12019-03-12 02:34:07 -07003701 [VppRoutePath(eep1.ip4.address,
3702 eep1.epg.bvi.sw_if_index)],
Neale Rannsb6a47952018-11-21 05:44:35 -08003703 table_id=t4.table_id)
3704 ip_220.add_vpp_config()
3705
3706 l3o_220 = VppGbpSubnet(
3707 self, rd1, "10.220.0.0", 24,
3708 VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003709 sclass=4220)
Neale Rannsb6a47952018-11-21 05:44:35 -08003710 l3o_220.add_vpp_config()
3711
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003712 #
3713 # A subnet reachable through the external EP2
3714 #
3715 ip_221 = VppIpRoute(self, "10.221.0.0", 24,
3716 [VppRoutePath(eep2.ip4.address,
3717 eep2.epg.bvi.sw_if_index)],
3718 table_id=t4.table_id)
3719 ip_221.add_vpp_config()
3720
3721 l3o_221 = VppGbpSubnet(
3722 self, rd1, "10.221.0.0", 24,
3723 VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT,
3724 sclass=4221)
3725 l3o_221.add_vpp_config()
3726
3727 #
3728 # ping between hosts in remote subnets
3729 # dropped without a contract
3730 #
3731 p = (Ether(src=eep1.mac, dst=str(self.router_mac)) /
3732 Dot1Q(vlan=100) /
3733 IP(src="10.220.0.1", dst="10.221.0.1") /
3734 ICMP(type='echo-request'))
3735
3736 rxs = self.send_and_assert_no_replies(self.pg0, p * 1)
3737
3738 #
3739 # contract for the external nets to communicate
3740 #
3741 acl = VppGbpAcl(self)
3742 rule4 = acl.create_rule(permit_deny=1, proto=17)
3743 rule6 = acl.create_rule(is_ipv6=1, permit_deny=1, proto=17)
3744 acl_index = acl.add_vpp_config([rule4, rule6])
3745
3746 c1 = VppGbpContract(
3747 self, 4220, 4221, acl_index,
3748 [VppGbpContractRule(
3749 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
3750 []),
Filip Vargaf4749ca2019-04-25 14:55:32 +02003751 VppGbpContractRule(
3752 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
3753 [])],
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003754 [ETH_P_IP, ETH_P_IPV6])
3755 c1.add_vpp_config()
3756
3757 #
3758 # Contracts allowing ext-net 200 to talk with external EPs
3759 #
3760 c2 = VppGbpContract(
3761 self, 4220, 113, acl_index,
3762 [VppGbpContractRule(
3763 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
3764 []),
Filip Vargaf4749ca2019-04-25 14:55:32 +02003765 VppGbpContractRule(
3766 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
3767 [])],
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003768 [ETH_P_IP, ETH_P_IPV6])
3769 c2.add_vpp_config()
3770 c3 = VppGbpContract(
3771 self, 113, 4220, acl_index,
3772 [VppGbpContractRule(
3773 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
3774 []),
Filip Vargaf4749ca2019-04-25 14:55:32 +02003775 VppGbpContractRule(
3776 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
3777 [])],
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003778 [ETH_P_IP, ETH_P_IPV6])
3779 c3.add_vpp_config()
3780
3781 #
3782 # ping between hosts in remote subnets
3783 #
3784 p = (Ether(src=eep1.mac, dst=str(self.router_mac)) /
3785 Dot1Q(vlan=100) /
3786 IP(src="10.220.0.1", dst="10.221.0.1") /
3787 UDP(sport=1234, dport=1234) /
3788 Raw('\xa5' * 100))
3789
3790 rxs = self.send_and_expect(self.pg0, p * 1, self.pg0)
3791
3792 for rx in rxs:
3793 self.assertEqual(rx[Ether].src, str(self.router_mac))
3794 self.assertEqual(rx[Ether].dst, eep2.mac)
3795 self.assertEqual(rx[Dot1Q].vlan, 101)
3796
3797 # we did not learn these external hosts
3798 self.assertFalse(find_gbp_endpoint(self, ip="10.220.0.1"))
3799 self.assertFalse(find_gbp_endpoint(self, ip="10.221.0.1"))
3800
3801 #
3802 # from remote external EP to local external EP
3803 #
Neale Rannsb6a47952018-11-21 05:44:35 -08003804 p = (Ether(src=self.pg7.remote_mac,
3805 dst=self.pg7.local_mac) /
3806 IP(src=self.pg7.remote_ip4,
3807 dst=self.pg7.local_ip4) /
3808 UDP(sport=1234, dport=48879) /
Neale Ranns879d11c2019-01-21 23:34:18 -08003809 VXLAN(vni=444, gpid=113, flags=0x88) /
Ole Troan8006c6a2018-12-17 12:02:26 +01003810 Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) /
Neale Rannsb6a47952018-11-21 05:44:35 -08003811 IP(src="10.0.0.101", dst="10.220.0.1") /
3812 UDP(sport=1234, dport=1234) /
3813 Raw('\xa5' * 100))
3814
3815 rxs = self.send_and_expect(self.pg7, p * 1, self.pg0)
3816
3817 #
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003818 # ping from an external host to the remote external EP
Neale Ranns36abbf12019-03-12 02:34:07 -07003819 #
3820 p = (Ether(src=eep1.mac, dst=str(self.router_mac)) /
3821 Dot1Q(vlan=100) /
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003822 IP(src="10.220.0.1", dst=rep.ip4.address) /
3823 UDP(sport=1234, dport=1234) /
3824 Raw('\xa5' * 100))
Neale Ranns36abbf12019-03-12 02:34:07 -07003825
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003826 rxs = self.send_and_expect(self.pg0, p * 1, self.pg7)
Neale Ranns36abbf12019-03-12 02:34:07 -07003827
3828 for rx in rxs:
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003829 self.assertEqual(rx[Ether].src, self.pg7.local_mac)
3830 # self.assertEqual(rx[Ether].dst, self.pg7.remote_mac)
3831 self.assertEqual(rx[IP].src, self.pg7.local_ip4)
3832 self.assertEqual(rx[IP].dst, self.pg7.remote_ip4)
3833 self.assertEqual(rx[VXLAN].vni, 444)
3834 self.assertTrue(rx[VXLAN].flags.G)
3835 self.assertTrue(rx[VXLAN].flags.Instance)
3836 # the sclass of the ext-net the packet came from
3837 self.assertEqual(rx[VXLAN].gpid, 4220)
3838 # policy was applied to the original IP packet
3839 self.assertTrue(rx[VXLAN].gpflags.A)
3840 # since it's an external host the reciever should not learn it
3841 self.assertTrue(rx[VXLAN].gpflags.D)
3842 inner = rx[VXLAN].payload
3843 self.assertEqual(inner[IP].src, "10.220.0.1")
3844 self.assertEqual(inner[IP].dst, rep.ip4.address)
3845
3846 #
3847 # An external subnet reachable via the remote external EP
3848 #
3849
3850 #
3851 # first the VXLAN-GBP tunnel over which it is reached
3852 #
3853 vx_tun_r = VppVxlanGbpTunnel(
3854 self, self.pg7.local_ip4,
3855 self.pg7.remote_ip4, 445,
3856 mode=(VppEnum.vl_api_vxlan_gbp_api_tunnel_mode_t.
3857 VXLAN_GBP_API_TUNNEL_MODE_L3))
3858 vx_tun_r.add_vpp_config()
3859 VppIpInterfaceBind(self, vx_tun_r, t4).add_vpp_config()
3860
3861 self.logger.info(self.vapi.cli("sh vxlan-gbp tunnel"))
3862
3863 #
3864 # then the special adj to resolve through on that tunnel
3865 #
3866 n1 = VppNeighbor(self,
3867 vx_tun_r.sw_if_index,
3868 "00:0c:0c:0c:0c:0c",
3869 self.pg7.remote_ip4)
3870 n1.add_vpp_config()
3871
3872 #
3873 # the route via the adj above
3874 #
3875 ip_222 = VppIpRoute(self, "10.222.0.0", 24,
3876 [VppRoutePath(self.pg7.remote_ip4,
3877 vx_tun_r.sw_if_index)],
3878 table_id=t4.table_id)
3879 ip_222.add_vpp_config()
3880
3881 l3o_222 = VppGbpSubnet(
3882 self, rd1, "10.222.0.0", 24,
3883 VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT,
3884 sclass=4222)
3885 l3o_222.add_vpp_config()
3886
3887 #
3888 # ping between hosts in local and remote external subnets
3889 # dropped without a contract
3890 #
3891 p = (Ether(src=eep1.mac, dst=str(self.router_mac)) /
3892 Dot1Q(vlan=100) /
3893 IP(src="10.220.0.1", dst="10.222.0.1") /
3894 UDP(sport=1234, dport=1234) /
3895 Raw('\xa5' * 100))
3896
3897 rxs = self.send_and_assert_no_replies(self.pg0, p * 1)
3898
3899 #
3900 # Add contracts ext-nets for 220 -> 222
3901 #
3902 c4 = VppGbpContract(
3903 self, 4220, 4222, acl_index,
3904 [VppGbpContractRule(
3905 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
3906 []),
Filip Vargaf4749ca2019-04-25 14:55:32 +02003907 VppGbpContractRule(
3908 VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT,
3909 [])],
Neale Ranns4dd4cf42019-03-27 05:06:47 -07003910 [ETH_P_IP, ETH_P_IPV6])
3911 c4.add_vpp_config()
3912
3913 #
3914 # ping from host in local to remote external subnets
3915 #
3916 p = (Ether(src=eep1.mac, dst=str(self.router_mac)) /
3917 Dot1Q(vlan=100) /
3918 IP(src="10.220.0.1", dst="10.222.0.1") /
3919 UDP(sport=1234, dport=1234) /
3920 Raw('\xa5' * 100))
3921
3922 rxs = self.send_and_expect(self.pg0, p * 3, self.pg7)
3923
3924 for rx in rxs:
3925 self.assertEqual(rx[Ether].src, self.pg7.local_mac)
3926 self.assertEqual(rx[Ether].dst, self.pg7.remote_mac)
3927 self.assertEqual(rx[IP].src, self.pg7.local_ip4)
3928 self.assertEqual(rx[IP].dst, self.pg7.remote_ip4)
3929 self.assertEqual(rx[VXLAN].vni, 445)
3930 self.assertTrue(rx[VXLAN].flags.G)
3931 self.assertTrue(rx[VXLAN].flags.Instance)
3932 # the sclass of the ext-net the packet came from
3933 self.assertEqual(rx[VXLAN].gpid, 4220)
3934 # policy was applied to the original IP packet
3935 self.assertTrue(rx[VXLAN].gpflags.A)
3936 # since it's an external host the reciever should not learn it
3937 self.assertTrue(rx[VXLAN].gpflags.D)
3938 inner = rx[VXLAN].payload
3939 self.assertEqual(inner[Ether].dst, "00:0c:0c:0c:0c:0c")
3940 self.assertEqual(inner[IP].src, "10.220.0.1")
3941 self.assertEqual(inner[IP].dst, "10.222.0.1")
3942
3943 #
3944 # ping from host in remote to local external subnets
3945 # there's no contract for this, but the A bit is set.
3946 #
3947 p = (Ether(src=self.pg7.remote_mac, dst=self.pg7.local_mac) /
3948 IP(src=self.pg7.remote_ip4, dst=self.pg7.local_ip4) /
3949 UDP(sport=1234, dport=48879) /
3950 VXLAN(vni=445, gpid=4222, flags=0x88, gpflags='A') /
3951 Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) /
3952 IP(src="10.222.0.1", dst="10.220.0.1") /
3953 UDP(sport=1234, dport=1234) /
3954 Raw('\xa5' * 100))
3955
3956 rxs = self.send_and_expect(self.pg7, p * 3, self.pg0)
3957 self.assertFalse(find_gbp_endpoint(self, ip="10.222.0.1"))
Neale Ranns36abbf12019-03-12 02:34:07 -07003958
3959 #
Neale Ranns2b600182019-03-29 05:08:27 -07003960 # ping from host in remote to remote external subnets
3961 # this is dropped by reflection check.
3962 #
3963 p = (Ether(src=self.pg7.remote_mac, dst=self.pg7.local_mac) /
3964 IP(src=self.pg7.remote_ip4, dst=self.pg7.local_ip4) /
3965 UDP(sport=1234, dport=48879) /
3966 VXLAN(vni=445, gpid=4222, flags=0x88, gpflags='A') /
3967 Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) /
3968 IP(src="10.222.0.1", dst="10.222.0.2") /
3969 UDP(sport=1234, dport=1234) /
3970 Raw('\xa5' * 100))
3971
3972 rxs = self.send_and_assert_no_replies(self.pg7, p * 3)
3973
3974 #
Neale Rannsb6a47952018-11-21 05:44:35 -08003975 # cleanup
3976 #
3977 self.pg7.unconfig_ip4()
Neale Ranns36abbf12019-03-12 02:34:07 -07003978 vlan_100.set_vtr(L2_VTR_OP.L2_DISABLED)
Neale Rannsb6a47952018-11-21 05:44:35 -08003979
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003980
3981if __name__ == '__main__':
3982 unittest.main(testRunner=VppTestRunner)