blob: c3822b01faa85439d287ba68eca156416afcc022 [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
Dmitry Valter34fa0ce2024-03-11 10:38:46 +000028from config import config
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020029
Mohsin Kazmi0972edc2021-07-09 14:19:37 +020030from vpp_ipsec import VppIpsecSA, VppIpsecTunProtect
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020031from template_ipsec import (
32 IPsecIPv4Params,
33 IPsecIPv6Params,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020034 config_tun_params,
35)
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020036
37""" Test_gso is a subclass of VPPTestCase classes.
38 GSO tests.
39"""
40
41
42class TestGSO(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020043 """GSO Test Case"""
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +020044
45 def __init__(self, *args):
46 VppTestCase.__init__(self, *args)
47
48 @classmethod
49 def setUpClass(self):
50 super(TestGSO, self).setUpClass()
Mohsin Kazmi0b042092020-04-17 16:50:56 +000051 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 Kazmi22e9cfd2019-07-23 11:54:48 +020058
59 @classmethod
60 def tearDownClass(self):
61 super(TestGSO, self).tearDownClass()
62
63 def setUp(self):
64 super(TestGSO, self).setUp()
Mohsin Kazmi0b042092020-04-17 16:50:56 +000065 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 Sekerad9b0c6f2022-04-26 19:02:15 +020074 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 Kazmi0b042092020-04-17 16:50:56 +000080
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020081 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 Kazmi84f91fa2020-04-23 17:59:49 +020087
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020088 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 Kazmi22e9cfd2019-07-23 11:54:48 +020094
Arthur de Kerhor2f4586d2021-09-22 14:53:24 +020095 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 Kazmi22e9cfd2019-07-23 11:54:48 +020098 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200107 """GSO test"""
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200108 #
109 # Send jumbo frame with gso disabled and DF bit is set
110 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200111 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 Kazmi22e9cfd2019-07-23 11:54:48 +0200117
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 Kazmiadf62092020-05-28 20:49:46 +0200129 # Send checksum offload frames
130 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200131 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 Kazmiadf62092020-05-28 20:49:46 +0200137
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200138 rxs = self.send_and_expect(self.pg2, 100 * [p40], self.pg0)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200139
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 Sekerad9b0c6f2022-04-26 19:02:15 +0200150 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 Kazmiadf62092020-05-28 20:49:46 +0200156
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200157 rxs = self.send_and_expect(self.pg2, 100 * [p60], self.pg0)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200158
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 Kazmi22e9cfd2019-07-23 11:54:48 +0200169 # Send jumbo frame with gso enabled and DF bit is set
170 # input and output interfaces support GSO
171 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200172 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 Kazmi22e9cfd2019-07-23 11:54:48 +0200181
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200182 rxs = self.send_and_expect(self.pg2, 100 * [p41], self.pg3, 100)
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200183
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 Kazmi0b042092020-04-17 16:50:56 +0000194 # ipv6
195 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200196 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 Kazmi0b042092020-04-17 16:50:56 +0000202
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200203 rxs = self.send_and_expect(self.pg2, 100 * [p61], self.pg3, 100)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000204
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 Kazmi22e9cfd2019-07-23 11:54:48 +0200215 # 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200219 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 Kazmi22e9cfd2019-07-23 11:54:48 +0200228
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200229 rxs = self.send_and_expect(self.pg2, 5 * [p42], self.pg0, 225)
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200230 size = 0
231 for rx in rxs:
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000232 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
233 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200234 self.assertEqual(rx[IP].src, self.pg2.remote_ip4)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000235 self.assertEqual(rx[IP].dst, self.pg0.remote_ip4)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200236 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 Kazmi22e9cfd2019-07-23 11:54:48 +0200239 self.assertEqual(rx[TCP].sport, 1234)
240 self.assertEqual(rx[TCP].dport, 1234)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200241 self.assertEqual(payload_len, len(rx[Raw]))
242 size += payload_len
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200243 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200244
245 #
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000246 # ipv6
247 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200248 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 Kazmi0b042092020-04-17 16:50:56 +0000254
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200255 rxs = self.send_and_expect(self.pg2, 5 * [p62], self.pg0, 225)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000256 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 Kazmiadf62092020-05-28 20:49:46 +0200262 payload_len = rx[IPv6].plen - 20
263 self.assert_tcp_checksum_valid(rx)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000264 self.assertEqual(rx[TCP].sport, 1234)
265 self.assertEqual(rx[TCP].dport, 1234)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200266 self.assertEqual(payload_len, len(rx[Raw]))
267 size += payload_len
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200268 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000269
270 #
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200271 # 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200275 self.vapi.feature_gso_enable_disable(
276 sw_if_index=self.pg1.sw_if_index, enable_disable=1
277 )
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200278
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200279 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 Kazmi22e9cfd2019-07-23 11:54:48 +0200285
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200286 rxs = self.send_and_expect(self.pg2, 5 * [p43], self.pg1, 5 * 119)
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200287 size = 0
288 for rx in rxs:
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200289 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 Kazmiadf62092020-05-28 20:49:46 +0200293 self.assert_ip_checksum_valid(rx)
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200294 size += rx[IP].len - 20
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200295 size -= 20 * 5 # TCP header
296 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +0200297
Mohsin Kazmi3f1964d2019-08-22 18:40:28 +0200298 #
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000299 # 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200304 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 Kazmi0b042092020-04-17 16:50:56 +0000310
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200311 rxs = self.send_and_expect_some(self.pg2, 5 * [p63], self.pg2, 5)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000312 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 Kazmi3f1964d2019-08-22 18:40:28 +0200325 # Send jumbo frame with gso enabled only on input interface with 9K MTU
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000326 # 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 Kazmi3f1964d2019-08-22 18:40:28 +0200328 #
329 self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [9000, 0, 0, 0])
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000330 self.vapi.sw_interface_set_mtu(self.pg4.sw_if_index, [9000, 0, 0, 0])
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200331 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 Kazmi3f1964d2019-08-22 18:40:28 +0200337
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200338 rxs = self.send_and_expect(self.pg4, 5 * [p44], self.pg1, 165)
Mohsin Kazmi3f1964d2019-08-22 18:40:28 +0200339 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 Kazmi0b042092020-04-17 16:50:56 +0000343 self.assertEqual(rx[IP].src, self.pg4.remote_ip4)
Mohsin Kazmi3f1964d2019-08-22 18:40:28 +0200344 self.assertEqual(rx[IP].dst, self.pg1.remote_ip4)
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200345 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200350 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi3f1964d2019-08-22 18:40:28 +0200351
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000352 #
353 # IPv6
354 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200355 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 Kazmi0b042092020-04-17 16:50:56 +0000361
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200362 rxs = self.send_and_expect(self.pg4, 5 * [p64], self.pg1, 170)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000363 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 Kazmiadf62092020-05-28 20:49:46 +0200369 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200373 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000374
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200375 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 Kazmi1ab8b3c2020-05-05 10:31:17 +0000381
Dmitry Valter34fa0ce2024-03-11 10:38:46 +0000382 @unittest.skipIf(
383 "vxlan" in config.excluded_plugins, "Exclude tests requiring VXLAN plugin"
384 )
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000385 def test_gso_vxlan(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200386 """GSO VXLAN test"""
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000387 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 Kazmi84f91fa2020-04-23 17:59:49 +0200393
394 #
395 # enable ipv4/vxlan
396 #
397 self.vxlan.add_vpp_config()
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000398 self.vapi.sw_interface_set_l2_bridge(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200399 rx_sw_if_index=self.vxlan.sw_if_index, bd_id=self.single_tunnel_bd
400 )
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000401 self.vapi.sw_interface_set_l2_bridge(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200402 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 Kazmi0b042092020-04-17 16:50:56 +0000407
408 #
409 # IPv4/IPv4 - VXLAN
410 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200411 p45 = (
Steven Luonge4238aa2024-04-19 09:49:20 -0700412 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200413 / 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 Kazmi0b042092020-04-17 16:50:56 +0000417
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200418 rxs = self.send_and_expect(self.pg2, 5 * [p45], self.pg0, 225)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000419 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 Kazmiadf62092020-05-28 20:49:46 +0200425 self.assert_ip_checksum_valid(rx)
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000426 self.assert_udp_checksum_valid(rx, ignore_zero_checksum=True)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000427 self.assertEqual(rx[VXLAN].vni, 10)
428 inner = rx[VXLAN].payload
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200429 self.assertEqual(rx[IP].len - 20 - 8 - 8, len(inner))
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000430 self.assertEqual(inner[Ether].src, self.pg2.remote_mac)
Steven Luonge4238aa2024-04-19 09:49:20 -0700431 self.assertEqual(inner[Ether].dst, self.pg2.local_mac)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000432 self.assertEqual(inner[IP].src, self.pg2.remote_ip4)
433 self.assertEqual(inner[IP].dst, "172.16.3.3")
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200434 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200439 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000440
441 #
442 # IPv4/IPv6 - VXLAN
443 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200444 p65 = (
Steven Luonge4238aa2024-04-19 09:49:20 -0700445 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200446 / IPv6(src=self.pg2.remote_ip6, dst="fd01:3::3")
447 / TCP(sport=1234, dport=1234)
448 / Raw(b"\xa5" * 65200)
449 )
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000450
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200451 rxs = self.send_and_expect(self.pg2, 5 * [p65], self.pg0, 225)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000452 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 Kazmiadf62092020-05-28 20:49:46 +0200458 self.assert_ip_checksum_valid(rx)
Mohsin Kazmi7b3339e2022-09-29 15:28:04 +0000459 self.assert_udp_checksum_valid(rx, ignore_zero_checksum=True)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000460 self.assertEqual(rx[VXLAN].vni, 10)
461 inner = rx[VXLAN].payload
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200462 self.assertEqual(rx[IP].len - 20 - 8 - 8, len(inner))
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000463 self.assertEqual(inner[Ether].src, self.pg2.remote_mac)
Steven Luonge4238aa2024-04-19 09:49:20 -0700464 self.assertEqual(inner[Ether].dst, self.pg2.local_mac)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000465 self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6)
466 self.assertEqual(inner[IPv6].dst, "fd01:3::3")
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200467 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200471 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000472
473 #
474 # disable ipv4/vxlan
475 #
476 self.vxlan.remove_vpp_config()
477
478 #
479 # enable ipv6/vxlan
480 #
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200481 self.vxlan2.add_vpp_config()
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000482 self.vapi.sw_interface_set_l2_bridge(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200483 rx_sw_if_index=self.vxlan2.sw_if_index, bd_id=self.single_tunnel_bd
484 )
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000485
486 #
487 # IPv6/IPv4 - VXLAN
488 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200489 p46 = (
Steven Luonge4238aa2024-04-19 09:49:20 -0700490 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200491 / 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 Kazmi0b042092020-04-17 16:50:56 +0000495
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200496 rxs = self.send_and_expect(self.pg2, 5 * [p46], self.pg0, 225)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000497 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 Isaev698eb872020-05-21 16:34:17 +0300503 self.assert_udp_checksum_valid(rx, ignore_zero_checksum=False)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000504 self.assertEqual(rx[VXLAN].vni, 10)
505 inner = rx[VXLAN].payload
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200506 self.assertEqual(rx[IPv6].plen - 8 - 8, len(inner))
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000507 self.assertEqual(inner[Ether].src, self.pg2.remote_mac)
Steven Luonge4238aa2024-04-19 09:49:20 -0700508 self.assertEqual(inner[Ether].dst, self.pg2.local_mac)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000509 self.assertEqual(inner[IP].src, self.pg2.remote_ip4)
510 self.assertEqual(inner[IP].dst, "172.16.3.3")
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200511 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200516 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000517
518 #
519 # IPv6/IPv6 - VXLAN
520 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200521 p66 = (
Steven Luonge4238aa2024-04-19 09:49:20 -0700522 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200523 / IPv6(src=self.pg2.remote_ip6, dst="fd01:3::3")
524 / TCP(sport=1234, dport=1234)
525 / Raw(b"\xa5" * 65200)
526 )
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000527
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200528 rxs = self.send_and_expect(self.pg2, 5 * [p66], self.pg0, 225)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000529 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 Isaev698eb872020-05-21 16:34:17 +0300535 self.assert_udp_checksum_valid(rx, ignore_zero_checksum=False)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000536 self.assertEqual(rx[VXLAN].vni, 10)
537 inner = rx[VXLAN].payload
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200538 self.assertEqual(rx[IPv6].plen - 8 - 8, len(inner))
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000539 self.assertEqual(inner[Ether].src, self.pg2.remote_mac)
Steven Luonge4238aa2024-04-19 09:49:20 -0700540 self.assertEqual(inner[Ether].dst, self.pg2.local_mac)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000541 self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6)
542 self.assertEqual(inner[IPv6].dst, "fd01:3::3")
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200543 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200547 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi0b042092020-04-17 16:50:56 +0000548
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200549 #
550 # disable ipv4/vxlan
551 #
552 self.vxlan2.remove_vpp_config()
553
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200554 self.vapi.feature_gso_enable_disable(
555 sw_if_index=self.pg0.sw_if_index, enable_disable=0
556 )
Mohsin Kazmi1ab8b3c2020-05-05 10:31:17 +0000557
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200558 def test_gso_ipip(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200559 """GSO IPIP test"""
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200560 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200565 self.vapi.feature_gso_enable_disable(
566 sw_if_index=self.pg0.sw_if_index, enable_disable=1
567 )
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200568
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 Sekerad9b0c6f2022-04-26 19:02:15 +0200580 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 Kazmi84f91fa2020-04-23 17:59:49 +0200591 self.ip4_via_ip4_tunnel.add_vpp_config()
592
593 #
594 # IPv4/IPv4 - IPIP
595 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200596 p47 = (
Steven Luonge4238aa2024-04-19 09:49:20 -0700597 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200598 / 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 Kazmi84f91fa2020-04-23 17:59:49 +0200602
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200603 rxs = self.send_and_expect(self.pg2, 5 * [p47], self.pg0, 225)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200604 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 Kazmiadf62092020-05-28 20:49:46 +0200610 self.assert_ip_checksum_valid(rx)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200611 self.assertEqual(rx[IP].proto, 4) # ipencap
612 inner = rx[IP].payload
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200613 self.assertEqual(rx[IP].len - 20, len(inner))
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200614 self.assertEqual(inner[IP].src, self.pg2.remote_ip4)
615 self.assertEqual(inner[IP].dst, "172.16.10.3")
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200616 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200621 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200622
623 self.ip6_via_ip4_tunnel = VppIpRoute(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200624 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 Kazmi84f91fa2020-04-23 17:59:49 +0200635 self.ip6_via_ip4_tunnel.add_vpp_config()
636 #
637 # IPv4/IPv6 - IPIP
638 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200639 p67 = (
Steven Luonge4238aa2024-04-19 09:49:20 -0700640 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200641 / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3")
642 / TCP(sport=1234, dport=1234)
643 / Raw(b"\xa5" * 65200)
644 )
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200645
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200646 rxs = self.send_and_expect(self.pg2, 5 * [p67], self.pg0, 225)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200647 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 Kazmiadf62092020-05-28 20:49:46 +0200653 self.assert_ip_checksum_valid(rx)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200654 self.assertEqual(rx[IP].proto, 41) # ipv6
655 inner = rx[IP].payload
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200656 self.assertEqual(rx[IP].len - 20, len(inner))
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200657 self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6)
658 self.assertEqual(inner[IPv6].dst, "fd01:10::3")
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200659 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200663 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200664
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 Troan5c2a2372020-11-19 16:01:23 +0100670 self.vapi.feature_gso_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200671 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 Kazmi84f91fa2020-04-23 17:59:49 +0200676
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200677 rxs = self.send_and_expect(self.pg2, 5 * [p47], self.pg0, 225)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200678 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 Kazmiadf62092020-05-28 20:49:46 +0200684 self.assert_ip_checksum_valid(rx)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200685 self.assertEqual(rx[IP].proto, 4) # ipencap
686 inner = rx[IP].payload
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200687 self.assertEqual(rx[IP].len - 20, len(inner))
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200688 self.assertEqual(inner[IP].src, self.pg2.remote_ip4)
689 self.assertEqual(inner[IP].dst, "172.16.10.3")
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200690 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200695 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200696
697 #
698 # disable ipip4
699 #
Ole Troan5c2a2372020-11-19 16:01:23 +0100700 self.vapi.feature_gso_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200701 sw_if_index=self.ipip4.sw_if_index, enable_disable=0
702 )
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200703 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200710 self.vapi.feature_gso_enable_disable(
711 sw_if_index=self.pg0.sw_if_index, enable_disable=1
712 )
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200713 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200721 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 Kazmi84f91fa2020-04-23 17:59:49 +0200732 self.ip4_via_ip6_tunnel.add_vpp_config()
733
734 #
735 # IPv6/IPv4 - IPIP
736 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200737 p48 = (
Steven Luonge4238aa2024-04-19 09:49:20 -0700738 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200739 / 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 Kazmi84f91fa2020-04-23 17:59:49 +0200743
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200744 rxs = self.send_and_expect(self.pg2, 5 * [p48], self.pg0, 225)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200745 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 Kazmiadf62092020-05-28 20:49:46 +0200753 self.assertEqual(rx[IPv6].plen, len(inner))
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200754 self.assertEqual(inner[IP].src, self.pg2.remote_ip4)
755 self.assertEqual(inner[IP].dst, "172.16.10.3")
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200756 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200761 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200762
763 self.ip6_via_ip6_tunnel = VppIpRoute(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200764 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 Kazmi84f91fa2020-04-23 17:59:49 +0200775 self.ip6_via_ip6_tunnel.add_vpp_config()
776
777 #
778 # IPv6/IPv6 - IPIP
779 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200780 p68 = (
Steven Luonge4238aa2024-04-19 09:49:20 -0700781 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200782 / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3")
783 / TCP(sport=1234, dport=1234)
784 / Raw(b"\xa5" * 65200)
785 )
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200786
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200787 rxs = self.send_and_expect(self.pg2, 5 * [p68], self.pg0, 225)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200788 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 Kazmiadf62092020-05-28 20:49:46 +0200796 self.assertEqual(rx[IPv6].plen, len(inner))
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200797 self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6)
798 self.assertEqual(inner[IPv6].dst, "fd01:10::3")
Mohsin Kazmiadf62092020-05-28 20:49:46 +0200799 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200803 self.assertEqual(size, 65200 * 5)
Mohsin Kazmi84f91fa2020-04-23 17:59:49 +0200804
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 Sekerad9b0c6f2022-04-26 19:02:15 +0200812 self.vapi.feature_gso_enable_disable(
813 sw_if_index=self.pg0.sw_if_index, enable_disable=0
814 )
Mohsin Kazmi1ab8b3c2020-05-05 10:31:17 +0000815
Arthur de Kerhor2f4586d2021-09-22 14:53:24 +0200816 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 Luonge4238aa2024-04-19 09:49:20 -0700849 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Arthur de Kerhor2f4586d2021-09-22 14:53:24 +0200850 / 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 Luonge4238aa2024-04-19 09:49:20 -0700959 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Arthur de Kerhor2f4586d2021-09-22 14:53:24 +0200960 / 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 Kazmi0972edc2021-07-09 14:19:37 +02001012 def test_gso_ipsec(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001013 """GSO IPSEC test"""
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001014 #
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 Sekerad9b0c6f2022-04-26 19:02:15 +02001024 sw_if_index=self.ipip4.sw_if_index, enable_disable=1
1025 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001026
1027 # Add IPv4 routes via tunnel interface
1028 self.ip4_via_ip4_tunnel = VppIpRoute(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001029 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 Kazmi0972edc2021-07-09 14:19:37 +02001040 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 Sekerad9b0c6f2022-04-26 19:02:15 +02001047 self.tun_sa_in_v4 = VppIpsecSA(
1048 self,
Arthur de Kerhor0df06b62022-11-16 18:45:24 +01001049 self.ipv4_params.scapy_tun_sa_id,
1050 self.ipv4_params.scapy_tun_spi,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001051 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 Kazmi0972edc2021-07-09 14:19:37 +02001057 self.tun_sa_in_v4.add_vpp_config()
1058
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001059 self.tun_sa_out_v4 = VppIpsecSA(
1060 self,
Arthur de Kerhor0df06b62022-11-16 18:45:24 +01001061 self.ipv4_params.vpp_tun_sa_id,
1062 self.ipv4_params.vpp_tun_spi,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001063 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 Kazmi0972edc2021-07-09 14:19:37 +02001069 self.tun_sa_out_v4.add_vpp_config()
1070
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001071 self.tun_protect_v4 = VppIpsecTunProtect(
1072 self, self.ipip4, self.tun_sa_out_v4, [self.tun_sa_in_v4]
1073 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001074
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 Sekerad9b0c6f2022-04-26 19:02:15 +02001084 ipsec44 = (
Steven Luonge4238aa2024-04-19 09:49:20 -07001085 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001086 / 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 Kazmi0972edc2021-07-09 14:19:37 +02001090
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 Kerhor0df06b62022-11-16 18:45:24 +01001099 self.assertEqual(rx[ESP].spi, self.ipv4_params.vpp_tun_spi)
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001100 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 Sekerad9b0c6f2022-04-26 19:02:15 +02001107 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 Kazmi0972edc2021-07-09 14:19:37 +02001118 self.ip6_via_ip4_tunnel.add_vpp_config()
1119 #
1120 # IPv4/IPv6 - IPSEC
1121 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001122 ipsec46 = (
Steven Luonge4238aa2024-04-19 09:49:20 -07001123 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001124 / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3")
1125 / TCP(sport=1234, dport=1234)
1126 / Raw(b"\xa5" * 65200)
1127 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001128
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 Kerhor0df06b62022-11-16 18:45:24 +01001137 self.assertEqual(rx[ESP].spi, self.ipv4_params.vpp_tun_spi)
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001138 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 Sekerad9b0c6f2022-04-26 19:02:15 +02001152 self.vapi.feature_gso_enable_disable(self.ipip4.sw_if_index, enable_disable=0)
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001153 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 Sekerad9b0c6f2022-04-26 19:02:15 +02001161 self.vapi.feature_gso_enable_disable(self.ipip6.sw_if_index, enable_disable=1)
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001162
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 Sekerad9b0c6f2022-04-26 19:02:15 +02001169 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 Kazmi0972edc2021-07-09 14:19:37 +02001180 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 Sekerad9b0c6f2022-04-26 19:02:15 +02001186 self.tun_sa_in_v6 = VppIpsecSA(
1187 self,
Arthur de Kerhor0df06b62022-11-16 18:45:24 +01001188 self.ipv6_params.scapy_tun_sa_id,
1189 self.ipv6_params.scapy_tun_spi,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001190 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 Kazmi0972edc2021-07-09 14:19:37 +02001196 self.tun_sa_in_v6.add_vpp_config()
1197
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001198 self.tun_sa_out_v6 = VppIpsecSA(
1199 self,
Arthur de Kerhor0df06b62022-11-16 18:45:24 +01001200 self.ipv6_params.vpp_tun_sa_id,
1201 self.ipv6_params.vpp_tun_spi,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001202 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 Kazmi0972edc2021-07-09 14:19:37 +02001208 self.tun_sa_out_v6.add_vpp_config()
1209
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001210 self.tun_protect_v6 = VppIpsecTunProtect(
1211 self, self.ipip6, self.tun_sa_out_v6, [self.tun_sa_in_v6]
1212 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001213
1214 self.tun_protect_v6.add_vpp_config()
1215
1216 #
1217 # IPv6/IPv4 - IPSEC
1218 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001219 ipsec64 = (
Steven Luonge4238aa2024-04-19 09:49:20 -07001220 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001221 / 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 Kazmi0972edc2021-07-09 14:19:37 +02001225
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 Kerhor0df06b62022-11-16 18:45:24 +01001234 self.assertEqual(rx[ESP].spi, self.ipv6_params.vpp_tun_spi)
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001235 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 Sekerad9b0c6f2022-04-26 19:02:15 +02001242 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 Kazmi0972edc2021-07-09 14:19:37 +02001253 self.ip6_via_ip6_tunnel.add_vpp_config()
1254
1255 #
1256 # IPv6/IPv6 - IPSEC
1257 #
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001258 ipsec66 = (
Steven Luonge4238aa2024-04-19 09:49:20 -07001259 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001260 / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3")
1261 / TCP(sport=1234, dport=1234)
1262 / Raw(b"\xa5" * 65200)
1263 )
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001264
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 Kerhor0df06b62022-11-16 18:45:24 +01001273 self.assertEqual(rx[ESP].spi, self.ipv6_params.vpp_tun_spi)
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001274 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 Sekerad9b0c6f2022-04-26 19:02:15 +02001292 self.vapi.feature_gso_enable_disable(self.pg0.sw_if_index, enable_disable=0)
Mohsin Kazmi0972edc2021-07-09 14:19:37 +02001293
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001294
1295if __name__ == "__main__":
Mohsin Kazmi22e9cfd2019-07-23 11:54:48 +02001296 unittest.main(testRunner=VppTestRunner)