Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 2 | """GSO functional tests""" |
| 3 | |
| 4 | # |
| 5 | # Add tests for: |
| 6 | # - GSO |
| 7 | # - Verify that sending Jumbo frame without GSO enabled correctly |
| 8 | # - Verify that sending Jumbo frame with GSO enabled correctly |
| 9 | # - Verify that sending Jumbo frame with GSO enabled only on ingress interface |
| 10 | # |
| 11 | import unittest |
| 12 | |
| 13 | from scapy.packet import Raw |
Arthur de Kerhor | 2f4586d | 2021-09-22 14:53:24 +0200 | [diff] [blame] | 14 | from scapy.layers.l2 import GRE |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 15 | from scapy.layers.inet6 import IPv6, Ether, IP, ICMPv6PacketTooBig |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 16 | from scapy.layers.inet6 import ipv6nh, IPerror6 |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 17 | from scapy.layers.inet import TCP, ICMP |
| 18 | from scapy.layers.vxlan import VXLAN |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 19 | from scapy.layers.ipsec import ESP |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 20 | |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 21 | from vpp_papi import VppEnum |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 22 | from framework import VppTestCase |
| 23 | from asfframework import VppTestRunner |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 24 | from vpp_ip_route import VppIpRoute, VppRoutePath, FibPathProto |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 25 | from vpp_ipip_tun_interface import VppIpIpTunInterface |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 26 | from vpp_vxlan_tunnel import VppVxlanTunnel |
Arthur de Kerhor | 2f4586d | 2021-09-22 14:53:24 +0200 | [diff] [blame] | 27 | from vpp_gre_interface import VppGreInterface |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame] | 28 | from config import config |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 29 | |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 30 | from vpp_ipsec import VppIpsecSA, VppIpsecTunProtect |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 31 | from template_ipsec import ( |
| 32 | IPsecIPv4Params, |
| 33 | IPsecIPv6Params, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 34 | config_tun_params, |
| 35 | ) |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 36 | |
| 37 | """ Test_gso is a subclass of VPPTestCase classes. |
| 38 | GSO tests. |
| 39 | """ |
| 40 | |
| 41 | |
| 42 | class TestGSO(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 43 | """GSO Test Case""" |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 44 | |
| 45 | def __init__(self, *args): |
| 46 | VppTestCase.__init__(self, *args) |
| 47 | |
| 48 | @classmethod |
| 49 | def setUpClass(self): |
| 50 | super(TestGSO, self).setUpClass() |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 51 | res = self.create_pg_interfaces(range(2)) |
| 52 | res_gso = self.create_pg_interfaces(range(2, 4), 1, 1460) |
| 53 | self.create_pg_interfaces(range(4, 5), 1, 8940) |
| 54 | self.pg_interfaces.append(res[0]) |
| 55 | self.pg_interfaces.append(res[1]) |
| 56 | self.pg_interfaces.append(res_gso[0]) |
| 57 | self.pg_interfaces.append(res_gso[1]) |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 58 | |
| 59 | @classmethod |
| 60 | def tearDownClass(self): |
| 61 | super(TestGSO, self).tearDownClass() |
| 62 | |
| 63 | def setUp(self): |
| 64 | super(TestGSO, self).setUp() |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 65 | for i in self.pg_interfaces: |
| 66 | i.admin_up() |
| 67 | i.config_ip4() |
| 68 | i.config_ip6() |
| 69 | i.disable_ipv6_ra() |
| 70 | i.resolve_arp() |
| 71 | i.resolve_ndp() |
| 72 | |
| 73 | self.single_tunnel_bd = 10 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 74 | self.vxlan = VppVxlanTunnel( |
| 75 | self, |
| 76 | src=self.pg0.local_ip4, |
| 77 | dst=self.pg0.remote_ip4, |
| 78 | vni=self.single_tunnel_bd, |
| 79 | ) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 80 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 81 | self.vxlan2 = VppVxlanTunnel( |
| 82 | self, |
| 83 | src=self.pg0.local_ip6, |
| 84 | dst=self.pg0.remote_ip6, |
| 85 | vni=self.single_tunnel_bd, |
| 86 | ) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 87 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 88 | self.ipip4 = VppIpIpTunInterface( |
| 89 | self, self.pg0, self.pg0.local_ip4, self.pg0.remote_ip4 |
| 90 | ) |
| 91 | self.ipip6 = VppIpIpTunInterface( |
| 92 | self, self.pg0, self.pg0.local_ip6, self.pg0.remote_ip6 |
| 93 | ) |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 94 | |
Arthur de Kerhor | 2f4586d | 2021-09-22 14:53:24 +0200 | [diff] [blame] | 95 | self.gre4 = VppGreInterface(self, self.pg0.local_ip4, self.pg0.remote_ip4) |
| 96 | self.gre6 = VppGreInterface(self, self.pg0.local_ip6, self.pg0.remote_ip6) |
| 97 | |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 98 | def tearDown(self): |
| 99 | super(TestGSO, self).tearDown() |
| 100 | if not self.vpp_dead: |
| 101 | for i in self.pg_interfaces: |
| 102 | i.unconfig_ip4() |
| 103 | i.unconfig_ip6() |
| 104 | i.admin_down() |
| 105 | |
| 106 | def test_gso(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 107 | """GSO test""" |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 108 | # |
| 109 | # Send jumbo frame with gso disabled and DF bit is set |
| 110 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 111 | p4 = ( |
| 112 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 113 | / IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4, flags="DF") |
| 114 | / TCP(sport=1234, dport=1234) |
| 115 | / Raw(b"\xa5" * 65200) |
| 116 | ) |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 117 | |
| 118 | rxs = self.send_and_expect(self.pg0, [p4], self.pg0) |
| 119 | |
| 120 | for rx in rxs: |
| 121 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 122 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 123 | self.assertEqual(rx[IP].src, self.pg0.local_ip4) |
| 124 | self.assertEqual(rx[IP].dst, self.pg0.remote_ip4) |
| 125 | self.assertEqual(rx[ICMP].type, 3) # "dest-unreach" |
| 126 | self.assertEqual(rx[ICMP].code, 4) # "fragmentation-needed" |
| 127 | |
| 128 | # |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 129 | # Send checksum offload frames |
| 130 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 131 | p40 = ( |
| 132 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
| 133 | / IP(src=self.pg2.remote_ip4, dst=self.pg0.remote_ip4, flags="DF") |
| 134 | / TCP(sport=1234, dport=1234) |
| 135 | / Raw(b"\xa5" * 1460) |
| 136 | ) |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 137 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 138 | rxs = self.send_and_expect(self.pg2, 100 * [p40], self.pg0) |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 139 | |
| 140 | for rx in rxs: |
| 141 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 142 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 143 | self.assertEqual(rx[IP].src, self.pg2.remote_ip4) |
| 144 | self.assertEqual(rx[IP].dst, self.pg0.remote_ip4) |
| 145 | payload_len = rx[IP].len - 20 - 20 |
| 146 | self.assert_ip_checksum_valid(rx) |
| 147 | self.assert_tcp_checksum_valid(rx) |
| 148 | self.assertEqual(payload_len, len(rx[Raw])) |
| 149 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 150 | p60 = ( |
| 151 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
| 152 | / IPv6(src=self.pg2.remote_ip6, dst=self.pg0.remote_ip6) |
| 153 | / TCP(sport=1234, dport=1234) |
| 154 | / Raw(b"\xa5" * 1440) |
| 155 | ) |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 156 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 157 | rxs = self.send_and_expect(self.pg2, 100 * [p60], self.pg0) |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 158 | |
| 159 | for rx in rxs: |
| 160 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 161 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 162 | self.assertEqual(rx[IPv6].src, self.pg2.remote_ip6) |
| 163 | self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6) |
| 164 | payload_len = rx[IPv6].plen - 20 |
| 165 | self.assert_tcp_checksum_valid(rx) |
| 166 | self.assertEqual(payload_len, len(rx[Raw])) |
| 167 | |
| 168 | # |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 169 | # Send jumbo frame with gso enabled and DF bit is set |
| 170 | # input and output interfaces support GSO |
| 171 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 172 | self.vapi.feature_gso_enable_disable( |
| 173 | sw_if_index=self.pg3.sw_if_index, enable_disable=1 |
| 174 | ) |
| 175 | p41 = ( |
| 176 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
| 177 | / IP(src=self.pg2.remote_ip4, dst=self.pg3.remote_ip4, flags="DF") |
| 178 | / TCP(sport=1234, dport=1234) |
| 179 | / Raw(b"\xa5" * 65200) |
| 180 | ) |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 181 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 182 | rxs = self.send_and_expect(self.pg2, 100 * [p41], self.pg3, 100) |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 183 | |
| 184 | for rx in rxs: |
| 185 | self.assertEqual(rx[Ether].src, self.pg3.local_mac) |
| 186 | self.assertEqual(rx[Ether].dst, self.pg3.remote_mac) |
| 187 | self.assertEqual(rx[IP].src, self.pg2.remote_ip4) |
| 188 | self.assertEqual(rx[IP].dst, self.pg3.remote_ip4) |
| 189 | self.assertEqual(rx[IP].len, 65240) # 65200 + 20 (IP) + 20 (TCP) |
| 190 | self.assertEqual(rx[TCP].sport, 1234) |
| 191 | self.assertEqual(rx[TCP].dport, 1234) |
| 192 | |
| 193 | # |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 194 | # ipv6 |
| 195 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 196 | p61 = ( |
| 197 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
| 198 | / IPv6(src=self.pg2.remote_ip6, dst=self.pg3.remote_ip6) |
| 199 | / TCP(sport=1234, dport=1234) |
| 200 | / Raw(b"\xa5" * 65200) |
| 201 | ) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 202 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 203 | rxs = self.send_and_expect(self.pg2, 100 * [p61], self.pg3, 100) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 204 | |
| 205 | for rx in rxs: |
| 206 | self.assertEqual(rx[Ether].src, self.pg3.local_mac) |
| 207 | self.assertEqual(rx[Ether].dst, self.pg3.remote_mac) |
| 208 | self.assertEqual(rx[IPv6].src, self.pg2.remote_ip6) |
| 209 | self.assertEqual(rx[IPv6].dst, self.pg3.remote_ip6) |
| 210 | self.assertEqual(rx[IPv6].plen, 65220) # 65200 + 20 (TCP) |
| 211 | self.assertEqual(rx[TCP].sport, 1234) |
| 212 | self.assertEqual(rx[TCP].dport, 1234) |
| 213 | |
| 214 | # |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 215 | # Send jumbo frame with gso enabled only on input interface |
| 216 | # and DF bit is set. GSO packet will be chunked into gso_size |
| 217 | # data payload |
| 218 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 219 | self.vapi.feature_gso_enable_disable( |
| 220 | sw_if_index=self.pg0.sw_if_index, enable_disable=1 |
| 221 | ) |
| 222 | p42 = ( |
| 223 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
| 224 | / IP(src=self.pg2.remote_ip4, dst=self.pg0.remote_ip4, flags="DF") |
| 225 | / TCP(sport=1234, dport=1234) |
| 226 | / Raw(b"\xa5" * 65200) |
| 227 | ) |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 228 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 229 | rxs = self.send_and_expect(self.pg2, 5 * [p42], self.pg0, 225) |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 230 | size = 0 |
| 231 | for rx in rxs: |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 232 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 233 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 234 | self.assertEqual(rx[IP].src, self.pg2.remote_ip4) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 235 | self.assertEqual(rx[IP].dst, self.pg0.remote_ip4) |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 236 | payload_len = rx[IP].len - 20 - 20 # len - 20 (IP4) - 20 (TCP) |
| 237 | self.assert_ip_checksum_valid(rx) |
| 238 | self.assert_tcp_checksum_valid(rx) |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 239 | self.assertEqual(rx[TCP].sport, 1234) |
| 240 | self.assertEqual(rx[TCP].dport, 1234) |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 241 | self.assertEqual(payload_len, len(rx[Raw])) |
| 242 | size += payload_len |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 243 | self.assertEqual(size, 65200 * 5) |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 244 | |
| 245 | # |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 246 | # ipv6 |
| 247 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 248 | p62 = ( |
| 249 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
| 250 | / IPv6(src=self.pg2.remote_ip6, dst=self.pg0.remote_ip6) |
| 251 | / TCP(sport=1234, dport=1234) |
| 252 | / Raw(b"\xa5" * 65200) |
| 253 | ) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 254 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 255 | rxs = self.send_and_expect(self.pg2, 5 * [p62], self.pg0, 225) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 256 | size = 0 |
| 257 | for rx in rxs: |
| 258 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 259 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 260 | self.assertEqual(rx[IPv6].src, self.pg2.remote_ip6) |
| 261 | self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6) |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 262 | payload_len = rx[IPv6].plen - 20 |
| 263 | self.assert_tcp_checksum_valid(rx) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 264 | self.assertEqual(rx[TCP].sport, 1234) |
| 265 | self.assertEqual(rx[TCP].dport, 1234) |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 266 | self.assertEqual(payload_len, len(rx[Raw])) |
| 267 | size += payload_len |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 268 | self.assertEqual(size, 65200 * 5) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 269 | |
| 270 | # |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 271 | # Send jumbo frame with gso enabled only on input interface |
| 272 | # and DF bit is unset. GSO packet will be fragmented. |
| 273 | # |
| 274 | self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [576, 0, 0, 0]) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 275 | self.vapi.feature_gso_enable_disable( |
| 276 | sw_if_index=self.pg1.sw_if_index, enable_disable=1 |
| 277 | ) |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 278 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 279 | p43 = ( |
| 280 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
| 281 | / IP(src=self.pg2.remote_ip4, dst=self.pg1.remote_ip4) |
| 282 | / TCP(sport=1234, dport=1234) |
| 283 | / Raw(b"\xa5" * 65200) |
| 284 | ) |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 285 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 286 | rxs = self.send_and_expect(self.pg2, 5 * [p43], self.pg1, 5 * 119) |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 287 | size = 0 |
| 288 | for rx in rxs: |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 289 | self.assertEqual(rx[Ether].src, self.pg1.local_mac) |
| 290 | self.assertEqual(rx[Ether].dst, self.pg1.remote_mac) |
| 291 | self.assertEqual(rx[IP].src, self.pg2.remote_ip4) |
| 292 | self.assertEqual(rx[IP].dst, self.pg1.remote_ip4) |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 293 | self.assert_ip_checksum_valid(rx) |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 294 | size += rx[IP].len - 20 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 295 | size -= 20 * 5 # TCP header |
| 296 | self.assertEqual(size, 65200 * 5) |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 297 | |
Mohsin Kazmi | 3f1964d | 2019-08-22 18:40:28 +0200 | [diff] [blame] | 298 | # |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 299 | # IPv6 |
| 300 | # Send jumbo frame with gso enabled only on input interface. |
| 301 | # ICMPv6 Packet Too Big will be sent back to sender. |
| 302 | # |
| 303 | self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [1280, 0, 0, 0]) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 304 | p63 = ( |
| 305 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
| 306 | / IPv6(src=self.pg2.remote_ip6, dst=self.pg1.remote_ip6) |
| 307 | / TCP(sport=1234, dport=1234) |
| 308 | / Raw(b"\xa5" * 65200) |
| 309 | ) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 310 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 311 | rxs = self.send_and_expect_some(self.pg2, 5 * [p63], self.pg2, 5) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 312 | for rx in rxs: |
| 313 | self.assertEqual(rx[Ether].src, self.pg2.local_mac) |
| 314 | self.assertEqual(rx[Ether].dst, self.pg2.remote_mac) |
| 315 | self.assertEqual(rx[IPv6].src, self.pg2.local_ip6) |
| 316 | self.assertEqual(rx[IPv6].dst, self.pg2.remote_ip6) |
| 317 | self.assertEqual(rx[IPv6].plen, 1240) # MTU - IPv6 header |
| 318 | self.assertEqual(ipv6nh[rx[IPv6].nh], "ICMPv6") |
| 319 | self.assertEqual(rx[ICMPv6PacketTooBig].mtu, 1280) |
| 320 | self.assertEqual(rx[IPerror6].src, self.pg2.remote_ip6) |
| 321 | self.assertEqual(rx[IPerror6].dst, self.pg1.remote_ip6) |
| 322 | self.assertEqual(rx[IPerror6].plen - 20, 65200) |
| 323 | |
| 324 | # |
Mohsin Kazmi | 3f1964d | 2019-08-22 18:40:28 +0200 | [diff] [blame] | 325 | # Send jumbo frame with gso enabled only on input interface with 9K MTU |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 326 | # and DF bit is unset. GSO packet will be fragmented. MSS is 8960. GSO |
| 327 | # size will be min(MSS, 2048 - 14 - 20) vlib_buffer_t size |
Mohsin Kazmi | 3f1964d | 2019-08-22 18:40:28 +0200 | [diff] [blame] | 328 | # |
| 329 | self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [9000, 0, 0, 0]) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 330 | self.vapi.sw_interface_set_mtu(self.pg4.sw_if_index, [9000, 0, 0, 0]) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 331 | p44 = ( |
| 332 | Ether(src=self.pg4.remote_mac, dst=self.pg4.local_mac) |
| 333 | / IP(src=self.pg4.remote_ip4, dst=self.pg1.remote_ip4) |
| 334 | / TCP(sport=1234, dport=1234) |
| 335 | / Raw(b"\xa5" * 65200) |
| 336 | ) |
Mohsin Kazmi | 3f1964d | 2019-08-22 18:40:28 +0200 | [diff] [blame] | 337 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 338 | rxs = self.send_and_expect(self.pg4, 5 * [p44], self.pg1, 165) |
Mohsin Kazmi | 3f1964d | 2019-08-22 18:40:28 +0200 | [diff] [blame] | 339 | size = 0 |
| 340 | for rx in rxs: |
| 341 | self.assertEqual(rx[Ether].src, self.pg1.local_mac) |
| 342 | self.assertEqual(rx[Ether].dst, self.pg1.remote_mac) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 343 | self.assertEqual(rx[IP].src, self.pg4.remote_ip4) |
Mohsin Kazmi | 3f1964d | 2019-08-22 18:40:28 +0200 | [diff] [blame] | 344 | self.assertEqual(rx[IP].dst, self.pg1.remote_ip4) |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 345 | payload_len = rx[IP].len - 20 - 20 # len - 20 (IP4) - 20 (TCP) |
| 346 | self.assert_ip_checksum_valid(rx) |
| 347 | self.assert_tcp_checksum_valid(rx) |
| 348 | self.assertEqual(payload_len, len(rx[Raw])) |
| 349 | size += payload_len |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 350 | self.assertEqual(size, 65200 * 5) |
Mohsin Kazmi | 3f1964d | 2019-08-22 18:40:28 +0200 | [diff] [blame] | 351 | |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 352 | # |
| 353 | # IPv6 |
| 354 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 355 | p64 = ( |
| 356 | Ether(src=self.pg4.remote_mac, dst=self.pg4.local_mac) |
| 357 | / IPv6(src=self.pg4.remote_ip6, dst=self.pg1.remote_ip6) |
| 358 | / TCP(sport=1234, dport=1234) |
| 359 | / Raw(b"\xa5" * 65200) |
| 360 | ) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 361 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 362 | rxs = self.send_and_expect(self.pg4, 5 * [p64], self.pg1, 170) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 363 | size = 0 |
| 364 | for rx in rxs: |
| 365 | self.assertEqual(rx[Ether].src, self.pg1.local_mac) |
| 366 | self.assertEqual(rx[Ether].dst, self.pg1.remote_mac) |
| 367 | self.assertEqual(rx[IPv6].src, self.pg4.remote_ip6) |
| 368 | self.assertEqual(rx[IPv6].dst, self.pg1.remote_ip6) |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 369 | payload_len = rx[IPv6].plen - 20 |
| 370 | self.assert_tcp_checksum_valid(rx) |
| 371 | self.assertEqual(payload_len, len(rx[Raw])) |
| 372 | size += payload_len |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 373 | self.assertEqual(size, 65200 * 5) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 374 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 375 | self.vapi.feature_gso_enable_disable( |
| 376 | sw_if_index=self.pg0.sw_if_index, enable_disable=0 |
| 377 | ) |
| 378 | self.vapi.feature_gso_enable_disable( |
| 379 | sw_if_index=self.pg1.sw_if_index, enable_disable=0 |
| 380 | ) |
Mohsin Kazmi | 1ab8b3c | 2020-05-05 10:31:17 +0000 | [diff] [blame] | 381 | |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame] | 382 | @unittest.skipIf( |
| 383 | "vxlan" in config.excluded_plugins, "Exclude tests requiring VXLAN plugin" |
| 384 | ) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 385 | def test_gso_vxlan(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 386 | """GSO VXLAN test""" |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 387 | self.logger.info(self.vapi.cli("sh int addr")) |
| 388 | # |
| 389 | # Send jumbo frame with gso enabled only on input interface and |
| 390 | # create VXLAN VTEP on VPP pg0, and put vxlan_tunnel0 and pg2 |
| 391 | # into BD. |
| 392 | # |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 393 | |
| 394 | # |
| 395 | # enable ipv4/vxlan |
| 396 | # |
| 397 | self.vxlan.add_vpp_config() |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 398 | self.vapi.sw_interface_set_l2_bridge( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 399 | rx_sw_if_index=self.vxlan.sw_if_index, bd_id=self.single_tunnel_bd |
| 400 | ) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 401 | self.vapi.sw_interface_set_l2_bridge( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 402 | rx_sw_if_index=self.pg2.sw_if_index, bd_id=self.single_tunnel_bd |
| 403 | ) |
| 404 | self.vapi.feature_gso_enable_disable( |
| 405 | sw_if_index=self.pg0.sw_if_index, enable_disable=1 |
| 406 | ) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 407 | |
| 408 | # |
| 409 | # IPv4/IPv4 - VXLAN |
| 410 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 411 | p45 = ( |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 412 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 413 | / IP(src=self.pg2.remote_ip4, dst="172.16.3.3", flags="DF") |
| 414 | / TCP(sport=1234, dport=1234) |
| 415 | / Raw(b"\xa5" * 65200) |
| 416 | ) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 417 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 418 | rxs = self.send_and_expect(self.pg2, 5 * [p45], self.pg0, 225) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 419 | size = 0 |
| 420 | for rx in rxs: |
| 421 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 422 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 423 | self.assertEqual(rx[IP].src, self.pg0.local_ip4) |
| 424 | self.assertEqual(rx[IP].dst, self.pg0.remote_ip4) |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 425 | self.assert_ip_checksum_valid(rx) |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 426 | self.assert_udp_checksum_valid(rx, ignore_zero_checksum=True) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 427 | self.assertEqual(rx[VXLAN].vni, 10) |
| 428 | inner = rx[VXLAN].payload |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 429 | self.assertEqual(rx[IP].len - 20 - 8 - 8, len(inner)) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 430 | self.assertEqual(inner[Ether].src, self.pg2.remote_mac) |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 431 | self.assertEqual(inner[Ether].dst, self.pg2.local_mac) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 432 | self.assertEqual(inner[IP].src, self.pg2.remote_ip4) |
| 433 | self.assertEqual(inner[IP].dst, "172.16.3.3") |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 434 | self.assert_ip_checksum_valid(inner) |
| 435 | self.assert_tcp_checksum_valid(inner) |
| 436 | payload_len = inner[IP].len - 20 - 20 |
| 437 | self.assertEqual(payload_len, len(inner[Raw])) |
| 438 | size += payload_len |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 439 | self.assertEqual(size, 65200 * 5) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 440 | |
| 441 | # |
| 442 | # IPv4/IPv6 - VXLAN |
| 443 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 444 | p65 = ( |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 445 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 446 | / IPv6(src=self.pg2.remote_ip6, dst="fd01:3::3") |
| 447 | / TCP(sport=1234, dport=1234) |
| 448 | / Raw(b"\xa5" * 65200) |
| 449 | ) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 450 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 451 | rxs = self.send_and_expect(self.pg2, 5 * [p65], self.pg0, 225) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 452 | size = 0 |
| 453 | for rx in rxs: |
| 454 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 455 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 456 | self.assertEqual(rx[IP].src, self.pg0.local_ip4) |
| 457 | self.assertEqual(rx[IP].dst, self.pg0.remote_ip4) |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 458 | self.assert_ip_checksum_valid(rx) |
Mohsin Kazmi | 7b3339e | 2022-09-29 15:28:04 +0000 | [diff] [blame] | 459 | self.assert_udp_checksum_valid(rx, ignore_zero_checksum=True) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 460 | self.assertEqual(rx[VXLAN].vni, 10) |
| 461 | inner = rx[VXLAN].payload |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 462 | self.assertEqual(rx[IP].len - 20 - 8 - 8, len(inner)) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 463 | self.assertEqual(inner[Ether].src, self.pg2.remote_mac) |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 464 | self.assertEqual(inner[Ether].dst, self.pg2.local_mac) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 465 | self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6) |
| 466 | self.assertEqual(inner[IPv6].dst, "fd01:3::3") |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 467 | self.assert_tcp_checksum_valid(inner) |
| 468 | payload_len = inner[IPv6].plen - 20 |
| 469 | self.assertEqual(payload_len, len(inner[Raw])) |
| 470 | size += payload_len |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 471 | self.assertEqual(size, 65200 * 5) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 472 | |
| 473 | # |
| 474 | # disable ipv4/vxlan |
| 475 | # |
| 476 | self.vxlan.remove_vpp_config() |
| 477 | |
| 478 | # |
| 479 | # enable ipv6/vxlan |
| 480 | # |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 481 | self.vxlan2.add_vpp_config() |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 482 | self.vapi.sw_interface_set_l2_bridge( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 483 | rx_sw_if_index=self.vxlan2.sw_if_index, bd_id=self.single_tunnel_bd |
| 484 | ) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 485 | |
| 486 | # |
| 487 | # IPv6/IPv4 - VXLAN |
| 488 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 489 | p46 = ( |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 490 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 491 | / IP(src=self.pg2.remote_ip4, dst="172.16.3.3", flags="DF") |
| 492 | / TCP(sport=1234, dport=1234) |
| 493 | / Raw(b"\xa5" * 65200) |
| 494 | ) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 495 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 496 | rxs = self.send_and_expect(self.pg2, 5 * [p46], self.pg0, 225) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 497 | size = 0 |
| 498 | for rx in rxs: |
| 499 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 500 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 501 | self.assertEqual(rx[IPv6].src, self.pg0.local_ip6) |
| 502 | self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6) |
Vladimir Isaev | 698eb87 | 2020-05-21 16:34:17 +0300 | [diff] [blame] | 503 | self.assert_udp_checksum_valid(rx, ignore_zero_checksum=False) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 504 | self.assertEqual(rx[VXLAN].vni, 10) |
| 505 | inner = rx[VXLAN].payload |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 506 | self.assertEqual(rx[IPv6].plen - 8 - 8, len(inner)) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 507 | self.assertEqual(inner[Ether].src, self.pg2.remote_mac) |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 508 | self.assertEqual(inner[Ether].dst, self.pg2.local_mac) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 509 | self.assertEqual(inner[IP].src, self.pg2.remote_ip4) |
| 510 | self.assertEqual(inner[IP].dst, "172.16.3.3") |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 511 | self.assert_ip_checksum_valid(inner) |
| 512 | self.assert_tcp_checksum_valid(inner) |
| 513 | payload_len = inner[IP].len - 20 - 20 |
| 514 | self.assertEqual(payload_len, len(inner[Raw])) |
| 515 | size += payload_len |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 516 | self.assertEqual(size, 65200 * 5) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 517 | |
| 518 | # |
| 519 | # IPv6/IPv6 - VXLAN |
| 520 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 521 | p66 = ( |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 522 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 523 | / IPv6(src=self.pg2.remote_ip6, dst="fd01:3::3") |
| 524 | / TCP(sport=1234, dport=1234) |
| 525 | / Raw(b"\xa5" * 65200) |
| 526 | ) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 527 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 528 | rxs = self.send_and_expect(self.pg2, 5 * [p66], self.pg0, 225) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 529 | size = 0 |
| 530 | for rx in rxs: |
| 531 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 532 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 533 | self.assertEqual(rx[IPv6].src, self.pg0.local_ip6) |
| 534 | self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6) |
Vladimir Isaev | 698eb87 | 2020-05-21 16:34:17 +0300 | [diff] [blame] | 535 | self.assert_udp_checksum_valid(rx, ignore_zero_checksum=False) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 536 | self.assertEqual(rx[VXLAN].vni, 10) |
| 537 | inner = rx[VXLAN].payload |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 538 | self.assertEqual(rx[IPv6].plen - 8 - 8, len(inner)) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 539 | self.assertEqual(inner[Ether].src, self.pg2.remote_mac) |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 540 | self.assertEqual(inner[Ether].dst, self.pg2.local_mac) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 541 | self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6) |
| 542 | self.assertEqual(inner[IPv6].dst, "fd01:3::3") |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 543 | self.assert_tcp_checksum_valid(inner) |
| 544 | payload_len = inner[IPv6].plen - 20 |
| 545 | self.assertEqual(payload_len, len(inner[Raw])) |
| 546 | size += payload_len |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 547 | self.assertEqual(size, 65200 * 5) |
Mohsin Kazmi | 0b04209 | 2020-04-17 16:50:56 +0000 | [diff] [blame] | 548 | |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 549 | # |
| 550 | # disable ipv4/vxlan |
| 551 | # |
| 552 | self.vxlan2.remove_vpp_config() |
| 553 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 554 | self.vapi.feature_gso_enable_disable( |
| 555 | sw_if_index=self.pg0.sw_if_index, enable_disable=0 |
| 556 | ) |
Mohsin Kazmi | 1ab8b3c | 2020-05-05 10:31:17 +0000 | [diff] [blame] | 557 | |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 558 | def test_gso_ipip(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 559 | """GSO IPIP test""" |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 560 | self.logger.info(self.vapi.cli("sh int addr")) |
| 561 | # |
| 562 | # Send jumbo frame with gso enabled only on input interface and |
| 563 | # create IPIP tunnel on VPP pg0. |
| 564 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 565 | self.vapi.feature_gso_enable_disable( |
| 566 | sw_if_index=self.pg0.sw_if_index, enable_disable=1 |
| 567 | ) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 568 | |
| 569 | # |
| 570 | # enable ipip4 |
| 571 | # |
| 572 | self.ipip4.add_vpp_config() |
| 573 | |
| 574 | # Set interface up and enable IP on it |
| 575 | self.ipip4.admin_up() |
| 576 | self.ipip4.set_unnumbered(self.pg0.sw_if_index) |
| 577 | |
| 578 | # Add IPv4 routes via tunnel interface |
| 579 | self.ip4_via_ip4_tunnel = VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 580 | self, |
| 581 | "172.16.10.0", |
| 582 | 24, |
| 583 | [ |
| 584 | VppRoutePath( |
| 585 | "0.0.0.0", |
| 586 | self.ipip4.sw_if_index, |
| 587 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP4, |
| 588 | ) |
| 589 | ], |
| 590 | ) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 591 | self.ip4_via_ip4_tunnel.add_vpp_config() |
| 592 | |
| 593 | # |
| 594 | # IPv4/IPv4 - IPIP |
| 595 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 596 | p47 = ( |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 597 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 598 | / IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags="DF") |
| 599 | / TCP(sport=1234, dport=1234) |
| 600 | / Raw(b"\xa5" * 65200) |
| 601 | ) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 602 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 603 | rxs = self.send_and_expect(self.pg2, 5 * [p47], self.pg0, 225) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 604 | size = 0 |
| 605 | for rx in rxs: |
| 606 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 607 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 608 | self.assertEqual(rx[IP].src, self.pg0.local_ip4) |
| 609 | self.assertEqual(rx[IP].dst, self.pg0.remote_ip4) |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 610 | self.assert_ip_checksum_valid(rx) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 611 | self.assertEqual(rx[IP].proto, 4) # ipencap |
| 612 | inner = rx[IP].payload |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 613 | self.assertEqual(rx[IP].len - 20, len(inner)) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 614 | self.assertEqual(inner[IP].src, self.pg2.remote_ip4) |
| 615 | self.assertEqual(inner[IP].dst, "172.16.10.3") |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 616 | self.assert_ip_checksum_valid(inner) |
| 617 | self.assert_tcp_checksum_valid(inner) |
| 618 | payload_len = inner[IP].len - 20 - 20 |
| 619 | self.assertEqual(payload_len, len(inner[Raw])) |
| 620 | size += payload_len |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 621 | self.assertEqual(size, 65200 * 5) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 622 | |
| 623 | self.ip6_via_ip4_tunnel = VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 624 | self, |
| 625 | "fd01:10::", |
| 626 | 64, |
| 627 | [ |
| 628 | VppRoutePath( |
| 629 | "::", |
| 630 | self.ipip4.sw_if_index, |
| 631 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6, |
| 632 | ) |
| 633 | ], |
| 634 | ) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 635 | self.ip6_via_ip4_tunnel.add_vpp_config() |
| 636 | # |
| 637 | # IPv4/IPv6 - IPIP |
| 638 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 639 | p67 = ( |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 640 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 641 | / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3") |
| 642 | / TCP(sport=1234, dport=1234) |
| 643 | / Raw(b"\xa5" * 65200) |
| 644 | ) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 645 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 646 | rxs = self.send_and_expect(self.pg2, 5 * [p67], self.pg0, 225) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 647 | size = 0 |
| 648 | for rx in rxs: |
| 649 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 650 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 651 | self.assertEqual(rx[IP].src, self.pg0.local_ip4) |
| 652 | self.assertEqual(rx[IP].dst, self.pg0.remote_ip4) |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 653 | self.assert_ip_checksum_valid(rx) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 654 | self.assertEqual(rx[IP].proto, 41) # ipv6 |
| 655 | inner = rx[IP].payload |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 656 | self.assertEqual(rx[IP].len - 20, len(inner)) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 657 | self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6) |
| 658 | self.assertEqual(inner[IPv6].dst, "fd01:10::3") |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 659 | self.assert_tcp_checksum_valid(inner) |
| 660 | payload_len = inner[IPv6].plen - 20 |
| 661 | self.assertEqual(payload_len, len(inner[Raw])) |
| 662 | size += payload_len |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 663 | self.assertEqual(size, 65200 * 5) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 664 | |
| 665 | # |
| 666 | # Send jumbo frame with gso enabled only on input interface and |
| 667 | # create IPIP tunnel on VPP pg0. Enable gso feature node on ipip |
| 668 | # tunnel - IPSec use case |
| 669 | # |
Ole Troan | 5c2a237 | 2020-11-19 16:01:23 +0100 | [diff] [blame] | 670 | self.vapi.feature_gso_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 671 | sw_if_index=self.pg0.sw_if_index, enable_disable=0 |
| 672 | ) |
| 673 | self.vapi.feature_gso_enable_disable( |
| 674 | sw_if_index=self.ipip4.sw_if_index, enable_disable=1 |
| 675 | ) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 676 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 677 | rxs = self.send_and_expect(self.pg2, 5 * [p47], self.pg0, 225) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 678 | size = 0 |
| 679 | for rx in rxs: |
| 680 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 681 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 682 | self.assertEqual(rx[IP].src, self.pg0.local_ip4) |
| 683 | self.assertEqual(rx[IP].dst, self.pg0.remote_ip4) |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 684 | self.assert_ip_checksum_valid(rx) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 685 | self.assertEqual(rx[IP].proto, 4) # ipencap |
| 686 | inner = rx[IP].payload |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 687 | self.assertEqual(rx[IP].len - 20, len(inner)) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 688 | self.assertEqual(inner[IP].src, self.pg2.remote_ip4) |
| 689 | self.assertEqual(inner[IP].dst, "172.16.10.3") |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 690 | self.assert_ip_checksum_valid(inner) |
| 691 | self.assert_tcp_checksum_valid(inner) |
| 692 | payload_len = inner[IP].len - 20 - 20 |
| 693 | self.assertEqual(payload_len, len(inner[Raw])) |
| 694 | size += payload_len |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 695 | self.assertEqual(size, 65200 * 5) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 696 | |
| 697 | # |
| 698 | # disable ipip4 |
| 699 | # |
Ole Troan | 5c2a237 | 2020-11-19 16:01:23 +0100 | [diff] [blame] | 700 | self.vapi.feature_gso_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 701 | sw_if_index=self.ipip4.sw_if_index, enable_disable=0 |
| 702 | ) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 703 | self.ip4_via_ip4_tunnel.remove_vpp_config() |
| 704 | self.ip6_via_ip4_tunnel.remove_vpp_config() |
| 705 | self.ipip4.remove_vpp_config() |
| 706 | |
| 707 | # |
| 708 | # enable ipip6 |
| 709 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 710 | self.vapi.feature_gso_enable_disable( |
| 711 | sw_if_index=self.pg0.sw_if_index, enable_disable=1 |
| 712 | ) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 713 | self.ipip6.add_vpp_config() |
| 714 | |
| 715 | # Set interface up and enable IP on it |
| 716 | self.ipip6.admin_up() |
| 717 | self.ipip6.set_unnumbered(self.pg0.sw_if_index) |
| 718 | |
| 719 | # Add IPv4 routes via tunnel interface |
| 720 | self.ip4_via_ip6_tunnel = VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 721 | self, |
| 722 | "172.16.10.0", |
| 723 | 24, |
| 724 | [ |
| 725 | VppRoutePath( |
| 726 | "0.0.0.0", |
| 727 | self.ipip6.sw_if_index, |
| 728 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP4, |
| 729 | ) |
| 730 | ], |
| 731 | ) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 732 | self.ip4_via_ip6_tunnel.add_vpp_config() |
| 733 | |
| 734 | # |
| 735 | # IPv6/IPv4 - IPIP |
| 736 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 737 | p48 = ( |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 738 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 739 | / IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags="DF") |
| 740 | / TCP(sport=1234, dport=1234) |
| 741 | / Raw(b"\xa5" * 65200) |
| 742 | ) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 743 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 744 | rxs = self.send_and_expect(self.pg2, 5 * [p48], self.pg0, 225) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 745 | size = 0 |
| 746 | for rx in rxs: |
| 747 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 748 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 749 | self.assertEqual(rx[IPv6].src, self.pg0.local_ip6) |
| 750 | self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6) |
| 751 | self.assertEqual(ipv6nh[rx[IPv6].nh], "IP") |
| 752 | inner = rx[IPv6].payload |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 753 | self.assertEqual(rx[IPv6].plen, len(inner)) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 754 | self.assertEqual(inner[IP].src, self.pg2.remote_ip4) |
| 755 | self.assertEqual(inner[IP].dst, "172.16.10.3") |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 756 | self.assert_ip_checksum_valid(inner) |
| 757 | self.assert_tcp_checksum_valid(inner) |
| 758 | payload_len = inner[IP].len - 20 - 20 |
| 759 | self.assertEqual(payload_len, len(inner[Raw])) |
| 760 | size += payload_len |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 761 | self.assertEqual(size, 65200 * 5) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 762 | |
| 763 | self.ip6_via_ip6_tunnel = VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 764 | self, |
| 765 | "fd01:10::", |
| 766 | 64, |
| 767 | [ |
| 768 | VppRoutePath( |
| 769 | "::", |
| 770 | self.ipip6.sw_if_index, |
| 771 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6, |
| 772 | ) |
| 773 | ], |
| 774 | ) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 775 | self.ip6_via_ip6_tunnel.add_vpp_config() |
| 776 | |
| 777 | # |
| 778 | # IPv6/IPv6 - IPIP |
| 779 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 780 | p68 = ( |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 781 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 782 | / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3") |
| 783 | / TCP(sport=1234, dport=1234) |
| 784 | / Raw(b"\xa5" * 65200) |
| 785 | ) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 786 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 787 | rxs = self.send_and_expect(self.pg2, 5 * [p68], self.pg0, 225) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 788 | size = 0 |
| 789 | for rx in rxs: |
| 790 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 791 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 792 | self.assertEqual(rx[IPv6].src, self.pg0.local_ip6) |
| 793 | self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6) |
| 794 | self.assertEqual(ipv6nh[rx[IPv6].nh], "IPv6") |
| 795 | inner = rx[IPv6].payload |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 796 | self.assertEqual(rx[IPv6].plen, len(inner)) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 797 | self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6) |
| 798 | self.assertEqual(inner[IPv6].dst, "fd01:10::3") |
Mohsin Kazmi | adf6209 | 2020-05-28 20:49:46 +0200 | [diff] [blame] | 799 | self.assert_tcp_checksum_valid(inner) |
| 800 | payload_len = inner[IPv6].plen - 20 |
| 801 | self.assertEqual(payload_len, len(inner[Raw])) |
| 802 | size += payload_len |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 803 | self.assertEqual(size, 65200 * 5) |
Mohsin Kazmi | 84f91fa | 2020-04-23 17:59:49 +0200 | [diff] [blame] | 804 | |
| 805 | # |
| 806 | # disable ipip6 |
| 807 | # |
| 808 | self.ip4_via_ip6_tunnel.remove_vpp_config() |
| 809 | self.ip6_via_ip6_tunnel.remove_vpp_config() |
| 810 | self.ipip6.remove_vpp_config() |
| 811 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 812 | self.vapi.feature_gso_enable_disable( |
| 813 | sw_if_index=self.pg0.sw_if_index, enable_disable=0 |
| 814 | ) |
Mohsin Kazmi | 1ab8b3c | 2020-05-05 10:31:17 +0000 | [diff] [blame] | 815 | |
Arthur de Kerhor | 2f4586d | 2021-09-22 14:53:24 +0200 | [diff] [blame] | 816 | def test_gso_gre(self): |
| 817 | """GSO GRE test""" |
| 818 | # |
| 819 | # Send jumbo frame with gso enabled only on gre tunnel interface. |
| 820 | # create GRE tunnel on VPP pg0. |
| 821 | # |
| 822 | |
| 823 | # |
| 824 | # create gre 4 tunnel |
| 825 | # |
| 826 | self.gre4.add_vpp_config() |
| 827 | self.gre4.admin_up() |
| 828 | self.gre4.config_ip4() |
| 829 | |
| 830 | # |
| 831 | # Add a route that resolves the tunnel's destination |
| 832 | # |
| 833 | # Add IPv4 routes via tunnel interface |
| 834 | self.ip4_via_gre4_tunnel = VppIpRoute( |
| 835 | self, |
| 836 | "172.16.10.0", |
| 837 | 24, |
| 838 | [ |
| 839 | VppRoutePath( |
| 840 | "0.0.0.0", |
| 841 | self.gre4.sw_if_index, |
| 842 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP4, |
| 843 | ) |
| 844 | ], |
| 845 | ) |
| 846 | self.ip4_via_gre4_tunnel.add_vpp_config() |
| 847 | |
| 848 | pgre4 = ( |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 849 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
Arthur de Kerhor | 2f4586d | 2021-09-22 14:53:24 +0200 | [diff] [blame] | 850 | / IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags="DF") |
| 851 | / TCP(sport=1234, dport=1234) |
| 852 | / Raw(b"\xa5" * 65200) |
| 853 | ) |
| 854 | |
| 855 | # test when GSO segmentation is disabled, Packets are truncated |
| 856 | rxs = self.send_and_expect(self.pg2, 5 * [pgre4], self.pg0, 5) |
| 857 | for rx in rxs: |
| 858 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 859 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 860 | self.assertEqual(rx[IP].src, self.pg0.local_ip4) |
| 861 | self.assertEqual(rx[IP].dst, self.pg0.remote_ip4) |
| 862 | self.assert_ip_checksum_valid(rx) |
| 863 | self.assertEqual(rx[IP].proto, 0x2F) # GRE encap |
| 864 | self.assertEqual(rx[GRE].proto, 0x0800) # IPv4 |
| 865 | inner = rx[GRE].payload |
| 866 | self.assertNotEqual(rx[IP].len - 20 - 4, len(inner)) |
| 867 | self.assertEqual(inner[IP].src, self.pg2.remote_ip4) |
| 868 | self.assertEqual(inner[IP].dst, "172.16.10.3") |
| 869 | self.assert_ip_checksum_valid(inner) |
| 870 | payload_len = inner[IP].len - 20 - 20 |
| 871 | self.assertEqual(payload_len, 65200) |
| 872 | # truncated packet to MTU size |
| 873 | self.assertNotEqual(payload_len, len(inner[Raw])) |
| 874 | |
| 875 | # enable the GSO segmentation on GRE tunnel |
| 876 | self.vapi.feature_gso_enable_disable( |
| 877 | sw_if_index=self.gre4.sw_if_index, enable_disable=1 |
| 878 | ) |
| 879 | |
| 880 | # test again, this time payload will be chuncked to GSO size (i.e. 1448) |
| 881 | rxs = self.send_and_expect(self.pg2, 5 * [pgre4], self.pg0, 225) |
| 882 | size = 0 |
| 883 | for rx in rxs: |
| 884 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 885 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 886 | self.assertEqual(rx[IP].src, self.pg0.local_ip4) |
| 887 | self.assertEqual(rx[IP].dst, self.pg0.remote_ip4) |
| 888 | self.assert_ip_checksum_valid(rx) |
| 889 | self.assertEqual(rx[IP].proto, 0x2F) # GRE encap |
| 890 | self.assertEqual(rx[GRE].proto, 0x0800) # IPv4 |
| 891 | inner = rx[GRE].payload |
| 892 | self.assertEqual(rx[IP].len - 20 - 4, len(inner)) |
| 893 | self.assertEqual(inner[IP].src, self.pg2.remote_ip4) |
| 894 | self.assertEqual(inner[IP].dst, "172.16.10.3") |
| 895 | self.assert_ip_checksum_valid(inner) |
| 896 | self.assert_tcp_checksum_valid(inner) |
| 897 | payload_len = inner[IP].len - 20 - 20 |
| 898 | self.assertEqual(payload_len, len(inner[Raw])) |
| 899 | size += payload_len |
| 900 | self.assertEqual(size, 65200 * 5) |
| 901 | |
| 902 | # Disable the GSO segmentation on GRE tunnel |
| 903 | self.vapi.feature_gso_enable_disable( |
| 904 | sw_if_index=self.gre4.sw_if_index, enable_disable=0 |
| 905 | ) |
| 906 | |
| 907 | # test again when GSO segmentation is disabled, Packets are truncated |
| 908 | rxs = self.send_and_expect(self.pg2, 5 * [pgre4], self.pg0, 5) |
| 909 | for rx in rxs: |
| 910 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 911 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 912 | self.assertEqual(rx[IP].src, self.pg0.local_ip4) |
| 913 | self.assertEqual(rx[IP].dst, self.pg0.remote_ip4) |
| 914 | self.assert_ip_checksum_valid(rx) |
| 915 | self.assertEqual(rx[IP].proto, 0x2F) # GRE encap |
| 916 | self.assertEqual(rx[GRE].proto, 0x0800) # IPv4 |
| 917 | inner = rx[GRE].payload |
| 918 | self.assertNotEqual(rx[IP].len - 20 - 4, len(inner)) |
| 919 | self.assertEqual(inner[IP].src, self.pg2.remote_ip4) |
| 920 | self.assertEqual(inner[IP].dst, "172.16.10.3") |
| 921 | self.assert_ip_checksum_valid(inner) |
| 922 | payload_len = inner[IP].len - 20 - 20 |
| 923 | self.assertEqual(payload_len, 65200) |
| 924 | # truncated packet to MTU size |
| 925 | self.assertNotEqual(payload_len, len(inner[Raw])) |
| 926 | |
| 927 | self.ip4_via_gre4_tunnel.remove_vpp_config() |
| 928 | self.gre4.remove_vpp_config() |
| 929 | |
| 930 | self.gre6.add_vpp_config() |
| 931 | self.gre6.admin_up() |
| 932 | self.gre6.config_ip4() |
| 933 | |
| 934 | # |
| 935 | # Add a route that resolves the tunnel's destination |
| 936 | # Add IPv6 routes via tunnel interface |
| 937 | # |
| 938 | self.vapi.feature_gso_enable_disable( |
| 939 | sw_if_index=self.gre6.sw_if_index, enable_disable=1 |
| 940 | ) |
| 941 | self.ip6_via_gre6_tunnel = VppIpRoute( |
| 942 | self, |
| 943 | "fd01:10::", |
| 944 | 64, |
| 945 | [ |
| 946 | VppRoutePath( |
| 947 | "::", |
| 948 | self.gre6.sw_if_index, |
| 949 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6, |
| 950 | ) |
| 951 | ], |
| 952 | ) |
| 953 | self.ip6_via_gre6_tunnel.add_vpp_config() |
| 954 | |
| 955 | # |
| 956 | # Create IPv6 packet |
| 957 | # |
| 958 | pgre6 = ( |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 959 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
Arthur de Kerhor | 2f4586d | 2021-09-22 14:53:24 +0200 | [diff] [blame] | 960 | / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3") |
| 961 | / TCP(sport=1234, dport=1234) |
| 962 | / Raw(b"\xa5" * 65200) |
| 963 | ) |
| 964 | |
| 965 | # test when GSO segmentation is enabled, payload will be segmented |
| 966 | # into GSO size (i.e. 1448) |
| 967 | rxs = self.send_and_expect(self.pg2, 5 * [pgre6], self.pg0, 225) |
| 968 | size = 0 |
| 969 | for rx in rxs: |
| 970 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 971 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 972 | self.assertEqual(rx[IPv6].src, self.pg0.local_ip6) |
| 973 | self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6) |
| 974 | self.assertEqual(ipv6nh[rx[IPv6].nh], "GRE") |
| 975 | self.assertEqual(rx[GRE].proto, 0x86DD) # IPv6 |
| 976 | inner = rx[GRE].payload |
| 977 | self.assertEqual(rx[IPv6].plen - 4, len(inner)) |
| 978 | self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6) |
| 979 | self.assertEqual(inner[IPv6].dst, "fd01:10::3") |
| 980 | self.assert_tcp_checksum_valid(inner) |
| 981 | payload_len = inner[IPv6].plen - 20 |
| 982 | self.assertEqual(payload_len, len(inner[Raw])) |
| 983 | size += payload_len |
| 984 | self.assertEqual(size, 65200 * 5) |
| 985 | |
| 986 | # disable GSO segmentation |
| 987 | self.vapi.feature_gso_enable_disable( |
| 988 | sw_if_index=self.gre6.sw_if_index, enable_disable=0 |
| 989 | ) |
| 990 | |
| 991 | # test again, this time packets will be truncated |
| 992 | rxs = self.send_and_expect(self.pg2, 5 * [pgre6], self.pg0, 5) |
| 993 | for rx in rxs: |
| 994 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 995 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 996 | self.assertEqual(rx[IPv6].src, self.pg0.local_ip6) |
| 997 | self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6) |
| 998 | self.assertEqual(ipv6nh[rx[IPv6].nh], "GRE") |
| 999 | self.assertEqual(rx[GRE].proto, 0x86DD) # IPv6 |
| 1000 | inner = rx[GRE].payload |
| 1001 | self.assertNotEqual(rx[IPv6].plen - 4, len(inner)) |
| 1002 | self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6) |
| 1003 | self.assertEqual(inner[IPv6].dst, "fd01:10::3") |
| 1004 | payload_len = inner[IPv6].plen - 20 |
| 1005 | self.assertEqual(payload_len, 65200) |
| 1006 | # packets are truncated to MTU size |
| 1007 | self.assertNotEqual(payload_len, len(inner[Raw])) |
| 1008 | |
| 1009 | self.ip6_via_gre6_tunnel.remove_vpp_config() |
| 1010 | self.gre6.remove_vpp_config() |
| 1011 | |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1012 | def test_gso_ipsec(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1013 | """GSO IPSEC test""" |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1014 | # |
| 1015 | # Send jumbo frame with gso enabled only on input interface and |
| 1016 | # create IPIP tunnel on VPP pg0. |
| 1017 | # |
| 1018 | |
| 1019 | # |
| 1020 | # enable ipip4 |
| 1021 | # |
| 1022 | self.ipip4.add_vpp_config() |
| 1023 | self.vapi.feature_gso_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1024 | sw_if_index=self.ipip4.sw_if_index, enable_disable=1 |
| 1025 | ) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1026 | |
| 1027 | # Add IPv4 routes via tunnel interface |
| 1028 | self.ip4_via_ip4_tunnel = VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1029 | self, |
| 1030 | "172.16.10.0", |
| 1031 | 24, |
| 1032 | [ |
| 1033 | VppRoutePath( |
| 1034 | "0.0.0.0", |
| 1035 | self.ipip4.sw_if_index, |
| 1036 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP4, |
| 1037 | ) |
| 1038 | ], |
| 1039 | ) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1040 | self.ip4_via_ip4_tunnel.add_vpp_config() |
| 1041 | |
| 1042 | # IPSec config |
| 1043 | self.ipv4_params = IPsecIPv4Params() |
| 1044 | self.encryption_type = ESP |
| 1045 | config_tun_params(self.ipv4_params, self.encryption_type, self.ipip4) |
| 1046 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1047 | self.tun_sa_in_v4 = VppIpsecSA( |
| 1048 | self, |
Arthur de Kerhor | 0df06b6 | 2022-11-16 18:45:24 +0100 | [diff] [blame] | 1049 | self.ipv4_params.scapy_tun_sa_id, |
| 1050 | self.ipv4_params.scapy_tun_spi, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1051 | self.ipv4_params.auth_algo_vpp_id, |
| 1052 | self.ipv4_params.auth_key, |
| 1053 | self.ipv4_params.crypt_algo_vpp_id, |
| 1054 | self.ipv4_params.crypt_key, |
| 1055 | VppEnum.vl_api_ipsec_proto_t.IPSEC_API_PROTO_ESP, |
| 1056 | ) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1057 | self.tun_sa_in_v4.add_vpp_config() |
| 1058 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1059 | self.tun_sa_out_v4 = VppIpsecSA( |
| 1060 | self, |
Arthur de Kerhor | 0df06b6 | 2022-11-16 18:45:24 +0100 | [diff] [blame] | 1061 | self.ipv4_params.vpp_tun_sa_id, |
| 1062 | self.ipv4_params.vpp_tun_spi, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1063 | self.ipv4_params.auth_algo_vpp_id, |
| 1064 | self.ipv4_params.auth_key, |
| 1065 | self.ipv4_params.crypt_algo_vpp_id, |
| 1066 | self.ipv4_params.crypt_key, |
| 1067 | VppEnum.vl_api_ipsec_proto_t.IPSEC_API_PROTO_ESP, |
| 1068 | ) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1069 | self.tun_sa_out_v4.add_vpp_config() |
| 1070 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1071 | self.tun_protect_v4 = VppIpsecTunProtect( |
| 1072 | self, self.ipip4, self.tun_sa_out_v4, [self.tun_sa_in_v4] |
| 1073 | ) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1074 | |
| 1075 | self.tun_protect_v4.add_vpp_config() |
| 1076 | |
| 1077 | # Set interface up and enable IP on it |
| 1078 | self.ipip4.admin_up() |
| 1079 | self.ipip4.set_unnumbered(self.pg0.sw_if_index) |
| 1080 | |
| 1081 | # |
| 1082 | # IPv4/IPv4 - IPSEC |
| 1083 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1084 | ipsec44 = ( |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 1085 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1086 | / IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags="DF") |
| 1087 | / TCP(sport=1234, dport=1234) |
| 1088 | / Raw(b"\xa5" * 65200) |
| 1089 | ) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1090 | |
| 1091 | rxs = self.send_and_expect(self.pg2, [ipsec44], self.pg0, 45) |
| 1092 | size = 0 |
| 1093 | for rx in rxs: |
| 1094 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 1095 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 1096 | self.assertEqual(rx[IP].src, self.pg0.local_ip4) |
| 1097 | self.assertEqual(rx[IP].dst, self.pg0.remote_ip4) |
| 1098 | self.assertEqual(rx[IP].proto, 50) # ESP |
Arthur de Kerhor | 0df06b6 | 2022-11-16 18:45:24 +0100 | [diff] [blame] | 1099 | self.assertEqual(rx[ESP].spi, self.ipv4_params.vpp_tun_spi) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1100 | inner = self.ipv4_params.vpp_tun_sa.decrypt(rx[IP]) |
| 1101 | self.assertEqual(inner[IP].src, self.pg2.remote_ip4) |
| 1102 | self.assertEqual(inner[IP].dst, "172.16.10.3") |
| 1103 | size += inner[IP].len - 20 - 20 |
| 1104 | self.assertEqual(size, 65200) |
| 1105 | |
| 1106 | self.ip6_via_ip4_tunnel = VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1107 | self, |
| 1108 | "fd01:10::", |
| 1109 | 64, |
| 1110 | [ |
| 1111 | VppRoutePath( |
| 1112 | "::", |
| 1113 | self.ipip4.sw_if_index, |
| 1114 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6, |
| 1115 | ) |
| 1116 | ], |
| 1117 | ) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1118 | self.ip6_via_ip4_tunnel.add_vpp_config() |
| 1119 | # |
| 1120 | # IPv4/IPv6 - IPSEC |
| 1121 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1122 | ipsec46 = ( |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 1123 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1124 | / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3") |
| 1125 | / TCP(sport=1234, dport=1234) |
| 1126 | / Raw(b"\xa5" * 65200) |
| 1127 | ) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1128 | |
| 1129 | rxs = self.send_and_expect(self.pg2, [ipsec46], self.pg0, 45) |
| 1130 | size = 0 |
| 1131 | for rx in rxs: |
| 1132 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 1133 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 1134 | self.assertEqual(rx[IP].src, self.pg0.local_ip4) |
| 1135 | self.assertEqual(rx[IP].dst, self.pg0.remote_ip4) |
| 1136 | self.assertEqual(rx[IP].proto, 50) # ESP |
Arthur de Kerhor | 0df06b6 | 2022-11-16 18:45:24 +0100 | [diff] [blame] | 1137 | self.assertEqual(rx[ESP].spi, self.ipv4_params.vpp_tun_spi) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1138 | inner = self.ipv4_params.vpp_tun_sa.decrypt(rx[IP]) |
| 1139 | self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6) |
| 1140 | self.assertEqual(inner[IPv6].dst, "fd01:10::3") |
| 1141 | size += inner[IPv6].plen - 20 |
| 1142 | self.assertEqual(size, 65200) |
| 1143 | |
| 1144 | # disable IPSec |
| 1145 | self.tun_protect_v4.remove_vpp_config() |
| 1146 | self.tun_sa_in_v4.remove_vpp_config() |
| 1147 | self.tun_sa_out_v4.remove_vpp_config() |
| 1148 | |
| 1149 | # |
| 1150 | # disable ipip4 |
| 1151 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1152 | self.vapi.feature_gso_enable_disable(self.ipip4.sw_if_index, enable_disable=0) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1153 | self.ip4_via_ip4_tunnel.remove_vpp_config() |
| 1154 | self.ip6_via_ip4_tunnel.remove_vpp_config() |
| 1155 | self.ipip4.remove_vpp_config() |
| 1156 | |
| 1157 | # |
| 1158 | # enable ipip6 |
| 1159 | # |
| 1160 | self.ipip6.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1161 | self.vapi.feature_gso_enable_disable(self.ipip6.sw_if_index, enable_disable=1) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1162 | |
| 1163 | # Set interface up and enable IP on it |
| 1164 | self.ipip6.admin_up() |
| 1165 | self.ipip6.set_unnumbered(self.pg0.sw_if_index) |
| 1166 | |
| 1167 | # Add IPv4 routes via tunnel interface |
| 1168 | self.ip4_via_ip6_tunnel = VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1169 | self, |
| 1170 | "172.16.10.0", |
| 1171 | 24, |
| 1172 | [ |
| 1173 | VppRoutePath( |
| 1174 | "0.0.0.0", |
| 1175 | self.ipip6.sw_if_index, |
| 1176 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP4, |
| 1177 | ) |
| 1178 | ], |
| 1179 | ) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1180 | self.ip4_via_ip6_tunnel.add_vpp_config() |
| 1181 | |
| 1182 | # IPSec config |
| 1183 | self.ipv6_params = IPsecIPv6Params() |
| 1184 | self.encryption_type = ESP |
| 1185 | config_tun_params(self.ipv6_params, self.encryption_type, self.ipip6) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1186 | self.tun_sa_in_v6 = VppIpsecSA( |
| 1187 | self, |
Arthur de Kerhor | 0df06b6 | 2022-11-16 18:45:24 +0100 | [diff] [blame] | 1188 | self.ipv6_params.scapy_tun_sa_id, |
| 1189 | self.ipv6_params.scapy_tun_spi, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1190 | self.ipv6_params.auth_algo_vpp_id, |
| 1191 | self.ipv6_params.auth_key, |
| 1192 | self.ipv6_params.crypt_algo_vpp_id, |
| 1193 | self.ipv6_params.crypt_key, |
| 1194 | VppEnum.vl_api_ipsec_proto_t.IPSEC_API_PROTO_ESP, |
| 1195 | ) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1196 | self.tun_sa_in_v6.add_vpp_config() |
| 1197 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1198 | self.tun_sa_out_v6 = VppIpsecSA( |
| 1199 | self, |
Arthur de Kerhor | 0df06b6 | 2022-11-16 18:45:24 +0100 | [diff] [blame] | 1200 | self.ipv6_params.vpp_tun_sa_id, |
| 1201 | self.ipv6_params.vpp_tun_spi, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1202 | self.ipv6_params.auth_algo_vpp_id, |
| 1203 | self.ipv6_params.auth_key, |
| 1204 | self.ipv6_params.crypt_algo_vpp_id, |
| 1205 | self.ipv6_params.crypt_key, |
| 1206 | VppEnum.vl_api_ipsec_proto_t.IPSEC_API_PROTO_ESP, |
| 1207 | ) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1208 | self.tun_sa_out_v6.add_vpp_config() |
| 1209 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1210 | self.tun_protect_v6 = VppIpsecTunProtect( |
| 1211 | self, self.ipip6, self.tun_sa_out_v6, [self.tun_sa_in_v6] |
| 1212 | ) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1213 | |
| 1214 | self.tun_protect_v6.add_vpp_config() |
| 1215 | |
| 1216 | # |
| 1217 | # IPv6/IPv4 - IPSEC |
| 1218 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1219 | ipsec64 = ( |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 1220 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1221 | / IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags="DF") |
| 1222 | / TCP(sport=1234, dport=1234) |
| 1223 | / Raw(b"\xa5" * 65200) |
| 1224 | ) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1225 | |
| 1226 | rxs = self.send_and_expect(self.pg2, [ipsec64], self.pg0, 45) |
| 1227 | size = 0 |
| 1228 | for rx in rxs: |
| 1229 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 1230 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 1231 | self.assertEqual(rx[IPv6].src, self.pg0.local_ip6) |
| 1232 | self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6) |
| 1233 | self.assertEqual(ipv6nh[rx[IPv6].nh], "ESP Header") |
Arthur de Kerhor | 0df06b6 | 2022-11-16 18:45:24 +0100 | [diff] [blame] | 1234 | self.assertEqual(rx[ESP].spi, self.ipv6_params.vpp_tun_spi) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1235 | inner = self.ipv6_params.vpp_tun_sa.decrypt(rx[IPv6]) |
| 1236 | self.assertEqual(inner[IP].src, self.pg2.remote_ip4) |
| 1237 | self.assertEqual(inner[IP].dst, "172.16.10.3") |
| 1238 | size += inner[IP].len - 20 - 20 |
| 1239 | self.assertEqual(size, 65200) |
| 1240 | |
| 1241 | self.ip6_via_ip6_tunnel = VppIpRoute( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1242 | self, |
| 1243 | "fd01:10::", |
| 1244 | 64, |
| 1245 | [ |
| 1246 | VppRoutePath( |
| 1247 | "::", |
| 1248 | self.ipip6.sw_if_index, |
| 1249 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6, |
| 1250 | ) |
| 1251 | ], |
| 1252 | ) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1253 | self.ip6_via_ip6_tunnel.add_vpp_config() |
| 1254 | |
| 1255 | # |
| 1256 | # IPv6/IPv6 - IPSEC |
| 1257 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1258 | ipsec66 = ( |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 1259 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1260 | / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3") |
| 1261 | / TCP(sport=1234, dport=1234) |
| 1262 | / Raw(b"\xa5" * 65200) |
| 1263 | ) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1264 | |
| 1265 | rxs = self.send_and_expect(self.pg2, [ipsec66], self.pg0, 45) |
| 1266 | size = 0 |
| 1267 | for rx in rxs: |
| 1268 | self.assertEqual(rx[Ether].src, self.pg0.local_mac) |
| 1269 | self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) |
| 1270 | self.assertEqual(rx[IPv6].src, self.pg0.local_ip6) |
| 1271 | self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6) |
| 1272 | self.assertEqual(ipv6nh[rx[IPv6].nh], "ESP Header") |
Arthur de Kerhor | 0df06b6 | 2022-11-16 18:45:24 +0100 | [diff] [blame] | 1273 | self.assertEqual(rx[ESP].spi, self.ipv6_params.vpp_tun_spi) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1274 | inner = self.ipv6_params.vpp_tun_sa.decrypt(rx[IPv6]) |
| 1275 | self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6) |
| 1276 | self.assertEqual(inner[IPv6].dst, "fd01:10::3") |
| 1277 | size += inner[IPv6].plen - 20 |
| 1278 | self.assertEqual(size, 65200) |
| 1279 | |
| 1280 | # disable IPSec |
| 1281 | self.tun_protect_v6.remove_vpp_config() |
| 1282 | self.tun_sa_in_v6.remove_vpp_config() |
| 1283 | self.tun_sa_out_v6.remove_vpp_config() |
| 1284 | |
| 1285 | # |
| 1286 | # disable ipip6 |
| 1287 | # |
| 1288 | self.ip4_via_ip6_tunnel.remove_vpp_config() |
| 1289 | self.ip6_via_ip6_tunnel.remove_vpp_config() |
| 1290 | self.ipip6.remove_vpp_config() |
| 1291 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1292 | self.vapi.feature_gso_enable_disable(self.pg0.sw_if_index, enable_disable=0) |
Mohsin Kazmi | 0972edc | 2021-07-09 14:19:37 +0200 | [diff] [blame] | 1293 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1294 | |
| 1295 | if __name__ == "__main__": |
Mohsin Kazmi | 22e9cfd | 2019-07-23 11:54:48 +0200 | [diff] [blame] | 1296 | unittest.main(testRunner=VppTestRunner) |