Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 2 | import typing |
| 3 | from socket import AF_INET6, inet_pton, inet_ntop |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 4 | import unittest |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 5 | from ipaddress import ip_address, IPv4Network, IPv6Network |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 6 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 7 | from scapy.packet import Raw |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 8 | from scapy.layers.l2 import Ether, ARP, Dot1Q |
Neale Ranns | 36abbf1 | 2019-03-12 02:34:07 -0700 | [diff] [blame] | 9 | from scapy.layers.inet import IP, UDP, ICMP |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 10 | from scapy.layers.inet6 import ( |
| 11 | IPv6, |
| 12 | ICMPv6ND_NS, |
| 13 | ICMPv6NDOptSrcLLAddr, |
| 14 | ICMPv6ND_NA, |
| 15 | ICMPv6EchoRequest, |
| 16 | ) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 17 | from scapy.utils6 import in6_getnsma, in6_getnsmac |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 18 | from scapy.layers.vxlan import VXLAN |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 19 | from scapy.data import ETH_P_IP, ETH_P_IPV6 |
Paul Vinciguerra | a279d9c | 2019-02-28 09:00:09 -0800 | [diff] [blame] | 20 | |
Andrew Yourtchenko | 8dc0d48 | 2021-01-29 13:17:19 +0000 | [diff] [blame] | 21 | from framework import tag_fixme_vpp_workers |
Paul Vinciguerra | a279d9c | 2019-02-28 09:00:09 -0800 | [diff] [blame] | 22 | from framework import VppTestCase, VppTestRunner |
| 23 | from vpp_object import VppObject |
| 24 | from vpp_interface import VppInterface |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 25 | from vpp_ip_route import ( |
| 26 | VppIpRoute, |
| 27 | VppRoutePath, |
| 28 | VppIpTable, |
| 29 | VppIpInterfaceAddress, |
| 30 | VppIpInterfaceBind, |
| 31 | find_route, |
| 32 | FibPathProto, |
| 33 | FibPathType, |
| 34 | ) |
| 35 | from vpp_l2 import ( |
| 36 | VppBridgeDomain, |
| 37 | VppBridgeDomainPort, |
| 38 | VppBridgeDomainArpEntry, |
| 39 | VppL2FibEntry, |
| 40 | find_bridge_domain_port, |
| 41 | VppL2Vtr, |
| 42 | ) |
Paul Vinciguerra | 95c0ca4 | 2019-03-28 13:07:00 -0700 | [diff] [blame] | 43 | from vpp_sub_interface import L2_VTR_OP, VppDot1QSubint |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 44 | from vpp_ip import DpoProto, get_dpo_proto |
Paul Vinciguerra | a279d9c | 2019-02-28 09:00:09 -0800 | [diff] [blame] | 45 | from vpp_papi import VppEnum, MACAddress |
Paul Vinciguerra | a279d9c | 2019-02-28 09:00:09 -0800 | [diff] [blame] | 46 | from vpp_vxlan_gbp_tunnel import find_vxlan_gbp_tunnel, INDEX_INVALID, \ |
| 47 | VppVxlanGbpTunnel |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 48 | from vpp_neighbor import VppNeighbor |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 49 | from vpp_acl import AclRule, VppAcl |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 50 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 51 | NUM_PKTS = 67 |
| 52 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 53 | |
Neale Ranns | 6d1ba56 | 2019-07-10 01:14:58 -0700 | [diff] [blame] | 54 | def find_gbp_endpoint(test, sw_if_index=None, ip=None, mac=None, |
Benoît Ganne | 040d47c | 2020-04-16 16:57:00 +0200 | [diff] [blame] | 55 | tep=None, sclass=None, flags=None): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 56 | if ip: |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 57 | vip = ip |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 58 | if mac: |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 59 | vmac = MACAddress(mac) |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 60 | |
| 61 | eps = test.vapi.gbp_endpoint_dump() |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 62 | |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 63 | for ep in eps: |
Neale Ranns | 3eea9de | 2019-06-21 02:09:25 -0700 | [diff] [blame] | 64 | if tep: |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 65 | src = tep[0] |
| 66 | dst = tep[1] |
| 67 | if src != str(ep.endpoint.tun.src) or \ |
| 68 | dst != str(ep.endpoint.tun.dst): |
Neale Ranns | 3eea9de | 2019-06-21 02:09:25 -0700 | [diff] [blame] | 69 | continue |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 70 | if sw_if_index: |
| 71 | if ep.endpoint.sw_if_index != sw_if_index: |
| 72 | continue |
Neale Ranns | 6d1ba56 | 2019-07-10 01:14:58 -0700 | [diff] [blame] | 73 | if sclass: |
| 74 | if ep.endpoint.sclass != sclass: |
| 75 | continue |
Benoît Ganne | 040d47c | 2020-04-16 16:57:00 +0200 | [diff] [blame] | 76 | if flags: |
| 77 | if flags != (flags & ep.endpoint.flags): |
| 78 | continue |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 79 | if ip: |
| 80 | for eip in ep.endpoint.ips: |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 81 | if vip == str(eip): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 82 | return True |
| 83 | if mac: |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 84 | if vmac == ep.endpoint.mac: |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 85 | return True |
Neale Ranns | 3eea9de | 2019-06-21 02:09:25 -0700 | [diff] [blame] | 86 | |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 87 | return False |
| 88 | |
| 89 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 90 | def find_gbp_vxlan(test: VppTestCase, vni): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 91 | ts = test.vapi.gbp_vxlan_tunnel_dump() |
| 92 | for t in ts: |
| 93 | if t.tunnel.vni == vni: |
| 94 | return True |
| 95 | return False |
| 96 | |
| 97 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 98 | class VppGbpEndpoint(VppObject): |
| 99 | """ |
Mohsin Kazmi | 22b3b84 | 2018-04-17 19:35:42 +0200 | [diff] [blame] | 100 | GBP Endpoint |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 101 | """ |
| 102 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 103 | @property |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 104 | def mac(self): |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 105 | return str(self.vmac) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 106 | |
| 107 | @property |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 108 | def ip4(self): |
| 109 | return self._ip4 |
| 110 | |
| 111 | @property |
| 112 | def fip4(self): |
| 113 | return self._fip4 |
| 114 | |
| 115 | @property |
| 116 | def ip6(self): |
| 117 | return self._ip6 |
| 118 | |
| 119 | @property |
| 120 | def fip6(self): |
| 121 | return self._fip6 |
| 122 | |
| 123 | @property |
| 124 | def ips(self): |
| 125 | return [self.ip4, self.ip6] |
| 126 | |
| 127 | @property |
| 128 | def fips(self): |
| 129 | return [self.fip4, self.fip6] |
| 130 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 131 | def __init__(self, test, itf, epg, recirc, ip4, fip4, ip6, fip6, |
| 132 | flags=0, |
| 133 | tun_src="0.0.0.0", |
| 134 | tun_dst="0.0.0.0", |
| 135 | mac=True): |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 136 | self._test = test |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 137 | self.itf = itf |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 138 | self.handle = None |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 139 | self.epg = epg |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 140 | self.recirc = recirc |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 141 | |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 142 | self._ip4 = ip4 |
| 143 | self._fip4 = fip4 |
| 144 | self._ip6 = ip6 |
| 145 | self._fip6 = fip6 |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 146 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 147 | if mac: |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 148 | self.vmac = MACAddress(self.itf.remote_mac) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 149 | else: |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 150 | self.vmac = MACAddress("00:00:00:00:00:00") |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 151 | |
| 152 | self.flags = flags |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 153 | self.tun_src = tun_src |
| 154 | self.tun_dst = tun_dst |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 155 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 156 | def encode(self): |
| 157 | ips = [self.ip4, self.ip6] |
| 158 | return { |
| 159 | "sw_if_index": self.itf.sw_if_index, |
| 160 | "ips": ips, |
| 161 | "n_ips": len(ips), |
| 162 | "mac": self.vmac.packed, |
| 163 | "sclass": self.epg.sclass, |
| 164 | "flags": self.flags, |
| 165 | "tun": { |
| 166 | "src": self.tun_src, |
| 167 | "dst": self.tun_dst, |
| 168 | }, |
| 169 | } |
| 170 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 171 | def add_vpp_config(self): |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 172 | res = self._test.vapi.gbp_endpoint_add( |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 173 | endpoint=self.encode(), |
| 174 | ) |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 175 | self.handle = res.handle |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 176 | self._test.registry.register(self, self._test.logger) |
| 177 | |
| 178 | def remove_vpp_config(self): |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 179 | self._test.vapi.gbp_endpoint_del(handle=self.handle) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 180 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 181 | def object_id(self): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 182 | return "gbp-endpoint:[%d==%d:%s:%d]" % (self.handle, |
| 183 | self.itf.sw_if_index, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 184 | self.ip4, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 185 | self.epg.sclass) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 186 | |
| 187 | def query_vpp_config(self): |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 188 | return find_gbp_endpoint(self._test, |
| 189 | self.itf.sw_if_index, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 190 | self.ip4) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 191 | |
| 192 | |
| 193 | class VppGbpRecirc(VppObject): |
| 194 | """ |
Mohsin Kazmi | 22b3b84 | 2018-04-17 19:35:42 +0200 | [diff] [blame] | 195 | GBP Recirculation Interface |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 196 | """ |
| 197 | |
| 198 | def __init__(self, test, epg, recirc, is_ext=False): |
| 199 | self._test = test |
| 200 | self.recirc = recirc |
| 201 | self.epg = epg |
| 202 | self.is_ext = is_ext |
| 203 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 204 | def encode(self): |
| 205 | return { |
| 206 | "is_ext": self.is_ext, |
| 207 | "sw_if_index": self.recirc.sw_if_index, |
| 208 | "sclass": self.epg.sclass, |
| 209 | } |
| 210 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 211 | def add_vpp_config(self): |
| 212 | self._test.vapi.gbp_recirc_add_del( |
| 213 | 1, |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 214 | recirc=self.encode(), |
| 215 | ) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 216 | self._test.registry.register(self, self._test.logger) |
| 217 | |
| 218 | def remove_vpp_config(self): |
| 219 | self._test.vapi.gbp_recirc_add_del( |
| 220 | 0, |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 221 | recirc=self.encode(), |
| 222 | ) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 223 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 224 | def object_id(self): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 225 | return "gbp-recirc:[%d]" % (self.recirc.sw_if_index) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 226 | |
| 227 | def query_vpp_config(self): |
| 228 | rs = self._test.vapi.gbp_recirc_dump() |
| 229 | for r in rs: |
| 230 | if r.recirc.sw_if_index == self.recirc.sw_if_index: |
| 231 | return True |
| 232 | return False |
| 233 | |
| 234 | |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 235 | class VppGbpExtItf(VppObject): |
| 236 | """ |
| 237 | GBP ExtItfulation Interface |
| 238 | """ |
| 239 | |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 240 | def __init__(self, test, itf, bd, rd, anon=False): |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 241 | self._test = test |
| 242 | self.itf = itf |
| 243 | self.bd = bd |
| 244 | self.rd = rd |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 245 | self.flags = 1 if anon else 0 |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 246 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 247 | def encode(self): |
| 248 | return { |
| 249 | "sw_if_index": self.itf.sw_if_index, |
| 250 | "bd_id": self.bd.bd_id, |
| 251 | "rd_id": self.rd.rd_id, |
| 252 | "flags": self.flags, |
| 253 | } |
| 254 | |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 255 | def add_vpp_config(self): |
| 256 | self._test.vapi.gbp_ext_itf_add_del( |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 257 | 1, |
| 258 | ext_itf=self.encode(), |
| 259 | ) |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 260 | self._test.registry.register(self, self._test.logger) |
| 261 | |
| 262 | def remove_vpp_config(self): |
| 263 | self._test.vapi.gbp_ext_itf_add_del( |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 264 | 0, |
| 265 | ext_itf=self.encode(), |
| 266 | ) |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 267 | |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 268 | def object_id(self): |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 269 | return "gbp-ext-itf:[%d]%s" % (self.itf.sw_if_index, |
| 270 | " [anon]" if self.flags else "") |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 271 | |
| 272 | def query_vpp_config(self): |
| 273 | rs = self._test.vapi.gbp_ext_itf_dump() |
| 274 | for r in rs: |
| 275 | if r.ext_itf.sw_if_index == self.itf.sw_if_index: |
| 276 | return True |
| 277 | return False |
| 278 | |
| 279 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 280 | class VppGbpSubnet(VppObject): |
| 281 | """ |
Mohsin Kazmi | 22b3b84 | 2018-04-17 19:35:42 +0200 | [diff] [blame] | 282 | GBP Subnet |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 283 | """ |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 284 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 285 | def __init__(self, test, rd, address, address_len, |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 286 | type, sw_if_index=0xffffffff, sclass=0xffff): |
| 287 | # TODO: replace hardcoded defaults when vpp_papi supports |
| 288 | # defaults in typedefs |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 289 | self._test = test |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 290 | self.rd_id = rd.rd_id |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 291 | a = ip_address(address) |
| 292 | if 4 == a.version: |
| 293 | self.prefix = IPv4Network("%s/%d" % (address, address_len), |
| 294 | strict=False) |
| 295 | else: |
| 296 | self.prefix = IPv6Network("%s/%d" % (address, address_len), |
| 297 | strict=False) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 298 | self.type = type |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 299 | self.sw_if_index = sw_if_index |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 300 | self.sclass = sclass |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 301 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 302 | def encode(self): |
| 303 | return { |
| 304 | "type": self.type, |
| 305 | "sw_if_index": self.sw_if_index, |
| 306 | "sclass": self.sclass, |
| 307 | "prefix": self.prefix, |
| 308 | "rd_id": self.rd_id, |
| 309 | } |
| 310 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 311 | def add_vpp_config(self): |
| 312 | self._test.vapi.gbp_subnet_add_del( |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 313 | is_add=1, |
| 314 | subnet=self.encode(), |
| 315 | ) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 316 | self._test.registry.register(self, self._test.logger) |
| 317 | |
| 318 | def remove_vpp_config(self): |
| 319 | self._test.vapi.gbp_subnet_add_del( |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 320 | is_add=0, |
| 321 | subnet=self.encode() |
| 322 | ) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 323 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 324 | def object_id(self): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 325 | return "gbp-subnet:[%d-%s]" % (self.rd_id, self.prefix) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 326 | |
| 327 | def query_vpp_config(self): |
| 328 | ss = self._test.vapi.gbp_subnet_dump() |
| 329 | for s in ss: |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 330 | if s.subnet.rd_id == self.rd_id and \ |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 331 | s.subnet.type == self.type and \ |
| 332 | s.subnet.prefix == self.prefix: |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 333 | return True |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 334 | return False |
| 335 | |
| 336 | |
Neale Ranns | 32f6d8e | 2019-03-05 04:22:08 -0800 | [diff] [blame] | 337 | class VppGbpEndpointRetention(object): |
| 338 | def __init__(self, remote_ep_timeout=0xffffffff): |
| 339 | self.remote_ep_timeout = remote_ep_timeout |
| 340 | |
| 341 | def encode(self): |
| 342 | return {'remote_ep_timeout': self.remote_ep_timeout} |
| 343 | |
| 344 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 345 | class VppGbpEndpointGroup(VppObject): |
| 346 | """ |
Mohsin Kazmi | 22b3b84 | 2018-04-17 19:35:42 +0200 | [diff] [blame] | 347 | GBP Endpoint Group |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 348 | """ |
| 349 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 350 | def __init__(self, test, vnid, sclass, rd, bd, uplink, |
Neale Ranns | 32f6d8e | 2019-03-05 04:22:08 -0800 | [diff] [blame] | 351 | bvi, bvi_ip4, bvi_ip6=None, |
| 352 | retention=VppGbpEndpointRetention()): |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 353 | self._test = test |
| 354 | self.uplink = uplink |
| 355 | self.bvi = bvi |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 356 | self.bvi_ip4 = bvi_ip4 |
| 357 | self.bvi_ip6 = bvi_ip6 |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 358 | self.vnid = vnid |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 359 | self.bd = bd # VppGbpBridgeDomain |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 360 | self.rd = rd |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 361 | self.sclass = sclass |
| 362 | if 0 == self.sclass: |
| 363 | self.sclass = 0xffff |
Neale Ranns | 32f6d8e | 2019-03-05 04:22:08 -0800 | [diff] [blame] | 364 | self.retention = retention |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 365 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 366 | def encode(self) -> dict: |
| 367 | return { |
| 368 | "uplink_sw_if_index": self.uplink.sw_if_index |
| 369 | if self.uplink else INDEX_INVALID, |
| 370 | "bd_id": self.bd.bd.bd_id, |
| 371 | "rd_id": self.rd.rd_id, |
| 372 | "vnid": self.vnid, |
| 373 | "sclass": self.sclass, |
| 374 | "retention": self.retention.encode(), |
| 375 | } |
| 376 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 377 | def add_vpp_config(self): |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 378 | self._test.vapi.gbp_endpoint_group_add(epg=self.encode()) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 379 | self._test.registry.register(self, self._test.logger) |
| 380 | |
| 381 | def remove_vpp_config(self): |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 382 | self._test.vapi.gbp_endpoint_group_del(sclass=self.sclass) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 383 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 384 | def object_id(self) -> str: |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 385 | return "gbp-endpoint-group:[%d]" % (self.vnid) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 386 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 387 | def query_vpp_config(self) -> bool: |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 388 | epgs = self._test.vapi.gbp_endpoint_group_dump() |
| 389 | for epg in epgs: |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 390 | if epg.epg.vnid == self.vnid: |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 391 | return True |
| 392 | return False |
| 393 | |
| 394 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 395 | class VppGbpBridgeDomain(VppObject): |
| 396 | """ |
| 397 | GBP Bridge Domain |
| 398 | """ |
| 399 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 400 | def __init__(self, test, bd, rd, bvi, |
| 401 | uu_fwd: typing.Optional[VppVxlanGbpTunnel] = None, |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 402 | bm_flood=None, learn=True, |
| 403 | uu_drop=False, bm_drop=False, |
| 404 | ucast_arp=False): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 405 | self._test = test |
| 406 | self.bvi = bvi |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 407 | self.uu_fwd = uu_fwd |
| 408 | self.bm_flood = bm_flood |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 409 | self.bd = bd |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 410 | self.rd = rd |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 411 | |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 412 | e = VppEnum.vl_api_gbp_bridge_domain_flags_t |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 413 | |
| 414 | self.flags = e.GBP_BD_API_FLAG_NONE |
| 415 | if not learn: |
| 416 | self.flags |= e.GBP_BD_API_FLAG_DO_NOT_LEARN |
| 417 | if uu_drop: |
| 418 | self.flags |= e.GBP_BD_API_FLAG_UU_FWD_DROP |
| 419 | if bm_drop: |
| 420 | self.flags |= e.GBP_BD_API_FLAG_MCAST_DROP |
| 421 | if ucast_arp: |
| 422 | self.flags |= e.GBP_BD_API_FLAG_UCAST_ARP |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 423 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 424 | def encode(self) -> dict: |
| 425 | return { |
| 426 | "flags": self.flags, |
| 427 | "bvi_sw_if_index": self.bvi.sw_if_index, |
| 428 | "uu_fwd_sw_if_index": self.uu_fwd.sw_if_index |
| 429 | if self.uu_fwd else INDEX_INVALID, |
| 430 | "bm_flood_sw_if_index": self.bm_flood.sw_if_index |
| 431 | if self.bm_flood else INDEX_INVALID, |
| 432 | "bd_id": self.bd.bd_id, |
| 433 | "rd_id": self.rd.rd_id, |
| 434 | } |
| 435 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 436 | def add_vpp_config(self): |
| 437 | self._test.vapi.gbp_bridge_domain_add( |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 438 | bd=self.encode(), |
| 439 | ) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 440 | self._test.registry.register(self, self._test.logger) |
| 441 | |
| 442 | def remove_vpp_config(self): |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 443 | self._test.vapi.gbp_bridge_domain_del(bd_id=self.bd.bd_id) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 444 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 445 | def object_id(self) -> str: |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 446 | return "gbp-bridge-domain:[%d]" % (self.bd.bd_id) |
| 447 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 448 | def query_vpp_config(self) -> bool: |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 449 | bds = self._test.vapi.gbp_bridge_domain_dump() |
| 450 | for bd in bds: |
| 451 | if bd.bd.bd_id == self.bd.bd_id: |
| 452 | return True |
| 453 | return False |
| 454 | |
| 455 | |
| 456 | class VppGbpRouteDomain(VppObject): |
| 457 | """ |
| 458 | GBP Route Domain |
| 459 | """ |
| 460 | |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 461 | def __init__(self, test, rd_id, scope, t4, t6, ip4_uu=None, ip6_uu=None): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 462 | self._test = test |
| 463 | self.rd_id = rd_id |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 464 | self.scope = scope |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 465 | self.t4 = t4 |
| 466 | self.t6 = t6 |
| 467 | self.ip4_uu = ip4_uu |
| 468 | self.ip6_uu = ip6_uu |
| 469 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 470 | def encode(self) -> dict: |
| 471 | return { |
| 472 | "rd_id": self.rd_id, |
| 473 | "scope": self.scope, |
| 474 | "ip4_table_id": self.t4.table_id, |
| 475 | "ip6_table_id": self.t6.table_id, |
| 476 | "ip4_uu_sw_if_index": self.ip4_uu.sw_if_index |
| 477 | if self.ip4_uu else INDEX_INVALID, |
| 478 | "ip6_uu_sw_if_index": self.ip6_uu.sw_if_index |
| 479 | if self.ip6_uu else INDEX_INVALID, |
| 480 | |
| 481 | } |
| 482 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 483 | def add_vpp_config(self): |
| 484 | self._test.vapi.gbp_route_domain_add( |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 485 | rd=self.encode(), |
| 486 | ) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 487 | self._test.registry.register(self, self._test.logger) |
| 488 | |
| 489 | def remove_vpp_config(self): |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 490 | self._test.vapi.gbp_route_domain_del(rd_id=self.rd_id) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 491 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 492 | def object_id(self): |
| 493 | return "gbp-route-domain:[%d]" % (self.rd_id) |
| 494 | |
| 495 | def query_vpp_config(self): |
| 496 | rds = self._test.vapi.gbp_route_domain_dump() |
| 497 | for rd in rds: |
| 498 | if rd.rd.rd_id == self.rd_id: |
| 499 | return True |
| 500 | return False |
| 501 | |
| 502 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 503 | class VppGbpContractNextHop: |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 504 | def __init__(self, mac, bd, ip, rd): |
| 505 | self.mac = mac |
| 506 | self.ip = ip |
| 507 | self.bd = bd |
| 508 | self.rd = rd |
| 509 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 510 | def encode(self) -> dict: |
| 511 | return { |
| 512 | "ip": self.ip, |
| 513 | "mac": self.mac.packed, |
| 514 | "bd_id": self.bd.bd.bd_id, |
| 515 | "rd_id": self.rd.rd_id, |
| 516 | } |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 517 | |
| 518 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 519 | class VppGbpContractRule: |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 520 | def __init__(self, action, hash_mode, nhs=None): |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 521 | self.action = action |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 522 | self.hash_mode = hash_mode |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 523 | self.nhs = [] if nhs is None else nhs |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 524 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 525 | def encode(self) -> dict: |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 526 | nhs = [] |
| 527 | for nh in self.nhs: |
| 528 | nhs.append(nh.encode()) |
| 529 | while len(nhs) < 8: |
| 530 | nhs.append({}) |
| 531 | return {'action': self.action, |
| 532 | 'nh_set': { |
| 533 | 'hash_mode': self.hash_mode, |
| 534 | 'n_nhs': len(self.nhs), |
| 535 | 'nhs': nhs}} |
| 536 | |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 537 | def __repr__(self): |
| 538 | return '<VppGbpContractRule action=%s, hash_mode=%s>' % ( |
| 539 | self.action, self.hash_mode) |
| 540 | |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 541 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 542 | class VppGbpContract(VppObject): |
| 543 | """ |
Mohsin Kazmi | 22b3b84 | 2018-04-17 19:35:42 +0200 | [diff] [blame] | 544 | GBP Contract |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 545 | """ |
| 546 | |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 547 | def __init__(self, test, scope, sclass, dclass, acl_index, |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 548 | rules: list, allowed_ethertypes: list): |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 549 | self._test = test |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 550 | self.scope = scope |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 551 | self.acl_index = acl_index |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 552 | self.sclass = sclass |
| 553 | self.dclass = dclass |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 554 | self.rules = rules |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 555 | self.allowed_ethertypes = allowed_ethertypes |
Neale Ranns | fa0ac2c | 2019-03-12 04:34:53 -0700 | [diff] [blame] | 556 | while (len(self.allowed_ethertypes) < 16): |
| 557 | self.allowed_ethertypes.append(0) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 558 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 559 | def encode(self) -> dict: |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 560 | rules = [] |
| 561 | for r in self.rules: |
| 562 | rules.append(r.encode()) |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 563 | return { |
| 564 | 'acl_index': self.acl_index, |
| 565 | 'scope': self.scope, |
| 566 | 'sclass': self.sclass, |
| 567 | 'dclass': self.dclass, |
| 568 | 'n_rules': len(rules), |
| 569 | 'rules': rules, |
| 570 | 'n_ether_types': len(self.allowed_ethertypes), |
| 571 | 'allowed_ethertypes': self.allowed_ethertypes, |
| 572 | } |
| 573 | |
| 574 | def add_vpp_config(self): |
Neale Ranns | 796c84b | 2019-03-28 07:56:23 -0700 | [diff] [blame] | 575 | r = self._test.vapi.gbp_contract_add_del( |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 576 | is_add=1, |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 577 | contract=self.encode() |
| 578 | ) |
| 579 | |
Neale Ranns | 796c84b | 2019-03-28 07:56:23 -0700 | [diff] [blame] | 580 | self.stats_index = r.stats_index |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 581 | self._test.registry.register(self, self._test.logger) |
| 582 | |
| 583 | def remove_vpp_config(self): |
| 584 | self._test.vapi.gbp_contract_add_del( |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 585 | is_add=0, |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 586 | contract=self.encode(), |
| 587 | ) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 588 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 589 | def object_id(self): |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 590 | return "gbp-contract:[%d:%d:%d:%d]" % (self.scope, |
| 591 | self.sclass, |
| 592 | self.dclass, |
| 593 | self.acl_index) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 594 | |
| 595 | def query_vpp_config(self): |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 596 | cs = self._test.vapi.gbp_contract_dump() |
| 597 | for c in cs: |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 598 | if c.contract.scope == self.scope \ |
| 599 | and c.contract.sclass == self.sclass \ |
| 600 | and c.contract.dclass == self.dclass: |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 601 | return True |
| 602 | return False |
| 603 | |
Neale Ranns | 796c84b | 2019-03-28 07:56:23 -0700 | [diff] [blame] | 604 | def get_drop_stats(self): |
| 605 | c = self._test.statistics.get_counter("/net/gbp/contract/drop") |
| 606 | return c[0][self.stats_index] |
| 607 | |
| 608 | def get_permit_stats(self): |
| 609 | c = self._test.statistics.get_counter("/net/gbp/contract/permit") |
| 610 | return c[0][self.stats_index] |
| 611 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 612 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 613 | class VppGbpVxlanTunnel(VppInterface): |
| 614 | """ |
| 615 | GBP VXLAN tunnel |
| 616 | """ |
| 617 | |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 618 | def __init__(self, test, vni, bd_rd_id, mode, src): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 619 | super(VppGbpVxlanTunnel, self).__init__(test) |
| 620 | self._test = test |
| 621 | self.vni = vni |
| 622 | self.bd_rd_id = bd_rd_id |
| 623 | self.mode = mode |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 624 | self.src = src |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 625 | |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 626 | def encode(self) -> dict: |
| 627 | return { |
| 628 | "vni": self.vni, |
| 629 | "mode": self.mode, |
| 630 | "bd_rd_id": self.bd_rd_id, |
| 631 | "src": self.src, |
| 632 | } |
| 633 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 634 | def add_vpp_config(self): |
| 635 | r = self._test.vapi.gbp_vxlan_tunnel_add( |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 636 | tunnel=self.encode(), |
| 637 | ) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 638 | self.set_sw_if_index(r.sw_if_index) |
| 639 | self._test.registry.register(self, self._test.logger) |
| 640 | |
| 641 | def remove_vpp_config(self): |
Paul Vinciguerra | dc22c83 | 2021-04-25 21:50:38 -0400 | [diff] [blame] | 642 | self._test.vapi.gbp_vxlan_tunnel_del(vni=self.vni) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 643 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 644 | def object_id(self): |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 645 | return "gbp-vxlan:%d" % (self.sw_if_index) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 646 | |
| 647 | def query_vpp_config(self): |
| 648 | return find_gbp_vxlan(self._test, self.vni) |
| 649 | |
| 650 | |
Andrew Yourtchenko | 8dc0d48 | 2021-01-29 13:17:19 +0000 | [diff] [blame] | 651 | @tag_fixme_vpp_workers |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 652 | class TestGBP(VppTestCase): |
| 653 | """ GBP Test Case """ |
| 654 | |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 655 | @property |
Filip Varga | 5f4f208 | 2020-09-30 22:24:47 +0200 | [diff] [blame] | 656 | def nat_config_flags(self): |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 657 | return VppEnum.vl_api_nat_config_flags_t |
| 658 | |
Filip Varga | 5f4f208 | 2020-09-30 22:24:47 +0200 | [diff] [blame] | 659 | @property |
| 660 | def nat44_config_flags(self): |
| 661 | return VppEnum.vl_api_nat44_config_flags_t |
| 662 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 663 | @classmethod |
| 664 | def setUpClass(cls): |
| 665 | super(TestGBP, cls).setUpClass() |
| 666 | |
| 667 | @classmethod |
| 668 | def tearDownClass(cls): |
| 669 | super(TestGBP, cls).tearDownClass() |
| 670 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 671 | def setUp(self): |
| 672 | super(TestGBP, self).setUp() |
| 673 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 674 | self.create_pg_interfaces(range(9)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 675 | self.create_loopback_interfaces(8) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 676 | |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 677 | self.router_mac = MACAddress("00:11:22:33:44:55") |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 678 | |
| 679 | for i in self.pg_interfaces: |
| 680 | i.admin_up() |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 681 | for i in self.lo_interfaces: |
| 682 | i.admin_up() |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 683 | |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 684 | self.vlan_100 = VppDot1QSubint(self, self.pg0, 100) |
| 685 | self.vlan_100.admin_up() |
| 686 | self.vlan_101 = VppDot1QSubint(self, self.pg0, 101) |
| 687 | self.vlan_101.admin_up() |
| 688 | self.vlan_102 = VppDot1QSubint(self, self.pg0, 102) |
| 689 | self.vlan_102.admin_up() |
| 690 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 691 | def tearDown(self): |
| 692 | for i in self.pg_interfaces: |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 693 | i.admin_down() |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 694 | super(TestGBP, self).tearDown() |
Benoît Ganne | d51880c | 2019-09-03 18:17:38 +0200 | [diff] [blame] | 695 | for i in self.lo_interfaces: |
| 696 | i.remove_vpp_config() |
| 697 | self.lo_interfaces = [] |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 698 | self.vlan_102.remove_vpp_config() |
| 699 | self.vlan_101.remove_vpp_config() |
| 700 | self.vlan_100.remove_vpp_config() |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 701 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 702 | def send_and_expect_bridged(self, src, tx, dst): |
| 703 | rx = self.send_and_expect(src, tx, dst) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 704 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 705 | for r in rx: |
| 706 | self.assertEqual(r[Ether].src, tx[0][Ether].src) |
| 707 | self.assertEqual(r[Ether].dst, tx[0][Ether].dst) |
| 708 | self.assertEqual(r[IP].src, tx[0][IP].src) |
| 709 | self.assertEqual(r[IP].dst, tx[0][IP].dst) |
| 710 | return rx |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 711 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 712 | def send_and_expect_bridged6(self, src, tx, dst): |
| 713 | rx = self.send_and_expect(src, tx, dst) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 714 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 715 | for r in rx: |
| 716 | self.assertEqual(r[Ether].src, tx[0][Ether].src) |
| 717 | self.assertEqual(r[Ether].dst, tx[0][Ether].dst) |
| 718 | self.assertEqual(r[IPv6].src, tx[0][IPv6].src) |
| 719 | self.assertEqual(r[IPv6].dst, tx[0][IPv6].dst) |
| 720 | return rx |
| 721 | |
| 722 | def send_and_expect_routed(self, src, tx, dst, src_mac): |
| 723 | rx = self.send_and_expect(src, tx, dst) |
| 724 | |
| 725 | for r in rx: |
| 726 | self.assertEqual(r[Ether].src, src_mac) |
| 727 | self.assertEqual(r[Ether].dst, dst.remote_mac) |
| 728 | self.assertEqual(r[IP].src, tx[0][IP].src) |
| 729 | self.assertEqual(r[IP].dst, tx[0][IP].dst) |
| 730 | return rx |
| 731 | |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 732 | def send_and_expect_routed6(self, src, tx, dst, src_mac): |
| 733 | rx = self.send_and_expect(src, tx, dst) |
| 734 | |
| 735 | for r in rx: |
| 736 | self.assertEqual(r[Ether].src, src_mac) |
| 737 | self.assertEqual(r[Ether].dst, dst.remote_mac) |
| 738 | self.assertEqual(r[IPv6].src, tx[0][IPv6].src) |
| 739 | self.assertEqual(r[IPv6].dst, tx[0][IPv6].dst) |
| 740 | return rx |
| 741 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 742 | def send_and_expect_natted(self, src, tx, dst, src_ip): |
| 743 | rx = self.send_and_expect(src, tx, dst) |
| 744 | |
| 745 | for r in rx: |
| 746 | self.assertEqual(r[Ether].src, tx[0][Ether].src) |
| 747 | self.assertEqual(r[Ether].dst, tx[0][Ether].dst) |
| 748 | self.assertEqual(r[IP].src, src_ip) |
| 749 | self.assertEqual(r[IP].dst, tx[0][IP].dst) |
| 750 | return rx |
| 751 | |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 752 | def send_and_expect_natted6(self, src, tx, dst, src_ip): |
| 753 | rx = self.send_and_expect(src, tx, dst) |
| 754 | |
| 755 | for r in rx: |
| 756 | self.assertEqual(r[Ether].src, tx[0][Ether].src) |
| 757 | self.assertEqual(r[Ether].dst, tx[0][Ether].dst) |
| 758 | self.assertEqual(r[IPv6].src, src_ip) |
| 759 | self.assertEqual(r[IPv6].dst, tx[0][IPv6].dst) |
| 760 | return rx |
| 761 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 762 | def send_and_expect_unnatted(self, src, tx, dst, dst_ip): |
| 763 | rx = self.send_and_expect(src, tx, dst) |
| 764 | |
| 765 | for r in rx: |
| 766 | self.assertEqual(r[Ether].src, tx[0][Ether].src) |
| 767 | self.assertEqual(r[Ether].dst, tx[0][Ether].dst) |
| 768 | self.assertEqual(r[IP].dst, dst_ip) |
| 769 | self.assertEqual(r[IP].src, tx[0][IP].src) |
| 770 | return rx |
| 771 | |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 772 | def send_and_expect_unnatted6(self, src, tx, dst, dst_ip): |
| 773 | rx = self.send_and_expect(src, tx, dst) |
| 774 | |
| 775 | for r in rx: |
| 776 | self.assertEqual(r[Ether].src, tx[0][Ether].src) |
| 777 | self.assertEqual(r[Ether].dst, tx[0][Ether].dst) |
| 778 | self.assertEqual(r[IPv6].dst, dst_ip) |
| 779 | self.assertEqual(r[IPv6].src, tx[0][IPv6].src) |
| 780 | return rx |
| 781 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 782 | def send_and_expect_double_natted(self, src, tx, dst, src_ip, dst_ip): |
| 783 | rx = self.send_and_expect(src, tx, dst) |
| 784 | |
| 785 | for r in rx: |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 786 | self.assertEqual(r[Ether].src, str(self.router_mac)) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 787 | self.assertEqual(r[Ether].dst, dst.remote_mac) |
| 788 | self.assertEqual(r[IP].dst, dst_ip) |
| 789 | self.assertEqual(r[IP].src, src_ip) |
| 790 | return rx |
| 791 | |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 792 | def send_and_expect_double_natted6(self, src, tx, dst, src_ip, dst_ip): |
| 793 | rx = self.send_and_expect(src, tx, dst) |
| 794 | |
| 795 | for r in rx: |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 796 | self.assertEqual(r[Ether].src, str(self.router_mac)) |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 797 | self.assertEqual(r[Ether].dst, dst.remote_mac) |
| 798 | self.assertEqual(r[IPv6].dst, dst_ip) |
| 799 | self.assertEqual(r[IPv6].src, src_ip) |
| 800 | return rx |
| 801 | |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 802 | def send_and_expect_no_arp(self, src, tx, dst): |
| 803 | self.pg_send(src, tx) |
| 804 | dst.get_capture(0, timeout=1) |
| 805 | dst.assert_nothing_captured(remark="") |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 806 | |
| 807 | def send_and_expect_arp(self, src, tx, dst): |
| 808 | rx = self.send_and_expect(src, tx, dst) |
| 809 | |
| 810 | for r in rx: |
| 811 | self.assertEqual(r[Ether].src, tx[0][Ether].src) |
| 812 | self.assertEqual(r[Ether].dst, tx[0][Ether].dst) |
| 813 | self.assertEqual(r[ARP].psrc, tx[0][ARP].psrc) |
| 814 | self.assertEqual(r[ARP].pdst, tx[0][ARP].pdst) |
| 815 | self.assertEqual(r[ARP].hwsrc, tx[0][ARP].hwsrc) |
| 816 | self.assertEqual(r[ARP].hwdst, tx[0][ARP].hwdst) |
| 817 | return rx |
| 818 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 819 | def test_gbp(self): |
| 820 | """ Group Based Policy """ |
| 821 | |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 822 | ep_flags = VppEnum.vl_api_gbp_endpoint_flags_t |
| 823 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 824 | # |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 825 | # Route Domains |
| 826 | # |
| 827 | gt4 = VppIpTable(self, 0) |
| 828 | gt4.add_vpp_config() |
| 829 | gt6 = VppIpTable(self, 0, is_ip6=True) |
| 830 | gt6.add_vpp_config() |
| 831 | nt4 = VppIpTable(self, 20) |
| 832 | nt4.add_vpp_config() |
| 833 | nt6 = VppIpTable(self, 20, is_ip6=True) |
| 834 | nt6.add_vpp_config() |
| 835 | |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 836 | rd0 = VppGbpRouteDomain(self, 0, 400, gt4, gt6, None, None) |
| 837 | rd20 = VppGbpRouteDomain(self, 20, 420, nt4, nt6, None, None) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 838 | |
| 839 | rd0.add_vpp_config() |
| 840 | rd20.add_vpp_config() |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 841 | |
| 842 | # |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 843 | # Bridge Domains |
| 844 | # |
| 845 | bd1 = VppBridgeDomain(self, 1) |
| 846 | bd2 = VppBridgeDomain(self, 2) |
| 847 | bd20 = VppBridgeDomain(self, 20) |
| 848 | |
| 849 | bd1.add_vpp_config() |
| 850 | bd2.add_vpp_config() |
| 851 | bd20.add_vpp_config() |
| 852 | |
| 853 | gbd1 = VppGbpBridgeDomain(self, bd1, rd0, self.loop0) |
| 854 | gbd2 = VppGbpBridgeDomain(self, bd2, rd0, self.loop1) |
| 855 | gbd20 = VppGbpBridgeDomain(self, bd20, rd20, self.loop2) |
| 856 | |
| 857 | gbd1.add_vpp_config() |
| 858 | gbd2.add_vpp_config() |
| 859 | gbd20.add_vpp_config() |
| 860 | |
| 861 | # |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 862 | # 3 EPGs, 2 of which share a BD. |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 863 | # 2 NAT EPGs, one for floating-IP subnets, the other for internet |
| 864 | # |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 865 | epgs = [VppGbpEndpointGroup(self, 220, 1220, rd0, gbd1, |
| 866 | self.pg4, self.loop0, |
| 867 | "10.0.0.128", "2001:10::128"), |
| 868 | VppGbpEndpointGroup(self, 221, 1221, rd0, gbd1, |
| 869 | self.pg5, self.loop0, |
| 870 | "10.0.1.128", "2001:10:1::128"), |
| 871 | VppGbpEndpointGroup(self, 222, 1222, rd0, gbd2, |
| 872 | self.pg6, self.loop1, |
| 873 | "10.0.2.128", "2001:10:2::128"), |
| 874 | VppGbpEndpointGroup(self, 333, 1333, rd20, gbd20, |
| 875 | self.pg7, self.loop2, |
| 876 | "11.0.0.128", "3001::128"), |
| 877 | VppGbpEndpointGroup(self, 444, 1444, rd20, gbd20, |
| 878 | self.pg8, self.loop2, |
| 879 | "11.0.0.129", "3001::129")] |
| 880 | recircs = [VppGbpRecirc(self, epgs[0], self.loop3), |
| 881 | VppGbpRecirc(self, epgs[1], self.loop4), |
| 882 | VppGbpRecirc(self, epgs[2], self.loop5), |
| 883 | VppGbpRecirc(self, epgs[3], self.loop6, is_ext=True), |
| 884 | VppGbpRecirc(self, epgs[4], self.loop7, is_ext=True)] |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 885 | |
| 886 | epg_nat = epgs[3] |
| 887 | recirc_nat = recircs[3] |
| 888 | |
| 889 | # |
| 890 | # 4 end-points, 2 in the same subnet, 3 in the same BD |
| 891 | # |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 892 | eps = [VppGbpEndpoint(self, self.pg0, |
| 893 | epgs[0], recircs[0], |
| 894 | "10.0.0.1", "11.0.0.1", |
| 895 | "2001:10::1", "3001::1"), |
| 896 | VppGbpEndpoint(self, self.pg1, |
| 897 | epgs[0], recircs[0], |
| 898 | "10.0.0.2", "11.0.0.2", |
| 899 | "2001:10::2", "3001::2"), |
| 900 | VppGbpEndpoint(self, self.pg2, |
| 901 | epgs[1], recircs[1], |
| 902 | "10.0.1.1", "11.0.0.3", |
| 903 | "2001:10:1::1", "3001::3"), |
| 904 | VppGbpEndpoint(self, self.pg3, |
| 905 | epgs[2], recircs[2], |
| 906 | "10.0.2.1", "11.0.0.4", |
| 907 | "2001:10:2::1", "3001::4")] |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 908 | |
Filip Varga | e7a80a9 | 2021-02-26 09:31:21 +0100 | [diff] [blame] | 909 | self.vapi.nat44_ed_plugin_enable_disable(enable=1) |
Filip Varga | ed2ee5e | 2021-03-23 12:57:58 +0100 | [diff] [blame] | 910 | self.vapi.nat66_plugin_enable_disable(enable=1) |
Filip Varga | 5f4f208 | 2020-09-30 22:24:47 +0200 | [diff] [blame] | 911 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 912 | # |
| 913 | # Config related to each of the EPGs |
| 914 | # |
| 915 | for epg in epgs: |
| 916 | # IP config on the BVI interfaces |
| 917 | if epg != epgs[1] and epg != epgs[4]: |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 918 | b4 = VppIpInterfaceBind(self, epg.bvi, |
| 919 | epg.rd.t4).add_vpp_config() |
| 920 | b6 = VppIpInterfaceBind(self, epg.bvi, |
| 921 | epg.rd.t6).add_vpp_config() |
Benoît Ganne | a03d25d | 2019-09-03 17:54:21 +0200 | [diff] [blame] | 922 | epg.bvi.set_mac(self.router_mac) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 923 | |
| 924 | # The BVIs are NAT inside interfaces |
Filip Varga | 5f4f208 | 2020-09-30 22:24:47 +0200 | [diff] [blame] | 925 | flags = self.nat_config_flags.NAT_IS_INSIDE |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 926 | self.vapi.nat44_interface_add_del_feature( |
| 927 | sw_if_index=epg.bvi.sw_if_index, |
| 928 | flags=flags, is_add=1) |
| 929 | self.vapi.nat66_add_del_interface( |
Filip Varga | ed2ee5e | 2021-03-23 12:57:58 +0100 | [diff] [blame] | 930 | sw_if_index=epg.bvi.sw_if_index, |
| 931 | flags=flags, is_add=1) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 932 | |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 933 | if_ip4 = VppIpInterfaceAddress(self, epg.bvi, |
| 934 | epg.bvi_ip4, 32, |
| 935 | bind=b4).add_vpp_config() |
| 936 | if_ip6 = VppIpInterfaceAddress(self, epg.bvi, |
| 937 | epg.bvi_ip6, 128, |
| 938 | bind=b6).add_vpp_config() |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 939 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 940 | # EPG uplink interfaces in the RD |
| 941 | VppIpInterfaceBind(self, epg.uplink, epg.rd.t4).add_vpp_config() |
| 942 | VppIpInterfaceBind(self, epg.uplink, epg.rd.t6).add_vpp_config() |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 943 | |
| 944 | # add the BD ARP termination entry for BVI IP |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 945 | epg.bd_arp_ip4 = VppBridgeDomainArpEntry(self, epg.bd.bd, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 946 | str(self.router_mac), |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 947 | epg.bvi_ip4) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 948 | epg.bd_arp_ip6 = VppBridgeDomainArpEntry(self, epg.bd.bd, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 949 | str(self.router_mac), |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 950 | epg.bvi_ip6) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 951 | epg.bd_arp_ip4.add_vpp_config() |
| 952 | epg.bd_arp_ip6.add_vpp_config() |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 953 | |
| 954 | # EPG in VPP |
| 955 | epg.add_vpp_config() |
| 956 | |
| 957 | for recirc in recircs: |
| 958 | # EPG's ingress recirculation interface maps to its RD |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 959 | VppIpInterfaceBind(self, recirc.recirc, |
| 960 | recirc.epg.rd.t4).add_vpp_config() |
| 961 | VppIpInterfaceBind(self, recirc.recirc, |
| 962 | recirc.epg.rd.t6).add_vpp_config() |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 963 | |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 964 | self.vapi.nat44_interface_add_del_feature( |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 965 | sw_if_index=recirc.recirc.sw_if_index, is_add=1) |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 966 | self.vapi.nat66_add_del_interface( |
Filip Varga | ed2ee5e | 2021-03-23 12:57:58 +0100 | [diff] [blame] | 967 | sw_if_index=recirc.recirc.sw_if_index, is_add=1) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 968 | |
| 969 | recirc.add_vpp_config() |
| 970 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 971 | for recirc in recircs: |
| 972 | self.assertTrue(find_bridge_domain_port(self, |
| 973 | recirc.epg.bd.bd.bd_id, |
| 974 | recirc.recirc.sw_if_index)) |
| 975 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 976 | for ep in eps: |
| 977 | self.pg_enable_capture(self.pg_interfaces) |
| 978 | self.pg_start() |
| 979 | # |
| 980 | # routes to the endpoints. We need these since there are no |
| 981 | # adj-fibs due to the fact the the BVI address has /32 and |
| 982 | # the subnet is not attached. |
| 983 | # |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 984 | for (ip, fip) in zip(ep.ips, ep.fips): |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 985 | # Add static mappings for each EP from the 10/8 to 11/8 network |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 986 | if ip_address(ip).version == 4: |
Filip Varga | 5f4f208 | 2020-09-30 22:24:47 +0200 | [diff] [blame] | 987 | flags = self.nat_config_flags.NAT_IS_ADDR_ONLY |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 988 | self.vapi.nat44_add_del_static_mapping( |
| 989 | is_add=1, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 990 | local_ip_address=ip, |
| 991 | external_ip_address=fip, |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 992 | external_sw_if_index=0xFFFFFFFF, |
| 993 | vrf_id=0, |
| 994 | flags=flags) |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 995 | else: |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 996 | self.vapi.nat66_add_del_static_mapping( |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 997 | local_ip_address=ip, |
| 998 | external_ip_address=fip, |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 999 | vrf_id=0, is_add=1) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1000 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1001 | # VPP EP create ... |
| 1002 | ep.add_vpp_config() |
| 1003 | |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1004 | self.logger.info(self.vapi.cli("sh gbp endpoint")) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1005 | |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1006 | # ... results in a Gratuitous ARP/ND on the EPG's uplink |
| 1007 | rx = ep.epg.uplink.get_capture(len(ep.ips), timeout=0.2) |
| 1008 | |
| 1009 | for ii, ip in enumerate(ep.ips): |
| 1010 | p = rx[ii] |
| 1011 | |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1012 | if ip_address(ip).version == 6: |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1013 | self.assertTrue(p.haslayer(ICMPv6ND_NA)) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1014 | self.assertEqual(p[ICMPv6ND_NA].tgt, ip) |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1015 | else: |
| 1016 | self.assertTrue(p.haslayer(ARP)) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1017 | self.assertEqual(p[ARP].psrc, ip) |
| 1018 | self.assertEqual(p[ARP].pdst, ip) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1019 | |
| 1020 | # add the BD ARP termination entry for floating IP |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1021 | for fip in ep.fips: |
Neale Ranns | bc764c8 | 2019-06-19 07:07:13 -0700 | [diff] [blame] | 1022 | ba = VppBridgeDomainArpEntry(self, epg_nat.bd.bd, ep.mac, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1023 | fip) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1024 | ba.add_vpp_config() |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1025 | |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1026 | # floating IPs route via EPG recirc |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1027 | r = VppIpRoute( |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1028 | self, fip, ip_address(fip).max_prefixlen, |
| 1029 | [VppRoutePath(fip, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1030 | ep.recirc.recirc.sw_if_index, |
| 1031 | type=FibPathType.FIB_PATH_TYPE_DVR, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1032 | proto=get_dpo_proto(fip))], |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1033 | table_id=20) |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1034 | r.add_vpp_config() |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1035 | |
| 1036 | # L2 FIB entries in the NAT EPG BD to bridge the packets from |
| 1037 | # the outside direct to the internal EPG |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1038 | lf = VppL2FibEntry(self, epg_nat.bd.bd, ep.mac, |
| 1039 | ep.recirc.recirc, bvi_mac=0) |
| 1040 | lf.add_vpp_config() |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1041 | |
| 1042 | # |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1043 | # ARP packets for unknown IP are sent to the EPG uplink |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1044 | # |
| 1045 | pkt_arp = (Ether(dst="ff:ff:ff:ff:ff:ff", |
| 1046 | src=self.pg0.remote_mac) / |
| 1047 | ARP(op="who-has", |
| 1048 | hwdst="ff:ff:ff:ff:ff:ff", |
| 1049 | hwsrc=self.pg0.remote_mac, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1050 | pdst="10.0.0.88", |
| 1051 | psrc="10.0.0.99")) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1052 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1053 | self.vapi.cli("clear trace") |
| 1054 | self.pg0.add_stream(pkt_arp) |
| 1055 | |
| 1056 | self.pg_enable_capture(self.pg_interfaces) |
| 1057 | self.pg_start() |
| 1058 | |
| 1059 | rxd = epgs[0].uplink.get_capture(1) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1060 | |
| 1061 | # |
| 1062 | # ARP/ND packets get a response |
| 1063 | # |
| 1064 | pkt_arp = (Ether(dst="ff:ff:ff:ff:ff:ff", |
| 1065 | src=self.pg0.remote_mac) / |
| 1066 | ARP(op="who-has", |
| 1067 | hwdst="ff:ff:ff:ff:ff:ff", |
| 1068 | hwsrc=self.pg0.remote_mac, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1069 | pdst=epgs[0].bvi_ip4, |
| 1070 | psrc=eps[0].ip4)) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1071 | |
| 1072 | self.send_and_expect(self.pg0, [pkt_arp], self.pg0) |
| 1073 | |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1074 | nsma = in6_getnsma(inet_pton(AF_INET6, eps[0].ip6)) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1075 | d = inet_ntop(AF_INET6, nsma) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1076 | pkt_nd = (Ether(dst=in6_getnsmac(nsma), |
| 1077 | src=self.pg0.remote_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1078 | IPv6(dst=d, src=eps[0].ip6) / |
| 1079 | ICMPv6ND_NS(tgt=epgs[0].bvi_ip6) / |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1080 | ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac)) |
| 1081 | self.send_and_expect(self.pg0, [pkt_nd], self.pg0) |
| 1082 | |
| 1083 | # |
| 1084 | # broadcast packets are flooded |
| 1085 | # |
| 1086 | pkt_bcast = (Ether(dst="ff:ff:ff:ff:ff:ff", |
| 1087 | src=self.pg0.remote_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1088 | IP(src=eps[0].ip4, dst="232.1.1.1") / |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1089 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1090 | Raw(b'\xa5' * 100)) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1091 | |
| 1092 | self.vapi.cli("clear trace") |
| 1093 | self.pg0.add_stream(pkt_bcast) |
| 1094 | |
| 1095 | self.pg_enable_capture(self.pg_interfaces) |
| 1096 | self.pg_start() |
| 1097 | |
| 1098 | rxd = eps[1].itf.get_capture(1) |
| 1099 | self.assertEqual(rxd[0][Ether].dst, pkt_bcast[Ether].dst) |
| 1100 | rxd = epgs[0].uplink.get_capture(1) |
| 1101 | self.assertEqual(rxd[0][Ether].dst, pkt_bcast[Ether].dst) |
| 1102 | |
| 1103 | # |
| 1104 | # packets to non-local L3 destinations dropped |
| 1105 | # |
| 1106 | pkt_intra_epg_220_ip4 = (Ether(src=self.pg0.remote_mac, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 1107 | dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1108 | IP(src=eps[0].ip4, |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1109 | dst="10.0.0.99") / |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1110 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1111 | Raw(b'\xa5' * 100)) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1112 | pkt_inter_epg_222_ip4 = (Ether(src=self.pg0.remote_mac, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 1113 | dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1114 | IP(src=eps[0].ip4, |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1115 | dst="10.0.1.99") / |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1116 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1117 | Raw(b'\xa5' * 100)) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1118 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1119 | self.send_and_assert_no_replies(self.pg0, |
| 1120 | pkt_intra_epg_220_ip4 * NUM_PKTS) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1121 | |
| 1122 | pkt_inter_epg_222_ip6 = (Ether(src=self.pg0.remote_mac, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 1123 | dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1124 | IPv6(src=eps[0].ip6, |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1125 | dst="2001:10::99") / |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1126 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1127 | Raw(b'\xa5' * 100)) |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1128 | self.send_and_assert_no_replies(self.pg0, |
| 1129 | pkt_inter_epg_222_ip6 * NUM_PKTS) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1130 | |
| 1131 | # |
| 1132 | # Add the subnet routes |
| 1133 | # |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1134 | s41 = VppGbpSubnet( |
| 1135 | self, rd0, "10.0.0.0", 24, |
| 1136 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_INTERNAL) |
| 1137 | s42 = VppGbpSubnet( |
| 1138 | self, rd0, "10.0.1.0", 24, |
| 1139 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_INTERNAL) |
| 1140 | s43 = VppGbpSubnet( |
| 1141 | self, rd0, "10.0.2.0", 24, |
| 1142 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_INTERNAL) |
| 1143 | s61 = VppGbpSubnet( |
| 1144 | self, rd0, "2001:10::1", 64, |
| 1145 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_INTERNAL) |
| 1146 | s62 = VppGbpSubnet( |
| 1147 | self, rd0, "2001:10:1::1", 64, |
| 1148 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_INTERNAL) |
| 1149 | s63 = VppGbpSubnet( |
| 1150 | self, rd0, "2001:10:2::1", 64, |
| 1151 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_INTERNAL) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1152 | s41.add_vpp_config() |
| 1153 | s42.add_vpp_config() |
| 1154 | s43.add_vpp_config() |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1155 | s61.add_vpp_config() |
| 1156 | s62.add_vpp_config() |
| 1157 | s63.add_vpp_config() |
| 1158 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1159 | self.send_and_expect_bridged(eps[0].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1160 | pkt_intra_epg_220_ip4 * NUM_PKTS, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1161 | eps[0].epg.uplink) |
| 1162 | self.send_and_expect_bridged(eps[0].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1163 | pkt_inter_epg_222_ip4 * NUM_PKTS, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1164 | eps[0].epg.uplink) |
| 1165 | self.send_and_expect_bridged6(eps[0].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1166 | pkt_inter_epg_222_ip6 * NUM_PKTS, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1167 | eps[0].epg.uplink) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1168 | |
| 1169 | self.logger.info(self.vapi.cli("sh ip fib 11.0.0.2")) |
| 1170 | self.logger.info(self.vapi.cli("sh gbp endpoint-group")) |
| 1171 | self.logger.info(self.vapi.cli("sh gbp endpoint")) |
| 1172 | self.logger.info(self.vapi.cli("sh gbp recirc")) |
| 1173 | self.logger.info(self.vapi.cli("sh int")) |
| 1174 | self.logger.info(self.vapi.cli("sh int addr")) |
| 1175 | self.logger.info(self.vapi.cli("sh int feat loop6")) |
| 1176 | self.logger.info(self.vapi.cli("sh vlib graph ip4-gbp-src-classify")) |
| 1177 | self.logger.info(self.vapi.cli("sh int feat loop3")) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1178 | self.logger.info(self.vapi.cli("sh int feat pg0")) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1179 | |
| 1180 | # |
| 1181 | # Packet destined to unknown unicast is sent on the epg uplink ... |
| 1182 | # |
| 1183 | pkt_intra_epg_220_to_uplink = (Ether(src=self.pg0.remote_mac, |
| 1184 | dst="00:00:00:33:44:55") / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1185 | IP(src=eps[0].ip4, |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1186 | dst="10.0.0.99") / |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1187 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1188 | Raw(b'\xa5' * 100)) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1189 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1190 | self.send_and_expect_bridged(eps[0].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1191 | pkt_intra_epg_220_to_uplink * NUM_PKTS, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1192 | eps[0].epg.uplink) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1193 | # ... and nowhere else |
| 1194 | self.pg1.get_capture(0, timeout=0.1) |
| 1195 | self.pg1.assert_nothing_captured(remark="Flood onto other VMS") |
| 1196 | |
| 1197 | pkt_intra_epg_221_to_uplink = (Ether(src=self.pg2.remote_mac, |
| 1198 | dst="00:00:00:33:44:66") / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1199 | IP(src=eps[0].ip4, |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1200 | dst="10.0.0.99") / |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1201 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1202 | Raw(b'\xa5' * 100)) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1203 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1204 | self.send_and_expect_bridged(eps[2].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1205 | pkt_intra_epg_221_to_uplink * NUM_PKTS, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1206 | eps[2].epg.uplink) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1207 | |
| 1208 | # |
| 1209 | # Packets from the uplink are forwarded in the absence of a contract |
| 1210 | # |
| 1211 | pkt_intra_epg_220_from_uplink = (Ether(src="00:00:00:33:44:55", |
| 1212 | dst=self.pg0.remote_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1213 | IP(src=eps[0].ip4, |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1214 | dst="10.0.0.99") / |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1215 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1216 | Raw(b'\xa5' * 100)) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1217 | |
| 1218 | self.send_and_expect_bridged(self.pg4, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1219 | pkt_intra_epg_220_from_uplink * NUM_PKTS, |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1220 | self.pg0) |
| 1221 | |
| 1222 | # |
| 1223 | # in the absence of policy, endpoints in the same EPG |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1224 | # can communicate |
| 1225 | # |
| 1226 | pkt_intra_epg = (Ether(src=self.pg0.remote_mac, |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1227 | dst=self.pg1.remote_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1228 | IP(src=eps[0].ip4, |
| 1229 | dst=eps[1].ip4) / |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1230 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1231 | Raw(b'\xa5' * 100)) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1232 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1233 | self.send_and_expect_bridged(self.pg0, |
| 1234 | pkt_intra_epg * NUM_PKTS, |
| 1235 | self.pg1) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1236 | |
| 1237 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1238 | # in the absence of policy, endpoints in the different EPG |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1239 | # cannot communicate |
| 1240 | # |
| 1241 | pkt_inter_epg_220_to_221 = (Ether(src=self.pg0.remote_mac, |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1242 | dst=self.pg2.remote_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1243 | IP(src=eps[0].ip4, |
| 1244 | dst=eps[2].ip4) / |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1245 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1246 | Raw(b'\xa5' * 100)) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1247 | pkt_inter_epg_221_to_220 = (Ether(src=self.pg2.remote_mac, |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1248 | dst=self.pg0.remote_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1249 | IP(src=eps[2].ip4, |
| 1250 | dst=eps[0].ip4) / |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1251 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1252 | Raw(b'\xa5' * 100)) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1253 | pkt_inter_epg_220_to_222 = (Ether(src=self.pg0.remote_mac, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 1254 | dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1255 | IP(src=eps[0].ip4, |
| 1256 | dst=eps[3].ip4) / |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1257 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1258 | Raw(b'\xa5' * 100)) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1259 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1260 | self.send_and_assert_no_replies(eps[0].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1261 | pkt_inter_epg_220_to_221 * NUM_PKTS) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1262 | self.send_and_assert_no_replies(eps[0].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1263 | pkt_inter_epg_220_to_222 * NUM_PKTS) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1264 | |
| 1265 | # |
| 1266 | # A uni-directional contract from EPG 220 -> 221 |
| 1267 | # |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 1268 | rule = AclRule(is_permit=1, proto=17) |
| 1269 | rule2 = AclRule(src_prefix=IPv6Network((0, 0)), |
| 1270 | dst_prefix=IPv6Network((0, 0)), is_permit=1, proto=17) |
| 1271 | acl = VppAcl(self, rules=[rule, rule2]) |
| 1272 | acl.add_vpp_config() |
| 1273 | |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1274 | c1 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 1275 | self, 400, epgs[0].sclass, epgs[1].sclass, acl.acl_index, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1276 | [VppGbpContractRule( |
| 1277 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 1278 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1279 | []), |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 1280 | VppGbpContractRule( |
| 1281 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 1282 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 1283 | [])], |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 1284 | [ETH_P_IP, ETH_P_IPV6]) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1285 | c1.add_vpp_config() |
| 1286 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1287 | self.send_and_expect_bridged(eps[0].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1288 | pkt_inter_epg_220_to_221 * NUM_PKTS, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1289 | eps[2].itf) |
| 1290 | self.send_and_assert_no_replies(eps[0].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1291 | pkt_inter_epg_220_to_222 * NUM_PKTS) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1292 | |
| 1293 | # |
| 1294 | # contract for the return direction |
| 1295 | # |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1296 | c2 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 1297 | self, 400, epgs[1].sclass, epgs[0].sclass, acl.acl_index, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1298 | [VppGbpContractRule( |
| 1299 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 1300 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1301 | []), |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 1302 | VppGbpContractRule( |
| 1303 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 1304 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 1305 | [])], |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 1306 | [ETH_P_IP, ETH_P_IPV6]) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1307 | c2.add_vpp_config() |
| 1308 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1309 | self.send_and_expect_bridged(eps[0].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1310 | pkt_inter_epg_220_to_221 * NUM_PKTS, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1311 | eps[2].itf) |
| 1312 | self.send_and_expect_bridged(eps[2].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1313 | pkt_inter_epg_221_to_220 * NUM_PKTS, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1314 | eps[0].itf) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1315 | |
Neale Ranns | 796c84b | 2019-03-28 07:56:23 -0700 | [diff] [blame] | 1316 | ds = c2.get_drop_stats() |
| 1317 | self.assertEqual(ds['packets'], 0) |
| 1318 | ps = c2.get_permit_stats() |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1319 | self.assertEqual(ps['packets'], NUM_PKTS) |
Neale Ranns | 796c84b | 2019-03-28 07:56:23 -0700 | [diff] [blame] | 1320 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1321 | # |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 1322 | # the contract does not allow non-IP |
| 1323 | # |
| 1324 | pkt_non_ip_inter_epg_220_to_221 = (Ether(src=self.pg0.remote_mac, |
| 1325 | dst=self.pg2.remote_mac) / |
| 1326 | ARP()) |
| 1327 | self.send_and_assert_no_replies(eps[0].itf, |
| 1328 | pkt_non_ip_inter_epg_220_to_221 * 17) |
| 1329 | |
| 1330 | # |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1331 | # check that inter group is still disabled for the groups |
| 1332 | # not in the contract. |
| 1333 | # |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1334 | self.send_and_assert_no_replies(eps[0].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1335 | pkt_inter_epg_220_to_222 * NUM_PKTS) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1336 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1337 | # |
| 1338 | # A uni-directional contract from EPG 220 -> 222 'L3 routed' |
| 1339 | # |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1340 | c3 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 1341 | self, 400, epgs[0].sclass, epgs[2].sclass, acl.acl_index, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1342 | [VppGbpContractRule( |
| 1343 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 1344 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1345 | []), |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 1346 | VppGbpContractRule( |
| 1347 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 1348 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 1349 | [])], |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 1350 | [ETH_P_IP, ETH_P_IPV6]) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1351 | c3.add_vpp_config() |
| 1352 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1353 | self.logger.info(self.vapi.cli("sh gbp contract")) |
| 1354 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1355 | self.send_and_expect_routed(eps[0].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1356 | pkt_inter_epg_220_to_222 * NUM_PKTS, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1357 | eps[3].itf, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 1358 | str(self.router_mac)) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1359 | # |
| 1360 | # remove both contracts, traffic stops in both directions |
| 1361 | # |
| 1362 | c2.remove_vpp_config() |
| 1363 | c1.remove_vpp_config() |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1364 | c3.remove_vpp_config() |
Mohsin Kazmi | 22b3b84 | 2018-04-17 19:35:42 +0200 | [diff] [blame] | 1365 | acl.remove_vpp_config() |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1366 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1367 | self.send_and_assert_no_replies(eps[2].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1368 | pkt_inter_epg_221_to_220 * NUM_PKTS) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1369 | self.send_and_assert_no_replies(eps[0].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1370 | pkt_inter_epg_220_to_221 * NUM_PKTS) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1371 | self.send_and_expect_bridged(eps[0].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1372 | pkt_intra_epg * NUM_PKTS, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1373 | eps[1].itf) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1374 | |
| 1375 | # |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1376 | # EPs to the outside world |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1377 | # |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1378 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1379 | # in the EP's RD an external subnet via the NAT EPG's recirc |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1380 | se1 = VppGbpSubnet( |
| 1381 | self, rd0, "0.0.0.0", 0, |
| 1382 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_EXTERNAL, |
| 1383 | sw_if_index=recirc_nat.recirc.sw_if_index, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 1384 | sclass=epg_nat.sclass) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1385 | se2 = VppGbpSubnet( |
| 1386 | self, rd0, "11.0.0.0", 8, |
| 1387 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_EXTERNAL, |
| 1388 | sw_if_index=recirc_nat.recirc.sw_if_index, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 1389 | sclass=epg_nat.sclass) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1390 | se16 = VppGbpSubnet( |
| 1391 | self, rd0, "::", 0, |
| 1392 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_EXTERNAL, |
| 1393 | sw_if_index=recirc_nat.recirc.sw_if_index, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 1394 | sclass=epg_nat.sclass) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1395 | # in the NAT RD an external subnet via the NAT EPG's uplink |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1396 | se3 = VppGbpSubnet( |
| 1397 | self, rd20, "0.0.0.0", 0, |
| 1398 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_EXTERNAL, |
| 1399 | sw_if_index=epg_nat.uplink.sw_if_index, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 1400 | sclass=epg_nat.sclass) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1401 | se36 = VppGbpSubnet( |
| 1402 | self, rd20, "::", 0, |
| 1403 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_EXTERNAL, |
| 1404 | sw_if_index=epg_nat.uplink.sw_if_index, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 1405 | sclass=epg_nat.sclass) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1406 | se4 = VppGbpSubnet( |
| 1407 | self, rd20, "11.0.0.0", 8, |
| 1408 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_STITCHED_EXTERNAL, |
| 1409 | sw_if_index=epg_nat.uplink.sw_if_index, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 1410 | sclass=epg_nat.sclass) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1411 | se1.add_vpp_config() |
| 1412 | se2.add_vpp_config() |
| 1413 | se16.add_vpp_config() |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1414 | se3.add_vpp_config() |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1415 | se36.add_vpp_config() |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1416 | se4.add_vpp_config() |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1417 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1418 | self.logger.info(self.vapi.cli("sh ip fib 0.0.0.0/0")) |
| 1419 | self.logger.info(self.vapi.cli("sh ip fib 11.0.0.1")) |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1420 | self.logger.info(self.vapi.cli("sh ip6 fib ::/0")) |
| 1421 | self.logger.info(self.vapi.cli("sh ip6 fib %s" % |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1422 | eps[0].fip6)) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1423 | |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1424 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1425 | # From an EP to an outside address: IN2OUT |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1426 | # |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1427 | pkt_inter_epg_220_to_global = (Ether(src=self.pg0.remote_mac, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 1428 | dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1429 | IP(src=eps[0].ip4, |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1430 | dst="1.1.1.1") / |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1431 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1432 | Raw(b'\xa5' * 100)) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1433 | |
| 1434 | # no policy yet |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1435 | self.send_and_assert_no_replies(eps[0].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1436 | pkt_inter_epg_220_to_global * NUM_PKTS) |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 1437 | rule = AclRule(is_permit=1, proto=17, ports=1234) |
| 1438 | rule2 = AclRule(is_permit=1, proto=17, ports=1234, |
| 1439 | src_prefix=IPv6Network((0, 0)), |
| 1440 | dst_prefix=IPv6Network((0, 0))) |
| 1441 | acl2 = VppAcl(self, rules=[rule, rule2]) |
| 1442 | acl2.add_vpp_config() |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1443 | |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1444 | c4 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 1445 | self, 400, epgs[0].sclass, epgs[3].sclass, acl2.acl_index, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1446 | [VppGbpContractRule( |
| 1447 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 1448 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1449 | []), |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 1450 | VppGbpContractRule( |
| 1451 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 1452 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 1453 | [])], |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 1454 | [ETH_P_IP, ETH_P_IPV6]) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1455 | c4.add_vpp_config() |
| 1456 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1457 | self.send_and_expect_natted(eps[0].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1458 | pkt_inter_epg_220_to_global * NUM_PKTS, |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1459 | self.pg7, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1460 | eps[0].fip4) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1461 | |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1462 | pkt_inter_epg_220_to_global = (Ether(src=self.pg0.remote_mac, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 1463 | dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1464 | IPv6(src=eps[0].ip6, |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1465 | dst="6001::1") / |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1466 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1467 | Raw(b'\xa5' * 100)) |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1468 | |
| 1469 | self.send_and_expect_natted6(self.pg0, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1470 | pkt_inter_epg_220_to_global * NUM_PKTS, |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1471 | self.pg7, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1472 | eps[0].fip6) |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1473 | # |
| 1474 | # From a global address to an EP: OUT2IN |
| 1475 | # |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 1476 | pkt_inter_epg_220_from_global = (Ether(src=str(self.router_mac), |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1477 | dst=self.pg0.remote_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1478 | IP(dst=eps[0].fip4, |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1479 | src="1.1.1.1") / |
| 1480 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1481 | Raw(b'\xa5' * 100)) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1482 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1483 | self.send_and_assert_no_replies( |
| 1484 | self.pg7, pkt_inter_epg_220_from_global * NUM_PKTS) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1485 | |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1486 | c5 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 1487 | self, 400, epgs[3].sclass, epgs[0].sclass, acl2.acl_index, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1488 | [VppGbpContractRule( |
| 1489 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 1490 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1491 | []), |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 1492 | VppGbpContractRule( |
| 1493 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 1494 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 1495 | [])], |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 1496 | [ETH_P_IP, ETH_P_IPV6]) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1497 | c5.add_vpp_config() |
| 1498 | |
| 1499 | self.send_and_expect_unnatted(self.pg7, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1500 | pkt_inter_epg_220_from_global * NUM_PKTS, |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1501 | eps[0].itf, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1502 | eps[0].ip4) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1503 | |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 1504 | pkt_inter_epg_220_from_global = (Ether(src=str(self.router_mac), |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1505 | dst=self.pg0.remote_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1506 | IPv6(dst=eps[0].fip6, |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1507 | src="6001::1") / |
| 1508 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1509 | Raw(b'\xa5' * 100)) |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1510 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1511 | self.send_and_expect_unnatted6( |
| 1512 | self.pg7, |
| 1513 | pkt_inter_epg_220_from_global * NUM_PKTS, |
| 1514 | eps[0].itf, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1515 | eps[0].ip6) |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1516 | |
| 1517 | # |
| 1518 | # From a local VM to another local VM using resp. public addresses: |
| 1519 | # IN2OUT2IN |
| 1520 | # |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1521 | pkt_intra_epg_220_global = (Ether(src=self.pg0.remote_mac, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 1522 | dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1523 | IP(src=eps[0].ip4, |
| 1524 | dst=eps[1].fip4) / |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1525 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1526 | Raw(b'\xa5' * 100)) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1527 | |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1528 | self.send_and_expect_double_natted(eps[0].itf, |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1529 | pkt_intra_epg_220_global * NUM_PKTS, |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1530 | eps[1].itf, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1531 | eps[0].fip4, |
| 1532 | eps[1].ip4) |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1533 | |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1534 | pkt_intra_epg_220_global = (Ether(src=self.pg0.remote_mac, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 1535 | dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1536 | IPv6(src=eps[0].ip6, |
| 1537 | dst=eps[1].fip6) / |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1538 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1539 | Raw(b'\xa5' * 100)) |
Neale Ranns | 4a6d023 | 2018-04-24 07:45:33 -0700 | [diff] [blame] | 1540 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1541 | self.send_and_expect_double_natted6( |
| 1542 | eps[0].itf, |
| 1543 | pkt_intra_epg_220_global * NUM_PKTS, |
| 1544 | eps[1].itf, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1545 | eps[0].fip6, |
| 1546 | eps[1].ip6) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1547 | |
| 1548 | # |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1549 | # cleanup |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1550 | # |
Filip Varga | e7a80a9 | 2021-02-26 09:31:21 +0100 | [diff] [blame] | 1551 | self.vapi.nat44_ed_plugin_enable_disable(enable=0) |
Filip Varga | ed2ee5e | 2021-03-23 12:57:58 +0100 | [diff] [blame] | 1552 | self.vapi.nat66_plugin_enable_disable(enable=0) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1553 | |
Neale Ranns | 774356a | 2018-11-29 12:02:16 +0000 | [diff] [blame] | 1554 | def wait_for_ep_timeout(self, sw_if_index=None, ip=None, mac=None, |
Neale Ranns | 3eea9de | 2019-06-21 02:09:25 -0700 | [diff] [blame] | 1555 | tep=None, n_tries=100, s_time=1): |
Benoît Ganne | 040d47c | 2020-04-16 16:57:00 +0200 | [diff] [blame] | 1556 | # only learnt EP can timeout |
| 1557 | ep_flags = VppEnum.vl_api_gbp_endpoint_flags_t |
| 1558 | flags = ep_flags.GBP_API_ENDPOINT_FLAG_LEARNT |
Neale Ranns | 774356a | 2018-11-29 12:02:16 +0000 | [diff] [blame] | 1559 | while (n_tries): |
Benoît Ganne | 040d47c | 2020-04-16 16:57:00 +0200 | [diff] [blame] | 1560 | if not find_gbp_endpoint(self, sw_if_index, ip, mac, tep=tep, |
| 1561 | flags=flags): |
Neale Ranns | 774356a | 2018-11-29 12:02:16 +0000 | [diff] [blame] | 1562 | return True |
| 1563 | n_tries = n_tries - 1 |
| 1564 | self.sleep(s_time) |
Benoît Ganne | 040d47c | 2020-04-16 16:57:00 +0200 | [diff] [blame] | 1565 | self.assertFalse(find_gbp_endpoint(self, sw_if_index, ip, mac, tep=tep, |
| 1566 | flags=flags)) |
Neale Ranns | 774356a | 2018-11-29 12:02:16 +0000 | [diff] [blame] | 1567 | return False |
| 1568 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1569 | def test_gbp_learn_l2(self): |
| 1570 | """ GBP L2 Endpoint Learning """ |
| 1571 | |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 1572 | drop_no_contract = self.statistics.get_err_counter( |
| 1573 | '/err/gbp-policy-port/drop-no-contract') |
| 1574 | allow_intra_class = self.statistics.get_err_counter( |
| 1575 | '/err/gbp-policy-port/allow-intra-sclass') |
Neale Ranns | 796c84b | 2019-03-28 07:56:23 -0700 | [diff] [blame] | 1576 | |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 1577 | ep_flags = VppEnum.vl_api_gbp_endpoint_flags_t |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1578 | learnt = [{'mac': '00:00:11:11:11:01', |
| 1579 | 'ip': '10.0.0.1', |
| 1580 | 'ip6': '2001:10::2'}, |
| 1581 | {'mac': '00:00:11:11:11:02', |
| 1582 | 'ip': '10.0.0.2', |
| 1583 | 'ip6': '2001:10::3'}] |
| 1584 | |
| 1585 | # |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1586 | # IP tables |
| 1587 | # |
| 1588 | gt4 = VppIpTable(self, 1) |
| 1589 | gt4.add_vpp_config() |
| 1590 | gt6 = VppIpTable(self, 1, is_ip6=True) |
| 1591 | gt6.add_vpp_config() |
| 1592 | |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 1593 | rd1 = VppGbpRouteDomain(self, 1, 401, gt4, gt6) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1594 | rd1.add_vpp_config() |
| 1595 | |
| 1596 | # |
| 1597 | # Pg2 hosts the vxlan tunnel, hosts on pg2 to act as TEPs |
| 1598 | # Pg3 hosts the IP4 UU-flood VXLAN tunnel |
| 1599 | # Pg4 hosts the IP6 UU-flood VXLAN tunnel |
| 1600 | # |
| 1601 | self.pg2.config_ip4() |
| 1602 | self.pg2.resolve_arp() |
| 1603 | self.pg2.generate_remote_hosts(4) |
| 1604 | self.pg2.configure_ipv4_neighbors() |
| 1605 | self.pg3.config_ip4() |
| 1606 | self.pg3.resolve_arp() |
| 1607 | self.pg4.config_ip4() |
| 1608 | self.pg4.resolve_arp() |
| 1609 | |
| 1610 | # |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 1611 | # Add a mcast destination VXLAN-GBP tunnel for B&M traffic |
| 1612 | # |
| 1613 | tun_bm = VppVxlanGbpTunnel(self, self.pg4.local_ip4, |
| 1614 | "239.1.1.1", 88, |
| 1615 | mcast_itf=self.pg4) |
| 1616 | tun_bm.add_vpp_config() |
| 1617 | |
| 1618 | # |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1619 | # a GBP bridge domain with a BVI and a UU-flood interface |
| 1620 | # |
| 1621 | bd1 = VppBridgeDomain(self, 1) |
| 1622 | bd1.add_vpp_config() |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 1623 | gbd1 = VppGbpBridgeDomain(self, bd1, rd1, self.loop0, |
| 1624 | self.pg3, tun_bm) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1625 | gbd1.add_vpp_config() |
| 1626 | |
| 1627 | self.logger.info(self.vapi.cli("sh bridge 1 detail")) |
| 1628 | self.logger.info(self.vapi.cli("sh gbp bridge")) |
| 1629 | |
| 1630 | # ... and has a /32 applied |
| 1631 | ip_addr = VppIpInterfaceAddress(self, gbd1.bvi, "10.0.0.128", 32) |
| 1632 | ip_addr.add_vpp_config() |
| 1633 | |
| 1634 | # |
| 1635 | # The Endpoint-group in which we are learning endpoints |
| 1636 | # |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 1637 | epg_220 = VppGbpEndpointGroup(self, 220, 112, rd1, gbd1, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1638 | None, self.loop0, |
| 1639 | "10.0.0.128", |
Neale Ranns | 32f6d8e | 2019-03-05 04:22:08 -0800 | [diff] [blame] | 1640 | "2001:10::128", |
Neale Ranns | 8d0d8d2 | 2020-04-07 08:44:20 +0000 | [diff] [blame] | 1641 | VppGbpEndpointRetention(4)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1642 | epg_220.add_vpp_config() |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 1643 | epg_330 = VppGbpEndpointGroup(self, 330, 113, rd1, gbd1, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1644 | None, self.loop1, |
| 1645 | "10.0.1.128", |
Neale Ranns | 32f6d8e | 2019-03-05 04:22:08 -0800 | [diff] [blame] | 1646 | "2001:11::128", |
Neale Ranns | 8d0d8d2 | 2020-04-07 08:44:20 +0000 | [diff] [blame] | 1647 | VppGbpEndpointRetention(4)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1648 | epg_330.add_vpp_config() |
| 1649 | |
| 1650 | # |
| 1651 | # The VXLAN GBP tunnel is a bridge-port and has L2 endpoint |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1652 | # learning enabled |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1653 | # |
| 1654 | vx_tun_l2_1 = VppGbpVxlanTunnel( |
| 1655 | self, 99, bd1.bd_id, |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 1656 | VppEnum.vl_api_gbp_vxlan_tunnel_mode_t.GBP_VXLAN_TUNNEL_MODE_L2, |
| 1657 | self.pg2.local_ip4) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1658 | vx_tun_l2_1.add_vpp_config() |
| 1659 | |
| 1660 | # |
| 1661 | # A static endpoint that the learnt endpoints are trying to |
| 1662 | # talk to |
| 1663 | # |
| 1664 | ep = VppGbpEndpoint(self, self.pg0, |
| 1665 | epg_220, None, |
| 1666 | "10.0.0.127", "11.0.0.127", |
| 1667 | "2001:10::1", "3001::1") |
| 1668 | ep.add_vpp_config() |
| 1669 | |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1670 | self.assertTrue(find_route(self, ep.ip4, 32, table_id=1)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1671 | |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1672 | # a packet with an sclass from an unknown EPG |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1673 | p = (Ether(src=self.pg2.remote_mac, |
| 1674 | dst=self.pg2.local_mac) / |
| 1675 | IP(src=self.pg2.remote_hosts[0].ip4, |
| 1676 | dst=self.pg2.local_ip4) / |
| 1677 | UDP(sport=1234, dport=48879) / |
| 1678 | VXLAN(vni=99, gpid=88, flags=0x88) / |
| 1679 | Ether(src=learnt[0]["mac"], dst=ep.mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1680 | IP(src=learnt[0]["ip"], dst=ep.ip4) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1681 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1682 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1683 | |
| 1684 | self.send_and_assert_no_replies(self.pg2, p) |
| 1685 | |
Neale Ranns | 796c84b | 2019-03-28 07:56:23 -0700 | [diff] [blame] | 1686 | self.logger.info(self.vapi.cli("sh error")) |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 1687 | self.assert_error_counter_equal( |
| 1688 | '/err/gbp-policy-port/drop-no-contract', |
| 1689 | drop_no_contract + 1) |
Neale Ranns | 796c84b | 2019-03-28 07:56:23 -0700 | [diff] [blame] | 1690 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1691 | # |
| 1692 | # we should not have learnt a new tunnel endpoint, since |
| 1693 | # the EPG was not learnt. |
| 1694 | # |
| 1695 | self.assertEqual(INDEX_INVALID, |
| 1696 | find_vxlan_gbp_tunnel(self, |
| 1697 | self.pg2.local_ip4, |
| 1698 | self.pg2.remote_hosts[0].ip4, |
| 1699 | 99)) |
| 1700 | |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 1701 | # ep is not learnt, because the EPG is unknown |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1702 | self.assertEqual(len(self.vapi.gbp_endpoint_dump()), 1) |
| 1703 | |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 1704 | # |
| 1705 | # Learn new EPs from IP packets |
| 1706 | # |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1707 | for ii, l in enumerate(learnt): |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1708 | # a packet with an sclass from a known EPG |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1709 | # arriving on an unknown TEP |
| 1710 | p = (Ether(src=self.pg2.remote_mac, |
| 1711 | dst=self.pg2.local_mac) / |
| 1712 | IP(src=self.pg2.remote_hosts[1].ip4, |
| 1713 | dst=self.pg2.local_ip4) / |
| 1714 | UDP(sport=1234, dport=48879) / |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 1715 | VXLAN(vni=99, gpid=112, flags=0x88) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1716 | Ether(src=l['mac'], dst=ep.mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1717 | IP(src=l['ip'], dst=ep.ip4) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1718 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1719 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1720 | |
| 1721 | rx = self.send_and_expect(self.pg2, [p], self.pg0) |
| 1722 | |
| 1723 | # the new TEP |
| 1724 | tep1_sw_if_index = find_vxlan_gbp_tunnel( |
| 1725 | self, |
| 1726 | self.pg2.local_ip4, |
| 1727 | self.pg2.remote_hosts[1].ip4, |
| 1728 | 99) |
| 1729 | self.assertNotEqual(INDEX_INVALID, tep1_sw_if_index) |
| 1730 | |
| 1731 | # |
| 1732 | # the EP is learnt via the learnt TEP |
| 1733 | # both from its MAC and its IP |
| 1734 | # |
| 1735 | self.assertTrue(find_gbp_endpoint(self, |
| 1736 | vx_tun_l2_1.sw_if_index, |
| 1737 | mac=l['mac'])) |
| 1738 | self.assertTrue(find_gbp_endpoint(self, |
| 1739 | vx_tun_l2_1.sw_if_index, |
| 1740 | ip=l['ip'])) |
| 1741 | |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 1742 | self.assert_error_counter_equal( |
| 1743 | '/err/gbp-policy-port/allow-intra-sclass', |
| 1744 | allow_intra_class + 2) |
Neale Ranns | 796c84b | 2019-03-28 07:56:23 -0700 | [diff] [blame] | 1745 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1746 | self.logger.info(self.vapi.cli("show gbp endpoint")) |
| 1747 | self.logger.info(self.vapi.cli("show gbp vxlan")) |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 1748 | self.logger.info(self.vapi.cli("show ip mfib")) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1749 | |
| 1750 | # |
| 1751 | # If we sleep for the threshold time, the learnt endpoints should |
| 1752 | # age out |
| 1753 | # |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1754 | for l in learnt: |
Neale Ranns | 774356a | 2018-11-29 12:02:16 +0000 | [diff] [blame] | 1755 | self.wait_for_ep_timeout(vx_tun_l2_1.sw_if_index, |
| 1756 | mac=l['mac']) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1757 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1758 | # |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 1759 | # Learn new EPs from GARP packets received on the BD's mcast tunnel |
| 1760 | # |
| 1761 | for ii, l in enumerate(learnt): |
Neale Ranns | 81cfa9c | 2019-07-04 14:12:50 +0000 | [diff] [blame] | 1762 | # add some junk in the reserved field of the vxlan-header |
| 1763 | # next to the VNI. we should accept since reserved bits are |
| 1764 | # ignored on rx. |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 1765 | p = (Ether(src=self.pg2.remote_mac, |
| 1766 | dst=self.pg2.local_mac) / |
| 1767 | IP(src=self.pg2.remote_hosts[1].ip4, |
| 1768 | dst="239.1.1.1") / |
| 1769 | UDP(sport=1234, dport=48879) / |
Neale Ranns | 81cfa9c | 2019-07-04 14:12:50 +0000 | [diff] [blame] | 1770 | VXLAN(vni=88, reserved2=0x80, gpid=112, flags=0x88) / |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 1771 | Ether(src=l['mac'], dst="ff:ff:ff:ff:ff:ff") / |
| 1772 | ARP(op="who-has", |
| 1773 | psrc=l['ip'], pdst=l['ip'], |
| 1774 | hwsrc=l['mac'], hwdst="ff:ff:ff:ff:ff:ff")) |
| 1775 | |
| 1776 | rx = self.send_and_expect(self.pg4, [p], self.pg0) |
| 1777 | |
| 1778 | # the new TEP |
| 1779 | tep1_sw_if_index = find_vxlan_gbp_tunnel( |
| 1780 | self, |
| 1781 | self.pg2.local_ip4, |
| 1782 | self.pg2.remote_hosts[1].ip4, |
| 1783 | 99) |
| 1784 | self.assertNotEqual(INDEX_INVALID, tep1_sw_if_index) |
| 1785 | |
| 1786 | # |
| 1787 | # the EP is learnt via the learnt TEP |
| 1788 | # both from its MAC and its IP |
| 1789 | # |
| 1790 | self.assertTrue(find_gbp_endpoint(self, |
| 1791 | vx_tun_l2_1.sw_if_index, |
| 1792 | mac=l['mac'])) |
| 1793 | self.assertTrue(find_gbp_endpoint(self, |
| 1794 | vx_tun_l2_1.sw_if_index, |
| 1795 | ip=l['ip'])) |
| 1796 | |
| 1797 | # |
| 1798 | # wait for the learnt endpoints to age out |
| 1799 | # |
| 1800 | for l in learnt: |
| 1801 | self.wait_for_ep_timeout(vx_tun_l2_1.sw_if_index, |
| 1802 | mac=l['mac']) |
| 1803 | |
| 1804 | # |
| 1805 | # Learn new EPs from L2 packets |
| 1806 | # |
| 1807 | for ii, l in enumerate(learnt): |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1808 | # a packet with an sclass from a known EPG |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 1809 | # arriving on an unknown TEP |
| 1810 | p = (Ether(src=self.pg2.remote_mac, |
| 1811 | dst=self.pg2.local_mac) / |
| 1812 | IP(src=self.pg2.remote_hosts[1].ip4, |
| 1813 | dst=self.pg2.local_ip4) / |
| 1814 | UDP(sport=1234, dport=48879) / |
| 1815 | VXLAN(vni=99, gpid=112, flags=0x88) / |
| 1816 | Ether(src=l['mac'], dst=ep.mac) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1817 | Raw(b'\xa5' * 100)) |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 1818 | |
| 1819 | rx = self.send_and_expect(self.pg2, [p], self.pg0) |
| 1820 | |
| 1821 | # the new TEP |
| 1822 | tep1_sw_if_index = find_vxlan_gbp_tunnel( |
| 1823 | self, |
| 1824 | self.pg2.local_ip4, |
| 1825 | self.pg2.remote_hosts[1].ip4, |
| 1826 | 99) |
| 1827 | self.assertNotEqual(INDEX_INVALID, tep1_sw_if_index) |
| 1828 | |
| 1829 | # |
| 1830 | # the EP is learnt via the learnt TEP |
| 1831 | # both from its MAC and its IP |
| 1832 | # |
| 1833 | self.assertTrue(find_gbp_endpoint(self, |
| 1834 | vx_tun_l2_1.sw_if_index, |
| 1835 | mac=l['mac'])) |
| 1836 | |
| 1837 | self.logger.info(self.vapi.cli("show gbp endpoint")) |
| 1838 | self.logger.info(self.vapi.cli("show gbp vxlan")) |
| 1839 | self.logger.info(self.vapi.cli("show vxlan-gbp tunnel")) |
| 1840 | |
| 1841 | # |
| 1842 | # wait for the learnt endpoints to age out |
| 1843 | # |
| 1844 | for l in learnt: |
| 1845 | self.wait_for_ep_timeout(vx_tun_l2_1.sw_if_index, |
| 1846 | mac=l['mac']) |
| 1847 | |
| 1848 | # |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1849 | # repeat. the do not learn bit is set so the EPs are not learnt |
| 1850 | # |
| 1851 | for l in learnt: |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1852 | # a packet with an sclass from a known EPG |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1853 | p = (Ether(src=self.pg2.remote_mac, |
| 1854 | dst=self.pg2.local_mac) / |
| 1855 | IP(src=self.pg2.remote_hosts[1].ip4, |
| 1856 | dst=self.pg2.local_ip4) / |
| 1857 | UDP(sport=1234, dport=48879) / |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 1858 | VXLAN(vni=99, gpid=112, flags=0x88, gpflags="D") / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1859 | Ether(src=l['mac'], dst=ep.mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1860 | IP(src=l['ip'], dst=ep.ip4) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1861 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1862 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1863 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1864 | rx = self.send_and_expect(self.pg2, p * NUM_PKTS, self.pg0) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1865 | |
| 1866 | for l in learnt: |
| 1867 | self.assertFalse(find_gbp_endpoint(self, |
| 1868 | vx_tun_l2_1.sw_if_index, |
| 1869 | mac=l['mac'])) |
| 1870 | |
| 1871 | # |
| 1872 | # repeat |
| 1873 | # |
| 1874 | for l in learnt: |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1875 | # a packet with an sclass from a known EPG |
Neale Ranns | 81cfa9c | 2019-07-04 14:12:50 +0000 | [diff] [blame] | 1876 | # set a reserved bit in addition to the G and I |
| 1877 | # reserved bits should not be checked on rx. |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1878 | p = (Ether(src=self.pg2.remote_mac, |
| 1879 | dst=self.pg2.local_mac) / |
| 1880 | IP(src=self.pg2.remote_hosts[1].ip4, |
| 1881 | dst=self.pg2.local_ip4) / |
| 1882 | UDP(sport=1234, dport=48879) / |
Neale Ranns | 81cfa9c | 2019-07-04 14:12:50 +0000 | [diff] [blame] | 1883 | VXLAN(vni=99, gpid=112, flags=0xc8) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1884 | Ether(src=l['mac'], dst=ep.mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1885 | IP(src=l['ip'], dst=ep.ip4) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1886 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1887 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1888 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1889 | rx = self.send_and_expect(self.pg2, p * NUM_PKTS, self.pg0) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1890 | |
| 1891 | self.assertTrue(find_gbp_endpoint(self, |
| 1892 | vx_tun_l2_1.sw_if_index, |
| 1893 | mac=l['mac'])) |
| 1894 | |
| 1895 | # |
| 1896 | # Static EP replies to dynamics |
| 1897 | # |
| 1898 | self.logger.info(self.vapi.cli("sh l2fib bd_id 1")) |
| 1899 | for l in learnt: |
| 1900 | p = (Ether(src=ep.mac, dst=l['mac']) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1901 | IP(dst=l['ip'], src=ep.ip4) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1902 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1903 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1904 | |
| 1905 | rxs = self.send_and_expect(self.pg0, p * 17, self.pg2) |
| 1906 | |
| 1907 | for rx in rxs: |
| 1908 | self.assertEqual(rx[IP].src, self.pg2.local_ip4) |
| 1909 | self.assertEqual(rx[IP].dst, self.pg2.remote_hosts[1].ip4) |
| 1910 | self.assertEqual(rx[UDP].dport, 48879) |
| 1911 | # the UDP source port is a random value for hashing |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 1912 | self.assertEqual(rx[VXLAN].gpid, 112) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1913 | self.assertEqual(rx[VXLAN].vni, 99) |
| 1914 | self.assertTrue(rx[VXLAN].flags.G) |
| 1915 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 1916 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 1917 | self.assertFalse(rx[VXLAN].gpflags.D) |
| 1918 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1919 | for l in learnt: |
Neale Ranns | 774356a | 2018-11-29 12:02:16 +0000 | [diff] [blame] | 1920 | self.wait_for_ep_timeout(vx_tun_l2_1.sw_if_index, |
| 1921 | mac=l['mac']) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1922 | |
| 1923 | # |
| 1924 | # repeat in the other EPG |
| 1925 | # there's no contract between 220 and 330, but the A-bit is set |
| 1926 | # so the packet is cleared for delivery |
| 1927 | # |
| 1928 | for l in learnt: |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1929 | # a packet with an sclass from a known EPG |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1930 | p = (Ether(src=self.pg2.remote_mac, |
| 1931 | dst=self.pg2.local_mac) / |
| 1932 | IP(src=self.pg2.remote_hosts[1].ip4, |
| 1933 | dst=self.pg2.local_ip4) / |
| 1934 | UDP(sport=1234, dport=48879) / |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 1935 | VXLAN(vni=99, gpid=113, flags=0x88, gpflags='A') / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1936 | Ether(src=l['mac'], dst=ep.mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1937 | IP(src=l['ip'], dst=ep.ip4) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1938 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1939 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1940 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1941 | rx = self.send_and_expect(self.pg2, p * NUM_PKTS, self.pg0) |
Mohsin Kazmi | e60dfd7 | 2019-04-16 15:15:07 +0200 | [diff] [blame] | 1942 | |
| 1943 | self.assertTrue(find_gbp_endpoint(self, |
| 1944 | vx_tun_l2_1.sw_if_index, |
| 1945 | mac=l['mac'])) |
| 1946 | |
| 1947 | # |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1948 | # static EP cannot reach the learnt EPs since there is no contract |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1949 | # only test 1 EP as the others could timeout |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1950 | # |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1951 | p = (Ether(src=ep.mac, dst=l['mac']) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1952 | IP(dst=learnt[0]['ip'], src=ep.ip4) / |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1953 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1954 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1955 | |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1956 | self.send_and_assert_no_replies(self.pg0, [p]) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1957 | |
| 1958 | # |
| 1959 | # refresh the entries after the check for no replies above |
| 1960 | # |
| 1961 | for l in learnt: |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1962 | # a packet with an sclass from a known EPG |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1963 | p = (Ether(src=self.pg2.remote_mac, |
| 1964 | dst=self.pg2.local_mac) / |
| 1965 | IP(src=self.pg2.remote_hosts[1].ip4, |
| 1966 | dst=self.pg2.local_ip4) / |
| 1967 | UDP(sport=1234, dport=48879) / |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 1968 | VXLAN(vni=99, gpid=113, flags=0x88, gpflags='A') / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1969 | Ether(src=l['mac'], dst=ep.mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1970 | IP(src=l['ip'], dst=ep.ip4) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1971 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 1972 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1973 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 1974 | rx = self.send_and_expect(self.pg2, p * NUM_PKTS, self.pg0) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1975 | |
| 1976 | self.assertTrue(find_gbp_endpoint(self, |
| 1977 | vx_tun_l2_1.sw_if_index, |
| 1978 | mac=l['mac'])) |
| 1979 | |
| 1980 | # |
| 1981 | # Add the contract so they can talk |
| 1982 | # |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 1983 | rule = AclRule(is_permit=1, proto=17) |
| 1984 | rule2 = AclRule(src_prefix=IPv6Network((0, 0)), |
| 1985 | dst_prefix=IPv6Network((0, 0)), is_permit=1, proto=17) |
| 1986 | acl = VppAcl(self, rules=[rule, rule2]) |
| 1987 | acl.add_vpp_config() |
| 1988 | |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1989 | c1 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 1990 | self, 401, epg_220.sclass, epg_330.sclass, acl.acl_index, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1991 | [VppGbpContractRule( |
| 1992 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 1993 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 1994 | []), |
Neale Ranns | e28c87c | 2019-07-05 00:53:45 -0700 | [diff] [blame] | 1995 | VppGbpContractRule( |
| 1996 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
| 1997 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
| 1998 | [])], |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 1999 | [ETH_P_IP, ETH_P_IPV6]) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2000 | c1.add_vpp_config() |
| 2001 | |
| 2002 | for l in learnt: |
| 2003 | p = (Ether(src=ep.mac, dst=l['mac']) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2004 | IP(dst=l['ip'], src=ep.ip4) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2005 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2006 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2007 | |
| 2008 | self.send_and_expect(self.pg0, [p], self.pg2) |
| 2009 | |
| 2010 | # |
| 2011 | # send UU packets from the local EP |
| 2012 | # |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2013 | self.logger.info(self.vapi.cli("sh gbp bridge")) |
Neale Ranns | e28c87c | 2019-07-05 00:53:45 -0700 | [diff] [blame] | 2014 | self.logger.info(self.vapi.cli("sh bridge-domain 1 detail")) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2015 | p_uu = (Ether(src=ep.mac, dst="00:11:11:11:11:11") / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2016 | IP(dst="10.0.0.133", src=ep.ip4) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2017 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2018 | Raw(b'\xa5' * 100)) |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 2019 | rxs = self.send_and_expect(ep.itf, [p_uu], gbd1.uu_fwd) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2020 | |
| 2021 | self.logger.info(self.vapi.cli("sh bridge 1 detail")) |
| 2022 | |
| 2023 | p_bm = (Ether(src=ep.mac, dst="ff:ff:ff:ff:ff:ff") / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2024 | IP(dst="10.0.0.133", src=ep.ip4) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2025 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2026 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2027 | rxs = self.send_and_expect_only(ep.itf, [p_bm], tun_bm.mcast_itf) |
| 2028 | |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 2029 | for rx in rxs: |
| 2030 | self.assertEqual(rx[IP].src, self.pg4.local_ip4) |
| 2031 | self.assertEqual(rx[IP].dst, "239.1.1.1") |
| 2032 | self.assertEqual(rx[UDP].dport, 48879) |
| 2033 | # the UDP source port is a random value for hashing |
| 2034 | self.assertEqual(rx[VXLAN].gpid, 112) |
| 2035 | self.assertEqual(rx[VXLAN].vni, 88) |
| 2036 | self.assertTrue(rx[VXLAN].flags.G) |
| 2037 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 2038 | self.assertFalse(rx[VXLAN].gpflags.A) |
| 2039 | self.assertFalse(rx[VXLAN].gpflags.D) |
| 2040 | |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 2041 | rule = AclRule(is_permit=1, proto=17) |
| 2042 | rule2 = AclRule(src_prefix=IPv6Network((0, 0)), |
| 2043 | dst_prefix=IPv6Network((0, 0)), is_permit=1, proto=17) |
| 2044 | acl = VppAcl(self, rules=[rule, rule2]) |
| 2045 | acl.add_vpp_config() |
| 2046 | |
Neale Ranns | e28c87c | 2019-07-05 00:53:45 -0700 | [diff] [blame] | 2047 | c2 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 2048 | self, 401, epg_330.sclass, epg_220.sclass, acl.acl_index, |
Neale Ranns | e28c87c | 2019-07-05 00:53:45 -0700 | [diff] [blame] | 2049 | [VppGbpContractRule( |
| 2050 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
| 2051 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
| 2052 | []), |
| 2053 | VppGbpContractRule( |
| 2054 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
| 2055 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
| 2056 | [])], |
| 2057 | [ETH_P_IP, ETH_P_IPV6]) |
| 2058 | c2.add_vpp_config() |
| 2059 | |
| 2060 | for l in learnt: |
| 2061 | self.wait_for_ep_timeout(vx_tun_l2_1.sw_if_index, |
| 2062 | mac=l['mac']) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2063 | # |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2064 | # Check v6 Endpoints learning |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2065 | # |
| 2066 | for l in learnt: |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 2067 | # a packet with an sclass from a known EPG |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2068 | p = (Ether(src=self.pg2.remote_mac, |
| 2069 | dst=self.pg2.local_mac) / |
| 2070 | IP(src=self.pg2.remote_hosts[1].ip4, |
| 2071 | dst=self.pg2.local_ip4) / |
| 2072 | UDP(sport=1234, dport=48879) / |
Neale Ranns | e28c87c | 2019-07-05 00:53:45 -0700 | [diff] [blame] | 2073 | VXLAN(vni=99, gpid=113, flags=0x88) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2074 | Ether(src=l['mac'], dst=ep.mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2075 | IPv6(src=l['ip6'], dst=ep.ip6) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2076 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2077 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2078 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 2079 | rx = self.send_and_expect(self.pg2, p * NUM_PKTS, self.pg0) |
Neale Ranns | e28c87c | 2019-07-05 00:53:45 -0700 | [diff] [blame] | 2080 | rx = self.send_and_expect(self.pg2, p * NUM_PKTS, self.pg0) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2081 | |
Neale Ranns | e28c87c | 2019-07-05 00:53:45 -0700 | [diff] [blame] | 2082 | self.assertTrue(find_gbp_endpoint( |
| 2083 | self, |
| 2084 | vx_tun_l2_1.sw_if_index, |
| 2085 | ip=l['ip6'], |
| 2086 | tep=[self.pg2.local_ip4, |
| 2087 | self.pg2.remote_hosts[1].ip4])) |
| 2088 | |
| 2089 | self.logger.info(self.vapi.cli("sh int")) |
| 2090 | self.logger.info(self.vapi.cli("sh vxlan-gbp tunnel")) |
| 2091 | self.logger.info(self.vapi.cli("sh gbp vxlan")) |
| 2092 | self.logger.info(self.vapi.cli("sh gbp endpoint")) |
| 2093 | self.logger.info(self.vapi.cli("sh gbp interface")) |
| 2094 | |
| 2095 | # |
| 2096 | # EP moves to a different TEP |
| 2097 | # |
| 2098 | for l in learnt: |
| 2099 | # a packet with an sclass from a known EPG |
| 2100 | p = (Ether(src=self.pg2.remote_mac, |
| 2101 | dst=self.pg2.local_mac) / |
| 2102 | IP(src=self.pg2.remote_hosts[2].ip4, |
| 2103 | dst=self.pg2.local_ip4) / |
| 2104 | UDP(sport=1234, dport=48879) / |
| 2105 | VXLAN(vni=99, gpid=113, flags=0x88) / |
| 2106 | Ether(src=l['mac'], dst=ep.mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2107 | IPv6(src=l['ip6'], dst=ep.ip6) / |
Neale Ranns | e28c87c | 2019-07-05 00:53:45 -0700 | [diff] [blame] | 2108 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2109 | Raw(b'\xa5' * 100)) |
Neale Ranns | e28c87c | 2019-07-05 00:53:45 -0700 | [diff] [blame] | 2110 | |
| 2111 | rx = self.send_and_expect(self.pg2, p * 1, self.pg0) |
| 2112 | rx = self.send_and_expect(self.pg2, p * NUM_PKTS, self.pg0) |
| 2113 | |
| 2114 | self.assertTrue(find_gbp_endpoint( |
| 2115 | self, |
| 2116 | vx_tun_l2_1.sw_if_index, |
Neale Ranns | 6d1ba56 | 2019-07-10 01:14:58 -0700 | [diff] [blame] | 2117 | sclass=113, |
Neale Ranns | e28c87c | 2019-07-05 00:53:45 -0700 | [diff] [blame] | 2118 | mac=l['mac'], |
| 2119 | tep=[self.pg2.local_ip4, |
| 2120 | self.pg2.remote_hosts[2].ip4])) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2121 | |
| 2122 | # |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2123 | # v6 remote EP reachability |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2124 | # |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2125 | for l in learnt: |
| 2126 | p = (Ether(src=ep.mac, dst=l['mac']) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2127 | IPv6(dst=l['ip6'], src=ep.ip6) / |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2128 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2129 | Raw(b'\xa5' * 100)) |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2130 | |
| 2131 | rxs = self.send_and_expect(self.pg0, p * NUM_PKTS, self.pg2) |
| 2132 | |
| 2133 | for rx in rxs: |
| 2134 | self.assertEqual(rx[IP].src, self.pg2.local_ip4) |
Neale Ranns | e28c87c | 2019-07-05 00:53:45 -0700 | [diff] [blame] | 2135 | self.assertEqual(rx[IP].dst, self.pg2.remote_hosts[2].ip4) |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2136 | self.assertEqual(rx[UDP].dport, 48879) |
| 2137 | # the UDP source port is a random value for hashing |
| 2138 | self.assertEqual(rx[VXLAN].gpid, 112) |
| 2139 | self.assertEqual(rx[VXLAN].vni, 99) |
| 2140 | self.assertTrue(rx[VXLAN].flags.G) |
| 2141 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 2142 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 2143 | self.assertFalse(rx[VXLAN].gpflags.D) |
| 2144 | self.assertEqual(rx[IPv6].dst, l['ip6']) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2145 | |
| 2146 | # |
Neale Ranns | 6d1ba56 | 2019-07-10 01:14:58 -0700 | [diff] [blame] | 2147 | # EP changes sclass |
| 2148 | # |
| 2149 | for l in learnt: |
| 2150 | # a packet with an sclass from a known EPG |
| 2151 | p = (Ether(src=self.pg2.remote_mac, |
| 2152 | dst=self.pg2.local_mac) / |
| 2153 | IP(src=self.pg2.remote_hosts[2].ip4, |
| 2154 | dst=self.pg2.local_ip4) / |
| 2155 | UDP(sport=1234, dport=48879) / |
| 2156 | VXLAN(vni=99, gpid=112, flags=0x88) / |
| 2157 | Ether(src=l['mac'], dst=ep.mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2158 | IPv6(src=l['ip6'], dst=ep.ip6) / |
Neale Ranns | 6d1ba56 | 2019-07-10 01:14:58 -0700 | [diff] [blame] | 2159 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2160 | Raw(b'\xa5' * 100)) |
Neale Ranns | 6d1ba56 | 2019-07-10 01:14:58 -0700 | [diff] [blame] | 2161 | |
| 2162 | rx = self.send_and_expect(self.pg2, p * 1, self.pg0) |
| 2163 | rx = self.send_and_expect(self.pg2, p * NUM_PKTS, self.pg0) |
| 2164 | |
| 2165 | self.assertTrue(find_gbp_endpoint( |
| 2166 | self, |
| 2167 | vx_tun_l2_1.sw_if_index, |
| 2168 | mac=l['mac'], |
| 2169 | sclass=112, |
| 2170 | tep=[self.pg2.local_ip4, |
| 2171 | self.pg2.remote_hosts[2].ip4])) |
| 2172 | |
| 2173 | # |
| 2174 | # check reachability and contract intra-epg |
| 2175 | # |
| 2176 | allow_intra_class = self.statistics.get_err_counter( |
| 2177 | '/err/gbp-policy-mac/allow-intra-sclass') |
| 2178 | |
| 2179 | for l in learnt: |
| 2180 | p = (Ether(src=ep.mac, dst=l['mac']) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2181 | IPv6(dst=l['ip6'], src=ep.ip6) / |
Neale Ranns | 6d1ba56 | 2019-07-10 01:14:58 -0700 | [diff] [blame] | 2182 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2183 | Raw(b'\xa5' * 100)) |
Neale Ranns | 6d1ba56 | 2019-07-10 01:14:58 -0700 | [diff] [blame] | 2184 | |
| 2185 | rxs = self.send_and_expect(self.pg0, p * NUM_PKTS, self.pg2) |
| 2186 | |
| 2187 | for rx in rxs: |
| 2188 | self.assertEqual(rx[IP].src, self.pg2.local_ip4) |
| 2189 | self.assertEqual(rx[IP].dst, self.pg2.remote_hosts[2].ip4) |
| 2190 | self.assertEqual(rx[UDP].dport, 48879) |
| 2191 | self.assertEqual(rx[VXLAN].gpid, 112) |
| 2192 | self.assertEqual(rx[VXLAN].vni, 99) |
| 2193 | self.assertTrue(rx[VXLAN].flags.G) |
| 2194 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 2195 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 2196 | self.assertFalse(rx[VXLAN].gpflags.D) |
| 2197 | self.assertEqual(rx[IPv6].dst, l['ip6']) |
| 2198 | |
| 2199 | allow_intra_class += NUM_PKTS |
| 2200 | |
| 2201 | self.assert_error_counter_equal( |
| 2202 | '/err/gbp-policy-mac/allow-intra-sclass', |
| 2203 | allow_intra_class) |
| 2204 | |
| 2205 | # |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2206 | # clean up |
| 2207 | # |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2208 | for l in learnt: |
Neale Ranns | 774356a | 2018-11-29 12:02:16 +0000 | [diff] [blame] | 2209 | self.wait_for_ep_timeout(vx_tun_l2_1.sw_if_index, |
| 2210 | mac=l['mac']) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2211 | self.pg2.unconfig_ip4() |
| 2212 | self.pg3.unconfig_ip4() |
| 2213 | self.pg4.unconfig_ip4() |
| 2214 | |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2215 | def test_gbp_contract(self): |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2216 | """ GBP Contracts """ |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2217 | |
| 2218 | # |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 2219 | # Route Domains |
| 2220 | # |
| 2221 | gt4 = VppIpTable(self, 0) |
| 2222 | gt4.add_vpp_config() |
| 2223 | gt6 = VppIpTable(self, 0, is_ip6=True) |
| 2224 | gt6.add_vpp_config() |
| 2225 | |
| 2226 | rd0 = VppGbpRouteDomain(self, 0, 400, gt4, gt6, None, None) |
| 2227 | |
| 2228 | rd0.add_vpp_config() |
| 2229 | |
| 2230 | # |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2231 | # Bridge Domains |
| 2232 | # |
| 2233 | bd1 = VppBridgeDomain(self, 1, arp_term=0) |
| 2234 | bd2 = VppBridgeDomain(self, 2, arp_term=0) |
| 2235 | |
| 2236 | bd1.add_vpp_config() |
| 2237 | bd2.add_vpp_config() |
| 2238 | |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 2239 | gbd1 = VppGbpBridgeDomain(self, bd1, rd0, self.loop0) |
| 2240 | gbd2 = VppGbpBridgeDomain(self, bd2, rd0, self.loop1) |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2241 | |
| 2242 | gbd1.add_vpp_config() |
| 2243 | gbd2.add_vpp_config() |
| 2244 | |
| 2245 | # |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2246 | # 3 EPGs, 2 of which share a BD. |
| 2247 | # |
| 2248 | epgs = [VppGbpEndpointGroup(self, 220, 1220, rd0, gbd1, |
| 2249 | None, self.loop0, |
| 2250 | "10.0.0.128", "2001:10::128"), |
| 2251 | VppGbpEndpointGroup(self, 221, 1221, rd0, gbd1, |
| 2252 | None, self.loop0, |
| 2253 | "10.0.1.128", "2001:10:1::128"), |
| 2254 | VppGbpEndpointGroup(self, 222, 1222, rd0, gbd2, |
| 2255 | None, self.loop1, |
| 2256 | "10.0.2.128", "2001:10:2::128")] |
| 2257 | # |
| 2258 | # 4 end-points, 2 in the same subnet, 3 in the same BD |
| 2259 | # |
| 2260 | eps = [VppGbpEndpoint(self, self.pg0, |
| 2261 | epgs[0], None, |
| 2262 | "10.0.0.1", "11.0.0.1", |
| 2263 | "2001:10::1", "3001::1"), |
| 2264 | VppGbpEndpoint(self, self.pg1, |
| 2265 | epgs[0], None, |
| 2266 | "10.0.0.2", "11.0.0.2", |
| 2267 | "2001:10::2", "3001::2"), |
| 2268 | VppGbpEndpoint(self, self.pg2, |
| 2269 | epgs[1], None, |
| 2270 | "10.0.1.1", "11.0.0.3", |
| 2271 | "2001:10:1::1", "3001::3"), |
| 2272 | VppGbpEndpoint(self, self.pg3, |
| 2273 | epgs[2], None, |
| 2274 | "10.0.2.1", "11.0.0.4", |
| 2275 | "2001:10:2::1", "3001::4")] |
| 2276 | |
| 2277 | # |
| 2278 | # Config related to each of the EPGs |
| 2279 | # |
| 2280 | for epg in epgs: |
| 2281 | # IP config on the BVI interfaces |
| 2282 | if epg != epgs[1]: |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 2283 | b4 = VppIpInterfaceBind(self, epg.bvi, |
| 2284 | epg.rd.t4).add_vpp_config() |
| 2285 | b6 = VppIpInterfaceBind(self, epg.bvi, |
| 2286 | epg.rd.t6).add_vpp_config() |
Benoît Ganne | a03d25d | 2019-09-03 17:54:21 +0200 | [diff] [blame] | 2287 | epg.bvi.set_mac(self.router_mac) |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2288 | |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 2289 | if_ip4 = VppIpInterfaceAddress(self, epg.bvi, |
| 2290 | epg.bvi_ip4, 32, |
| 2291 | bind=b4).add_vpp_config() |
| 2292 | if_ip6 = VppIpInterfaceAddress(self, epg.bvi, |
| 2293 | epg.bvi_ip6, 128, |
| 2294 | bind=b6).add_vpp_config() |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2295 | |
| 2296 | # add the BD ARP termination entry for BVI IP |
| 2297 | epg.bd_arp_ip4 = VppBridgeDomainArpEntry(self, epg.bd.bd, |
| 2298 | str(self.router_mac), |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2299 | epg.bvi_ip4) |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2300 | epg.bd_arp_ip4.add_vpp_config() |
| 2301 | |
| 2302 | # EPG in VPP |
| 2303 | epg.add_vpp_config() |
| 2304 | |
| 2305 | # |
| 2306 | # config ep |
| 2307 | # |
| 2308 | for ep in eps: |
| 2309 | ep.add_vpp_config() |
| 2310 | |
| 2311 | self.logger.info(self.vapi.cli("show gbp endpoint")) |
| 2312 | self.logger.info(self.vapi.cli("show interface")) |
| 2313 | self.logger.info(self.vapi.cli("show br")) |
| 2314 | |
| 2315 | # |
| 2316 | # Intra epg allowed without contract |
| 2317 | # |
| 2318 | pkt_intra_epg_220_to_220 = (Ether(src=self.pg0.remote_mac, |
| 2319 | dst=self.pg1.remote_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2320 | IP(src=eps[0].ip4, |
| 2321 | dst=eps[1].ip4) / |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2322 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2323 | Raw(b'\xa5' * 100)) |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2324 | |
| 2325 | self.send_and_expect_bridged(self.pg0, |
| 2326 | pkt_intra_epg_220_to_220 * 65, |
| 2327 | self.pg1) |
| 2328 | |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2329 | pkt_intra_epg_220_to_220 = (Ether(src=self.pg0.remote_mac, |
| 2330 | dst=self.pg1.remote_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2331 | IPv6(src=eps[0].ip6, |
| 2332 | dst=eps[1].ip6) / |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2333 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2334 | Raw(b'\xa5' * 100)) |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2335 | |
| 2336 | self.send_and_expect_bridged6(self.pg0, |
| 2337 | pkt_intra_epg_220_to_220 * 65, |
| 2338 | self.pg1) |
| 2339 | |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2340 | # |
| 2341 | # Inter epg denied without contract |
| 2342 | # |
| 2343 | pkt_inter_epg_220_to_221 = (Ether(src=self.pg0.remote_mac, |
| 2344 | dst=self.pg2.remote_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2345 | IP(src=eps[0].ip4, |
| 2346 | dst=eps[2].ip4) / |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2347 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2348 | Raw(b'\xa5' * 100)) |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2349 | |
| 2350 | self.send_and_assert_no_replies(self.pg0, pkt_inter_epg_220_to_221) |
| 2351 | |
| 2352 | # |
| 2353 | # A uni-directional contract from EPG 220 -> 221 |
| 2354 | # |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 2355 | rule = AclRule(is_permit=1, proto=17) |
| 2356 | rule2 = AclRule(src_prefix=IPv6Network((0, 0)), |
| 2357 | dst_prefix=IPv6Network((0, 0)), is_permit=1, proto=17) |
| 2358 | rule3 = AclRule(is_permit=1, proto=1) |
| 2359 | acl = VppAcl(self, rules=[rule, rule2, rule3]) |
| 2360 | acl.add_vpp_config() |
| 2361 | |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2362 | c1 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 2363 | self, 400, epgs[0].sclass, epgs[1].sclass, acl.acl_index, |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2364 | [VppGbpContractRule( |
| 2365 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 2366 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2367 | []), |
| 2368 | VppGbpContractRule( |
| 2369 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 2370 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2371 | []), |
| 2372 | VppGbpContractRule( |
| 2373 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
| 2374 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2375 | [])], |
| 2376 | [ETH_P_IP, ETH_P_IPV6]) |
| 2377 | c1.add_vpp_config() |
| 2378 | |
| 2379 | self.send_and_expect_bridged(eps[0].itf, |
| 2380 | pkt_inter_epg_220_to_221 * 65, |
| 2381 | eps[2].itf) |
| 2382 | |
| 2383 | pkt_inter_epg_220_to_222 = (Ether(src=self.pg0.remote_mac, |
| 2384 | dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2385 | IP(src=eps[0].ip4, |
| 2386 | dst=eps[3].ip4) / |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2387 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2388 | Raw(b'\xa5' * 100)) |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2389 | self.send_and_assert_no_replies(eps[0].itf, |
| 2390 | pkt_inter_epg_220_to_222 * 65) |
| 2391 | |
| 2392 | # |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2393 | # ping router IP in different BD |
| 2394 | # |
| 2395 | pkt_router_ping_220_to_221 = (Ether(src=self.pg0.remote_mac, |
| 2396 | dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2397 | IP(src=eps[0].ip4, |
| 2398 | dst=epgs[1].bvi_ip4) / |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2399 | ICMP(type='echo-request')) |
| 2400 | |
| 2401 | self.send_and_expect(self.pg0, [pkt_router_ping_220_to_221], self.pg0) |
| 2402 | |
| 2403 | pkt_router_ping_220_to_221 = (Ether(src=self.pg0.remote_mac, |
| 2404 | dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2405 | IPv6(src=eps[0].ip6, |
| 2406 | dst=epgs[1].bvi_ip6) / |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2407 | ICMPv6EchoRequest()) |
| 2408 | |
| 2409 | self.send_and_expect(self.pg0, [pkt_router_ping_220_to_221], self.pg0) |
| 2410 | |
| 2411 | # |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2412 | # contract for the return direction |
| 2413 | # |
| 2414 | c2 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 2415 | self, 400, epgs[1].sclass, epgs[0].sclass, acl.acl_index, |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2416 | [VppGbpContractRule( |
| 2417 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 2418 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2419 | []), |
| 2420 | VppGbpContractRule( |
| 2421 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 2422 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2423 | [])], |
| 2424 | [ETH_P_IP, ETH_P_IPV6]) |
| 2425 | c2.add_vpp_config() |
| 2426 | |
| 2427 | self.send_and_expect_bridged(eps[0].itf, |
| 2428 | pkt_inter_epg_220_to_221 * 65, |
| 2429 | eps[2].itf) |
| 2430 | pkt_inter_epg_221_to_220 = (Ether(src=self.pg2.remote_mac, |
| 2431 | dst=self.pg0.remote_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2432 | IP(src=eps[2].ip4, |
| 2433 | dst=eps[0].ip4) / |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2434 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2435 | Raw(b'\xa5' * 100)) |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2436 | self.send_and_expect_bridged(eps[2].itf, |
| 2437 | pkt_inter_epg_221_to_220 * 65, |
| 2438 | eps[0].itf) |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2439 | pkt_inter_epg_221_to_220 = (Ether(src=self.pg2.remote_mac, |
| 2440 | dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2441 | IP(src=eps[2].ip4, |
| 2442 | dst=eps[0].ip4) / |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2443 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2444 | Raw(b'\xa5' * 100)) |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2445 | self.send_and_expect_routed(eps[2].itf, |
| 2446 | pkt_inter_epg_221_to_220 * 65, |
| 2447 | eps[0].itf, |
| 2448 | str(self.router_mac)) |
| 2449 | pkt_inter_epg_221_to_220 = (Ether(src=self.pg2.remote_mac, |
| 2450 | dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2451 | IPv6(src=eps[2].ip6, |
| 2452 | dst=eps[0].ip6) / |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2453 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2454 | Raw(b'\xa5' * 100)) |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2455 | self.send_and_expect_routed6(eps[2].itf, |
| 2456 | pkt_inter_epg_221_to_220 * 65, |
| 2457 | eps[0].itf, |
| 2458 | str(self.router_mac)) |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2459 | |
| 2460 | # |
| 2461 | # contract between 220 and 222 uni-direction |
| 2462 | # |
| 2463 | c3 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 2464 | self, 400, epgs[0].sclass, epgs[2].sclass, acl.acl_index, |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2465 | [VppGbpContractRule( |
| 2466 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 2467 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2468 | []), |
| 2469 | VppGbpContractRule( |
| 2470 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 2471 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Mohsin Kazmi | fe52dea | 2019-04-18 15:54:58 +0200 | [diff] [blame] | 2472 | [])], |
| 2473 | [ETH_P_IP, ETH_P_IPV6]) |
| 2474 | c3.add_vpp_config() |
| 2475 | |
| 2476 | self.send_and_expect(eps[0].itf, |
| 2477 | pkt_inter_epg_220_to_222 * 65, |
| 2478 | eps[3].itf) |
| 2479 | |
| 2480 | c3.remove_vpp_config() |
| 2481 | c1.remove_vpp_config() |
| 2482 | c2.remove_vpp_config() |
| 2483 | acl.remove_vpp_config() |
| 2484 | |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2485 | def test_gbp_bd_drop_flags(self): |
| 2486 | """ GBP BD drop flags """ |
Mohsin Kazmi | 7363d47 | 2019-04-04 13:22:15 +0200 | [diff] [blame] | 2487 | |
| 2488 | # |
| 2489 | # IP tables |
| 2490 | # |
| 2491 | gt4 = VppIpTable(self, 1) |
| 2492 | gt4.add_vpp_config() |
| 2493 | gt6 = VppIpTable(self, 1, is_ip6=True) |
| 2494 | gt6.add_vpp_config() |
| 2495 | |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 2496 | rd1 = VppGbpRouteDomain(self, 1, 401, gt4, gt6) |
Mohsin Kazmi | 7363d47 | 2019-04-04 13:22:15 +0200 | [diff] [blame] | 2497 | rd1.add_vpp_config() |
| 2498 | |
| 2499 | # |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2500 | # a GBP bridge domain with a BVI only |
Mohsin Kazmi | 7363d47 | 2019-04-04 13:22:15 +0200 | [diff] [blame] | 2501 | # |
| 2502 | bd1 = VppBridgeDomain(self, 1) |
| 2503 | bd1.add_vpp_config() |
| 2504 | |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2505 | gbd1 = VppGbpBridgeDomain(self, bd1, rd1, self.loop0, |
| 2506 | None, None, |
| 2507 | uu_drop=True, bm_drop=True) |
Mohsin Kazmi | 7363d47 | 2019-04-04 13:22:15 +0200 | [diff] [blame] | 2508 | gbd1.add_vpp_config() |
| 2509 | |
| 2510 | self.logger.info(self.vapi.cli("sh bridge 1 detail")) |
| 2511 | self.logger.info(self.vapi.cli("sh gbp bridge")) |
| 2512 | |
| 2513 | # ... and has a /32 applied |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 2514 | ip_addr = VppIpInterfaceAddress(self, gbd1.bvi, |
| 2515 | "10.0.0.128", 32).add_vpp_config() |
Mohsin Kazmi | 7363d47 | 2019-04-04 13:22:15 +0200 | [diff] [blame] | 2516 | |
| 2517 | # |
| 2518 | # The Endpoint-group |
| 2519 | # |
| 2520 | epg_220 = VppGbpEndpointGroup(self, 220, 112, rd1, gbd1, |
| 2521 | None, self.loop0, |
| 2522 | "10.0.0.128", |
| 2523 | "2001:10::128", |
Neale Ranns | 8d0d8d2 | 2020-04-07 08:44:20 +0000 | [diff] [blame] | 2524 | VppGbpEndpointRetention(3)) |
Mohsin Kazmi | 7363d47 | 2019-04-04 13:22:15 +0200 | [diff] [blame] | 2525 | epg_220.add_vpp_config() |
| 2526 | |
| 2527 | ep = VppGbpEndpoint(self, self.pg0, |
| 2528 | epg_220, None, |
| 2529 | "10.0.0.127", "11.0.0.127", |
| 2530 | "2001:10::1", "3001::1") |
| 2531 | ep.add_vpp_config() |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2532 | |
Mohsin Kazmi | 7363d47 | 2019-04-04 13:22:15 +0200 | [diff] [blame] | 2533 | # |
| 2534 | # send UU/BM packet from the local EP with UU drop and BM drop enabled |
| 2535 | # in bd |
| 2536 | # |
| 2537 | self.logger.info(self.vapi.cli("sh bridge 1 detail")) |
| 2538 | self.logger.info(self.vapi.cli("sh gbp bridge")) |
| 2539 | p_uu = (Ether(src=ep.mac, dst="00:11:11:11:11:11") / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2540 | IP(dst="10.0.0.133", src=ep.ip4) / |
Mohsin Kazmi | 7363d47 | 2019-04-04 13:22:15 +0200 | [diff] [blame] | 2541 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2542 | Raw(b'\xa5' * 100)) |
Mohsin Kazmi | 7363d47 | 2019-04-04 13:22:15 +0200 | [diff] [blame] | 2543 | self.send_and_assert_no_replies(ep.itf, [p_uu]) |
| 2544 | |
| 2545 | p_bm = (Ether(src=ep.mac, dst="ff:ff:ff:ff:ff:ff") / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2546 | IP(dst="10.0.0.133", src=ep.ip4) / |
Mohsin Kazmi | 7363d47 | 2019-04-04 13:22:15 +0200 | [diff] [blame] | 2547 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2548 | Raw(b'\xa5' * 100)) |
Mohsin Kazmi | 7363d47 | 2019-04-04 13:22:15 +0200 | [diff] [blame] | 2549 | self.send_and_assert_no_replies(ep.itf, [p_bm]) |
| 2550 | |
| 2551 | self.pg3.unconfig_ip4() |
Mohsin Kazmi | 7363d47 | 2019-04-04 13:22:15 +0200 | [diff] [blame] | 2552 | |
| 2553 | self.logger.info(self.vapi.cli("sh int")) |
| 2554 | |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2555 | def test_gbp_bd_arp_flags(self): |
| 2556 | """ GBP BD arp flags """ |
| 2557 | |
| 2558 | # |
| 2559 | # IP tables |
| 2560 | # |
| 2561 | gt4 = VppIpTable(self, 1) |
| 2562 | gt4.add_vpp_config() |
| 2563 | gt6 = VppIpTable(self, 1, is_ip6=True) |
| 2564 | gt6.add_vpp_config() |
| 2565 | |
| 2566 | rd1 = VppGbpRouteDomain(self, 1, 401, gt4, gt6) |
| 2567 | rd1.add_vpp_config() |
| 2568 | |
| 2569 | # |
| 2570 | # Pg4 hosts the IP6 UU-flood VXLAN tunnel |
| 2571 | # |
| 2572 | self.pg4.config_ip4() |
| 2573 | self.pg4.resolve_arp() |
| 2574 | |
| 2575 | # |
| 2576 | # Add a mcast destination VXLAN-GBP tunnel for B&M traffic |
| 2577 | # |
| 2578 | tun_uu = VppVxlanGbpTunnel(self, self.pg4.local_ip4, |
| 2579 | "239.1.1.1", 88, |
| 2580 | mcast_itf=self.pg4) |
| 2581 | tun_uu.add_vpp_config() |
| 2582 | |
| 2583 | # |
| 2584 | # a GBP bridge domain with a BVI and a UU-flood interface |
| 2585 | # |
| 2586 | bd1 = VppBridgeDomain(self, 1) |
| 2587 | bd1.add_vpp_config() |
| 2588 | |
| 2589 | gbd1 = VppGbpBridgeDomain(self, bd1, rd1, self.loop0, |
| 2590 | tun_uu, None, |
| 2591 | ucast_arp=True) |
| 2592 | gbd1.add_vpp_config() |
| 2593 | |
| 2594 | # ... and has a /32 applied |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 2595 | ip_addr = VppIpInterfaceAddress(self, gbd1.bvi, |
| 2596 | "10.0.0.128", 32).add_vpp_config() |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2597 | |
| 2598 | # |
| 2599 | # The Endpoint-group |
| 2600 | # |
| 2601 | epg_220 = VppGbpEndpointGroup(self, 220, 112, rd1, gbd1, |
| 2602 | None, self.loop0, |
| 2603 | "10.0.0.128", |
| 2604 | "2001:10::128", |
| 2605 | VppGbpEndpointRetention(2)) |
| 2606 | epg_220.add_vpp_config() |
| 2607 | |
| 2608 | ep = VppGbpEndpoint(self, self.pg0, |
| 2609 | epg_220, None, |
| 2610 | "10.0.0.127", "11.0.0.127", |
| 2611 | "2001:10::1", "3001::1") |
| 2612 | ep.add_vpp_config() |
| 2613 | |
| 2614 | # |
| 2615 | # send ARP packet from the local EP expect it on the uu interface |
| 2616 | # |
| 2617 | self.logger.info(self.vapi.cli("sh bridge 1 detail")) |
| 2618 | self.logger.info(self.vapi.cli("sh gbp bridge")) |
| 2619 | p_arp = (Ether(src=ep.mac, dst="ff:ff:ff:ff:ff:ff") / |
| 2620 | ARP(op="who-has", |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2621 | psrc=ep.ip4, pdst="10.0.0.99", |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2622 | hwsrc=ep.mac, |
| 2623 | hwdst="ff:ff:ff:ff:ff:ff")) |
| 2624 | self.send_and_expect(ep.itf, [p_arp], self.pg4) |
| 2625 | |
| 2626 | self.pg4.unconfig_ip4() |
| 2627 | |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2628 | def test_gbp_learn_vlan_l2(self): |
| 2629 | """ GBP L2 Endpoint w/ VLANs""" |
| 2630 | |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 2631 | ep_flags = VppEnum.vl_api_gbp_endpoint_flags_t |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2632 | learnt = [{'mac': '00:00:11:11:11:01', |
| 2633 | 'ip': '10.0.0.1', |
| 2634 | 'ip6': '2001:10::2'}, |
| 2635 | {'mac': '00:00:11:11:11:02', |
| 2636 | 'ip': '10.0.0.2', |
| 2637 | 'ip6': '2001:10::3'}] |
| 2638 | |
| 2639 | # |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2640 | # IP tables |
| 2641 | # |
| 2642 | gt4 = VppIpTable(self, 1) |
| 2643 | gt4.add_vpp_config() |
| 2644 | gt6 = VppIpTable(self, 1, is_ip6=True) |
| 2645 | gt6.add_vpp_config() |
| 2646 | |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 2647 | rd1 = VppGbpRouteDomain(self, 1, 401, gt4, gt6) |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2648 | rd1.add_vpp_config() |
| 2649 | |
| 2650 | # |
| 2651 | # Pg2 hosts the vxlan tunnel, hosts on pg2 to act as TEPs |
| 2652 | # |
| 2653 | self.pg2.config_ip4() |
| 2654 | self.pg2.resolve_arp() |
| 2655 | self.pg2.generate_remote_hosts(4) |
| 2656 | self.pg2.configure_ipv4_neighbors() |
| 2657 | self.pg3.config_ip4() |
| 2658 | self.pg3.resolve_arp() |
| 2659 | |
| 2660 | # |
| 2661 | # The EP will be on a vlan sub-interface |
| 2662 | # |
| 2663 | vlan_11 = VppDot1QSubint(self, self.pg0, 11) |
| 2664 | vlan_11.admin_up() |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 2665 | self.vapi.l2_interface_vlan_tag_rewrite( |
| 2666 | sw_if_index=vlan_11.sw_if_index, vtr_op=L2_VTR_OP.L2_POP_1, |
| 2667 | push_dot1q=11) |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2668 | |
| 2669 | bd_uu_fwd = VppVxlanGbpTunnel(self, self.pg3.local_ip4, |
| 2670 | self.pg3.remote_ip4, 116) |
| 2671 | bd_uu_fwd.add_vpp_config() |
| 2672 | |
| 2673 | # |
| 2674 | # a GBP bridge domain with a BVI and a UU-flood interface |
| 2675 | # The BD is marked as do not learn, so no endpoints are ever |
| 2676 | # learnt in this BD. |
| 2677 | # |
| 2678 | bd1 = VppBridgeDomain(self, 1) |
| 2679 | bd1.add_vpp_config() |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 2680 | gbd1 = VppGbpBridgeDomain(self, bd1, rd1, self.loop0, bd_uu_fwd, |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2681 | learn=False) |
| 2682 | gbd1.add_vpp_config() |
| 2683 | |
| 2684 | self.logger.info(self.vapi.cli("sh bridge 1 detail")) |
| 2685 | self.logger.info(self.vapi.cli("sh gbp bridge")) |
| 2686 | |
| 2687 | # ... and has a /32 applied |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 2688 | ip_addr = VppIpInterfaceAddress(self, gbd1.bvi, |
| 2689 | "10.0.0.128", 32).add_vpp_config() |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2690 | |
| 2691 | # |
| 2692 | # The Endpoint-group in which we are learning endpoints |
| 2693 | # |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 2694 | epg_220 = VppGbpEndpointGroup(self, 220, 441, rd1, gbd1, |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2695 | None, self.loop0, |
| 2696 | "10.0.0.128", |
Neale Ranns | 32f6d8e | 2019-03-05 04:22:08 -0800 | [diff] [blame] | 2697 | "2001:10::128", |
Neale Ranns | 8d0d8d2 | 2020-04-07 08:44:20 +0000 | [diff] [blame] | 2698 | VppGbpEndpointRetention(4)) |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2699 | epg_220.add_vpp_config() |
| 2700 | |
| 2701 | # |
| 2702 | # The VXLAN GBP tunnel is a bridge-port and has L2 endpoint |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 2703 | # learning enabled |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2704 | # |
| 2705 | vx_tun_l2_1 = VppGbpVxlanTunnel( |
| 2706 | self, 99, bd1.bd_id, |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 2707 | VppEnum.vl_api_gbp_vxlan_tunnel_mode_t.GBP_VXLAN_TUNNEL_MODE_L2, |
| 2708 | self.pg2.local_ip4) |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2709 | vx_tun_l2_1.add_vpp_config() |
| 2710 | |
| 2711 | # |
| 2712 | # A static endpoint that the learnt endpoints are trying to |
| 2713 | # talk to |
| 2714 | # |
| 2715 | ep = VppGbpEndpoint(self, vlan_11, |
| 2716 | epg_220, None, |
| 2717 | "10.0.0.127", "11.0.0.127", |
| 2718 | "2001:10::1", "3001::1") |
| 2719 | ep.add_vpp_config() |
| 2720 | |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2721 | self.assertTrue(find_route(self, ep.ip4, 32, table_id=1)) |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2722 | |
| 2723 | # |
| 2724 | # Send to the static EP |
| 2725 | # |
| 2726 | for ii, l in enumerate(learnt): |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 2727 | # a packet with an sclass from a known EPG |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2728 | # arriving on an unknown TEP |
| 2729 | p = (Ether(src=self.pg2.remote_mac, |
| 2730 | dst=self.pg2.local_mac) / |
| 2731 | IP(src=self.pg2.remote_hosts[1].ip4, |
| 2732 | dst=self.pg2.local_ip4) / |
| 2733 | UDP(sport=1234, dport=48879) / |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 2734 | VXLAN(vni=99, gpid=441, flags=0x88) / |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2735 | Ether(src=l['mac'], dst=ep.mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2736 | IP(src=l['ip'], dst=ep.ip4) / |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2737 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2738 | Raw(b'\xa5' * 100)) |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2739 | |
| 2740 | rxs = self.send_and_expect(self.pg2, [p], self.pg0) |
| 2741 | |
| 2742 | # |
| 2743 | # packet to EP has the EP's vlan tag |
| 2744 | # |
| 2745 | for rx in rxs: |
| 2746 | self.assertEqual(rx[Dot1Q].vlan, 11) |
| 2747 | |
| 2748 | # |
| 2749 | # the EP is not learnt since the BD setting prevents it |
| 2750 | # also no TEP too |
| 2751 | # |
| 2752 | self.assertFalse(find_gbp_endpoint(self, |
| 2753 | vx_tun_l2_1.sw_if_index, |
| 2754 | mac=l['mac'])) |
| 2755 | self.assertEqual(INDEX_INVALID, |
| 2756 | find_vxlan_gbp_tunnel( |
| 2757 | self, |
| 2758 | self.pg2.local_ip4, |
| 2759 | self.pg2.remote_hosts[1].ip4, |
| 2760 | 99)) |
| 2761 | |
| 2762 | self.assertEqual(len(self.vapi.gbp_endpoint_dump()), 1) |
| 2763 | |
| 2764 | # |
| 2765 | # static to remotes |
| 2766 | # we didn't learn the remotes so they are sent to the UU-fwd |
| 2767 | # |
| 2768 | for l in learnt: |
| 2769 | p = (Ether(src=ep.mac, dst=l['mac']) / |
| 2770 | Dot1Q(vlan=11) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2771 | IP(dst=l['ip'], src=ep.ip4) / |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2772 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2773 | Raw(b'\xa5' * 100)) |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2774 | |
| 2775 | rxs = self.send_and_expect(self.pg0, p * 17, self.pg3) |
| 2776 | |
| 2777 | for rx in rxs: |
| 2778 | self.assertEqual(rx[IP].src, self.pg3.local_ip4) |
| 2779 | self.assertEqual(rx[IP].dst, self.pg3.remote_ip4) |
| 2780 | self.assertEqual(rx[UDP].dport, 48879) |
| 2781 | # the UDP source port is a random value for hashing |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 2782 | self.assertEqual(rx[VXLAN].gpid, 441) |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2783 | self.assertEqual(rx[VXLAN].vni, 116) |
| 2784 | self.assertTrue(rx[VXLAN].flags.G) |
| 2785 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 2786 | self.assertFalse(rx[VXLAN].gpflags.A) |
| 2787 | self.assertFalse(rx[VXLAN].gpflags.D) |
| 2788 | |
| 2789 | self.pg2.unconfig_ip4() |
| 2790 | self.pg3.unconfig_ip4() |
| 2791 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2792 | def test_gbp_learn_l3(self): |
| 2793 | """ GBP L3 Endpoint Learning """ |
| 2794 | |
Paul Vinciguerra | 9673e3e | 2019-05-10 20:41:08 -0400 | [diff] [blame] | 2795 | self.vapi.cli("set logging class gbp level debug") |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 2796 | |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 2797 | ep_flags = VppEnum.vl_api_gbp_endpoint_flags_t |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2798 | routed_dst_mac = "00:0c:0c:0c:0c:0c" |
| 2799 | routed_src_mac = "00:22:bd:f8:19:ff" |
| 2800 | |
| 2801 | learnt = [{'mac': '00:00:11:11:11:02', |
| 2802 | 'ip': '10.0.1.2', |
| 2803 | 'ip6': '2001:10::2'}, |
| 2804 | {'mac': '00:00:11:11:11:03', |
| 2805 | 'ip': '10.0.1.3', |
| 2806 | 'ip6': '2001:10::3'}] |
| 2807 | |
| 2808 | # |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2809 | # IP tables |
| 2810 | # |
| 2811 | t4 = VppIpTable(self, 1) |
| 2812 | t4.add_vpp_config() |
| 2813 | t6 = VppIpTable(self, 1, True) |
| 2814 | t6.add_vpp_config() |
| 2815 | |
| 2816 | tun_ip4_uu = VppVxlanGbpTunnel(self, self.pg4.local_ip4, |
| 2817 | self.pg4.remote_ip4, 114) |
| 2818 | tun_ip6_uu = VppVxlanGbpTunnel(self, self.pg4.local_ip4, |
| 2819 | self.pg4.remote_ip4, 116) |
| 2820 | tun_ip4_uu.add_vpp_config() |
| 2821 | tun_ip6_uu.add_vpp_config() |
| 2822 | |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 2823 | rd1 = VppGbpRouteDomain(self, 2, 401, t4, t6, tun_ip4_uu, tun_ip6_uu) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2824 | rd1.add_vpp_config() |
| 2825 | |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 2826 | self.loop0.set_mac(self.router_mac) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2827 | |
| 2828 | # |
| 2829 | # Bind the BVI to the RD |
| 2830 | # |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 2831 | b4 = VppIpInterfaceBind(self, self.loop0, t4).add_vpp_config() |
| 2832 | b6 = VppIpInterfaceBind(self, self.loop0, t6).add_vpp_config() |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2833 | |
| 2834 | # |
| 2835 | # Pg2 hosts the vxlan tunnel |
| 2836 | # hosts on pg2 to act as TEPs |
| 2837 | # pg3 is BD uu-fwd |
| 2838 | # pg4 is RD uu-fwd |
| 2839 | # |
| 2840 | self.pg2.config_ip4() |
| 2841 | self.pg2.resolve_arp() |
| 2842 | self.pg2.generate_remote_hosts(4) |
| 2843 | self.pg2.configure_ipv4_neighbors() |
| 2844 | self.pg3.config_ip4() |
| 2845 | self.pg3.resolve_arp() |
| 2846 | self.pg4.config_ip4() |
| 2847 | self.pg4.resolve_arp() |
| 2848 | |
| 2849 | # |
| 2850 | # a GBP bridge domain with a BVI and a UU-flood interface |
| 2851 | # |
| 2852 | bd1 = VppBridgeDomain(self, 1) |
| 2853 | bd1.add_vpp_config() |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 2854 | gbd1 = VppGbpBridgeDomain(self, bd1, rd1, self.loop0, self.pg3) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2855 | gbd1.add_vpp_config() |
| 2856 | |
| 2857 | self.logger.info(self.vapi.cli("sh bridge 1 detail")) |
| 2858 | self.logger.info(self.vapi.cli("sh gbp bridge")) |
| 2859 | self.logger.info(self.vapi.cli("sh gbp route")) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2860 | |
| 2861 | # ... and has a /32 and /128 applied |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 2862 | ip4_addr = VppIpInterfaceAddress(self, gbd1.bvi, |
| 2863 | "10.0.0.128", 32, |
| 2864 | bind=b4).add_vpp_config() |
| 2865 | ip6_addr = VppIpInterfaceAddress(self, gbd1.bvi, |
| 2866 | "2001:10::128", 128, |
| 2867 | bind=b6).add_vpp_config() |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2868 | |
| 2869 | # |
| 2870 | # The Endpoint-group in which we are learning endpoints |
| 2871 | # |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 2872 | epg_220 = VppGbpEndpointGroup(self, 220, 441, rd1, gbd1, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2873 | None, self.loop0, |
| 2874 | "10.0.0.128", |
Neale Ranns | 32f6d8e | 2019-03-05 04:22:08 -0800 | [diff] [blame] | 2875 | "2001:10::128", |
Neale Ranns | 8d0d8d2 | 2020-04-07 08:44:20 +0000 | [diff] [blame] | 2876 | VppGbpEndpointRetention(4)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2877 | epg_220.add_vpp_config() |
| 2878 | |
| 2879 | # |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 2880 | # The VXLAN GBP tunnel is in L3 mode with learning enabled |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2881 | # |
| 2882 | vx_tun_l3 = VppGbpVxlanTunnel( |
| 2883 | self, 101, rd1.rd_id, |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 2884 | VppEnum.vl_api_gbp_vxlan_tunnel_mode_t.GBP_VXLAN_TUNNEL_MODE_L3, |
| 2885 | self.pg2.local_ip4) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2886 | vx_tun_l3.add_vpp_config() |
| 2887 | |
| 2888 | # |
| 2889 | # A static endpoint that the learnt endpoints are trying to |
| 2890 | # talk to |
| 2891 | # |
| 2892 | ep = VppGbpEndpoint(self, self.pg0, |
| 2893 | epg_220, None, |
| 2894 | "10.0.0.127", "11.0.0.127", |
| 2895 | "2001:10::1", "3001::1") |
| 2896 | ep.add_vpp_config() |
| 2897 | |
| 2898 | # |
| 2899 | # learn some remote IPv4 EPs |
| 2900 | # |
| 2901 | for ii, l in enumerate(learnt): |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 2902 | # a packet with an sclass from a known EPG |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2903 | # arriving on an unknown TEP |
| 2904 | p = (Ether(src=self.pg2.remote_mac, |
| 2905 | dst=self.pg2.local_mac) / |
| 2906 | IP(src=self.pg2.remote_hosts[1].ip4, |
| 2907 | dst=self.pg2.local_ip4) / |
| 2908 | UDP(sport=1234, dport=48879) / |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 2909 | VXLAN(vni=101, gpid=441, flags=0x88) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2910 | Ether(src=l['mac'], dst="00:00:00:11:11:11") / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2911 | IP(src=l['ip'], dst=ep.ip4) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2912 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2913 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2914 | |
| 2915 | rx = self.send_and_expect(self.pg2, [p], self.pg0) |
| 2916 | |
| 2917 | # the new TEP |
| 2918 | tep1_sw_if_index = find_vxlan_gbp_tunnel( |
| 2919 | self, |
| 2920 | self.pg2.local_ip4, |
| 2921 | self.pg2.remote_hosts[1].ip4, |
| 2922 | vx_tun_l3.vni) |
| 2923 | self.assertNotEqual(INDEX_INVALID, tep1_sw_if_index) |
| 2924 | |
| 2925 | # endpoint learnt via the parent GBP-vxlan interface |
| 2926 | self.assertTrue(find_gbp_endpoint(self, |
| 2927 | vx_tun_l3._sw_if_index, |
| 2928 | ip=l['ip'])) |
| 2929 | |
| 2930 | # |
| 2931 | # Static IPv4 EP replies to learnt |
| 2932 | # |
| 2933 | for l in learnt: |
| 2934 | p = (Ether(src=ep.mac, dst=self.loop0.local_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2935 | IP(dst=l['ip'], src=ep.ip4) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2936 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2937 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2938 | |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 2939 | rxs = self.send_and_expect(self.pg0, p * 1, self.pg2) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2940 | |
| 2941 | for rx in rxs: |
| 2942 | self.assertEqual(rx[IP].src, self.pg2.local_ip4) |
| 2943 | self.assertEqual(rx[IP].dst, self.pg2.remote_hosts[1].ip4) |
| 2944 | self.assertEqual(rx[UDP].dport, 48879) |
| 2945 | # the UDP source port is a random value for hashing |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 2946 | self.assertEqual(rx[VXLAN].gpid, 441) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2947 | self.assertEqual(rx[VXLAN].vni, 101) |
| 2948 | self.assertTrue(rx[VXLAN].flags.G) |
| 2949 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 2950 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 2951 | self.assertFalse(rx[VXLAN].gpflags.D) |
| 2952 | |
| 2953 | inner = rx[VXLAN].payload |
| 2954 | |
| 2955 | self.assertEqual(inner[Ether].src, routed_src_mac) |
| 2956 | self.assertEqual(inner[Ether].dst, routed_dst_mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2957 | self.assertEqual(inner[IP].src, ep.ip4) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2958 | self.assertEqual(inner[IP].dst, l['ip']) |
| 2959 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2960 | for l in learnt: |
| 2961 | self.assertFalse(find_gbp_endpoint(self, |
| 2962 | tep1_sw_if_index, |
| 2963 | ip=l['ip'])) |
| 2964 | |
| 2965 | # |
| 2966 | # learn some remote IPv6 EPs |
| 2967 | # |
| 2968 | for ii, l in enumerate(learnt): |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 2969 | # a packet with an sclass from a known EPG |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2970 | # arriving on an unknown TEP |
| 2971 | p = (Ether(src=self.pg2.remote_mac, |
| 2972 | dst=self.pg2.local_mac) / |
| 2973 | IP(src=self.pg2.remote_hosts[1].ip4, |
| 2974 | dst=self.pg2.local_ip4) / |
| 2975 | UDP(sport=1234, dport=48879) / |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 2976 | VXLAN(vni=101, gpid=441, flags=0x88) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2977 | Ether(src=l['mac'], dst="00:00:00:11:11:11") / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 2978 | IPv6(src=l['ip6'], dst=ep.ip6) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2979 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 2980 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2981 | |
| 2982 | rx = self.send_and_expect(self.pg2, [p], self.pg0) |
| 2983 | |
| 2984 | # the new TEP |
| 2985 | tep1_sw_if_index = find_vxlan_gbp_tunnel( |
| 2986 | self, |
| 2987 | self.pg2.local_ip4, |
| 2988 | self.pg2.remote_hosts[1].ip4, |
| 2989 | vx_tun_l3.vni) |
| 2990 | self.assertNotEqual(INDEX_INVALID, tep1_sw_if_index) |
| 2991 | |
| 2992 | self.logger.info(self.vapi.cli("show gbp bridge")) |
| 2993 | self.logger.info(self.vapi.cli("show vxlan-gbp tunnel")) |
| 2994 | self.logger.info(self.vapi.cli("show gbp vxlan")) |
| 2995 | self.logger.info(self.vapi.cli("show int addr")) |
| 2996 | |
| 2997 | # endpoint learnt via the TEP |
| 2998 | self.assertTrue(find_gbp_endpoint(self, ip=l['ip6'])) |
| 2999 | |
| 3000 | self.logger.info(self.vapi.cli("show gbp endpoint")) |
| 3001 | self.logger.info(self.vapi.cli("show ip fib index 1 %s" % l['ip'])) |
| 3002 | |
| 3003 | # |
| 3004 | # Static EP replies to learnt |
| 3005 | # |
| 3006 | for l in learnt: |
| 3007 | p = (Ether(src=ep.mac, dst=self.loop0.local_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3008 | IPv6(dst=l['ip6'], src=ep.ip6) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3009 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3010 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3011 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 3012 | rxs = self.send_and_expect(self.pg0, p * NUM_PKTS, self.pg2) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3013 | |
| 3014 | for rx in rxs: |
| 3015 | self.assertEqual(rx[IP].src, self.pg2.local_ip4) |
| 3016 | self.assertEqual(rx[IP].dst, self.pg2.remote_hosts[1].ip4) |
| 3017 | self.assertEqual(rx[UDP].dport, 48879) |
| 3018 | # the UDP source port is a random value for hashing |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 3019 | self.assertEqual(rx[VXLAN].gpid, 441) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3020 | self.assertEqual(rx[VXLAN].vni, 101) |
| 3021 | self.assertTrue(rx[VXLAN].flags.G) |
| 3022 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 3023 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 3024 | self.assertFalse(rx[VXLAN].gpflags.D) |
| 3025 | |
| 3026 | inner = rx[VXLAN].payload |
| 3027 | |
| 3028 | self.assertEqual(inner[Ether].src, routed_src_mac) |
| 3029 | self.assertEqual(inner[Ether].dst, routed_dst_mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3030 | self.assertEqual(inner[IPv6].src, ep.ip6) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3031 | self.assertEqual(inner[IPv6].dst, l['ip6']) |
| 3032 | |
| 3033 | self.logger.info(self.vapi.cli("sh gbp endpoint")) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3034 | for l in learnt: |
Neale Ranns | 774356a | 2018-11-29 12:02:16 +0000 | [diff] [blame] | 3035 | self.wait_for_ep_timeout(ip=l['ip']) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3036 | |
| 3037 | # |
| 3038 | # Static sends to unknown EP with no route |
| 3039 | # |
| 3040 | p = (Ether(src=ep.mac, dst=self.loop0.local_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3041 | IP(dst="10.0.0.99", src=ep.ip4) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3042 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3043 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3044 | |
| 3045 | self.send_and_assert_no_replies(self.pg0, [p]) |
| 3046 | |
| 3047 | # |
| 3048 | # Add a route to static EP's v4 and v6 subnet |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3049 | # |
| 3050 | se_10_24 = VppGbpSubnet( |
| 3051 | self, rd1, "10.0.0.0", 24, |
| 3052 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_TRANSPORT) |
| 3053 | se_10_24.add_vpp_config() |
| 3054 | |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 3055 | # |
| 3056 | # static pings router |
| 3057 | # |
| 3058 | p = (Ether(src=ep.mac, dst=self.loop0.local_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3059 | IP(dst=epg_220.bvi_ip4, src=ep.ip4) / |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 3060 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3061 | Raw(b'\xa5' * 100)) |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 3062 | |
| 3063 | self.send_and_expect(self.pg0, p * NUM_PKTS, self.pg0) |
| 3064 | |
| 3065 | p = (Ether(src=ep.mac, dst=self.loop0.local_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3066 | IPv6(dst=epg_220.bvi_ip6, src=ep.ip6) / |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 3067 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3068 | Raw(b'\xa5' * 100)) |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 3069 | |
| 3070 | self.send_and_expect(self.pg0, p * NUM_PKTS, self.pg0) |
| 3071 | |
| 3072 | # |
| 3073 | # packets to address in the subnet are sent on the uu-fwd |
| 3074 | # |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3075 | p = (Ether(src=ep.mac, dst=self.loop0.local_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3076 | IP(dst="10.0.0.99", src=ep.ip4) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3077 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3078 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3079 | |
| 3080 | rxs = self.send_and_expect(self.pg0, [p], self.pg4) |
| 3081 | for rx in rxs: |
| 3082 | self.assertEqual(rx[IP].src, self.pg4.local_ip4) |
| 3083 | self.assertEqual(rx[IP].dst, self.pg4.remote_ip4) |
| 3084 | self.assertEqual(rx[UDP].dport, 48879) |
| 3085 | # the UDP source port is a random value for hashing |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 3086 | self.assertEqual(rx[VXLAN].gpid, 441) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3087 | self.assertEqual(rx[VXLAN].vni, 114) |
| 3088 | self.assertTrue(rx[VXLAN].flags.G) |
| 3089 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 3090 | # policy is not applied to packets sent to the uu-fwd interfaces |
| 3091 | self.assertFalse(rx[VXLAN].gpflags.A) |
| 3092 | self.assertFalse(rx[VXLAN].gpflags.D) |
| 3093 | |
| 3094 | # |
| 3095 | # learn some remote IPv4 EPs |
| 3096 | # |
| 3097 | for ii, l in enumerate(learnt): |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 3098 | # a packet with an sclass from a known EPG |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3099 | # arriving on an unknown TEP |
| 3100 | p = (Ether(src=self.pg2.remote_mac, |
| 3101 | dst=self.pg2.local_mac) / |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 3102 | IP(src=self.pg2.remote_hosts[2].ip4, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3103 | dst=self.pg2.local_ip4) / |
| 3104 | UDP(sport=1234, dport=48879) / |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 3105 | VXLAN(vni=101, gpid=441, flags=0x88) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3106 | Ether(src=l['mac'], dst="00:00:00:11:11:11") / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3107 | IP(src=l['ip'], dst=ep.ip4) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3108 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3109 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3110 | |
| 3111 | rx = self.send_and_expect(self.pg2, [p], self.pg0) |
| 3112 | |
| 3113 | # the new TEP |
| 3114 | tep1_sw_if_index = find_vxlan_gbp_tunnel( |
| 3115 | self, |
| 3116 | self.pg2.local_ip4, |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 3117 | self.pg2.remote_hosts[2].ip4, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3118 | vx_tun_l3.vni) |
| 3119 | self.assertNotEqual(INDEX_INVALID, tep1_sw_if_index) |
| 3120 | |
| 3121 | # endpoint learnt via the parent GBP-vxlan interface |
| 3122 | self.assertTrue(find_gbp_endpoint(self, |
| 3123 | vx_tun_l3._sw_if_index, |
| 3124 | ip=l['ip'])) |
| 3125 | |
| 3126 | # |
| 3127 | # Add a remote endpoint from the API |
| 3128 | # |
| 3129 | rep_88 = VppGbpEndpoint(self, vx_tun_l3, |
| 3130 | epg_220, None, |
| 3131 | "10.0.0.88", "11.0.0.88", |
| 3132 | "2001:10::88", "3001::88", |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 3133 | ep_flags.GBP_API_ENDPOINT_FLAG_REMOTE, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3134 | self.pg2.local_ip4, |
Neale Ranns | 3eea9de | 2019-06-21 02:09:25 -0700 | [diff] [blame] | 3135 | self.pg2.remote_hosts[2].ip4, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3136 | mac=None) |
| 3137 | rep_88.add_vpp_config() |
| 3138 | |
| 3139 | # |
| 3140 | # Add a remote endpoint from the API that matches an existing one |
Neale Ranns | 3eea9de | 2019-06-21 02:09:25 -0700 | [diff] [blame] | 3141 | # this is a lower priority, hence the packet is sent to the DP leanrt |
| 3142 | # TEP |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3143 | # |
| 3144 | rep_2 = VppGbpEndpoint(self, vx_tun_l3, |
| 3145 | epg_220, None, |
| 3146 | learnt[0]['ip'], "11.0.0.101", |
| 3147 | learnt[0]['ip6'], "3001::101", |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 3148 | ep_flags.GBP_API_ENDPOINT_FLAG_REMOTE, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3149 | self.pg2.local_ip4, |
| 3150 | self.pg2.remote_hosts[1].ip4, |
| 3151 | mac=None) |
| 3152 | rep_2.add_vpp_config() |
| 3153 | |
| 3154 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 3155 | # Add a route to the learned EP's v4 subnet |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3156 | # packets should be send on the v4/v6 uu=fwd interface resp. |
| 3157 | # |
| 3158 | se_10_1_24 = VppGbpSubnet( |
| 3159 | self, rd1, "10.0.1.0", 24, |
| 3160 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_TRANSPORT) |
| 3161 | se_10_1_24.add_vpp_config() |
| 3162 | |
| 3163 | self.logger.info(self.vapi.cli("show gbp endpoint")) |
| 3164 | |
| 3165 | ips = ["10.0.0.88", learnt[0]['ip']] |
| 3166 | for ip in ips: |
| 3167 | p = (Ether(src=ep.mac, dst=self.loop0.local_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3168 | IP(dst=ip, src=ep.ip4) / |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3169 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3170 | Raw(b'\xa5' * 100)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3171 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 3172 | rxs = self.send_and_expect(self.pg0, p * NUM_PKTS, self.pg2) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3173 | |
| 3174 | for rx in rxs: |
| 3175 | self.assertEqual(rx[IP].src, self.pg2.local_ip4) |
Neale Ranns | 3eea9de | 2019-06-21 02:09:25 -0700 | [diff] [blame] | 3176 | self.assertEqual(rx[IP].dst, self.pg2.remote_hosts[2].ip4) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3177 | self.assertEqual(rx[UDP].dport, 48879) |
| 3178 | # the UDP source port is a random value for hashing |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 3179 | self.assertEqual(rx[VXLAN].gpid, 441) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3180 | self.assertEqual(rx[VXLAN].vni, 101) |
| 3181 | self.assertTrue(rx[VXLAN].flags.G) |
| 3182 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 3183 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 3184 | self.assertFalse(rx[VXLAN].gpflags.D) |
| 3185 | |
| 3186 | inner = rx[VXLAN].payload |
| 3187 | |
| 3188 | self.assertEqual(inner[Ether].src, routed_src_mac) |
| 3189 | self.assertEqual(inner[Ether].dst, routed_dst_mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3190 | self.assertEqual(inner[IP].src, ep.ip4) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3191 | self.assertEqual(inner[IP].dst, ip) |
| 3192 | |
| 3193 | # |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3194 | # remove the API remote EPs, only API sourced is gone, the DP |
| 3195 | # learnt one remains |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3196 | # |
| 3197 | rep_88.remove_vpp_config() |
| 3198 | rep_2.remove_vpp_config() |
| 3199 | |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3200 | self.assertTrue(find_gbp_endpoint(self, ip=rep_2.ip4)) |
Neale Ranns | 00a469d | 2018-12-20 06:12:19 -0800 | [diff] [blame] | 3201 | |
| 3202 | p = (Ether(src=ep.mac, dst=self.loop0.local_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3203 | IP(src=ep.ip4, dst=rep_2.ip4) / |
Neale Ranns | 00a469d | 2018-12-20 06:12:19 -0800 | [diff] [blame] | 3204 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3205 | Raw(b'\xa5' * 100)) |
Neale Ranns | 00a469d | 2018-12-20 06:12:19 -0800 | [diff] [blame] | 3206 | rxs = self.send_and_expect(self.pg0, [p], self.pg2) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3207 | |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3208 | self.assertFalse(find_gbp_endpoint(self, ip=rep_88.ip4)) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3209 | |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3210 | p = (Ether(src=ep.mac, dst=self.loop0.local_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3211 | IP(src=ep.ip4, dst=rep_88.ip4) / |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3212 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3213 | Raw(b'\xa5' * 100)) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3214 | rxs = self.send_and_expect(self.pg0, [p], self.pg4) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3215 | |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3216 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 3217 | # to appease the testcase we cannot have the registered EP still |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3218 | # present (because it's DP learnt) when the TC ends so wait until |
| 3219 | # it is removed |
| 3220 | # |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3221 | self.wait_for_ep_timeout(ip=rep_88.ip4) |
| 3222 | self.wait_for_ep_timeout(ip=rep_2.ip4) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3223 | |
| 3224 | # |
Neale Ranns | 3eea9de | 2019-06-21 02:09:25 -0700 | [diff] [blame] | 3225 | # Same as above, learn a remote EP via CP and DP |
| 3226 | # this time remove the DP one first. expect the CP data to remain |
| 3227 | # |
| 3228 | rep_3 = VppGbpEndpoint(self, vx_tun_l3, |
| 3229 | epg_220, None, |
| 3230 | "10.0.1.4", "11.0.0.103", |
| 3231 | "2001::10:3", "3001::103", |
| 3232 | ep_flags.GBP_API_ENDPOINT_FLAG_REMOTE, |
| 3233 | self.pg2.local_ip4, |
| 3234 | self.pg2.remote_hosts[1].ip4, |
| 3235 | mac=None) |
| 3236 | rep_3.add_vpp_config() |
| 3237 | |
| 3238 | p = (Ether(src=self.pg2.remote_mac, |
| 3239 | dst=self.pg2.local_mac) / |
| 3240 | IP(src=self.pg2.remote_hosts[2].ip4, |
| 3241 | dst=self.pg2.local_ip4) / |
| 3242 | UDP(sport=1234, dport=48879) / |
| 3243 | VXLAN(vni=101, gpid=441, flags=0x88) / |
| 3244 | Ether(src=l['mac'], dst="00:00:00:11:11:11") / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3245 | IP(src="10.0.1.4", dst=ep.ip4) / |
Neale Ranns | 3eea9de | 2019-06-21 02:09:25 -0700 | [diff] [blame] | 3246 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3247 | Raw(b'\xa5' * 100)) |
Neale Ranns | 3eea9de | 2019-06-21 02:09:25 -0700 | [diff] [blame] | 3248 | rxs = self.send_and_expect(self.pg2, p * NUM_PKTS, self.pg0) |
| 3249 | |
| 3250 | self.assertTrue(find_gbp_endpoint(self, |
| 3251 | vx_tun_l3._sw_if_index, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3252 | ip=rep_3.ip4, |
Neale Ranns | 3eea9de | 2019-06-21 02:09:25 -0700 | [diff] [blame] | 3253 | tep=[self.pg2.local_ip4, |
| 3254 | self.pg2.remote_hosts[2].ip4])) |
| 3255 | |
| 3256 | p = (Ether(src=ep.mac, dst=self.loop0.local_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3257 | IP(dst="10.0.1.4", src=ep.ip4) / |
Neale Ranns | 3eea9de | 2019-06-21 02:09:25 -0700 | [diff] [blame] | 3258 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3259 | Raw(b'\xa5' * 100)) |
Neale Ranns | 3eea9de | 2019-06-21 02:09:25 -0700 | [diff] [blame] | 3260 | rxs = self.send_and_expect(self.pg0, p * NUM_PKTS, self.pg2) |
| 3261 | |
| 3262 | # host 2 is the DP learned TEP |
| 3263 | for rx in rxs: |
| 3264 | self.assertEqual(rx[IP].src, self.pg2.local_ip4) |
| 3265 | self.assertEqual(rx[IP].dst, self.pg2.remote_hosts[2].ip4) |
| 3266 | |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3267 | self.wait_for_ep_timeout(ip=rep_3.ip4, |
Neale Ranns | 3eea9de | 2019-06-21 02:09:25 -0700 | [diff] [blame] | 3268 | tep=[self.pg2.local_ip4, |
| 3269 | self.pg2.remote_hosts[2].ip4]) |
| 3270 | |
| 3271 | rxs = self.send_and_expect(self.pg0, p * NUM_PKTS, self.pg2) |
| 3272 | |
| 3273 | # host 1 is the CP learned TEP |
| 3274 | for rx in rxs: |
| 3275 | self.assertEqual(rx[IP].src, self.pg2.local_ip4) |
| 3276 | self.assertEqual(rx[IP].dst, self.pg2.remote_hosts[1].ip4) |
| 3277 | |
| 3278 | # |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3279 | # shutdown with learnt endpoint present |
| 3280 | # |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3281 | p = (Ether(src=self.pg2.remote_mac, |
| 3282 | dst=self.pg2.local_mac) / |
| 3283 | IP(src=self.pg2.remote_hosts[1].ip4, |
| 3284 | dst=self.pg2.local_ip4) / |
| 3285 | UDP(sport=1234, dport=48879) / |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 3286 | VXLAN(vni=101, gpid=441, flags=0x88) / |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3287 | Ether(src=l['mac'], dst="00:00:00:11:11:11") / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3288 | IP(src=learnt[1]['ip'], dst=ep.ip4) / |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3289 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3290 | Raw(b'\xa5' * 100)) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3291 | |
| 3292 | rx = self.send_and_expect(self.pg2, [p], self.pg0) |
| 3293 | |
| 3294 | # endpoint learnt via the parent GBP-vxlan interface |
| 3295 | self.assertTrue(find_gbp_endpoint(self, |
| 3296 | vx_tun_l3._sw_if_index, |
| 3297 | ip=l['ip'])) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3298 | |
| 3299 | # |
| 3300 | # TODO |
| 3301 | # remote endpoint becomes local |
| 3302 | # |
| 3303 | self.pg2.unconfig_ip4() |
| 3304 | self.pg3.unconfig_ip4() |
| 3305 | self.pg4.unconfig_ip4() |
| 3306 | |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3307 | def test_gbp_redirect(self): |
| 3308 | """ GBP Endpoint Redirect """ |
| 3309 | |
Paul Vinciguerra | 9673e3e | 2019-05-10 20:41:08 -0400 | [diff] [blame] | 3310 | self.vapi.cli("set logging class gbp level debug") |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3311 | |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 3312 | ep_flags = VppEnum.vl_api_gbp_endpoint_flags_t |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3313 | routed_dst_mac = "00:0c:0c:0c:0c:0c" |
| 3314 | routed_src_mac = "00:22:bd:f8:19:ff" |
| 3315 | |
| 3316 | learnt = [{'mac': '00:00:11:11:11:02', |
| 3317 | 'ip': '10.0.1.2', |
| 3318 | 'ip6': '2001:10::2'}, |
| 3319 | {'mac': '00:00:11:11:11:03', |
| 3320 | 'ip': '10.0.1.3', |
| 3321 | 'ip6': '2001:10::3'}] |
| 3322 | |
| 3323 | # |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3324 | # IP tables |
| 3325 | # |
| 3326 | t4 = VppIpTable(self, 1) |
| 3327 | t4.add_vpp_config() |
| 3328 | t6 = VppIpTable(self, 1, True) |
| 3329 | t6.add_vpp_config() |
| 3330 | |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 3331 | rd1 = VppGbpRouteDomain(self, 2, 402, t4, t6) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3332 | rd1.add_vpp_config() |
| 3333 | |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 3334 | self.loop0.set_mac(self.router_mac) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3335 | |
| 3336 | # |
| 3337 | # Bind the BVI to the RD |
| 3338 | # |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 3339 | b_ip4 = VppIpInterfaceBind(self, self.loop0, t4).add_vpp_config() |
| 3340 | b_ip6 = VppIpInterfaceBind(self, self.loop0, t6).add_vpp_config() |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3341 | |
| 3342 | # |
| 3343 | # Pg7 hosts a BD's UU-fwd |
| 3344 | # |
| 3345 | self.pg7.config_ip4() |
| 3346 | self.pg7.resolve_arp() |
| 3347 | |
| 3348 | # |
| 3349 | # a GBP bridge domains for the EPs |
| 3350 | # |
| 3351 | bd1 = VppBridgeDomain(self, 1) |
| 3352 | bd1.add_vpp_config() |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 3353 | gbd1 = VppGbpBridgeDomain(self, bd1, rd1, self.loop0) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3354 | gbd1.add_vpp_config() |
| 3355 | |
| 3356 | bd2 = VppBridgeDomain(self, 2) |
| 3357 | bd2.add_vpp_config() |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 3358 | gbd2 = VppGbpBridgeDomain(self, bd2, rd1, self.loop1) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3359 | gbd2.add_vpp_config() |
| 3360 | |
| 3361 | # ... and has a /32 and /128 applied |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 3362 | ip4_addr = VppIpInterfaceAddress(self, gbd1.bvi, |
| 3363 | "10.0.0.128", 32, |
| 3364 | bind=b_ip4).add_vpp_config() |
| 3365 | ip6_addr = VppIpInterfaceAddress(self, gbd1.bvi, |
| 3366 | "2001:10::128", 128, |
| 3367 | bind=b_ip6).add_vpp_config() |
| 3368 | ip4_addr = VppIpInterfaceAddress(self, gbd2.bvi, |
| 3369 | "10.0.1.128", 32).add_vpp_config() |
| 3370 | ip6_addr = VppIpInterfaceAddress(self, gbd2.bvi, |
| 3371 | "2001:11::128", 128).add_vpp_config() |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3372 | |
| 3373 | # |
| 3374 | # The Endpoint-groups in which we are learning endpoints |
| 3375 | # |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 3376 | epg_220 = VppGbpEndpointGroup(self, 220, 440, rd1, gbd1, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3377 | None, gbd1.bvi, |
| 3378 | "10.0.0.128", |
Neale Ranns | 32f6d8e | 2019-03-05 04:22:08 -0800 | [diff] [blame] | 3379 | "2001:10::128", |
Neale Ranns | 8d0d8d2 | 2020-04-07 08:44:20 +0000 | [diff] [blame] | 3380 | VppGbpEndpointRetention(60)) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3381 | epg_220.add_vpp_config() |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 3382 | epg_221 = VppGbpEndpointGroup(self, 221, 441, rd1, gbd2, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3383 | None, gbd2.bvi, |
| 3384 | "10.0.1.128", |
Neale Ranns | 32f6d8e | 2019-03-05 04:22:08 -0800 | [diff] [blame] | 3385 | "2001:11::128", |
Neale Ranns | 8d0d8d2 | 2020-04-07 08:44:20 +0000 | [diff] [blame] | 3386 | VppGbpEndpointRetention(60)) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3387 | epg_221.add_vpp_config() |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 3388 | epg_222 = VppGbpEndpointGroup(self, 222, 442, rd1, gbd1, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3389 | None, gbd1.bvi, |
| 3390 | "10.0.2.128", |
Neale Ranns | 32f6d8e | 2019-03-05 04:22:08 -0800 | [diff] [blame] | 3391 | "2001:12::128", |
Neale Ranns | 8d0d8d2 | 2020-04-07 08:44:20 +0000 | [diff] [blame] | 3392 | VppGbpEndpointRetention(60)) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3393 | epg_222.add_vpp_config() |
| 3394 | |
| 3395 | # |
| 3396 | # a GBP bridge domains for the SEPs |
| 3397 | # |
| 3398 | bd_uu1 = VppVxlanGbpTunnel(self, self.pg7.local_ip4, |
| 3399 | self.pg7.remote_ip4, 116) |
| 3400 | bd_uu1.add_vpp_config() |
| 3401 | bd_uu2 = VppVxlanGbpTunnel(self, self.pg7.local_ip4, |
| 3402 | self.pg7.remote_ip4, 117) |
| 3403 | bd_uu2.add_vpp_config() |
| 3404 | |
| 3405 | bd3 = VppBridgeDomain(self, 3) |
| 3406 | bd3.add_vpp_config() |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 3407 | gbd3 = VppGbpBridgeDomain(self, bd3, rd1, self.loop2, |
| 3408 | bd_uu1, learn=False) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3409 | gbd3.add_vpp_config() |
| 3410 | bd4 = VppBridgeDomain(self, 4) |
| 3411 | bd4.add_vpp_config() |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 3412 | gbd4 = VppGbpBridgeDomain(self, bd4, rd1, self.loop3, |
| 3413 | bd_uu2, learn=False) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3414 | gbd4.add_vpp_config() |
| 3415 | |
| 3416 | # |
| 3417 | # EPGs in which the service endpoints exist |
| 3418 | # |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 3419 | epg_320 = VppGbpEndpointGroup(self, 320, 550, rd1, gbd3, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3420 | None, gbd1.bvi, |
| 3421 | "12.0.0.128", |
Neale Ranns | 32f6d8e | 2019-03-05 04:22:08 -0800 | [diff] [blame] | 3422 | "4001:10::128", |
Neale Ranns | 8d0d8d2 | 2020-04-07 08:44:20 +0000 | [diff] [blame] | 3423 | VppGbpEndpointRetention(60)) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3424 | epg_320.add_vpp_config() |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 3425 | epg_321 = VppGbpEndpointGroup(self, 321, 551, rd1, gbd4, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3426 | None, gbd2.bvi, |
| 3427 | "12.0.1.128", |
Neale Ranns | 32f6d8e | 2019-03-05 04:22:08 -0800 | [diff] [blame] | 3428 | "4001:11::128", |
Neale Ranns | 8d0d8d2 | 2020-04-07 08:44:20 +0000 | [diff] [blame] | 3429 | VppGbpEndpointRetention(60)) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3430 | epg_321.add_vpp_config() |
| 3431 | |
| 3432 | # |
| 3433 | # three local endpoints |
| 3434 | # |
| 3435 | ep1 = VppGbpEndpoint(self, self.pg0, |
| 3436 | epg_220, None, |
| 3437 | "10.0.0.1", "11.0.0.1", |
| 3438 | "2001:10::1", "3001:10::1") |
| 3439 | ep1.add_vpp_config() |
| 3440 | ep2 = VppGbpEndpoint(self, self.pg1, |
| 3441 | epg_221, None, |
| 3442 | "10.0.1.1", "11.0.1.1", |
| 3443 | "2001:11::1", "3001:11::1") |
| 3444 | ep2.add_vpp_config() |
| 3445 | ep3 = VppGbpEndpoint(self, self.pg2, |
| 3446 | epg_222, None, |
| 3447 | "10.0.2.2", "11.0.2.2", |
| 3448 | "2001:12::1", "3001:12::1") |
| 3449 | ep3.add_vpp_config() |
| 3450 | |
| 3451 | # |
| 3452 | # service endpoints |
| 3453 | # |
| 3454 | sep1 = VppGbpEndpoint(self, self.pg3, |
| 3455 | epg_320, None, |
| 3456 | "12.0.0.1", "13.0.0.1", |
| 3457 | "4001:10::1", "5001:10::1") |
| 3458 | sep1.add_vpp_config() |
| 3459 | sep2 = VppGbpEndpoint(self, self.pg4, |
| 3460 | epg_320, None, |
| 3461 | "12.0.0.2", "13.0.0.2", |
| 3462 | "4001:10::2", "5001:10::2") |
| 3463 | sep2.add_vpp_config() |
| 3464 | sep3 = VppGbpEndpoint(self, self.pg5, |
| 3465 | epg_321, None, |
| 3466 | "12.0.1.1", "13.0.1.1", |
| 3467 | "4001:11::1", "5001:11::1") |
| 3468 | sep3.add_vpp_config() |
| 3469 | # this EP is not installed immediately |
| 3470 | sep4 = VppGbpEndpoint(self, self.pg6, |
| 3471 | epg_321, None, |
| 3472 | "12.0.1.2", "13.0.1.2", |
| 3473 | "4001:11::2", "5001:11::2") |
| 3474 | |
| 3475 | # |
| 3476 | # an L2 switch packet between local EPs in different EPGs |
| 3477 | # different dest ports on each so the are LB hashed differently |
| 3478 | # |
| 3479 | p4 = [(Ether(src=ep1.mac, dst=ep3.mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3480 | IP(src=ep1.ip4, dst=ep3.ip4) / |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3481 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3482 | Raw(b'\xa5' * 100)), |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3483 | (Ether(src=ep3.mac, dst=ep1.mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3484 | IP(src=ep3.ip4, dst=ep1.ip4) / |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3485 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3486 | Raw(b'\xa5' * 100))] |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3487 | p6 = [(Ether(src=ep1.mac, dst=ep3.mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3488 | IPv6(src=ep1.ip6, dst=ep3.ip6) / |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3489 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3490 | Raw(b'\xa5' * 100)), |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3491 | (Ether(src=ep3.mac, dst=ep1.mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3492 | IPv6(src=ep3.ip6, dst=ep1.ip6) / |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3493 | UDP(sport=1234, dport=1230) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3494 | Raw(b'\xa5' * 100))] |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3495 | |
| 3496 | # should be dropped since no contract yet |
| 3497 | self.send_and_assert_no_replies(self.pg0, [p4[0]]) |
| 3498 | self.send_and_assert_no_replies(self.pg0, [p6[0]]) |
| 3499 | |
| 3500 | # |
| 3501 | # Add a contract with a rule to load-balance redirect via SEP1 and SEP2 |
| 3502 | # one of the next-hops is via an EP that is not known |
| 3503 | # |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 3504 | rule4 = AclRule(is_permit=1, proto=17) |
| 3505 | rule6 = AclRule(src_prefix=IPv6Network((0, 0)), |
| 3506 | dst_prefix=IPv6Network((0, 0)), is_permit=1, proto=17) |
| 3507 | acl = VppAcl(self, rules=[rule4, rule6]) |
| 3508 | acl.add_vpp_config() |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3509 | |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3510 | # |
| 3511 | # test the src-ip hash mode |
| 3512 | # |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3513 | c1 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 3514 | self, 402, epg_220.sclass, epg_222.sclass, acl.acl_index, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3515 | [VppGbpContractRule( |
| 3516 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3517 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3518 | [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd, |
| 3519 | sep1.ip4, sep1.epg.rd), |
| 3520 | VppGbpContractNextHop(sep2.vmac, sep2.epg.bd, |
| 3521 | sep2.ip4, sep2.epg.rd)]), |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 3522 | VppGbpContractRule( |
| 3523 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 3524 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
| 3525 | [VppGbpContractNextHop(sep3.vmac, sep3.epg.bd, |
| 3526 | sep3.ip6, sep3.epg.rd), |
| 3527 | VppGbpContractNextHop(sep4.vmac, sep4.epg.bd, |
| 3528 | sep4.ip6, sep4.epg.rd)])], |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 3529 | [ETH_P_IP, ETH_P_IPV6]) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3530 | c1.add_vpp_config() |
| 3531 | |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3532 | c2 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 3533 | self, 402, epg_222.sclass, epg_220.sclass, acl.acl_index, |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3534 | [VppGbpContractRule( |
| 3535 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 3536 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
| 3537 | [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd, |
| 3538 | sep1.ip4, sep1.epg.rd), |
| 3539 | VppGbpContractNextHop(sep2.vmac, sep2.epg.bd, |
| 3540 | sep2.ip4, sep2.epg.rd)]), |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 3541 | VppGbpContractRule( |
| 3542 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 3543 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
| 3544 | [VppGbpContractNextHop(sep3.vmac, sep3.epg.bd, |
| 3545 | sep3.ip6, sep3.epg.rd), |
| 3546 | VppGbpContractNextHop(sep4.vmac, sep4.epg.bd, |
| 3547 | sep4.ip6, sep4.epg.rd)])], |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 3548 | [ETH_P_IP, ETH_P_IPV6]) |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3549 | c2.add_vpp_config() |
| 3550 | |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3551 | # |
| 3552 | # send again with the contract preset, now packets arrive |
| 3553 | # at SEP1 or SEP2 depending on the hashing |
| 3554 | # |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3555 | rxs = self.send_and_expect(self.pg0, p4[0] * 17, sep1.itf) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3556 | |
| 3557 | for rx in rxs: |
| 3558 | self.assertEqual(rx[Ether].src, routed_src_mac) |
| 3559 | self.assertEqual(rx[Ether].dst, sep1.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3560 | self.assertEqual(rx[IP].src, ep1.ip4) |
| 3561 | self.assertEqual(rx[IP].dst, ep3.ip4) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3562 | |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3563 | rxs = self.send_and_expect(self.pg2, p4[1] * 17, sep2.itf) |
| 3564 | |
| 3565 | for rx in rxs: |
| 3566 | self.assertEqual(rx[Ether].src, routed_src_mac) |
| 3567 | self.assertEqual(rx[Ether].dst, sep2.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3568 | self.assertEqual(rx[IP].src, ep3.ip4) |
| 3569 | self.assertEqual(rx[IP].dst, ep1.ip4) |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3570 | |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3571 | rxs = self.send_and_expect(self.pg0, p6[0] * 17, self.pg7) |
| 3572 | |
| 3573 | for rx in rxs: |
| 3574 | self.assertEqual(rx[Ether].src, self.pg7.local_mac) |
| 3575 | self.assertEqual(rx[Ether].dst, self.pg7.remote_mac) |
| 3576 | self.assertEqual(rx[IP].src, self.pg7.local_ip4) |
| 3577 | self.assertEqual(rx[IP].dst, self.pg7.remote_ip4) |
| 3578 | self.assertEqual(rx[VXLAN].vni, 117) |
| 3579 | self.assertTrue(rx[VXLAN].flags.G) |
| 3580 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 3581 | # redirect policy has been applied |
| 3582 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 3583 | self.assertFalse(rx[VXLAN].gpflags.D) |
| 3584 | |
| 3585 | inner = rx[VXLAN].payload |
| 3586 | |
| 3587 | self.assertEqual(inner[Ether].src, routed_src_mac) |
| 3588 | self.assertEqual(inner[Ether].dst, sep4.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3589 | self.assertEqual(inner[IPv6].src, ep1.ip6) |
| 3590 | self.assertEqual(inner[IPv6].dst, ep3.ip6) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3591 | |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3592 | rxs = self.send_and_expect(self.pg2, p6[1] * 17, sep3.itf) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3593 | |
| 3594 | for rx in rxs: |
| 3595 | self.assertEqual(rx[Ether].src, routed_src_mac) |
| 3596 | self.assertEqual(rx[Ether].dst, sep3.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3597 | self.assertEqual(rx[IPv6].src, ep3.ip6) |
| 3598 | self.assertEqual(rx[IPv6].dst, ep1.ip6) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3599 | |
| 3600 | # |
| 3601 | # programme the unknown EP |
| 3602 | # |
| 3603 | sep4.add_vpp_config() |
| 3604 | |
| 3605 | rxs = self.send_and_expect(self.pg0, p6[0] * 17, sep4.itf) |
| 3606 | |
| 3607 | for rx in rxs: |
| 3608 | self.assertEqual(rx[Ether].src, routed_src_mac) |
| 3609 | self.assertEqual(rx[Ether].dst, sep4.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3610 | self.assertEqual(rx[IPv6].src, ep1.ip6) |
| 3611 | self.assertEqual(rx[IPv6].dst, ep3.ip6) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3612 | |
| 3613 | # |
| 3614 | # and revert back to unprogrammed |
| 3615 | # |
| 3616 | sep4.remove_vpp_config() |
| 3617 | |
| 3618 | rxs = self.send_and_expect(self.pg0, p6[0] * 17, 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, self.pg7.remote_ip4) |
| 3625 | self.assertEqual(rx[VXLAN].vni, 117) |
| 3626 | self.assertTrue(rx[VXLAN].flags.G) |
| 3627 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 3628 | # redirect policy has been applied |
| 3629 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 3630 | self.assertFalse(rx[VXLAN].gpflags.D) |
| 3631 | |
| 3632 | inner = rx[VXLAN].payload |
| 3633 | |
| 3634 | self.assertEqual(inner[Ether].src, routed_src_mac) |
| 3635 | self.assertEqual(inner[Ether].dst, sep4.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3636 | self.assertEqual(inner[IPv6].src, ep1.ip6) |
| 3637 | self.assertEqual(inner[IPv6].dst, ep3.ip6) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3638 | |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3639 | c1.remove_vpp_config() |
| 3640 | c2.remove_vpp_config() |
| 3641 | |
| 3642 | # |
| 3643 | # test the symmetric hash mode |
| 3644 | # |
| 3645 | c1 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 3646 | self, 402, epg_220.sclass, epg_222.sclass, acl.acl_index, |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3647 | [VppGbpContractRule( |
| 3648 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 3649 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SYMMETRIC, |
| 3650 | [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd, |
| 3651 | sep1.ip4, sep1.epg.rd), |
| 3652 | VppGbpContractNextHop(sep2.vmac, sep2.epg.bd, |
| 3653 | sep2.ip4, sep2.epg.rd)]), |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 3654 | VppGbpContractRule( |
| 3655 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 3656 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SYMMETRIC, |
| 3657 | [VppGbpContractNextHop(sep3.vmac, sep3.epg.bd, |
| 3658 | sep3.ip6, sep3.epg.rd), |
| 3659 | VppGbpContractNextHop(sep4.vmac, sep4.epg.bd, |
| 3660 | sep4.ip6, sep4.epg.rd)])], |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 3661 | [ETH_P_IP, ETH_P_IPV6]) |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3662 | c1.add_vpp_config() |
| 3663 | |
| 3664 | c2 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 3665 | self, 402, epg_222.sclass, epg_220.sclass, acl.acl_index, |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3666 | [VppGbpContractRule( |
| 3667 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 3668 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SYMMETRIC, |
| 3669 | [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd, |
| 3670 | sep1.ip4, sep1.epg.rd), |
| 3671 | VppGbpContractNextHop(sep2.vmac, sep2.epg.bd, |
| 3672 | sep2.ip4, sep2.epg.rd)]), |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 3673 | VppGbpContractRule( |
| 3674 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 3675 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SYMMETRIC, |
| 3676 | [VppGbpContractNextHop(sep3.vmac, sep3.epg.bd, |
| 3677 | sep3.ip6, sep3.epg.rd), |
| 3678 | VppGbpContractNextHop(sep4.vmac, sep4.epg.bd, |
| 3679 | sep4.ip6, sep4.epg.rd)])], |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 3680 | [ETH_P_IP, ETH_P_IPV6]) |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3681 | c2.add_vpp_config() |
| 3682 | |
| 3683 | # |
| 3684 | # send again with the contract preset, now packets arrive |
| 3685 | # at SEP1 for both directions |
| 3686 | # |
| 3687 | rxs = self.send_and_expect(self.pg0, p4[0] * 17, sep1.itf) |
| 3688 | |
| 3689 | for rx in rxs: |
| 3690 | self.assertEqual(rx[Ether].src, routed_src_mac) |
| 3691 | self.assertEqual(rx[Ether].dst, sep1.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3692 | self.assertEqual(rx[IP].src, ep1.ip4) |
| 3693 | self.assertEqual(rx[IP].dst, ep3.ip4) |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3694 | |
| 3695 | rxs = self.send_and_expect(self.pg2, p4[1] * 17, sep1.itf) |
| 3696 | |
| 3697 | for rx in rxs: |
| 3698 | self.assertEqual(rx[Ether].src, routed_src_mac) |
| 3699 | self.assertEqual(rx[Ether].dst, sep1.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3700 | self.assertEqual(rx[IP].src, ep3.ip4) |
| 3701 | self.assertEqual(rx[IP].dst, ep1.ip4) |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3702 | |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3703 | # |
| 3704 | # programme the unknown EP for the L3 tests |
| 3705 | # |
| 3706 | sep4.add_vpp_config() |
| 3707 | |
| 3708 | # |
| 3709 | # an L3 switch packet between local EPs in different EPGs |
| 3710 | # different dest ports on each so the are LB hashed differently |
| 3711 | # |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 3712 | p4 = [(Ether(src=ep1.mac, dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3713 | IP(src=ep1.ip4, dst=ep2.ip4) / |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3714 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3715 | Raw(b'\xa5' * 100)), |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 3716 | (Ether(src=ep2.mac, dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3717 | IP(src=ep2.ip4, dst=ep1.ip4) / |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3718 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3719 | Raw(b'\xa5' * 100))] |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 3720 | p6 = [(Ether(src=ep1.mac, dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3721 | IPv6(src=ep1.ip6, dst=ep2.ip6) / |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3722 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3723 | Raw(b'\xa5' * 100)), |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 3724 | (Ether(src=ep2.mac, dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3725 | IPv6(src=ep2.ip6, dst=ep1.ip6) / |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3726 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3727 | Raw(b'\xa5' * 100))] |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3728 | |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3729 | c3 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 3730 | self, 402, epg_220.sclass, epg_221.sclass, acl.acl_index, |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 3731 | [VppGbpContractRule( |
| 3732 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 3733 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SYMMETRIC, |
| 3734 | [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd, |
| 3735 | sep1.ip4, sep1.epg.rd), |
| 3736 | VppGbpContractNextHop(sep2.vmac, sep2.epg.bd, |
| 3737 | sep2.ip4, sep2.epg.rd)]), |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 3738 | VppGbpContractRule( |
| 3739 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 3740 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SYMMETRIC, |
| 3741 | [VppGbpContractNextHop(sep3.vmac, sep3.epg.bd, |
| 3742 | sep3.ip6, sep3.epg.rd), |
| 3743 | VppGbpContractNextHop(sep4.vmac, sep4.epg.bd, |
| 3744 | sep4.ip6, sep4.epg.rd)])], |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 3745 | [ETH_P_IP, ETH_P_IPV6]) |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3746 | c3.add_vpp_config() |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3747 | |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3748 | rxs = self.send_and_expect(self.pg0, p4[0] * 17, sep1.itf) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3749 | |
| 3750 | for rx in rxs: |
| 3751 | self.assertEqual(rx[Ether].src, routed_src_mac) |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3752 | self.assertEqual(rx[Ether].dst, sep1.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3753 | self.assertEqual(rx[IP].src, ep1.ip4) |
| 3754 | self.assertEqual(rx[IP].dst, ep2.ip4) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3755 | |
| 3756 | # |
| 3757 | # learn a remote EP in EPG 221 |
Benoît Ganne | b854324 | 2019-07-31 14:15:57 +0200 | [diff] [blame] | 3758 | # packets coming from unknown remote EPs will be leant & redirected |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3759 | # |
| 3760 | vx_tun_l3 = VppGbpVxlanTunnel( |
| 3761 | self, 444, rd1.rd_id, |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 3762 | VppEnum.vl_api_gbp_vxlan_tunnel_mode_t.GBP_VXLAN_TUNNEL_MODE_L3, |
| 3763 | self.pg2.local_ip4) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3764 | vx_tun_l3.add_vpp_config() |
| 3765 | |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3766 | c4 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 3767 | self, 402, epg_221.sclass, epg_220.sclass, acl.acl_index, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3768 | [VppGbpContractRule( |
Benoît Ganne | b854324 | 2019-07-31 14:15:57 +0200 | [diff] [blame] | 3769 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 3770 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Benoît Ganne | b854324 | 2019-07-31 14:15:57 +0200 | [diff] [blame] | 3771 | [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd, |
| 3772 | sep1.ip4, sep1.epg.rd), |
| 3773 | VppGbpContractNextHop(sep2.vmac, sep2.epg.bd, |
| 3774 | sep2.ip4, sep2.epg.rd)]), |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 3775 | VppGbpContractRule( |
Benoît Ganne | b854324 | 2019-07-31 14:15:57 +0200 | [diff] [blame] | 3776 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 3777 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Benoît Ganne | b854324 | 2019-07-31 14:15:57 +0200 | [diff] [blame] | 3778 | [VppGbpContractNextHop(sep3.vmac, sep3.epg.bd, |
| 3779 | sep3.ip6, sep3.epg.rd), |
| 3780 | VppGbpContractNextHop(sep4.vmac, sep4.epg.bd, |
| 3781 | sep4.ip6, sep4.epg.rd)])], |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 3782 | [ETH_P_IP, ETH_P_IPV6]) |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3783 | c4.add_vpp_config() |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3784 | |
| 3785 | p = (Ether(src=self.pg7.remote_mac, |
| 3786 | dst=self.pg7.local_mac) / |
| 3787 | IP(src=self.pg7.remote_ip4, |
| 3788 | dst=self.pg7.local_ip4) / |
| 3789 | UDP(sport=1234, dport=48879) / |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 3790 | VXLAN(vni=444, gpid=441, flags=0x88) / |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 3791 | Ether(src="00:22:22:22:22:33", dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3792 | IP(src="10.0.0.88", dst=ep1.ip4) / |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3793 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3794 | Raw(b'\xa5' * 100)) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3795 | |
Benoît Ganne | b854324 | 2019-07-31 14:15:57 +0200 | [diff] [blame] | 3796 | # unknown remote EP to local EP redirected |
| 3797 | rxs = self.send_and_expect(self.pg7, [p], sep1.itf) |
| 3798 | |
| 3799 | for rx in rxs: |
| 3800 | self.assertEqual(rx[Ether].src, routed_src_mac) |
| 3801 | self.assertEqual(rx[Ether].dst, sep1.mac) |
| 3802 | self.assertEqual(rx[IP].src, "10.0.0.88") |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3803 | self.assertEqual(rx[IP].dst, ep1.ip4) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3804 | |
| 3805 | # endpoint learnt via the parent GBP-vxlan interface |
| 3806 | self.assertTrue(find_gbp_endpoint(self, |
| 3807 | vx_tun_l3._sw_if_index, |
| 3808 | ip="10.0.0.88")) |
| 3809 | |
| 3810 | p = (Ether(src=self.pg7.remote_mac, |
| 3811 | dst=self.pg7.local_mac) / |
| 3812 | IP(src=self.pg7.remote_ip4, |
| 3813 | dst=self.pg7.local_ip4) / |
| 3814 | UDP(sport=1234, dport=48879) / |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 3815 | VXLAN(vni=444, gpid=441, flags=0x88) / |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 3816 | Ether(src="00:22:22:22:22:33", dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3817 | IPv6(src="2001:10::88", dst=ep1.ip6) / |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3818 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3819 | Raw(b'\xa5' * 100)) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3820 | |
Benoît Ganne | b854324 | 2019-07-31 14:15:57 +0200 | [diff] [blame] | 3821 | # unknown remote EP to local EP redirected (ipv6) |
| 3822 | rxs = self.send_and_expect(self.pg7, [p], sep3.itf) |
| 3823 | |
| 3824 | for rx in rxs: |
| 3825 | self.assertEqual(rx[Ether].src, routed_src_mac) |
| 3826 | self.assertEqual(rx[Ether].dst, sep3.mac) |
| 3827 | self.assertEqual(rx[IPv6].src, "2001:10::88") |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3828 | self.assertEqual(rx[IPv6].dst, ep1.ip6) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3829 | |
| 3830 | # endpoint learnt via the parent GBP-vxlan interface |
| 3831 | self.assertTrue(find_gbp_endpoint(self, |
| 3832 | vx_tun_l3._sw_if_index, |
| 3833 | ip="2001:10::88")) |
| 3834 | |
| 3835 | # |
| 3836 | # L3 switch from local to remote EP |
| 3837 | # |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 3838 | p4 = [(Ether(src=ep1.mac, dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3839 | IP(src=ep1.ip4, dst="10.0.0.88") / |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3840 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3841 | Raw(b'\xa5' * 100))] |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 3842 | p6 = [(Ether(src=ep1.mac, dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3843 | IPv6(src=ep1.ip6, dst="2001:10::88") / |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3844 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 3845 | Raw(b'\xa5' * 100))] |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3846 | |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3847 | rxs = self.send_and_expect(self.pg0, p4[0] * 17, sep1.itf) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3848 | |
| 3849 | for rx in rxs: |
| 3850 | self.assertEqual(rx[Ether].src, routed_src_mac) |
| 3851 | self.assertEqual(rx[Ether].dst, sep1.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3852 | self.assertEqual(rx[IP].src, ep1.ip4) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3853 | self.assertEqual(rx[IP].dst, "10.0.0.88") |
| 3854 | |
| 3855 | rxs = self.send_and_expect(self.pg0, p6[0] * 17, sep4.itf) |
| 3856 | |
| 3857 | for rx in rxs: |
| 3858 | self.assertEqual(rx[Ether].src, routed_src_mac) |
| 3859 | self.assertEqual(rx[Ether].dst, sep4.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3860 | self.assertEqual(rx[IPv6].src, ep1.ip6) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3861 | self.assertEqual(rx[IPv6].dst, "2001:10::88") |
| 3862 | |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3863 | # |
| 3864 | # test the dst-ip hash mode |
| 3865 | # |
| 3866 | c5 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 3867 | self, 402, epg_220.sclass, epg_221.sclass, acl.acl_index, |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3868 | [VppGbpContractRule( |
| 3869 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 3870 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_DST_IP, |
| 3871 | [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd, |
| 3872 | sep1.ip4, sep1.epg.rd), |
| 3873 | VppGbpContractNextHop(sep2.vmac, sep2.epg.bd, |
| 3874 | sep2.ip4, sep2.epg.rd)]), |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 3875 | VppGbpContractRule( |
| 3876 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 3877 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_DST_IP, |
| 3878 | [VppGbpContractNextHop(sep3.vmac, sep3.epg.bd, |
| 3879 | sep3.ip6, sep3.epg.rd), |
| 3880 | VppGbpContractNextHop(sep4.vmac, sep4.epg.bd, |
| 3881 | sep4.ip6, sep4.epg.rd)])], |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 3882 | [ETH_P_IP, ETH_P_IPV6]) |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3883 | c5.add_vpp_config() |
| 3884 | |
| 3885 | rxs = self.send_and_expect(self.pg0, p4[0] * 17, sep1.itf) |
| 3886 | |
| 3887 | for rx in rxs: |
| 3888 | self.assertEqual(rx[Ether].src, routed_src_mac) |
| 3889 | self.assertEqual(rx[Ether].dst, sep1.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3890 | self.assertEqual(rx[IP].src, ep1.ip4) |
Mohsin Kazmi | d40c3e6 | 2018-11-21 10:46:57 +0100 | [diff] [blame] | 3891 | self.assertEqual(rx[IP].dst, "10.0.0.88") |
| 3892 | |
| 3893 | rxs = self.send_and_expect(self.pg0, p6[0] * 17, sep3.itf) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3894 | |
| 3895 | for rx in rxs: |
| 3896 | self.assertEqual(rx[Ether].src, routed_src_mac) |
| 3897 | self.assertEqual(rx[Ether].dst, sep3.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3898 | self.assertEqual(rx[IPv6].src, ep1.ip6) |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3899 | self.assertEqual(rx[IPv6].dst, "2001:10::88") |
| 3900 | |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 3901 | # |
Benoît Ganne | 6603567 | 2019-08-02 17:57:08 +0200 | [diff] [blame] | 3902 | # a programmed remote SEP in EPG 320 |
Benoît Ganne | 388f418 | 2019-07-31 14:29:00 +0200 | [diff] [blame] | 3903 | # |
| 3904 | |
| 3905 | # gbp vxlan tunnel for the remote SEP |
| 3906 | vx_tun_l3_sep = VppGbpVxlanTunnel( |
| 3907 | self, 555, rd1.rd_id, |
| 3908 | VppEnum.vl_api_gbp_vxlan_tunnel_mode_t.GBP_VXLAN_TUNNEL_MODE_L3, |
| 3909 | self.pg2.local_ip4) |
| 3910 | vx_tun_l3_sep.add_vpp_config() |
| 3911 | |
| 3912 | # remote SEP |
| 3913 | sep5 = VppGbpEndpoint(self, vx_tun_l3_sep, |
| 3914 | epg_320, None, |
| 3915 | "12.0.0.10", "13.0.0.10", |
| 3916 | "4001:10::10", "5001:10::10", |
| 3917 | ep_flags.GBP_API_ENDPOINT_FLAG_REMOTE, |
| 3918 | self.pg7.local_ip4, |
| 3919 | self.pg7.remote_ip4, |
| 3920 | mac=None) |
| 3921 | sep5.add_vpp_config() |
| 3922 | |
| 3923 | # |
Benoît Ganne | 6603567 | 2019-08-02 17:57:08 +0200 | [diff] [blame] | 3924 | # local l3out redirect tests |
Benoît Ganne | 388f418 | 2019-07-31 14:29:00 +0200 | [diff] [blame] | 3925 | # |
| 3926 | |
| 3927 | # add local l3out |
| 3928 | # the external bd |
| 3929 | self.loop4.set_mac(self.router_mac) |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 3930 | b_lo4_ip4 = VppIpInterfaceBind(self, self.loop4, t4).add_vpp_config() |
| 3931 | b_lo4_ip6 = VppIpInterfaceBind(self, self.loop4, t6).add_vpp_config() |
Benoît Ganne | 388f418 | 2019-07-31 14:29:00 +0200 | [diff] [blame] | 3932 | ebd = VppBridgeDomain(self, 100) |
| 3933 | ebd.add_vpp_config() |
| 3934 | gebd = VppGbpBridgeDomain(self, ebd, rd1, self.loop4, None, None) |
| 3935 | gebd.add_vpp_config() |
| 3936 | # the external epg |
| 3937 | eepg = VppGbpEndpointGroup(self, 888, 765, rd1, gebd, |
| 3938 | None, gebd.bvi, |
| 3939 | "10.1.0.128", |
| 3940 | "2001:10:1::128", |
Neale Ranns | 8d0d8d2 | 2020-04-07 08:44:20 +0000 | [diff] [blame] | 3941 | VppGbpEndpointRetention(60)) |
Benoît Ganne | 388f418 | 2019-07-31 14:29:00 +0200 | [diff] [blame] | 3942 | eepg.add_vpp_config() |
| 3943 | # add subnets to BVI |
| 3944 | VppIpInterfaceAddress( |
| 3945 | self, |
| 3946 | gebd.bvi, |
| 3947 | "10.1.0.128", |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 3948 | 24, bind=b_lo4_ip4).add_vpp_config() |
Benoît Ganne | 388f418 | 2019-07-31 14:29:00 +0200 | [diff] [blame] | 3949 | VppIpInterfaceAddress( |
| 3950 | self, |
| 3951 | gebd.bvi, |
| 3952 | "2001:10:1::128", |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 3953 | 64, bind=b_lo4_ip6).add_vpp_config() |
Benoît Ganne | 388f418 | 2019-07-31 14:29:00 +0200 | [diff] [blame] | 3954 | # ... which are L3-out subnets |
| 3955 | VppGbpSubnet(self, rd1, "10.1.0.0", 24, |
| 3956 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT, |
| 3957 | sclass=765).add_vpp_config() |
| 3958 | VppGbpSubnet(self, rd1, "2001:10:1::128", 64, |
| 3959 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT, |
| 3960 | sclass=765).add_vpp_config() |
| 3961 | # external endpoints |
| 3962 | VppL2Vtr(self, self.vlan_100, L2_VTR_OP.L2_POP_1).add_vpp_config() |
| 3963 | eep1 = VppGbpEndpoint(self, self.vlan_100, eepg, None, "10.1.0.1", |
| 3964 | "11.1.0.1", "2001:10:1::1", "3001:10:1::1", |
| 3965 | ep_flags.GBP_API_ENDPOINT_FLAG_EXTERNAL) |
| 3966 | eep1.add_vpp_config() |
| 3967 | VppL2Vtr(self, self.vlan_101, L2_VTR_OP.L2_POP_1).add_vpp_config() |
| 3968 | eep2 = VppGbpEndpoint(self, self.vlan_101, eepg, None, "10.1.0.2", |
| 3969 | "11.1.0.2", "2001:10:1::2", "3001:10:1::2", |
| 3970 | ep_flags.GBP_API_ENDPOINT_FLAG_EXTERNAL) |
| 3971 | eep2.add_vpp_config() |
| 3972 | |
| 3973 | # external subnets reachable though eep1 and eep2 respectively |
| 3974 | VppIpRoute(self, "10.220.0.0", 24, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3975 | [VppRoutePath(eep1.ip4, eep1.epg.bvi.sw_if_index)], |
Benoît Ganne | 388f418 | 2019-07-31 14:29:00 +0200 | [diff] [blame] | 3976 | table_id=t4.table_id).add_vpp_config() |
| 3977 | VppGbpSubnet(self, rd1, "10.220.0.0", 24, |
| 3978 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT, |
| 3979 | sclass=4220).add_vpp_config() |
| 3980 | VppIpRoute(self, "10:220::", 64, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3981 | [VppRoutePath(eep1.ip6, eep1.epg.bvi.sw_if_index)], |
Benoît Ganne | 388f418 | 2019-07-31 14:29:00 +0200 | [diff] [blame] | 3982 | table_id=t6.table_id).add_vpp_config() |
| 3983 | VppGbpSubnet(self, rd1, "10:220::", 64, |
| 3984 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT, |
| 3985 | sclass=4220).add_vpp_config() |
| 3986 | VppIpRoute(self, "10.221.0.0", 24, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3987 | [VppRoutePath(eep2.ip4, eep2.epg.bvi.sw_if_index)], |
Benoît Ganne | 388f418 | 2019-07-31 14:29:00 +0200 | [diff] [blame] | 3988 | table_id=t4.table_id).add_vpp_config() |
| 3989 | VppGbpSubnet(self, rd1, "10.221.0.0", 24, |
| 3990 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT, |
| 3991 | sclass=4221).add_vpp_config() |
| 3992 | VppIpRoute(self, "10:221::", 64, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 3993 | [VppRoutePath(eep2.ip6, eep2.epg.bvi.sw_if_index)], |
Benoît Ganne | 388f418 | 2019-07-31 14:29:00 +0200 | [diff] [blame] | 3994 | table_id=t6.table_id).add_vpp_config() |
| 3995 | VppGbpSubnet(self, rd1, "10:221::", 64, |
| 3996 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT, |
| 3997 | sclass=4221).add_vpp_config() |
| 3998 | |
Benoît Ganne | 6603567 | 2019-08-02 17:57:08 +0200 | [diff] [blame] | 3999 | # |
| 4000 | # l3out redirect to remote (known, then unknown) SEP |
| 4001 | # |
| 4002 | |
Benoît Ganne | 388f418 | 2019-07-31 14:29:00 +0200 | [diff] [blame] | 4003 | # packets from 1 external subnet to the other |
| 4004 | p = [(Ether(src=eep1.mac, dst=self.router_mac) / |
| 4005 | Dot1Q(vlan=100) / |
| 4006 | IP(src="10.220.0.17", dst="10.221.0.65") / |
| 4007 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 4008 | Raw(b'\xa5' * 100)), |
Benoît Ganne | 388f418 | 2019-07-31 14:29:00 +0200 | [diff] [blame] | 4009 | (Ether(src=eep1.mac, dst=self.router_mac) / |
| 4010 | Dot1Q(vlan=100) / |
| 4011 | IPv6(src="10:220::17", dst="10:221::65") / |
| 4012 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 4013 | Raw(b'\xa5' * 100))] |
Benoît Ganne | 388f418 | 2019-07-31 14:29:00 +0200 | [diff] [blame] | 4014 | |
| 4015 | # packets should be dropped in absence of contract |
| 4016 | self.send_and_assert_no_replies(self.pg0, p) |
| 4017 | |
| 4018 | # contract redirecting to sep5 |
| 4019 | VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 4020 | self, 402, 4220, 4221, acl.acl_index, |
Benoît Ganne | 388f418 | 2019-07-31 14:29:00 +0200 | [diff] [blame] | 4021 | [VppGbpContractRule( |
| 4022 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 4023 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_DST_IP, |
| 4024 | [VppGbpContractNextHop(sep5.vmac, sep5.epg.bd, |
| 4025 | sep5.ip4, sep5.epg.rd)]), |
| 4026 | VppGbpContractRule( |
| 4027 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 4028 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_DST_IP, |
| 4029 | [VppGbpContractNextHop(sep5.vmac, sep5.epg.bd, |
| 4030 | sep5.ip6, sep5.epg.rd)])], |
| 4031 | [ETH_P_IP, ETH_P_IPV6]).add_vpp_config() |
| 4032 | |
| 4033 | rxs = self.send_and_expect(self.pg0, p, self.pg7) |
| 4034 | |
| 4035 | for rx, tx in zip(rxs, p): |
| 4036 | self.assertEqual(rx[Ether].src, self.pg7.local_mac) |
| 4037 | self.assertEqual(rx[Ether].dst, self.pg7.remote_mac) |
| 4038 | self.assertEqual(rx[IP].src, self.pg7.local_ip4) |
| 4039 | self.assertEqual(rx[IP].dst, self.pg7.remote_ip4) |
| 4040 | # this should use the programmed remote leaf TEP |
| 4041 | self.assertEqual(rx[VXLAN].vni, 555) |
| 4042 | self.assertEqual(rx[VXLAN].gpid, 4220) |
| 4043 | self.assertTrue(rx[VXLAN].flags.G) |
| 4044 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 4045 | # redirect policy has been applied |
| 4046 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 4047 | self.assertTrue(rx[VXLAN].gpflags.D) |
| 4048 | rxip = rx[VXLAN][Ether].payload |
| 4049 | txip = tx[Dot1Q].payload |
| 4050 | self.assertEqual(rxip.src, txip.src) |
| 4051 | self.assertEqual(rxip.dst, txip.dst) |
| 4052 | |
Benoît Ganne | 4ea511c | 2019-08-02 16:36:35 +0200 | [diff] [blame] | 4053 | # remote SEP: it is now an unknown remote SEP and should go |
Benoît Ganne | 388f418 | 2019-07-31 14:29:00 +0200 | [diff] [blame] | 4054 | # to spine proxy |
| 4055 | sep5.remove_vpp_config() |
| 4056 | |
| 4057 | rxs = self.send_and_expect(self.pg0, p, self.pg7) |
| 4058 | |
| 4059 | for rx, tx in zip(rxs, p): |
| 4060 | self.assertEqual(rx[Ether].src, self.pg7.local_mac) |
| 4061 | self.assertEqual(rx[Ether].dst, self.pg7.remote_mac) |
| 4062 | self.assertEqual(rx[IP].src, self.pg7.local_ip4) |
| 4063 | self.assertEqual(rx[IP].dst, self.pg7.remote_ip4) |
| 4064 | # this should use the spine proxy TEP |
| 4065 | self.assertEqual(rx[VXLAN].vni, epg_320.bd.uu_fwd.vni) |
| 4066 | self.assertEqual(rx[VXLAN].gpid, 4220) |
| 4067 | self.assertTrue(rx[VXLAN].flags.G) |
| 4068 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 4069 | # redirect policy has been applied |
| 4070 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 4071 | self.assertTrue(rx[VXLAN].gpflags.D) |
| 4072 | rxip = rx[VXLAN][Ether].payload |
| 4073 | txip = tx[Dot1Q].payload |
| 4074 | self.assertEqual(rxip.src, txip.src) |
| 4075 | self.assertEqual(rxip.dst, txip.dst) |
| 4076 | |
| 4077 | # |
Benoît Ganne | 6603567 | 2019-08-02 17:57:08 +0200 | [diff] [blame] | 4078 | # l3out redirect to local SEP |
| 4079 | # |
| 4080 | |
| 4081 | # change the contract between l3out to redirect to local SEPs |
| 4082 | # instead of remote SEP |
| 4083 | VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 4084 | self, 402, 4220, 4221, acl.acl_index, |
Benoît Ganne | 6603567 | 2019-08-02 17:57:08 +0200 | [diff] [blame] | 4085 | [VppGbpContractRule( |
| 4086 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 4087 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_DST_IP, |
| 4088 | [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd, |
| 4089 | sep1.ip4, sep1.epg.rd)]), |
| 4090 | VppGbpContractRule( |
| 4091 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 4092 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_DST_IP, |
| 4093 | [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd, |
| 4094 | sep1.ip6, sep1.epg.rd)])], |
| 4095 | [ETH_P_IP, ETH_P_IPV6]).add_vpp_config() |
| 4096 | |
| 4097 | rxs = self.send_and_expect(self.pg0, p, sep1.itf) |
| 4098 | for rx, tx in zip(rxs, p): |
| 4099 | self.assertEqual(rx[Ether].src, routed_src_mac) |
| 4100 | self.assertEqual(rx[Ether].dst, sep1.mac) |
| 4101 | rxip = rx[Ether].payload |
| 4102 | txip = tx[Ether].payload |
| 4103 | self.assertEqual(rxip.src, txip.src) |
| 4104 | self.assertEqual(rxip.dst, txip.dst) |
| 4105 | |
| 4106 | # |
| 4107 | # redirect remote EP to remote (known then unknown) SEP |
Benoît Ganne | 4ea511c | 2019-08-02 16:36:35 +0200 | [diff] [blame] | 4108 | # |
| 4109 | |
| 4110 | # remote SEP known again |
| 4111 | sep5.add_vpp_config() |
| 4112 | |
| 4113 | # contract to redirect to learnt SEP |
| 4114 | VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 4115 | self, 402, epg_221.sclass, epg_222.sclass, acl.acl_index, |
Benoît Ganne | 4ea511c | 2019-08-02 16:36:35 +0200 | [diff] [blame] | 4116 | [VppGbpContractRule( |
| 4117 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 4118 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_DST_IP, |
| 4119 | [VppGbpContractNextHop(sep5.vmac, sep5.epg.bd, |
| 4120 | sep5.ip4, sep5.epg.rd)]), |
| 4121 | VppGbpContractRule( |
| 4122 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 4123 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_DST_IP, |
| 4124 | [VppGbpContractNextHop(sep5.vmac, sep5.epg.bd, |
| 4125 | sep5.ip6, sep5.epg.rd)])], |
| 4126 | [ETH_P_IP, ETH_P_IPV6]).add_vpp_config() |
| 4127 | |
| 4128 | # packets from unknown EP 221 to known EP in EPG 222 |
| 4129 | # should be redirected to known remote SEP |
| 4130 | base = (Ether(src=self.pg7.remote_mac, dst=self.pg7.local_mac) / |
| 4131 | IP(src=self.pg7.remote_ip4, dst=self.pg7.local_ip4) / |
| 4132 | UDP(sport=1234, dport=48879) / |
| 4133 | VXLAN(vni=444, gpid=441, flags=0x88) / |
| 4134 | Ether(src="00:22:22:22:22:44", dst=str(self.router_mac))) |
| 4135 | p = [(base / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4136 | IP(src="10.0.1.100", dst=ep3.ip4) / |
Benoît Ganne | 4ea511c | 2019-08-02 16:36:35 +0200 | [diff] [blame] | 4137 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 4138 | Raw(b'\xa5' * 100)), |
Benoît Ganne | 4ea511c | 2019-08-02 16:36:35 +0200 | [diff] [blame] | 4139 | (base / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4140 | IPv6(src="2001:10::100", dst=ep3.ip6) / |
Benoît Ganne | 4ea511c | 2019-08-02 16:36:35 +0200 | [diff] [blame] | 4141 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 4142 | Raw(b'\xa5' * 100))] |
Benoît Ganne | 4ea511c | 2019-08-02 16:36:35 +0200 | [diff] [blame] | 4143 | |
| 4144 | # unknown remote EP to local EP redirected to known remote SEP |
| 4145 | rxs = self.send_and_expect(self.pg7, p, self.pg7) |
| 4146 | |
| 4147 | for rx, tx in zip(rxs, p): |
| 4148 | self.assertEqual(rx[Ether].src, self.pg7.local_mac) |
| 4149 | self.assertEqual(rx[Ether].dst, self.pg7.remote_mac) |
| 4150 | self.assertEqual(rx[IP].src, self.pg7.local_ip4) |
| 4151 | self.assertEqual(rx[IP].dst, self.pg7.remote_ip4) |
| 4152 | # this should use the programmed remote leaf TEP |
| 4153 | self.assertEqual(rx[VXLAN].vni, 555) |
| 4154 | self.assertEqual(rx[VXLAN].gpid, epg_221.sclass) |
| 4155 | self.assertTrue(rx[VXLAN].flags.G) |
| 4156 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 4157 | # redirect policy has been applied |
| 4158 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 4159 | self.assertFalse(rx[VXLAN].gpflags.D) |
| 4160 | rxip = rx[VXLAN][Ether].payload |
| 4161 | txip = tx[VXLAN][Ether].payload |
| 4162 | self.assertEqual(rxip.src, txip.src) |
| 4163 | self.assertEqual(rxip.dst, txip.dst) |
| 4164 | |
| 4165 | # endpoint learnt via the parent GBP-vxlan interface |
| 4166 | self.assertTrue(find_gbp_endpoint(self, |
| 4167 | vx_tun_l3._sw_if_index, |
| 4168 | ip="10.0.1.100")) |
| 4169 | self.assertTrue(find_gbp_endpoint(self, |
| 4170 | vx_tun_l3._sw_if_index, |
| 4171 | ip="2001:10::100")) |
| 4172 | |
| 4173 | # remote SEP: it is now an unknown remote SEP and should go |
| 4174 | # to spine proxy |
| 4175 | sep5.remove_vpp_config() |
| 4176 | |
| 4177 | # remote EP (coming from spine proxy) to local EP redirected to |
| 4178 | # known remote SEP |
| 4179 | rxs = self.send_and_expect(self.pg7, p, self.pg7) |
| 4180 | |
| 4181 | for rx, tx in zip(rxs, p): |
| 4182 | self.assertEqual(rx[Ether].src, self.pg7.local_mac) |
| 4183 | self.assertEqual(rx[Ether].dst, self.pg7.remote_mac) |
| 4184 | self.assertEqual(rx[IP].src, self.pg7.local_ip4) |
| 4185 | self.assertEqual(rx[IP].dst, self.pg7.remote_ip4) |
| 4186 | # this should use the spine proxy TEP |
| 4187 | self.assertEqual(rx[VXLAN].vni, epg_320.bd.uu_fwd.vni) |
| 4188 | self.assertEqual(rx[VXLAN].gpid, epg_221.sclass) |
| 4189 | self.assertTrue(rx[VXLAN].flags.G) |
| 4190 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 4191 | # redirect policy has been applied |
| 4192 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 4193 | self.assertFalse(rx[VXLAN].gpflags.D) |
| 4194 | rxip = rx[VXLAN][Ether].payload |
| 4195 | txip = tx[VXLAN][Ether].payload |
| 4196 | self.assertEqual(rxip.src, txip.src) |
| 4197 | self.assertEqual(rxip.dst, txip.dst) |
| 4198 | |
| 4199 | # |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4200 | # cleanup |
| 4201 | # |
| 4202 | self.pg7.unconfig_ip4() |
| 4203 | |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4204 | def test_gbp_redirect_extended(self): |
| 4205 | """ GBP Endpoint Redirect Extended """ |
| 4206 | |
| 4207 | self.vapi.cli("set logging class gbp level debug") |
| 4208 | |
| 4209 | ep_flags = VppEnum.vl_api_gbp_endpoint_flags_t |
| 4210 | routed_dst_mac = "00:0c:0c:0c:0c:0c" |
| 4211 | routed_src_mac = "00:22:bd:f8:19:ff" |
| 4212 | |
| 4213 | learnt = [{'mac': '00:00:11:11:11:02', |
| 4214 | 'ip': '10.0.1.2', |
| 4215 | 'ip6': '2001:10::2'}, |
| 4216 | {'mac': '00:00:11:11:11:03', |
| 4217 | 'ip': '10.0.1.3', |
| 4218 | 'ip6': '2001:10::3'}] |
| 4219 | |
| 4220 | # |
| 4221 | # IP tables |
| 4222 | # |
| 4223 | t4 = VppIpTable(self, 1) |
| 4224 | t4.add_vpp_config() |
| 4225 | t6 = VppIpTable(self, 1, True) |
| 4226 | t6.add_vpp_config() |
| 4227 | |
| 4228 | # create IPv4 and IPv6 RD UU VxLAN-GBP TEP and bind them to the right |
| 4229 | # VRF |
| 4230 | rd_uu4 = VppVxlanGbpTunnel( |
| 4231 | self, |
| 4232 | self.pg7.local_ip4, |
| 4233 | self.pg7.remote_ip4, |
| 4234 | 114, |
| 4235 | mode=(VppEnum.vl_api_vxlan_gbp_api_tunnel_mode_t. |
| 4236 | VXLAN_GBP_API_TUNNEL_MODE_L3)) |
| 4237 | rd_uu4.add_vpp_config() |
| 4238 | VppIpInterfaceBind(self, rd_uu4, t4).add_vpp_config() |
| 4239 | |
| 4240 | rd_uu6 = VppVxlanGbpTunnel( |
| 4241 | self, |
| 4242 | self.pg7.local_ip4, |
| 4243 | self.pg7.remote_ip4, |
| 4244 | 115, |
| 4245 | mode=(VppEnum.vl_api_vxlan_gbp_api_tunnel_mode_t. |
| 4246 | VXLAN_GBP_API_TUNNEL_MODE_L3)) |
| 4247 | rd_uu6.add_vpp_config() |
| 4248 | VppIpInterfaceBind(self, rd_uu6, t4).add_vpp_config() |
| 4249 | |
| 4250 | rd1 = VppGbpRouteDomain(self, 2, 402, t4, t6, rd_uu4, rd_uu6) |
| 4251 | rd1.add_vpp_config() |
| 4252 | |
| 4253 | self.loop0.set_mac(self.router_mac) |
| 4254 | self.loop1.set_mac(self.router_mac) |
| 4255 | self.loop2.set_mac(self.router_mac) |
| 4256 | |
| 4257 | # |
| 4258 | # Bind the BVI to the RD |
| 4259 | # |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 4260 | b_lo0_ip4 = VppIpInterfaceBind(self, self.loop0, t4).add_vpp_config() |
| 4261 | b_lo0_ip6 = VppIpInterfaceBind(self, self.loop0, t6).add_vpp_config() |
| 4262 | b_lo1_ip4 = VppIpInterfaceBind(self, self.loop1, t4).add_vpp_config() |
| 4263 | b_lo1_ip6 = VppIpInterfaceBind(self, self.loop1, t6).add_vpp_config() |
| 4264 | b_lo2_ip4 = VppIpInterfaceBind(self, self.loop2, t4).add_vpp_config() |
| 4265 | b_lo2_ip6 = VppIpInterfaceBind(self, self.loop2, t6).add_vpp_config() |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4266 | |
| 4267 | # |
| 4268 | # Pg7 hosts a BD's UU-fwd |
| 4269 | # |
| 4270 | self.pg7.config_ip4() |
| 4271 | self.pg7.resolve_arp() |
| 4272 | |
| 4273 | # |
| 4274 | # a GBP bridge domains for the EPs |
| 4275 | # |
| 4276 | bd1 = VppBridgeDomain(self, 1) |
| 4277 | bd1.add_vpp_config() |
| 4278 | gbd1 = VppGbpBridgeDomain(self, bd1, rd1, self.loop0) |
| 4279 | gbd1.add_vpp_config() |
| 4280 | |
| 4281 | bd2 = VppBridgeDomain(self, 2) |
| 4282 | bd2.add_vpp_config() |
| 4283 | gbd2 = VppGbpBridgeDomain(self, bd2, rd1, self.loop1) |
| 4284 | gbd2.add_vpp_config() |
| 4285 | |
| 4286 | # ... and has a /32 and /128 applied |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 4287 | ip4_addr1 = VppIpInterfaceAddress(self, gbd1.bvi, |
| 4288 | "10.0.0.128", 32, |
| 4289 | bind=b_lo0_ip4).add_vpp_config() |
| 4290 | ip6_addr1 = VppIpInterfaceAddress(self, gbd1.bvi, |
| 4291 | "2001:10::128", 128, |
| 4292 | bind=b_lo0_ip6).add_vpp_config() |
| 4293 | ip4_addr2 = VppIpInterfaceAddress(self, gbd2.bvi, |
| 4294 | "10.0.1.128", 32, |
| 4295 | bind=b_lo1_ip4).add_vpp_config() |
| 4296 | ip6_addr2 = VppIpInterfaceAddress(self, gbd2.bvi, |
| 4297 | "2001:11::128", 128, |
| 4298 | bind=b_lo1_ip6).add_vpp_config() |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4299 | |
| 4300 | # |
| 4301 | # The Endpoint-groups |
| 4302 | # |
| 4303 | epg_220 = VppGbpEndpointGroup(self, 220, 440, rd1, gbd1, |
| 4304 | None, gbd1.bvi, |
| 4305 | "10.0.0.128", |
| 4306 | "2001:10::128", |
Neale Ranns | 8d0d8d2 | 2020-04-07 08:44:20 +0000 | [diff] [blame] | 4307 | VppGbpEndpointRetention(60)) |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4308 | epg_220.add_vpp_config() |
| 4309 | epg_221 = VppGbpEndpointGroup(self, 221, 441, rd1, gbd2, |
| 4310 | None, gbd2.bvi, |
| 4311 | "10.0.1.128", |
| 4312 | "2001:11::128", |
Neale Ranns | 8d0d8d2 | 2020-04-07 08:44:20 +0000 | [diff] [blame] | 4313 | VppGbpEndpointRetention(60)) |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4314 | epg_221.add_vpp_config() |
| 4315 | |
| 4316 | # |
| 4317 | # a GBP bridge domains for the SEPs |
| 4318 | # |
| 4319 | bd_uu3 = VppVxlanGbpTunnel(self, self.pg7.local_ip4, |
| 4320 | self.pg7.remote_ip4, 116) |
| 4321 | bd_uu3.add_vpp_config() |
| 4322 | |
| 4323 | bd3 = VppBridgeDomain(self, 3) |
| 4324 | bd3.add_vpp_config() |
| 4325 | gbd3 = VppGbpBridgeDomain(self, bd3, rd1, self.loop2, |
| 4326 | bd_uu3, learn=False) |
| 4327 | gbd3.add_vpp_config() |
| 4328 | |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 4329 | ip4_addr3 = VppIpInterfaceAddress(self, gbd3.bvi, |
| 4330 | "12.0.0.128", 32, |
| 4331 | bind=b_lo2_ip4).add_vpp_config() |
| 4332 | ip6_addr3 = VppIpInterfaceAddress(self, gbd3.bvi, |
| 4333 | "4001:10::128", 128, |
| 4334 | bind=b_lo2_ip6).add_vpp_config() |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4335 | |
| 4336 | # |
| 4337 | # self.logger.info(self.vapi.cli("show gbp bridge")) |
| 4338 | # self.logger.info(self.vapi.cli("show vxlan-gbp tunnel")) |
| 4339 | # self.logger.info(self.vapi.cli("show gbp vxlan")) |
| 4340 | # self.logger.info(self.vapi.cli("show int addr")) |
| 4341 | # |
| 4342 | |
| 4343 | # |
| 4344 | # EPGs in which the service endpoints exist |
| 4345 | # |
| 4346 | epg_320 = VppGbpEndpointGroup(self, 320, 550, rd1, gbd3, |
| 4347 | None, gbd3.bvi, |
| 4348 | "12.0.0.128", |
| 4349 | "4001:10::128", |
Neale Ranns | 8d0d8d2 | 2020-04-07 08:44:20 +0000 | [diff] [blame] | 4350 | VppGbpEndpointRetention(60)) |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4351 | epg_320.add_vpp_config() |
| 4352 | |
| 4353 | # |
| 4354 | # endpoints |
| 4355 | # |
| 4356 | ep1 = VppGbpEndpoint(self, self.pg0, |
| 4357 | epg_220, None, |
| 4358 | "10.0.0.1", "11.0.0.1", |
| 4359 | "2001:10::1", "3001:10::1") |
| 4360 | ep1.add_vpp_config() |
| 4361 | ep2 = VppGbpEndpoint(self, self.pg1, |
| 4362 | epg_221, None, |
| 4363 | "10.0.1.1", "11.0.1.1", |
| 4364 | "2001:11::1", "3001:11::1") |
| 4365 | ep2.add_vpp_config() |
| 4366 | |
| 4367 | # |
| 4368 | # service endpoints |
| 4369 | # |
| 4370 | sep1 = VppGbpEndpoint(self, self.pg3, |
| 4371 | epg_320, None, |
| 4372 | "12.0.0.1", "13.0.0.1", |
| 4373 | "4001:10::1", "5001:10::1") |
| 4374 | sep2 = VppGbpEndpoint(self, self.pg4, |
| 4375 | epg_320, None, |
| 4376 | "12.0.0.2", "13.0.0.2", |
| 4377 | "4001:10::2", "5001:10::2") |
| 4378 | |
| 4379 | # sep1 and sep2 are not added to config yet |
| 4380 | # they are unknown for now |
| 4381 | |
| 4382 | # |
| 4383 | # add routes to EPG subnets |
| 4384 | # |
| 4385 | VppGbpSubnet(self, rd1, "10.0.0.0", 24, |
| 4386 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_TRANSPORT |
| 4387 | ).add_vpp_config() |
| 4388 | VppGbpSubnet(self, rd1, "10.0.1.0", 24, |
| 4389 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_TRANSPORT |
| 4390 | ).add_vpp_config() |
| 4391 | |
| 4392 | # |
| 4393 | # Local host to known local host in different BD |
| 4394 | # with SFC contract (source and destination are in |
| 4395 | # one node and service endpoint in another node) |
| 4396 | # |
| 4397 | p4 = [(Ether(src=ep1.mac, dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4398 | IP(src=ep1.ip4, dst=ep2.ip4) / |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4399 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 4400 | Raw(b'\xa5' * 100)), |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4401 | (Ether(src=ep2.mac, dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4402 | IP(src=ep2.ip4, dst=ep1.ip4) / |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4403 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 4404 | Raw(b'\xa5' * 100))] |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4405 | p6 = [(Ether(src=ep1.mac, dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4406 | IPv6(src=ep1.ip6, dst=ep2.ip6) / |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4407 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 4408 | Raw(b'\xa5' * 100)), |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4409 | (Ether(src=ep2.mac, dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4410 | IPv6(src=ep2.ip6, dst=ep1.ip6) / |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4411 | UDP(sport=1234, dport=1230) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 4412 | Raw(b'\xa5' * 100))] |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4413 | |
| 4414 | # should be dropped since no contract yet |
| 4415 | self.send_and_assert_no_replies(self.pg0, [p4[0]]) |
| 4416 | self.send_and_assert_no_replies(self.pg0, [p6[0]]) |
| 4417 | |
| 4418 | # |
| 4419 | # Add a contract with a rule to load-balance redirect via SEP1 and SEP2 |
| 4420 | # one of the next-hops is via an EP that is not known |
| 4421 | # |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 4422 | rule4 = AclRule(is_permit=1, proto=17) |
| 4423 | rule6 = AclRule(src_prefix=IPv6Network((0, 0)), |
| 4424 | dst_prefix=IPv6Network((0, 0)), is_permit=1, proto=17) |
| 4425 | acl = VppAcl(self, rules=[rule4, rule6]) |
| 4426 | acl.add_vpp_config() |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4427 | |
| 4428 | # |
| 4429 | # test the src-ip hash mode |
| 4430 | # |
| 4431 | c1 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 4432 | self, 402, epg_220.sclass, epg_221.sclass, acl.acl_index, |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4433 | [VppGbpContractRule( |
| 4434 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 4435 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SYMMETRIC, |
| 4436 | [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd, |
| 4437 | sep1.ip4, sep1.epg.rd)]), |
| 4438 | VppGbpContractRule( |
| 4439 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 4440 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SYMMETRIC, |
| 4441 | [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd, |
| 4442 | sep1.ip6, sep1.epg.rd)])], |
| 4443 | [ETH_P_IP, ETH_P_IPV6]) |
| 4444 | c1.add_vpp_config() |
| 4445 | |
| 4446 | c2 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 4447 | self, 402, epg_221.sclass, epg_220.sclass, acl.acl_index, |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4448 | [VppGbpContractRule( |
| 4449 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 4450 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SYMMETRIC, |
| 4451 | [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd, |
| 4452 | sep1.ip4, sep1.epg.rd)]), |
| 4453 | VppGbpContractRule( |
| 4454 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_REDIRECT, |
| 4455 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SYMMETRIC, |
| 4456 | [VppGbpContractNextHop(sep1.vmac, sep1.epg.bd, |
| 4457 | sep1.ip6, sep1.epg.rd)])], |
| 4458 | [ETH_P_IP, ETH_P_IPV6]) |
| 4459 | c2.add_vpp_config() |
| 4460 | |
| 4461 | # ep1 <--> ep2 redirected through sep1 |
| 4462 | # sep1 is unknown |
| 4463 | # packet is redirected to sep bd and then go through sep bd UU |
| 4464 | |
| 4465 | rxs = self.send_and_expect(self.pg0, p4[0] * 17, self.pg7) |
| 4466 | |
| 4467 | for rx in rxs: |
| 4468 | self.assertEqual(rx[Ether].src, self.pg7.local_mac) |
| 4469 | self.assertEqual(rx[Ether].dst, self.pg7.remote_mac) |
| 4470 | self.assertEqual(rx[IP].src, self.pg7.local_ip4) |
| 4471 | self.assertEqual(rx[IP].dst, self.pg7.remote_ip4) |
| 4472 | self.assertEqual(rx[VXLAN].vni, 116) |
| 4473 | self.assertTrue(rx[VXLAN].flags.G) |
| 4474 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 4475 | # redirect policy has been applied |
| 4476 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 4477 | self.assertFalse(rx[VXLAN].gpflags.D) |
| 4478 | |
| 4479 | inner = rx[VXLAN].payload |
| 4480 | |
| 4481 | self.assertEqual(inner[Ether].src, routed_src_mac) |
| 4482 | self.assertEqual(inner[Ether].dst, sep1.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4483 | self.assertEqual(inner[IP].src, ep1.ip4) |
| 4484 | self.assertEqual(inner[IP].dst, ep2.ip4) |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4485 | |
| 4486 | rxs = self.send_and_expect(self.pg1, p4[1] * 17, self.pg7) |
| 4487 | |
| 4488 | for rx in rxs: |
| 4489 | self.assertEqual(rx[Ether].src, self.pg7.local_mac) |
| 4490 | self.assertEqual(rx[Ether].dst, self.pg7.remote_mac) |
| 4491 | self.assertEqual(rx[IP].src, self.pg7.local_ip4) |
| 4492 | self.assertEqual(rx[IP].dst, self.pg7.remote_ip4) |
| 4493 | self.assertEqual(rx[VXLAN].vni, 116) |
| 4494 | self.assertTrue(rx[VXLAN].flags.G) |
| 4495 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 4496 | # redirect policy has been applied |
| 4497 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 4498 | self.assertFalse(rx[VXLAN].gpflags.D) |
| 4499 | |
| 4500 | inner = rx[VXLAN].payload |
| 4501 | |
| 4502 | self.assertEqual(inner[Ether].src, routed_src_mac) |
| 4503 | self.assertEqual(inner[Ether].dst, sep1.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4504 | self.assertEqual(inner[IP].src, ep2.ip4) |
| 4505 | self.assertEqual(inner[IP].dst, ep1.ip4) |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4506 | |
| 4507 | rxs = self.send_and_expect(self.pg0, p6[0] * 17, self.pg7) |
| 4508 | |
| 4509 | for rx in rxs: |
| 4510 | self.assertEqual(rx[Ether].src, self.pg7.local_mac) |
| 4511 | self.assertEqual(rx[Ether].dst, self.pg7.remote_mac) |
| 4512 | self.assertEqual(rx[IP].src, self.pg7.local_ip4) |
| 4513 | self.assertEqual(rx[IP].dst, self.pg7.remote_ip4) |
| 4514 | self.assertEqual(rx[VXLAN].vni, 116) |
| 4515 | self.assertTrue(rx[VXLAN].flags.G) |
| 4516 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 4517 | # redirect policy has been applied |
| 4518 | inner = rx[VXLAN].payload |
| 4519 | |
| 4520 | self.assertEqual(inner[Ether].src, routed_src_mac) |
| 4521 | self.assertEqual(inner[Ether].dst, sep1.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4522 | self.assertEqual(inner[IPv6].src, ep1.ip6) |
| 4523 | self.assertEqual(inner[IPv6].dst, ep2.ip6) |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4524 | |
| 4525 | rxs = self.send_and_expect(self.pg1, p6[1] * 17, self.pg7) |
| 4526 | |
| 4527 | for rx in rxs: |
| 4528 | self.assertEqual(rx[Ether].src, self.pg7.local_mac) |
| 4529 | self.assertEqual(rx[Ether].dst, self.pg7.remote_mac) |
| 4530 | self.assertEqual(rx[IP].src, self.pg7.local_ip4) |
| 4531 | self.assertEqual(rx[IP].dst, self.pg7.remote_ip4) |
| 4532 | self.assertEqual(rx[VXLAN].vni, 116) |
| 4533 | self.assertTrue(rx[VXLAN].flags.G) |
| 4534 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 4535 | # redirect policy has been applied |
| 4536 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 4537 | self.assertFalse(rx[VXLAN].gpflags.D) |
| 4538 | |
| 4539 | inner = rx[VXLAN].payload |
| 4540 | |
| 4541 | self.assertEqual(inner[Ether].src, routed_src_mac) |
| 4542 | self.assertEqual(inner[Ether].dst, sep1.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4543 | self.assertEqual(inner[IPv6].src, ep2.ip6) |
| 4544 | self.assertEqual(inner[IPv6].dst, ep1.ip6) |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4545 | |
| 4546 | # configure sep1: it is now local |
| 4547 | # packets between ep1 and ep2 are redirected locally |
| 4548 | sep1.add_vpp_config() |
| 4549 | |
| 4550 | rxs = self.send_and_expect(self.pg0, p4[0] * 17, sep1.itf) |
| 4551 | |
| 4552 | for rx in rxs: |
| 4553 | self.assertEqual(rx[Ether].src, routed_src_mac) |
| 4554 | self.assertEqual(rx[Ether].dst, sep1.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4555 | self.assertEqual(rx[IP].src, ep1.ip4) |
| 4556 | self.assertEqual(rx[IP].dst, ep2.ip4) |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4557 | |
| 4558 | rxs = self.send_and_expect(self.pg1, p6[1] * 17, sep1.itf) |
| 4559 | |
| 4560 | for rx in rxs: |
| 4561 | self.assertEqual(rx[Ether].src, routed_src_mac) |
| 4562 | self.assertEqual(rx[Ether].dst, sep1.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4563 | self.assertEqual(rx[IPv6].src, ep2.ip6) |
| 4564 | self.assertEqual(rx[IPv6].dst, ep1.ip6) |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4565 | |
| 4566 | # packet coming from the l2 spine-proxy to sep1 |
| 4567 | p = (Ether(src=self.pg7.remote_mac, |
| 4568 | dst=self.pg7.local_mac) / |
| 4569 | IP(src=self.pg7.remote_ip4, |
| 4570 | dst=self.pg7.local_ip4) / |
| 4571 | UDP(sport=1234, dport=48879) / |
| 4572 | VXLAN(vni=116, gpid=440, gpflags=0x08, flags=0x88) / |
| 4573 | Ether(src=str(self.router_mac), dst=sep1.mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4574 | IP(src=ep1.ip4, dst=ep2.ip4) / |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4575 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 4576 | Raw(b'\xa5' * 100)) |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4577 | |
| 4578 | rxs = self.send_and_expect(self.pg7, [p] * 17, sep1.itf) |
| 4579 | |
| 4580 | for rx in rxs: |
| 4581 | self.assertEqual(rx[Ether].src, str(self.router_mac)) |
| 4582 | self.assertEqual(rx[Ether].dst, sep1.mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4583 | self.assertEqual(rx[IP].src, ep1.ip4) |
| 4584 | self.assertEqual(rx[IP].dst, ep2.ip4) |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4585 | |
| 4586 | # contract for SEP to communicate with dst EP |
| 4587 | c3 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 4588 | self, 402, epg_320.sclass, epg_221.sclass, acl.acl_index, |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4589 | [VppGbpContractRule( |
| 4590 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
| 4591 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SYMMETRIC), |
| 4592 | VppGbpContractRule( |
| 4593 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
| 4594 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SYMMETRIC)], |
| 4595 | [ETH_P_IP, ETH_P_IPV6]) |
| 4596 | c3.add_vpp_config() |
| 4597 | |
| 4598 | # temporarily remove ep2, so that ep2 is remote & unknown |
| 4599 | ep2.remove_vpp_config() |
| 4600 | |
| 4601 | # packet going back from sep1 to its original dest (ep2) |
| 4602 | # as ep2 is now unknown (see above), it must go through |
| 4603 | # the rd UU (packet is routed) |
| 4604 | |
| 4605 | p1 = (Ether(src=sep1.mac, dst=self.router_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4606 | IP(src=ep1.ip4, dst=ep2.ip4) / |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4607 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 4608 | Raw(b'\xa5' * 100)) |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4609 | |
| 4610 | rxs = self.send_and_expect(self.pg3, [p1] * 17, self.pg7) |
| 4611 | |
| 4612 | for rx in rxs: |
| 4613 | self.assertEqual(rx[Ether].src, self.pg7.local_mac) |
| 4614 | self.assertEqual(rx[Ether].dst, self.pg7.remote_mac) |
| 4615 | self.assertEqual(rx[IP].src, self.pg7.local_ip4) |
| 4616 | self.assertEqual(rx[IP].dst, self.pg7.remote_ip4) |
| 4617 | self.assertEqual(rx[VXLAN].vni, 114) |
| 4618 | self.assertTrue(rx[VXLAN].flags.G) |
| 4619 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 4620 | # redirect policy has been applied |
| 4621 | inner = rx[VXLAN].payload |
| 4622 | self.assertEqual(inner[Ether].src, routed_src_mac) |
| 4623 | self.assertEqual(inner[Ether].dst, routed_dst_mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4624 | self.assertEqual(inner[IP].src, ep1.ip4) |
| 4625 | self.assertEqual(inner[IP].dst, ep2.ip4) |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4626 | |
| 4627 | self.logger.info(self.vapi.cli("show bridge 3 detail")) |
| 4628 | sep1.remove_vpp_config() |
| 4629 | |
| 4630 | self.logger.info(self.vapi.cli("show bridge 1 detail")) |
| 4631 | self.logger.info(self.vapi.cli("show bridge 2 detail")) |
| 4632 | |
| 4633 | # re-add ep2: it is local again :) |
| 4634 | ep2.add_vpp_config() |
| 4635 | |
| 4636 | # packet coming back from the remote sep through rd UU |
| 4637 | p2 = (Ether(src=self.pg7.remote_mac, |
| 4638 | dst=self.pg7.local_mac) / |
| 4639 | IP(src=self.pg7.remote_ip4, |
| 4640 | dst=self.pg7.local_ip4) / |
| 4641 | UDP(sport=1234, dport=48879) / |
| 4642 | VXLAN(vni=114, gpid=441, gpflags=0x09, flags=0x88) / |
| 4643 | Ether(src=str(self.router_mac), dst=self.router_mac) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4644 | IP(src=ep1.ip4, dst=ep2.ip4) / |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4645 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 4646 | Raw(b'\xa5' * 100)) |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4647 | |
| 4648 | rxs = self.send_and_expect(self.pg7, [p2], self.pg1) |
| 4649 | |
| 4650 | for rx in rxs: |
| 4651 | self.assertEqual(rx[Ether].src, str(self.router_mac)) |
| 4652 | self.assertEqual(rx[Ether].dst, self.pg1.remote_mac) |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4653 | self.assertEqual(rx[IP].src, ep1.ip4) |
| 4654 | self.assertEqual(rx[IP].dst, ep2.ip4) |
Mohsin Kazmi | a3c8ca1 | 2019-07-10 18:45:55 +0200 | [diff] [blame] | 4655 | |
| 4656 | # |
| 4657 | # bd_uu2.add_vpp_config() |
| 4658 | # |
| 4659 | |
| 4660 | # |
| 4661 | # cleanup |
| 4662 | # |
| 4663 | c1.remove_vpp_config() |
| 4664 | c2.remove_vpp_config() |
| 4665 | c3.remove_vpp_config() |
| 4666 | self.pg7.unconfig_ip4() |
| 4667 | |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4668 | def test_gbp_l3_out(self): |
| 4669 | """ GBP L3 Out """ |
| 4670 | |
| 4671 | ep_flags = VppEnum.vl_api_gbp_endpoint_flags_t |
Paul Vinciguerra | 9673e3e | 2019-05-10 20:41:08 -0400 | [diff] [blame] | 4672 | self.vapi.cli("set logging class gbp level debug") |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4673 | |
| 4674 | routed_dst_mac = "00:0c:0c:0c:0c:0c" |
| 4675 | routed_src_mac = "00:22:bd:f8:19:ff" |
| 4676 | |
| 4677 | # |
| 4678 | # IP tables |
| 4679 | # |
| 4680 | t4 = VppIpTable(self, 1) |
| 4681 | t4.add_vpp_config() |
| 4682 | t6 = VppIpTable(self, 1, True) |
| 4683 | t6.add_vpp_config() |
| 4684 | |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 4685 | rd1 = VppGbpRouteDomain(self, 2, 55, t4, t6) |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4686 | rd1.add_vpp_config() |
| 4687 | |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 4688 | self.loop0.set_mac(self.router_mac) |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4689 | |
| 4690 | # |
| 4691 | # Bind the BVI to the RD |
| 4692 | # |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 4693 | b_ip4 = VppIpInterfaceBind(self, self.loop0, t4).add_vpp_config() |
| 4694 | b_ip6 = VppIpInterfaceBind(self, self.loop0, t6).add_vpp_config() |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4695 | |
| 4696 | # |
| 4697 | # Pg7 hosts a BD's BUM |
| 4698 | # Pg1 some other l3 interface |
| 4699 | # |
| 4700 | self.pg7.config_ip4() |
| 4701 | self.pg7.resolve_arp() |
| 4702 | |
| 4703 | # |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 4704 | # a multicast vxlan-gbp tunnel for broadcast in the BD |
| 4705 | # |
| 4706 | tun_bm = VppVxlanGbpTunnel(self, self.pg7.local_ip4, |
| 4707 | "239.1.1.1", 88, |
| 4708 | mcast_itf=self.pg7) |
| 4709 | tun_bm.add_vpp_config() |
| 4710 | |
| 4711 | # |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4712 | # a GBP external bridge domains for the EPs |
| 4713 | # |
| 4714 | bd1 = VppBridgeDomain(self, 1) |
| 4715 | bd1.add_vpp_config() |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 4716 | gbd1 = VppGbpBridgeDomain(self, bd1, rd1, self.loop0, None, tun_bm) |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4717 | gbd1.add_vpp_config() |
| 4718 | |
| 4719 | # |
| 4720 | # The Endpoint-groups in which the external endpoints exist |
| 4721 | # |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 4722 | epg_220 = VppGbpEndpointGroup(self, 220, 113, rd1, gbd1, |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4723 | None, gbd1.bvi, |
| 4724 | "10.0.0.128", |
Neale Ranns | 32f6d8e | 2019-03-05 04:22:08 -0800 | [diff] [blame] | 4725 | "2001:10::128", |
Neale Ranns | 8d0d8d2 | 2020-04-07 08:44:20 +0000 | [diff] [blame] | 4726 | VppGbpEndpointRetention(4)) |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4727 | epg_220.add_vpp_config() |
| 4728 | |
| 4729 | # the BVIs have the subnets applied ... |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 4730 | ip4_addr = VppIpInterfaceAddress(self, gbd1.bvi, "10.0.0.128", |
| 4731 | 24, bind=b_ip4).add_vpp_config() |
| 4732 | ip6_addr = VppIpInterfaceAddress(self, gbd1.bvi, "2001:10::128", |
| 4733 | 64, bind=b_ip6).add_vpp_config() |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4734 | |
| 4735 | # ... which are L3-out subnets |
| 4736 | l3o_1 = VppGbpSubnet( |
| 4737 | self, rd1, "10.0.0.0", 24, |
| 4738 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 4739 | sclass=113) |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4740 | l3o_1.add_vpp_config() |
| 4741 | |
| 4742 | # |
| 4743 | # an external interface attached to the outside world and the |
| 4744 | # external BD |
| 4745 | # |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 4746 | VppL2Vtr(self, self.vlan_100, L2_VTR_OP.L2_POP_1).add_vpp_config() |
| 4747 | VppL2Vtr(self, self.vlan_101, L2_VTR_OP.L2_POP_1).add_vpp_config() |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 4748 | vlan_144 = VppDot1QSubint(self, self.pg0, 144) |
| 4749 | vlan_144.admin_up() |
Benoît Ganne | 286921e | 2019-06-05 19:08:40 +0200 | [diff] [blame] | 4750 | # vlan_102 is not poped |
Neale Ranns | 36abbf1 | 2019-03-12 02:34:07 -0700 | [diff] [blame] | 4751 | |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4752 | # |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 4753 | # an unicast vxlan-gbp for inter-RD traffic |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4754 | # |
| 4755 | vx_tun_l3 = VppGbpVxlanTunnel( |
| 4756 | self, 444, rd1.rd_id, |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 4757 | VppEnum.vl_api_gbp_vxlan_tunnel_mode_t.GBP_VXLAN_TUNNEL_MODE_L3, |
| 4758 | self.pg2.local_ip4) |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4759 | vx_tun_l3.add_vpp_config() |
| 4760 | |
| 4761 | # |
Neale Ranns | 36abbf1 | 2019-03-12 02:34:07 -0700 | [diff] [blame] | 4762 | # External Endpoints |
| 4763 | # |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 4764 | eep1 = VppGbpEndpoint(self, self.vlan_100, |
Neale Ranns | 36abbf1 | 2019-03-12 02:34:07 -0700 | [diff] [blame] | 4765 | epg_220, None, |
| 4766 | "10.0.0.1", "11.0.0.1", |
| 4767 | "2001:10::1", "3001::1", |
| 4768 | ep_flags.GBP_API_ENDPOINT_FLAG_EXTERNAL) |
| 4769 | eep1.add_vpp_config() |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 4770 | eep2 = VppGbpEndpoint(self, self.vlan_101, |
Neale Ranns | 36abbf1 | 2019-03-12 02:34:07 -0700 | [diff] [blame] | 4771 | epg_220, None, |
| 4772 | "10.0.0.2", "11.0.0.2", |
| 4773 | "2001:10::2", "3001::2", |
| 4774 | ep_flags.GBP_API_ENDPOINT_FLAG_EXTERNAL) |
| 4775 | eep2.add_vpp_config() |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 4776 | eep3 = VppGbpEndpoint(self, self.vlan_102, |
Benoît Ganne | 286921e | 2019-06-05 19:08:40 +0200 | [diff] [blame] | 4777 | epg_220, None, |
| 4778 | "10.0.0.3", "11.0.0.3", |
| 4779 | "2001:10::3", "3001::3", |
| 4780 | ep_flags.GBP_API_ENDPOINT_FLAG_EXTERNAL) |
| 4781 | eep3.add_vpp_config() |
Neale Ranns | 36abbf1 | 2019-03-12 02:34:07 -0700 | [diff] [blame] | 4782 | |
| 4783 | # |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 4784 | # A remote external endpoint |
Neale Ranns | 36abbf1 | 2019-03-12 02:34:07 -0700 | [diff] [blame] | 4785 | # |
| 4786 | rep = VppGbpEndpoint(self, vx_tun_l3, |
| 4787 | epg_220, None, |
| 4788 | "10.0.0.101", "11.0.0.101", |
| 4789 | "2001:10::101", "3001::101", |
| 4790 | ep_flags.GBP_API_ENDPOINT_FLAG_REMOTE, |
| 4791 | self.pg7.local_ip4, |
| 4792 | self.pg7.remote_ip4, |
| 4793 | mac=None) |
| 4794 | rep.add_vpp_config() |
| 4795 | |
| 4796 | # |
Benoît Ganne | c47b97d | 2019-06-06 17:53:21 +0200 | [diff] [blame] | 4797 | # EP1 impersonating EP3 is dropped |
| 4798 | # |
| 4799 | p = (Ether(src=eep1.mac, dst="ff:ff:ff:ff:ff:ff") / |
| 4800 | Dot1Q(vlan=100) / |
| 4801 | ARP(op="who-has", |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 4802 | psrc="10.0.0.3", pdst="10.0.0.128", |
| 4803 | hwsrc=eep1.mac, hwdst="ff:ff:ff:ff:ff:ff")) |
Benoît Ganne | c47b97d | 2019-06-06 17:53:21 +0200 | [diff] [blame] | 4804 | self.send_and_assert_no_replies(self.pg0, p) |
| 4805 | |
| 4806 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 4807 | # ARP packet from External EPs are accepted and replied to |
Neale Ranns | 4c2bff0 | 2019-03-14 02:52:27 -0700 | [diff] [blame] | 4808 | # |
| 4809 | p_arp = (Ether(src=eep1.mac, dst="ff:ff:ff:ff:ff:ff") / |
| 4810 | Dot1Q(vlan=100) / |
| 4811 | ARP(op="who-has", |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4812 | psrc=eep1.ip4, pdst="10.0.0.128", |
Neale Ranns | 4c2bff0 | 2019-03-14 02:52:27 -0700 | [diff] [blame] | 4813 | hwsrc=eep1.mac, hwdst="ff:ff:ff:ff:ff:ff")) |
| 4814 | rxs = self.send_and_expect(self.pg0, p_arp * 1, self.pg0) |
| 4815 | |
| 4816 | # |
Benoît Ganne | 286921e | 2019-06-05 19:08:40 +0200 | [diff] [blame] | 4817 | # ARP packet from host in remote subnet are accepted and replied to |
| 4818 | # |
Benoît Ganne | c47b97d | 2019-06-06 17:53:21 +0200 | [diff] [blame] | 4819 | p_arp = (Ether(src=eep3.mac, dst="ff:ff:ff:ff:ff:ff") / |
Benoît Ganne | 286921e | 2019-06-05 19:08:40 +0200 | [diff] [blame] | 4820 | Dot1Q(vlan=102) / |
| 4821 | ARP(op="who-has", |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4822 | psrc=eep3.ip4, pdst="10.0.0.128", |
Benoît Ganne | c47b97d | 2019-06-06 17:53:21 +0200 | [diff] [blame] | 4823 | hwsrc=eep3.mac, hwdst="ff:ff:ff:ff:ff:ff")) |
Benoît Ganne | 286921e | 2019-06-05 19:08:40 +0200 | [diff] [blame] | 4824 | rxs = self.send_and_expect(self.pg0, p_arp * 1, self.pg0) |
| 4825 | |
| 4826 | # |
Paul Vinciguerra | a7427ec | 2019-03-10 10:04:23 -0700 | [diff] [blame] | 4827 | # packets destined to unknown addresses in the BVI's subnet |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4828 | # are ARP'd for |
| 4829 | # |
Neale Ranns | 36abbf1 | 2019-03-12 02:34:07 -0700 | [diff] [blame] | 4830 | p4 = (Ether(src=eep1.mac, dst=str(self.router_mac)) / |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4831 | Dot1Q(vlan=100) / |
| 4832 | IP(src="10.0.0.1", dst="10.0.0.88") / |
| 4833 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 4834 | Raw(b'\xa5' * 100)) |
Neale Ranns | 36abbf1 | 2019-03-12 02:34:07 -0700 | [diff] [blame] | 4835 | p6 = (Ether(src=eep1.mac, dst=str(self.router_mac)) / |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4836 | Dot1Q(vlan=100) / |
| 4837 | IPv6(src="2001:10::1", dst="2001:10::88") / |
| 4838 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 4839 | Raw(b'\xa5' * 100)) |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4840 | |
| 4841 | rxs = self.send_and_expect(self.pg0, p4 * 1, self.pg7) |
| 4842 | |
| 4843 | for rx in rxs: |
| 4844 | self.assertEqual(rx[Ether].src, self.pg7.local_mac) |
| 4845 | # self.assertEqual(rx[Ether].dst, self.pg7.remote_mac) |
| 4846 | self.assertEqual(rx[IP].src, self.pg7.local_ip4) |
| 4847 | self.assertEqual(rx[IP].dst, "239.1.1.1") |
| 4848 | self.assertEqual(rx[VXLAN].vni, 88) |
| 4849 | self.assertTrue(rx[VXLAN].flags.G) |
| 4850 | self.assertTrue(rx[VXLAN].flags.Instance) |
Neale Ranns | 45db885 | 2019-01-09 00:04:04 -0800 | [diff] [blame] | 4851 | # policy was applied to the original IP packet |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 4852 | self.assertEqual(rx[VXLAN].gpid, 113) |
Neale Ranns | 45db885 | 2019-01-09 00:04:04 -0800 | [diff] [blame] | 4853 | self.assertTrue(rx[VXLAN].gpflags.A) |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4854 | self.assertFalse(rx[VXLAN].gpflags.D) |
| 4855 | |
| 4856 | inner = rx[VXLAN].payload |
| 4857 | |
| 4858 | self.assertTrue(inner.haslayer(ARP)) |
| 4859 | |
| 4860 | # |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4861 | # remote to external |
| 4862 | # |
| 4863 | p = (Ether(src=self.pg7.remote_mac, |
| 4864 | dst=self.pg7.local_mac) / |
| 4865 | IP(src=self.pg7.remote_ip4, |
| 4866 | dst=self.pg7.local_ip4) / |
| 4867 | UDP(sport=1234, dport=48879) / |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 4868 | VXLAN(vni=444, gpid=113, flags=0x88) / |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 4869 | Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) / |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4870 | IP(src="10.0.0.101", dst="10.0.0.1") / |
| 4871 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 4872 | Raw(b'\xa5' * 100)) |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4873 | |
| 4874 | rxs = self.send_and_expect(self.pg7, p * 1, self.pg0) |
| 4875 | |
| 4876 | # |
Neale Ranns | 36abbf1 | 2019-03-12 02:34:07 -0700 | [diff] [blame] | 4877 | # local EP pings router |
| 4878 | # |
| 4879 | p = (Ether(src=eep1.mac, dst=str(self.router_mac)) / |
| 4880 | Dot1Q(vlan=100) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4881 | IP(src=eep1.ip4, dst="10.0.0.128") / |
Neale Ranns | 36abbf1 | 2019-03-12 02:34:07 -0700 | [diff] [blame] | 4882 | ICMP(type='echo-request')) |
| 4883 | |
| 4884 | rxs = self.send_and_expect(self.pg0, p * 1, self.pg0) |
| 4885 | |
| 4886 | for rx in rxs: |
| 4887 | self.assertEqual(rx[Ether].src, str(self.router_mac)) |
| 4888 | self.assertEqual(rx[Ether].dst, eep1.mac) |
| 4889 | self.assertEqual(rx[Dot1Q].vlan, 100) |
| 4890 | |
| 4891 | # |
| 4892 | # local EP pings other local EP |
| 4893 | # |
| 4894 | p = (Ether(src=eep1.mac, dst=eep2.mac) / |
| 4895 | Dot1Q(vlan=100) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4896 | IP(src=eep1.ip4, dst=eep2.ip4) / |
Neale Ranns | 36abbf1 | 2019-03-12 02:34:07 -0700 | [diff] [blame] | 4897 | ICMP(type='echo-request')) |
| 4898 | |
| 4899 | rxs = self.send_and_expect(self.pg0, p * 1, self.pg0) |
| 4900 | |
| 4901 | for rx in rxs: |
| 4902 | self.assertEqual(rx[Ether].src, eep1.mac) |
| 4903 | self.assertEqual(rx[Ether].dst, eep2.mac) |
| 4904 | self.assertEqual(rx[Dot1Q].vlan, 101) |
| 4905 | |
| 4906 | # |
Benoît Ganne | 286921e | 2019-06-05 19:08:40 +0200 | [diff] [blame] | 4907 | # local EP pings router w/o vlan tag poped |
| 4908 | # |
| 4909 | p = (Ether(src=eep3.mac, dst=str(self.router_mac)) / |
| 4910 | Dot1Q(vlan=102) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4911 | IP(src=eep3.ip4, dst="10.0.0.128") / |
Benoît Ganne | 286921e | 2019-06-05 19:08:40 +0200 | [diff] [blame] | 4912 | ICMP(type='echo-request')) |
| 4913 | |
| 4914 | rxs = self.send_and_expect(self.pg0, p * 1, self.pg0) |
| 4915 | |
| 4916 | for rx in rxs: |
| 4917 | self.assertEqual(rx[Ether].src, str(self.router_mac)) |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 4918 | self.assertEqual(rx[Ether].dst, self.vlan_102.remote_mac) |
Benoît Ganne | 286921e | 2019-06-05 19:08:40 +0200 | [diff] [blame] | 4919 | |
| 4920 | # |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 4921 | # A ip4 subnet reachable through the external EP1 |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4922 | # |
| 4923 | ip_220 = VppIpRoute(self, "10.220.0.0", 24, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4924 | [VppRoutePath(eep1.ip4, |
Neale Ranns | 36abbf1 | 2019-03-12 02:34:07 -0700 | [diff] [blame] | 4925 | eep1.epg.bvi.sw_if_index)], |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4926 | table_id=t4.table_id) |
| 4927 | ip_220.add_vpp_config() |
| 4928 | |
| 4929 | l3o_220 = VppGbpSubnet( |
| 4930 | self, rd1, "10.220.0.0", 24, |
| 4931 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 4932 | sclass=4220) |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 4933 | l3o_220.add_vpp_config() |
| 4934 | |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 4935 | # |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 4936 | # An ip6 subnet reachable through the external EP1 |
| 4937 | # |
| 4938 | ip6_220 = VppIpRoute(self, "10:220::", 64, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4939 | [VppRoutePath(eep1.ip6, |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 4940 | eep1.epg.bvi.sw_if_index)], |
| 4941 | table_id=t6.table_id) |
| 4942 | ip6_220.add_vpp_config() |
| 4943 | |
| 4944 | l3o6_220 = VppGbpSubnet( |
| 4945 | self, rd1, "10:220::", 64, |
| 4946 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT, |
| 4947 | sclass=4220) |
| 4948 | l3o6_220.add_vpp_config() |
| 4949 | |
| 4950 | # |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 4951 | # A subnet reachable through the external EP2 |
| 4952 | # |
| 4953 | ip_221 = VppIpRoute(self, "10.221.0.0", 24, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 4954 | [VppRoutePath(eep2.ip4, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 4955 | eep2.epg.bvi.sw_if_index)], |
| 4956 | table_id=t4.table_id) |
| 4957 | ip_221.add_vpp_config() |
| 4958 | |
| 4959 | l3o_221 = VppGbpSubnet( |
| 4960 | self, rd1, "10.221.0.0", 24, |
| 4961 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT, |
| 4962 | sclass=4221) |
| 4963 | l3o_221.add_vpp_config() |
| 4964 | |
| 4965 | # |
| 4966 | # ping between hosts in remote subnets |
| 4967 | # dropped without a contract |
| 4968 | # |
| 4969 | p = (Ether(src=eep1.mac, dst=str(self.router_mac)) / |
| 4970 | Dot1Q(vlan=100) / |
| 4971 | IP(src="10.220.0.1", dst="10.221.0.1") / |
| 4972 | ICMP(type='echo-request')) |
| 4973 | |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 4974 | self.send_and_assert_no_replies(self.pg0, p * 1) |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 4975 | |
| 4976 | # |
| 4977 | # contract for the external nets to communicate |
| 4978 | # |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 4979 | rule4 = AclRule(is_permit=1, proto=17) |
| 4980 | rule6 = AclRule(src_prefix=IPv6Network((0, 0)), |
| 4981 | dst_prefix=IPv6Network((0, 0)), is_permit=1, proto=17) |
| 4982 | acl = VppAcl(self, rules=[rule4, rule6]) |
| 4983 | acl.add_vpp_config() |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 4984 | |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 4985 | # |
| 4986 | # A contract with the wrong scope is not matched |
| 4987 | # |
| 4988 | c_44 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 4989 | self, 44, 4220, 4221, acl.acl_index, |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 4990 | [VppGbpContractRule( |
| 4991 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Neale Ranns | bb098f1 | 2019-10-22 12:32:49 +0000 | [diff] [blame] | 4992 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 4993 | []), |
Neale Ranns | bb098f1 | 2019-10-22 12:32:49 +0000 | [diff] [blame] | 4994 | VppGbpContractRule( |
| 4995 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
| 4996 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
| 4997 | [])], |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 4998 | [ETH_P_IP, ETH_P_IPV6]) |
| 4999 | c_44.add_vpp_config() |
| 5000 | self.send_and_assert_no_replies(self.pg0, p * 1) |
| 5001 | |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5002 | c1 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 5003 | self, 55, 4220, 4221, acl.acl_index, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5004 | [VppGbpContractRule( |
| 5005 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 5006 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5007 | []), |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 5008 | VppGbpContractRule( |
| 5009 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 5010 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 5011 | [])], |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5012 | [ETH_P_IP, ETH_P_IPV6]) |
| 5013 | c1.add_vpp_config() |
| 5014 | |
| 5015 | # |
| 5016 | # Contracts allowing ext-net 200 to talk with external EPs |
| 5017 | # |
| 5018 | c2 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 5019 | self, 55, 4220, 113, acl.acl_index, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5020 | [VppGbpContractRule( |
| 5021 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 5022 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5023 | []), |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 5024 | VppGbpContractRule( |
| 5025 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 5026 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 5027 | [])], |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5028 | [ETH_P_IP, ETH_P_IPV6]) |
| 5029 | c2.add_vpp_config() |
| 5030 | c3 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 5031 | self, 55, 113, 4220, acl.acl_index, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5032 | [VppGbpContractRule( |
| 5033 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 5034 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5035 | []), |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 5036 | VppGbpContractRule( |
| 5037 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 5038 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 5039 | [])], |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5040 | [ETH_P_IP, ETH_P_IPV6]) |
| 5041 | c3.add_vpp_config() |
| 5042 | |
| 5043 | # |
| 5044 | # ping between hosts in remote subnets |
| 5045 | # |
| 5046 | p = (Ether(src=eep1.mac, dst=str(self.router_mac)) / |
| 5047 | Dot1Q(vlan=100) / |
| 5048 | IP(src="10.220.0.1", dst="10.221.0.1") / |
| 5049 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5050 | Raw(b'\xa5' * 100)) |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5051 | |
| 5052 | rxs = self.send_and_expect(self.pg0, p * 1, self.pg0) |
| 5053 | |
| 5054 | for rx in rxs: |
| 5055 | self.assertEqual(rx[Ether].src, str(self.router_mac)) |
| 5056 | self.assertEqual(rx[Ether].dst, eep2.mac) |
| 5057 | self.assertEqual(rx[Dot1Q].vlan, 101) |
| 5058 | |
| 5059 | # we did not learn these external hosts |
| 5060 | self.assertFalse(find_gbp_endpoint(self, ip="10.220.0.1")) |
| 5061 | self.assertFalse(find_gbp_endpoint(self, ip="10.221.0.1")) |
| 5062 | |
| 5063 | # |
| 5064 | # from remote external EP to local external EP |
| 5065 | # |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 5066 | p = (Ether(src=self.pg7.remote_mac, |
| 5067 | dst=self.pg7.local_mac) / |
| 5068 | IP(src=self.pg7.remote_ip4, |
| 5069 | dst=self.pg7.local_ip4) / |
| 5070 | UDP(sport=1234, dport=48879) / |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 5071 | VXLAN(vni=444, gpid=113, flags=0x88) / |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 5072 | Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) / |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 5073 | IP(src="10.0.0.101", dst="10.220.0.1") / |
| 5074 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5075 | Raw(b'\xa5' * 100)) |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 5076 | |
| 5077 | rxs = self.send_and_expect(self.pg7, p * 1, self.pg0) |
| 5078 | |
| 5079 | # |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5080 | # ping from an external host to the remote external EP |
Neale Ranns | 36abbf1 | 2019-03-12 02:34:07 -0700 | [diff] [blame] | 5081 | # |
| 5082 | p = (Ether(src=eep1.mac, dst=str(self.router_mac)) / |
| 5083 | Dot1Q(vlan=100) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 5084 | IP(src="10.220.0.1", dst=rep.ip4) / |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5085 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5086 | Raw(b'\xa5' * 100)) |
Neale Ranns | 36abbf1 | 2019-03-12 02:34:07 -0700 | [diff] [blame] | 5087 | |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5088 | rxs = self.send_and_expect(self.pg0, p * 1, self.pg7) |
Neale Ranns | 36abbf1 | 2019-03-12 02:34:07 -0700 | [diff] [blame] | 5089 | |
| 5090 | for rx in rxs: |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5091 | self.assertEqual(rx[Ether].src, self.pg7.local_mac) |
| 5092 | # self.assertEqual(rx[Ether].dst, self.pg7.remote_mac) |
| 5093 | self.assertEqual(rx[IP].src, self.pg7.local_ip4) |
| 5094 | self.assertEqual(rx[IP].dst, self.pg7.remote_ip4) |
| 5095 | self.assertEqual(rx[VXLAN].vni, 444) |
| 5096 | self.assertTrue(rx[VXLAN].flags.G) |
| 5097 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 5098 | # the sclass of the ext-net the packet came from |
| 5099 | self.assertEqual(rx[VXLAN].gpid, 4220) |
| 5100 | # policy was applied to the original IP packet |
| 5101 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 5102 | # since it's an external host the reciever should not learn it |
| 5103 | self.assertTrue(rx[VXLAN].gpflags.D) |
| 5104 | inner = rx[VXLAN].payload |
| 5105 | self.assertEqual(inner[IP].src, "10.220.0.1") |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 5106 | self.assertEqual(inner[IP].dst, rep.ip4) |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5107 | |
| 5108 | # |
| 5109 | # An external subnet reachable via the remote external EP |
| 5110 | # |
| 5111 | |
| 5112 | # |
| 5113 | # first the VXLAN-GBP tunnel over which it is reached |
| 5114 | # |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5115 | vx_tun_r1 = VppVxlanGbpTunnel( |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5116 | self, self.pg7.local_ip4, |
| 5117 | self.pg7.remote_ip4, 445, |
| 5118 | mode=(VppEnum.vl_api_vxlan_gbp_api_tunnel_mode_t. |
| 5119 | VXLAN_GBP_API_TUNNEL_MODE_L3)) |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5120 | vx_tun_r1.add_vpp_config() |
| 5121 | VppIpInterfaceBind(self, vx_tun_r1, t4).add_vpp_config() |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5122 | |
| 5123 | self.logger.info(self.vapi.cli("sh vxlan-gbp tunnel")) |
| 5124 | |
| 5125 | # |
| 5126 | # then the special adj to resolve through on that tunnel |
| 5127 | # |
| 5128 | n1 = VppNeighbor(self, |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5129 | vx_tun_r1.sw_if_index, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5130 | "00:0c:0c:0c:0c:0c", |
| 5131 | self.pg7.remote_ip4) |
| 5132 | n1.add_vpp_config() |
| 5133 | |
| 5134 | # |
| 5135 | # the route via the adj above |
| 5136 | # |
| 5137 | ip_222 = VppIpRoute(self, "10.222.0.0", 24, |
| 5138 | [VppRoutePath(self.pg7.remote_ip4, |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5139 | vx_tun_r1.sw_if_index)], |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5140 | table_id=t4.table_id) |
| 5141 | ip_222.add_vpp_config() |
| 5142 | |
| 5143 | l3o_222 = VppGbpSubnet( |
| 5144 | self, rd1, "10.222.0.0", 24, |
| 5145 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT, |
| 5146 | sclass=4222) |
| 5147 | l3o_222.add_vpp_config() |
| 5148 | |
| 5149 | # |
| 5150 | # ping between hosts in local and remote external subnets |
| 5151 | # dropped without a contract |
| 5152 | # |
| 5153 | p = (Ether(src=eep1.mac, dst=str(self.router_mac)) / |
| 5154 | Dot1Q(vlan=100) / |
| 5155 | IP(src="10.220.0.1", dst="10.222.0.1") / |
| 5156 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5157 | Raw(b'\xa5' * 100)) |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5158 | |
| 5159 | rxs = self.send_and_assert_no_replies(self.pg0, p * 1) |
| 5160 | |
| 5161 | # |
| 5162 | # Add contracts ext-nets for 220 -> 222 |
| 5163 | # |
| 5164 | c4 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 5165 | self, 55, 4220, 4222, acl.acl_index, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5166 | [VppGbpContractRule( |
| 5167 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 5168 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5169 | []), |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 5170 | VppGbpContractRule( |
| 5171 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 5172 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
Filip Varga | f4749ca | 2019-04-25 14:55:32 +0200 | [diff] [blame] | 5173 | [])], |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5174 | [ETH_P_IP, ETH_P_IPV6]) |
| 5175 | c4.add_vpp_config() |
| 5176 | |
| 5177 | # |
| 5178 | # ping from host in local to remote external subnets |
| 5179 | # |
| 5180 | p = (Ether(src=eep1.mac, dst=str(self.router_mac)) / |
| 5181 | Dot1Q(vlan=100) / |
| 5182 | IP(src="10.220.0.1", dst="10.222.0.1") / |
| 5183 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5184 | Raw(b'\xa5' * 100)) |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5185 | |
| 5186 | rxs = self.send_and_expect(self.pg0, p * 3, self.pg7) |
| 5187 | |
| 5188 | for rx in rxs: |
| 5189 | self.assertEqual(rx[Ether].src, self.pg7.local_mac) |
| 5190 | self.assertEqual(rx[Ether].dst, self.pg7.remote_mac) |
| 5191 | self.assertEqual(rx[IP].src, self.pg7.local_ip4) |
| 5192 | self.assertEqual(rx[IP].dst, self.pg7.remote_ip4) |
| 5193 | self.assertEqual(rx[VXLAN].vni, 445) |
| 5194 | self.assertTrue(rx[VXLAN].flags.G) |
| 5195 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 5196 | # the sclass of the ext-net the packet came from |
| 5197 | self.assertEqual(rx[VXLAN].gpid, 4220) |
| 5198 | # policy was applied to the original IP packet |
| 5199 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 5200 | # since it's an external host the reciever should not learn it |
| 5201 | self.assertTrue(rx[VXLAN].gpflags.D) |
| 5202 | inner = rx[VXLAN].payload |
| 5203 | self.assertEqual(inner[Ether].dst, "00:0c:0c:0c:0c:0c") |
| 5204 | self.assertEqual(inner[IP].src, "10.220.0.1") |
| 5205 | self.assertEqual(inner[IP].dst, "10.222.0.1") |
| 5206 | |
| 5207 | # |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5208 | # make the external subnet ECMP |
| 5209 | # |
| 5210 | vx_tun_r2 = VppVxlanGbpTunnel( |
| 5211 | self, self.pg7.local_ip4, |
| 5212 | self.pg7.remote_ip4, 446, |
| 5213 | mode=(VppEnum.vl_api_vxlan_gbp_api_tunnel_mode_t. |
| 5214 | VXLAN_GBP_API_TUNNEL_MODE_L3)) |
| 5215 | vx_tun_r2.add_vpp_config() |
| 5216 | VppIpInterfaceBind(self, vx_tun_r2, t4).add_vpp_config() |
| 5217 | |
| 5218 | self.logger.info(self.vapi.cli("sh vxlan-gbp tunnel")) |
| 5219 | |
| 5220 | n2 = VppNeighbor(self, |
| 5221 | vx_tun_r2.sw_if_index, |
| 5222 | "00:0c:0c:0c:0c:0c", |
| 5223 | self.pg7.remote_ip4) |
| 5224 | n2.add_vpp_config() |
| 5225 | |
| 5226 | ip_222.modify([VppRoutePath(self.pg7.remote_ip4, |
| 5227 | vx_tun_r1.sw_if_index), |
| 5228 | VppRoutePath(self.pg7.remote_ip4, |
| 5229 | vx_tun_r2.sw_if_index)]) |
| 5230 | |
| 5231 | # |
| 5232 | # now expect load-balance |
| 5233 | # |
| 5234 | p = [(Ether(src=eep1.mac, dst=str(self.router_mac)) / |
| 5235 | Dot1Q(vlan=100) / |
| 5236 | IP(src="10.220.0.1", dst="10.222.0.1") / |
| 5237 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5238 | Raw(b'\xa5' * 100)), |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5239 | (Ether(src=eep1.mac, dst=str(self.router_mac)) / |
| 5240 | Dot1Q(vlan=100) / |
| 5241 | IP(src="10.220.0.1", dst="10.222.0.1") / |
| 5242 | UDP(sport=1222, dport=1235) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5243 | Raw(b'\xa5' * 100))] |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5244 | |
| 5245 | rxs = self.send_and_expect(self.pg0, p, self.pg7) |
| 5246 | |
| 5247 | self.assertEqual(rxs[0][VXLAN].vni, 445) |
| 5248 | self.assertEqual(rxs[1][VXLAN].vni, 446) |
| 5249 | |
| 5250 | # |
| 5251 | # Same LB test for v6 |
| 5252 | # |
| 5253 | n3 = VppNeighbor(self, |
| 5254 | vx_tun_r1.sw_if_index, |
| 5255 | "00:0c:0c:0c:0c:0c", |
| 5256 | self.pg7.remote_ip6) |
| 5257 | n3.add_vpp_config() |
| 5258 | n4 = VppNeighbor(self, |
| 5259 | vx_tun_r2.sw_if_index, |
| 5260 | "00:0c:0c:0c:0c:0c", |
| 5261 | self.pg7.remote_ip6) |
| 5262 | n4.add_vpp_config() |
| 5263 | |
| 5264 | ip_222_6 = VppIpRoute(self, "10:222::", 64, |
| 5265 | [VppRoutePath(self.pg7.remote_ip6, |
| 5266 | vx_tun_r1.sw_if_index), |
| 5267 | VppRoutePath(self.pg7.remote_ip6, |
| 5268 | vx_tun_r2.sw_if_index)], |
| 5269 | table_id=t6.table_id) |
| 5270 | ip_222_6.add_vpp_config() |
| 5271 | |
| 5272 | l3o_222_6 = VppGbpSubnet( |
| 5273 | self, rd1, "10:222::", 64, |
| 5274 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT, |
| 5275 | sclass=4222) |
| 5276 | l3o_222_6.add_vpp_config() |
| 5277 | |
| 5278 | p = [(Ether(src=eep1.mac, dst=str(self.router_mac)) / |
| 5279 | Dot1Q(vlan=100) / |
| 5280 | IPv6(src="10:220::1", dst="10:222::1") / |
| 5281 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5282 | Raw(b'\xa5' * 100)), |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5283 | (Ether(src=eep1.mac, dst=str(self.router_mac)) / |
| 5284 | Dot1Q(vlan=100) / |
| 5285 | IPv6(src="10:220::1", dst="10:222::1") / |
| 5286 | UDP(sport=7777, dport=8881) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5287 | Raw(b'\xa5' * 100))] |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5288 | |
| 5289 | self.logger.info(self.vapi.cli("sh ip6 fib 10:222::1")) |
| 5290 | rxs = self.send_and_expect(self.pg0, p, self.pg7) |
| 5291 | |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 5292 | self.assertEqual(rxs[0][VXLAN].vni, 445) |
| 5293 | self.assertEqual(rxs[1][VXLAN].vni, 446) |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5294 | |
| 5295 | # |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5296 | # ping from host in remote to local external subnets |
| 5297 | # there's no contract for this, but the A bit is set. |
| 5298 | # |
| 5299 | p = (Ether(src=self.pg7.remote_mac, dst=self.pg7.local_mac) / |
| 5300 | IP(src=self.pg7.remote_ip4, dst=self.pg7.local_ip4) / |
| 5301 | UDP(sport=1234, dport=48879) / |
| 5302 | VXLAN(vni=445, gpid=4222, flags=0x88, gpflags='A') / |
| 5303 | Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) / |
| 5304 | IP(src="10.222.0.1", dst="10.220.0.1") / |
| 5305 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5306 | Raw(b'\xa5' * 100)) |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 5307 | |
| 5308 | rxs = self.send_and_expect(self.pg7, p * 3, self.pg0) |
| 5309 | self.assertFalse(find_gbp_endpoint(self, ip="10.222.0.1")) |
Neale Ranns | 36abbf1 | 2019-03-12 02:34:07 -0700 | [diff] [blame] | 5310 | |
| 5311 | # |
Neale Ranns | 2b60018 | 2019-03-29 05:08:27 -0700 | [diff] [blame] | 5312 | # ping from host in remote to remote external subnets |
| 5313 | # this is dropped by reflection check. |
| 5314 | # |
| 5315 | p = (Ether(src=self.pg7.remote_mac, dst=self.pg7.local_mac) / |
| 5316 | IP(src=self.pg7.remote_ip4, dst=self.pg7.local_ip4) / |
| 5317 | UDP(sport=1234, dport=48879) / |
| 5318 | VXLAN(vni=445, gpid=4222, flags=0x88, gpflags='A') / |
| 5319 | Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) / |
| 5320 | IP(src="10.222.0.1", dst="10.222.0.2") / |
| 5321 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5322 | Raw(b'\xa5' * 100)) |
Neale Ranns | 2b60018 | 2019-03-29 05:08:27 -0700 | [diff] [blame] | 5323 | |
| 5324 | rxs = self.send_and_assert_no_replies(self.pg7, p * 3) |
| 5325 | |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5326 | p = (Ether(src=self.pg7.remote_mac, dst=self.pg7.local_mac) / |
| 5327 | IP(src=self.pg7.remote_ip4, dst=self.pg7.local_ip4) / |
| 5328 | UDP(sport=1234, dport=48879) / |
| 5329 | VXLAN(vni=445, gpid=4222, flags=0x88, gpflags='A') / |
| 5330 | Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) / |
| 5331 | IPv6(src="10:222::1", dst="10:222::2") / |
| 5332 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5333 | Raw(b'\xa5' * 100)) |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5334 | |
| 5335 | rxs = self.send_and_assert_no_replies(self.pg7, p * 3) |
| 5336 | |
| 5337 | # |
| 5338 | # local EP |
| 5339 | # |
| 5340 | lep1 = VppGbpEndpoint(self, vlan_144, |
| 5341 | epg_220, None, |
| 5342 | "10.0.0.44", "11.0.0.44", |
| 5343 | "2001:10::44", "3001::44") |
| 5344 | lep1.add_vpp_config() |
| 5345 | |
| 5346 | # |
| 5347 | # local EP to local ip4 external subnet |
| 5348 | # |
| 5349 | p = (Ether(src=lep1.mac, dst=str(self.router_mac)) / |
| 5350 | Dot1Q(vlan=144) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 5351 | IP(src=lep1.ip4, dst="10.220.0.1") / |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5352 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5353 | Raw(b'\xa5' * 100)) |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5354 | |
| 5355 | rxs = self.send_and_expect(self.pg0, p * 1, self.pg0) |
| 5356 | |
| 5357 | for rx in rxs: |
| 5358 | self.assertEqual(rx[Ether].src, str(self.router_mac)) |
| 5359 | self.assertEqual(rx[Ether].dst, eep1.mac) |
| 5360 | self.assertEqual(rx[Dot1Q].vlan, 100) |
| 5361 | |
| 5362 | # |
| 5363 | # local EP to local ip6 external subnet |
| 5364 | # |
| 5365 | p = (Ether(src=lep1.mac, dst=str(self.router_mac)) / |
| 5366 | Dot1Q(vlan=144) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 5367 | IPv6(src=lep1.ip6, dst="10:220::1") / |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5368 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5369 | Raw(b'\xa5' * 100)) |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5370 | |
| 5371 | rxs = self.send_and_expect(self.pg0, p * 1, self.pg0) |
| 5372 | |
| 5373 | for rx in rxs: |
| 5374 | self.assertEqual(rx[Ether].src, str(self.router_mac)) |
| 5375 | self.assertEqual(rx[Ether].dst, eep1.mac) |
| 5376 | self.assertEqual(rx[Dot1Q].vlan, 100) |
| 5377 | |
| 5378 | # |
| 5379 | # ip4 and ip6 subnets that load-balance |
| 5380 | # |
| 5381 | ip_20 = VppIpRoute(self, "10.20.0.0", 24, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 5382 | [VppRoutePath(eep1.ip4, |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5383 | eep1.epg.bvi.sw_if_index), |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 5384 | VppRoutePath(eep2.ip4, |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5385 | eep2.epg.bvi.sw_if_index)], |
| 5386 | table_id=t4.table_id) |
| 5387 | ip_20.add_vpp_config() |
| 5388 | |
| 5389 | l3o_20 = VppGbpSubnet( |
| 5390 | self, rd1, "10.20.0.0", 24, |
| 5391 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT, |
| 5392 | sclass=4220) |
| 5393 | l3o_20.add_vpp_config() |
| 5394 | |
| 5395 | ip6_20 = VppIpRoute(self, "10:20::", 64, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 5396 | [VppRoutePath(eep1.ip6, |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5397 | eep1.epg.bvi.sw_if_index), |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 5398 | VppRoutePath(eep2.ip6, |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5399 | eep2.epg.bvi.sw_if_index)], |
| 5400 | table_id=t6.table_id) |
| 5401 | ip6_20.add_vpp_config() |
| 5402 | |
| 5403 | l3o6_20 = VppGbpSubnet( |
| 5404 | self, rd1, "10:20::", 64, |
| 5405 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT, |
| 5406 | sclass=4220) |
| 5407 | l3o6_20.add_vpp_config() |
| 5408 | |
| 5409 | self.logger.info(self.vapi.cli("sh ip fib 10.20.0.1")) |
| 5410 | self.logger.info(self.vapi.cli("sh ip6 fib 10:20::1")) |
| 5411 | |
| 5412 | # two ip6 packets whose port are chosen so they load-balance |
| 5413 | p = [(Ether(src=lep1.mac, dst=str(self.router_mac)) / |
| 5414 | Dot1Q(vlan=144) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 5415 | IPv6(src=lep1.ip6, dst="10:20::1") / |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5416 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5417 | Raw(b'\xa5' * 100)), |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5418 | (Ether(src=lep1.mac, dst=str(self.router_mac)) / |
| 5419 | Dot1Q(vlan=144) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 5420 | IPv6(src=lep1.ip6, dst="10:20::1") / |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5421 | UDP(sport=124, dport=1230) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5422 | Raw(b'\xa5' * 100))] |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5423 | |
| 5424 | rxs = self.send_and_expect(self.pg0, p, self.pg0, 2) |
| 5425 | |
Neale Ranns | 3d5f08a | 2021-01-22 16:12:38 +0000 | [diff] [blame] | 5426 | self.assertEqual(rxs[0][Dot1Q].vlan, 101) |
| 5427 | self.assertEqual(rxs[1][Dot1Q].vlan, 100) |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5428 | |
| 5429 | # two ip4 packets whose port are chosen so they load-balance |
| 5430 | p = [(Ether(src=lep1.mac, dst=str(self.router_mac)) / |
| 5431 | Dot1Q(vlan=144) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 5432 | IP(src=lep1.ip4, dst="10.20.0.1") / |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5433 | UDP(sport=1235, dport=1235) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5434 | Raw(b'\xa5' * 100)), |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5435 | (Ether(src=lep1.mac, dst=str(self.router_mac)) / |
| 5436 | Dot1Q(vlan=144) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 5437 | IP(src=lep1.ip4, dst="10.20.0.1") / |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5438 | UDP(sport=124, dport=1230) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5439 | Raw(b'\xa5' * 100))] |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5440 | |
| 5441 | rxs = self.send_and_expect(self.pg0, p, self.pg0, 2) |
| 5442 | |
| 5443 | self.assertEqual(rxs[0][Dot1Q].vlan, 101) |
| 5444 | self.assertEqual(rxs[1][Dot1Q].vlan, 100) |
| 5445 | |
Neale Ranns | 2b60018 | 2019-03-29 05:08:27 -0700 | [diff] [blame] | 5446 | # |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 5447 | # cleanup |
| 5448 | # |
Neale Ranns | 69a85b5 | 2019-06-14 07:49:50 +0000 | [diff] [blame] | 5449 | ip_222.remove_vpp_config() |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 5450 | self.pg7.unconfig_ip4() |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5451 | self.vlan_101.set_vtr(L2_VTR_OP.L2_DISABLED) |
| 5452 | self.vlan_100.set_vtr(L2_VTR_OP.L2_DISABLED) |
| 5453 | |
| 5454 | def test_gbp_anon_l3_out(self): |
| 5455 | """ GBP Anonymous L3 Out """ |
| 5456 | |
| 5457 | ep_flags = VppEnum.vl_api_gbp_endpoint_flags_t |
| 5458 | self.vapi.cli("set logging class gbp level debug") |
| 5459 | |
| 5460 | routed_dst_mac = "00:0c:0c:0c:0c:0c" |
| 5461 | routed_src_mac = "00:22:bd:f8:19:ff" |
| 5462 | |
| 5463 | # |
| 5464 | # IP tables |
| 5465 | # |
| 5466 | t4 = VppIpTable(self, 1) |
| 5467 | t4.add_vpp_config() |
| 5468 | t6 = VppIpTable(self, 1, True) |
| 5469 | t6.add_vpp_config() |
| 5470 | |
| 5471 | rd1 = VppGbpRouteDomain(self, 2, 55, t4, t6) |
| 5472 | rd1.add_vpp_config() |
| 5473 | |
| 5474 | self.loop0.set_mac(self.router_mac) |
| 5475 | |
| 5476 | # |
| 5477 | # Bind the BVI to the RD |
| 5478 | # |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 5479 | bind_l0_ip4 = VppIpInterfaceBind(self, self.loop0, t4).add_vpp_config() |
| 5480 | bind_l0_ip6 = VppIpInterfaceBind(self, self.loop0, t6).add_vpp_config() |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5481 | |
| 5482 | # |
| 5483 | # Pg7 hosts a BD's BUM |
| 5484 | # Pg1 some other l3 interface |
| 5485 | # |
| 5486 | self.pg7.config_ip4() |
| 5487 | self.pg7.resolve_arp() |
| 5488 | |
| 5489 | # |
| 5490 | # a GBP external bridge domains for the EPs |
| 5491 | # |
| 5492 | bd1 = VppBridgeDomain(self, 1) |
| 5493 | bd1.add_vpp_config() |
| 5494 | gbd1 = VppGbpBridgeDomain(self, bd1, rd1, self.loop0, None, None) |
| 5495 | gbd1.add_vpp_config() |
| 5496 | |
| 5497 | # |
| 5498 | # The Endpoint-groups in which the external endpoints exist |
| 5499 | # |
| 5500 | epg_220 = VppGbpEndpointGroup(self, 220, 113, rd1, gbd1, |
| 5501 | None, gbd1.bvi, |
| 5502 | "10.0.0.128", |
| 5503 | "2001:10::128", |
Neale Ranns | 8d0d8d2 | 2020-04-07 08:44:20 +0000 | [diff] [blame] | 5504 | VppGbpEndpointRetention(4)) |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5505 | epg_220.add_vpp_config() |
| 5506 | |
| 5507 | # the BVIs have the subnet applied ... |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 5508 | ip4_addr = VppIpInterfaceAddress(self, gbd1.bvi, |
| 5509 | "10.0.0.128", 24, |
| 5510 | bind=bind_l0_ip4).add_vpp_config() |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5511 | |
| 5512 | # ... which is an Anonymous L3-out subnets |
| 5513 | l3o_1 = VppGbpSubnet( |
| 5514 | self, rd1, "10.0.0.0", 24, |
| 5515 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_ANON_L3_OUT, |
| 5516 | sclass=113) |
| 5517 | l3o_1.add_vpp_config() |
| 5518 | |
| 5519 | # |
| 5520 | # an external interface attached to the outside world and the |
| 5521 | # external BD |
| 5522 | # |
| 5523 | VppL2Vtr(self, self.vlan_100, L2_VTR_OP.L2_POP_1).add_vpp_config() |
| 5524 | VppL2Vtr(self, self.vlan_101, L2_VTR_OP.L2_POP_1).add_vpp_config() |
| 5525 | |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5526 | # |
| 5527 | # vlan_100 and vlan_101 are anonymous l3-out interfaces |
| 5528 | # |
| 5529 | ext_itf = VppGbpExtItf(self, self.vlan_100, bd1, rd1, anon=True) |
| 5530 | ext_itf.add_vpp_config() |
| 5531 | ext_itf = VppGbpExtItf(self, self.vlan_101, bd1, rd1, anon=True) |
| 5532 | ext_itf.add_vpp_config() |
| 5533 | |
| 5534 | # |
| 5535 | # an unicast vxlan-gbp for inter-RD traffic |
| 5536 | # |
| 5537 | vx_tun_l3 = VppGbpVxlanTunnel( |
| 5538 | self, 444, rd1.rd_id, |
| 5539 | VppEnum.vl_api_gbp_vxlan_tunnel_mode_t.GBP_VXLAN_TUNNEL_MODE_L3, |
| 5540 | self.pg2.local_ip4) |
| 5541 | vx_tun_l3.add_vpp_config() |
| 5542 | |
| 5543 | # |
| 5544 | # A remote external endpoint |
| 5545 | # |
| 5546 | rep = VppGbpEndpoint(self, vx_tun_l3, |
| 5547 | epg_220, None, |
| 5548 | "10.0.0.201", "11.0.0.201", |
| 5549 | "2001:10::201", "3001::101", |
| 5550 | ep_flags.GBP_API_ENDPOINT_FLAG_REMOTE, |
| 5551 | self.pg7.local_ip4, |
| 5552 | self.pg7.remote_ip4, |
| 5553 | mac=None) |
| 5554 | rep.add_vpp_config() |
| 5555 | |
| 5556 | # |
| 5557 | # ARP packet from host in external subnet are accepted, flooded and |
| 5558 | # replied to. We expect 2 packets: |
| 5559 | # - APR request flooded over the other vlan subif |
| 5560 | # - ARP reply from BVI |
| 5561 | # |
| 5562 | p_arp = (Ether(src=self.vlan_100.remote_mac, |
| 5563 | dst="ff:ff:ff:ff:ff:ff") / |
| 5564 | Dot1Q(vlan=100) / |
| 5565 | ARP(op="who-has", |
| 5566 | psrc="10.0.0.100", |
| 5567 | pdst="10.0.0.128", |
| 5568 | hwsrc=self.vlan_100.remote_mac, |
| 5569 | hwdst="ff:ff:ff:ff:ff:ff")) |
| 5570 | rxs = self.send_and_expect(self.pg0, p_arp * 1, self.pg0, n_rx=2) |
| 5571 | |
| 5572 | p_arp = (Ether(src=self.vlan_101.remote_mac, |
| 5573 | dst="ff:ff:ff:ff:ff:ff") / |
| 5574 | Dot1Q(vlan=101) / |
| 5575 | ARP(op="who-has", |
| 5576 | psrc='10.0.0.101', |
| 5577 | pdst="10.0.0.128", |
| 5578 | hwsrc=self.vlan_101.remote_mac, |
| 5579 | hwdst="ff:ff:ff:ff:ff:ff")) |
| 5580 | rxs = self.send_and_expect(self.pg0, p_arp * 1, self.pg0, n_rx=2) |
| 5581 | |
| 5582 | # |
| 5583 | # remote to external |
| 5584 | # |
| 5585 | p = (Ether(src=self.pg7.remote_mac, |
| 5586 | dst=self.pg7.local_mac) / |
| 5587 | IP(src=self.pg7.remote_ip4, |
| 5588 | dst=self.pg7.local_ip4) / |
| 5589 | UDP(sport=1234, dport=48879) / |
| 5590 | VXLAN(vni=vx_tun_l3.vni, gpid=epg_220.sclass, flags=0x88) / |
| 5591 | Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) / |
| 5592 | IP(src=str(rep.ip4), dst="10.0.0.100") / |
| 5593 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5594 | Raw(b'\xa5' * 100)) |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5595 | rxs = self.send_and_expect(self.pg7, p * 1, self.pg0) |
| 5596 | |
| 5597 | # |
| 5598 | # local EP pings router |
| 5599 | # |
| 5600 | p = (Ether(src=self.vlan_100.remote_mac, dst=str(self.router_mac)) / |
| 5601 | Dot1Q(vlan=100) / |
| 5602 | IP(src="10.0.0.100", dst="10.0.0.128") / |
| 5603 | ICMP(type='echo-request')) |
| 5604 | rxs = self.send_and_expect(self.pg0, p * 1, self.pg0) |
| 5605 | |
| 5606 | for rx in rxs: |
| 5607 | self.assertEqual(rx[Ether].src, str(self.router_mac)) |
| 5608 | self.assertEqual(rx[Ether].dst, self.vlan_100.remote_mac) |
| 5609 | self.assertEqual(rx[Dot1Q].vlan, 100) |
| 5610 | |
| 5611 | # |
| 5612 | # local EP pings other local EP |
| 5613 | # |
| 5614 | p = (Ether(src=self.vlan_100.remote_mac, |
| 5615 | dst=self.vlan_101.remote_mac) / |
| 5616 | Dot1Q(vlan=100) / |
| 5617 | IP(src="10.0.0.100", dst="10.0.0.101") / |
| 5618 | ICMP(type='echo-request')) |
| 5619 | rxs = self.send_and_expect(self.pg0, p * 1, self.pg0) |
| 5620 | |
| 5621 | for rx in rxs: |
| 5622 | self.assertEqual(rx[Ether].src, self.vlan_100.remote_mac) |
| 5623 | self.assertEqual(rx[Ether].dst, self.vlan_101.remote_mac) |
| 5624 | self.assertEqual(rx[Dot1Q].vlan, 101) |
| 5625 | |
| 5626 | # |
| 5627 | # A subnet reachable through an external router on vlan 100 |
| 5628 | # |
| 5629 | ip_220 = VppIpRoute(self, "10.220.0.0", 24, |
| 5630 | [VppRoutePath("10.0.0.100", |
| 5631 | epg_220.bvi.sw_if_index)], |
| 5632 | table_id=t4.table_id) |
| 5633 | ip_220.add_vpp_config() |
| 5634 | |
| 5635 | l3o_220 = VppGbpSubnet( |
| 5636 | self, rd1, "10.220.0.0", 24, |
| 5637 | # note: this a "regular" L3 out subnet (not connected) |
| 5638 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT, |
| 5639 | sclass=4220) |
| 5640 | l3o_220.add_vpp_config() |
| 5641 | |
| 5642 | # |
| 5643 | # A subnet reachable through an external router on vlan 101 |
| 5644 | # |
| 5645 | ip_221 = VppIpRoute(self, "10.221.0.0", 24, |
| 5646 | [VppRoutePath("10.0.0.101", |
| 5647 | epg_220.bvi.sw_if_index)], |
| 5648 | table_id=t4.table_id) |
| 5649 | ip_221.add_vpp_config() |
| 5650 | |
| 5651 | l3o_221 = VppGbpSubnet( |
| 5652 | self, rd1, "10.221.0.0", 24, |
| 5653 | # note: this a "regular" L3 out subnet (not connected) |
| 5654 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT, |
| 5655 | sclass=4221) |
| 5656 | l3o_221.add_vpp_config() |
| 5657 | |
| 5658 | # |
| 5659 | # ping between hosts in remote subnets |
| 5660 | # dropped without a contract |
| 5661 | # |
| 5662 | p = (Ether(src=self.vlan_100.remote_mac, dst=str(self.router_mac)) / |
| 5663 | Dot1Q(vlan=100) / |
| 5664 | IP(src="10.220.0.1", dst="10.221.0.1") / |
| 5665 | ICMP(type='echo-request')) |
| 5666 | |
| 5667 | rxs = self.send_and_assert_no_replies(self.pg0, p * 1) |
| 5668 | |
| 5669 | # |
| 5670 | # contract for the external nets to communicate |
| 5671 | # |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 5672 | rule4 = AclRule(is_permit=1, proto=17) |
| 5673 | rule6 = AclRule(src_prefix=IPv6Network((0, 0)), |
| 5674 | dst_prefix=IPv6Network((0, 0)), is_permit=1, proto=17) |
| 5675 | acl = VppAcl(self, rules=[rule4, rule6]) |
| 5676 | acl.add_vpp_config() |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5677 | |
| 5678 | c1 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 5679 | self, 55, 4220, 4221, acl.acl_index, |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5680 | [VppGbpContractRule( |
| 5681 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
| 5682 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
| 5683 | []), |
| 5684 | VppGbpContractRule( |
| 5685 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
| 5686 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
| 5687 | [])], |
| 5688 | [ETH_P_IP, ETH_P_IPV6]) |
| 5689 | c1.add_vpp_config() |
| 5690 | |
| 5691 | # |
| 5692 | # Contracts allowing ext-net 200 to talk with external EPs |
| 5693 | # |
| 5694 | c2 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 5695 | self, 55, 4220, 113, acl.acl_index, |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5696 | [VppGbpContractRule( |
| 5697 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
| 5698 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
| 5699 | []), |
| 5700 | VppGbpContractRule( |
| 5701 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
| 5702 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
| 5703 | [])], |
| 5704 | [ETH_P_IP, ETH_P_IPV6]) |
| 5705 | c2.add_vpp_config() |
| 5706 | c3 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 5707 | self, 55, 113, 4220, acl.acl_index, |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5708 | [VppGbpContractRule( |
| 5709 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
| 5710 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
| 5711 | []), |
| 5712 | VppGbpContractRule( |
| 5713 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
| 5714 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
| 5715 | [])], |
| 5716 | [ETH_P_IP, ETH_P_IPV6]) |
| 5717 | c3.add_vpp_config() |
| 5718 | |
| 5719 | # |
| 5720 | # ping between hosts in remote subnets |
| 5721 | # |
| 5722 | p = (Ether(src=self.vlan_100.remote_mac, dst=str(self.router_mac)) / |
| 5723 | Dot1Q(vlan=100) / |
| 5724 | IP(src="10.220.0.1", dst="10.221.0.1") / |
| 5725 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5726 | Raw(b'\xa5' * 100)) |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5727 | |
| 5728 | rxs = self.send_and_expect(self.pg0, p * 1, self.pg0) |
| 5729 | |
| 5730 | for rx in rxs: |
| 5731 | self.assertEqual(rx[Ether].src, str(self.router_mac)) |
| 5732 | self.assertEqual(rx[Ether].dst, self.vlan_101.remote_mac) |
| 5733 | self.assertEqual(rx[Dot1Q].vlan, 101) |
| 5734 | |
| 5735 | # we did not learn these external hosts |
| 5736 | self.assertFalse(find_gbp_endpoint(self, ip="10.220.0.1")) |
| 5737 | self.assertFalse(find_gbp_endpoint(self, ip="10.221.0.1")) |
| 5738 | |
| 5739 | # |
| 5740 | # from remote external EP to local external EP |
| 5741 | # |
| 5742 | p = (Ether(src=self.pg7.remote_mac, |
| 5743 | dst=self.pg7.local_mac) / |
| 5744 | IP(src=self.pg7.remote_ip4, |
| 5745 | dst=self.pg7.local_ip4) / |
| 5746 | UDP(sport=1234, dport=48879) / |
| 5747 | VXLAN(vni=444, gpid=113, flags=0x88) / |
| 5748 | Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 5749 | IP(src=rep.ip4, dst="10.220.0.1") / |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5750 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5751 | Raw(b'\xa5' * 100)) |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5752 | |
| 5753 | rxs = self.send_and_expect(self.pg7, p * 1, self.pg0) |
| 5754 | |
| 5755 | # |
| 5756 | # ping from an external host to the remote external EP |
| 5757 | # |
| 5758 | p = (Ether(src=self.vlan_100.remote_mac, dst=str(self.router_mac)) / |
| 5759 | Dot1Q(vlan=100) / |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 5760 | IP(src="10.220.0.1", dst=rep.ip4) / |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5761 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5762 | Raw(b'\xa5' * 100)) |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5763 | |
| 5764 | rxs = self.send_and_expect(self.pg0, p * 1, self.pg7) |
| 5765 | |
| 5766 | for rx in rxs: |
| 5767 | self.assertEqual(rx[Ether].src, self.pg7.local_mac) |
| 5768 | # self.assertEqual(rx[Ether].dst, self.pg7.remote_mac) |
| 5769 | self.assertEqual(rx[IP].src, self.pg7.local_ip4) |
| 5770 | self.assertEqual(rx[IP].dst, self.pg7.remote_ip4) |
| 5771 | self.assertEqual(rx[VXLAN].vni, 444) |
| 5772 | self.assertTrue(rx[VXLAN].flags.G) |
| 5773 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 5774 | # the sclass of the ext-net the packet came from |
| 5775 | self.assertEqual(rx[VXLAN].gpid, 4220) |
| 5776 | # policy was applied to the original IP packet |
| 5777 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 5778 | # since it's an external host the reciever should not learn it |
| 5779 | self.assertTrue(rx[VXLAN].gpflags.D) |
| 5780 | inner = rx[VXLAN].payload |
| 5781 | self.assertEqual(inner[IP].src, "10.220.0.1") |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 5782 | self.assertEqual(inner[IP].dst, rep.ip4) |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5783 | |
| 5784 | # |
| 5785 | # An external subnet reachable via the remote external EP |
| 5786 | # |
| 5787 | |
| 5788 | # |
| 5789 | # first the VXLAN-GBP tunnel over which it is reached |
| 5790 | # |
| 5791 | vx_tun_r = VppVxlanGbpTunnel( |
| 5792 | self, self.pg7.local_ip4, |
| 5793 | self.pg7.remote_ip4, 445, |
| 5794 | mode=(VppEnum.vl_api_vxlan_gbp_api_tunnel_mode_t. |
| 5795 | VXLAN_GBP_API_TUNNEL_MODE_L3)) |
| 5796 | vx_tun_r.add_vpp_config() |
| 5797 | VppIpInterfaceBind(self, vx_tun_r, t4).add_vpp_config() |
| 5798 | |
| 5799 | self.logger.info(self.vapi.cli("sh vxlan-gbp tunnel")) |
| 5800 | |
| 5801 | # |
| 5802 | # then the special adj to resolve through on that tunnel |
| 5803 | # |
| 5804 | n1 = VppNeighbor(self, |
| 5805 | vx_tun_r.sw_if_index, |
| 5806 | "00:0c:0c:0c:0c:0c", |
| 5807 | self.pg7.remote_ip4) |
| 5808 | n1.add_vpp_config() |
| 5809 | |
| 5810 | # |
| 5811 | # the route via the adj above |
| 5812 | # |
| 5813 | ip_222 = VppIpRoute(self, "10.222.0.0", 24, |
| 5814 | [VppRoutePath(self.pg7.remote_ip4, |
| 5815 | vx_tun_r.sw_if_index)], |
| 5816 | table_id=t4.table_id) |
| 5817 | ip_222.add_vpp_config() |
| 5818 | |
| 5819 | l3o_222 = VppGbpSubnet( |
| 5820 | self, rd1, "10.222.0.0", 24, |
| 5821 | # note: this a "regular" l3out subnet (not connected) |
| 5822 | VppEnum.vl_api_gbp_subnet_type_t.GBP_API_SUBNET_L3_OUT, |
| 5823 | sclass=4222) |
| 5824 | l3o_222.add_vpp_config() |
| 5825 | |
| 5826 | # |
| 5827 | # ping between hosts in local and remote external subnets |
| 5828 | # dropped without a contract |
| 5829 | # |
| 5830 | p = (Ether(src=self.vlan_100.remote_mac, dst=str(self.router_mac)) / |
| 5831 | Dot1Q(vlan=100) / |
| 5832 | IP(src="10.220.0.1", dst="10.222.0.1") / |
| 5833 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5834 | Raw(b'\xa5' * 100)) |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5835 | |
| 5836 | rxs = self.send_and_assert_no_replies(self.pg0, p * 1) |
| 5837 | |
| 5838 | # |
| 5839 | # Add contracts ext-nets for 220 -> 222 |
| 5840 | # |
| 5841 | c4 = VppGbpContract( |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 5842 | self, 55, 4220, 4222, acl.acl_index, |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5843 | [VppGbpContractRule( |
| 5844 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
| 5845 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
| 5846 | []), |
| 5847 | VppGbpContractRule( |
| 5848 | VppEnum.vl_api_gbp_rule_action_t.GBP_API_RULE_PERMIT, |
| 5849 | VppEnum.vl_api_gbp_hash_mode_t.GBP_API_HASH_MODE_SRC_IP, |
| 5850 | [])], |
| 5851 | [ETH_P_IP, ETH_P_IPV6]) |
| 5852 | c4.add_vpp_config() |
| 5853 | |
| 5854 | # |
| 5855 | # ping from host in local to remote external subnets |
| 5856 | # |
| 5857 | p = (Ether(src=self.vlan_100.remote_mac, dst=str(self.router_mac)) / |
| 5858 | Dot1Q(vlan=100) / |
| 5859 | IP(src="10.220.0.1", dst="10.222.0.1") / |
| 5860 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5861 | Raw(b'\xa5' * 100)) |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5862 | |
| 5863 | rxs = self.send_and_expect(self.pg0, p * 3, self.pg7) |
| 5864 | |
| 5865 | for rx in rxs: |
| 5866 | self.assertEqual(rx[Ether].src, self.pg7.local_mac) |
| 5867 | self.assertEqual(rx[Ether].dst, self.pg7.remote_mac) |
| 5868 | self.assertEqual(rx[IP].src, self.pg7.local_ip4) |
| 5869 | self.assertEqual(rx[IP].dst, self.pg7.remote_ip4) |
| 5870 | self.assertEqual(rx[VXLAN].vni, 445) |
| 5871 | self.assertTrue(rx[VXLAN].flags.G) |
| 5872 | self.assertTrue(rx[VXLAN].flags.Instance) |
| 5873 | # the sclass of the ext-net the packet came from |
| 5874 | self.assertEqual(rx[VXLAN].gpid, 4220) |
| 5875 | # policy was applied to the original IP packet |
| 5876 | self.assertTrue(rx[VXLAN].gpflags.A) |
| 5877 | # since it's an external host the reciever should not learn it |
| 5878 | self.assertTrue(rx[VXLAN].gpflags.D) |
| 5879 | inner = rx[VXLAN].payload |
| 5880 | self.assertEqual(inner[Ether].dst, "00:0c:0c:0c:0c:0c") |
| 5881 | self.assertEqual(inner[IP].src, "10.220.0.1") |
| 5882 | self.assertEqual(inner[IP].dst, "10.222.0.1") |
| 5883 | |
| 5884 | # |
| 5885 | # ping from host in remote to local external subnets |
| 5886 | # there's no contract for this, but the A bit is set. |
| 5887 | # |
| 5888 | p = (Ether(src=self.pg7.remote_mac, dst=self.pg7.local_mac) / |
| 5889 | IP(src=self.pg7.remote_ip4, dst=self.pg7.local_ip4) / |
| 5890 | UDP(sport=1234, dport=48879) / |
| 5891 | VXLAN(vni=445, gpid=4222, flags=0x88, gpflags='A') / |
| 5892 | Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) / |
| 5893 | IP(src="10.222.0.1", dst="10.220.0.1") / |
| 5894 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5895 | Raw(b'\xa5' * 100)) |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5896 | |
| 5897 | rxs = self.send_and_expect(self.pg7, p * 3, self.pg0) |
| 5898 | self.assertFalse(find_gbp_endpoint(self, ip="10.222.0.1")) |
| 5899 | |
| 5900 | # |
| 5901 | # ping from host in remote to remote external subnets |
| 5902 | # this is dropped by reflection check. |
| 5903 | # |
| 5904 | p = (Ether(src=self.pg7.remote_mac, dst=self.pg7.local_mac) / |
| 5905 | IP(src=self.pg7.remote_ip4, dst=self.pg7.local_ip4) / |
| 5906 | UDP(sport=1234, dport=48879) / |
| 5907 | VXLAN(vni=445, gpid=4222, flags=0x88, gpflags='A') / |
| 5908 | Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) / |
| 5909 | IP(src="10.222.0.1", dst="10.222.0.2") / |
| 5910 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 5911 | Raw(b'\xa5' * 100)) |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 5912 | |
| 5913 | rxs = self.send_and_assert_no_replies(self.pg7, p * 3) |
| 5914 | |
| 5915 | # |
| 5916 | # cleanup |
| 5917 | # |
| 5918 | self.vlan_101.set_vtr(L2_VTR_OP.L2_DISABLED) |
| 5919 | self.vlan_100.set_vtr(L2_VTR_OP.L2_DISABLED) |
| 5920 | self.pg7.unconfig_ip4() |
Benoît Ganne | 040d47c | 2020-04-16 16:57:00 +0200 | [diff] [blame] | 5921 | # make sure the programmed EP is no longer learnt from DP |
| 5922 | self.wait_for_ep_timeout(sw_if_index=rep.itf.sw_if_index, ip=rep.ip4) |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 5923 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 5924 | |
| 5925 | if __name__ == '__main__': |
| 5926 | unittest.main(testRunner=VppTestRunner) |