blob: 3d9ce5fb4eedafead95c3f47623f3010f1f1bdc2 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +02002"""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#
11import unittest
12
13from scapy.packet import Raw
Arthur de Kerhor2f4586d2021-09-22 14:53:24 +020014from scapy.layers.l2 import GRE
Dave Wallace8800f732023-08-31 00:47:44 -040015from scapy.layers.inet6 import IPv6, Ether, IP, ICMPv6PacketTooBig
Mohsin Kazmi0b042092020-04-17 16:50:56 +000016from scapy.layers.inet6 import ipv6nh, IPerror6
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020017from scapy.layers.inet import TCP, ICMP
18from scapy.layers.vxlan import VXLAN
Dave Wallace8800f732023-08-31 00:47:44 -040019from scapy.layers.ipsec import ESP
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020020
Mohsin Kazmi0972edc2021-07-09 14:19:37 +020021from vpp_papi import VppEnum
Dave Wallace8800f732023-08-31 00:47:44 -040022from framework import VppTestCase
23from asfframework import VppTestRunner
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020024from vpp_ip_route import VppIpRoute, VppRoutePath, FibPathProto
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +020025from vpp_ipip_tun_interface import VppIpIpTunInterface
Mohsin Kazmi0b042092020-04-17 16:50:56 +000026from vpp_vxlan_tunnel import VppVxlanTunnel
Arthur de Kerhor2f4586d2021-09-22 14:53:24 +020027from vpp_gre_interface import VppGreInterface
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020028
Mohsin Kazmi0972edc2021-07-09 14:19:37 +020029from vpp_ipsec import VppIpsecSA, VppIpsecTunProtect
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020030from template_ipsec import (
31 IPsecIPv4Params,
32 IPsecIPv6Params,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020033 config_tun_params,
34)
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020035
36""" Test_gso is a subclass of VPPTestCase classes.
37 GSO tests.
38"""
39
40
41class TestGSO(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020042 """GSO Test Case"""
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020043
44 def __init__(self, *args):
45 VppTestCase.__init__(self, *args)
46
47 @classmethod
48 def setUpClass(self):
49 super(TestGSO, self).setUpClass()
Mohsin Kazmi0b042092020-04-17 16:50:56 +000050 res = self.create_pg_interfaces(range(2))
51 res_gso = self.create_pg_interfaces(range(2, 4), 1, 1460)
52 self.create_pg_interfaces(range(4, 5), 1, 8940)
53 self.pg_interfaces.append(res[0])
54 self.pg_interfaces.append(res[1])
55 self.pg_interfaces.append(res_gso[0])
56 self.pg_interfaces.append(res_gso[1])
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020057
58 @classmethod
59 def tearDownClass(self):
60 super(TestGSO, self).tearDownClass()
61
62 def setUp(self):
63 super(TestGSO, self).setUp()
Mohsin Kazmi0b042092020-04-17 16:50:56 +000064 for i in self.pg_interfaces:
65 i.admin_up()
66 i.config_ip4()
67 i.config_ip6()
68 i.disable_ipv6_ra()
69 i.resolve_arp()
70 i.resolve_ndp()
71
72 self.single_tunnel_bd = 10
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020073 self.vxlan = VppVxlanTunnel(
74 self,
75 src=self.pg0.local_ip4,
76 dst=self.pg0.remote_ip4,
77 vni=self.single_tunnel_bd,
78 )
Mohsin Kazmi0b042092020-04-17 16:50:56 +000079
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020080 self.vxlan2 = VppVxlanTunnel(
81 self,
82 src=self.pg0.local_ip6,
83 dst=self.pg0.remote_ip6,
84 vni=self.single_tunnel_bd,
85 )
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +020086
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020087 self.ipip4 = VppIpIpTunInterface(
88 self, self.pg0, self.pg0.local_ip4, self.pg0.remote_ip4
89 )
90 self.ipip6 = VppIpIpTunInterface(
91 self, self.pg0, self.pg0.local_ip6, self.pg0.remote_ip6
92 )
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020093
Arthur de Kerhor2f4586d2021-09-22 14:53:24 +020094 self.gre4 = VppGreInterface(self, self.pg0.local_ip4, self.pg0.remote_ip4)
95 self.gre6 = VppGreInterface(self, self.pg0.local_ip6, self.pg0.remote_ip6)
96
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020097 def tearDown(self):
98 super(TestGSO, self).tearDown()
99 if not self.vpp_dead:
100 for i in self.pg_interfaces:
101 i.unconfig_ip4()
102 i.unconfig_ip6()
103 i.admin_down()
104
105 def test_gso(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200106 """GSO test"""
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200107 #
108 # Send jumbo frame with gso disabled and DF bit is set
109 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200110 p4 = (
111 Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
112 / IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4, flags="DF")
113 / TCP(sport=1234, dport=1234)
114 / Raw(b"\xa5" * 65200)
115 )
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200116
117 rxs = self.send_and_expect(self.pg0, [p4], self.pg0)
118
119 for rx in rxs:
120 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
121 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
122 self.assertEqual(rx[IP].src, self.pg0.local_ip4)
123 self.assertEqual(rx[IP].dst, self.pg0.remote_ip4)
124 self.assertEqual(rx[ICMP].type, 3) # "dest-unreach"
125 self.assertEqual(rx[ICMP].code, 4) # "fragmentation-needed"
126
127 #
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200128 # Send checksum offload frames
129 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200130 p40 = (
131 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
132 / IP(src=self.pg2.remote_ip4, dst=self.pg0.remote_ip4, flags="DF")
133 / TCP(sport=1234, dport=1234)
134 / Raw(b"\xa5" * 1460)
135 )
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200136
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200137 rxs = self.send_and_expect(self.pg2, 100 * [p40], self.pg0)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200138
139 for rx in rxs:
140 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
141 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
142 self.assertEqual(rx[IP].src, self.pg2.remote_ip4)
143 self.assertEqual(rx[IP].dst, self.pg0.remote_ip4)
144 payload_len = rx[IP].len - 20 - 20
145 self.assert_ip_checksum_valid(rx)
146 self.assert_tcp_checksum_valid(rx)
147 self.assertEqual(payload_len, len(rx[Raw]))
148
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200149 p60 = (
150 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
151 / IPv6(src=self.pg2.remote_ip6, dst=self.pg0.remote_ip6)
152 / TCP(sport=1234, dport=1234)
153 / Raw(b"\xa5" * 1440)
154 )
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200155
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200156 rxs = self.send_and_expect(self.pg2, 100 * [p60], self.pg0)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200157
158 for rx in rxs:
159 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
160 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
161 self.assertEqual(rx[IPv6].src, self.pg2.remote_ip6)
162 self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6)
163 payload_len = rx[IPv6].plen - 20
164 self.assert_tcp_checksum_valid(rx)
165 self.assertEqual(payload_len, len(rx[Raw]))
166
167 #
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200168 # Send jumbo frame with gso enabled and DF bit is set
169 # input and output interfaces support GSO
170 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200171 self.vapi.feature_gso_enable_disable(
172 sw_if_index=self.pg3.sw_if_index, enable_disable=1
173 )
174 p41 = (
175 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
176 / IP(src=self.pg2.remote_ip4, dst=self.pg3.remote_ip4, flags="DF")
177 / TCP(sport=1234, dport=1234)
178 / Raw(b"\xa5" * 65200)
179 )
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200180
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200181 rxs = self.send_and_expect(self.pg2, 100 * [p41], self.pg3, 100)
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200182
183 for rx in rxs:
184 self.assertEqual(rx[Ether].src, self.pg3.local_mac)
185 self.assertEqual(rx[Ether].dst, self.pg3.remote_mac)
186 self.assertEqual(rx[IP].src, self.pg2.remote_ip4)
187 self.assertEqual(rx[IP].dst, self.pg3.remote_ip4)
188 self.assertEqual(rx[IP].len, 65240) # 65200 + 20 (IP) + 20 (TCP)
189 self.assertEqual(rx[TCP].sport, 1234)
190 self.assertEqual(rx[TCP].dport, 1234)
191
192 #
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000193 # ipv6
194 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200195 p61 = (
196 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
197 / IPv6(src=self.pg2.remote_ip6, dst=self.pg3.remote_ip6)
198 / TCP(sport=1234, dport=1234)
199 / Raw(b"\xa5" * 65200)
200 )
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000201
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200202 rxs = self.send_and_expect(self.pg2, 100 * [p61], self.pg3, 100)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000203
204 for rx in rxs:
205 self.assertEqual(rx[Ether].src, self.pg3.local_mac)
206 self.assertEqual(rx[Ether].dst, self.pg3.remote_mac)
207 self.assertEqual(rx[IPv6].src, self.pg2.remote_ip6)
208 self.assertEqual(rx[IPv6].dst, self.pg3.remote_ip6)
209 self.assertEqual(rx[IPv6].plen, 65220) # 65200 + 20 (TCP)
210 self.assertEqual(rx[TCP].sport, 1234)
211 self.assertEqual(rx[TCP].dport, 1234)
212
213 #
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200214 # Send jumbo frame with gso enabled only on input interface
215 # and DF bit is set. GSO packet will be chunked into gso_size
216 # data payload
217 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200218 self.vapi.feature_gso_enable_disable(
219 sw_if_index=self.pg0.sw_if_index, enable_disable=1
220 )
221 p42 = (
222 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
223 / IP(src=self.pg2.remote_ip4, dst=self.pg0.remote_ip4, flags="DF")
224 / TCP(sport=1234, dport=1234)
225 / Raw(b"\xa5" * 65200)
226 )
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200227
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200228 rxs = self.send_and_expect(self.pg2, 5 * [p42], self.pg0, 225)
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200229 size = 0
230 for rx in rxs:
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000231 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
232 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200233 self.assertEqual(rx[IP].src, self.pg2.remote_ip4)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000234 self.assertEqual(rx[IP].dst, self.pg0.remote_ip4)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200235 payload_len = rx[IP].len - 20 - 20 # len - 20 (IP4) - 20 (TCP)
236 self.assert_ip_checksum_valid(rx)
237 self.assert_tcp_checksum_valid(rx)
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200238 self.assertEqual(rx[TCP].sport, 1234)
239 self.assertEqual(rx[TCP].dport, 1234)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200240 self.assertEqual(payload_len, len(rx[Raw]))
241 size += payload_len
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200242 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200243
244 #
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000245 # ipv6
246 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200247 p62 = (
248 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
249 / IPv6(src=self.pg2.remote_ip6, dst=self.pg0.remote_ip6)
250 / TCP(sport=1234, dport=1234)
251 / Raw(b"\xa5" * 65200)
252 )
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000253
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200254 rxs = self.send_and_expect(self.pg2, 5 * [p62], self.pg0, 225)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000255 size = 0
256 for rx in rxs:
257 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
258 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
259 self.assertEqual(rx[IPv6].src, self.pg2.remote_ip6)
260 self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200261 payload_len = rx[IPv6].plen - 20
262 self.assert_tcp_checksum_valid(rx)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000263 self.assertEqual(rx[TCP].sport, 1234)
264 self.assertEqual(rx[TCP].dport, 1234)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200265 self.assertEqual(payload_len, len(rx[Raw]))
266 size += payload_len
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200267 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000268
269 #
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200270 # Send jumbo frame with gso enabled only on input interface
271 # and DF bit is unset. GSO packet will be fragmented.
272 #
273 self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [576, 0, 0, 0])
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200274 self.vapi.feature_gso_enable_disable(
275 sw_if_index=self.pg1.sw_if_index, enable_disable=1
276 )
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200277
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200278 p43 = (
279 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
280 / IP(src=self.pg2.remote_ip4, dst=self.pg1.remote_ip4)
281 / TCP(sport=1234, dport=1234)
282 / Raw(b"\xa5" * 65200)
283 )
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200284
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200285 rxs = self.send_and_expect(self.pg2, 5 * [p43], self.pg1, 5 * 119)
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200286 size = 0
287 for rx in rxs:
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200288 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
289 self.assertEqual(rx[Ether].dst, self.pg1.remote_mac)
290 self.assertEqual(rx[IP].src, self.pg2.remote_ip4)
291 self.assertEqual(rx[IP].dst, self.pg1.remote_ip4)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200292 self.assert_ip_checksum_valid(rx)
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200293 size += rx[IP].len - 20
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200294 size -= 20 * 5 # TCP header
295 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200296
Mohsin Kazmi3f1964d2019-08-22 18:40:28 +0200297 #
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000298 # IPv6
299 # Send jumbo frame with gso enabled only on input interface.
300 # ICMPv6 Packet Too Big will be sent back to sender.
301 #
302 self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [1280, 0, 0, 0])
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200303 p63 = (
304 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
305 / IPv6(src=self.pg2.remote_ip6, dst=self.pg1.remote_ip6)
306 / TCP(sport=1234, dport=1234)
307 / Raw(b"\xa5" * 65200)
308 )
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000309
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200310 rxs = self.send_and_expect_some(self.pg2, 5 * [p63], self.pg2, 5)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000311 for rx in rxs:
312 self.assertEqual(rx[Ether].src, self.pg2.local_mac)
313 self.assertEqual(rx[Ether].dst, self.pg2.remote_mac)
314 self.assertEqual(rx[IPv6].src, self.pg2.local_ip6)
315 self.assertEqual(rx[IPv6].dst, self.pg2.remote_ip6)
316 self.assertEqual(rx[IPv6].plen, 1240) # MTU - IPv6 header
317 self.assertEqual(ipv6nh[rx[IPv6].nh], "ICMPv6")
318 self.assertEqual(rx[ICMPv6PacketTooBig].mtu, 1280)
319 self.assertEqual(rx[IPerror6].src, self.pg2.remote_ip6)
320 self.assertEqual(rx[IPerror6].dst, self.pg1.remote_ip6)
321 self.assertEqual(rx[IPerror6].plen - 20, 65200)
322
323 #
Mohsin Kazmi3f1964d2019-08-22 18:40:28 +0200324 # Send jumbo frame with gso enabled only on input interface with 9K MTU
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000325 # and DF bit is unset. GSO packet will be fragmented. MSS is 8960. GSO
326 # size will be min(MSS, 2048 - 14 - 20) vlib_buffer_t size
Mohsin Kazmi3f1964d2019-08-22 18:40:28 +0200327 #
328 self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [9000, 0, 0, 0])
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000329 self.vapi.sw_interface_set_mtu(self.pg4.sw_if_index, [9000, 0, 0, 0])
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200330 p44 = (
331 Ether(src=self.pg4.remote_mac, dst=self.pg4.local_mac)
332 / IP(src=self.pg4.remote_ip4, dst=self.pg1.remote_ip4)
333 / TCP(sport=1234, dport=1234)
334 / Raw(b"\xa5" * 65200)
335 )
Mohsin Kazmi3f1964d2019-08-22 18:40:28 +0200336
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200337 rxs = self.send_and_expect(self.pg4, 5 * [p44], self.pg1, 165)
Mohsin Kazmi3f1964d2019-08-22 18:40:28 +0200338 size = 0
339 for rx in rxs:
340 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
341 self.assertEqual(rx[Ether].dst, self.pg1.remote_mac)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000342 self.assertEqual(rx[IP].src, self.pg4.remote_ip4)
Mohsin Kazmi3f1964d2019-08-22 18:40:28 +0200343 self.assertEqual(rx[IP].dst, self.pg1.remote_ip4)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200344 payload_len = rx[IP].len - 20 - 20 # len - 20 (IP4) - 20 (TCP)
345 self.assert_ip_checksum_valid(rx)
346 self.assert_tcp_checksum_valid(rx)
347 self.assertEqual(payload_len, len(rx[Raw]))
348 size += payload_len
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200349 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi3f1964d2019-08-22 18:40:28 +0200350
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000351 #
352 # IPv6
353 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200354 p64 = (
355 Ether(src=self.pg4.remote_mac, dst=self.pg4.local_mac)
356 / IPv6(src=self.pg4.remote_ip6, dst=self.pg1.remote_ip6)
357 / TCP(sport=1234, dport=1234)
358 / Raw(b"\xa5" * 65200)
359 )
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000360
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200361 rxs = self.send_and_expect(self.pg4, 5 * [p64], self.pg1, 170)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000362 size = 0
363 for rx in rxs:
364 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
365 self.assertEqual(rx[Ether].dst, self.pg1.remote_mac)
366 self.assertEqual(rx[IPv6].src, self.pg4.remote_ip6)
367 self.assertEqual(rx[IPv6].dst, self.pg1.remote_ip6)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200368 payload_len = rx[IPv6].plen - 20
369 self.assert_tcp_checksum_valid(rx)
370 self.assertEqual(payload_len, len(rx[Raw]))
371 size += payload_len
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200372 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000373
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200374 self.vapi.feature_gso_enable_disable(
375 sw_if_index=self.pg0.sw_if_index, enable_disable=0
376 )
377 self.vapi.feature_gso_enable_disable(
378 sw_if_index=self.pg1.sw_if_index, enable_disable=0
379 )
Mohsin Kazmi1ab8b3c2020-05-05 10:31:17 +0000380
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000381 def test_gso_vxlan(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200382 """GSO VXLAN test"""
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000383 self.logger.info(self.vapi.cli("sh int addr"))
384 #
385 # Send jumbo frame with gso enabled only on input interface and
386 # create VXLAN VTEP on VPP pg0, and put vxlan_tunnel0 and pg2
387 # into BD.
388 #
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200389
390 #
391 # enable ipv4/vxlan
392 #
393 self.vxlan.add_vpp_config()
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000394 self.vapi.sw_interface_set_l2_bridge(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200395 rx_sw_if_index=self.vxlan.sw_if_index, bd_id=self.single_tunnel_bd
396 )
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000397 self.vapi.sw_interface_set_l2_bridge(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200398 rx_sw_if_index=self.pg2.sw_if_index, bd_id=self.single_tunnel_bd
399 )
400 self.vapi.feature_gso_enable_disable(
401 sw_if_index=self.pg0.sw_if_index, enable_disable=1
402 )
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000403
404 #
405 # IPv4/IPv4 - VXLAN
406 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200407 p45 = (
Steven Luonge4238aa2024-04-19 09:49:20 -0700408 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200409 / IP(src=self.pg2.remote_ip4, dst="172.16.3.3", flags="DF")
410 / TCP(sport=1234, dport=1234)
411 / Raw(b"\xa5" * 65200)
412 )
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000413
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200414 rxs = self.send_and_expect(self.pg2, 5 * [p45], self.pg0, 225)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000415 size = 0
416 for rx in rxs:
417 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
418 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
419 self.assertEqual(rx[IP].src, self.pg0.local_ip4)
420 self.assertEqual(rx[IP].dst, self.pg0.remote_ip4)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200421 self.assert_ip_checksum_valid(rx)
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000422 self.assert_udp_checksum_valid(rx, ignore_zero_checksum=True)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000423 self.assertEqual(rx[VXLAN].vni, 10)
424 inner = rx[VXLAN].payload
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200425 self.assertEqual(rx[IP].len - 20 - 8 - 8, len(inner))
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000426 self.assertEqual(inner[Ether].src, self.pg2.remote_mac)
Steven Luonge4238aa2024-04-19 09:49:20 -0700427 self.assertEqual(inner[Ether].dst, self.pg2.local_mac)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000428 self.assertEqual(inner[IP].src, self.pg2.remote_ip4)
429 self.assertEqual(inner[IP].dst, "172.16.3.3")
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200430 self.assert_ip_checksum_valid(inner)
431 self.assert_tcp_checksum_valid(inner)
432 payload_len = inner[IP].len - 20 - 20
433 self.assertEqual(payload_len, len(inner[Raw]))
434 size += payload_len
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200435 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000436
437 #
438 # IPv4/IPv6 - VXLAN
439 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200440 p65 = (
Steven Luonge4238aa2024-04-19 09:49:20 -0700441 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200442 / IPv6(src=self.pg2.remote_ip6, dst="fd01:3::3")
443 / TCP(sport=1234, dport=1234)
444 / Raw(b"\xa5" * 65200)
445 )
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000446
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200447 rxs = self.send_and_expect(self.pg2, 5 * [p65], self.pg0, 225)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000448 size = 0
449 for rx in rxs:
450 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
451 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
452 self.assertEqual(rx[IP].src, self.pg0.local_ip4)
453 self.assertEqual(rx[IP].dst, self.pg0.remote_ip4)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200454 self.assert_ip_checksum_valid(rx)
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000455 self.assert_udp_checksum_valid(rx, ignore_zero_checksum=True)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000456 self.assertEqual(rx[VXLAN].vni, 10)
457 inner = rx[VXLAN].payload
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200458 self.assertEqual(rx[IP].len - 20 - 8 - 8, len(inner))
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000459 self.assertEqual(inner[Ether].src, self.pg2.remote_mac)
Steven Luonge4238aa2024-04-19 09:49:20 -0700460 self.assertEqual(inner[Ether].dst, self.pg2.local_mac)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000461 self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6)
462 self.assertEqual(inner[IPv6].dst, "fd01:3::3")
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200463 self.assert_tcp_checksum_valid(inner)
464 payload_len = inner[IPv6].plen - 20
465 self.assertEqual(payload_len, len(inner[Raw]))
466 size += payload_len
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200467 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000468
469 #
470 # disable ipv4/vxlan
471 #
472 self.vxlan.remove_vpp_config()
473
474 #
475 # enable ipv6/vxlan
476 #
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200477 self.vxlan2.add_vpp_config()
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000478 self.vapi.sw_interface_set_l2_bridge(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200479 rx_sw_if_index=self.vxlan2.sw_if_index, bd_id=self.single_tunnel_bd
480 )
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000481
482 #
483 # IPv6/IPv4 - VXLAN
484 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200485 p46 = (
Steven Luonge4238aa2024-04-19 09:49:20 -0700486 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200487 / IP(src=self.pg2.remote_ip4, dst="172.16.3.3", flags="DF")
488 / TCP(sport=1234, dport=1234)
489 / Raw(b"\xa5" * 65200)
490 )
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000491
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200492 rxs = self.send_and_expect(self.pg2, 5 * [p46], self.pg0, 225)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000493 size = 0
494 for rx in rxs:
495 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
496 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
497 self.assertEqual(rx[IPv6].src, self.pg0.local_ip6)
498 self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6)
Vladimir Isaev698eb872020-05-21 16:34:17 +0300499 self.assert_udp_checksum_valid(rx, ignore_zero_checksum=False)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000500 self.assertEqual(rx[VXLAN].vni, 10)
501 inner = rx[VXLAN].payload
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200502 self.assertEqual(rx[IPv6].plen - 8 - 8, len(inner))
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000503 self.assertEqual(inner[Ether].src, self.pg2.remote_mac)
Steven Luonge4238aa2024-04-19 09:49:20 -0700504 self.assertEqual(inner[Ether].dst, self.pg2.local_mac)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000505 self.assertEqual(inner[IP].src, self.pg2.remote_ip4)
506 self.assertEqual(inner[IP].dst, "172.16.3.3")
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200507 self.assert_ip_checksum_valid(inner)
508 self.assert_tcp_checksum_valid(inner)
509 payload_len = inner[IP].len - 20 - 20
510 self.assertEqual(payload_len, len(inner[Raw]))
511 size += payload_len
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200512 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000513
514 #
515 # IPv6/IPv6 - VXLAN
516 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200517 p66 = (
Steven Luonge4238aa2024-04-19 09:49:20 -0700518 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200519 / IPv6(src=self.pg2.remote_ip6, dst="fd01:3::3")
520 / TCP(sport=1234, dport=1234)
521 / Raw(b"\xa5" * 65200)
522 )
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000523
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200524 rxs = self.send_and_expect(self.pg2, 5 * [p66], self.pg0, 225)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000525 size = 0
526 for rx in rxs:
527 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
528 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
529 self.assertEqual(rx[IPv6].src, self.pg0.local_ip6)
530 self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6)
Vladimir Isaev698eb872020-05-21 16:34:17 +0300531 self.assert_udp_checksum_valid(rx, ignore_zero_checksum=False)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000532 self.assertEqual(rx[VXLAN].vni, 10)
533 inner = rx[VXLAN].payload
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200534 self.assertEqual(rx[IPv6].plen - 8 - 8, len(inner))
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000535 self.assertEqual(inner[Ether].src, self.pg2.remote_mac)
Steven Luonge4238aa2024-04-19 09:49:20 -0700536 self.assertEqual(inner[Ether].dst, self.pg2.local_mac)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000537 self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6)
538 self.assertEqual(inner[IPv6].dst, "fd01:3::3")
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200539 self.assert_tcp_checksum_valid(inner)
540 payload_len = inner[IPv6].plen - 20
541 self.assertEqual(payload_len, len(inner[Raw]))
542 size += payload_len
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200543 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000544
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200545 #
546 # disable ipv4/vxlan
547 #
548 self.vxlan2.remove_vpp_config()
549
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200550 self.vapi.feature_gso_enable_disable(
551 sw_if_index=self.pg0.sw_if_index, enable_disable=0
552 )
Mohsin Kazmi1ab8b3c2020-05-05 10:31:17 +0000553
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200554 def test_gso_ipip(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200555 """GSO IPIP test"""
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200556 self.logger.info(self.vapi.cli("sh int addr"))
557 #
558 # Send jumbo frame with gso enabled only on input interface and
559 # create IPIP tunnel on VPP pg0.
560 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200561 self.vapi.feature_gso_enable_disable(
562 sw_if_index=self.pg0.sw_if_index, enable_disable=1
563 )
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200564
565 #
566 # enable ipip4
567 #
568 self.ipip4.add_vpp_config()
569
570 # Set interface up and enable IP on it
571 self.ipip4.admin_up()
572 self.ipip4.set_unnumbered(self.pg0.sw_if_index)
573
574 # Add IPv4 routes via tunnel interface
575 self.ip4_via_ip4_tunnel = VppIpRoute(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200576 self,
577 "172.16.10.0",
578 24,
579 [
580 VppRoutePath(
581 "0.0.0.0",
582 self.ipip4.sw_if_index,
583 proto=FibPathProto.FIB_PATH_NH_PROTO_IP4,
584 )
585 ],
586 )
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200587 self.ip4_via_ip4_tunnel.add_vpp_config()
588
589 #
590 # IPv4/IPv4 - IPIP
591 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200592 p47 = (
Steven Luonge4238aa2024-04-19 09:49:20 -0700593 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200594 / IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags="DF")
595 / TCP(sport=1234, dport=1234)
596 / Raw(b"\xa5" * 65200)
597 )
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200598
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200599 rxs = self.send_and_expect(self.pg2, 5 * [p47], self.pg0, 225)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200600 size = 0
601 for rx in rxs:
602 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
603 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
604 self.assertEqual(rx[IP].src, self.pg0.local_ip4)
605 self.assertEqual(rx[IP].dst, self.pg0.remote_ip4)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200606 self.assert_ip_checksum_valid(rx)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200607 self.assertEqual(rx[IP].proto, 4) # ipencap
608 inner = rx[IP].payload
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200609 self.assertEqual(rx[IP].len - 20, len(inner))
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200610 self.assertEqual(inner[IP].src, self.pg2.remote_ip4)
611 self.assertEqual(inner[IP].dst, "172.16.10.3")
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200612 self.assert_ip_checksum_valid(inner)
613 self.assert_tcp_checksum_valid(inner)
614 payload_len = inner[IP].len - 20 - 20
615 self.assertEqual(payload_len, len(inner[Raw]))
616 size += payload_len
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200617 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200618
619 self.ip6_via_ip4_tunnel = VppIpRoute(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200620 self,
621 "fd01:10::",
622 64,
623 [
624 VppRoutePath(
625 "::",
626 self.ipip4.sw_if_index,
627 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6,
628 )
629 ],
630 )
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200631 self.ip6_via_ip4_tunnel.add_vpp_config()
632 #
633 # IPv4/IPv6 - IPIP
634 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200635 p67 = (
Steven Luonge4238aa2024-04-19 09:49:20 -0700636 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200637 / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3")
638 / TCP(sport=1234, dport=1234)
639 / Raw(b"\xa5" * 65200)
640 )
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200641
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200642 rxs = self.send_and_expect(self.pg2, 5 * [p67], self.pg0, 225)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200643 size = 0
644 for rx in rxs:
645 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
646 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
647 self.assertEqual(rx[IP].src, self.pg0.local_ip4)
648 self.assertEqual(rx[IP].dst, self.pg0.remote_ip4)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200649 self.assert_ip_checksum_valid(rx)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200650 self.assertEqual(rx[IP].proto, 41) # ipv6
651 inner = rx[IP].payload
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200652 self.assertEqual(rx[IP].len - 20, len(inner))
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200653 self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6)
654 self.assertEqual(inner[IPv6].dst, "fd01:10::3")
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200655 self.assert_tcp_checksum_valid(inner)
656 payload_len = inner[IPv6].plen - 20
657 self.assertEqual(payload_len, len(inner[Raw]))
658 size += payload_len
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200659 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200660
661 #
662 # Send jumbo frame with gso enabled only on input interface and
663 # create IPIP tunnel on VPP pg0. Enable gso feature node on ipip
664 # tunnel - IPSec use case
665 #
Ole Troan5c2a2372020-11-19 16:01:23 +0100666 self.vapi.feature_gso_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200667 sw_if_index=self.pg0.sw_if_index, enable_disable=0
668 )
669 self.vapi.feature_gso_enable_disable(
670 sw_if_index=self.ipip4.sw_if_index, enable_disable=1
671 )
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200672
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200673 rxs = self.send_and_expect(self.pg2, 5 * [p47], self.pg0, 225)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200674 size = 0
675 for rx in rxs:
676 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
677 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
678 self.assertEqual(rx[IP].src, self.pg0.local_ip4)
679 self.assertEqual(rx[IP].dst, self.pg0.remote_ip4)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200680 self.assert_ip_checksum_valid(rx)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200681 self.assertEqual(rx[IP].proto, 4) # ipencap
682 inner = rx[IP].payload
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200683 self.assertEqual(rx[IP].len - 20, len(inner))
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200684 self.assertEqual(inner[IP].src, self.pg2.remote_ip4)
685 self.assertEqual(inner[IP].dst, "172.16.10.3")
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200686 self.assert_ip_checksum_valid(inner)
687 self.assert_tcp_checksum_valid(inner)
688 payload_len = inner[IP].len - 20 - 20
689 self.assertEqual(payload_len, len(inner[Raw]))
690 size += payload_len
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200691 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200692
693 #
694 # disable ipip4
695 #
Ole Troan5c2a2372020-11-19 16:01:23 +0100696 self.vapi.feature_gso_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200697 sw_if_index=self.ipip4.sw_if_index, enable_disable=0
698 )
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200699 self.ip4_via_ip4_tunnel.remove_vpp_config()
700 self.ip6_via_ip4_tunnel.remove_vpp_config()
701 self.ipip4.remove_vpp_config()
702
703 #
704 # enable ipip6
705 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200706 self.vapi.feature_gso_enable_disable(
707 sw_if_index=self.pg0.sw_if_index, enable_disable=1
708 )
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200709 self.ipip6.add_vpp_config()
710
711 # Set interface up and enable IP on it
712 self.ipip6.admin_up()
713 self.ipip6.set_unnumbered(self.pg0.sw_if_index)
714
715 # Add IPv4 routes via tunnel interface
716 self.ip4_via_ip6_tunnel = VppIpRoute(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200717 self,
718 "172.16.10.0",
719 24,
720 [
721 VppRoutePath(
722 "0.0.0.0",
723 self.ipip6.sw_if_index,
724 proto=FibPathProto.FIB_PATH_NH_PROTO_IP4,
725 )
726 ],
727 )
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200728 self.ip4_via_ip6_tunnel.add_vpp_config()
729
730 #
731 # IPv6/IPv4 - IPIP
732 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200733 p48 = (
Steven Luonge4238aa2024-04-19 09:49:20 -0700734 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200735 / IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags="DF")
736 / TCP(sport=1234, dport=1234)
737 / Raw(b"\xa5" * 65200)
738 )
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200739
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200740 rxs = self.send_and_expect(self.pg2, 5 * [p48], self.pg0, 225)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200741 size = 0
742 for rx in rxs:
743 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
744 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
745 self.assertEqual(rx[IPv6].src, self.pg0.local_ip6)
746 self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6)
747 self.assertEqual(ipv6nh[rx[IPv6].nh], "IP")
748 inner = rx[IPv6].payload
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200749 self.assertEqual(rx[IPv6].plen, len(inner))
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200750 self.assertEqual(inner[IP].src, self.pg2.remote_ip4)
751 self.assertEqual(inner[IP].dst, "172.16.10.3")
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200752 self.assert_ip_checksum_valid(inner)
753 self.assert_tcp_checksum_valid(inner)
754 payload_len = inner[IP].len - 20 - 20
755 self.assertEqual(payload_len, len(inner[Raw]))
756 size += payload_len
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200757 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200758
759 self.ip6_via_ip6_tunnel = VppIpRoute(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200760 self,
761 "fd01:10::",
762 64,
763 [
764 VppRoutePath(
765 "::",
766 self.ipip6.sw_if_index,
767 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6,
768 )
769 ],
770 )
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200771 self.ip6_via_ip6_tunnel.add_vpp_config()
772
773 #
774 # IPv6/IPv6 - IPIP
775 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200776 p68 = (
Steven Luonge4238aa2024-04-19 09:49:20 -0700777 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200778 / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3")
779 / TCP(sport=1234, dport=1234)
780 / Raw(b"\xa5" * 65200)
781 )
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200782
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200783 rxs = self.send_and_expect(self.pg2, 5 * [p68], self.pg0, 225)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200784 size = 0
785 for rx in rxs:
786 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
787 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
788 self.assertEqual(rx[IPv6].src, self.pg0.local_ip6)
789 self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6)
790 self.assertEqual(ipv6nh[rx[IPv6].nh], "IPv6")
791 inner = rx[IPv6].payload
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200792 self.assertEqual(rx[IPv6].plen, len(inner))
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200793 self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6)
794 self.assertEqual(inner[IPv6].dst, "fd01:10::3")
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200795 self.assert_tcp_checksum_valid(inner)
796 payload_len = inner[IPv6].plen - 20
797 self.assertEqual(payload_len, len(inner[Raw]))
798 size += payload_len
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200799 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200800
801 #
802 # disable ipip6
803 #
804 self.ip4_via_ip6_tunnel.remove_vpp_config()
805 self.ip6_via_ip6_tunnel.remove_vpp_config()
806 self.ipip6.remove_vpp_config()
807
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200808 self.vapi.feature_gso_enable_disable(
809 sw_if_index=self.pg0.sw_if_index, enable_disable=0
810 )
Mohsin Kazmi1ab8b3c2020-05-05 10:31:17 +0000811
Arthur de Kerhor2f4586d2021-09-22 14:53:24 +0200812 def test_gso_gre(self):
813 """GSO GRE test"""
814 #
815 # Send jumbo frame with gso enabled only on gre tunnel interface.
816 # create GRE tunnel on VPP pg0.
817 #
818
819 #
820 # create gre 4 tunnel
821 #
822 self.gre4.add_vpp_config()
823 self.gre4.admin_up()
824 self.gre4.config_ip4()
825
826 #
827 # Add a route that resolves the tunnel's destination
828 #
829 # Add IPv4 routes via tunnel interface
830 self.ip4_via_gre4_tunnel = VppIpRoute(
831 self,
832 "172.16.10.0",
833 24,
834 [
835 VppRoutePath(
836 "0.0.0.0",
837 self.gre4.sw_if_index,
838 proto=FibPathProto.FIB_PATH_NH_PROTO_IP4,
839 )
840 ],
841 )
842 self.ip4_via_gre4_tunnel.add_vpp_config()
843
844 pgre4 = (
Steven Luonge4238aa2024-04-19 09:49:20 -0700845 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Arthur de Kerhor2f4586d2021-09-22 14:53:24 +0200846 / IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags="DF")
847 / TCP(sport=1234, dport=1234)
848 / Raw(b"\xa5" * 65200)
849 )
850
851 # test when GSO segmentation is disabled, Packets are truncated
852 rxs = self.send_and_expect(self.pg2, 5 * [pgre4], self.pg0, 5)
853 for rx in rxs:
854 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
855 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
856 self.assertEqual(rx[IP].src, self.pg0.local_ip4)
857 self.assertEqual(rx[IP].dst, self.pg0.remote_ip4)
858 self.assert_ip_checksum_valid(rx)
859 self.assertEqual(rx[IP].proto, 0x2F) # GRE encap
860 self.assertEqual(rx[GRE].proto, 0x0800) # IPv4
861 inner = rx[GRE].payload
862 self.assertNotEqual(rx[IP].len - 20 - 4, len(inner))
863 self.assertEqual(inner[IP].src, self.pg2.remote_ip4)
864 self.assertEqual(inner[IP].dst, "172.16.10.3")
865 self.assert_ip_checksum_valid(inner)
866 payload_len = inner[IP].len - 20 - 20
867 self.assertEqual(payload_len, 65200)
868 # truncated packet to MTU size
869 self.assertNotEqual(payload_len, len(inner[Raw]))
870
871 # enable the GSO segmentation on GRE tunnel
872 self.vapi.feature_gso_enable_disable(
873 sw_if_index=self.gre4.sw_if_index, enable_disable=1
874 )
875
876 # test again, this time payload will be chuncked to GSO size (i.e. 1448)
877 rxs = self.send_and_expect(self.pg2, 5 * [pgre4], self.pg0, 225)
878 size = 0
879 for rx in rxs:
880 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
881 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
882 self.assertEqual(rx[IP].src, self.pg0.local_ip4)
883 self.assertEqual(rx[IP].dst, self.pg0.remote_ip4)
884 self.assert_ip_checksum_valid(rx)
885 self.assertEqual(rx[IP].proto, 0x2F) # GRE encap
886 self.assertEqual(rx[GRE].proto, 0x0800) # IPv4
887 inner = rx[GRE].payload
888 self.assertEqual(rx[IP].len - 20 - 4, len(inner))
889 self.assertEqual(inner[IP].src, self.pg2.remote_ip4)
890 self.assertEqual(inner[IP].dst, "172.16.10.3")
891 self.assert_ip_checksum_valid(inner)
892 self.assert_tcp_checksum_valid(inner)
893 payload_len = inner[IP].len - 20 - 20
894 self.assertEqual(payload_len, len(inner[Raw]))
895 size += payload_len
896 self.assertEqual(size, 65200 * 5)
897
898 # Disable the GSO segmentation on GRE tunnel
899 self.vapi.feature_gso_enable_disable(
900 sw_if_index=self.gre4.sw_if_index, enable_disable=0
901 )
902
903 # test again when GSO segmentation is disabled, Packets are truncated
904 rxs = self.send_and_expect(self.pg2, 5 * [pgre4], self.pg0, 5)
905 for rx in rxs:
906 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
907 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
908 self.assertEqual(rx[IP].src, self.pg0.local_ip4)
909 self.assertEqual(rx[IP].dst, self.pg0.remote_ip4)
910 self.assert_ip_checksum_valid(rx)
911 self.assertEqual(rx[IP].proto, 0x2F) # GRE encap
912 self.assertEqual(rx[GRE].proto, 0x0800) # IPv4
913 inner = rx[GRE].payload
914 self.assertNotEqual(rx[IP].len - 20 - 4, len(inner))
915 self.assertEqual(inner[IP].src, self.pg2.remote_ip4)
916 self.assertEqual(inner[IP].dst, "172.16.10.3")
917 self.assert_ip_checksum_valid(inner)
918 payload_len = inner[IP].len - 20 - 20
919 self.assertEqual(payload_len, 65200)
920 # truncated packet to MTU size
921 self.assertNotEqual(payload_len, len(inner[Raw]))
922
923 self.ip4_via_gre4_tunnel.remove_vpp_config()
924 self.gre4.remove_vpp_config()
925
926 self.gre6.add_vpp_config()
927 self.gre6.admin_up()
928 self.gre6.config_ip4()
929
930 #
931 # Add a route that resolves the tunnel's destination
932 # Add IPv6 routes via tunnel interface
933 #
934 self.vapi.feature_gso_enable_disable(
935 sw_if_index=self.gre6.sw_if_index, enable_disable=1
936 )
937 self.ip6_via_gre6_tunnel = VppIpRoute(
938 self,
939 "fd01:10::",
940 64,
941 [
942 VppRoutePath(
943 "::",
944 self.gre6.sw_if_index,
945 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6,
946 )
947 ],
948 )
949 self.ip6_via_gre6_tunnel.add_vpp_config()
950
951 #
952 # Create IPv6 packet
953 #
954 pgre6 = (
Steven Luonge4238aa2024-04-19 09:49:20 -0700955 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Arthur de Kerhor2f4586d2021-09-22 14:53:24 +0200956 / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3")
957 / TCP(sport=1234, dport=1234)
958 / Raw(b"\xa5" * 65200)
959 )
960
961 # test when GSO segmentation is enabled, payload will be segmented
962 # into GSO size (i.e. 1448)
963 rxs = self.send_and_expect(self.pg2, 5 * [pgre6], self.pg0, 225)
964 size = 0
965 for rx in rxs:
966 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
967 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
968 self.assertEqual(rx[IPv6].src, self.pg0.local_ip6)
969 self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6)
970 self.assertEqual(ipv6nh[rx[IPv6].nh], "GRE")
971 self.assertEqual(rx[GRE].proto, 0x86DD) # IPv6
972 inner = rx[GRE].payload
973 self.assertEqual(rx[IPv6].plen - 4, len(inner))
974 self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6)
975 self.assertEqual(inner[IPv6].dst, "fd01:10::3")
976 self.assert_tcp_checksum_valid(inner)
977 payload_len = inner[IPv6].plen - 20
978 self.assertEqual(payload_len, len(inner[Raw]))
979 size += payload_len
980 self.assertEqual(size, 65200 * 5)
981
982 # disable GSO segmentation
983 self.vapi.feature_gso_enable_disable(
984 sw_if_index=self.gre6.sw_if_index, enable_disable=0
985 )
986
987 # test again, this time packets will be truncated
988 rxs = self.send_and_expect(self.pg2, 5 * [pgre6], self.pg0, 5)
989 for rx in rxs:
990 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
991 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
992 self.assertEqual(rx[IPv6].src, self.pg0.local_ip6)
993 self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6)
994 self.assertEqual(ipv6nh[rx[IPv6].nh], "GRE")
995 self.assertEqual(rx[GRE].proto, 0x86DD) # IPv6
996 inner = rx[GRE].payload
997 self.assertNotEqual(rx[IPv6].plen - 4, len(inner))
998 self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6)
999 self.assertEqual(inner[IPv6].dst, "fd01:10::3")
1000 payload_len = inner[IPv6].plen - 20
1001 self.assertEqual(payload_len, 65200)
1002 # packets are truncated to MTU size
1003 self.assertNotEqual(payload_len, len(inner[Raw]))
1004
1005 self.ip6_via_gre6_tunnel.remove_vpp_config()
1006 self.gre6.remove_vpp_config()
1007
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001008 def test_gso_ipsec(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001009 """GSO IPSEC test"""
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001010 #
1011 # Send jumbo frame with gso enabled only on input interface and
1012 # create IPIP tunnel on VPP pg0.
1013 #
1014
1015 #
1016 # enable ipip4
1017 #
1018 self.ipip4.add_vpp_config()
1019 self.vapi.feature_gso_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001020 sw_if_index=self.ipip4.sw_if_index, enable_disable=1
1021 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001022
1023 # Add IPv4 routes via tunnel interface
1024 self.ip4_via_ip4_tunnel = VppIpRoute(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001025 self,
1026 "172.16.10.0",
1027 24,
1028 [
1029 VppRoutePath(
1030 "0.0.0.0",
1031 self.ipip4.sw_if_index,
1032 proto=FibPathProto.FIB_PATH_NH_PROTO_IP4,
1033 )
1034 ],
1035 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001036 self.ip4_via_ip4_tunnel.add_vpp_config()
1037
1038 # IPSec config
1039 self.ipv4_params = IPsecIPv4Params()
1040 self.encryption_type = ESP
1041 config_tun_params(self.ipv4_params, self.encryption_type, self.ipip4)
1042
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001043 self.tun_sa_in_v4 = VppIpsecSA(
1044 self,
Arthur de Kerhor0df06b62022-11-16 18:45:24 +01001045 self.ipv4_params.scapy_tun_sa_id,
1046 self.ipv4_params.scapy_tun_spi,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001047 self.ipv4_params.auth_algo_vpp_id,
1048 self.ipv4_params.auth_key,
1049 self.ipv4_params.crypt_algo_vpp_id,
1050 self.ipv4_params.crypt_key,
1051 VppEnum.vl_api_ipsec_proto_t.IPSEC_API_PROTO_ESP,
1052 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001053 self.tun_sa_in_v4.add_vpp_config()
1054
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001055 self.tun_sa_out_v4 = VppIpsecSA(
1056 self,
Arthur de Kerhor0df06b62022-11-16 18:45:24 +01001057 self.ipv4_params.vpp_tun_sa_id,
1058 self.ipv4_params.vpp_tun_spi,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001059 self.ipv4_params.auth_algo_vpp_id,
1060 self.ipv4_params.auth_key,
1061 self.ipv4_params.crypt_algo_vpp_id,
1062 self.ipv4_params.crypt_key,
1063 VppEnum.vl_api_ipsec_proto_t.IPSEC_API_PROTO_ESP,
1064 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001065 self.tun_sa_out_v4.add_vpp_config()
1066
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001067 self.tun_protect_v4 = VppIpsecTunProtect(
1068 self, self.ipip4, self.tun_sa_out_v4, [self.tun_sa_in_v4]
1069 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001070
1071 self.tun_protect_v4.add_vpp_config()
1072
1073 # Set interface up and enable IP on it
1074 self.ipip4.admin_up()
1075 self.ipip4.set_unnumbered(self.pg0.sw_if_index)
1076
1077 #
1078 # IPv4/IPv4 - IPSEC
1079 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001080 ipsec44 = (
Steven Luonge4238aa2024-04-19 09:49:20 -07001081 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001082 / IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags="DF")
1083 / TCP(sport=1234, dport=1234)
1084 / Raw(b"\xa5" * 65200)
1085 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001086
1087 rxs = self.send_and_expect(self.pg2, [ipsec44], self.pg0, 45)
1088 size = 0
1089 for rx in rxs:
1090 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
1091 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
1092 self.assertEqual(rx[IP].src, self.pg0.local_ip4)
1093 self.assertEqual(rx[IP].dst, self.pg0.remote_ip4)
1094 self.assertEqual(rx[IP].proto, 50) # ESP
Arthur de Kerhor0df06b62022-11-16 18:45:24 +01001095 self.assertEqual(rx[ESP].spi, self.ipv4_params.vpp_tun_spi)
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001096 inner = self.ipv4_params.vpp_tun_sa.decrypt(rx[IP])
1097 self.assertEqual(inner[IP].src, self.pg2.remote_ip4)
1098 self.assertEqual(inner[IP].dst, "172.16.10.3")
1099 size += inner[IP].len - 20 - 20
1100 self.assertEqual(size, 65200)
1101
1102 self.ip6_via_ip4_tunnel = VppIpRoute(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001103 self,
1104 "fd01:10::",
1105 64,
1106 [
1107 VppRoutePath(
1108 "::",
1109 self.ipip4.sw_if_index,
1110 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6,
1111 )
1112 ],
1113 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001114 self.ip6_via_ip4_tunnel.add_vpp_config()
1115 #
1116 # IPv4/IPv6 - IPSEC
1117 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001118 ipsec46 = (
Steven Luonge4238aa2024-04-19 09:49:20 -07001119 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001120 / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3")
1121 / TCP(sport=1234, dport=1234)
1122 / Raw(b"\xa5" * 65200)
1123 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001124
1125 rxs = self.send_and_expect(self.pg2, [ipsec46], self.pg0, 45)
1126 size = 0
1127 for rx in rxs:
1128 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
1129 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
1130 self.assertEqual(rx[IP].src, self.pg0.local_ip4)
1131 self.assertEqual(rx[IP].dst, self.pg0.remote_ip4)
1132 self.assertEqual(rx[IP].proto, 50) # ESP
Arthur de Kerhor0df06b62022-11-16 18:45:24 +01001133 self.assertEqual(rx[ESP].spi, self.ipv4_params.vpp_tun_spi)
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001134 inner = self.ipv4_params.vpp_tun_sa.decrypt(rx[IP])
1135 self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6)
1136 self.assertEqual(inner[IPv6].dst, "fd01:10::3")
1137 size += inner[IPv6].plen - 20
1138 self.assertEqual(size, 65200)
1139
1140 # disable IPSec
1141 self.tun_protect_v4.remove_vpp_config()
1142 self.tun_sa_in_v4.remove_vpp_config()
1143 self.tun_sa_out_v4.remove_vpp_config()
1144
1145 #
1146 # disable ipip4
1147 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001148 self.vapi.feature_gso_enable_disable(self.ipip4.sw_if_index, enable_disable=0)
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001149 self.ip4_via_ip4_tunnel.remove_vpp_config()
1150 self.ip6_via_ip4_tunnel.remove_vpp_config()
1151 self.ipip4.remove_vpp_config()
1152
1153 #
1154 # enable ipip6
1155 #
1156 self.ipip6.add_vpp_config()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001157 self.vapi.feature_gso_enable_disable(self.ipip6.sw_if_index, enable_disable=1)
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001158
1159 # Set interface up and enable IP on it
1160 self.ipip6.admin_up()
1161 self.ipip6.set_unnumbered(self.pg0.sw_if_index)
1162
1163 # Add IPv4 routes via tunnel interface
1164 self.ip4_via_ip6_tunnel = VppIpRoute(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001165 self,
1166 "172.16.10.0",
1167 24,
1168 [
1169 VppRoutePath(
1170 "0.0.0.0",
1171 self.ipip6.sw_if_index,
1172 proto=FibPathProto.FIB_PATH_NH_PROTO_IP4,
1173 )
1174 ],
1175 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001176 self.ip4_via_ip6_tunnel.add_vpp_config()
1177
1178 # IPSec config
1179 self.ipv6_params = IPsecIPv6Params()
1180 self.encryption_type = ESP
1181 config_tun_params(self.ipv6_params, self.encryption_type, self.ipip6)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001182 self.tun_sa_in_v6 = VppIpsecSA(
1183 self,
Arthur de Kerhor0df06b62022-11-16 18:45:24 +01001184 self.ipv6_params.scapy_tun_sa_id,
1185 self.ipv6_params.scapy_tun_spi,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001186 self.ipv6_params.auth_algo_vpp_id,
1187 self.ipv6_params.auth_key,
1188 self.ipv6_params.crypt_algo_vpp_id,
1189 self.ipv6_params.crypt_key,
1190 VppEnum.vl_api_ipsec_proto_t.IPSEC_API_PROTO_ESP,
1191 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001192 self.tun_sa_in_v6.add_vpp_config()
1193
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001194 self.tun_sa_out_v6 = VppIpsecSA(
1195 self,
Arthur de Kerhor0df06b62022-11-16 18:45:24 +01001196 self.ipv6_params.vpp_tun_sa_id,
1197 self.ipv6_params.vpp_tun_spi,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001198 self.ipv6_params.auth_algo_vpp_id,
1199 self.ipv6_params.auth_key,
1200 self.ipv6_params.crypt_algo_vpp_id,
1201 self.ipv6_params.crypt_key,
1202 VppEnum.vl_api_ipsec_proto_t.IPSEC_API_PROTO_ESP,
1203 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001204 self.tun_sa_out_v6.add_vpp_config()
1205
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001206 self.tun_protect_v6 = VppIpsecTunProtect(
1207 self, self.ipip6, self.tun_sa_out_v6, [self.tun_sa_in_v6]
1208 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001209
1210 self.tun_protect_v6.add_vpp_config()
1211
1212 #
1213 # IPv6/IPv4 - IPSEC
1214 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001215 ipsec64 = (
Steven Luonge4238aa2024-04-19 09:49:20 -07001216 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001217 / IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags="DF")
1218 / TCP(sport=1234, dport=1234)
1219 / Raw(b"\xa5" * 65200)
1220 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001221
1222 rxs = self.send_and_expect(self.pg2, [ipsec64], self.pg0, 45)
1223 size = 0
1224 for rx in rxs:
1225 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
1226 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
1227 self.assertEqual(rx[IPv6].src, self.pg0.local_ip6)
1228 self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6)
1229 self.assertEqual(ipv6nh[rx[IPv6].nh], "ESP Header")
Arthur de Kerhor0df06b62022-11-16 18:45:24 +01001230 self.assertEqual(rx[ESP].spi, self.ipv6_params.vpp_tun_spi)
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001231 inner = self.ipv6_params.vpp_tun_sa.decrypt(rx[IPv6])
1232 self.assertEqual(inner[IP].src, self.pg2.remote_ip4)
1233 self.assertEqual(inner[IP].dst, "172.16.10.3")
1234 size += inner[IP].len - 20 - 20
1235 self.assertEqual(size, 65200)
1236
1237 self.ip6_via_ip6_tunnel = VppIpRoute(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001238 self,
1239 "fd01:10::",
1240 64,
1241 [
1242 VppRoutePath(
1243 "::",
1244 self.ipip6.sw_if_index,
1245 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6,
1246 )
1247 ],
1248 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001249 self.ip6_via_ip6_tunnel.add_vpp_config()
1250
1251 #
1252 # IPv6/IPv6 - IPSEC
1253 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001254 ipsec66 = (
Steven Luonge4238aa2024-04-19 09:49:20 -07001255 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001256 / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3")
1257 / TCP(sport=1234, dport=1234)
1258 / Raw(b"\xa5" * 65200)
1259 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001260
1261 rxs = self.send_and_expect(self.pg2, [ipsec66], self.pg0, 45)
1262 size = 0
1263 for rx in rxs:
1264 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
1265 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
1266 self.assertEqual(rx[IPv6].src, self.pg0.local_ip6)
1267 self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6)
1268 self.assertEqual(ipv6nh[rx[IPv6].nh], "ESP Header")
Arthur de Kerhor0df06b62022-11-16 18:45:24 +01001269 self.assertEqual(rx[ESP].spi, self.ipv6_params.vpp_tun_spi)
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001270 inner = self.ipv6_params.vpp_tun_sa.decrypt(rx[IPv6])
1271 self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6)
1272 self.assertEqual(inner[IPv6].dst, "fd01:10::3")
1273 size += inner[IPv6].plen - 20
1274 self.assertEqual(size, 65200)
1275
1276 # disable IPSec
1277 self.tun_protect_v6.remove_vpp_config()
1278 self.tun_sa_in_v6.remove_vpp_config()
1279 self.tun_sa_out_v6.remove_vpp_config()
1280
1281 #
1282 # disable ipip6
1283 #
1284 self.ip4_via_ip6_tunnel.remove_vpp_config()
1285 self.ip6_via_ip6_tunnel.remove_vpp_config()
1286 self.ipip6.remove_vpp_config()
1287
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001288 self.vapi.feature_gso_enable_disable(self.pg0.sw_if_index, enable_disable=0)
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001289
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001290
1291if __name__ == "__main__":
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +02001292 unittest.main(testRunner=VppTestRunner)