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