blob: 97cebff8dceebb879af06edf47acc3d2d22a8c25 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Jan Gelety057bb8c2016-12-20 17:32:45 +01002"""IP6 VRF Multi-instance Test Case HLD:
3
4**NOTES:**
5 - higher number of pg-ip6 interfaces causes problems => only 15 pg-ip6 \
Dave Wallaced1706812021-08-12 18:36:02 -04006 interfaces in 5 VRFs are tested
Jan Gelety057bb8c2016-12-20 17:32:45 +01007 - jumbo packets in configuration with 15 pg-ip6 interfaces leads to \
Dave Wallaced1706812021-08-12 18:36:02 -04008 problems too
Jan Gelety057bb8c2016-12-20 17:32:45 +01009
10**config 1**
11 - add 15 pg-ip6 interfaces
12 - configure 5 hosts per pg-ip6 interface
13 - configure 4 VRFs
14 - add 3 pg-ip6 interfaces per VRF
15
16**test 1**
17 - send IP6 packets between all pg-ip6 interfaces in all VRF groups
18
19**verify 1**
Neale Ranns097fa662018-05-01 05:17:55 -070020 - check VRF data by parsing output of ip_route_dump API command
Dave Wallaced1706812021-08-12 18:36:02 -040021 - all packets received correctly in case of pg-ip6 interfaces in the
22 same VRF
Jan Gelety057bb8c2016-12-20 17:32:45 +010023 - no packet received in case of pg-ip6 interfaces not in VRF
Jan Geletyd16ba622018-06-21 16:57:47 +020024 - no packet received in case of pg-ip6 interfaces in different VRFs
Jan Gelety057bb8c2016-12-20 17:32:45 +010025
26**config 2**
Jan Geletyb5b2ef52017-02-23 15:01:29 +010027 - reset 2 VRFs
Jan Gelety057bb8c2016-12-20 17:32:45 +010028
29**test 2**
30 - send IP6 packets between all pg-ip6 interfaces in all VRF groups
31
32**verify 2**
Neale Ranns097fa662018-05-01 05:17:55 -070033 - check VRF data by parsing output of ip_route_dump API command
Dave Wallaced1706812021-08-12 18:36:02 -040034 - all packets received correctly in case of pg-ip6 interfaces in the
35 same VRF
Jan Gelety057bb8c2016-12-20 17:32:45 +010036 - no packet received in case of pg-ip6 interfaces not in VRF
Jan Geletyd16ba622018-06-21 16:57:47 +020037 - no packet received in case of pg-ip6 interfaces in different VRFs
Jan Gelety057bb8c2016-12-20 17:32:45 +010038
39**config 3**
Jan Geletyb5b2ef52017-02-23 15:01:29 +010040 - add 1 of reset VRFs and 1 new VRF
Jan Gelety057bb8c2016-12-20 17:32:45 +010041
42**test 3**
43 - send IP6 packets between all pg-ip6 interfaces in all VRF groups
44
45**verify 3**
Neale Ranns097fa662018-05-01 05:17:55 -070046 - check VRF data by parsing output of ip_route_dump API command
Dave Wallaced1706812021-08-12 18:36:02 -040047 - all packets received correctly in case of pg-ip6 interfaces in the
48 same VRF
Jan Gelety057bb8c2016-12-20 17:32:45 +010049 - no packet received in case of pg-ip6 interfaces not in VRF
Jan Geletyd16ba622018-06-21 16:57:47 +020050 - no packet received in case of pg-ip6 interfaces in different VRFs
Jan Gelety057bb8c2016-12-20 17:32:45 +010051
52**config 4**
Jan Geletyb5b2ef52017-02-23 15:01:29 +010053 - reset all VRFs (i.e. no VRF except VRF=0 created)
Jan Gelety057bb8c2016-12-20 17:32:45 +010054
55**test 4**
56 - send IP6 packets between all pg-ip6 interfaces in all VRF groups
57
58**verify 4**
Neale Ranns097fa662018-05-01 05:17:55 -070059 - check VRF data by parsing output of ip_route_dump API command
Dave Wallaced1706812021-08-12 18:36:02 -040060 - all packets received correctly in case of pg-ip6 interfaces in the
61 same VRF
Jan Gelety057bb8c2016-12-20 17:32:45 +010062 - no packet received in case of pg-ip6 interfaces not in VRF
Jan Geletyd16ba622018-06-21 16:57:47 +020063 - no packet received in case of pg-ip6 interfaces in different VRFs
Jan Gelety057bb8c2016-12-20 17:32:45 +010064"""
65
66import unittest
67import random
Jan Geletyb5b2ef52017-02-23 15:01:29 +010068import socket
Jan Gelety057bb8c2016-12-20 17:32:45 +010069
70from scapy.packet import Raw
71from scapy.layers.l2 import Ether
Jan Geletyb5b2ef52017-02-23 15:01:29 +010072from scapy.layers.inet6 import UDP, IPv6, ICMPv6ND_NS, ICMPv6ND_RA, \
73 RouterAlert, IPv6ExtHdrHopByHop
74from scapy.utils6 import in6_ismaddr, in6_isllsnmaddr, in6_getAddrType
75from scapy.pton_ntop import inet_ntop
Jan Gelety057bb8c2016-12-20 17:32:45 +010076
77from framework import VppTestCase, VppTestRunner
78from util import ppp
Jan Gelety95c87b52017-02-27 10:46:14 +010079from vrf import VRFState
Jan Geletyb5b2ef52017-02-23 15:01:29 +010080
81
82def is_ipv6_misc_ext(p):
83 """ Is packet one of uninteresting IPv6 broadcasts (extended to filter out
84 ICMPv6 Neighbor Discovery - Neighbor Advertisement packets too)? """
85 if p.haslayer(ICMPv6ND_RA):
86 if in6_ismaddr(p[IPv6].dst):
87 return True
88 if p.haslayer(ICMPv6ND_NS):
89 if in6_isllsnmaddr(p[IPv6].dst):
90 return True
91 if p.haslayer(IPv6ExtHdrHopByHop):
92 for o in p[IPv6ExtHdrHopByHop].options:
93 if isinstance(o, RouterAlert):
94 return True
95 return False
96
Jan Gelety057bb8c2016-12-20 17:32:45 +010097
98class TestIP6VrfMultiInst(VppTestCase):
99 """ IP6 VRF Multi-instance Test Case """
100
101 @classmethod
102 def setUpClass(cls):
103 """
104 Perform standard class setup (defined by class method setUpClass in
105 class VppTestCase) before running the test case, set test case related
106 variables and configure VPP.
107 """
108 super(TestIP6VrfMultiInst, cls).setUpClass()
109
110 # Test variables
111 cls.hosts_per_pg = 5
112 cls.nr_of_vrfs = 5
113 cls.pg_ifs_per_vrf = 3
114
115 try:
116 # Create pg interfaces
117 cls.create_pg_interfaces(
118 range(cls.nr_of_vrfs * cls.pg_ifs_per_vrf))
119
120 # Packet flows mapping pg0 -> pg1, pg2 etc.
121 cls.flows = dict()
122 for i in range(len(cls.pg_interfaces)):
Ole Troan19757332019-10-18 14:54:30 +0200123 multiplicand = i // cls.pg_ifs_per_vrf
Jan Gelety057bb8c2016-12-20 17:32:45 +0100124 pg_list = [
125 cls.pg_interfaces[multiplicand * cls.pg_ifs_per_vrf + j]
126 for j in range(cls.pg_ifs_per_vrf)
127 if (multiplicand * cls.pg_ifs_per_vrf + j) != i]
128 cls.flows[cls.pg_interfaces[i]] = pg_list
129
130 # Packet sizes - jumbo packet (9018 bytes) skipped
131 cls.pg_if_packet_sizes = [64, 512, 1518]
132
133 # Set up all interfaces
134 for pg_if in cls.pg_interfaces:
135 pg_if.admin_up()
136 pg_if.generate_remote_hosts(cls.hosts_per_pg)
137
138 # Create list of VRFs
139 cls.vrf_list = list()
140
Jan Geletyb5b2ef52017-02-23 15:01:29 +0100141 # Create list of reset VRFs
142 cls.vrf_reset_list = list()
Jan Gelety057bb8c2016-12-20 17:32:45 +0100143
144 # Create list of pg_interfaces in VRFs
145 cls.pg_in_vrf = list()
146
Jan Geletyd16ba622018-06-21 16:57:47 +0200147 # Create list of pg_interfaces not in VRFs
Jan Gelety057bb8c2016-12-20 17:32:45 +0100148 cls.pg_not_in_vrf = [pg_if for pg_if in cls.pg_interfaces]
149
150 # Create mapping of pg_interfaces to VRF IDs
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200151 cls.pg_if_sets = dict()
Jan Gelety057bb8c2016-12-20 17:32:45 +0100152 for i in range(cls.nr_of_vrfs):
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200153 set_id = i + 1
Jan Gelety057bb8c2016-12-20 17:32:45 +0100154 pg_list = [
155 cls.pg_interfaces[i * cls.pg_ifs_per_vrf + j]
156 for j in range(cls.pg_ifs_per_vrf)]
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200157 cls.pg_if_sets[set_id] = pg_list
Jan Gelety057bb8c2016-12-20 17:32:45 +0100158
159 except Exception:
160 super(TestIP6VrfMultiInst, cls).tearDownClass()
161 raise
162
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700163 @classmethod
164 def tearDownClass(cls):
165 super(TestIP6VrfMultiInst, cls).tearDownClass()
166
Jan Gelety057bb8c2016-12-20 17:32:45 +0100167 def setUp(self):
168 """
169 Clear trace and packet infos before running each test.
170 """
171 super(TestIP6VrfMultiInst, self).setUp()
172 self.reset_packet_infos()
173
174 def tearDown(self):
175 """
176 Show various debug prints after each test.
177 """
178 super(TestIP6VrfMultiInst, self).tearDown()
Paul Vinciguerra90cf21b2019-03-13 09:23:05 -0700179
180 def show_commands_at_teardown(self):
181 self.logger.info(self.vapi.ppcli("show ip6 fib"))
182 self.logger.info(self.vapi.ppcli("show ip6 neighbors"))
Jan Gelety057bb8c2016-12-20 17:32:45 +0100183
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200184 def _assign_interfaces(self, vrf_id, if_set_id):
185 for i in range(self.pg_ifs_per_vrf):
186 pg_if = self.pg_if_sets[if_set_id][i]
187 pg_if.set_table_ip6(vrf_id)
188 self.logger.info("pg-interface %s added to IPv6 VRF ID %d"
189 % (pg_if.name, vrf_id))
190 if pg_if not in self.pg_in_vrf:
191 self.pg_in_vrf.append(pg_if)
192 if pg_if in self.pg_not_in_vrf:
193 self.pg_not_in_vrf.remove(pg_if)
194 pg_if.config_ip6()
195 pg_if.disable_ipv6_ra()
196 pg_if.configure_ipv6_neighbors()
197
Jan Gelety057bb8c2016-12-20 17:32:45 +0100198 def create_vrf_and_assign_interfaces(self, count, start=1):
199 """
Jan Geletyd16ba622018-06-21 16:57:47 +0200200 Create required number of FIB tables / VRFs, put 3 pg-ip6 interfaces
Jan Gelety057bb8c2016-12-20 17:32:45 +0100201 to every FIB table / VRF.
202
203 :param int count: Number of FIB tables / VRFs to be created.
204 :param int start: Starting number of the FIB table / VRF ID. \
205 (Default value = 1)
206 """
207 for i in range(count):
208 vrf_id = i + start
Neale Ranns9db6ada2019-11-08 12:42:31 +0000209 self.vapi.ip_table_add_del(is_add=1,
210 table={'table_id': vrf_id, 'is_ip6': 1})
Jan Gelety057bb8c2016-12-20 17:32:45 +0100211 self.logger.info("IPv6 VRF ID %d created" % vrf_id)
212 if vrf_id not in self.vrf_list:
213 self.vrf_list.append(vrf_id)
Jan Geletyb5b2ef52017-02-23 15:01:29 +0100214 if vrf_id in self.vrf_reset_list:
215 self.vrf_reset_list.remove(vrf_id)
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200216 self._assign_interfaces(vrf_id, vrf_id)
Jan Gelety057bb8c2016-12-20 17:32:45 +0100217 self.logger.debug(self.vapi.ppcli("show ip6 fib"))
218 self.logger.debug(self.vapi.ppcli("show ip6 neighbors"))
219
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200220 def create_vrf_by_id_and_assign_interfaces(self, set_id,
221 vrf_id=0xffffffff):
222 """
223 Create a FIB table / VRF by vrf_id, put 3 pg-ip6 interfaces
224 to FIB table / VRF.
225
226 :param int vrf_id: Required table ID / VRF ID. \
227 (Default value = 0xffffffff, ID will be selected automatically)
228 """
229 ret = self.vapi.ip_table_allocate(table={'table_id': vrf_id,
230 'is_ip6': 1})
231 vrf_id = ret.table.table_id
232 self.logger.info("IPv6 VRF ID %d created" % vrf_id)
233 if vrf_id not in self.vrf_list:
234 self.vrf_list.append(vrf_id)
235 if vrf_id in self.vrf_reset_list:
236 self.vrf_reset_list.remove(vrf_id)
237 self._assign_interfaces(vrf_id, set_id)
238 self.logger.debug(self.vapi.ppcli("show ip6 fib"))
239 self.logger.debug(self.vapi.ppcli("show ip6 neighbors"))
240
241 return vrf_id
242
243 def reset_vrf_and_remove_from_vrf_list(self, vrf_id, if_set_id=None):
Jan Gelety057bb8c2016-12-20 17:32:45 +0100244 """
Jan Gelety95c87b52017-02-27 10:46:14 +0100245 Reset required FIB table / VRF and remove it from VRF list.
Jan Gelety057bb8c2016-12-20 17:32:45 +0100246
Jan Geletyb5b2ef52017-02-23 15:01:29 +0100247 :param int vrf_id: The FIB table / VRF ID to be reset.
Jan Gelety057bb8c2016-12-20 17:32:45 +0100248 """
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200249 if if_set_id is None:
250 if_set_id = vrf_id
Neale Ranns9db6ada2019-11-08 12:42:31 +0000251 self.vapi.ip_table_flush(table={'table_id': vrf_id, 'is_ip6': 1})
Jan Gelety057bb8c2016-12-20 17:32:45 +0100252 if vrf_id in self.vrf_list:
253 self.vrf_list.remove(vrf_id)
Jan Geletyb5b2ef52017-02-23 15:01:29 +0100254 if vrf_id not in self.vrf_reset_list:
255 self.vrf_reset_list.append(vrf_id)
Jan Gelety057bb8c2016-12-20 17:32:45 +0100256 for j in range(self.pg_ifs_per_vrf):
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200257 pg_if = self.pg_if_sets[if_set_id][j]
Neale Ranns4008ac92017-02-13 23:20:04 -0800258 pg_if.unconfig_ip6()
Jan Gelety057bb8c2016-12-20 17:32:45 +0100259 if pg_if in self.pg_in_vrf:
260 self.pg_in_vrf.remove(pg_if)
261 if pg_if not in self.pg_not_in_vrf:
262 self.pg_not_in_vrf.append(pg_if)
Jan Gelety95c87b52017-02-27 10:46:14 +0100263 self.logger.info("IPv6 VRF ID %d reset finished" % vrf_id)
Jan Gelety057bb8c2016-12-20 17:32:45 +0100264 self.logger.debug(self.vapi.ppcli("show ip6 fib"))
265 self.logger.debug(self.vapi.ppcli("show ip6 neighbors"))
Neale Ranns9db6ada2019-11-08 12:42:31 +0000266 self.vapi.ip_table_add_del(is_add=0,
267 table={'table_id': vrf_id, 'is_ip6': 1})
Jan Gelety057bb8c2016-12-20 17:32:45 +0100268
269 def create_stream(self, src_if, packet_sizes):
270 """
271 Create input packet stream for defined interface using hosts list.
272
273 :param object src_if: Interface to create packet stream for.
274 :param list packet_sizes: List of required packet sizes.
275 :return: Stream of packets.
276 """
277 pkts = []
278 src_hosts = src_if.remote_hosts
279 for dst_if in self.flows[src_if]:
280 for dst_host in dst_if.remote_hosts:
281 src_host = random.choice(src_hosts)
282 pkt_info = self.create_packet_info(src_if, dst_if)
283 payload = self.info_to_payload(pkt_info)
284 p = (Ether(dst=src_if.local_mac, src=src_host.mac) /
285 IPv6(src=src_host.ip6, dst=dst_host.ip6) /
286 UDP(sport=1234, dport=1234) /
287 Raw(payload))
288 pkt_info.data = p.copy()
289 size = random.choice(packet_sizes)
290 self.extend_packet(p, size)
291 pkts.append(p)
292 self.logger.debug("Input stream created for port %s. Length: %u pkt(s)"
293 % (src_if.name, len(pkts)))
294 return pkts
295
Jan Geletyd16ba622018-06-21 16:57:47 +0200296 def create_stream_crosswise_vrf(self, src_if, vrf_id, packet_sizes):
297 """
298 Create input packet stream for negative test for leaking across
299 different VRFs for defined interface using hosts list.
300
301 :param object src_if: Interface to create packet stream for.
302 :param int vrf_id: The FIB table / VRF ID where src_if is assigned.
303 :param list packet_sizes: List of required packet sizes.
304 :return: Stream of packets.
305 """
306 pkts = []
307 src_hosts = src_if.remote_hosts
308 vrf_lst = list(self.vrf_list)
309 vrf_lst.remove(vrf_id)
310 for vrf in vrf_lst:
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200311 for dst_if in self.pg_if_sets[vrf]:
Jan Geletyd16ba622018-06-21 16:57:47 +0200312 for dst_host in dst_if.remote_hosts:
313 src_host = random.choice(src_hosts)
314 pkt_info = self.create_packet_info(src_if, dst_if)
315 payload = self.info_to_payload(pkt_info)
316 p = (Ether(dst=src_if.local_mac, src=src_host.mac) /
317 IPv6(src=src_host.ip6, dst=dst_host.ip6) /
318 UDP(sport=1234, dport=1234) /
319 Raw(payload))
320 pkt_info.data = p.copy()
321 size = random.choice(packet_sizes)
322 self.extend_packet(p, size)
323 pkts.append(p)
324 self.logger.debug("Input stream created for port %s. Length: %u pkt(s)"
325 % (src_if.name, len(pkts)))
326 return pkts
327
Jan Gelety057bb8c2016-12-20 17:32:45 +0100328 def verify_capture(self, pg_if, capture):
329 """
330 Verify captured input packet stream for defined interface.
331
332 :param object pg_if: Interface to verify captured packet stream for.
333 :param list capture: Captured packet stream.
334 """
335 last_info = dict()
336 for i in self.pg_interfaces:
337 last_info[i.sw_if_index] = None
338 dst_sw_if_index = pg_if.sw_if_index
339 for packet in capture:
340 try:
341 ip = packet[IPv6]
342 udp = packet[UDP]
Paul Vinciguerraeaea4212019-03-06 11:58:06 -0800343 payload_info = self.payload_to_info(packet[Raw])
Jan Gelety057bb8c2016-12-20 17:32:45 +0100344 packet_index = payload_info.index
345 self.assertEqual(payload_info.dst, dst_sw_if_index)
346 self.logger.debug("Got packet on port %s: src=%u (id=%u)" %
347 (pg_if.name, payload_info.src, packet_index))
348 next_info = self.get_next_packet_info_for_interface2(
349 payload_info.src, dst_sw_if_index,
350 last_info[payload_info.src])
351 last_info[payload_info.src] = next_info
352 self.assertIsNotNone(next_info)
353 self.assertEqual(packet_index, next_info.index)
354 saved_packet = next_info.data
355 # Check standard fields
356 self.assertEqual(ip.src, saved_packet[IPv6].src)
357 self.assertEqual(ip.dst, saved_packet[IPv6].dst)
358 self.assertEqual(udp.sport, saved_packet[UDP].sport)
359 self.assertEqual(udp.dport, saved_packet[UDP].dport)
360 except:
361 self.logger.error(ppp("Unexpected or invalid packet:", packet))
362 raise
363 for i in self.pg_interfaces:
364 remaining_packet = self.get_next_packet_info_for_interface2(
365 i, dst_sw_if_index, last_info[i.sw_if_index])
366 self.assertIsNone(
367 remaining_packet,
368 "Port %u: Packet expected from source %u didn't arrive" %
369 (dst_sw_if_index, i.sw_if_index))
370
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200371 def verify_vrf(self, vrf_id, if_set_id=None):
Jan Gelety057bb8c2016-12-20 17:32:45 +0100372 """
373 Check if the FIB table / VRF ID is configured.
374
375 :param int vrf_id: The FIB table / VRF ID to be verified.
376 :return: 1 if the FIB table / VRF ID is configured, otherwise return 0.
377 """
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200378 if if_set_id is None:
379 if_set_id = vrf_id
Neale Ranns097fa662018-05-01 05:17:55 -0700380 ip6_fib_dump = self.vapi.ip_route_dump(vrf_id, True)
381 vrf_exist = len(ip6_fib_dump)
Jan Gelety057bb8c2016-12-20 17:32:45 +0100382 vrf_count = 0
383 for ip6_fib_details in ip6_fib_dump:
Neale Ranns097fa662018-05-01 05:17:55 -0700384 addr = ip6_fib_details.route.prefix.network_address
385 found = False
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200386 for pg_if in self.pg_if_sets[if_set_id]:
Neale Ranns097fa662018-05-01 05:17:55 -0700387 if found:
388 break
389 for host in pg_if.remote_hosts:
390 if str(addr) == host.ip6:
391 vrf_count += 1
392 found = True
Jan Gelety95c87b52017-02-27 10:46:14 +0100393 break
Jan Geletyb5b2ef52017-02-23 15:01:29 +0100394 if not vrf_exist and vrf_count == 0:
Jan Gelety057bb8c2016-12-20 17:32:45 +0100395 self.logger.info("IPv6 VRF ID %d is not configured" % vrf_id)
Jan Gelety95c87b52017-02-27 10:46:14 +0100396 return VRFState.not_configured
Jan Geletyb5b2ef52017-02-23 15:01:29 +0100397 elif vrf_exist and vrf_count == 0:
398 self.logger.info("IPv6 VRF ID %d has been reset" % vrf_id)
Jan Gelety95c87b52017-02-27 10:46:14 +0100399 return VRFState.reset
Jan Gelety057bb8c2016-12-20 17:32:45 +0100400 else:
401 self.logger.info("IPv6 VRF ID %d is configured" % vrf_id)
Jan Gelety95c87b52017-02-27 10:46:14 +0100402 return VRFState.configured
Jan Gelety057bb8c2016-12-20 17:32:45 +0100403
404 def run_verify_test(self):
405 """
Jan Geletyd16ba622018-06-21 16:57:47 +0200406 Create packet streams for all configured pg interfaces, send all \
Jan Gelety057bb8c2016-12-20 17:32:45 +0100407 prepared packet streams and verify that:
Jan Geletyd16ba622018-06-21 16:57:47 +0200408 - all packets received correctly on all pg-ip6 interfaces assigned
409 to VRFs
410 - no packet received on all pg-ip6 interfaces not assigned to VRFs
Jan Gelety057bb8c2016-12-20 17:32:45 +0100411
Jan Geletyd16ba622018-06-21 16:57:47 +0200412 :raise RuntimeError: If no packet captured on pg-ip6 interface assigned
413 to VRF or if any packet is captured on pg-ip6 interface not
414 assigned to VRF.
Jan Gelety057bb8c2016-12-20 17:32:45 +0100415 """
416 # Test
417 # Create incoming packet streams for packet-generator interfaces
418 for pg_if in self.pg_interfaces:
419 pkts = self.create_stream(pg_if, self.pg_if_packet_sizes)
420 pg_if.add_stream(pkts)
421
422 # Enable packet capture and start packet sending
423 self.pg_enable_capture(self.pg_interfaces)
424 self.pg_start()
425
426 # Verify
427 # Verify outgoing packet streams per packet-generator interface
428 for pg_if in self.pg_interfaces:
429 if pg_if in self.pg_in_vrf:
430 capture = pg_if.get_capture(remark="interface is in VRF")
431 self.verify_capture(pg_if, capture)
432 elif pg_if in self.pg_not_in_vrf:
Jan Geletyb5b2ef52017-02-23 15:01:29 +0100433 pg_if.assert_nothing_captured(remark="interface is not in VRF",
434 filter_out_fn=is_ipv6_misc_ext)
Jan Gelety057bb8c2016-12-20 17:32:45 +0100435 self.logger.debug("No capture for interface %s" % pg_if.name)
436 else:
437 raise Exception("Unknown interface: %s" % pg_if.name)
438
Jan Geletyd16ba622018-06-21 16:57:47 +0200439 def run_crosswise_vrf_test(self):
440 """
441 Create packet streams for every pg-ip6 interface in VRF towards all
Dave Wallaced1706812021-08-12 18:36:02 -0400442 pg-ip6 interfaces in other VRFs, send all prepared packet streams and
Jan Geletyd16ba622018-06-21 16:57:47 +0200443 verify that:
Dave Wallaced1706812021-08-12 18:36:02 -0400444
445 - no packet received on all configured pg-ip6 interfaces
Jan Geletyd16ba622018-06-21 16:57:47 +0200446
447 :raise RuntimeError: If any packet is captured on any pg-ip6 interface.
448 """
449 # Test
450 # Create incoming packet streams for packet-generator interfaces
451 for vrf_id in self.vrf_list:
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200452 for pg_if in self.pg_if_sets[vrf_id]:
Jan Geletyd16ba622018-06-21 16:57:47 +0200453 pkts = self.create_stream_crosswise_vrf(
454 pg_if, vrf_id, self.pg_if_packet_sizes)
455 pg_if.add_stream(pkts)
456
457 # Enable packet capture and start packet sending
458 self.pg_enable_capture(self.pg_interfaces)
459 self.pg_start()
460
461 # Verify
462 # Verify outgoing packet streams per packet-generator interface
463 for pg_if in self.pg_interfaces:
464 pg_if.assert_nothing_captured(remark="interface is in other VRF",
465 filter_out_fn=is_ipv6_misc_ext)
466 self.logger.debug("No capture for interface %s" % pg_if.name)
467
Jan Gelety057bb8c2016-12-20 17:32:45 +0100468 def test_ip6_vrf_01(self):
469 """ IP6 VRF Multi-instance test 1 - create 4 VRFs
470 """
471 # Config 1
472 # Create 4 VRFs
473 self.create_vrf_and_assign_interfaces(4)
474
475 # Verify 1
476 for vrf_id in self.vrf_list:
Jan Gelety95c87b52017-02-27 10:46:14 +0100477 self.assert_equal(self.verify_vrf(vrf_id),
478 VRFState.configured, VRFState)
Jan Gelety057bb8c2016-12-20 17:32:45 +0100479
480 # Test 1
481 self.run_verify_test()
Jan Geletyd16ba622018-06-21 16:57:47 +0200482 self.run_crosswise_vrf_test()
Jan Gelety057bb8c2016-12-20 17:32:45 +0100483
Jan Gelety057bb8c2016-12-20 17:32:45 +0100484 def test_ip6_vrf_02(self):
485 """ IP6 VRF Multi-instance test 2 - reset 2 VRFs
486 """
487 # Config 2
488 # Delete 2 VRFs
Jan Gelety95c87b52017-02-27 10:46:14 +0100489 self.reset_vrf_and_remove_from_vrf_list(1)
490 self.reset_vrf_and_remove_from_vrf_list(2)
Jan Gelety057bb8c2016-12-20 17:32:45 +0100491
492 # Verify 2
Jan Geletyb5b2ef52017-02-23 15:01:29 +0100493 for vrf_id in self.vrf_reset_list:
Jan Gelety95c87b52017-02-27 10:46:14 +0100494 self.assert_equal(self.verify_vrf(vrf_id),
495 VRFState.reset, VRFState)
Jan Gelety057bb8c2016-12-20 17:32:45 +0100496 for vrf_id in self.vrf_list:
Jan Gelety95c87b52017-02-27 10:46:14 +0100497 self.assert_equal(self.verify_vrf(vrf_id),
498 VRFState.configured, VRFState)
Jan Gelety057bb8c2016-12-20 17:32:45 +0100499
500 # Test 2
501 self.run_verify_test()
Jan Geletyd16ba622018-06-21 16:57:47 +0200502 self.run_crosswise_vrf_test()
Jan Gelety057bb8c2016-12-20 17:32:45 +0100503
Jan Geletyb5b2ef52017-02-23 15:01:29 +0100504 # Reset routes learned from ICMPv6 Neighbor Discovery
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200505 # for vrf_id in self.vrf_reset_list:
506 # self.reset_vrf_and_remove_from_vrf_list(vrf_id)
Jan Geletyb5b2ef52017-02-23 15:01:29 +0100507
Jan Gelety057bb8c2016-12-20 17:32:45 +0100508 def test_ip6_vrf_03(self):
509 """ IP6 VRF Multi-instance 3 - add 2 VRFs
510 """
511 # Config 3
Jan Geletyb5b2ef52017-02-23 15:01:29 +0100512 # Add 1 of reset VRFs and 1 new VRF
513 self.create_vrf_and_assign_interfaces(1)
Jan Gelety057bb8c2016-12-20 17:32:45 +0100514 self.create_vrf_and_assign_interfaces(1, start=5)
515
516 # Verify 3
Jan Geletyb5b2ef52017-02-23 15:01:29 +0100517 for vrf_id in self.vrf_reset_list:
Jan Gelety95c87b52017-02-27 10:46:14 +0100518 self.assert_equal(self.verify_vrf(vrf_id),
519 VRFState.reset, VRFState)
Jan Gelety057bb8c2016-12-20 17:32:45 +0100520 for vrf_id in self.vrf_list:
Jan Gelety95c87b52017-02-27 10:46:14 +0100521 self.assert_equal(self.verify_vrf(vrf_id),
522 VRFState.configured, VRFState)
Jan Gelety057bb8c2016-12-20 17:32:45 +0100523
524 # Test 3
525 self.run_verify_test()
Jan Geletyd16ba622018-06-21 16:57:47 +0200526 self.run_crosswise_vrf_test()
Jan Gelety057bb8c2016-12-20 17:32:45 +0100527
Jan Geletyb5b2ef52017-02-23 15:01:29 +0100528 # Reset routes learned from ICMPv6 Neighbor Discovery
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200529 # for vrf_id in self.vrf_reset_list:
530 # self.reset_vrf_and_remove_from_vrf_list(vrf_id)
Jan Geletyb5b2ef52017-02-23 15:01:29 +0100531
Jan Gelety057bb8c2016-12-20 17:32:45 +0100532 def test_ip6_vrf_04(self):
533 """ IP6 VRF Multi-instance test 4 - reset 4 VRFs
534 """
535 # Config 4
Jan Gelety95c87b52017-02-27 10:46:14 +0100536 # Reset all VRFs (i.e. no VRF except VRF=0 configured)
Jan Gelety057bb8c2016-12-20 17:32:45 +0100537 for i in range(len(self.vrf_list)):
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200538 # This call removes the first item of vrf_list as a side effect
Jan Gelety95c87b52017-02-27 10:46:14 +0100539 self.reset_vrf_and_remove_from_vrf_list(self.vrf_list[0])
Jan Gelety057bb8c2016-12-20 17:32:45 +0100540
541 # Verify 4
Jan Geletyb5b2ef52017-02-23 15:01:29 +0100542 for vrf_id in self.vrf_reset_list:
Jan Gelety95c87b52017-02-27 10:46:14 +0100543 self.assert_equal(self.verify_vrf(vrf_id),
544 VRFState.reset, VRFState)
545 vrf_list_length = len(self.vrf_list)
546 self.assertEqual(
547 vrf_list_length, 0,
548 "List of configured VRFs is not empty: %s != 0" % vrf_list_length)
Jan Gelety057bb8c2016-12-20 17:32:45 +0100549
550 # Test 4
551 self.run_verify_test()
Jan Geletyd16ba622018-06-21 16:57:47 +0200552 self.run_crosswise_vrf_test()
Jan Gelety057bb8c2016-12-20 17:32:45 +0100553
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200554 @unittest.skip('VPP crashes after running this test. \
555 There seems to be an issue with the way fib locks are managed')
556 def test_ip6_vrf_05(self):
557 """ IP6 VRF Multi-instance test 5 - auto allocate vrf id
558 """
559 # Config 5
560 # Create several VRFs
561 # Set vrf_id manually first
562 self.create_vrf_by_id_and_assign_interfaces(1, 10)
563 # Set vrf_id automatically a few times
564 auto_vrf_id = [
565 self.create_vrf_by_id_and_assign_interfaces(i) for i in range(2, 5)
566 ]
567
568 # Verify 5
569 self.assert_equal(self.verify_vrf(10, 1), VRFState.configured,
570 VRFState)
571 for i, vrf in enumerate(auto_vrf_id):
572 self.assert_equal(self.verify_vrf(vrf, i+2),
573 VRFState.configured, VRFState)
574
575 # Test 5
576 self.run_verify_test()
577
578 # Config 5.1
579 # Reset VRFs
580 self.reset_vrf_and_remove_from_vrf_list(10, 1)
581 for i, vrf in enumerate(auto_vrf_id):
582 self.reset_vrf_and_remove_from_vrf_list(vrf, i+2)
583
584 # Verify 5.1
585 self.assert_equal(self.verify_vrf(10, 1), VRFState.reset, VRFState)
586 for i, vrf in enumerate(auto_vrf_id):
587 self.assert_equal(self.verify_vrf(vrf, i+2),
588 VRFState.reset, VRFState)
589
590 vrf_list_length = len(self.vrf_list)
591 self.assertEqual(
592 vrf_list_length, 0,
593 "List of configured VRFs is not empty: %s != 0" % vrf_list_length)
594
Nathan Skrzypczak275bd792021-09-17 17:29:14 +0200595 def test_ip6_vrf_06(self):
596 """ IP6 VRF Multi-instance test 6 - recreate 4 VRFs
597 """
598 # Reconfigure all the VRFs
599 self.create_vrf_and_assign_interfaces(4)
600 # Verify
601 for vrf_id in self.vrf_list:
602 self.assert_equal(self.verify_vrf(vrf_id),
603 VRFState.configured, VRFState)
604 # Test
605 self.run_verify_test()
606 self.run_crosswise_vrf_test()
607 # Cleanup
608 for i in range(len(self.vrf_list)):
609 self.reset_vrf_and_remove_from_vrf_list(self.vrf_list[0])
610 # Verify
611 for vrf_id in self.vrf_reset_list:
612 self.assert_equal(self.verify_vrf(vrf_id),
613 VRFState.reset, VRFState)
614 vrf_list_length = len(self.vrf_list)
615 self.assertEqual(
616 vrf_list_length, 0,
617 "List of configured VRFs is not empty: %s != 0" % vrf_list_length)
618 # Test
619 self.run_verify_test()
620 self.run_crosswise_vrf_test()
621
Jan Gelety057bb8c2016-12-20 17:32:45 +0100622
623if __name__ == '__main__':
624 unittest.main(testRunner=VppTestRunner)