Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 2 | |
| 3 | import socket |
Paul Vinciguerra | 2f15631 | 2020-05-02 22:34:40 -0400 | [diff] [blame] | 4 | from util import ip4_range |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 5 | import unittest |
Andrew Yourtchenko | 8dc0d48 | 2021-01-29 13:17:19 +0000 | [diff] [blame] | 6 | from framework import tag_fixme_vpp_workers |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 7 | from framework import VppTestCase, VppTestRunner |
| 8 | from template_bd import BridgeDomain |
| 9 | |
snaramre | 5d4b891 | 2019-12-13 23:39:35 +0000 | [diff] [blame] | 10 | from scapy.layers.l2 import Ether |
| 11 | from scapy.packet import Raw |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 12 | from scapy.layers.inet import IP, UDP |
Jakub Grajciar | ebae419 | 2019-05-23 13:01:41 +0200 | [diff] [blame] | 13 | from scapy.layers.inet6 import IPv6 |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 14 | from scapy.contrib.gtp import GTP_U_Header |
| 15 | from scapy.utils import atol |
Paul Vinciguerra | 2f15631 | 2020-05-02 22:34:40 -0400 | [diff] [blame] | 16 | |
| 17 | import util |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 18 | from vpp_ip_route import VppIpRoute, VppRoutePath |
| 19 | from vpp_ip import INVALID_INDEX |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 20 | |
| 21 | |
Andrew Yourtchenko | 8dc0d48 | 2021-01-29 13:17:19 +0000 | [diff] [blame] | 22 | @tag_fixme_vpp_workers |
Jakub Grajciar | ebae419 | 2019-05-23 13:01:41 +0200 | [diff] [blame] | 23 | class TestGtpuUDP(VppTestCase): |
| 24 | """ GTPU UDP ports Test Case """ |
| 25 | |
| 26 | def setUp(self): |
Paul Vinciguerra | 20344a1 | 2019-06-06 18:01:07 -0400 | [diff] [blame] | 27 | super(TestGtpuUDP, self).setUp() |
Jakub Grajciar | ebae419 | 2019-05-23 13:01:41 +0200 | [diff] [blame] | 28 | |
| 29 | self.dport = 2152 |
| 30 | |
| 31 | self.ip4_err = 0 |
| 32 | self.ip6_err = 0 |
| 33 | |
| 34 | self.create_pg_interfaces(range(1)) |
| 35 | for pg in self.pg_interfaces: |
| 36 | pg.admin_up() |
| 37 | self.pg0.config_ip4() |
| 38 | self.pg0.config_ip6() |
| 39 | |
| 40 | def _check_udp_port_ip4(self, enabled=True): |
| 41 | |
| 42 | pkt = (Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac) / |
| 43 | IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) / |
| 44 | UDP(sport=self.dport, dport=self.dport, chksum=0)) |
| 45 | |
| 46 | self.pg0.add_stream(pkt) |
| 47 | self.pg_start() |
| 48 | |
| 49 | err = self.statistics.get_counter( |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 50 | '/err/ip4-udp-lookup/No listener for dst port')[0] |
Jakub Grajciar | ebae419 | 2019-05-23 13:01:41 +0200 | [diff] [blame] | 51 | |
| 52 | if enabled: |
| 53 | self.assertEqual(err, self.ip4_err) |
| 54 | else: |
| 55 | self.assertEqual(err, self.ip4_err + 1) |
| 56 | |
| 57 | self.ip4_err = err |
| 58 | |
| 59 | def _check_udp_port_ip6(self, enabled=True): |
| 60 | |
| 61 | pkt = (Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac) / |
| 62 | IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) / |
| 63 | UDP(sport=self.dport, dport=self.dport, chksum=0)) |
| 64 | |
| 65 | self.pg0.add_stream(pkt) |
| 66 | self.pg_start() |
| 67 | |
| 68 | err = self.statistics.get_counter( |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 69 | '/err/ip6-udp-lookup/No listener for dst port')[0] |
Jakub Grajciar | ebae419 | 2019-05-23 13:01:41 +0200 | [diff] [blame] | 70 | |
| 71 | if enabled: |
| 72 | self.assertEqual(err, self.ip6_err) |
| 73 | else: |
| 74 | self.assertEqual(err, self.ip6_err + 1) |
| 75 | |
| 76 | self.ip6_err = err |
| 77 | |
| 78 | def test_udp_port(self): |
| 79 | """ test UDP ports |
| 80 | Check if there are no udp listeners before gtpu is enabled |
| 81 | """ |
Jakub Grajciar | ebae419 | 2019-05-23 13:01:41 +0200 | [diff] [blame] | 82 | # UDP ports should be disabled unless a tunnel is configured |
| 83 | self._check_udp_port_ip4(False) |
| 84 | self._check_udp_port_ip6(False) |
| 85 | |
Ole Troan | 55636cb | 2019-12-08 14:14:37 +0100 | [diff] [blame] | 86 | r = self.vapi.gtpu_add_del_tunnel(is_add=True, |
| 87 | mcast_sw_if_index=0xFFFFFFFF, |
| 88 | decap_next_index=0xFFFFFFFF, |
| 89 | src_address=self.pg0.local_ip4, |
| 90 | dst_address=self.pg0.remote_ip4) |
Jakub Grajciar | ebae419 | 2019-05-23 13:01:41 +0200 | [diff] [blame] | 91 | |
| 92 | # UDP port 2152 enabled for ip4 |
| 93 | self._check_udp_port_ip4() |
| 94 | |
Ole Troan | 55636cb | 2019-12-08 14:14:37 +0100 | [diff] [blame] | 95 | r = self.vapi.gtpu_add_del_tunnel(is_add=True, |
| 96 | mcast_sw_if_index=0xFFFFFFFF, |
| 97 | decap_next_index=0xFFFFFFFF, |
| 98 | src_address=self.pg0.local_ip6, |
| 99 | dst_address=self.pg0.remote_ip6) |
Jakub Grajciar | ebae419 | 2019-05-23 13:01:41 +0200 | [diff] [blame] | 100 | |
| 101 | # UDP port 2152 enabled for ip6 |
| 102 | self._check_udp_port_ip6() |
| 103 | |
Ole Troan | 55636cb | 2019-12-08 14:14:37 +0100 | [diff] [blame] | 104 | r = self.vapi.gtpu_add_del_tunnel(is_add=False, |
| 105 | mcast_sw_if_index=0xFFFFFFFF, |
| 106 | decap_next_index=0xFFFFFFFF, |
| 107 | src_address=self.pg0.local_ip4, |
| 108 | dst_address=self.pg0.remote_ip4) |
Jakub Grajciar | ebae419 | 2019-05-23 13:01:41 +0200 | [diff] [blame] | 109 | |
Ole Troan | 55636cb | 2019-12-08 14:14:37 +0100 | [diff] [blame] | 110 | r = self.vapi.gtpu_add_del_tunnel(is_add=False, |
| 111 | mcast_sw_if_index=0xFFFFFFFF, |
| 112 | decap_next_index=0xFFFFFFFF, |
| 113 | src_address=self.pg0.local_ip6, |
| 114 | dst_address=self.pg0.remote_ip6) |
Jakub Grajciar | ebae419 | 2019-05-23 13:01:41 +0200 | [diff] [blame] | 115 | |
| 116 | |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 117 | class TestGtpu(BridgeDomain, VppTestCase): |
| 118 | """ GTPU Test Case """ |
| 119 | |
| 120 | def __init__(self, *args): |
| 121 | BridgeDomain.__init__(self) |
| 122 | VppTestCase.__init__(self, *args) |
| 123 | |
| 124 | def encapsulate(self, pkt, vni): |
| 125 | """ |
| 126 | Encapsulate the original payload frame by adding GTPU header with its |
| 127 | UDP, IP and Ethernet fields |
| 128 | """ |
| 129 | return (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / |
| 130 | IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) / |
| 131 | UDP(sport=self.dport, dport=self.dport, chksum=0) / |
Neale Ranns | 2bc9402 | 2018-02-25 12:27:18 -0800 | [diff] [blame] | 132 | GTP_U_Header(teid=vni, gtp_type=self.gtp_type, length=150) / |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 133 | pkt) |
| 134 | |
Eyal Bari | cef1e2a | 2018-06-18 13:01:59 +0300 | [diff] [blame] | 135 | def ip_range(self, start, end): |
| 136 | """ range of remote ip's """ |
| 137 | return ip4_range(self.pg0.remote_ip4, start, end) |
| 138 | |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 139 | def encap_mcast(self, pkt, src_ip, src_mac, vni): |
| 140 | """ |
| 141 | Encapsulate the original payload frame by adding GTPU header with its |
| 142 | UDP, IP and Ethernet fields |
| 143 | """ |
| 144 | return (Ether(src=src_mac, dst=self.mcast_mac) / |
| 145 | IP(src=src_ip, dst=self.mcast_ip4) / |
| 146 | UDP(sport=self.dport, dport=self.dport, chksum=0) / |
Neale Ranns | 2bc9402 | 2018-02-25 12:27:18 -0800 | [diff] [blame] | 147 | GTP_U_Header(teid=vni, gtp_type=self.gtp_type, length=150) / |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 148 | pkt) |
| 149 | |
| 150 | def decapsulate(self, pkt): |
| 151 | """ |
| 152 | Decapsulate the original payload frame by removing GTPU header |
| 153 | """ |
| 154 | return pkt[GTP_U_Header].payload |
| 155 | |
| 156 | # Method for checking GTPU encapsulation. |
| 157 | # |
| 158 | def check_encapsulation(self, pkt, vni, local_only=False, mcast_pkt=False): |
| 159 | # Verify source MAC is VPP_MAC and destination MAC is MY_MAC resolved |
| 160 | # by VPP using ARP. |
| 161 | self.assertEqual(pkt[Ether].src, self.pg0.local_mac) |
| 162 | if not local_only: |
| 163 | if not mcast_pkt: |
| 164 | self.assertEqual(pkt[Ether].dst, self.pg0.remote_mac) |
| 165 | else: |
| 166 | self.assertEqual(pkt[Ether].dst, type(self).mcast_mac) |
| 167 | # Verify GTPU tunnel source IP is VPP_IP and destination IP is MY_IP. |
| 168 | self.assertEqual(pkt[IP].src, self.pg0.local_ip4) |
| 169 | if not local_only: |
| 170 | if not mcast_pkt: |
| 171 | self.assertEqual(pkt[IP].dst, self.pg0.remote_ip4) |
| 172 | else: |
| 173 | self.assertEqual(pkt[IP].dst, type(self).mcast_ip4) |
| 174 | # Verify UDP destination port is GTPU 2152, source UDP port could be |
| 175 | # arbitrary. |
| 176 | self.assertEqual(pkt[UDP].dport, type(self).dport) |
Neale Ranns | 2bc9402 | 2018-02-25 12:27:18 -0800 | [diff] [blame] | 177 | # Verify teid |
| 178 | self.assertEqual(pkt[GTP_U_Header].teid, vni) |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 179 | |
| 180 | def test_encap(self): |
| 181 | """ Encapsulation test |
| 182 | Send frames from pg1 |
| 183 | Verify receipt of encapsulated frames on pg0 |
| 184 | """ |
| 185 | self.pg1.add_stream([self.frame_reply]) |
| 186 | |
| 187 | self.pg0.enable_capture() |
| 188 | |
| 189 | self.pg_start() |
| 190 | |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 191 | # Pick first received frame and check if it's correctly encapsulated. |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 192 | out = self.pg0.get_capture(1) |
| 193 | pkt = out[0] |
Neale Ranns | 91fd910 | 2020-04-03 07:46:28 +0000 | [diff] [blame] | 194 | self.check_encapsulation(pkt, self.single_tunnel_vni) |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 195 | |
| 196 | # payload = self.decapsulate(pkt) |
| 197 | # self.assert_eq_pkts(payload, self.frame_reply) |
| 198 | |
| 199 | def test_ucast_flood(self): |
| 200 | """ Unicast flood test |
| 201 | Send frames from pg3 |
| 202 | Verify receipt of encapsulated frames on pg0 |
| 203 | """ |
| 204 | self.pg3.add_stream([self.frame_reply]) |
| 205 | |
| 206 | self.pg0.enable_capture() |
| 207 | |
| 208 | self.pg_start() |
| 209 | |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 210 | # Get packet from each tunnel and assert it's correctly encapsulated. |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 211 | out = self.pg0.get_capture(self.n_ucast_tunnels) |
| 212 | for pkt in out: |
| 213 | self.check_encapsulation(pkt, self.ucast_flood_bd, True) |
| 214 | # payload = self.decapsulate(pkt) |
| 215 | # self.assert_eq_pkts(payload, self.frame_reply) |
| 216 | |
| 217 | def test_mcast_flood(self): |
| 218 | """ Multicast flood test |
| 219 | Send frames from pg2 |
| 220 | Verify receipt of encapsulated frames on pg0 |
| 221 | """ |
| 222 | self.pg2.add_stream([self.frame_reply]) |
| 223 | |
| 224 | self.pg0.enable_capture() |
| 225 | |
| 226 | self.pg_start() |
| 227 | |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 228 | # Pick first received frame and check if it's correctly encapsulated. |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 229 | out = self.pg0.get_capture(1) |
| 230 | pkt = out[0] |
| 231 | self.check_encapsulation(pkt, self.mcast_flood_bd, |
| 232 | local_only=False, mcast_pkt=True) |
| 233 | |
| 234 | # payload = self.decapsulate(pkt) |
| 235 | # self.assert_eq_pkts(payload, self.frame_reply) |
| 236 | |
| 237 | @classmethod |
| 238 | def create_gtpu_flood_test_bd(cls, teid, n_ucast_tunnels): |
| 239 | # Create 10 ucast gtpu tunnels under bd |
| 240 | ip_range_start = 10 |
| 241 | ip_range_end = ip_range_start + n_ucast_tunnels |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 242 | next_hop_address = cls.pg0.remote_ip4 |
| 243 | for dest_ip4 in ip4_range(next_hop_address, ip_range_start, |
| 244 | ip_range_end): |
Paul Vinciguerra | 2f15631 | 2020-05-02 22:34:40 -0400 | [diff] [blame] | 245 | # add host route so dest_ip4 will not be resolved |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 246 | rip = VppIpRoute(cls, dest_ip4, 32, |
| 247 | [VppRoutePath(next_hop_address, |
| 248 | INVALID_INDEX)], |
| 249 | register=False) |
| 250 | rip.add_vpp_config() |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 251 | r = cls.vapi.gtpu_add_del_tunnel( |
Ole Troan | 55636cb | 2019-12-08 14:14:37 +0100 | [diff] [blame] | 252 | is_add=True, |
| 253 | mcast_sw_if_index=0xFFFFFFFF, |
| 254 | decap_next_index=0xFFFFFFFF, |
| 255 | src_address=cls.pg0.local_ip4, |
| 256 | dst_address=dest_ip4, |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 257 | teid=teid) |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 258 | cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, |
| 259 | bd_id=teid) |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 260 | |
| 261 | @classmethod |
| 262 | def add_del_shared_mcast_dst_load(cls, is_add): |
| 263 | """ |
| 264 | add or del tunnels sharing the same mcast dst |
| 265 | to test gtpu ref_count mechanism |
| 266 | """ |
| 267 | n_shared_dst_tunnels = 20 |
| 268 | teid_start = 1000 |
| 269 | teid_end = teid_start + n_shared_dst_tunnels |
| 270 | for teid in range(teid_start, teid_end): |
| 271 | r = cls.vapi.gtpu_add_del_tunnel( |
Ole Troan | 55636cb | 2019-12-08 14:14:37 +0100 | [diff] [blame] | 272 | decap_next_index=0xFFFFFFFF, |
| 273 | src_address=cls.pg0.local_ip4, |
| 274 | dst_address=cls.mcast_ip4, |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 275 | mcast_sw_if_index=1, |
| 276 | teid=teid, |
| 277 | is_add=is_add) |
| 278 | if r.sw_if_index == 0xffffffff: |
Paul Vinciguerra | c599c6f | 2019-03-12 17:41:27 -0700 | [diff] [blame] | 279 | raise ValueError("bad sw_if_index: ~0") |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 280 | |
| 281 | @classmethod |
| 282 | def add_shared_mcast_dst_load(cls): |
| 283 | cls.add_del_shared_mcast_dst_load(is_add=1) |
| 284 | |
| 285 | @classmethod |
| 286 | def del_shared_mcast_dst_load(cls): |
| 287 | cls.add_del_shared_mcast_dst_load(is_add=0) |
| 288 | |
| 289 | @classmethod |
| 290 | def add_del_mcast_tunnels_load(cls, is_add): |
| 291 | """ |
| 292 | add or del tunnels to test gtpu stability |
| 293 | """ |
| 294 | n_distinct_dst_tunnels = 20 |
| 295 | ip_range_start = 10 |
| 296 | ip_range_end = ip_range_start + n_distinct_dst_tunnels |
Ole Troan | 55636cb | 2019-12-08 14:14:37 +0100 | [diff] [blame] | 297 | for dest_ip4 in ip4_range(cls.mcast_ip4, ip_range_start, |
| 298 | ip_range_end): |
| 299 | teid = int(dest_ip4.split('.')[3]) |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 300 | cls.vapi.gtpu_add_del_tunnel( |
Ole Troan | 55636cb | 2019-12-08 14:14:37 +0100 | [diff] [blame] | 301 | decap_next_index=0xFFFFFFFF, |
| 302 | src_address=cls.pg0.local_ip4, |
| 303 | dst_address=dest_ip4, |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 304 | mcast_sw_if_index=1, |
| 305 | teid=teid, |
| 306 | is_add=is_add) |
| 307 | |
| 308 | @classmethod |
| 309 | def add_mcast_tunnels_load(cls): |
| 310 | cls.add_del_mcast_tunnels_load(is_add=1) |
| 311 | |
| 312 | @classmethod |
| 313 | def del_mcast_tunnels_load(cls): |
| 314 | cls.add_del_mcast_tunnels_load(is_add=0) |
| 315 | |
| 316 | # Class method to start the GTPU test case. |
| 317 | # Overrides setUpClass method in VppTestCase class. |
| 318 | # Python try..except statement is used to ensure that the tear down of |
| 319 | # the class will be executed even if exception is raised. |
| 320 | # @param cls The class pointer. |
| 321 | @classmethod |
| 322 | def setUpClass(cls): |
| 323 | super(TestGtpu, cls).setUpClass() |
| 324 | |
| 325 | try: |
| 326 | cls.dport = 2152 |
| 327 | cls.gtp_type = 0xff |
| 328 | |
| 329 | # Create 2 pg interfaces. |
| 330 | cls.create_pg_interfaces(range(4)) |
| 331 | for pg in cls.pg_interfaces: |
| 332 | pg.admin_up() |
| 333 | |
| 334 | # Configure IPv4 addresses on VPP pg0. |
| 335 | cls.pg0.config_ip4() |
| 336 | |
| 337 | # Resolve MAC address for VPP's IP address on pg0. |
| 338 | cls.pg0.resolve_arp() |
| 339 | |
| 340 | # Our Multicast address |
| 341 | cls.mcast_ip4 = '239.1.1.1' |
Paul Vinciguerra | 2f15631 | 2020-05-02 22:34:40 -0400 | [diff] [blame] | 342 | cls.mcast_mac = util.mcast_ip_to_mac(cls.mcast_ip4) |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 343 | |
| 344 | # Create GTPU VTEP on VPP pg0, and put gtpu_tunnel0 and pg1 |
| 345 | # into BD. |
| 346 | cls.single_tunnel_bd = 11 |
Neale Ranns | 91fd910 | 2020-04-03 07:46:28 +0000 | [diff] [blame] | 347 | cls.single_tunnel_vni = 11 |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 348 | r = cls.vapi.gtpu_add_del_tunnel( |
Ole Troan | 55636cb | 2019-12-08 14:14:37 +0100 | [diff] [blame] | 349 | is_add=True, |
| 350 | mcast_sw_if_index=0xFFFFFFFF, |
| 351 | decap_next_index=0xFFFFFFFF, |
| 352 | src_address=cls.pg0.local_ip4, |
| 353 | dst_address=cls.pg0.remote_ip4, |
Neale Ranns | 91fd910 | 2020-04-03 07:46:28 +0000 | [diff] [blame] | 354 | teid=cls.single_tunnel_vni) |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 355 | cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 356 | bd_id=cls.single_tunnel_bd) |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 357 | cls.vapi.sw_interface_set_l2_bridge( |
| 358 | rx_sw_if_index=cls.pg1.sw_if_index, bd_id=cls.single_tunnel_bd) |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 359 | |
| 360 | # Setup teid 2 to test multicast flooding |
| 361 | cls.n_ucast_tunnels = 10 |
| 362 | cls.mcast_flood_bd = 12 |
| 363 | cls.create_gtpu_flood_test_bd(cls.mcast_flood_bd, |
| 364 | cls.n_ucast_tunnels) |
| 365 | r = cls.vapi.gtpu_add_del_tunnel( |
Ole Troan | 55636cb | 2019-12-08 14:14:37 +0100 | [diff] [blame] | 366 | is_add=True, |
| 367 | src_address=cls.pg0.local_ip4, |
| 368 | dst_address=cls.mcast_ip4, |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 369 | mcast_sw_if_index=1, |
Ole Troan | 55636cb | 2019-12-08 14:14:37 +0100 | [diff] [blame] | 370 | decap_next_index=0xFFFFFFFF, |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 371 | teid=cls.mcast_flood_bd) |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 372 | cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 373 | bd_id=cls.mcast_flood_bd) |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 374 | cls.vapi.sw_interface_set_l2_bridge( |
| 375 | rx_sw_if_index=cls.pg2.sw_if_index, bd_id=cls.mcast_flood_bd) |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 376 | |
| 377 | # Add and delete mcast tunnels to check stability |
| 378 | cls.add_shared_mcast_dst_load() |
| 379 | cls.add_mcast_tunnels_load() |
| 380 | cls.del_shared_mcast_dst_load() |
| 381 | cls.del_mcast_tunnels_load() |
| 382 | |
| 383 | # Setup teid 3 to test unicast flooding |
| 384 | cls.ucast_flood_bd = 13 |
| 385 | cls.create_gtpu_flood_test_bd(cls.ucast_flood_bd, |
| 386 | cls.n_ucast_tunnels) |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 387 | cls.vapi.sw_interface_set_l2_bridge( |
| 388 | rx_sw_if_index=cls.pg3.sw_if_index, bd_id=cls.ucast_flood_bd) |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 389 | except Exception: |
| 390 | super(TestGtpu, cls).tearDownClass() |
| 391 | raise |
| 392 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 393 | @classmethod |
| 394 | def tearDownClass(cls): |
| 395 | super(TestGtpu, cls).tearDownClass() |
| 396 | |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 397 | # Method to define VPP actions before tear down of the test case. |
| 398 | # Overrides tearDown method in VppTestCase class. |
| 399 | # @param self The object pointer. |
| 400 | def tearDown(self): |
| 401 | super(TestGtpu, self).tearDown() |
Paul Vinciguerra | 90cf21b | 2019-03-13 09:23:05 -0700 | [diff] [blame] | 402 | |
| 403 | def show_commands_at_teardown(self): |
| 404 | self.logger.info(self.vapi.cli("show bridge-domain 11 detail")) |
| 405 | self.logger.info(self.vapi.cli("show bridge-domain 12 detail")) |
| 406 | self.logger.info(self.vapi.cli("show bridge-domain 13 detail")) |
| 407 | self.logger.info(self.vapi.cli("show int")) |
| 408 | self.logger.info(self.vapi.cli("show gtpu tunnel")) |
| 409 | self.logger.info(self.vapi.cli("show trace")) |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 410 | |
| 411 | |
| 412 | if __name__ == '__main__': |
| 413 | unittest.main(testRunner=VppTestRunner) |