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