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