blob: cef94f3dda6a6d9c0d507bd26e1e68ddc3882030 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Paul Vinciguerraf1f2aa62018-11-25 08:36:47 -08002
Klement Sekera75e7d132017-09-20 08:26:30 +02003import unittest
Klement Sekera630ab582019-07-19 09:14:19 +00004from random import shuffle, choice, randrange
Klement Sekera75e7d132017-09-20 08:26:30 +02005
Klement Sekera947a85c2019-07-24 12:40:37 +00006from framework import VppTestCase, VppTestRunner
7
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -07008import scapy.compat
Klement Sekera75e7d132017-09-20 08:26:30 +02009from scapy.packet import Raw
10from scapy.layers.l2 import Ether, GRE
Klement Sekera01c1fa42021-12-14 18:25:11 +000011from scapy.layers.inet import IP, UDP, ICMP, icmptypes
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020012from scapy.layers.inet6 import (
13 HBHOptUnknown,
14 ICMPv6ParamProblem,
15 ICMPv6TimeExceeded,
16 IPv6,
17 IPv6ExtHdrFragment,
18 IPv6ExtHdrHopByHop,
19 IPv6ExtHdrDestOpt,
20 PadN,
21 ICMPv6EchoRequest,
22 ICMPv6EchoReply,
23)
Paul Vinciguerra69555952019-03-01 08:46:29 -080024from framework import VppTestCase, VppTestRunner
Klement Sekera630ab582019-07-19 09:14:19 +000025from util import ppp, ppc, fragment_rfc791, fragment_rfc8200
Neale Ranns5a8844b2019-04-16 07:15:35 +000026from vpp_gre_interface import VppGreInterface
Neale Rannsc0a93142018-09-05 15:42:26 -070027from vpp_ip import DpoProto
Neale Ranns097fa662018-05-01 05:17:55 -070028from vpp_ip_route import VppIpRoute, VppRoutePath, FibPathProto
Klement Sekera896c8962019-06-24 11:52:49 +000029from vpp_papi import VppEnum
Klement Sekera75e7d132017-09-20 08:26:30 +020030
Klement Sekerad0f70a32018-12-14 17:24:13 +010031# 35 is enough to have >257 400-byte fragments
32test_packet_count = 35
Klement Sekera75e7d132017-09-20 08:26:30 +020033
34
Klement Sekera947a85c2019-07-24 12:40:37 +000035class TestIPv4Reassembly(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020036 """IPv4 Reassembly"""
Klement Sekera75e7d132017-09-20 08:26:30 +020037
38 @classmethod
39 def setUpClass(cls):
Klement Sekera01c1fa42021-12-14 18:25:11 +000040 super().setUpClass()
Klement Sekera75e7d132017-09-20 08:26:30 +020041
Klement Sekera4c533132018-02-22 11:41:12 +010042 cls.create_pg_interfaces([0, 1])
43 cls.src_if = cls.pg0
44 cls.dst_if = cls.pg1
Klement Sekera75e7d132017-09-20 08:26:30 +020045
46 # setup all interfaces
47 for i in cls.pg_interfaces:
48 i.admin_up()
49 i.config_ip4()
50 i.resolve_arp()
51
Klement Sekera75e7d132017-09-20 08:26:30 +020052 # packet sizes
53 cls.packet_sizes = [64, 512, 1518, 9018]
54 cls.padding = " abcdefghijklmn"
55 cls.create_stream(cls.packet_sizes)
56 cls.create_fragments()
57
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070058 @classmethod
59 def tearDownClass(cls):
Klement Sekera01c1fa42021-12-14 18:25:11 +000060 super().tearDownClass()
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070061
Klement Sekera75e7d132017-09-20 08:26:30 +020062 def setUp(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020063 """Test setup - force timeout on existing reassemblies"""
Klement Sekera01c1fa42021-12-14 18:25:11 +000064 super().setUp()
Klement Sekera4c533132018-02-22 11:41:12 +010065 self.vapi.ip_reassembly_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020066 sw_if_index=self.src_if.sw_if_index, enable_ip4=True
67 )
68 self.vapi.ip_reassembly_set(
69 timeout_ms=0,
70 max_reassemblies=1000,
71 max_reassembly_length=1000,
72 expire_walk_interval_ms=10,
73 )
74 self.virtual_sleep(0.25)
75 self.vapi.ip_reassembly_set(
76 timeout_ms=1000000,
77 max_reassemblies=1000,
78 max_reassembly_length=1000,
79 expire_walk_interval_ms=10000,
80 )
Klement Sekera75e7d132017-09-20 08:26:30 +020081
82 def tearDown(self):
Klement Sekera01c1fa42021-12-14 18:25:11 +000083 self.vapi.ip_reassembly_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020084 sw_if_index=self.src_if.sw_if_index, enable_ip4=False
85 )
Klement Sekera01c1fa42021-12-14 18:25:11 +000086 super().tearDown()
Paul Vinciguerra90cf21b2019-03-13 09:23:05 -070087
88 def show_commands_at_teardown(self):
Klement Sekera896c8962019-06-24 11:52:49 +000089 self.logger.debug(self.vapi.ppcli("show ip4-full-reassembly details"))
Klement Sekeracae98b72019-02-19 13:53:43 +010090 self.logger.debug(self.vapi.ppcli("show buffers"))
Klement Sekera75e7d132017-09-20 08:26:30 +020091
92 @classmethod
93 def create_stream(cls, packet_sizes, packet_count=test_packet_count):
Klement Sekerad0f70a32018-12-14 17:24:13 +010094 """Create input packet stream
Klement Sekera75e7d132017-09-20 08:26:30 +020095
96 :param list packet_sizes: Required packet sizes.
97 """
98 for i in range(0, packet_count):
Klement Sekera4c533132018-02-22 11:41:12 +010099 info = cls.create_packet_info(cls.src_if, cls.src_if)
Klement Sekera75e7d132017-09-20 08:26:30 +0200100 payload = cls.info_to_payload(info)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200101 p = (
102 Ether(dst=cls.src_if.local_mac, src=cls.src_if.remote_mac)
103 / IP(
104 id=info.index, src=cls.src_if.remote_ip4, dst=cls.dst_if.remote_ip4
105 )
106 / UDP(sport=1234, dport=5678)
107 / Raw(payload)
108 )
Klement Sekera75e7d132017-09-20 08:26:30 +0200109 size = packet_sizes[(i // 2) % len(packet_sizes)]
110 cls.extend_packet(p, size, cls.padding)
111 info.data = p
112
113 @classmethod
114 def create_fragments(cls):
115 infos = cls._packet_infos
116 cls.pkt_infos = []
Paul Vinciguerra090096b2020-12-03 00:42:46 -0500117 for index, info in infos.items():
Klement Sekera75e7d132017-09-20 08:26:30 +0200118 p = info.data
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700119 # cls.logger.debug(ppp("Packet:",
120 # p.__class__(scapy.compat.raw(p))))
Klement Sekera75e7d132017-09-20 08:26:30 +0200121 fragments_400 = fragment_rfc791(p, 400)
122 fragments_300 = fragment_rfc791(p, 300)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200123 fragments_200 = [x for f in fragments_400 for x in fragment_rfc791(f, 200)]
124 cls.pkt_infos.append((index, fragments_400, fragments_300, fragments_200))
125 cls.fragments_400 = [x for (_, frags, _, _) in cls.pkt_infos for x in frags]
126 cls.fragments_300 = [x for (_, _, frags, _) in cls.pkt_infos for x in frags]
127 cls.fragments_200 = [x for (_, _, _, frags) in cls.pkt_infos for x in frags]
128 cls.logger.debug(
129 "Fragmented %s packets into %s 400-byte fragments, "
130 "%s 300-byte fragments and %s 200-byte fragments"
131 % (
132 len(infos),
133 len(cls.fragments_400),
134 len(cls.fragments_300),
135 len(cls.fragments_200),
136 )
137 )
Klement Sekera75e7d132017-09-20 08:26:30 +0200138
Klement Sekera947a85c2019-07-24 12:40:37 +0000139 def verify_capture(self, capture, dropped_packet_indexes=[]):
140 """Verify captured packet stream.
141
142 :param list capture: Captured packet stream.
143 """
144 info = None
145 seen = set()
146 for packet in capture:
147 try:
148 self.logger.debug(ppp("Got packet:", packet))
149 ip = packet[IP]
150 udp = packet[UDP]
151 payload_info = self.payload_to_info(packet[Raw])
152 packet_index = payload_info.index
153 self.assertTrue(
154 packet_index not in dropped_packet_indexes,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200155 ppp("Packet received, but should be dropped:", packet),
156 )
Klement Sekera947a85c2019-07-24 12:40:37 +0000157 if packet_index in seen:
158 raise Exception(ppp("Duplicate packet received", packet))
159 seen.add(packet_index)
160 self.assertEqual(payload_info.dst, self.src_if.sw_if_index)
161 info = self._packet_infos[packet_index]
162 self.assertTrue(info is not None)
163 self.assertEqual(packet_index, info.index)
164 saved_packet = info.data
165 self.assertEqual(ip.src, saved_packet[IP].src)
166 self.assertEqual(ip.dst, saved_packet[IP].dst)
167 self.assertEqual(udp.payload, saved_packet[UDP].payload)
168 except Exception:
169 self.logger.error(ppp("Unexpected or invalid packet:", packet))
170 raise
171 for index in self._packet_infos:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200172 self.assertTrue(
173 index in seen or index in dropped_packet_indexes,
174 "Packet with packet_index %d not received" % index,
175 )
Klement Sekera947a85c2019-07-24 12:40:37 +0000176
177 def test_reassembly(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200178 """basic reassembly"""
Klement Sekera75e7d132017-09-20 08:26:30 +0200179
Klement Sekera947a85c2019-07-24 12:40:37 +0000180 self.pg_enable_capture()
181 self.src_if.add_stream(self.fragments_200)
182 self.pg_start()
183
184 packets = self.dst_if.get_capture(len(self.pkt_infos))
185 self.verify_capture(packets)
186 self.src_if.assert_nothing_captured()
187
188 # run it all again to verify correctness
189 self.pg_enable_capture()
190 self.src_if.add_stream(self.fragments_200)
191 self.pg_start()
192
193 packets = self.dst_if.get_capture(len(self.pkt_infos))
194 self.verify_capture(packets)
195 self.src_if.assert_nothing_captured()
196
Klement Sekera53be16d2020-12-15 21:47:36 +0100197 def test_verify_clear_trace_mid_reassembly(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200198 """verify clear trace works mid-reassembly"""
Klement Sekera53be16d2020-12-15 21:47:36 +0100199
200 self.pg_enable_capture()
201 self.src_if.add_stream(self.fragments_200[0:-1])
202 self.pg_start()
203
204 self.logger.debug(self.vapi.cli("show trace"))
205 self.vapi.cli("clear trace")
206
207 self.src_if.add_stream(self.fragments_200[-1])
208 self.pg_start()
209 packets = self.dst_if.get_capture(len(self.pkt_infos))
210 self.verify_capture(packets)
211
Klement Sekera947a85c2019-07-24 12:40:37 +0000212 def test_reversed(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200213 """reverse order reassembly"""
Klement Sekera75e7d132017-09-20 08:26:30 +0200214
Klement Sekera947a85c2019-07-24 12:40:37 +0000215 fragments = list(self.fragments_200)
216 fragments.reverse()
217
218 self.pg_enable_capture()
219 self.src_if.add_stream(fragments)
220 self.pg_start()
221
222 packets = self.dst_if.get_capture(len(self.packet_infos))
223 self.verify_capture(packets)
224 self.src_if.assert_nothing_captured()
225
226 # run it all again to verify correctness
227 self.pg_enable_capture()
228 self.src_if.add_stream(fragments)
229 self.pg_start()
230
231 packets = self.dst_if.get_capture(len(self.packet_infos))
232 self.verify_capture(packets)
233 self.src_if.assert_nothing_captured()
Klement Sekera75e7d132017-09-20 08:26:30 +0200234
Klement Sekera3a343d42019-05-16 14:35:46 +0200235 def test_long_fragment_chain(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200236 """long fragment chain"""
Klement Sekera3a343d42019-05-16 14:35:46 +0200237
Neale Rannse22a7042022-08-09 03:03:29 +0000238 error_cnt_str = "/err/ip4-full-reassembly-feature/reass_fragment_chain_too_long"
Klement Sekera3a343d42019-05-16 14:35:46 +0200239
Klement Sekera34641f22019-05-22 20:18:26 +0200240 error_cnt = self.statistics.get_err_counter(error_cnt_str)
Klement Sekera3a343d42019-05-16 14:35:46 +0200241
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200242 self.vapi.ip_reassembly_set(
243 timeout_ms=100,
244 max_reassemblies=1000,
245 max_reassembly_length=3,
246 expire_walk_interval_ms=50,
247 )
Klement Sekera3a343d42019-05-16 14:35:46 +0200248
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200249 p1 = (
250 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
251 / IP(id=1000, src=self.src_if.remote_ip4, dst=self.dst_if.remote_ip4)
252 / UDP(sport=1234, dport=5678)
253 / Raw(b"X" * 1000)
254 )
255 p2 = (
256 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
257 / IP(id=1001, src=self.src_if.remote_ip4, dst=self.dst_if.remote_ip4)
258 / UDP(sport=1234, dport=5678)
259 / Raw(b"X" * 1000)
260 )
Klement Sekera3a343d42019-05-16 14:35:46 +0200261 frags = fragment_rfc791(p1, 200) + fragment_rfc791(p2, 500)
262
263 self.pg_enable_capture()
264 self.src_if.add_stream(frags)
265 self.pg_start()
266
267 self.dst_if.get_capture(1)
Klement Sekera34641f22019-05-22 20:18:26 +0200268 self.assert_error_counter_equal(error_cnt_str, error_cnt + 1)
Klement Sekera3a343d42019-05-16 14:35:46 +0200269
Klement Sekera14d7e902018-12-10 13:46:09 +0100270 def test_5737(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200271 """fragment length + ip header size > 65535"""
Klement Sekera4ee633e2018-12-14 12:00:44 +0100272 self.vapi.cli("clear errors")
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200273 raw = b"""E\x00\x00\x88,\xf8\x1f\xfe@\x01\x98\x00\xc0\xa8\n-\xc0\xa8\n\
Ole Troan127fbec2019-10-18 15:22:56 +0200274\x01\x08\x00\xf0J\xed\xcb\xf1\xf5Test-group: IPv4.IPv4.ipv4-message.\
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200275Ethernet-Payload.IPv4-Packet.IPv4-Header.Fragment-Offset; Test-case: 5737"""
276 malformed_packet = Ether(
277 dst=self.src_if.local_mac, src=self.src_if.remote_mac
278 ) / IP(raw)
279 p = (
280 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
281 / IP(id=1000, src=self.src_if.remote_ip4, dst=self.dst_if.remote_ip4)
282 / UDP(sport=1234, dport=5678)
283 / Raw(b"X" * 1000)
284 )
Klement Sekera14d7e902018-12-10 13:46:09 +0100285 valid_fragments = fragment_rfc791(p, 400)
286
Neale Rannse22a7042022-08-09 03:03:29 +0000287 counter = "/err/ip4-full-reassembly-feature/reass_malformed_packet"
Ole Troan127fbec2019-10-18 15:22:56 +0200288 error_counter = self.statistics.get_err_counter(counter)
Klement Sekera14d7e902018-12-10 13:46:09 +0100289 self.pg_enable_capture()
290 self.src_if.add_stream([malformed_packet] + valid_fragments)
291 self.pg_start()
292
293 self.dst_if.get_capture(1)
Klement Sekera896c8962019-06-24 11:52:49 +0000294 self.logger.debug(self.vapi.ppcli("show error"))
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200295 self.assertEqual(self.statistics.get_err_counter(counter), error_counter + 1)
Klement Sekera14d7e902018-12-10 13:46:09 +0100296
Klement Sekera400f6d82018-12-13 14:35:48 +0100297 def test_44924(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200298 """compress tiny fragments"""
299 packets = [
300 (
301 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
302 / IP(
303 id=24339,
304 flags="MF",
305 frag=0,
306 ttl=64,
307 src=self.src_if.remote_ip4,
308 dst=self.dst_if.remote_ip4,
309 )
310 / ICMP(type="echo-request", code=0, id=0x1FE6, seq=0x2407)
311 / Raw(load="Test-group: IPv4")
312 ),
313 (
314 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
315 / IP(
316 id=24339,
317 flags="MF",
318 frag=3,
319 ttl=64,
320 src=self.src_if.remote_ip4,
321 dst=self.dst_if.remote_ip4,
322 )
323 / ICMP(type="echo-request", code=0, id=0x1FE6, seq=0x2407)
324 / Raw(load=".IPv4.Fragmentation.vali")
325 ),
326 (
327 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
328 / IP(
329 id=24339,
330 frag=6,
331 ttl=64,
332 src=self.src_if.remote_ip4,
333 dst=self.dst_if.remote_ip4,
334 )
335 / ICMP(type="echo-request", code=0, id=0x1FE6, seq=0x2407)
336 / Raw(load="d; Test-case: 44924")
337 ),
338 ]
Klement Sekera400f6d82018-12-13 14:35:48 +0100339
340 self.pg_enable_capture()
341 self.src_if.add_stream(packets)
342 self.pg_start()
343
344 self.dst_if.get_capture(1)
345
Klement Sekera4ee633e2018-12-14 12:00:44 +0100346 def test_frag_1(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200347 """fragment of size 1"""
Klement Sekera4ee633e2018-12-14 12:00:44 +0100348 self.vapi.cli("clear errors")
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200349 malformed_packets = [
350 (
351 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
352 / IP(
353 id=7,
354 len=21,
355 flags="MF",
356 frag=0,
357 ttl=64,
358 src=self.src_if.remote_ip4,
359 dst=self.dst_if.remote_ip4,
360 )
361 / ICMP(type="echo-request")
362 ),
363 (
364 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
365 / IP(
366 id=7,
367 len=21,
368 frag=1,
369 ttl=64,
370 src=self.src_if.remote_ip4,
371 dst=self.dst_if.remote_ip4,
372 )
373 / Raw(load=b"\x08")
374 ),
375 ]
Klement Sekera4ee633e2018-12-14 12:00:44 +0100376
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200377 p = (
378 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
379 / IP(id=1000, src=self.src_if.remote_ip4, dst=self.dst_if.remote_ip4)
380 / UDP(sport=1234, dport=5678)
381 / Raw(b"X" * 1000)
382 )
Klement Sekera4ee633e2018-12-14 12:00:44 +0100383 valid_fragments = fragment_rfc791(p, 400)
384
385 self.pg_enable_capture()
386 self.src_if.add_stream(malformed_packets + valid_fragments)
387 self.pg_start()
388
389 self.dst_if.get_capture(1)
390
Klement Sekera896c8962019-06-24 11:52:49 +0000391 self.assert_packet_counter_equal("ip4-full-reassembly-feature", 1)
Klement Sekera4ee633e2018-12-14 12:00:44 +0100392 # TODO remove above, uncomment below once clearing of counters
393 # is supported
394 # self.assert_packet_counter_equal(
Neale Rannse22a7042022-08-09 03:03:29 +0000395 # "/err/ip4-full-reassembly-feature/reass_malformed_packet", 1)
Klement Sekera4ee633e2018-12-14 12:00:44 +0100396
Klement Sekera947a85c2019-07-24 12:40:37 +0000397 def test_random(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200398 """random order reassembly"""
Klement Sekera947a85c2019-07-24 12:40:37 +0000399
400 fragments = list(self.fragments_200)
401 shuffle(fragments)
402
403 self.pg_enable_capture()
404 self.src_if.add_stream(fragments)
405 self.pg_start()
406
407 packets = self.dst_if.get_capture(len(self.packet_infos))
408 self.verify_capture(packets)
409 self.src_if.assert_nothing_captured()
410
411 # run it all again to verify correctness
412 self.pg_enable_capture()
413 self.src_if.add_stream(fragments)
414 self.pg_start()
415
416 packets = self.dst_if.get_capture(len(self.packet_infos))
417 self.verify_capture(packets)
418 self.src_if.assert_nothing_captured()
419
420 def test_duplicates(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200421 """duplicate fragments"""
Klement Sekera947a85c2019-07-24 12:40:37 +0000422
Klement Sekera75e7d132017-09-20 08:26:30 +0200423 fragments = [
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200424 x
425 for (_, frags, _, _) in self.pkt_infos
Klement Sekera75e7d132017-09-20 08:26:30 +0200426 for x in frags
427 for _ in range(0, min(2, len(frags)))
428 ]
Klement Sekera947a85c2019-07-24 12:40:37 +0000429
430 self.pg_enable_capture()
431 self.src_if.add_stream(fragments)
432 self.pg_start()
433
434 packets = self.dst_if.get_capture(len(self.pkt_infos))
435 self.verify_capture(packets)
436 self.src_if.assert_nothing_captured()
Klement Sekera75e7d132017-09-20 08:26:30 +0200437
438 def test_overlap1(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200439 """overlapping fragments case #1"""
Klement Sekera75e7d132017-09-20 08:26:30 +0200440
441 fragments = []
442 for _, _, frags_300, frags_200 in self.pkt_infos:
443 if len(frags_300) == 1:
444 fragments.extend(frags_300)
445 else:
446 for i, j in zip(frags_200, frags_300):
447 fragments.extend(i)
448 fragments.extend(j)
449
450 self.pg_enable_capture()
Klement Sekera4c533132018-02-22 11:41:12 +0100451 self.src_if.add_stream(fragments)
Klement Sekera75e7d132017-09-20 08:26:30 +0200452 self.pg_start()
453
Klement Sekera4c533132018-02-22 11:41:12 +0100454 packets = self.dst_if.get_capture(len(self.pkt_infos))
Klement Sekera947a85c2019-07-24 12:40:37 +0000455 self.verify_capture(packets)
Klement Sekera4c533132018-02-22 11:41:12 +0100456 self.src_if.assert_nothing_captured()
Klement Sekera75e7d132017-09-20 08:26:30 +0200457
458 # run it all to verify correctness
459 self.pg_enable_capture()
Klement Sekera4c533132018-02-22 11:41:12 +0100460 self.src_if.add_stream(fragments)
Klement Sekera75e7d132017-09-20 08:26:30 +0200461 self.pg_start()
462
Klement Sekera4c533132018-02-22 11:41:12 +0100463 packets = self.dst_if.get_capture(len(self.pkt_infos))
Klement Sekera947a85c2019-07-24 12:40:37 +0000464 self.verify_capture(packets)
Klement Sekera4c533132018-02-22 11:41:12 +0100465 self.src_if.assert_nothing_captured()
Klement Sekera75e7d132017-09-20 08:26:30 +0200466
467 def test_overlap2(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200468 """overlapping fragments case #2"""
Klement Sekera75e7d132017-09-20 08:26:30 +0200469
470 fragments = []
471 for _, _, frags_300, frags_200 in self.pkt_infos:
472 if len(frags_300) == 1:
473 fragments.extend(frags_300)
474 else:
475 # care must be taken here so that there are no fragments
476 # received by vpp after reassembly is finished, otherwise
477 # new reassemblies will be started and packet generator will
478 # freak out when it detects unfreed buffers
479 zipped = zip(frags_300, frags_200)
Paul Vinciguerrac7834e02019-03-02 10:43:05 -0800480 for i, j in zipped:
Klement Sekera75e7d132017-09-20 08:26:30 +0200481 fragments.extend(i)
482 fragments.extend(j)
Paul Vinciguerrac7834e02019-03-02 10:43:05 -0800483 fragments.pop()
Klement Sekera75e7d132017-09-20 08:26:30 +0200484
485 self.pg_enable_capture()
Klement Sekera4c533132018-02-22 11:41:12 +0100486 self.src_if.add_stream(fragments)
Klement Sekera75e7d132017-09-20 08:26:30 +0200487 self.pg_start()
488
Klement Sekera4c533132018-02-22 11:41:12 +0100489 packets = self.dst_if.get_capture(len(self.pkt_infos))
Klement Sekera947a85c2019-07-24 12:40:37 +0000490 self.verify_capture(packets)
Klement Sekera4c533132018-02-22 11:41:12 +0100491 self.src_if.assert_nothing_captured()
Klement Sekera75e7d132017-09-20 08:26:30 +0200492
493 # run it all to verify correctness
494 self.pg_enable_capture()
Klement Sekera4c533132018-02-22 11:41:12 +0100495 self.src_if.add_stream(fragments)
Klement Sekera75e7d132017-09-20 08:26:30 +0200496 self.pg_start()
497
Klement Sekera4c533132018-02-22 11:41:12 +0100498 packets = self.dst_if.get_capture(len(self.pkt_infos))
Klement Sekera947a85c2019-07-24 12:40:37 +0000499 self.verify_capture(packets)
Klement Sekera4c533132018-02-22 11:41:12 +0100500 self.src_if.assert_nothing_captured()
Klement Sekera75e7d132017-09-20 08:26:30 +0200501
Klement Sekera947a85c2019-07-24 12:40:37 +0000502 def test_timeout_inline(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200503 """timeout (inline)"""
Klement Sekera75e7d132017-09-20 08:26:30 +0200504
505 dropped_packet_indexes = set(
506 index for (index, frags, _, _) in self.pkt_infos if len(frags) > 1
507 )
508
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200509 self.vapi.ip_reassembly_set(
510 timeout_ms=0,
511 max_reassemblies=1000,
512 max_reassembly_length=3,
513 expire_walk_interval_ms=10000,
514 )
Klement Sekera947a85c2019-07-24 12:40:37 +0000515
516 self.pg_enable_capture()
517 self.src_if.add_stream(self.fragments_400)
518 self.pg_start()
519
520 packets = self.dst_if.get_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200521 len(self.pkt_infos) - len(dropped_packet_indexes)
522 )
Klement Sekera947a85c2019-07-24 12:40:37 +0000523 self.verify_capture(packets, dropped_packet_indexes)
Klement Sekera4c533132018-02-22 11:41:12 +0100524 self.src_if.assert_nothing_captured()
Klement Sekera75e7d132017-09-20 08:26:30 +0200525
526 def test_timeout_cleanup(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200527 """timeout (cleanup)"""
Klement Sekera75e7d132017-09-20 08:26:30 +0200528
529 # whole packets + fragmented packets sans last fragment
530 fragments = [
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200531 x
532 for (_, frags_400, _, _) in self.pkt_infos
533 for x in frags_400[: -1 if len(frags_400) > 1 else None]
Klement Sekera75e7d132017-09-20 08:26:30 +0200534 ]
535
536 # last fragments for fragmented packets
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200537 fragments2 = [
538 frags_400[-1]
539 for (_, frags_400, _, _) in self.pkt_infos
540 if len(frags_400) > 1
541 ]
Klement Sekera75e7d132017-09-20 08:26:30 +0200542
543 dropped_packet_indexes = set(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200544 index for (index, frags_400, _, _) in self.pkt_infos if len(frags_400) > 1
545 )
Klement Sekera75e7d132017-09-20 08:26:30 +0200546
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200547 self.vapi.ip_reassembly_set(
548 timeout_ms=100,
549 max_reassemblies=1000,
550 max_reassembly_length=1000,
551 expire_walk_interval_ms=50,
552 )
Klement Sekera75e7d132017-09-20 08:26:30 +0200553
554 self.pg_enable_capture()
Klement Sekera4c533132018-02-22 11:41:12 +0100555 self.src_if.add_stream(fragments)
Klement Sekera75e7d132017-09-20 08:26:30 +0200556 self.pg_start()
557
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200558 self.virtual_sleep(0.25, "wait before sending rest of fragments")
Klement Sekera75e7d132017-09-20 08:26:30 +0200559
Klement Sekera4c533132018-02-22 11:41:12 +0100560 self.src_if.add_stream(fragments2)
Klement Sekera75e7d132017-09-20 08:26:30 +0200561 self.pg_start()
Klement Sekera75e7d132017-09-20 08:26:30 +0200562
Klement Sekera4c533132018-02-22 11:41:12 +0100563 packets = self.dst_if.get_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200564 len(self.pkt_infos) - len(dropped_packet_indexes)
565 )
Klement Sekera947a85c2019-07-24 12:40:37 +0000566 self.verify_capture(packets, dropped_packet_indexes)
Klement Sekera4c533132018-02-22 11:41:12 +0100567 self.src_if.assert_nothing_captured()
Klement Sekera75e7d132017-09-20 08:26:30 +0200568
Klement Sekera947a85c2019-07-24 12:40:37 +0000569 def test_disabled(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200570 """reassembly disabled"""
Klement Sekera75e7d132017-09-20 08:26:30 +0200571
572 dropped_packet_indexes = set(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200573 index for (index, frags_400, _, _) in self.pkt_infos if len(frags_400) > 1
574 )
Klement Sekera947a85c2019-07-24 12:40:37 +0000575
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200576 self.vapi.ip_reassembly_set(
577 timeout_ms=1000,
578 max_reassemblies=0,
579 max_reassembly_length=3,
580 expire_walk_interval_ms=10000,
581 )
Klement Sekera947a85c2019-07-24 12:40:37 +0000582
583 self.pg_enable_capture()
584 self.src_if.add_stream(self.fragments_400)
585 self.pg_start()
586
587 packets = self.dst_if.get_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200588 len(self.pkt_infos) - len(dropped_packet_indexes)
589 )
Klement Sekera947a85c2019-07-24 12:40:37 +0000590 self.verify_capture(packets, dropped_packet_indexes)
591 self.src_if.assert_nothing_captured()
Klement Sekera75e7d132017-09-20 08:26:30 +0200592
Klement Sekera01c1fa42021-12-14 18:25:11 +0000593 def test_local_enable_disable(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200594 """local reassembly enabled/disable"""
Klement Sekera01c1fa42021-12-14 18:25:11 +0000595 self.vapi.ip_reassembly_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200596 sw_if_index=self.src_if.sw_if_index, enable_ip4=False
597 )
Klement Sekera01c1fa42021-12-14 18:25:11 +0000598 self.vapi.ip_local_reass_enable_disable(enable_ip4=True)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200599 p = (
600 Ether(src=self.src_if.remote_mac, dst=self.src_if.local_mac)
601 / IP(src=self.src_if.remote_ip4, dst=self.src_if.local_ip4)
602 / ICMP(id=1234, type="echo-request")
603 / Raw("x" * 1000)
604 )
Klement Sekera01c1fa42021-12-14 18:25:11 +0000605 frags = fragment_rfc791(p, 400)
606 r = self.send_and_expect(self.src_if, frags, self.src_if, n_rx=1)[0]
607 self.assertEqual(1234, r[ICMP].id)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200608 self.assertEqual(icmptypes[r[ICMP].type], "echo-reply")
Klement Sekera01c1fa42021-12-14 18:25:11 +0000609 self.vapi.ip_local_reass_enable_disable()
610
611 self.send_and_assert_no_replies(self.src_if, frags)
612 self.vapi.ip_local_reass_enable_disable(enable_ip4=True)
613
Klement Sekera75e7d132017-09-20 08:26:30 +0200614
Klement Sekerade34c352019-06-25 11:19:22 +0000615class TestIPv4SVReassembly(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200616 """IPv4 Shallow Virtual Reassembly"""
Klement Sekerade34c352019-06-25 11:19:22 +0000617
618 @classmethod
619 def setUpClass(cls):
Klement Sekera01c1fa42021-12-14 18:25:11 +0000620 super().setUpClass()
Klement Sekerade34c352019-06-25 11:19:22 +0000621
622 cls.create_pg_interfaces([0, 1])
623 cls.src_if = cls.pg0
624 cls.dst_if = cls.pg1
625
626 # setup all interfaces
627 for i in cls.pg_interfaces:
628 i.admin_up()
629 i.config_ip4()
630 i.resolve_arp()
631
632 def setUp(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200633 """Test setup - force timeout on existing reassemblies"""
Klement Sekera01c1fa42021-12-14 18:25:11 +0000634 super().setUp()
Klement Sekerade34c352019-06-25 11:19:22 +0000635 self.vapi.ip_reassembly_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200636 sw_if_index=self.src_if.sw_if_index,
637 enable_ip4=True,
638 type=VppEnum.vl_api_ip_reass_type_t.IP_REASS_TYPE_SHALLOW_VIRTUAL,
639 )
Klement Sekerade34c352019-06-25 11:19:22 +0000640 self.vapi.ip_reassembly_set(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200641 timeout_ms=0,
642 max_reassemblies=1000,
Klement Sekerade34c352019-06-25 11:19:22 +0000643 max_reassembly_length=1000,
644 type=VppEnum.vl_api_ip_reass_type_t.IP_REASS_TYPE_SHALLOW_VIRTUAL,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200645 expire_walk_interval_ms=10,
646 )
647 self.virtual_sleep(0.25)
Klement Sekerade34c352019-06-25 11:19:22 +0000648 self.vapi.ip_reassembly_set(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200649 timeout_ms=1000000,
650 max_reassemblies=1000,
Klement Sekerade34c352019-06-25 11:19:22 +0000651 max_reassembly_length=1000,
652 type=VppEnum.vl_api_ip_reass_type_t.IP_REASS_TYPE_SHALLOW_VIRTUAL,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200653 expire_walk_interval_ms=10000,
654 )
Klement Sekerade34c352019-06-25 11:19:22 +0000655
656 def tearDown(self):
Klement Sekera01c1fa42021-12-14 18:25:11 +0000657 super().tearDown()
Klement Sekerade34c352019-06-25 11:19:22 +0000658 self.logger.debug(self.vapi.ppcli("show ip4-sv-reassembly details"))
659 self.logger.debug(self.vapi.ppcli("show buffers"))
660
661 def test_basic(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200662 """basic reassembly"""
Klement Sekerade34c352019-06-25 11:19:22 +0000663 payload_len = 1000
664 payload = ""
665 counter = 0
666 while len(payload) < payload_len:
667 payload += "%u " % counter
668 counter += 1
669
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200670 p = (
671 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
672 / IP(id=1, src=self.src_if.remote_ip4, dst=self.dst_if.remote_ip4)
673 / UDP(sport=1234, dport=5678)
674 / Raw(payload)
675 )
676 fragments = fragment_rfc791(p, payload_len / 4)
Klement Sekerade34c352019-06-25 11:19:22 +0000677
678 # send fragment #2 - should be cached inside reassembly
679 self.pg_enable_capture()
680 self.src_if.add_stream(fragments[1])
681 self.pg_start()
682 self.logger.debug(self.vapi.ppcli("show ip4-sv-reassembly details"))
683 self.logger.debug(self.vapi.ppcli("show buffers"))
684 self.logger.debug(self.vapi.ppcli("show trace"))
685 self.dst_if.assert_nothing_captured()
686
687 # send fragment #1 - reassembly is finished now and both fragments
688 # forwarded
689 self.pg_enable_capture()
690 self.src_if.add_stream(fragments[0])
691 self.pg_start()
692 self.logger.debug(self.vapi.ppcli("show ip4-sv-reassembly details"))
693 self.logger.debug(self.vapi.ppcli("show buffers"))
694 self.logger.debug(self.vapi.ppcli("show trace"))
695 c = self.dst_if.get_capture(2)
696 for sent, recvd in zip([fragments[1], fragments[0]], c):
697 self.assertEqual(sent[IP].src, recvd[IP].src)
698 self.assertEqual(sent[IP].dst, recvd[IP].dst)
699 self.assertEqual(sent[Raw].payload, recvd[Raw].payload)
700
701 # send rest of fragments - should be immediately forwarded
702 self.pg_enable_capture()
703 self.src_if.add_stream(fragments[2:])
704 self.pg_start()
705 c = self.dst_if.get_capture(len(fragments[2:]))
706 for sent, recvd in zip(fragments[2:], c):
707 self.assertEqual(sent[IP].src, recvd[IP].src)
708 self.assertEqual(sent[IP].dst, recvd[IP].dst)
709 self.assertEqual(sent[Raw].payload, recvd[Raw].payload)
710
Klement Sekera53be16d2020-12-15 21:47:36 +0100711 def test_verify_clear_trace_mid_reassembly(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200712 """verify clear trace works mid-reassembly"""
Klement Sekera53be16d2020-12-15 21:47:36 +0100713 payload_len = 1000
714 payload = ""
715 counter = 0
716 while len(payload) < payload_len:
717 payload += "%u " % counter
718 counter += 1
719
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200720 p = (
721 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
722 / IP(id=1, src=self.src_if.remote_ip4, dst=self.dst_if.remote_ip4)
723 / UDP(sport=1234, dport=5678)
724 / Raw(payload)
725 )
726 fragments = fragment_rfc791(p, payload_len / 4)
Klement Sekera53be16d2020-12-15 21:47:36 +0100727
728 self.pg_enable_capture()
729 self.src_if.add_stream(fragments[1])
730 self.pg_start()
731
732 self.logger.debug(self.vapi.cli("show trace"))
733 self.vapi.cli("clear trace")
734
735 self.pg_enable_capture()
736 self.src_if.add_stream(fragments[0])
737 self.pg_start()
738 self.dst_if.get_capture(2)
739
740 self.logger.debug(self.vapi.cli("show trace"))
741 self.vapi.cli("clear trace")
742
743 self.pg_enable_capture()
744 self.src_if.add_stream(fragments[2:])
745 self.pg_start()
746 self.dst_if.get_capture(len(fragments[2:]))
747
Klement Sekerade34c352019-06-25 11:19:22 +0000748 def test_timeout(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200749 """reassembly timeout"""
Klement Sekerade34c352019-06-25 11:19:22 +0000750 payload_len = 1000
751 payload = ""
752 counter = 0
753 while len(payload) < payload_len:
754 payload += "%u " % counter
755 counter += 1
756
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200757 p = (
758 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
759 / IP(id=1, src=self.src_if.remote_ip4, dst=self.dst_if.remote_ip4)
760 / UDP(sport=1234, dport=5678)
761 / Raw(payload)
762 )
763 fragments = fragment_rfc791(p, payload_len / 4)
Klement Sekerade34c352019-06-25 11:19:22 +0000764
765 self.vapi.ip_reassembly_set(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200766 timeout_ms=100,
767 max_reassemblies=1000,
Klement Sekerade34c352019-06-25 11:19:22 +0000768 max_reassembly_length=1000,
769 expire_walk_interval_ms=50,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200770 type=VppEnum.vl_api_ip_reass_type_t.IP_REASS_TYPE_SHALLOW_VIRTUAL,
771 )
Klement Sekerade34c352019-06-25 11:19:22 +0000772
773 # send fragments #2 and #1 - should be forwarded
774 self.pg_enable_capture()
775 self.src_if.add_stream(fragments[0:2])
776 self.pg_start()
777 self.logger.debug(self.vapi.ppcli("show ip4-sv-reassembly details"))
778 self.logger.debug(self.vapi.ppcli("show buffers"))
779 self.logger.debug(self.vapi.ppcli("show trace"))
780 c = self.dst_if.get_capture(2)
781 for sent, recvd in zip([fragments[1], fragments[0]], c):
782 self.assertEqual(sent[IP].src, recvd[IP].src)
783 self.assertEqual(sent[IP].dst, recvd[IP].dst)
784 self.assertEqual(sent[Raw].payload, recvd[Raw].payload)
785
786 # wait for cleanup
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200787 self.virtual_sleep(0.25, "wait before sending rest of fragments")
Klement Sekerade34c352019-06-25 11:19:22 +0000788
789 # send rest of fragments - shouldn't be forwarded
790 self.pg_enable_capture()
791 self.src_if.add_stream(fragments[2:])
792 self.pg_start()
793 self.dst_if.assert_nothing_captured()
794
795 def test_lru(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200796 """reassembly reuses LRU element"""
Klement Sekerade34c352019-06-25 11:19:22 +0000797
798 self.vapi.ip_reassembly_set(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200799 timeout_ms=1000000,
800 max_reassemblies=1,
Klement Sekerade34c352019-06-25 11:19:22 +0000801 max_reassembly_length=1000,
802 type=VppEnum.vl_api_ip_reass_type_t.IP_REASS_TYPE_SHALLOW_VIRTUAL,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200803 expire_walk_interval_ms=10000,
804 )
Klement Sekerade34c352019-06-25 11:19:22 +0000805
806 payload_len = 1000
807 payload = ""
808 counter = 0
809 while len(payload) < payload_len:
810 payload += "%u " % counter
811 counter += 1
812
813 packet_count = 10
814
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200815 fragments = [
816 f
817 for i in range(packet_count)
818 for p in (
819 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
820 / IP(id=i, src=self.src_if.remote_ip4, dst=self.dst_if.remote_ip4)
821 / UDP(sport=1234, dport=5678)
822 / Raw(payload)
823 )
824 for f in fragment_rfc791(p, payload_len / 4)
825 ]
Klement Sekerade34c352019-06-25 11:19:22 +0000826
827 self.pg_enable_capture()
828 self.src_if.add_stream(fragments)
829 self.pg_start()
830 c = self.dst_if.get_capture(len(fragments))
831 for sent, recvd in zip(fragments, c):
832 self.assertEqual(sent[IP].src, recvd[IP].src)
833 self.assertEqual(sent[IP].dst, recvd[IP].dst)
834 self.assertEqual(sent[Raw].payload, recvd[Raw].payload)
835
Klement Sekera18c6cd92020-07-10 09:29:48 +0000836 def send_mixed_and_verify_capture(self, traffic):
837 stream = []
838 for t in traffic:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200839 for c in range(t["count"]):
Klement Sekera18c6cd92020-07-10 09:29:48 +0000840 stream.append(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200841 (
842 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
843 / IP(
844 id=self.counter,
845 flags=t["flags"],
846 src=self.src_if.remote_ip4,
847 dst=self.dst_if.remote_ip4,
848 )
849 / UDP(sport=1234, dport=5678)
850 / Raw("abcdef")
851 )
852 )
Klement Sekera18c6cd92020-07-10 09:29:48 +0000853 self.counter = self.counter + 1
854
855 self.pg_enable_capture()
856 self.src_if.add_stream(stream)
857 self.pg_start()
858 self.logger.debug(self.vapi.ppcli("show ip4-sv-reassembly details"))
859 self.logger.debug(self.vapi.ppcli("show buffers"))
860 self.logger.debug(self.vapi.ppcli("show trace"))
861 self.dst_if.get_capture(len(stream))
862
863 def test_mixed(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200864 """mixed traffic correctly passes through SVR"""
Klement Sekera18c6cd92020-07-10 09:29:48 +0000865 self.counter = 1
866
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200867 self.send_mixed_and_verify_capture([{"count": 1, "flags": ""}])
868 self.send_mixed_and_verify_capture([{"count": 2, "flags": ""}])
869 self.send_mixed_and_verify_capture([{"count": 3, "flags": ""}])
870 self.send_mixed_and_verify_capture([{"count": 8, "flags": ""}])
871 self.send_mixed_and_verify_capture([{"count": 257, "flags": ""}])
Klement Sekera18c6cd92020-07-10 09:29:48 +0000872
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200873 self.send_mixed_and_verify_capture([{"count": 1, "flags": "MF"}])
874 self.send_mixed_and_verify_capture([{"count": 2, "flags": "MF"}])
875 self.send_mixed_and_verify_capture([{"count": 3, "flags": "MF"}])
876 self.send_mixed_and_verify_capture([{"count": 8, "flags": "MF"}])
877 self.send_mixed_and_verify_capture([{"count": 257, "flags": "MF"}])
Klement Sekera18c6cd92020-07-10 09:29:48 +0000878
879 self.send_mixed_and_verify_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200880 [{"count": 1, "flags": ""}, {"count": 1, "flags": "MF"}]
881 )
Klement Sekera18c6cd92020-07-10 09:29:48 +0000882 self.send_mixed_and_verify_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200883 [{"count": 2, "flags": ""}, {"count": 2, "flags": "MF"}]
884 )
Klement Sekera18c6cd92020-07-10 09:29:48 +0000885 self.send_mixed_and_verify_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200886 [{"count": 3, "flags": ""}, {"count": 3, "flags": "MF"}]
887 )
Klement Sekera18c6cd92020-07-10 09:29:48 +0000888 self.send_mixed_and_verify_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200889 [{"count": 8, "flags": ""}, {"count": 8, "flags": "MF"}]
890 )
Klement Sekera18c6cd92020-07-10 09:29:48 +0000891 self.send_mixed_and_verify_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200892 [{"count": 129, "flags": ""}, {"count": 129, "flags": "MF"}]
893 )
Klement Sekera18c6cd92020-07-10 09:29:48 +0000894
895 self.send_mixed_and_verify_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200896 [
897 {"count": 1, "flags": ""},
898 {"count": 1, "flags": "MF"},
899 {"count": 1, "flags": ""},
900 {"count": 1, "flags": "MF"},
901 ]
902 )
Klement Sekera18c6cd92020-07-10 09:29:48 +0000903 self.send_mixed_and_verify_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200904 [
905 {"count": 2, "flags": ""},
906 {"count": 2, "flags": "MF"},
907 {"count": 2, "flags": ""},
908 {"count": 2, "flags": "MF"},
909 ]
910 )
Klement Sekera18c6cd92020-07-10 09:29:48 +0000911 self.send_mixed_and_verify_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200912 [
913 {"count": 3, "flags": ""},
914 {"count": 3, "flags": "MF"},
915 {"count": 3, "flags": ""},
916 {"count": 3, "flags": "MF"},
917 ]
918 )
Klement Sekera18c6cd92020-07-10 09:29:48 +0000919 self.send_mixed_and_verify_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200920 [
921 {"count": 8, "flags": ""},
922 {"count": 8, "flags": "MF"},
923 {"count": 8, "flags": ""},
924 {"count": 8, "flags": "MF"},
925 ]
926 )
Klement Sekera18c6cd92020-07-10 09:29:48 +0000927 self.send_mixed_and_verify_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200928 [
929 {"count": 65, "flags": ""},
930 {"count": 65, "flags": "MF"},
931 {"count": 65, "flags": ""},
932 {"count": 65, "flags": "MF"},
933 ]
934 )
Klement Sekera18c6cd92020-07-10 09:29:48 +0000935
Klement Sekerade34c352019-06-25 11:19:22 +0000936
Klement Sekera630ab582019-07-19 09:14:19 +0000937class TestIPv4MWReassembly(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200938 """IPv4 Reassembly (multiple workers)"""
939
Klement Sekera8d815022021-03-15 16:58:10 +0100940 vpp_worker_count = 3
Klement Sekera630ab582019-07-19 09:14:19 +0000941
942 @classmethod
943 def setUpClass(cls):
Klement Sekera01c1fa42021-12-14 18:25:11 +0000944 super().setUpClass()
Klement Sekera630ab582019-07-19 09:14:19 +0000945
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200946 cls.create_pg_interfaces(range(cls.vpp_worker_count + 1))
Klement Sekera630ab582019-07-19 09:14:19 +0000947 cls.src_if = cls.pg0
948 cls.send_ifs = cls.pg_interfaces[:-1]
949 cls.dst_if = cls.pg_interfaces[-1]
950
951 # setup all interfaces
952 for i in cls.pg_interfaces:
953 i.admin_up()
954 i.config_ip4()
955 i.resolve_arp()
956
957 # packets sizes reduced here because we are generating packets without
958 # Ethernet headers, which are added later (diff fragments go via
959 # different interfaces)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200960 cls.packet_sizes = [
961 64 - len(Ether()),
962 512 - len(Ether()),
963 1518 - len(Ether()),
964 9018 - len(Ether()),
965 ]
Klement Sekera630ab582019-07-19 09:14:19 +0000966 cls.padding = " abcdefghijklmn"
967 cls.create_stream(cls.packet_sizes)
968 cls.create_fragments()
969
970 @classmethod
971 def tearDownClass(cls):
Klement Sekera01c1fa42021-12-14 18:25:11 +0000972 super().tearDownClass()
Klement Sekera630ab582019-07-19 09:14:19 +0000973
974 def setUp(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200975 """Test setup - force timeout on existing reassemblies"""
Klement Sekera01c1fa42021-12-14 18:25:11 +0000976 super().setUp()
Klement Sekera630ab582019-07-19 09:14:19 +0000977 for intf in self.send_ifs:
978 self.vapi.ip_reassembly_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200979 sw_if_index=intf.sw_if_index, enable_ip4=True
980 )
981 self.vapi.ip_reassembly_set(
982 timeout_ms=0,
983 max_reassemblies=1000,
984 max_reassembly_length=1000,
985 expire_walk_interval_ms=10,
986 )
987 self.virtual_sleep(0.25)
988 self.vapi.ip_reassembly_set(
989 timeout_ms=1000000,
990 max_reassemblies=1000,
991 max_reassembly_length=1000,
992 expire_walk_interval_ms=10000,
993 )
Klement Sekera630ab582019-07-19 09:14:19 +0000994
995 def tearDown(self):
Klement Sekera01c1fa42021-12-14 18:25:11 +0000996 for intf in self.send_ifs:
997 self.vapi.ip_reassembly_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200998 sw_if_index=intf.sw_if_index, enable_ip4=False
999 )
Klement Sekera01c1fa42021-12-14 18:25:11 +00001000 super().tearDown()
Klement Sekera630ab582019-07-19 09:14:19 +00001001
1002 def show_commands_at_teardown(self):
Klement Sekera896c8962019-06-24 11:52:49 +00001003 self.logger.debug(self.vapi.ppcli("show ip4-full-reassembly details"))
Klement Sekera630ab582019-07-19 09:14:19 +00001004 self.logger.debug(self.vapi.ppcli("show buffers"))
1005
1006 @classmethod
1007 def create_stream(cls, packet_sizes, packet_count=test_packet_count):
1008 """Create input packet stream
1009
1010 :param list packet_sizes: Required packet sizes.
1011 """
1012 for i in range(0, packet_count):
1013 info = cls.create_packet_info(cls.src_if, cls.src_if)
1014 payload = cls.info_to_payload(info)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001015 p = (
1016 IP(id=info.index, src=cls.src_if.remote_ip4, dst=cls.dst_if.remote_ip4)
1017 / UDP(sport=1234, dport=5678)
1018 / Raw(payload)
1019 )
Klement Sekera630ab582019-07-19 09:14:19 +00001020 size = packet_sizes[(i // 2) % len(packet_sizes)]
1021 cls.extend_packet(p, size, cls.padding)
1022 info.data = p
1023
1024 @classmethod
1025 def create_fragments(cls):
1026 infos = cls._packet_infos
1027 cls.pkt_infos = []
Paul Vinciguerra090096b2020-12-03 00:42:46 -05001028 for index, info in infos.items():
Klement Sekera630ab582019-07-19 09:14:19 +00001029 p = info.data
1030 # cls.logger.debug(ppp("Packet:",
1031 # p.__class__(scapy.compat.raw(p))))
1032 fragments_400 = fragment_rfc791(p, 400)
1033 cls.pkt_infos.append((index, fragments_400))
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001034 cls.fragments_400 = [x for (_, frags) in cls.pkt_infos for x in frags]
1035 cls.logger.debug(
1036 "Fragmented %s packets into %s 400-byte fragments, "
1037 % (len(infos), len(cls.fragments_400))
1038 )
Klement Sekera630ab582019-07-19 09:14:19 +00001039
1040 def verify_capture(self, capture, dropped_packet_indexes=[]):
1041 """Verify captured packet stream.
1042
1043 :param list capture: Captured packet stream.
1044 """
1045 info = None
1046 seen = set()
1047 for packet in capture:
1048 try:
1049 self.logger.debug(ppp("Got packet:", packet))
1050 ip = packet[IP]
1051 udp = packet[UDP]
1052 payload_info = self.payload_to_info(packet[Raw])
1053 packet_index = payload_info.index
1054 self.assertTrue(
1055 packet_index not in dropped_packet_indexes,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001056 ppp("Packet received, but should be dropped:", packet),
1057 )
Klement Sekera630ab582019-07-19 09:14:19 +00001058 if packet_index in seen:
1059 raise Exception(ppp("Duplicate packet received", packet))
1060 seen.add(packet_index)
1061 self.assertEqual(payload_info.dst, self.src_if.sw_if_index)
1062 info = self._packet_infos[packet_index]
1063 self.assertTrue(info is not None)
1064 self.assertEqual(packet_index, info.index)
1065 saved_packet = info.data
1066 self.assertEqual(ip.src, saved_packet[IP].src)
1067 self.assertEqual(ip.dst, saved_packet[IP].dst)
1068 self.assertEqual(udp.payload, saved_packet[UDP].payload)
1069 except Exception:
1070 self.logger.error(ppp("Unexpected or invalid packet:", packet))
1071 raise
1072 for index in self._packet_infos:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001073 self.assertTrue(
1074 index in seen or index in dropped_packet_indexes,
1075 "Packet with packet_index %d not received" % index,
1076 )
Klement Sekera630ab582019-07-19 09:14:19 +00001077
1078 def send_packets(self, packets):
Klement Sekera8d815022021-03-15 16:58:10 +01001079 for counter in range(self.vpp_worker_count):
Klement Sekera630ab582019-07-19 09:14:19 +00001080 if 0 == len(packets[counter]):
1081 continue
1082 send_if = self.send_ifs[counter]
1083 send_if.add_stream(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001084 (
1085 Ether(dst=send_if.local_mac, src=send_if.remote_mac) / x
1086 for x in packets[counter]
1087 ),
1088 worker=counter,
1089 )
Klement Sekera630ab582019-07-19 09:14:19 +00001090 self.pg_start()
1091
1092 def test_worker_conflict(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001093 """1st and FO=0 fragments on different workers"""
Klement Sekera630ab582019-07-19 09:14:19 +00001094
1095 # in first wave we send fragments which don't start at offset 0
1096 # then we send fragments with offset 0 on a different thread
1097 # then the rest of packets on a random thread
Klement Sekera8d815022021-03-15 16:58:10 +01001098 first_packets = [[] for n in range(self.vpp_worker_count)]
1099 second_packets = [[] for n in range(self.vpp_worker_count)]
1100 rest_of_packets = [[] for n in range(self.vpp_worker_count)]
Klement Sekera630ab582019-07-19 09:14:19 +00001101 for (_, p) in self.pkt_infos:
Klement Sekera8d815022021-03-15 16:58:10 +01001102 wi = randrange(self.vpp_worker_count)
Klement Sekera630ab582019-07-19 09:14:19 +00001103 second_packets[wi].append(p[0])
1104 if len(p) <= 1:
1105 continue
1106 wi2 = wi
1107 while wi2 == wi:
Klement Sekera8d815022021-03-15 16:58:10 +01001108 wi2 = randrange(self.vpp_worker_count)
Klement Sekera630ab582019-07-19 09:14:19 +00001109 first_packets[wi2].append(p[1])
Klement Sekera8d815022021-03-15 16:58:10 +01001110 wi3 = randrange(self.vpp_worker_count)
Klement Sekera630ab582019-07-19 09:14:19 +00001111 rest_of_packets[wi3].extend(p[2:])
1112
1113 self.pg_enable_capture()
1114 self.send_packets(first_packets)
1115 self.send_packets(second_packets)
1116 self.send_packets(rest_of_packets)
1117
1118 packets = self.dst_if.get_capture(len(self.pkt_infos))
1119 self.verify_capture(packets)
1120 for send_if in self.send_ifs:
1121 send_if.assert_nothing_captured()
1122
Klement Sekera68bae5b2019-10-10 18:57:34 +00001123 self.logger.debug(self.vapi.ppcli("show trace"))
1124 self.logger.debug(self.vapi.ppcli("show ip4-full-reassembly details"))
1125 self.logger.debug(self.vapi.ppcli("show buffers"))
1126 self.vapi.cli("clear trace")
1127
Klement Sekera630ab582019-07-19 09:14:19 +00001128 self.pg_enable_capture()
1129 self.send_packets(first_packets)
1130 self.send_packets(second_packets)
1131 self.send_packets(rest_of_packets)
1132
1133 packets = self.dst_if.get_capture(len(self.pkt_infos))
1134 self.verify_capture(packets)
1135 for send_if in self.send_ifs:
1136 send_if.assert_nothing_captured()
1137
1138
Klement Sekera947a85c2019-07-24 12:40:37 +00001139class TestIPv6Reassembly(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001140 """IPv6 Reassembly"""
Klement Sekera75e7d132017-09-20 08:26:30 +02001141
1142 @classmethod
1143 def setUpClass(cls):
Klement Sekera01c1fa42021-12-14 18:25:11 +00001144 super().setUpClass()
Klement Sekera75e7d132017-09-20 08:26:30 +02001145
Klement Sekera4c533132018-02-22 11:41:12 +01001146 cls.create_pg_interfaces([0, 1])
1147 cls.src_if = cls.pg0
1148 cls.dst_if = cls.pg1
Klement Sekera75e7d132017-09-20 08:26:30 +02001149
1150 # setup all interfaces
1151 for i in cls.pg_interfaces:
1152 i.admin_up()
1153 i.config_ip6()
1154 i.resolve_ndp()
1155
Klement Sekera75e7d132017-09-20 08:26:30 +02001156 # packet sizes
1157 cls.packet_sizes = [64, 512, 1518, 9018]
1158 cls.padding = " abcdefghijklmn"
1159 cls.create_stream(cls.packet_sizes)
1160 cls.create_fragments()
1161
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001162 @classmethod
1163 def tearDownClass(cls):
Klement Sekera01c1fa42021-12-14 18:25:11 +00001164 super().tearDownClass()
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001165
Klement Sekera75e7d132017-09-20 08:26:30 +02001166 def setUp(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001167 """Test setup - force timeout on existing reassemblies"""
Klement Sekera01c1fa42021-12-14 18:25:11 +00001168 super().setUp()
Klement Sekera4c533132018-02-22 11:41:12 +01001169 self.vapi.ip_reassembly_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001170 sw_if_index=self.src_if.sw_if_index, enable_ip6=True
1171 )
1172 self.vapi.ip_reassembly_set(
1173 timeout_ms=0,
1174 max_reassemblies=1000,
1175 max_reassembly_length=1000,
1176 expire_walk_interval_ms=10,
1177 is_ip6=1,
1178 )
1179 self.virtual_sleep(0.25)
1180 self.vapi.ip_reassembly_set(
1181 timeout_ms=1000000,
1182 max_reassemblies=1000,
1183 max_reassembly_length=1000,
1184 expire_walk_interval_ms=10000,
1185 is_ip6=1,
1186 )
Klement Sekera896c8962019-06-24 11:52:49 +00001187 self.logger.debug(self.vapi.ppcli("show ip6-full-reassembly details"))
Klement Sekeracae98b72019-02-19 13:53:43 +01001188 self.logger.debug(self.vapi.ppcli("show buffers"))
Klement Sekera75e7d132017-09-20 08:26:30 +02001189
1190 def tearDown(self):
Klement Sekera01c1fa42021-12-14 18:25:11 +00001191 self.vapi.ip_reassembly_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001192 sw_if_index=self.src_if.sw_if_index, enable_ip6=False
1193 )
Klement Sekera01c1fa42021-12-14 18:25:11 +00001194 super().tearDown()
Paul Vinciguerra90cf21b2019-03-13 09:23:05 -07001195
1196 def show_commands_at_teardown(self):
Klement Sekera896c8962019-06-24 11:52:49 +00001197 self.logger.debug(self.vapi.ppcli("show ip6-full-reassembly details"))
Klement Sekeracae98b72019-02-19 13:53:43 +01001198 self.logger.debug(self.vapi.ppcli("show buffers"))
Klement Sekera75e7d132017-09-20 08:26:30 +02001199
1200 @classmethod
1201 def create_stream(cls, packet_sizes, packet_count=test_packet_count):
1202 """Create input packet stream for defined interface.
1203
1204 :param list packet_sizes: Required packet sizes.
1205 """
1206 for i in range(0, packet_count):
Klement Sekera4c533132018-02-22 11:41:12 +01001207 info = cls.create_packet_info(cls.src_if, cls.src_if)
Klement Sekera75e7d132017-09-20 08:26:30 +02001208 payload = cls.info_to_payload(info)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001209 p = (
1210 Ether(dst=cls.src_if.local_mac, src=cls.src_if.remote_mac)
1211 / IPv6(src=cls.src_if.remote_ip6, dst=cls.dst_if.remote_ip6)
1212 / UDP(sport=1234, dport=5678)
1213 / Raw(payload)
1214 )
Klement Sekera75e7d132017-09-20 08:26:30 +02001215 size = packet_sizes[(i // 2) % len(packet_sizes)]
1216 cls.extend_packet(p, size, cls.padding)
1217 info.data = p
1218
1219 @classmethod
1220 def create_fragments(cls):
1221 infos = cls._packet_infos
1222 cls.pkt_infos = []
Paul Vinciguerra090096b2020-12-03 00:42:46 -05001223 for index, info in infos.items():
Klement Sekera75e7d132017-09-20 08:26:30 +02001224 p = info.data
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -07001225 # cls.logger.debug(ppp("Packet:",
1226 # p.__class__(scapy.compat.raw(p))))
Klement Sekera75e7d132017-09-20 08:26:30 +02001227 fragments_400 = fragment_rfc8200(p, info.index, 400)
1228 fragments_300 = fragment_rfc8200(p, info.index, 300)
1229 cls.pkt_infos.append((index, fragments_400, fragments_300))
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001230 cls.fragments_400 = [x for _, frags, _ in cls.pkt_infos for x in frags]
1231 cls.fragments_300 = [x for _, _, frags in cls.pkt_infos for x in frags]
1232 cls.logger.debug(
1233 "Fragmented %s packets into %s 400-byte fragments, "
1234 "and %s 300-byte fragments"
1235 % (len(infos), len(cls.fragments_400), len(cls.fragments_300))
1236 )
Klement Sekera75e7d132017-09-20 08:26:30 +02001237
Klement Sekera947a85c2019-07-24 12:40:37 +00001238 def verify_capture(self, capture, dropped_packet_indexes=[]):
1239 """Verify captured packet strea .
1240
1241 :param list capture: Captured packet stream.
1242 """
1243 info = None
1244 seen = set()
1245 for packet in capture:
1246 try:
1247 self.logger.debug(ppp("Got packet:", packet))
1248 ip = packet[IPv6]
1249 udp = packet[UDP]
1250 payload_info = self.payload_to_info(packet[Raw])
1251 packet_index = payload_info.index
1252 self.assertTrue(
1253 packet_index not in dropped_packet_indexes,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001254 ppp("Packet received, but should be dropped:", packet),
1255 )
Klement Sekera947a85c2019-07-24 12:40:37 +00001256 if packet_index in seen:
1257 raise Exception(ppp("Duplicate packet received", packet))
1258 seen.add(packet_index)
1259 self.assertEqual(payload_info.dst, self.src_if.sw_if_index)
1260 info = self._packet_infos[packet_index]
1261 self.assertTrue(info is not None)
1262 self.assertEqual(packet_index, info.index)
1263 saved_packet = info.data
1264 self.assertEqual(ip.src, saved_packet[IPv6].src)
1265 self.assertEqual(ip.dst, saved_packet[IPv6].dst)
1266 self.assertEqual(udp.payload, saved_packet[UDP].payload)
1267 except Exception:
1268 self.logger.error(ppp("Unexpected or invalid packet:", packet))
1269 raise
1270 for index in self._packet_infos:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001271 self.assertTrue(
1272 index in seen or index in dropped_packet_indexes,
1273 "Packet with packet_index %d not received" % index,
1274 )
Klement Sekera947a85c2019-07-24 12:40:37 +00001275
1276 def test_reassembly(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001277 """basic reassembly"""
Klement Sekera75e7d132017-09-20 08:26:30 +02001278
Klement Sekera947a85c2019-07-24 12:40:37 +00001279 self.pg_enable_capture()
1280 self.src_if.add_stream(self.fragments_400)
1281 self.pg_start()
1282
1283 packets = self.dst_if.get_capture(len(self.pkt_infos))
1284 self.verify_capture(packets)
1285 self.src_if.assert_nothing_captured()
1286
1287 # run it all again to verify correctness
1288 self.pg_enable_capture()
1289 self.src_if.add_stream(self.fragments_400)
1290 self.pg_start()
1291
1292 packets = self.dst_if.get_capture(len(self.pkt_infos))
1293 self.verify_capture(packets)
1294 self.src_if.assert_nothing_captured()
1295
Klement Sekera769145c2019-03-06 11:59:57 +01001296 def test_buffer_boundary(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001297 """fragment header crossing buffer boundary"""
Klement Sekera769145c2019-03-06 11:59:57 +01001298
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001299 p = (
1300 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
1301 / IPv6(src=self.src_if.remote_ip6, dst=self.src_if.local_ip6)
1302 / IPv6ExtHdrHopByHop(options=[HBHOptUnknown(otype=0xFF, optlen=0)] * 1000)
1303 / IPv6ExtHdrFragment(m=1)
1304 / UDP(sport=1234, dport=5678)
1305 / Raw()
1306 )
Klement Sekera769145c2019-03-06 11:59:57 +01001307 self.pg_enable_capture()
1308 self.src_if.add_stream([p])
1309 self.pg_start()
1310 self.src_if.assert_nothing_captured()
1311 self.dst_if.assert_nothing_captured()
1312
Klement Sekera53be16d2020-12-15 21:47:36 +01001313 def test_verify_clear_trace_mid_reassembly(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001314 """verify clear trace works mid-reassembly"""
Klement Sekera53be16d2020-12-15 21:47:36 +01001315
1316 self.pg_enable_capture()
1317 self.src_if.add_stream(self.fragments_400[0:-1])
1318 self.pg_start()
1319
1320 self.logger.debug(self.vapi.cli("show trace"))
1321 self.vapi.cli("clear trace")
1322
1323 self.src_if.add_stream(self.fragments_400[-1])
1324 self.pg_start()
1325 packets = self.dst_if.get_capture(len(self.pkt_infos))
1326 self.verify_capture(packets)
1327
Klement Sekera947a85c2019-07-24 12:40:37 +00001328 def test_reversed(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001329 """reverse order reassembly"""
Klement Sekera75e7d132017-09-20 08:26:30 +02001330
Klement Sekera947a85c2019-07-24 12:40:37 +00001331 fragments = list(self.fragments_400)
1332 fragments.reverse()
1333
1334 self.pg_enable_capture()
1335 self.src_if.add_stream(fragments)
1336 self.pg_start()
1337
1338 packets = self.dst_if.get_capture(len(self.pkt_infos))
1339 self.verify_capture(packets)
1340 self.src_if.assert_nothing_captured()
1341
1342 # run it all again to verify correctness
1343 self.pg_enable_capture()
1344 self.src_if.add_stream(fragments)
1345 self.pg_start()
1346
1347 packets = self.dst_if.get_capture(len(self.pkt_infos))
1348 self.verify_capture(packets)
1349 self.src_if.assert_nothing_captured()
1350
1351 def test_random(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001352 """random order reassembly"""
Klement Sekera75e7d132017-09-20 08:26:30 +02001353
Klement Sekera947a85c2019-07-24 12:40:37 +00001354 fragments = list(self.fragments_400)
1355 shuffle(fragments)
1356
1357 self.pg_enable_capture()
1358 self.src_if.add_stream(fragments)
1359 self.pg_start()
1360
1361 packets = self.dst_if.get_capture(len(self.pkt_infos))
1362 self.verify_capture(packets)
1363 self.src_if.assert_nothing_captured()
1364
1365 # run it all again to verify correctness
1366 self.pg_enable_capture()
1367 self.src_if.add_stream(fragments)
1368 self.pg_start()
1369
1370 packets = self.dst_if.get_capture(len(self.pkt_infos))
1371 self.verify_capture(packets)
1372 self.src_if.assert_nothing_captured()
1373
1374 def test_duplicates(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001375 """duplicate fragments"""
Klement Sekera75e7d132017-09-20 08:26:30 +02001376
1377 fragments = [
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001378 x
1379 for (_, frags, _) in self.pkt_infos
Klement Sekera75e7d132017-09-20 08:26:30 +02001380 for x in frags
1381 for _ in range(0, min(2, len(frags)))
1382 ]
Klement Sekera947a85c2019-07-24 12:40:37 +00001383
1384 self.pg_enable_capture()
1385 self.src_if.add_stream(fragments)
1386 self.pg_start()
1387
1388 packets = self.dst_if.get_capture(len(self.pkt_infos))
1389 self.verify_capture(packets)
1390 self.src_if.assert_nothing_captured()
Klement Sekera75e7d132017-09-20 08:26:30 +02001391
Klement Sekera3a343d42019-05-16 14:35:46 +02001392 def test_long_fragment_chain(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001393 """long fragment chain"""
Klement Sekera3a343d42019-05-16 14:35:46 +02001394
Neale Rannse22a7042022-08-09 03:03:29 +00001395 error_cnt_str = "/err/ip6-full-reassembly-feature/reass_fragment_chain_too_long"
Klement Sekera3a343d42019-05-16 14:35:46 +02001396
Klement Sekera34641f22019-05-22 20:18:26 +02001397 error_cnt = self.statistics.get_err_counter(error_cnt_str)
Klement Sekera3a343d42019-05-16 14:35:46 +02001398
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001399 self.vapi.ip_reassembly_set(
1400 timeout_ms=100,
1401 max_reassemblies=1000,
1402 max_reassembly_length=3,
1403 expire_walk_interval_ms=50,
1404 is_ip6=1,
1405 )
Klement Sekera3a343d42019-05-16 14:35:46 +02001406
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001407 p = (
1408 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
1409 / IPv6(src=self.src_if.remote_ip6, dst=self.dst_if.remote_ip6)
1410 / UDP(sport=1234, dport=5678)
1411 / Raw(b"X" * 1000)
1412 )
Klement Sekera3a343d42019-05-16 14:35:46 +02001413 frags = fragment_rfc8200(p, 1, 300) + fragment_rfc8200(p, 2, 500)
1414
1415 self.pg_enable_capture()
1416 self.src_if.add_stream(frags)
1417 self.pg_start()
1418
1419 self.dst_if.get_capture(1)
Klement Sekera34641f22019-05-22 20:18:26 +02001420 self.assert_error_counter_equal(error_cnt_str, error_cnt + 1)
Klement Sekera3a343d42019-05-16 14:35:46 +02001421
Klement Sekera75e7d132017-09-20 08:26:30 +02001422 def test_overlap1(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001423 """overlapping fragments case #1"""
Klement Sekera75e7d132017-09-20 08:26:30 +02001424
1425 fragments = []
1426 for _, frags_400, frags_300 in self.pkt_infos:
1427 if len(frags_300) == 1:
1428 fragments.extend(frags_400)
1429 else:
1430 for i, j in zip(frags_300, frags_400):
1431 fragments.extend(i)
1432 fragments.extend(j)
1433
1434 dropped_packet_indexes = set(
1435 index for (index, _, frags) in self.pkt_infos if len(frags) > 1
1436 )
1437
1438 self.pg_enable_capture()
Klement Sekera4c533132018-02-22 11:41:12 +01001439 self.src_if.add_stream(fragments)
Klement Sekera75e7d132017-09-20 08:26:30 +02001440 self.pg_start()
1441
Klement Sekera4c533132018-02-22 11:41:12 +01001442 packets = self.dst_if.get_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001443 len(self.pkt_infos) - len(dropped_packet_indexes)
1444 )
Klement Sekera947a85c2019-07-24 12:40:37 +00001445 self.verify_capture(packets, dropped_packet_indexes)
Klement Sekera4c533132018-02-22 11:41:12 +01001446 self.src_if.assert_nothing_captured()
Klement Sekera75e7d132017-09-20 08:26:30 +02001447
1448 def test_overlap2(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001449 """overlapping fragments case #2"""
Klement Sekera75e7d132017-09-20 08:26:30 +02001450
1451 fragments = []
Klement Sekera4c533132018-02-22 11:41:12 +01001452 for _, frags_400, frags_300 in self.pkt_infos:
Klement Sekera75e7d132017-09-20 08:26:30 +02001453 if len(frags_400) == 1:
1454 fragments.extend(frags_400)
1455 else:
1456 # care must be taken here so that there are no fragments
1457 # received by vpp after reassembly is finished, otherwise
1458 # new reassemblies will be started and packet generator will
1459 # freak out when it detects unfreed buffers
Klement Sekera4c533132018-02-22 11:41:12 +01001460 zipped = zip(frags_400, frags_300)
Paul Vinciguerrac7834e02019-03-02 10:43:05 -08001461 for i, j in zipped:
Klement Sekera75e7d132017-09-20 08:26:30 +02001462 fragments.extend(i)
1463 fragments.extend(j)
Paul Vinciguerrac7834e02019-03-02 10:43:05 -08001464 fragments.pop()
Klement Sekera75e7d132017-09-20 08:26:30 +02001465
1466 dropped_packet_indexes = set(
1467 index for (index, _, frags) in self.pkt_infos if len(frags) > 1
1468 )
1469
1470 self.pg_enable_capture()
Klement Sekera4c533132018-02-22 11:41:12 +01001471 self.src_if.add_stream(fragments)
Klement Sekera75e7d132017-09-20 08:26:30 +02001472 self.pg_start()
1473
Klement Sekera4c533132018-02-22 11:41:12 +01001474 packets = self.dst_if.get_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001475 len(self.pkt_infos) - len(dropped_packet_indexes)
1476 )
Klement Sekera947a85c2019-07-24 12:40:37 +00001477 self.verify_capture(packets, dropped_packet_indexes)
Klement Sekera4c533132018-02-22 11:41:12 +01001478 self.src_if.assert_nothing_captured()
Klement Sekera75e7d132017-09-20 08:26:30 +02001479
Klement Sekera947a85c2019-07-24 12:40:37 +00001480 def test_timeout_inline(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001481 """timeout (inline)"""
Klement Sekera75e7d132017-09-20 08:26:30 +02001482
1483 dropped_packet_indexes = set(
1484 index for (index, frags, _) in self.pkt_infos if len(frags) > 1
1485 )
1486
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001487 self.vapi.ip_reassembly_set(
1488 timeout_ms=0,
1489 max_reassemblies=1000,
1490 max_reassembly_length=3,
1491 expire_walk_interval_ms=10000,
1492 is_ip6=1,
1493 )
Klement Sekera947a85c2019-07-24 12:40:37 +00001494
1495 self.pg_enable_capture()
1496 self.src_if.add_stream(self.fragments_400)
1497 self.pg_start()
1498
1499 packets = self.dst_if.get_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001500 len(self.pkt_infos) - len(dropped_packet_indexes)
1501 )
Klement Sekera947a85c2019-07-24 12:40:37 +00001502 self.verify_capture(packets, dropped_packet_indexes)
Neale Ranns5c6dd172022-02-17 09:08:47 +00001503 pkts = self.src_if._get_capture(1)
Klement Sekera75e7d132017-09-20 08:26:30 +02001504 for icmp in pkts:
1505 self.assertIn(ICMPv6TimeExceeded, icmp)
1506 self.assertIn(IPv6ExtHdrFragment, icmp)
1507 self.assertIn(icmp[IPv6ExtHdrFragment].id, dropped_packet_indexes)
1508 dropped_packet_indexes.remove(icmp[IPv6ExtHdrFragment].id)
1509
1510 def test_timeout_cleanup(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001511 """timeout (cleanup)"""
Klement Sekera75e7d132017-09-20 08:26:30 +02001512
1513 # whole packets + fragmented packets sans last fragment
1514 fragments = [
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001515 x
1516 for (_, frags_400, _) in self.pkt_infos
1517 for x in frags_400[: -1 if len(frags_400) > 1 else None]
Klement Sekera75e7d132017-09-20 08:26:30 +02001518 ]
1519
1520 # last fragments for fragmented packets
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001521 fragments2 = [
1522 frags_400[-1] for (_, frags_400, _) in self.pkt_infos if len(frags_400) > 1
1523 ]
Klement Sekera75e7d132017-09-20 08:26:30 +02001524
1525 dropped_packet_indexes = set(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001526 index for (index, frags_400, _) in self.pkt_infos if len(frags_400) > 1
1527 )
Klement Sekera75e7d132017-09-20 08:26:30 +02001528
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001529 self.vapi.ip_reassembly_set(
1530 timeout_ms=100,
1531 max_reassemblies=1000,
1532 max_reassembly_length=1000,
1533 expire_walk_interval_ms=50,
1534 )
Klement Sekera75e7d132017-09-20 08:26:30 +02001535
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001536 self.vapi.ip_reassembly_set(
1537 timeout_ms=100,
1538 max_reassemblies=1000,
1539 max_reassembly_length=1000,
1540 expire_walk_interval_ms=50,
1541 is_ip6=1,
1542 )
Klement Sekera75e7d132017-09-20 08:26:30 +02001543
1544 self.pg_enable_capture()
Klement Sekera4c533132018-02-22 11:41:12 +01001545 self.src_if.add_stream(fragments)
Klement Sekera75e7d132017-09-20 08:26:30 +02001546 self.pg_start()
1547
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001548 self.virtual_sleep(0.25, "wait before sending rest of fragments")
Klement Sekera75e7d132017-09-20 08:26:30 +02001549
Klement Sekera4c533132018-02-22 11:41:12 +01001550 self.src_if.add_stream(fragments2)
Klement Sekera75e7d132017-09-20 08:26:30 +02001551 self.pg_start()
Klement Sekera75e7d132017-09-20 08:26:30 +02001552
Klement Sekera4c533132018-02-22 11:41:12 +01001553 packets = self.dst_if.get_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001554 len(self.pkt_infos) - len(dropped_packet_indexes)
1555 )
Klement Sekera947a85c2019-07-24 12:40:37 +00001556 self.verify_capture(packets, dropped_packet_indexes)
Neale Ranns5c6dd172022-02-17 09:08:47 +00001557 pkts = self.src_if._get_capture(1)
Klement Sekera75e7d132017-09-20 08:26:30 +02001558 for icmp in pkts:
1559 self.assertIn(ICMPv6TimeExceeded, icmp)
1560 self.assertIn(IPv6ExtHdrFragment, icmp)
1561 self.assertIn(icmp[IPv6ExtHdrFragment].id, dropped_packet_indexes)
1562 dropped_packet_indexes.remove(icmp[IPv6ExtHdrFragment].id)
1563
Klement Sekera947a85c2019-07-24 12:40:37 +00001564 def test_disabled(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001565 """reassembly disabled"""
Klement Sekera75e7d132017-09-20 08:26:30 +02001566
1567 dropped_packet_indexes = set(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001568 index for (index, frags_400, _) in self.pkt_infos if len(frags_400) > 1
1569 )
Klement Sekera947a85c2019-07-24 12:40:37 +00001570
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001571 self.vapi.ip_reassembly_set(
1572 timeout_ms=1000,
1573 max_reassemblies=0,
1574 max_reassembly_length=3,
1575 expire_walk_interval_ms=10000,
1576 is_ip6=1,
1577 )
Klement Sekera947a85c2019-07-24 12:40:37 +00001578
1579 self.pg_enable_capture()
1580 self.src_if.add_stream(self.fragments_400)
1581 self.pg_start()
1582
1583 packets = self.dst_if.get_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001584 len(self.pkt_infos) - len(dropped_packet_indexes)
1585 )
Klement Sekera947a85c2019-07-24 12:40:37 +00001586 self.verify_capture(packets, dropped_packet_indexes)
Klement Sekera4c533132018-02-22 11:41:12 +01001587 self.src_if.assert_nothing_captured()
Klement Sekera75e7d132017-09-20 08:26:30 +02001588
1589 def test_missing_upper(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001590 """missing upper layer"""
1591 optdata = "\x00" * 100
1592 p = (
1593 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
1594 / IPv6(src=self.src_if.remote_ip6, dst=self.src_if.local_ip6)
1595 / IPv6ExtHdrFragment(m=1)
1596 / IPv6ExtHdrDestOpt(
1597 nh=17, options=PadN(optdata="\101" * 255) / PadN(optdata="\102" * 255)
1598 )
1599 )
Ole Troan03092c12021-11-23 15:55:39 +01001600
Klement Sekera75e7d132017-09-20 08:26:30 +02001601 self.pg_enable_capture()
Ole Troan03092c12021-11-23 15:55:39 +01001602 self.src_if.add_stream([p])
Klement Sekera75e7d132017-09-20 08:26:30 +02001603 self.pg_start()
Klement Sekera4c533132018-02-22 11:41:12 +01001604 pkts = self.src_if.get_capture(expected_count=1)
Klement Sekera75e7d132017-09-20 08:26:30 +02001605 icmp = pkts[0]
1606 self.assertIn(ICMPv6ParamProblem, icmp)
1607 self.assert_equal(icmp[ICMPv6ParamProblem].code, 3, "ICMP code")
1608
Klement Sekera755042d2021-12-01 10:14:38 +00001609 def test_truncated_fragment(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001610 """truncated fragment"""
1611 pkt = (
1612 Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac)
1613 / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6, nh=44, plen=2)
1614 / IPv6ExtHdrFragment(nh=6)
1615 )
Klement Sekera755042d2021-12-01 10:14:38 +00001616
1617 self.send_and_assert_no_replies(self.pg0, [pkt], self.pg0)
1618
Klement Sekera75e7d132017-09-20 08:26:30 +02001619 def test_invalid_frag_size(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001620 """fragment size not a multiple of 8"""
1621 p = (
1622 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
1623 / IPv6(src=self.src_if.remote_ip6, dst=self.src_if.local_ip6)
1624 / UDP(sport=1234, dport=5678)
1625 / Raw()
1626 )
Klement Sekera75e7d132017-09-20 08:26:30 +02001627 self.extend_packet(p, 1000, self.padding)
1628 fragments = fragment_rfc8200(p, 1, 500)
1629 bad_fragment = fragments[0]
1630 self.extend_packet(bad_fragment, len(bad_fragment) + 5)
1631 self.pg_enable_capture()
Klement Sekera4c533132018-02-22 11:41:12 +01001632 self.src_if.add_stream([bad_fragment])
Klement Sekera75e7d132017-09-20 08:26:30 +02001633 self.pg_start()
Klement Sekera4c533132018-02-22 11:41:12 +01001634 pkts = self.src_if.get_capture(expected_count=1)
Klement Sekera75e7d132017-09-20 08:26:30 +02001635 icmp = pkts[0]
1636 self.assertIn(ICMPv6ParamProblem, icmp)
1637 self.assert_equal(icmp[ICMPv6ParamProblem].code, 0, "ICMP code")
1638
1639 def test_invalid_packet_size(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001640 """total packet size > 65535"""
1641 p = (
1642 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
1643 / IPv6(src=self.src_if.remote_ip6, dst=self.src_if.local_ip6)
1644 / UDP(sport=1234, dport=5678)
1645 / Raw()
1646 )
Klement Sekera75e7d132017-09-20 08:26:30 +02001647 self.extend_packet(p, 1000, self.padding)
1648 fragments = fragment_rfc8200(p, 1, 500)
1649 bad_fragment = fragments[1]
1650 bad_fragment[IPv6ExtHdrFragment].offset = 65500
1651 self.pg_enable_capture()
Klement Sekera4c533132018-02-22 11:41:12 +01001652 self.src_if.add_stream([bad_fragment])
Klement Sekera75e7d132017-09-20 08:26:30 +02001653 self.pg_start()
Klement Sekera4c533132018-02-22 11:41:12 +01001654 pkts = self.src_if.get_capture(expected_count=1)
Klement Sekera75e7d132017-09-20 08:26:30 +02001655 icmp = pkts[0]
1656 self.assertIn(ICMPv6ParamProblem, icmp)
1657 self.assert_equal(icmp[ICMPv6ParamProblem].code, 0, "ICMP code")
1658
Ole Troan03092c12021-11-23 15:55:39 +01001659 def test_atomic_fragment(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001660 """IPv6 atomic fragment"""
1661 pkt = (
1662 Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac)
1663 / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6, nh=44, plen=65535)
1664 / IPv6ExtHdrFragment(
1665 offset=8191, m=1, res1=0xFF, res2=0xFF, nh=255, id=0xFFFF
1666 )
1667 / ("X" * 1452)
1668 )
Ole Troan03092c12021-11-23 15:55:39 +01001669
1670 rx = self.send_and_expect(self.pg0, [pkt], self.pg0)
1671 self.assertIn(ICMPv6ParamProblem, rx[0])
1672
1673 def test_truncated_fragment(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001674 """IPv6 truncated fragment header"""
1675 pkt = (
1676 Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac)
1677 / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6, nh=44, plen=2)
1678 / IPv6ExtHdrFragment(nh=6)
1679 )
Ole Troan03092c12021-11-23 15:55:39 +01001680
Klement Sekera7c3275e2021-12-07 09:49:53 +00001681 self.send_and_assert_no_replies(self.pg0, [pkt])
Ole Troan03092c12021-11-23 15:55:39 +01001682
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001683 pkt = (
1684 Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac)
1685 / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.remote_ip6)
1686 / ICMPv6EchoRequest()
1687 )
Ole Troan03092c12021-11-23 15:55:39 +01001688 rx = self.send_and_expect(self.pg0, [pkt], self.pg0)
1689
Klement Sekera7c3275e2021-12-07 09:49:53 +00001690 def test_one_fragment(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001691 """whole packet in one fragment processed independently"""
1692 pkt = (
1693 Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac)
1694 / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6)
1695 / ICMPv6EchoRequest()
1696 / Raw("X" * 1600)
1697 )
Klement Sekera7c3275e2021-12-07 09:49:53 +00001698 frags = fragment_rfc8200(pkt, 1, 400)
1699
1700 # send a fragment with known id
1701 self.send_and_assert_no_replies(self.pg0, [frags[0]])
1702
1703 # send an atomic fragment with same id - should be reassembled
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001704 pkt = (
1705 Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac)
1706 / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6)
1707 / IPv6ExtHdrFragment(id=1)
1708 / ICMPv6EchoRequest()
1709 )
Klement Sekera7c3275e2021-12-07 09:49:53 +00001710 rx = self.send_and_expect(self.pg0, [pkt], self.pg0)
1711 self.assertNotIn(IPv6ExtHdrFragment, rx)
1712
1713 # now finish the original reassembly, this should still be possible
1714 rx = self.send_and_expect(self.pg0, frags[1:], self.pg0, n_rx=1)
1715 self.assertNotIn(IPv6ExtHdrFragment, rx)
1716
1717 def test_bunch_of_fragments(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001718 """valid fragments followed by rogue fragments and atomic fragment"""
1719 pkt = (
1720 Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac)
1721 / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6)
1722 / ICMPv6EchoRequest()
1723 / Raw("X" * 1600)
1724 )
Klement Sekera7c3275e2021-12-07 09:49:53 +00001725 frags = fragment_rfc8200(pkt, 1, 400)
1726 self.send_and_expect(self.pg0, frags, self.pg0, n_rx=1)
1727
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001728 inc_frag = (
1729 Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac)
1730 / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6)
1731 / IPv6ExtHdrFragment(id=1, nh=58, offset=608)
1732 / Raw("X" * 308)
1733 )
Klement Sekera7c3275e2021-12-07 09:49:53 +00001734
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001735 self.send_and_assert_no_replies(self.pg0, inc_frag * 604)
Klement Sekera7c3275e2021-12-07 09:49:53 +00001736
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001737 pkt = (
1738 Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac)
1739 / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6)
1740 / IPv6ExtHdrFragment(id=1)
1741 / ICMPv6EchoRequest()
1742 )
Klement Sekera7c3275e2021-12-07 09:49:53 +00001743 rx = self.send_and_expect(self.pg0, [pkt], self.pg0)
1744 self.assertNotIn(IPv6ExtHdrFragment, rx)
1745
Klement Sekera01c1fa42021-12-14 18:25:11 +00001746 def test_local_enable_disable(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001747 """local reassembly enabled/disable"""
Klement Sekera01c1fa42021-12-14 18:25:11 +00001748 self.vapi.ip_reassembly_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001749 sw_if_index=self.src_if.sw_if_index, enable_ip6=False
1750 )
Klement Sekera01c1fa42021-12-14 18:25:11 +00001751 self.vapi.ip_local_reass_enable_disable(enable_ip6=True)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001752 pkt = (
1753 Ether(src=self.src_if.local_mac, dst=self.src_if.remote_mac)
1754 / IPv6(src=self.src_if.remote_ip6, dst=self.src_if.local_ip6)
1755 / ICMPv6EchoRequest(id=1234)
1756 / Raw("X" * 1600)
1757 )
Klement Sekera01c1fa42021-12-14 18:25:11 +00001758 frags = fragment_rfc8200(pkt, 1, 400)
1759 r = self.send_and_expect(self.src_if, frags, self.src_if, n_rx=1)[0]
1760 self.assertEqual(1234, r[ICMPv6EchoReply].id)
1761 self.vapi.ip_local_reass_enable_disable()
1762
1763 self.send_and_assert_no_replies(self.src_if, frags)
1764 self.vapi.ip_local_reass_enable_disable(enable_ip6=True)
1765
Klement Sekera75e7d132017-09-20 08:26:30 +02001766
Klement Sekera630ab582019-07-19 09:14:19 +00001767class TestIPv6MWReassembly(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001768 """IPv6 Reassembly (multiple workers)"""
1769
Klement Sekera8d815022021-03-15 16:58:10 +01001770 vpp_worker_count = 3
Klement Sekera630ab582019-07-19 09:14:19 +00001771
1772 @classmethod
1773 def setUpClass(cls):
Klement Sekera01c1fa42021-12-14 18:25:11 +00001774 super().setUpClass()
Klement Sekera630ab582019-07-19 09:14:19 +00001775
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001776 cls.create_pg_interfaces(range(cls.vpp_worker_count + 1))
Klement Sekera630ab582019-07-19 09:14:19 +00001777 cls.src_if = cls.pg0
1778 cls.send_ifs = cls.pg_interfaces[:-1]
1779 cls.dst_if = cls.pg_interfaces[-1]
1780
1781 # setup all interfaces
1782 for i in cls.pg_interfaces:
1783 i.admin_up()
1784 i.config_ip6()
1785 i.resolve_ndp()
1786
1787 # packets sizes reduced here because we are generating packets without
1788 # Ethernet headers, which are added later (diff fragments go via
1789 # different interfaces)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001790 cls.packet_sizes = [
1791 64 - len(Ether()),
1792 512 - len(Ether()),
1793 1518 - len(Ether()),
1794 9018 - len(Ether()),
1795 ]
Klement Sekera630ab582019-07-19 09:14:19 +00001796 cls.padding = " abcdefghijklmn"
1797 cls.create_stream(cls.packet_sizes)
1798 cls.create_fragments()
1799
1800 @classmethod
1801 def tearDownClass(cls):
Klement Sekera01c1fa42021-12-14 18:25:11 +00001802 super().tearDownClass()
Klement Sekera630ab582019-07-19 09:14:19 +00001803
1804 def setUp(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001805 """Test setup - force timeout on existing reassemblies"""
Klement Sekera01c1fa42021-12-14 18:25:11 +00001806 super().setUp()
Klement Sekera630ab582019-07-19 09:14:19 +00001807 for intf in self.send_ifs:
1808 self.vapi.ip_reassembly_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001809 sw_if_index=intf.sw_if_index, enable_ip6=True
1810 )
1811 self.vapi.ip_reassembly_set(
1812 timeout_ms=0,
1813 max_reassemblies=1000,
1814 max_reassembly_length=1000,
1815 expire_walk_interval_ms=10,
1816 is_ip6=1,
1817 )
1818 self.virtual_sleep(0.25)
1819 self.vapi.ip_reassembly_set(
1820 timeout_ms=1000000,
1821 max_reassemblies=1000,
1822 max_reassembly_length=1000,
1823 expire_walk_interval_ms=1000,
1824 is_ip6=1,
1825 )
Klement Sekera630ab582019-07-19 09:14:19 +00001826
1827 def tearDown(self):
Klement Sekera01c1fa42021-12-14 18:25:11 +00001828 for intf in self.send_ifs:
1829 self.vapi.ip_reassembly_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001830 sw_if_index=intf.sw_if_index, enable_ip6=False
1831 )
Klement Sekera01c1fa42021-12-14 18:25:11 +00001832 super().tearDown()
Klement Sekera630ab582019-07-19 09:14:19 +00001833
1834 def show_commands_at_teardown(self):
Klement Sekera896c8962019-06-24 11:52:49 +00001835 self.logger.debug(self.vapi.ppcli("show ip6-full-reassembly details"))
Klement Sekera630ab582019-07-19 09:14:19 +00001836 self.logger.debug(self.vapi.ppcli("show buffers"))
1837
1838 @classmethod
1839 def create_stream(cls, packet_sizes, packet_count=test_packet_count):
1840 """Create input packet stream
1841
1842 :param list packet_sizes: Required packet sizes.
1843 """
1844 for i in range(0, packet_count):
1845 info = cls.create_packet_info(cls.src_if, cls.src_if)
1846 payload = cls.info_to_payload(info)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001847 p = (
1848 IPv6(src=cls.src_if.remote_ip6, dst=cls.dst_if.remote_ip6)
1849 / UDP(sport=1234, dport=5678)
1850 / Raw(payload)
1851 )
Klement Sekera630ab582019-07-19 09:14:19 +00001852 size = packet_sizes[(i // 2) % len(packet_sizes)]
1853 cls.extend_packet(p, size, cls.padding)
1854 info.data = p
1855
1856 @classmethod
1857 def create_fragments(cls):
1858 infos = cls._packet_infos
1859 cls.pkt_infos = []
Paul Vinciguerra090096b2020-12-03 00:42:46 -05001860 for index, info in infos.items():
Klement Sekera630ab582019-07-19 09:14:19 +00001861 p = info.data
1862 # cls.logger.debug(ppp("Packet:",
1863 # p.__class__(scapy.compat.raw(p))))
1864 fragments_400 = fragment_rfc8200(p, index, 400)
1865 cls.pkt_infos.append((index, fragments_400))
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001866 cls.fragments_400 = [x for (_, frags) in cls.pkt_infos for x in frags]
1867 cls.logger.debug(
1868 "Fragmented %s packets into %s 400-byte fragments, "
1869 % (len(infos), len(cls.fragments_400))
1870 )
Klement Sekera630ab582019-07-19 09:14:19 +00001871
1872 def verify_capture(self, capture, dropped_packet_indexes=[]):
1873 """Verify captured packet strea .
1874
1875 :param list capture: Captured packet stream.
1876 """
1877 info = None
1878 seen = set()
1879 for packet in capture:
1880 try:
1881 self.logger.debug(ppp("Got packet:", packet))
1882 ip = packet[IPv6]
1883 udp = packet[UDP]
1884 payload_info = self.payload_to_info(packet[Raw])
1885 packet_index = payload_info.index
1886 self.assertTrue(
1887 packet_index not in dropped_packet_indexes,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001888 ppp("Packet received, but should be dropped:", packet),
1889 )
Klement Sekera630ab582019-07-19 09:14:19 +00001890 if packet_index in seen:
1891 raise Exception(ppp("Duplicate packet received", packet))
1892 seen.add(packet_index)
1893 self.assertEqual(payload_info.dst, self.src_if.sw_if_index)
1894 info = self._packet_infos[packet_index]
1895 self.assertTrue(info is not None)
1896 self.assertEqual(packet_index, info.index)
1897 saved_packet = info.data
1898 self.assertEqual(ip.src, saved_packet[IPv6].src)
1899 self.assertEqual(ip.dst, saved_packet[IPv6].dst)
1900 self.assertEqual(udp.payload, saved_packet[UDP].payload)
1901 except Exception:
1902 self.logger.error(ppp("Unexpected or invalid packet:", packet))
1903 raise
1904 for index in self._packet_infos:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001905 self.assertTrue(
1906 index in seen or index in dropped_packet_indexes,
1907 "Packet with packet_index %d not received" % index,
1908 )
Klement Sekera630ab582019-07-19 09:14:19 +00001909
1910 def send_packets(self, packets):
Klement Sekera8d815022021-03-15 16:58:10 +01001911 for counter in range(self.vpp_worker_count):
Klement Sekera630ab582019-07-19 09:14:19 +00001912 if 0 == len(packets[counter]):
1913 continue
1914 send_if = self.send_ifs[counter]
1915 send_if.add_stream(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001916 (
1917 Ether(dst=send_if.local_mac, src=send_if.remote_mac) / x
1918 for x in packets[counter]
1919 ),
1920 worker=counter,
1921 )
Klement Sekera630ab582019-07-19 09:14:19 +00001922 self.pg_start()
1923
1924 def test_worker_conflict(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001925 """1st and FO=0 fragments on different workers"""
Klement Sekera630ab582019-07-19 09:14:19 +00001926
1927 # in first wave we send fragments which don't start at offset 0
1928 # then we send fragments with offset 0 on a different thread
1929 # then the rest of packets on a random thread
Klement Sekera8d815022021-03-15 16:58:10 +01001930 first_packets = [[] for n in range(self.vpp_worker_count)]
1931 second_packets = [[] for n in range(self.vpp_worker_count)]
1932 rest_of_packets = [[] for n in range(self.vpp_worker_count)]
Klement Sekera630ab582019-07-19 09:14:19 +00001933 for (_, p) in self.pkt_infos:
Klement Sekera8d815022021-03-15 16:58:10 +01001934 wi = randrange(self.vpp_worker_count)
Klement Sekera630ab582019-07-19 09:14:19 +00001935 second_packets[wi].append(p[0])
1936 if len(p) <= 1:
1937 continue
1938 wi2 = wi
1939 while wi2 == wi:
Klement Sekera8d815022021-03-15 16:58:10 +01001940 wi2 = randrange(self.vpp_worker_count)
Klement Sekera630ab582019-07-19 09:14:19 +00001941 first_packets[wi2].append(p[1])
Klement Sekera8d815022021-03-15 16:58:10 +01001942 wi3 = randrange(self.vpp_worker_count)
Klement Sekera630ab582019-07-19 09:14:19 +00001943 rest_of_packets[wi3].extend(p[2:])
1944
1945 self.pg_enable_capture()
1946 self.send_packets(first_packets)
1947 self.send_packets(second_packets)
1948 self.send_packets(rest_of_packets)
1949
1950 packets = self.dst_if.get_capture(len(self.pkt_infos))
1951 self.verify_capture(packets)
1952 for send_if in self.send_ifs:
1953 send_if.assert_nothing_captured()
1954
Klement Sekera68bae5b2019-10-10 18:57:34 +00001955 self.logger.debug(self.vapi.ppcli("show trace"))
1956 self.logger.debug(self.vapi.ppcli("show ip6-full-reassembly details"))
1957 self.logger.debug(self.vapi.ppcli("show buffers"))
1958 self.vapi.cli("clear trace")
1959
Klement Sekera630ab582019-07-19 09:14:19 +00001960 self.pg_enable_capture()
1961 self.send_packets(first_packets)
1962 self.send_packets(second_packets)
1963 self.send_packets(rest_of_packets)
1964
1965 packets = self.dst_if.get_capture(len(self.pkt_infos))
1966 self.verify_capture(packets)
1967 for send_if in self.send_ifs:
1968 send_if.assert_nothing_captured()
1969
1970
Klement Sekerade34c352019-06-25 11:19:22 +00001971class TestIPv6SVReassembly(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001972 """IPv6 Shallow Virtual Reassembly"""
Klement Sekerade34c352019-06-25 11:19:22 +00001973
1974 @classmethod
1975 def setUpClass(cls):
Klement Sekera01c1fa42021-12-14 18:25:11 +00001976 super().setUpClass()
Klement Sekerade34c352019-06-25 11:19:22 +00001977
1978 cls.create_pg_interfaces([0, 1])
1979 cls.src_if = cls.pg0
1980 cls.dst_if = cls.pg1
1981
1982 # setup all interfaces
1983 for i in cls.pg_interfaces:
1984 i.admin_up()
1985 i.config_ip6()
1986 i.resolve_ndp()
1987
1988 def setUp(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001989 """Test setup - force timeout on existing reassemblies"""
Klement Sekera01c1fa42021-12-14 18:25:11 +00001990 super().setUp()
Klement Sekerade34c352019-06-25 11:19:22 +00001991 self.vapi.ip_reassembly_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001992 sw_if_index=self.src_if.sw_if_index,
1993 enable_ip6=True,
1994 type=VppEnum.vl_api_ip_reass_type_t.IP_REASS_TYPE_SHALLOW_VIRTUAL,
1995 )
Klement Sekerade34c352019-06-25 11:19:22 +00001996 self.vapi.ip_reassembly_set(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001997 timeout_ms=0,
1998 max_reassemblies=1000,
Klement Sekerade34c352019-06-25 11:19:22 +00001999 max_reassembly_length=1000,
2000 type=VppEnum.vl_api_ip_reass_type_t.IP_REASS_TYPE_SHALLOW_VIRTUAL,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002001 expire_walk_interval_ms=10,
2002 is_ip6=1,
2003 )
2004 self.virtual_sleep(0.25)
Klement Sekerade34c352019-06-25 11:19:22 +00002005 self.vapi.ip_reassembly_set(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002006 timeout_ms=1000000,
2007 max_reassemblies=1000,
Klement Sekerade34c352019-06-25 11:19:22 +00002008 max_reassembly_length=1000,
2009 type=VppEnum.vl_api_ip_reass_type_t.IP_REASS_TYPE_SHALLOW_VIRTUAL,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002010 expire_walk_interval_ms=10000,
2011 is_ip6=1,
2012 )
Klement Sekerade34c352019-06-25 11:19:22 +00002013
2014 def tearDown(self):
Klement Sekera01c1fa42021-12-14 18:25:11 +00002015 super().tearDown()
Klement Sekerade34c352019-06-25 11:19:22 +00002016 self.logger.debug(self.vapi.ppcli("show ip6-sv-reassembly details"))
2017 self.logger.debug(self.vapi.ppcli("show buffers"))
2018
2019 def test_basic(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002020 """basic reassembly"""
Klement Sekerade34c352019-06-25 11:19:22 +00002021 payload_len = 1000
2022 payload = ""
2023 counter = 0
2024 while len(payload) < payload_len:
2025 payload += "%u " % counter
2026 counter += 1
2027
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002028 p = (
2029 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
2030 / IPv6(src=self.src_if.remote_ip6, dst=self.dst_if.remote_ip6)
2031 / UDP(sport=1234, dport=5678)
2032 / Raw(payload)
2033 )
2034 fragments = fragment_rfc8200(p, 1, payload_len / 4)
Klement Sekerade34c352019-06-25 11:19:22 +00002035
2036 # send fragment #2 - should be cached inside reassembly
2037 self.pg_enable_capture()
2038 self.src_if.add_stream(fragments[1])
2039 self.pg_start()
2040 self.logger.debug(self.vapi.ppcli("show ip6-sv-reassembly details"))
2041 self.logger.debug(self.vapi.ppcli("show buffers"))
2042 self.logger.debug(self.vapi.ppcli("show trace"))
2043 self.dst_if.assert_nothing_captured()
2044
2045 # send fragment #1 - reassembly is finished now and both fragments
2046 # forwarded
2047 self.pg_enable_capture()
2048 self.src_if.add_stream(fragments[0])
2049 self.pg_start()
2050 self.logger.debug(self.vapi.ppcli("show ip6-sv-reassembly details"))
2051 self.logger.debug(self.vapi.ppcli("show buffers"))
2052 self.logger.debug(self.vapi.ppcli("show trace"))
2053 c = self.dst_if.get_capture(2)
2054 for sent, recvd in zip([fragments[1], fragments[0]], c):
2055 self.assertEqual(sent[IPv6].src, recvd[IPv6].src)
2056 self.assertEqual(sent[IPv6].dst, recvd[IPv6].dst)
2057 self.assertEqual(sent[Raw].payload, recvd[Raw].payload)
2058
2059 # send rest of fragments - should be immediately forwarded
2060 self.pg_enable_capture()
2061 self.src_if.add_stream(fragments[2:])
2062 self.pg_start()
2063 c = self.dst_if.get_capture(len(fragments[2:]))
2064 for sent, recvd in zip(fragments[2:], c):
2065 self.assertEqual(sent[IPv6].src, recvd[IPv6].src)
2066 self.assertEqual(sent[IPv6].dst, recvd[IPv6].dst)
2067 self.assertEqual(sent[Raw].payload, recvd[Raw].payload)
2068
Klement Sekera53be16d2020-12-15 21:47:36 +01002069 def test_verify_clear_trace_mid_reassembly(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002070 """verify clear trace works mid-reassembly"""
Klement Sekera53be16d2020-12-15 21:47:36 +01002071 payload_len = 1000
2072 payload = ""
2073 counter = 0
2074 while len(payload) < payload_len:
2075 payload += "%u " % counter
2076 counter += 1
2077
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002078 p = (
2079 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
2080 / IPv6(src=self.src_if.remote_ip6, dst=self.dst_if.remote_ip6)
2081 / UDP(sport=1234, dport=5678)
2082 / Raw(payload)
2083 )
2084 fragments = fragment_rfc8200(p, 1, payload_len / 4)
Klement Sekera53be16d2020-12-15 21:47:36 +01002085
2086 self.pg_enable_capture()
2087 self.src_if.add_stream(fragments[1])
2088 self.pg_start()
2089
2090 self.logger.debug(self.vapi.cli("show trace"))
2091 self.vapi.cli("clear trace")
2092
2093 self.pg_enable_capture()
2094 self.src_if.add_stream(fragments[0])
2095 self.pg_start()
2096 self.dst_if.get_capture(2)
2097
2098 self.logger.debug(self.vapi.cli("show trace"))
2099 self.vapi.cli("clear trace")
2100
2101 self.pg_enable_capture()
2102 self.src_if.add_stream(fragments[2:])
2103 self.pg_start()
2104 self.dst_if.get_capture(len(fragments[2:]))
2105
Klement Sekerade34c352019-06-25 11:19:22 +00002106 def test_timeout(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002107 """reassembly timeout"""
Klement Sekerade34c352019-06-25 11:19:22 +00002108 payload_len = 1000
2109 payload = ""
2110 counter = 0
2111 while len(payload) < payload_len:
2112 payload += "%u " % counter
2113 counter += 1
2114
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002115 p = (
2116 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
2117 / IPv6(src=self.src_if.remote_ip6, dst=self.dst_if.remote_ip6)
2118 / UDP(sport=1234, dport=5678)
2119 / Raw(payload)
2120 )
2121 fragments = fragment_rfc8200(p, 1, payload_len / 4)
Klement Sekerade34c352019-06-25 11:19:22 +00002122
2123 self.vapi.ip_reassembly_set(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002124 timeout_ms=100,
2125 max_reassemblies=1000,
Klement Sekerade34c352019-06-25 11:19:22 +00002126 max_reassembly_length=1000,
2127 expire_walk_interval_ms=50,
2128 is_ip6=1,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002129 type=VppEnum.vl_api_ip_reass_type_t.IP_REASS_TYPE_SHALLOW_VIRTUAL,
2130 )
Klement Sekerade34c352019-06-25 11:19:22 +00002131
2132 # send fragments #2 and #1 - should be forwarded
2133 self.pg_enable_capture()
2134 self.src_if.add_stream(fragments[0:2])
2135 self.pg_start()
2136 self.logger.debug(self.vapi.ppcli("show ip4-sv-reassembly details"))
2137 self.logger.debug(self.vapi.ppcli("show buffers"))
2138 self.logger.debug(self.vapi.ppcli("show trace"))
2139 c = self.dst_if.get_capture(2)
2140 for sent, recvd in zip([fragments[1], fragments[0]], c):
2141 self.assertEqual(sent[IPv6].src, recvd[IPv6].src)
2142 self.assertEqual(sent[IPv6].dst, recvd[IPv6].dst)
2143 self.assertEqual(sent[Raw].payload, recvd[Raw].payload)
2144
2145 # wait for cleanup
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002146 self.virtual_sleep(0.25, "wait before sending rest of fragments")
Klement Sekerade34c352019-06-25 11:19:22 +00002147
2148 # send rest of fragments - shouldn't be forwarded
2149 self.pg_enable_capture()
2150 self.src_if.add_stream(fragments[2:])
2151 self.pg_start()
2152 self.dst_if.assert_nothing_captured()
2153
2154 def test_lru(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002155 """reassembly reuses LRU element"""
Klement Sekerade34c352019-06-25 11:19:22 +00002156
2157 self.vapi.ip_reassembly_set(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002158 timeout_ms=1000000,
2159 max_reassemblies=1,
Klement Sekerade34c352019-06-25 11:19:22 +00002160 max_reassembly_length=1000,
2161 type=VppEnum.vl_api_ip_reass_type_t.IP_REASS_TYPE_SHALLOW_VIRTUAL,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002162 is_ip6=1,
2163 expire_walk_interval_ms=10000,
2164 )
Klement Sekerade34c352019-06-25 11:19:22 +00002165
2166 payload_len = 1000
2167 payload = ""
2168 counter = 0
2169 while len(payload) < payload_len:
2170 payload += "%u " % counter
2171 counter += 1
2172
2173 packet_count = 10
2174
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002175 fragments = [
2176 f
2177 for i in range(packet_count)
2178 for p in (
2179 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
2180 / IPv6(src=self.src_if.remote_ip6, dst=self.dst_if.remote_ip6)
2181 / UDP(sport=1234, dport=5678)
2182 / Raw(payload)
2183 )
2184 for f in fragment_rfc8200(p, i, payload_len / 4)
2185 ]
Klement Sekerade34c352019-06-25 11:19:22 +00002186
2187 self.pg_enable_capture()
2188 self.src_if.add_stream(fragments)
2189 self.pg_start()
2190 c = self.dst_if.get_capture(len(fragments))
2191 for sent, recvd in zip(fragments, c):
2192 self.assertEqual(sent[IPv6].src, recvd[IPv6].src)
2193 self.assertEqual(sent[IPv6].dst, recvd[IPv6].dst)
2194 self.assertEqual(sent[Raw].payload, recvd[Raw].payload)
2195
Klement Sekera7c3275e2021-12-07 09:49:53 +00002196 def test_one_fragment(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002197 """whole packet in one fragment processed independently"""
2198 pkt = (
2199 Ether(src=self.src_if.local_mac, dst=self.src_if.remote_mac)
2200 / IPv6(src=self.src_if.remote_ip6, dst=self.dst_if.remote_ip6)
2201 / ICMPv6EchoRequest()
2202 / Raw("X" * 1600)
2203 )
Klement Sekera7c3275e2021-12-07 09:49:53 +00002204 frags = fragment_rfc8200(pkt, 1, 400)
2205
2206 # send a fragment with known id
2207 self.send_and_expect(self.src_if, [frags[0]], self.dst_if)
2208
2209 # send an atomic fragment with same id - should be reassembled
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002210 pkt = (
2211 Ether(src=self.src_if.local_mac, dst=self.src_if.remote_mac)
2212 / IPv6(src=self.src_if.remote_ip6, dst=self.dst_if.remote_ip6)
2213 / IPv6ExtHdrFragment(id=1)
2214 / ICMPv6EchoRequest()
2215 )
Klement Sekera7c3275e2021-12-07 09:49:53 +00002216 rx = self.send_and_expect(self.src_if, [pkt], self.dst_if)
2217
2218 # now forward packets matching original reassembly, should still work
2219 rx = self.send_and_expect(self.src_if, frags[1:], self.dst_if)
2220
2221 def test_bunch_of_fragments(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002222 """valid fragments followed by rogue fragments and atomic fragment"""
2223 pkt = (
2224 Ether(src=self.src_if.local_mac, dst=self.src_if.remote_mac)
2225 / IPv6(src=self.src_if.remote_ip6, dst=self.dst_if.remote_ip6)
2226 / ICMPv6EchoRequest()
2227 / Raw("X" * 1600)
2228 )
Klement Sekera7c3275e2021-12-07 09:49:53 +00002229 frags = fragment_rfc8200(pkt, 1, 400)
2230 rx = self.send_and_expect(self.src_if, frags, self.dst_if)
2231
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002232 rogue = (
2233 Ether(src=self.src_if.local_mac, dst=self.src_if.remote_mac)
2234 / IPv6(src=self.src_if.remote_ip6, dst=self.dst_if.remote_ip6)
2235 / IPv6ExtHdrFragment(id=1, nh=58, offset=608)
2236 / Raw("X" * 308)
2237 )
Klement Sekera7c3275e2021-12-07 09:49:53 +00002238
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002239 self.send_and_expect(self.src_if, rogue * 604, self.dst_if)
Klement Sekera7c3275e2021-12-07 09:49:53 +00002240
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002241 pkt = (
2242 Ether(src=self.src_if.local_mac, dst=self.src_if.remote_mac)
2243 / IPv6(src=self.src_if.remote_ip6, dst=self.dst_if.remote_ip6)
2244 / IPv6ExtHdrFragment(id=1)
2245 / ICMPv6EchoRequest()
2246 )
Klement Sekera7c3275e2021-12-07 09:49:53 +00002247 rx = self.send_and_expect(self.src_if, [pkt], self.dst_if)
2248
Klement Sekera755042d2021-12-01 10:14:38 +00002249 def test_truncated_fragment(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002250 """truncated fragment"""
2251 pkt = (
2252 Ether(src=self.pg0.local_mac, dst=self.pg0.remote_mac)
2253 / IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6, nh=44, plen=2)
2254 / IPv6ExtHdrFragment(nh=6)
2255 )
Klement Sekera755042d2021-12-01 10:14:38 +00002256
2257 self.send_and_assert_no_replies(self.pg0, [pkt], self.pg0)
2258
Klement Sekerade34c352019-06-25 11:19:22 +00002259
Juraj Sloboda3048b632018-10-02 11:13:53 +02002260class TestIPv4ReassemblyLocalNode(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002261 """IPv4 Reassembly for packets coming to ip4-local node"""
Juraj Sloboda3048b632018-10-02 11:13:53 +02002262
2263 @classmethod
2264 def setUpClass(cls):
Klement Sekera01c1fa42021-12-14 18:25:11 +00002265 super().setUpClass()
Juraj Sloboda3048b632018-10-02 11:13:53 +02002266
2267 cls.create_pg_interfaces([0])
2268 cls.src_dst_if = cls.pg0
2269
2270 # setup all interfaces
2271 for i in cls.pg_interfaces:
2272 i.admin_up()
2273 i.config_ip4()
2274 i.resolve_arp()
2275
2276 cls.padding = " abcdefghijklmn"
2277 cls.create_stream()
2278 cls.create_fragments()
2279
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07002280 @classmethod
2281 def tearDownClass(cls):
Klement Sekera01c1fa42021-12-14 18:25:11 +00002282 super().tearDownClass()
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07002283
Juraj Sloboda3048b632018-10-02 11:13:53 +02002284 def setUp(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002285 """Test setup - force timeout on existing reassemblies"""
Klement Sekera01c1fa42021-12-14 18:25:11 +00002286 super().setUp()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002287 self.vapi.ip_reassembly_set(
2288 timeout_ms=0,
2289 max_reassemblies=1000,
2290 max_reassembly_length=1000,
2291 expire_walk_interval_ms=10,
2292 )
2293 self.virtual_sleep(0.25)
2294 self.vapi.ip_reassembly_set(
2295 timeout_ms=1000000,
2296 max_reassemblies=1000,
2297 max_reassembly_length=1000,
2298 expire_walk_interval_ms=10000,
2299 )
Juraj Sloboda3048b632018-10-02 11:13:53 +02002300
2301 def tearDown(self):
Klement Sekera01c1fa42021-12-14 18:25:11 +00002302 super().tearDown()
Paul Vinciguerra90cf21b2019-03-13 09:23:05 -07002303
2304 def show_commands_at_teardown(self):
Klement Sekera896c8962019-06-24 11:52:49 +00002305 self.logger.debug(self.vapi.ppcli("show ip4-full-reassembly details"))
Klement Sekeracae98b72019-02-19 13:53:43 +01002306 self.logger.debug(self.vapi.ppcli("show buffers"))
Juraj Sloboda3048b632018-10-02 11:13:53 +02002307
2308 @classmethod
2309 def create_stream(cls, packet_count=test_packet_count):
2310 """Create input packet stream for defined interface.
2311
2312 :param list packet_sizes: Required packet sizes.
2313 """
2314 for i in range(0, packet_count):
2315 info = cls.create_packet_info(cls.src_dst_if, cls.src_dst_if)
2316 payload = cls.info_to_payload(info)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002317 p = (
2318 Ether(dst=cls.src_dst_if.local_mac, src=cls.src_dst_if.remote_mac)
2319 / IP(
2320 id=info.index,
2321 src=cls.src_dst_if.remote_ip4,
2322 dst=cls.src_dst_if.local_ip4,
2323 )
2324 / ICMP(type="echo-request", id=1234)
2325 / Raw(payload)
2326 )
Juraj Sloboda3048b632018-10-02 11:13:53 +02002327 cls.extend_packet(p, 1518, cls.padding)
2328 info.data = p
2329
2330 @classmethod
2331 def create_fragments(cls):
2332 infos = cls._packet_infos
2333 cls.pkt_infos = []
Paul Vinciguerra090096b2020-12-03 00:42:46 -05002334 for index, info in infos.items():
Juraj Sloboda3048b632018-10-02 11:13:53 +02002335 p = info.data
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -07002336 # cls.logger.debug(ppp("Packet:",
2337 # p.__class__(scapy.compat.raw(p))))
Juraj Sloboda3048b632018-10-02 11:13:53 +02002338 fragments_300 = fragment_rfc791(p, 300)
2339 cls.pkt_infos.append((index, fragments_300))
2340 cls.fragments_300 = [x for (_, frags) in cls.pkt_infos for x in frags]
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002341 cls.logger.debug(
2342 "Fragmented %s packets into %s 300-byte fragments"
2343 % (len(infos), len(cls.fragments_300))
2344 )
Juraj Sloboda3048b632018-10-02 11:13:53 +02002345
2346 def verify_capture(self, capture):
2347 """Verify captured packet stream.
2348
2349 :param list capture: Captured packet stream.
2350 """
2351 info = None
2352 seen = set()
2353 for packet in capture:
2354 try:
2355 self.logger.debug(ppp("Got packet:", packet))
2356 ip = packet[IP]
2357 icmp = packet[ICMP]
Paul Vinciguerraeaea4212019-03-06 11:58:06 -08002358 payload_info = self.payload_to_info(packet[Raw])
Juraj Sloboda3048b632018-10-02 11:13:53 +02002359 packet_index = payload_info.index
2360 if packet_index in seen:
2361 raise Exception(ppp("Duplicate packet received", packet))
2362 seen.add(packet_index)
2363 self.assertEqual(payload_info.dst, self.src_dst_if.sw_if_index)
2364 info = self._packet_infos[packet_index]
Klement Sekera14d7e902018-12-10 13:46:09 +01002365 self.assertIsNotNone(info)
Juraj Sloboda3048b632018-10-02 11:13:53 +02002366 self.assertEqual(packet_index, info.index)
2367 saved_packet = info.data
2368 self.assertEqual(ip.src, saved_packet[IP].dst)
2369 self.assertEqual(ip.dst, saved_packet[IP].src)
2370 self.assertEqual(icmp.type, 0) # echo reply
2371 self.assertEqual(icmp.id, saved_packet[ICMP].id)
2372 self.assertEqual(icmp.payload, saved_packet[ICMP].payload)
2373 except Exception:
2374 self.logger.error(ppp("Unexpected or invalid packet:", packet))
2375 raise
2376 for index in self._packet_infos:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002377 self.assertIn(
2378 index, seen, "Packet with packet_index %d not received" % index
2379 )
Juraj Sloboda3048b632018-10-02 11:13:53 +02002380
2381 def test_reassembly(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002382 """basic reassembly"""
Juraj Sloboda3048b632018-10-02 11:13:53 +02002383
2384 self.pg_enable_capture()
2385 self.src_dst_if.add_stream(self.fragments_300)
2386 self.pg_start()
2387
2388 packets = self.src_dst_if.get_capture(len(self.pkt_infos))
2389 self.verify_capture(packets)
2390
2391 # run it all again to verify correctness
2392 self.pg_enable_capture()
2393 self.src_dst_if.add_stream(self.fragments_300)
2394 self.pg_start()
2395
2396 packets = self.src_dst_if.get_capture(len(self.pkt_infos))
2397 self.verify_capture(packets)
2398
2399
Klement Sekera75e7d132017-09-20 08:26:30 +02002400class TestFIFReassembly(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002401 """Fragments in fragments reassembly"""
Klement Sekera75e7d132017-09-20 08:26:30 +02002402
2403 @classmethod
2404 def setUpClass(cls):
Klement Sekera01c1fa42021-12-14 18:25:11 +00002405 super().setUpClass()
Klement Sekera75e7d132017-09-20 08:26:30 +02002406
Klement Sekera4c533132018-02-22 11:41:12 +01002407 cls.create_pg_interfaces([0, 1])
2408 cls.src_if = cls.pg0
2409 cls.dst_if = cls.pg1
2410 for i in cls.pg_interfaces:
2411 i.admin_up()
2412 i.config_ip4()
2413 i.resolve_arp()
2414 i.config_ip6()
2415 i.resolve_ndp()
Klement Sekera75e7d132017-09-20 08:26:30 +02002416
Klement Sekera75e7d132017-09-20 08:26:30 +02002417 cls.packet_sizes = [64, 512, 1518, 9018]
2418 cls.padding = " abcdefghijklmn"
2419
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07002420 @classmethod
2421 def tearDownClass(cls):
Klement Sekera01c1fa42021-12-14 18:25:11 +00002422 super().tearDownClass()
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07002423
Klement Sekera75e7d132017-09-20 08:26:30 +02002424 def setUp(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002425 """Test setup - force timeout on existing reassemblies"""
Klement Sekera01c1fa42021-12-14 18:25:11 +00002426 super().setUp()
Klement Sekera4c533132018-02-22 11:41:12 +01002427 self.vapi.ip_reassembly_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002428 sw_if_index=self.src_if.sw_if_index, enable_ip4=True, enable_ip6=True
2429 )
Klement Sekera4c533132018-02-22 11:41:12 +01002430 self.vapi.ip_reassembly_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002431 sw_if_index=self.dst_if.sw_if_index, enable_ip4=True, enable_ip6=True
2432 )
2433 self.vapi.ip_reassembly_set(
2434 timeout_ms=0,
2435 max_reassemblies=1000,
2436 max_reassembly_length=1000,
2437 expire_walk_interval_ms=10,
2438 )
2439 self.vapi.ip_reassembly_set(
2440 timeout_ms=0,
2441 max_reassemblies=1000,
2442 max_reassembly_length=1000,
2443 expire_walk_interval_ms=10,
2444 is_ip6=1,
2445 )
2446 self.virtual_sleep(0.25)
2447 self.vapi.ip_reassembly_set(
2448 timeout_ms=1000000,
2449 max_reassemblies=1000,
2450 max_reassembly_length=1000,
2451 expire_walk_interval_ms=10000,
2452 )
2453 self.vapi.ip_reassembly_set(
2454 timeout_ms=1000000,
2455 max_reassemblies=1000,
2456 max_reassembly_length=1000,
2457 expire_walk_interval_ms=10000,
2458 is_ip6=1,
2459 )
Klement Sekera75e7d132017-09-20 08:26:30 +02002460
2461 def tearDown(self):
Klement Sekera01c1fa42021-12-14 18:25:11 +00002462 super().tearDown()
Paul Vinciguerra90cf21b2019-03-13 09:23:05 -07002463
2464 def show_commands_at_teardown(self):
Klement Sekera896c8962019-06-24 11:52:49 +00002465 self.logger.debug(self.vapi.ppcli("show ip4-full-reassembly details"))
2466 self.logger.debug(self.vapi.ppcli("show ip6-full-reassembly details"))
Klement Sekeracae98b72019-02-19 13:53:43 +01002467 self.logger.debug(self.vapi.ppcli("show buffers"))
Klement Sekera75e7d132017-09-20 08:26:30 +02002468
2469 def verify_capture(self, capture, ip_class, dropped_packet_indexes=[]):
2470 """Verify captured packet stream.
2471
2472 :param list capture: Captured packet stream.
2473 """
2474 info = None
2475 seen = set()
2476 for packet in capture:
2477 try:
Klement Sekera4c533132018-02-22 11:41:12 +01002478 self.logger.debug(ppp("Got packet:", packet))
Klement Sekera75e7d132017-09-20 08:26:30 +02002479 ip = packet[ip_class]
2480 udp = packet[UDP]
Paul Vinciguerraeaea4212019-03-06 11:58:06 -08002481 payload_info = self.payload_to_info(packet[Raw])
Klement Sekera75e7d132017-09-20 08:26:30 +02002482 packet_index = payload_info.index
2483 self.assertTrue(
2484 packet_index not in dropped_packet_indexes,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002485 ppp("Packet received, but should be dropped:", packet),
2486 )
Klement Sekera75e7d132017-09-20 08:26:30 +02002487 if packet_index in seen:
2488 raise Exception(ppp("Duplicate packet received", packet))
2489 seen.add(packet_index)
Klement Sekera4c533132018-02-22 11:41:12 +01002490 self.assertEqual(payload_info.dst, self.dst_if.sw_if_index)
Klement Sekera75e7d132017-09-20 08:26:30 +02002491 info = self._packet_infos[packet_index]
2492 self.assertTrue(info is not None)
2493 self.assertEqual(packet_index, info.index)
2494 saved_packet = info.data
2495 self.assertEqual(ip.src, saved_packet[ip_class].src)
2496 self.assertEqual(ip.dst, saved_packet[ip_class].dst)
2497 self.assertEqual(udp.payload, saved_packet[UDP].payload)
Klement Sekera4c533132018-02-22 11:41:12 +01002498 except Exception:
Klement Sekera75e7d132017-09-20 08:26:30 +02002499 self.logger.error(ppp("Unexpected or invalid packet:", packet))
2500 raise
2501 for index in self._packet_infos:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002502 self.assertTrue(
2503 index in seen or index in dropped_packet_indexes,
2504 "Packet with packet_index %d not received" % index,
2505 )
Klement Sekera75e7d132017-09-20 08:26:30 +02002506
2507 def test_fif4(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002508 """Fragments in fragments (4o4)"""
Klement Sekera75e7d132017-09-20 08:26:30 +02002509
2510 # TODO this should be ideally in setUpClass, but then we hit a bug
2511 # with VppIpRoute incorrectly reporting it's present when it's not
2512 # so we need to manually remove the vpp config, thus we cannot have
2513 # it shared for multiple test cases
2514 self.tun_ip4 = "1.1.1.2"
2515
Klement Sekera4c533132018-02-22 11:41:12 +01002516 self.gre4 = VppGreInterface(self, self.src_if.local_ip4, self.tun_ip4)
Klement Sekera75e7d132017-09-20 08:26:30 +02002517 self.gre4.add_vpp_config()
2518 self.gre4.admin_up()
2519 self.gre4.config_ip4()
2520
Klement Sekera4c533132018-02-22 11:41:12 +01002521 self.vapi.ip_reassembly_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002522 sw_if_index=self.gre4.sw_if_index, enable_ip4=True
2523 )
Klement Sekera4c533132018-02-22 11:41:12 +01002524
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002525 self.route4 = VppIpRoute(
2526 self,
2527 self.tun_ip4,
2528 32,
2529 [VppRoutePath(self.src_if.remote_ip4, self.src_if.sw_if_index)],
2530 )
Klement Sekera75e7d132017-09-20 08:26:30 +02002531 self.route4.add_vpp_config()
2532
2533 self.reset_packet_infos()
2534 for i in range(test_packet_count):
Klement Sekera4c533132018-02-22 11:41:12 +01002535 info = self.create_packet_info(self.src_if, self.dst_if)
Klement Sekera75e7d132017-09-20 08:26:30 +02002536 payload = self.info_to_payload(info)
Klement Sekera4c533132018-02-22 11:41:12 +01002537 # Ethernet header here is only for size calculation, thus it
2538 # doesn't matter how it's initialized. This is to ensure that
2539 # reassembled packet is not > 9000 bytes, so that it's not dropped
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002540 p = (
2541 Ether()
2542 / IP(id=i, src=self.src_if.remote_ip4, dst=self.dst_if.remote_ip4)
2543 / UDP(sport=1234, dport=5678)
2544 / Raw(payload)
2545 )
Klement Sekera75e7d132017-09-20 08:26:30 +02002546 size = self.packet_sizes[(i // 2) % len(self.packet_sizes)]
2547 self.extend_packet(p, size, self.padding)
Klement Sekera4c533132018-02-22 11:41:12 +01002548 info.data = p[IP] # use only IP part, without ethernet header
Klement Sekera75e7d132017-09-20 08:26:30 +02002549
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002550 fragments = [
2551 x
2552 for _, p in self._packet_infos.items()
2553 for x in fragment_rfc791(p.data, 400)
2554 ]
Klement Sekera75e7d132017-09-20 08:26:30 +02002555
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002556 encapped_fragments = [
2557 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
2558 / IP(src=self.tun_ip4, dst=self.src_if.local_ip4)
2559 / GRE()
2560 / p
2561 for p in fragments
2562 ]
Klement Sekera75e7d132017-09-20 08:26:30 +02002563
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002564 fragmented_encapped_fragments = [
2565 x for p in encapped_fragments for x in fragment_rfc791(p, 200)
2566 ]
Klement Sekera75e7d132017-09-20 08:26:30 +02002567
Klement Sekera4c533132018-02-22 11:41:12 +01002568 self.src_if.add_stream(fragmented_encapped_fragments)
Klement Sekera75e7d132017-09-20 08:26:30 +02002569
2570 self.pg_enable_capture(self.pg_interfaces)
2571 self.pg_start()
2572
Klement Sekera4c533132018-02-22 11:41:12 +01002573 self.src_if.assert_nothing_captured()
2574 packets = self.dst_if.get_capture(len(self._packet_infos))
Klement Sekera75e7d132017-09-20 08:26:30 +02002575 self.verify_capture(packets, IP)
2576
2577 # TODO remove gre vpp config by hand until VppIpRoute gets fixed
2578 # so that it's query_vpp_config() works as it should
2579 self.gre4.remove_vpp_config()
Klement Sekera4c533132018-02-22 11:41:12 +01002580 self.logger.debug(self.vapi.ppcli("show interface"))
Klement Sekera75e7d132017-09-20 08:26:30 +02002581
2582 def test_fif6(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002583 """Fragments in fragments (6o6)"""
Klement Sekera75e7d132017-09-20 08:26:30 +02002584 # TODO this should be ideally in setUpClass, but then we hit a bug
2585 # with VppIpRoute incorrectly reporting it's present when it's not
2586 # so we need to manually remove the vpp config, thus we cannot have
2587 # it shared for multiple test cases
2588 self.tun_ip6 = "1002::1"
2589
Neale Ranns5a8844b2019-04-16 07:15:35 +00002590 self.gre6 = VppGreInterface(self, self.src_if.local_ip6, self.tun_ip6)
Klement Sekera75e7d132017-09-20 08:26:30 +02002591 self.gre6.add_vpp_config()
2592 self.gre6.admin_up()
2593 self.gre6.config_ip6()
2594
Klement Sekera4c533132018-02-22 11:41:12 +01002595 self.vapi.ip_reassembly_enable_disable(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002596 sw_if_index=self.gre6.sw_if_index, enable_ip6=True
2597 )
Klement Sekera4c533132018-02-22 11:41:12 +01002598
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002599 self.route6 = VppIpRoute(
2600 self,
2601 self.tun_ip6,
2602 128,
2603 [VppRoutePath(self.src_if.remote_ip6, self.src_if.sw_if_index)],
2604 )
Klement Sekera75e7d132017-09-20 08:26:30 +02002605 self.route6.add_vpp_config()
2606
2607 self.reset_packet_infos()
2608 for i in range(test_packet_count):
Klement Sekera4c533132018-02-22 11:41:12 +01002609 info = self.create_packet_info(self.src_if, self.dst_if)
Klement Sekera75e7d132017-09-20 08:26:30 +02002610 payload = self.info_to_payload(info)
Klement Sekera4c533132018-02-22 11:41:12 +01002611 # Ethernet header here is only for size calculation, thus it
2612 # doesn't matter how it's initialized. This is to ensure that
2613 # reassembled packet is not > 9000 bytes, so that it's not dropped
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002614 p = (
2615 Ether()
2616 / IPv6(src=self.src_if.remote_ip6, dst=self.dst_if.remote_ip6)
2617 / UDP(sport=1234, dport=5678)
2618 / Raw(payload)
2619 )
Klement Sekera75e7d132017-09-20 08:26:30 +02002620 size = self.packet_sizes[(i // 2) % len(self.packet_sizes)]
2621 self.extend_packet(p, size, self.padding)
Klement Sekera4c533132018-02-22 11:41:12 +01002622 info.data = p[IPv6] # use only IPv6 part, without ethernet header
Klement Sekera75e7d132017-09-20 08:26:30 +02002623
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002624 fragments = [
2625 x
2626 for _, i in self._packet_infos.items()
2627 for x in fragment_rfc8200(i.data, i.index, 400)
2628 ]
Klement Sekera75e7d132017-09-20 08:26:30 +02002629
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002630 encapped_fragments = [
2631 Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac)
2632 / IPv6(src=self.tun_ip6, dst=self.src_if.local_ip6)
2633 / GRE()
2634 / p
2635 for p in fragments
2636 ]
Klement Sekera75e7d132017-09-20 08:26:30 +02002637
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002638 fragmented_encapped_fragments = [
2639 x
2640 for p in encapped_fragments
2641 for x in (
Klement Sekera75e7d132017-09-20 08:26:30 +02002642 fragment_rfc8200(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002643 p, 2 * len(self._packet_infos) + p[IPv6ExtHdrFragment].id, 200
2644 )
2645 if IPv6ExtHdrFragment in p
2646 else [p]
Klement Sekera75e7d132017-09-20 08:26:30 +02002647 )
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002648 ]
Klement Sekera75e7d132017-09-20 08:26:30 +02002649
Klement Sekera4c533132018-02-22 11:41:12 +01002650 self.src_if.add_stream(fragmented_encapped_fragments)
Klement Sekera75e7d132017-09-20 08:26:30 +02002651
2652 self.pg_enable_capture(self.pg_interfaces)
2653 self.pg_start()
2654
Klement Sekera4c533132018-02-22 11:41:12 +01002655 self.src_if.assert_nothing_captured()
2656 packets = self.dst_if.get_capture(len(self._packet_infos))
Klement Sekera75e7d132017-09-20 08:26:30 +02002657 self.verify_capture(packets, IPv6)
2658
2659 # TODO remove gre vpp config by hand until VppIpRoute gets fixed
2660 # so that it's query_vpp_config() works as it should
Klement Sekera3ecc2212018-03-27 10:34:43 +02002661 self.gre6.remove_vpp_config()
Klement Sekera75e7d132017-09-20 08:26:30 +02002662
2663
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02002664if __name__ == "__main__":
Klement Sekera75e7d132017-09-20 08:26:30 +02002665 unittest.main(testRunner=VppTestRunner)