Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | import unittest |
| 3 | from random import shuffle |
| 4 | |
| 5 | from framework import VppTestCase, VppTestRunner |
| 6 | |
| 7 | from scapy.packet import Raw |
| 8 | from scapy.layers.l2 import Ether, GRE |
| 9 | from scapy.layers.inet import IP, UDP |
| 10 | from util import ppp, fragment_rfc791, fragment_rfc8200 |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 11 | from scapy.layers.inet6 import IPv6, IPv6ExtHdrFragment, ICMPv6ParamProblem,\ |
| 12 | ICMPv6TimeExceeded |
| 13 | from vpp_gre_interface import VppGreInterface, VppGre6Interface |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame^] | 14 | from vpp_ip import DpoProto |
| 15 | from vpp_ip_route import VppIpRoute, VppRoutePath |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 16 | |
| 17 | test_packet_count = 257 |
| 18 | |
| 19 | |
| 20 | class TestIPv4Reassembly(VppTestCase): |
| 21 | """ IPv4 Reassembly """ |
| 22 | |
| 23 | @classmethod |
| 24 | def setUpClass(cls): |
| 25 | super(TestIPv4Reassembly, cls).setUpClass() |
| 26 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 27 | cls.create_pg_interfaces([0, 1]) |
| 28 | cls.src_if = cls.pg0 |
| 29 | cls.dst_if = cls.pg1 |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 30 | |
| 31 | # setup all interfaces |
| 32 | for i in cls.pg_interfaces: |
| 33 | i.admin_up() |
| 34 | i.config_ip4() |
| 35 | i.resolve_arp() |
| 36 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 37 | # packet sizes |
| 38 | cls.packet_sizes = [64, 512, 1518, 9018] |
| 39 | cls.padding = " abcdefghijklmn" |
| 40 | cls.create_stream(cls.packet_sizes) |
| 41 | cls.create_fragments() |
| 42 | |
| 43 | def setUp(self): |
| 44 | """ Test setup - force timeout on existing reassemblies """ |
| 45 | super(TestIPv4Reassembly, self).setUp() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 46 | self.vapi.ip_reassembly_enable_disable( |
| 47 | sw_if_index=self.src_if.sw_if_index, enable_ip4=True) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 48 | self.vapi.ip_reassembly_set(timeout_ms=0, max_reassemblies=1000, |
| 49 | expire_walk_interval_ms=10) |
| 50 | self.sleep(.25) |
| 51 | self.vapi.ip_reassembly_set(timeout_ms=1000000, max_reassemblies=1000, |
| 52 | expire_walk_interval_ms=10000) |
| 53 | |
| 54 | def tearDown(self): |
| 55 | super(TestIPv4Reassembly, self).tearDown() |
| 56 | self.logger.debug(self.vapi.ppcli("show ip4-reassembly details")) |
| 57 | |
| 58 | @classmethod |
| 59 | def create_stream(cls, packet_sizes, packet_count=test_packet_count): |
| 60 | """Create input packet stream for defined interface. |
| 61 | |
| 62 | :param list packet_sizes: Required packet sizes. |
| 63 | """ |
| 64 | for i in range(0, packet_count): |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 65 | info = cls.create_packet_info(cls.src_if, cls.src_if) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 66 | payload = cls.info_to_payload(info) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 67 | p = (Ether(dst=cls.src_if.local_mac, src=cls.src_if.remote_mac) / |
| 68 | IP(id=info.index, src=cls.src_if.remote_ip4, |
| 69 | dst=cls.dst_if.remote_ip4) / |
| 70 | UDP(sport=1234, dport=5678) / |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 71 | Raw(payload)) |
| 72 | size = packet_sizes[(i // 2) % len(packet_sizes)] |
| 73 | cls.extend_packet(p, size, cls.padding) |
| 74 | info.data = p |
| 75 | |
| 76 | @classmethod |
| 77 | def create_fragments(cls): |
| 78 | infos = cls._packet_infos |
| 79 | cls.pkt_infos = [] |
| 80 | for index, info in infos.iteritems(): |
| 81 | p = info.data |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 82 | # cls.logger.debug(ppp("Packet:", p.__class__(str(p)))) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 83 | fragments_400 = fragment_rfc791(p, 400) |
| 84 | fragments_300 = fragment_rfc791(p, 300) |
| 85 | fragments_200 = [ |
| 86 | x for f in fragments_400 for x in fragment_rfc791(f, 200)] |
| 87 | cls.pkt_infos.append( |
| 88 | (index, fragments_400, fragments_300, fragments_200)) |
| 89 | cls.fragments_400 = [ |
| 90 | x for (_, frags, _, _) in cls.pkt_infos for x in frags] |
| 91 | cls.fragments_300 = [ |
| 92 | x for (_, _, frags, _) in cls.pkt_infos for x in frags] |
| 93 | cls.fragments_200 = [ |
| 94 | x for (_, _, _, frags) in cls.pkt_infos for x in frags] |
| 95 | cls.logger.debug("Fragmented %s packets into %s 400-byte fragments, " |
| 96 | "%s 300-byte fragments and %s 200-byte fragments" % |
| 97 | (len(infos), len(cls.fragments_400), |
| 98 | len(cls.fragments_300), len(cls.fragments_200))) |
| 99 | |
| 100 | def verify_capture(self, capture, dropped_packet_indexes=[]): |
| 101 | """Verify captured packet stream. |
| 102 | |
| 103 | :param list capture: Captured packet stream. |
| 104 | """ |
| 105 | info = None |
| 106 | seen = set() |
| 107 | for packet in capture: |
| 108 | try: |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 109 | self.logger.debug(ppp("Got packet:", packet)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 110 | ip = packet[IP] |
| 111 | udp = packet[UDP] |
| 112 | payload_info = self.payload_to_info(str(packet[Raw])) |
| 113 | packet_index = payload_info.index |
| 114 | self.assertTrue( |
| 115 | packet_index not in dropped_packet_indexes, |
| 116 | ppp("Packet received, but should be dropped:", packet)) |
| 117 | if packet_index in seen: |
| 118 | raise Exception(ppp("Duplicate packet received", packet)) |
| 119 | seen.add(packet_index) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 120 | self.assertEqual(payload_info.dst, self.src_if.sw_if_index) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 121 | info = self._packet_infos[packet_index] |
| 122 | self.assertTrue(info is not None) |
| 123 | self.assertEqual(packet_index, info.index) |
| 124 | saved_packet = info.data |
| 125 | self.assertEqual(ip.src, saved_packet[IP].src) |
| 126 | self.assertEqual(ip.dst, saved_packet[IP].dst) |
| 127 | self.assertEqual(udp.payload, saved_packet[UDP].payload) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 128 | except Exception: |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 129 | self.logger.error(ppp("Unexpected or invalid packet:", packet)) |
| 130 | raise |
| 131 | for index in self._packet_infos: |
| 132 | self.assertTrue(index in seen or index in dropped_packet_indexes, |
| 133 | "Packet with packet_index %d not received" % index) |
| 134 | |
| 135 | def test_reassembly(self): |
| 136 | """ basic reassembly """ |
| 137 | |
| 138 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 139 | self.src_if.add_stream(self.fragments_200) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 140 | self.pg_start() |
| 141 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 142 | packets = self.dst_if.get_capture(len(self.pkt_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 143 | self.verify_capture(packets) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 144 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 145 | |
| 146 | # run it all again to verify correctness |
| 147 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 148 | self.src_if.add_stream(self.fragments_200) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 149 | self.pg_start() |
| 150 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 151 | packets = self.dst_if.get_capture(len(self.pkt_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 152 | self.verify_capture(packets) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 153 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 154 | |
| 155 | def test_reversed(self): |
| 156 | """ reverse order reassembly """ |
| 157 | |
| 158 | fragments = list(self.fragments_200) |
| 159 | fragments.reverse() |
| 160 | |
| 161 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 162 | self.src_if.add_stream(fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 163 | self.pg_start() |
| 164 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 165 | packets = self.dst_if.get_capture(len(self.packet_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 166 | self.verify_capture(packets) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 167 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 168 | |
| 169 | # run it all again to verify correctness |
| 170 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 171 | self.src_if.add_stream(fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 172 | self.pg_start() |
| 173 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 174 | packets = self.dst_if.get_capture(len(self.packet_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 175 | self.verify_capture(packets) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 176 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 177 | |
| 178 | def test_random(self): |
| 179 | """ random order reassembly """ |
| 180 | |
| 181 | fragments = list(self.fragments_200) |
| 182 | shuffle(fragments) |
| 183 | |
| 184 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 185 | self.src_if.add_stream(fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 186 | self.pg_start() |
| 187 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 188 | packets = self.dst_if.get_capture(len(self.packet_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 189 | self.verify_capture(packets) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 190 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 191 | |
| 192 | # run it all again to verify correctness |
| 193 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 194 | self.src_if.add_stream(fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 195 | self.pg_start() |
| 196 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 197 | packets = self.dst_if.get_capture(len(self.packet_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 198 | self.verify_capture(packets) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 199 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 200 | |
| 201 | def test_duplicates(self): |
| 202 | """ duplicate fragments """ |
| 203 | |
| 204 | fragments = [ |
| 205 | x for (_, frags, _, _) in self.pkt_infos |
| 206 | for x in frags |
| 207 | for _ in range(0, min(2, len(frags))) |
| 208 | ] |
| 209 | |
| 210 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 211 | self.src_if.add_stream(fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 212 | self.pg_start() |
| 213 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 214 | packets = self.dst_if.get_capture(len(self.pkt_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 215 | self.verify_capture(packets) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 216 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 217 | |
| 218 | def test_overlap1(self): |
| 219 | """ overlapping fragments case #1 """ |
| 220 | |
| 221 | fragments = [] |
| 222 | for _, _, frags_300, frags_200 in self.pkt_infos: |
| 223 | if len(frags_300) == 1: |
| 224 | fragments.extend(frags_300) |
| 225 | else: |
| 226 | for i, j in zip(frags_200, frags_300): |
| 227 | fragments.extend(i) |
| 228 | fragments.extend(j) |
| 229 | |
| 230 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 231 | self.src_if.add_stream(fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 232 | self.pg_start() |
| 233 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 234 | packets = self.dst_if.get_capture(len(self.pkt_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 235 | self.verify_capture(packets) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 236 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 237 | |
| 238 | # run it all to verify correctness |
| 239 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 240 | self.src_if.add_stream(fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 241 | self.pg_start() |
| 242 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 243 | packets = self.dst_if.get_capture(len(self.pkt_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 244 | self.verify_capture(packets) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 245 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 246 | |
| 247 | def test_overlap2(self): |
| 248 | """ overlapping fragments case #2 """ |
| 249 | |
| 250 | fragments = [] |
| 251 | for _, _, frags_300, frags_200 in self.pkt_infos: |
| 252 | if len(frags_300) == 1: |
| 253 | fragments.extend(frags_300) |
| 254 | else: |
| 255 | # care must be taken here so that there are no fragments |
| 256 | # received by vpp after reassembly is finished, otherwise |
| 257 | # new reassemblies will be started and packet generator will |
| 258 | # freak out when it detects unfreed buffers |
| 259 | zipped = zip(frags_300, frags_200) |
| 260 | for i, j in zipped[:-1]: |
| 261 | fragments.extend(i) |
| 262 | fragments.extend(j) |
| 263 | fragments.append(zipped[-1][0]) |
| 264 | |
| 265 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 266 | self.src_if.add_stream(fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 267 | self.pg_start() |
| 268 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 269 | packets = self.dst_if.get_capture(len(self.pkt_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 270 | self.verify_capture(packets) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 271 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 272 | |
| 273 | # run it all to verify correctness |
| 274 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 275 | self.src_if.add_stream(fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 276 | self.pg_start() |
| 277 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 278 | packets = self.dst_if.get_capture(len(self.pkt_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 279 | self.verify_capture(packets) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 280 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 281 | |
| 282 | def test_timeout_inline(self): |
| 283 | """ timeout (inline) """ |
| 284 | |
| 285 | dropped_packet_indexes = set( |
| 286 | index for (index, frags, _, _) in self.pkt_infos if len(frags) > 1 |
| 287 | ) |
| 288 | |
| 289 | self.vapi.ip_reassembly_set(timeout_ms=0, max_reassemblies=1000, |
| 290 | expire_walk_interval_ms=10000) |
| 291 | |
| 292 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 293 | self.src_if.add_stream(self.fragments_400) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 294 | self.pg_start() |
| 295 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 296 | packets = self.dst_if.get_capture( |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 297 | len(self.pkt_infos) - len(dropped_packet_indexes)) |
| 298 | self.verify_capture(packets, dropped_packet_indexes) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 299 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 300 | |
| 301 | def test_timeout_cleanup(self): |
| 302 | """ timeout (cleanup) """ |
| 303 | |
| 304 | # whole packets + fragmented packets sans last fragment |
| 305 | fragments = [ |
| 306 | x for (_, frags_400, _, _) in self.pkt_infos |
| 307 | for x in frags_400[:-1 if len(frags_400) > 1 else None] |
| 308 | ] |
| 309 | |
| 310 | # last fragments for fragmented packets |
| 311 | fragments2 = [frags_400[-1] |
| 312 | for (_, frags_400, _, _) in self.pkt_infos |
| 313 | if len(frags_400) > 1] |
| 314 | |
| 315 | dropped_packet_indexes = set( |
| 316 | index for (index, frags_400, _, _) in self.pkt_infos |
| 317 | if len(frags_400) > 1) |
| 318 | |
| 319 | self.vapi.ip_reassembly_set(timeout_ms=100, max_reassemblies=1000, |
| 320 | expire_walk_interval_ms=50) |
| 321 | |
| 322 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 323 | self.src_if.add_stream(fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 324 | self.pg_start() |
| 325 | |
| 326 | self.sleep(.25, "wait before sending rest of fragments") |
| 327 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 328 | self.src_if.add_stream(fragments2) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 329 | self.pg_start() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 330 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 331 | packets = self.dst_if.get_capture( |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 332 | len(self.pkt_infos) - len(dropped_packet_indexes)) |
| 333 | self.verify_capture(packets, dropped_packet_indexes) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 334 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 335 | |
| 336 | def test_disabled(self): |
| 337 | """ reassembly disabled """ |
| 338 | |
| 339 | dropped_packet_indexes = set( |
| 340 | index for (index, frags_400, _, _) in self.pkt_infos |
| 341 | if len(frags_400) > 1) |
| 342 | |
| 343 | self.vapi.ip_reassembly_set(timeout_ms=1000, max_reassemblies=0, |
| 344 | expire_walk_interval_ms=10000) |
| 345 | |
| 346 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 347 | self.src_if.add_stream(self.fragments_400) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 348 | self.pg_start() |
| 349 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 350 | packets = self.dst_if.get_capture( |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 351 | len(self.pkt_infos) - len(dropped_packet_indexes)) |
| 352 | self.verify_capture(packets, dropped_packet_indexes) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 353 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 354 | |
| 355 | |
| 356 | class TestIPv6Reassembly(VppTestCase): |
| 357 | """ IPv6 Reassembly """ |
| 358 | |
| 359 | @classmethod |
| 360 | def setUpClass(cls): |
| 361 | super(TestIPv6Reassembly, cls).setUpClass() |
| 362 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 363 | cls.create_pg_interfaces([0, 1]) |
| 364 | cls.src_if = cls.pg0 |
| 365 | cls.dst_if = cls.pg1 |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 366 | |
| 367 | # setup all interfaces |
| 368 | for i in cls.pg_interfaces: |
| 369 | i.admin_up() |
| 370 | i.config_ip6() |
| 371 | i.resolve_ndp() |
| 372 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 373 | # packet sizes |
| 374 | cls.packet_sizes = [64, 512, 1518, 9018] |
| 375 | cls.padding = " abcdefghijklmn" |
| 376 | cls.create_stream(cls.packet_sizes) |
| 377 | cls.create_fragments() |
| 378 | |
| 379 | def setUp(self): |
| 380 | """ Test setup - force timeout on existing reassemblies """ |
| 381 | super(TestIPv6Reassembly, self).setUp() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 382 | self.vapi.ip_reassembly_enable_disable( |
| 383 | sw_if_index=self.src_if.sw_if_index, enable_ip6=True) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 384 | self.vapi.ip_reassembly_set(timeout_ms=0, max_reassemblies=1000, |
| 385 | expire_walk_interval_ms=10, is_ip6=1) |
| 386 | self.sleep(.25) |
| 387 | self.vapi.ip_reassembly_set(timeout_ms=1000000, max_reassemblies=1000, |
| 388 | expire_walk_interval_ms=10000, is_ip6=1) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 389 | self.logger.debug(self.vapi.ppcli("show ip6-reassembly details")) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 390 | |
| 391 | def tearDown(self): |
| 392 | super(TestIPv6Reassembly, self).tearDown() |
| 393 | self.logger.debug(self.vapi.ppcli("show ip6-reassembly details")) |
| 394 | |
| 395 | @classmethod |
| 396 | def create_stream(cls, packet_sizes, packet_count=test_packet_count): |
| 397 | """Create input packet stream for defined interface. |
| 398 | |
| 399 | :param list packet_sizes: Required packet sizes. |
| 400 | """ |
| 401 | for i in range(0, packet_count): |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 402 | info = cls.create_packet_info(cls.src_if, cls.src_if) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 403 | payload = cls.info_to_payload(info) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 404 | p = (Ether(dst=cls.src_if.local_mac, src=cls.src_if.remote_mac) / |
| 405 | IPv6(src=cls.src_if.remote_ip6, |
| 406 | dst=cls.dst_if.remote_ip6) / |
| 407 | UDP(sport=1234, dport=5678) / |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 408 | Raw(payload)) |
| 409 | size = packet_sizes[(i // 2) % len(packet_sizes)] |
| 410 | cls.extend_packet(p, size, cls.padding) |
| 411 | info.data = p |
| 412 | |
| 413 | @classmethod |
| 414 | def create_fragments(cls): |
| 415 | infos = cls._packet_infos |
| 416 | cls.pkt_infos = [] |
| 417 | for index, info in infos.iteritems(): |
| 418 | p = info.data |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 419 | # cls.logger.debug(ppp("Packet:", p.__class__(str(p)))) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 420 | fragments_400 = fragment_rfc8200(p, info.index, 400) |
| 421 | fragments_300 = fragment_rfc8200(p, info.index, 300) |
| 422 | cls.pkt_infos.append((index, fragments_400, fragments_300)) |
| 423 | cls.fragments_400 = [ |
| 424 | x for _, frags, _ in cls.pkt_infos for x in frags] |
| 425 | cls.fragments_300 = [ |
| 426 | x for _, _, frags in cls.pkt_infos for x in frags] |
| 427 | cls.logger.debug("Fragmented %s packets into %s 400-byte fragments, " |
| 428 | "and %s 300-byte fragments" % |
| 429 | (len(infos), len(cls.fragments_400), |
| 430 | len(cls.fragments_300))) |
| 431 | |
| 432 | def verify_capture(self, capture, dropped_packet_indexes=[]): |
| 433 | """Verify captured packet strea . |
| 434 | |
| 435 | :param list capture: Captured packet stream. |
| 436 | """ |
| 437 | info = None |
| 438 | seen = set() |
| 439 | for packet in capture: |
| 440 | try: |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 441 | self.logger.debug(ppp("Got packet:", packet)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 442 | ip = packet[IPv6] |
| 443 | udp = packet[UDP] |
| 444 | payload_info = self.payload_to_info(str(packet[Raw])) |
| 445 | packet_index = payload_info.index |
| 446 | self.assertTrue( |
| 447 | packet_index not in dropped_packet_indexes, |
| 448 | ppp("Packet received, but should be dropped:", packet)) |
| 449 | if packet_index in seen: |
| 450 | raise Exception(ppp("Duplicate packet received", packet)) |
| 451 | seen.add(packet_index) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 452 | self.assertEqual(payload_info.dst, self.src_if.sw_if_index) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 453 | info = self._packet_infos[packet_index] |
| 454 | self.assertTrue(info is not None) |
| 455 | self.assertEqual(packet_index, info.index) |
| 456 | saved_packet = info.data |
| 457 | self.assertEqual(ip.src, saved_packet[IPv6].src) |
| 458 | self.assertEqual(ip.dst, saved_packet[IPv6].dst) |
| 459 | self.assertEqual(udp.payload, saved_packet[UDP].payload) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 460 | except Exception: |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 461 | self.logger.error(ppp("Unexpected or invalid packet:", packet)) |
| 462 | raise |
| 463 | for index in self._packet_infos: |
| 464 | self.assertTrue(index in seen or index in dropped_packet_indexes, |
| 465 | "Packet with packet_index %d not received" % index) |
| 466 | |
| 467 | def test_reassembly(self): |
| 468 | """ basic reassembly """ |
| 469 | |
| 470 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 471 | self.src_if.add_stream(self.fragments_400) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 472 | self.pg_start() |
| 473 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 474 | packets = self.dst_if.get_capture(len(self.pkt_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 475 | self.verify_capture(packets) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 476 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 477 | |
| 478 | # run it all again to verify correctness |
| 479 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 480 | self.src_if.add_stream(self.fragments_400) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 481 | self.pg_start() |
| 482 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 483 | packets = self.dst_if.get_capture(len(self.pkt_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 484 | self.verify_capture(packets) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 485 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 486 | |
| 487 | def test_reversed(self): |
| 488 | """ reverse order reassembly """ |
| 489 | |
| 490 | fragments = list(self.fragments_400) |
| 491 | fragments.reverse() |
| 492 | |
| 493 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 494 | self.src_if.add_stream(fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 495 | self.pg_start() |
| 496 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 497 | packets = self.dst_if.get_capture(len(self.pkt_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 498 | self.verify_capture(packets) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 499 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 500 | |
| 501 | # run it all again to verify correctness |
| 502 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 503 | self.src_if.add_stream(fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 504 | self.pg_start() |
| 505 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 506 | packets = self.dst_if.get_capture(len(self.pkt_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 507 | self.verify_capture(packets) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 508 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 509 | |
| 510 | def test_random(self): |
| 511 | """ random order reassembly """ |
| 512 | |
| 513 | fragments = list(self.fragments_400) |
| 514 | shuffle(fragments) |
| 515 | |
| 516 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 517 | self.src_if.add_stream(fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 518 | self.pg_start() |
| 519 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 520 | packets = self.dst_if.get_capture(len(self.pkt_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 521 | self.verify_capture(packets) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 522 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 523 | |
| 524 | # run it all again to verify correctness |
| 525 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 526 | self.src_if.add_stream(fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 527 | self.pg_start() |
| 528 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 529 | packets = self.dst_if.get_capture(len(self.pkt_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 530 | self.verify_capture(packets) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 531 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 532 | |
| 533 | def test_duplicates(self): |
| 534 | """ duplicate fragments """ |
| 535 | |
| 536 | fragments = [ |
| 537 | x for (_, frags, _) in self.pkt_infos |
| 538 | for x in frags |
| 539 | for _ in range(0, min(2, len(frags))) |
| 540 | ] |
| 541 | |
| 542 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 543 | self.src_if.add_stream(fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 544 | self.pg_start() |
| 545 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 546 | packets = self.dst_if.get_capture(len(self.pkt_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 547 | self.verify_capture(packets) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 548 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 549 | |
| 550 | def test_overlap1(self): |
| 551 | """ overlapping fragments case #1 """ |
| 552 | |
| 553 | fragments = [] |
| 554 | for _, frags_400, frags_300 in self.pkt_infos: |
| 555 | if len(frags_300) == 1: |
| 556 | fragments.extend(frags_400) |
| 557 | else: |
| 558 | for i, j in zip(frags_300, frags_400): |
| 559 | fragments.extend(i) |
| 560 | fragments.extend(j) |
| 561 | |
| 562 | dropped_packet_indexes = set( |
| 563 | index for (index, _, frags) in self.pkt_infos if len(frags) > 1 |
| 564 | ) |
| 565 | |
| 566 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 567 | self.src_if.add_stream(fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 568 | self.pg_start() |
| 569 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 570 | packets = self.dst_if.get_capture( |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 571 | len(self.pkt_infos) - len(dropped_packet_indexes)) |
| 572 | self.verify_capture(packets, dropped_packet_indexes) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 573 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 574 | |
| 575 | def test_overlap2(self): |
| 576 | """ overlapping fragments case #2 """ |
| 577 | |
| 578 | fragments = [] |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 579 | for _, frags_400, frags_300 in self.pkt_infos: |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 580 | if len(frags_400) == 1: |
| 581 | fragments.extend(frags_400) |
| 582 | else: |
| 583 | # care must be taken here so that there are no fragments |
| 584 | # received by vpp after reassembly is finished, otherwise |
| 585 | # new reassemblies will be started and packet generator will |
| 586 | # freak out when it detects unfreed buffers |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 587 | zipped = zip(frags_400, frags_300) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 588 | for i, j in zipped[:-1]: |
| 589 | fragments.extend(i) |
| 590 | fragments.extend(j) |
| 591 | fragments.append(zipped[-1][0]) |
| 592 | |
| 593 | dropped_packet_indexes = set( |
| 594 | index for (index, _, frags) in self.pkt_infos if len(frags) > 1 |
| 595 | ) |
| 596 | |
| 597 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 598 | self.src_if.add_stream(fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 599 | self.pg_start() |
| 600 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 601 | packets = self.dst_if.get_capture( |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 602 | len(self.pkt_infos) - len(dropped_packet_indexes)) |
| 603 | self.verify_capture(packets, dropped_packet_indexes) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 604 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 605 | |
| 606 | def test_timeout_inline(self): |
| 607 | """ timeout (inline) """ |
| 608 | |
| 609 | dropped_packet_indexes = set( |
| 610 | index for (index, frags, _) in self.pkt_infos if len(frags) > 1 |
| 611 | ) |
| 612 | |
| 613 | self.vapi.ip_reassembly_set(timeout_ms=0, max_reassemblies=1000, |
| 614 | expire_walk_interval_ms=10000, is_ip6=1) |
| 615 | |
| 616 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 617 | self.src_if.add_stream(self.fragments_400) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 618 | self.pg_start() |
| 619 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 620 | packets = self.dst_if.get_capture( |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 621 | len(self.pkt_infos) - len(dropped_packet_indexes)) |
| 622 | self.verify_capture(packets, dropped_packet_indexes) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 623 | pkts = self.src_if.get_capture( |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 624 | expected_count=len(dropped_packet_indexes)) |
| 625 | for icmp in pkts: |
| 626 | self.assertIn(ICMPv6TimeExceeded, icmp) |
| 627 | self.assertIn(IPv6ExtHdrFragment, icmp) |
| 628 | self.assertIn(icmp[IPv6ExtHdrFragment].id, dropped_packet_indexes) |
| 629 | dropped_packet_indexes.remove(icmp[IPv6ExtHdrFragment].id) |
| 630 | |
| 631 | def test_timeout_cleanup(self): |
| 632 | """ timeout (cleanup) """ |
| 633 | |
| 634 | # whole packets + fragmented packets sans last fragment |
| 635 | fragments = [ |
| 636 | x for (_, frags_400, _) in self.pkt_infos |
| 637 | for x in frags_400[:-1 if len(frags_400) > 1 else None] |
| 638 | ] |
| 639 | |
| 640 | # last fragments for fragmented packets |
| 641 | fragments2 = [frags_400[-1] |
| 642 | for (_, frags_400, _) in self.pkt_infos |
| 643 | if len(frags_400) > 1] |
| 644 | |
| 645 | dropped_packet_indexes = set( |
| 646 | index for (index, frags_400, _) in self.pkt_infos |
| 647 | if len(frags_400) > 1) |
| 648 | |
| 649 | self.vapi.ip_reassembly_set(timeout_ms=100, max_reassemblies=1000, |
| 650 | expire_walk_interval_ms=50) |
| 651 | |
| 652 | self.vapi.ip_reassembly_set(timeout_ms=100, max_reassemblies=1000, |
| 653 | expire_walk_interval_ms=50, is_ip6=1) |
| 654 | |
| 655 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 656 | self.src_if.add_stream(fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 657 | self.pg_start() |
| 658 | |
| 659 | self.sleep(.25, "wait before sending rest of fragments") |
| 660 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 661 | self.src_if.add_stream(fragments2) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 662 | self.pg_start() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 663 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 664 | packets = self.dst_if.get_capture( |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 665 | len(self.pkt_infos) - len(dropped_packet_indexes)) |
| 666 | self.verify_capture(packets, dropped_packet_indexes) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 667 | pkts = self.src_if.get_capture( |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 668 | expected_count=len(dropped_packet_indexes)) |
| 669 | for icmp in pkts: |
| 670 | self.assertIn(ICMPv6TimeExceeded, icmp) |
| 671 | self.assertIn(IPv6ExtHdrFragment, icmp) |
| 672 | self.assertIn(icmp[IPv6ExtHdrFragment].id, dropped_packet_indexes) |
| 673 | dropped_packet_indexes.remove(icmp[IPv6ExtHdrFragment].id) |
| 674 | |
| 675 | def test_disabled(self): |
| 676 | """ reassembly disabled """ |
| 677 | |
| 678 | dropped_packet_indexes = set( |
| 679 | index for (index, frags_400, _) in self.pkt_infos |
| 680 | if len(frags_400) > 1) |
| 681 | |
| 682 | self.vapi.ip_reassembly_set(timeout_ms=1000, max_reassemblies=0, |
| 683 | expire_walk_interval_ms=10000, is_ip6=1) |
| 684 | |
| 685 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 686 | self.src_if.add_stream(self.fragments_400) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 687 | self.pg_start() |
| 688 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 689 | packets = self.dst_if.get_capture( |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 690 | len(self.pkt_infos) - len(dropped_packet_indexes)) |
| 691 | self.verify_capture(packets, dropped_packet_indexes) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 692 | self.src_if.assert_nothing_captured() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 693 | |
| 694 | def test_missing_upper(self): |
| 695 | """ missing upper layer """ |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 696 | p = (Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac) / |
| 697 | IPv6(src=self.src_if.remote_ip6, |
| 698 | dst=self.src_if.local_ip6) / |
| 699 | UDP(sport=1234, dport=5678) / |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 700 | Raw()) |
| 701 | self.extend_packet(p, 1000, self.padding) |
| 702 | fragments = fragment_rfc8200(p, 1, 500) |
| 703 | bad_fragment = p.__class__(str(fragments[1])) |
| 704 | bad_fragment[IPv6ExtHdrFragment].nh = 59 |
| 705 | bad_fragment[IPv6ExtHdrFragment].offset = 0 |
| 706 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 707 | self.src_if.add_stream([bad_fragment]) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 708 | self.pg_start() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 709 | pkts = self.src_if.get_capture(expected_count=1) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 710 | icmp = pkts[0] |
| 711 | self.assertIn(ICMPv6ParamProblem, icmp) |
| 712 | self.assert_equal(icmp[ICMPv6ParamProblem].code, 3, "ICMP code") |
| 713 | |
| 714 | def test_invalid_frag_size(self): |
| 715 | """ fragment size not a multiple of 8 """ |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 716 | p = (Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac) / |
| 717 | IPv6(src=self.src_if.remote_ip6, |
| 718 | dst=self.src_if.local_ip6) / |
| 719 | UDP(sport=1234, dport=5678) / |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 720 | Raw()) |
| 721 | self.extend_packet(p, 1000, self.padding) |
| 722 | fragments = fragment_rfc8200(p, 1, 500) |
| 723 | bad_fragment = fragments[0] |
| 724 | self.extend_packet(bad_fragment, len(bad_fragment) + 5) |
| 725 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 726 | self.src_if.add_stream([bad_fragment]) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 727 | self.pg_start() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 728 | pkts = self.src_if.get_capture(expected_count=1) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 729 | icmp = pkts[0] |
| 730 | self.assertIn(ICMPv6ParamProblem, icmp) |
| 731 | self.assert_equal(icmp[ICMPv6ParamProblem].code, 0, "ICMP code") |
| 732 | |
| 733 | def test_invalid_packet_size(self): |
| 734 | """ total packet size > 65535 """ |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 735 | p = (Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac) / |
| 736 | IPv6(src=self.src_if.remote_ip6, |
| 737 | dst=self.src_if.local_ip6) / |
| 738 | UDP(sport=1234, dport=5678) / |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 739 | Raw()) |
| 740 | self.extend_packet(p, 1000, self.padding) |
| 741 | fragments = fragment_rfc8200(p, 1, 500) |
| 742 | bad_fragment = fragments[1] |
| 743 | bad_fragment[IPv6ExtHdrFragment].offset = 65500 |
| 744 | self.pg_enable_capture() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 745 | self.src_if.add_stream([bad_fragment]) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 746 | self.pg_start() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 747 | pkts = self.src_if.get_capture(expected_count=1) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 748 | icmp = pkts[0] |
| 749 | self.assertIn(ICMPv6ParamProblem, icmp) |
| 750 | self.assert_equal(icmp[ICMPv6ParamProblem].code, 0, "ICMP code") |
| 751 | |
| 752 | |
| 753 | class TestFIFReassembly(VppTestCase): |
| 754 | """ Fragments in fragments reassembly """ |
| 755 | |
| 756 | @classmethod |
| 757 | def setUpClass(cls): |
| 758 | super(TestFIFReassembly, cls).setUpClass() |
| 759 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 760 | cls.create_pg_interfaces([0, 1]) |
| 761 | cls.src_if = cls.pg0 |
| 762 | cls.dst_if = cls.pg1 |
| 763 | for i in cls.pg_interfaces: |
| 764 | i.admin_up() |
| 765 | i.config_ip4() |
| 766 | i.resolve_arp() |
| 767 | i.config_ip6() |
| 768 | i.resolve_ndp() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 769 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 770 | cls.packet_sizes = [64, 512, 1518, 9018] |
| 771 | cls.padding = " abcdefghijklmn" |
| 772 | |
| 773 | def setUp(self): |
| 774 | """ Test setup - force timeout on existing reassemblies """ |
| 775 | super(TestFIFReassembly, self).setUp() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 776 | self.vapi.ip_reassembly_enable_disable( |
| 777 | sw_if_index=self.src_if.sw_if_index, enable_ip4=True, |
| 778 | enable_ip6=True) |
| 779 | self.vapi.ip_reassembly_enable_disable( |
| 780 | sw_if_index=self.dst_if.sw_if_index, enable_ip4=True, |
| 781 | enable_ip6=True) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 782 | self.vapi.ip_reassembly_set(timeout_ms=0, max_reassemblies=1000, |
| 783 | expire_walk_interval_ms=10) |
| 784 | self.vapi.ip_reassembly_set(timeout_ms=0, max_reassemblies=1000, |
| 785 | expire_walk_interval_ms=10, is_ip6=1) |
| 786 | self.sleep(.25) |
| 787 | self.vapi.ip_reassembly_set(timeout_ms=1000000, max_reassemblies=1000, |
| 788 | expire_walk_interval_ms=10000) |
| 789 | self.vapi.ip_reassembly_set(timeout_ms=1000000, max_reassemblies=1000, |
| 790 | expire_walk_interval_ms=10000, is_ip6=1) |
| 791 | |
| 792 | def tearDown(self): |
| 793 | self.logger.debug(self.vapi.ppcli("show ip4-reassembly details")) |
| 794 | self.logger.debug(self.vapi.ppcli("show ip6-reassembly details")) |
| 795 | super(TestFIFReassembly, self).tearDown() |
| 796 | |
| 797 | def verify_capture(self, capture, ip_class, dropped_packet_indexes=[]): |
| 798 | """Verify captured packet stream. |
| 799 | |
| 800 | :param list capture: Captured packet stream. |
| 801 | """ |
| 802 | info = None |
| 803 | seen = set() |
| 804 | for packet in capture: |
| 805 | try: |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 806 | self.logger.debug(ppp("Got packet:", packet)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 807 | ip = packet[ip_class] |
| 808 | udp = packet[UDP] |
| 809 | payload_info = self.payload_to_info(str(packet[Raw])) |
| 810 | packet_index = payload_info.index |
| 811 | self.assertTrue( |
| 812 | packet_index not in dropped_packet_indexes, |
| 813 | ppp("Packet received, but should be dropped:", packet)) |
| 814 | if packet_index in seen: |
| 815 | raise Exception(ppp("Duplicate packet received", packet)) |
| 816 | seen.add(packet_index) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 817 | self.assertEqual(payload_info.dst, self.dst_if.sw_if_index) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 818 | info = self._packet_infos[packet_index] |
| 819 | self.assertTrue(info is not None) |
| 820 | self.assertEqual(packet_index, info.index) |
| 821 | saved_packet = info.data |
| 822 | self.assertEqual(ip.src, saved_packet[ip_class].src) |
| 823 | self.assertEqual(ip.dst, saved_packet[ip_class].dst) |
| 824 | self.assertEqual(udp.payload, saved_packet[UDP].payload) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 825 | except Exception: |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 826 | self.logger.error(ppp("Unexpected or invalid packet:", packet)) |
| 827 | raise |
| 828 | for index in self._packet_infos: |
| 829 | self.assertTrue(index in seen or index in dropped_packet_indexes, |
| 830 | "Packet with packet_index %d not received" % index) |
| 831 | |
| 832 | def test_fif4(self): |
| 833 | """ Fragments in fragments (4o4) """ |
| 834 | |
| 835 | # TODO this should be ideally in setUpClass, but then we hit a bug |
| 836 | # with VppIpRoute incorrectly reporting it's present when it's not |
| 837 | # so we need to manually remove the vpp config, thus we cannot have |
| 838 | # it shared for multiple test cases |
| 839 | self.tun_ip4 = "1.1.1.2" |
| 840 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 841 | self.gre4 = VppGreInterface(self, self.src_if.local_ip4, self.tun_ip4) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 842 | self.gre4.add_vpp_config() |
| 843 | self.gre4.admin_up() |
| 844 | self.gre4.config_ip4() |
| 845 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 846 | self.vapi.ip_reassembly_enable_disable( |
| 847 | sw_if_index=self.gre4.sw_if_index, enable_ip4=True) |
| 848 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 849 | self.route4 = VppIpRoute(self, self.tun_ip4, 32, |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 850 | [VppRoutePath(self.src_if.remote_ip4, |
| 851 | self.src_if.sw_if_index)]) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 852 | self.route4.add_vpp_config() |
| 853 | |
| 854 | self.reset_packet_infos() |
| 855 | for i in range(test_packet_count): |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 856 | info = self.create_packet_info(self.src_if, self.dst_if) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 857 | payload = self.info_to_payload(info) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 858 | # Ethernet header here is only for size calculation, thus it |
| 859 | # doesn't matter how it's initialized. This is to ensure that |
| 860 | # reassembled packet is not > 9000 bytes, so that it's not dropped |
| 861 | p = (Ether() / |
| 862 | IP(id=i, src=self.src_if.remote_ip4, |
| 863 | dst=self.dst_if.remote_ip4) / |
| 864 | UDP(sport=1234, dport=5678) / |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 865 | Raw(payload)) |
| 866 | size = self.packet_sizes[(i // 2) % len(self.packet_sizes)] |
| 867 | self.extend_packet(p, size, self.padding) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 868 | info.data = p[IP] # use only IP part, without ethernet header |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 869 | |
| 870 | fragments = [x for _, p in self._packet_infos.iteritems() |
| 871 | for x in fragment_rfc791(p.data, 400)] |
| 872 | |
| 873 | encapped_fragments = \ |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 874 | [Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac) / |
| 875 | IP(src=self.tun_ip4, dst=self.src_if.local_ip4) / |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 876 | GRE() / |
| 877 | p |
| 878 | for p in fragments] |
| 879 | |
| 880 | fragmented_encapped_fragments = \ |
| 881 | [x for p in encapped_fragments |
| 882 | for x in fragment_rfc791(p, 200)] |
| 883 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 884 | self.src_if.add_stream(fragmented_encapped_fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 885 | |
| 886 | self.pg_enable_capture(self.pg_interfaces) |
| 887 | self.pg_start() |
| 888 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 889 | self.src_if.assert_nothing_captured() |
| 890 | packets = self.dst_if.get_capture(len(self._packet_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 891 | self.verify_capture(packets, IP) |
| 892 | |
| 893 | # TODO remove gre vpp config by hand until VppIpRoute gets fixed |
| 894 | # so that it's query_vpp_config() works as it should |
| 895 | self.gre4.remove_vpp_config() |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 896 | self.logger.debug(self.vapi.ppcli("show interface")) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 897 | |
| 898 | def test_fif6(self): |
| 899 | """ Fragments in fragments (6o6) """ |
| 900 | # TODO this should be ideally in setUpClass, but then we hit a bug |
| 901 | # with VppIpRoute incorrectly reporting it's present when it's not |
| 902 | # so we need to manually remove the vpp config, thus we cannot have |
| 903 | # it shared for multiple test cases |
| 904 | self.tun_ip6 = "1002::1" |
| 905 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 906 | self.gre6 = VppGre6Interface(self, self.src_if.local_ip6, self.tun_ip6) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 907 | self.gre6.add_vpp_config() |
| 908 | self.gre6.admin_up() |
| 909 | self.gre6.config_ip6() |
| 910 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 911 | self.vapi.ip_reassembly_enable_disable( |
| 912 | sw_if_index=self.gre6.sw_if_index, enable_ip6=True) |
| 913 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 914 | self.route6 = VppIpRoute(self, self.tun_ip6, 128, |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 915 | [VppRoutePath(self.src_if.remote_ip6, |
| 916 | self.src_if.sw_if_index, |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 917 | proto=DpoProto.DPO_PROTO_IP6)], |
| 918 | is_ip6=1) |
| 919 | self.route6.add_vpp_config() |
| 920 | |
| 921 | self.reset_packet_infos() |
| 922 | for i in range(test_packet_count): |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 923 | info = self.create_packet_info(self.src_if, self.dst_if) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 924 | payload = self.info_to_payload(info) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 925 | # Ethernet header here is only for size calculation, thus it |
| 926 | # doesn't matter how it's initialized. This is to ensure that |
| 927 | # reassembled packet is not > 9000 bytes, so that it's not dropped |
| 928 | p = (Ether() / |
| 929 | IPv6(src=self.src_if.remote_ip6, dst=self.dst_if.remote_ip6) / |
| 930 | UDP(sport=1234, dport=5678) / |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 931 | Raw(payload)) |
| 932 | size = self.packet_sizes[(i // 2) % len(self.packet_sizes)] |
| 933 | self.extend_packet(p, size, self.padding) |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 934 | info.data = p[IPv6] # use only IPv6 part, without ethernet header |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 935 | |
| 936 | fragments = [x for _, i in self._packet_infos.iteritems() |
| 937 | for x in fragment_rfc8200( |
| 938 | i.data, i.index, 400)] |
| 939 | |
| 940 | encapped_fragments = \ |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 941 | [Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac) / |
| 942 | IPv6(src=self.tun_ip6, dst=self.src_if.local_ip6) / |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 943 | GRE() / |
| 944 | p |
| 945 | for p in fragments] |
| 946 | |
| 947 | fragmented_encapped_fragments = \ |
| 948 | [x for p in encapped_fragments for x in ( |
| 949 | fragment_rfc8200( |
| 950 | p, |
| 951 | 2 * len(self._packet_infos) + p[IPv6ExtHdrFragment].id, |
| 952 | 200) |
| 953 | if IPv6ExtHdrFragment in p else [p] |
| 954 | ) |
| 955 | ] |
| 956 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 957 | self.src_if.add_stream(fragmented_encapped_fragments) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 958 | |
| 959 | self.pg_enable_capture(self.pg_interfaces) |
| 960 | self.pg_start() |
| 961 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 962 | self.src_if.assert_nothing_captured() |
| 963 | packets = self.dst_if.get_capture(len(self._packet_infos)) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 964 | self.verify_capture(packets, IPv6) |
| 965 | |
| 966 | # TODO remove gre vpp config by hand until VppIpRoute gets fixed |
| 967 | # so that it's query_vpp_config() works as it should |
Klement Sekera | 3ecc221 | 2018-03-27 10:34:43 +0200 | [diff] [blame] | 968 | self.gre6.remove_vpp_config() |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 969 | |
| 970 | |
| 971 | if __name__ == '__main__': |
| 972 | unittest.main(testRunner=VppTestRunner) |