blob: acef6c4ff09c5b6f886e9ab36d1a006706cf91f1 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Jane546d3b2016-12-08 13:10:03 +01002"""IP4 VRF Multi-instance Test Case HLD:
3
4**NOTES:**
5 - higher number of pg-ip4 interfaces causes problems => only 15 pg-ip4 \
Dave Wallaced1706812021-08-12 18:36:02 -04006 interfaces in 5 VRFs are tested
Jane546d3b2016-12-08 13:10:03 +01007 - jumbo packets in configuration with 15 pg-ip4 interfaces leads to \
Dave Wallaced1706812021-08-12 18:36:02 -04008 problems too
Jane546d3b2016-12-08 13:10:03 +01009
10**config 1**
11 - add 15 pg-ip4 interfaces
12 - configure 5 hosts per pg-ip4 interface
13 - configure 4 VRFs
14 - add 3 pg-ip4 interfaces per VRF
15
16**test 1**
17 - send IP4 packets between all pg-ip4 interfaces in all VRF groups
18
19**verify 1**
20 - check VRF data by parsing output of ip_fib_dump API command
Dave Wallaced1706812021-08-12 18:36:02 -040021 - all packets received correctly in case of pg-ip4 interfaces in the
22 same VRF
Jane546d3b2016-12-08 13:10:03 +010023 - no packet received in case of pg-ip4 interfaces not in VRF
Jan Geletyd16ba622018-06-21 16:57:47 +020024 - no packet received in case of pg-ip4 interfaces in different VRFs
Jane546d3b2016-12-08 13:10:03 +010025
26**config 2**
Jan Gelety95c87b52017-02-27 10:46:14 +010027 - reset 2 VRFs
Jane546d3b2016-12-08 13:10:03 +010028
29**test 2**
30 - send IP4 packets between all pg-ip4 interfaces in all VRF groups
31
32**verify 2**
Dave Wallaced1706812021-08-12 18:36:02 -040033 - all packets received correctly in case of pg-ip4 interfaces in the
34 same VRF
Jane546d3b2016-12-08 13:10:03 +010035 - no packet received in case of pg-ip4 interfaces not in VRF
Jan Geletyd16ba622018-06-21 16:57:47 +020036 - no packet received in case of pg-ip4 interfaces in different VRFs
Jane546d3b2016-12-08 13:10:03 +010037
38**config 3**
Jan Gelety95c87b52017-02-27 10:46:14 +010039 - add 1 of reset VRFs and 1 new VRF
Jane546d3b2016-12-08 13:10:03 +010040
41**test 3**
42 - send IP4 packets between all pg-ip4 interfaces in all VRF groups
43
44**verify 3**
45 - check VRF data by parsing output of ip_fib_dump API command
Dave Wallaced1706812021-08-12 18:36:02 -040046 - all packets received correctly in case of pg-ip4 interfaces in the
47 same VRF
Jane546d3b2016-12-08 13:10:03 +010048 - no packet received in case of pg-ip4 interfaces not in VRF
Jan Geletyd16ba622018-06-21 16:57:47 +020049 - no packet received in case of pg-ip4 interfaces in different VRFs
Jane546d3b2016-12-08 13:10:03 +010050
51**config 4**
Jan Gelety95c87b52017-02-27 10:46:14 +010052 - reset all created VRFs
Jane546d3b2016-12-08 13:10:03 +010053
54**test 4**
55 - send IP4 packets between all pg-ip4 interfaces in all VRF groups
56
57**verify 4**
58 - check VRF data by parsing output of ip_fib_dump API command
Dave Wallaced1706812021-08-12 18:36:02 -040059 - all packets received correctly in case of pg-ip4 interfaces in the
60 same VRF
Jane546d3b2016-12-08 13:10:03 +010061 - no packet received in case of pg-ip4 interfaces not in VRF
Jan Geletyd16ba622018-06-21 16:57:47 +020062 - no packet received in case of pg-ip4 interfaces in different VRFs
Jane546d3b2016-12-08 13:10:03 +010063"""
64
65import unittest
66import random
Jan Gelety95c87b52017-02-27 10:46:14 +010067import socket
Jane546d3b2016-12-08 13:10:03 +010068
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -070069import scapy.compat
Jane546d3b2016-12-08 13:10:03 +010070from scapy.packet import Raw
snaramre5d4b8912019-12-13 23:39:35 +000071from scapy.layers.l2 import Ether, ARP
72from scapy.layers.inet import IP, UDP
Jane546d3b2016-12-08 13:10:03 +010073
74from framework import VppTestCase, VppTestRunner
75from util import ppp
Jan Gelety95c87b52017-02-27 10:46:14 +010076from vrf import VRFState
Jane546d3b2016-12-08 13:10:03 +010077
78
79def is_ipv4_misc(p):
80 """ Is packet one of uninteresting IPv4 broadcasts? """
81 if p.haslayer(ARP):
82 return True
83 return False
84
85
86class TestIp4VrfMultiInst(VppTestCase):
87 """ IP4 VRF Multi-instance Test Case """
88
89 @classmethod
90 def setUpClass(cls):
91 """
92 Perform standard class setup (defined by class method setUpClass in
93 class VppTestCase) before running the test case, set test case related
94 variables and configure VPP.
95 """
96 super(TestIp4VrfMultiInst, cls).setUpClass()
97
98 # Test variables
99 cls.hosts_per_pg = 5
100 cls.nr_of_vrfs = 5
101 cls.pg_ifs_per_vrf = 3
102
103 try:
104 # Create pg interfaces
Klement Sekerada505f62017-01-04 12:58:53 +0100105 cls.create_pg_interfaces(
106 range(cls.nr_of_vrfs * cls.pg_ifs_per_vrf))
Jane546d3b2016-12-08 13:10:03 +0100107
108 # Packet flows mapping pg0 -> pg1, pg2 etc.
109 cls.flows = dict()
110 for i in range(len(cls.pg_interfaces)):
Ole Troan19757332019-10-18 14:54:30 +0200111 multiplicand = i // cls.pg_ifs_per_vrf
Jane546d3b2016-12-08 13:10:03 +0100112 pg_list = [
113 cls.pg_interfaces[multiplicand * cls.pg_ifs_per_vrf + j]
114 for j in range(cls.pg_ifs_per_vrf)
115 if (multiplicand * cls.pg_ifs_per_vrf + j) != i]
116 cls.flows[cls.pg_interfaces[i]] = pg_list
117
118 # Packet sizes - jumbo packet (9018 bytes) skipped
119 cls.pg_if_packet_sizes = [64, 512, 1518]
120
121 # Set up all interfaces
122 for pg_if in cls.pg_interfaces:
123 pg_if.admin_up()
124 pg_if.generate_remote_hosts(cls.hosts_per_pg)
125
126 # Create list of VRFs
127 cls.vrf_list = list()
128
Jan Gelety95c87b52017-02-27 10:46:14 +0100129 # Create list of reset VRFs
130 cls.vrf_reset_list = list()
Jane546d3b2016-12-08 13:10:03 +0100131
132 # Create list of pg_interfaces in VRFs
133 cls.pg_in_vrf = list()
134
Jan Geletyd16ba622018-06-21 16:57:47 +0200135 # Create list of pg_interfaces not in VRFs
Jane546d3b2016-12-08 13:10:03 +0100136 cls.pg_not_in_vrf = [pg_if for pg_if in cls.pg_interfaces]
137
138 # Create mapping of pg_interfaces to VRF IDs
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200139 cls.pg_if_sets = dict()
Jane546d3b2016-12-08 13:10:03 +0100140 for i in range(cls.nr_of_vrfs):
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200141 set_id = i + 1
Jane546d3b2016-12-08 13:10:03 +0100142 pg_list = [
143 cls.pg_interfaces[i * cls.pg_ifs_per_vrf + j]
144 for j in range(cls.pg_ifs_per_vrf)]
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200145 cls.pg_if_sets[set_id] = pg_list
Jane546d3b2016-12-08 13:10:03 +0100146
147 except Exception:
148 super(TestIp4VrfMultiInst, cls).tearDownClass()
149 raise
150
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700151 @classmethod
152 def tearDownClass(cls):
153 super(TestIp4VrfMultiInst, cls).tearDownClass()
154
Jane546d3b2016-12-08 13:10:03 +0100155 def setUp(self):
Jan Gelety3900fe52017-01-26 15:46:19 +0100156 """
Jane546d3b2016-12-08 13:10:03 +0100157 Clear trace and packet infos before running each test.
158 """
159 super(TestIp4VrfMultiInst, self).setUp()
160 self.reset_packet_infos()
161
162 def tearDown(self):
163 """
164 Show various debug prints after each test.
165 """
166 super(TestIp4VrfMultiInst, self).tearDown()
Paul Vinciguerra90cf21b2019-03-13 09:23:05 -0700167
168 def show_commands_at_teardown(self):
169 self.logger.info(self.vapi.ppcli("show ip fib"))
Neale Rannscbe25aa2019-09-30 10:53:31 +0000170 self.logger.info(self.vapi.ppcli("show ip4 neighbors"))
Jane546d3b2016-12-08 13:10:03 +0100171
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200172 def _assign_interfaces(self, vrf_id, if_set_id):
173 for i in range(self.pg_ifs_per_vrf):
174 pg_if = self.pg_if_sets[if_set_id][i]
175 pg_if.set_table_ip4(vrf_id)
176 self.logger.info("pg-interface %s added to IPv4 VRF ID %d"
177 % (pg_if.name, vrf_id))
178 if pg_if not in self.pg_in_vrf:
179 self.pg_in_vrf.append(pg_if)
180 if pg_if in self.pg_not_in_vrf:
181 self.pg_not_in_vrf.remove(pg_if)
182 pg_if.config_ip4()
183 pg_if.configure_ipv4_neighbors()
184
Jane546d3b2016-12-08 13:10:03 +0100185 def create_vrf_and_assign_interfaces(self, count, start=1):
Jan Gelety3900fe52017-01-26 15:46:19 +0100186 """
Jan Geletyd16ba622018-06-21 16:57:47 +0200187 Create required number of FIB tables / VRFs, put 3 pg-ip4 interfaces
Jane546d3b2016-12-08 13:10:03 +0100188 to every FIB table / VRF.
189
190 :param int count: Number of FIB tables / VRFs to be created.
191 :param int start: Starting number of the FIB table / VRF ID. \
192 (Default value = 1)
193 """
194
195 for i in range(count):
196 vrf_id = i + start
Neale Ranns9db6ada2019-11-08 12:42:31 +0000197 self.vapi.ip_table_add_del(is_add=1, table={'table_id': vrf_id})
Jane546d3b2016-12-08 13:10:03 +0100198 self.logger.info("IPv4 VRF ID %d created" % vrf_id)
199 if vrf_id not in self.vrf_list:
200 self.vrf_list.append(vrf_id)
Jan Gelety95c87b52017-02-27 10:46:14 +0100201 if vrf_id in self.vrf_reset_list:
202 self.vrf_reset_list.remove(vrf_id)
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200203 self._assign_interfaces(vrf_id, vrf_id)
Jane546d3b2016-12-08 13:10:03 +0100204 self.logger.debug(self.vapi.ppcli("show ip fib"))
Neale Rannscbe25aa2019-09-30 10:53:31 +0000205 self.logger.debug(self.vapi.ppcli("show ip4 neighbors"))
Jane546d3b2016-12-08 13:10:03 +0100206
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200207 def create_vrf_by_id_and_assign_interfaces(self, set_id,
208 vrf_id=0xffffffff):
209 """
210 Create a FIB table / VRF by vrf_id, put 3 pg-ip4 interfaces
211 to FIB table / VRF.
212
213 :param int vrf_id: Required table ID / VRF ID. \
214 (Default value = 0xffffffff, ID will be selected automatically)
215 """
216 ret = self.vapi.ip_table_allocate(table={'table_id': vrf_id})
217 vrf_id = ret.table.table_id
218 self.logger.info("IPv4 VRF ID %d created" % vrf_id)
219 if vrf_id not in self.vrf_list:
220 self.vrf_list.append(vrf_id)
221 if vrf_id in self.vrf_reset_list:
222 self.vrf_reset_list.remove(vrf_id)
223 self._assign_interfaces(vrf_id, set_id)
224 self.logger.debug(self.vapi.ppcli("show ip fib"))
225 self.logger.debug(self.vapi.ppcli("show ip4 neighbors"))
226
227 return vrf_id
228
229 def reset_vrf_and_remove_from_vrf_list(self, vrf_id, if_set_id=None):
Jan Gelety3900fe52017-01-26 15:46:19 +0100230 """
Jan Gelety95c87b52017-02-27 10:46:14 +0100231 Reset required FIB table / VRF and remove it from VRF list.
Jane546d3b2016-12-08 13:10:03 +0100232
Jan Gelety95c87b52017-02-27 10:46:14 +0100233 :param int vrf_id: The FIB table / VRF ID to be reset.
Jane546d3b2016-12-08 13:10:03 +0100234 """
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200235 if if_set_id is None:
236 if_set_id = vrf_id
Neale Ranns9db6ada2019-11-08 12:42:31 +0000237 self.vapi.ip_table_flush(table={'table_id': vrf_id})
Jane546d3b2016-12-08 13:10:03 +0100238 if vrf_id in self.vrf_list:
239 self.vrf_list.remove(vrf_id)
Jan Gelety95c87b52017-02-27 10:46:14 +0100240 if vrf_id not in self.vrf_reset_list:
241 self.vrf_reset_list.append(vrf_id)
Jane546d3b2016-12-08 13:10:03 +0100242 for j in range(self.pg_ifs_per_vrf):
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200243 pg_if = self.pg_if_sets[if_set_id][j]
Neale Ranns4008ac92017-02-13 23:20:04 -0800244 pg_if.unconfig_ip4()
Jane546d3b2016-12-08 13:10:03 +0100245 if pg_if in self.pg_in_vrf:
246 self.pg_in_vrf.remove(pg_if)
247 if pg_if not in self.pg_not_in_vrf:
248 self.pg_not_in_vrf.append(pg_if)
Jan Gelety95c87b52017-02-27 10:46:14 +0100249 self.logger.info("IPv4 VRF ID %d reset finished" % vrf_id)
Jane546d3b2016-12-08 13:10:03 +0100250 self.logger.debug(self.vapi.ppcli("show ip fib"))
Neale Rannscbe25aa2019-09-30 10:53:31 +0000251 self.logger.debug(self.vapi.ppcli("show ip neighbors"))
Neale Ranns9db6ada2019-11-08 12:42:31 +0000252 self.vapi.ip_table_add_del(is_add=0, table={'table_id': vrf_id})
Jane546d3b2016-12-08 13:10:03 +0100253
254 def create_stream(self, src_if, packet_sizes):
255 """
256 Create input packet stream for defined interface using hosts list.
257
258 :param object src_if: Interface to create packet stream for.
259 :param list packet_sizes: List of required packet sizes.
260 :return: Stream of packets.
261 """
262 pkts = []
263 src_hosts = src_if.remote_hosts
264 for dst_if in self.flows[src_if]:
265 for dst_host in dst_if.remote_hosts:
266 src_host = random.choice(src_hosts)
267 pkt_info = self.create_packet_info(src_if, dst_if)
268 payload = self.info_to_payload(pkt_info)
269 p = (Ether(dst=src_if.local_mac, src=src_host.mac) /
270 IP(src=src_host.ip4, dst=dst_host.ip4) /
271 UDP(sport=1234, dport=1234) /
272 Raw(payload))
273 pkt_info.data = p.copy()
274 size = random.choice(packet_sizes)
275 self.extend_packet(p, size)
276 pkts.append(p)
277 self.logger.debug("Input stream created for port %s. Length: %u pkt(s)"
278 % (src_if.name, len(pkts)))
279 return pkts
280
Jan Geletyd16ba622018-06-21 16:57:47 +0200281 def create_stream_crosswise_vrf(self, src_if, vrf_id, packet_sizes):
282 """
283 Create input packet stream for negative test for leaking across
284 different VRFs for defined interface using hosts list.
285
286 :param object src_if: Interface to create packet stream for.
287 :param int vrf_id: The FIB table / VRF ID where src_if is assigned.
288 :param list packet_sizes: List of required packet sizes.
289 :return: Stream of packets.
290 """
291 pkts = []
292 src_hosts = src_if.remote_hosts
293 vrf_lst = list(self.vrf_list)
294 vrf_lst.remove(vrf_id)
295 for vrf in vrf_lst:
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200296 for dst_if in self.pg_if_sets[vrf]:
Jan Geletyd16ba622018-06-21 16:57:47 +0200297 for dst_host in dst_if.remote_hosts:
298 src_host = random.choice(src_hosts)
299 pkt_info = self.create_packet_info(src_if, dst_if)
300 payload = self.info_to_payload(pkt_info)
301 p = (Ether(dst=src_if.local_mac, src=src_host.mac) /
302 IP(src=src_host.ip4, dst=dst_host.ip4) /
303 UDP(sport=1234, dport=1234) /
304 Raw(payload))
305 pkt_info.data = p.copy()
306 size = random.choice(packet_sizes)
307 self.extend_packet(p, size)
308 pkts.append(p)
309 self.logger.debug("Input stream created for port %s. Length: %u pkt(s)"
310 % (src_if.name, len(pkts)))
311 return pkts
312
Jane546d3b2016-12-08 13:10:03 +0100313 def verify_capture(self, pg_if, capture):
314 """
315 Verify captured input packet stream for defined interface.
316
317 :param object pg_if: Interface to verify captured packet stream for.
318 :param list capture: Captured packet stream.
319 """
320 last_info = dict()
321 for i in self.pg_interfaces:
322 last_info[i.sw_if_index] = None
323 dst_sw_if_index = pg_if.sw_if_index
324 for packet in capture:
325 try:
326 ip = packet[IP]
327 udp = packet[UDP]
Paul Vinciguerraeaea4212019-03-06 11:58:06 -0800328 payload_info = self.payload_to_info(packet[Raw])
Jane546d3b2016-12-08 13:10:03 +0100329 packet_index = payload_info.index
330 self.assertEqual(payload_info.dst, dst_sw_if_index)
331 self.logger.debug("Got packet on port %s: src=%u (id=%u)" %
332 (pg_if.name, payload_info.src, packet_index))
333 next_info = self.get_next_packet_info_for_interface2(
334 payload_info.src, dst_sw_if_index,
335 last_info[payload_info.src])
336 last_info[payload_info.src] = next_info
337 self.assertIsNotNone(next_info)
338 self.assertEqual(packet_index, next_info.index)
339 saved_packet = next_info.data
340 # Check standard fields
341 self.assertEqual(ip.src, saved_packet[IP].src)
342 self.assertEqual(ip.dst, saved_packet[IP].dst)
343 self.assertEqual(udp.sport, saved_packet[UDP].sport)
344 self.assertEqual(udp.dport, saved_packet[UDP].dport)
345 except:
346 self.logger.error(ppp("Unexpected or invalid packet:", packet))
347 raise
348 for i in self.pg_interfaces:
349 remaining_packet = self.get_next_packet_info_for_interface2(
350 i, dst_sw_if_index, last_info[i.sw_if_index])
351 self.assertIsNone(
352 remaining_packet,
353 "Port %u: Packet expected from source %u didn't arrive" %
354 (dst_sw_if_index, i.sw_if_index))
355
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200356 def verify_vrf(self, vrf_id, if_set_id=None):
Jane546d3b2016-12-08 13:10:03 +0100357 """
358 Check if the FIB table / VRF ID is configured.
359
360 :param int vrf_id: The FIB table / VRF ID to be verified.
361 :return: 1 if the FIB table / VRF ID is configured, otherwise return 0.
362 """
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200363 if if_set_id is None:
364 if_set_id = vrf_id
Neale Ranns097fa662018-05-01 05:17:55 -0700365 ip_fib_dump = self.vapi.ip_route_dump(vrf_id)
366 vrf_exist = len(ip_fib_dump)
Jane546d3b2016-12-08 13:10:03 +0100367 vrf_count = 0
368 for ip_fib_details in ip_fib_dump:
Neale Ranns097fa662018-05-01 05:17:55 -0700369 addr = ip_fib_details.route.prefix.network_address
370 found = False
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200371 for pg_if in self.pg_if_sets[if_set_id]:
Neale Ranns097fa662018-05-01 05:17:55 -0700372 if found:
373 break
374 for host in pg_if.remote_hosts:
375 if str(addr) == host.ip4:
376 vrf_count += 1
377 found = True
Jan Gelety95c87b52017-02-27 10:46:14 +0100378 break
Jan Gelety95c87b52017-02-27 10:46:14 +0100379 if not vrf_exist and vrf_count == 0:
Jane546d3b2016-12-08 13:10:03 +0100380 self.logger.info("IPv4 VRF ID %d is not configured" % vrf_id)
Jan Gelety95c87b52017-02-27 10:46:14 +0100381 return VRFState.not_configured
382 elif vrf_exist and vrf_count == 0:
383 self.logger.info("IPv4 VRF ID %d has been reset" % vrf_id)
384 return VRFState.reset
Jane546d3b2016-12-08 13:10:03 +0100385 else:
386 self.logger.info("IPv4 VRF ID %d is configured" % vrf_id)
Jan Gelety95c87b52017-02-27 10:46:14 +0100387 return VRFState.configured
Jane546d3b2016-12-08 13:10:03 +0100388
389 def run_verify_test(self):
390 """
Jan Geletyd16ba622018-06-21 16:57:47 +0200391 Create packet streams for all configured pg interfaces, send all \
Jane546d3b2016-12-08 13:10:03 +0100392 prepared packet streams and verify that:
Jan Geletyd16ba622018-06-21 16:57:47 +0200393 - all packets received correctly on all pg-ip4 interfaces assigned
394 to VRFs
395 - no packet received on all pg-ip4 interfaces not assigned to VRFs
Jane546d3b2016-12-08 13:10:03 +0100396
Jan Geletyd16ba622018-06-21 16:57:47 +0200397 :raise RuntimeError: If no packet captured on pg-ip4 interface assigned
398 to VRF or if any packet is captured on pg-ip4 interface not
399 assigned to VRF.
Jane546d3b2016-12-08 13:10:03 +0100400 """
401 # Test
402 # Create incoming packet streams for packet-generator interfaces
403 for pg_if in self.pg_interfaces:
404 pkts = self.create_stream(pg_if, self.pg_if_packet_sizes)
405 pg_if.add_stream(pkts)
406
407 # Enable packet capture and start packet sending
408 self.pg_enable_capture(self.pg_interfaces)
409 self.pg_start()
410
411 # Verify
412 # Verify outgoing packet streams per packet-generator interface
413 for pg_if in self.pg_interfaces:
414 if pg_if in self.pg_in_vrf:
415 capture = pg_if.get_capture(remark="interface is in VRF")
416 self.verify_capture(pg_if, capture)
417 elif pg_if in self.pg_not_in_vrf:
418 pg_if.assert_nothing_captured(remark="interface is not in VRF",
419 filter_out_fn=is_ipv4_misc)
420 self.logger.debug("No capture for interface %s" % pg_if.name)
421 else:
422 raise Exception("Unknown interface: %s" % pg_if.name)
423
Jan Geletyd16ba622018-06-21 16:57:47 +0200424 def run_crosswise_vrf_test(self):
425 """
426 Create packet streams for every pg-ip4 interface in VRF towards all
Dave Wallaced1706812021-08-12 18:36:02 -0400427 pg-ip4 interfaces in other VRFs, send all prepared packet streams and
Jan Geletyd16ba622018-06-21 16:57:47 +0200428 verify that:
Dave Wallaced1706812021-08-12 18:36:02 -0400429
430 - no packet received on all configured pg-ip4 interfaces
Jan Geletyd16ba622018-06-21 16:57:47 +0200431
432 :raise RuntimeError: If any packet is captured on any pg-ip4 interface.
433 """
434 # Test
435 # Create incoming packet streams for packet-generator interfaces
436 for vrf_id in self.vrf_list:
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200437 for pg_if in self.pg_if_sets[vrf_id]:
Jan Geletyd16ba622018-06-21 16:57:47 +0200438 pkts = self.create_stream_crosswise_vrf(
439 pg_if, vrf_id, self.pg_if_packet_sizes)
440 pg_if.add_stream(pkts)
441
442 # Enable packet capture and start packet sending
443 self.pg_enable_capture(self.pg_interfaces)
444 self.pg_start()
445
446 # Verify
447 # Verify outgoing packet streams per packet-generator interface
448 for pg_if in self.pg_interfaces:
449 pg_if.assert_nothing_captured(remark="interface is in other VRF",
450 filter_out_fn=is_ipv4_misc)
451 self.logger.debug("No capture for interface %s" % pg_if.name)
452
Jane546d3b2016-12-08 13:10:03 +0100453 def test_ip4_vrf_01(self):
Jan Gelety95c87b52017-02-27 10:46:14 +0100454 """ IP4 VRF Multi-instance test 1 - create 4 VRFs
Jane546d3b2016-12-08 13:10:03 +0100455 """
456 # Config 1
457 # Create 4 VRFs
458 self.create_vrf_and_assign_interfaces(4)
459
460 # Verify 1
461 for vrf_id in self.vrf_list:
Jan Gelety95c87b52017-02-27 10:46:14 +0100462 self.assert_equal(self.verify_vrf(vrf_id),
463 VRFState.configured, VRFState)
Jane546d3b2016-12-08 13:10:03 +0100464
465 # Test 1
466 self.run_verify_test()
Jan Geletyd16ba622018-06-21 16:57:47 +0200467 self.run_crosswise_vrf_test()
Jane546d3b2016-12-08 13:10:03 +0100468
469 def test_ip4_vrf_02(self):
Jan Gelety95c87b52017-02-27 10:46:14 +0100470 """ IP4 VRF Multi-instance test 2 - reset 2 VRFs
Jane546d3b2016-12-08 13:10:03 +0100471 """
472 # Config 2
Jan Gelety95c87b52017-02-27 10:46:14 +0100473 # Reset 2 VRFs
474 self.reset_vrf_and_remove_from_vrf_list(1)
475 self.reset_vrf_and_remove_from_vrf_list(2)
Jane546d3b2016-12-08 13:10:03 +0100476
477 # Verify 2
Jan Gelety95c87b52017-02-27 10:46:14 +0100478 for vrf_id in self.vrf_reset_list:
479 self.assert_equal(self.verify_vrf(vrf_id),
480 VRFState.reset, VRFState)
Jane546d3b2016-12-08 13:10:03 +0100481 for vrf_id in self.vrf_list:
Jan Gelety95c87b52017-02-27 10:46:14 +0100482 self.assert_equal(self.verify_vrf(vrf_id),
483 VRFState.configured, VRFState)
Jane546d3b2016-12-08 13:10:03 +0100484
485 # Test 2
486 self.run_verify_test()
Jan Geletyd16ba622018-06-21 16:57:47 +0200487 self.run_crosswise_vrf_test()
Jane546d3b2016-12-08 13:10:03 +0100488
489 def test_ip4_vrf_03(self):
490 """ IP4 VRF Multi-instance 3 - add 2 VRFs
491 """
492 # Config 3
Jan Gelety95c87b52017-02-27 10:46:14 +0100493 # Add 1 of reset VRFs and 1 new VRF
Jane546d3b2016-12-08 13:10:03 +0100494 self.create_vrf_and_assign_interfaces(1)
495 self.create_vrf_and_assign_interfaces(1, start=5)
496
497 # Verify 3
Jan Gelety95c87b52017-02-27 10:46:14 +0100498 for vrf_id in self.vrf_reset_list:
499 self.assert_equal(self.verify_vrf(vrf_id),
500 VRFState.reset, VRFState)
Jane546d3b2016-12-08 13:10:03 +0100501 for vrf_id in self.vrf_list:
Jan Gelety95c87b52017-02-27 10:46:14 +0100502 self.assert_equal(self.verify_vrf(vrf_id),
503 VRFState.configured, VRFState)
Jane546d3b2016-12-08 13:10:03 +0100504
505 # Test 3
506 self.run_verify_test()
Jan Geletyd16ba622018-06-21 16:57:47 +0200507 self.run_crosswise_vrf_test()
Jane546d3b2016-12-08 13:10:03 +0100508
509 def test_ip4_vrf_04(self):
Jan Gelety95c87b52017-02-27 10:46:14 +0100510 """ IP4 VRF Multi-instance test 4 - reset 4 VRFs
Jane546d3b2016-12-08 13:10:03 +0100511 """
512 # Config 4
Jan Gelety95c87b52017-02-27 10:46:14 +0100513 # Reset all VRFs (i.e. no VRF except VRF=0 configured)
Jane546d3b2016-12-08 13:10:03 +0100514 for i in range(len(self.vrf_list)):
Jan Gelety95c87b52017-02-27 10:46:14 +0100515 self.reset_vrf_and_remove_from_vrf_list(self.vrf_list[0])
Jane546d3b2016-12-08 13:10:03 +0100516
517 # Verify 4
Jan Gelety95c87b52017-02-27 10:46:14 +0100518 for vrf_id in self.vrf_reset_list:
519 self.assert_equal(self.verify_vrf(vrf_id),
520 VRFState.reset, VRFState)
521 vrf_list_length = len(self.vrf_list)
522 self.assertEqual(
523 vrf_list_length, 0,
524 "List of configured VRFs is not empty: %s != 0" % vrf_list_length)
Jane546d3b2016-12-08 13:10:03 +0100525
526 # Test 4
527 self.run_verify_test()
Jan Geletyd16ba622018-06-21 16:57:47 +0200528 self.run_crosswise_vrf_test()
Jane546d3b2016-12-08 13:10:03 +0100529
Aloys Augustin6e4cfb52021-09-16 20:53:14 +0200530 def test_ip4_vrf_05(self):
531 """ IP4 VRF Multi-instance test 5 - id allocation
532 """
533 # Config 5
534 # Create several VRFs
535 # Set vrf_id manually first
536 self.create_vrf_by_id_and_assign_interfaces(1, 1)
537 # Set vrf_id automatically a few times
538 auto_vrf_id = [
539 self.create_vrf_by_id_and_assign_interfaces(i) for i in range(2, 5)
540 ]
541
542 # Verify 5
543 self.assert_equal(self.verify_vrf(1, 1), VRFState.configured, VRFState)
544 for i, vrf in enumerate(auto_vrf_id):
545 self.assert_equal(self.verify_vrf(vrf, i+2),
546 VRFState.configured, VRFState)
547
548 # Test 5
549 self.run_verify_test()
550
551 # Config 5.1
552 # Reset VRFs
553 self.reset_vrf_and_remove_from_vrf_list(1)
554 for i, vrf in enumerate(auto_vrf_id):
555 self.reset_vrf_and_remove_from_vrf_list(vrf, i+2)
556
557 # Verify 5.1
558 self.assert_equal(self.verify_vrf(1, 1), VRFState.reset, VRFState)
559 for i, vrf in enumerate(auto_vrf_id):
560 self.assert_equal(self.verify_vrf(vrf, i+2),
561 VRFState.reset, VRFState)
562
563 vrf_list_length = len(self.vrf_list)
564 self.assertEqual(
565 vrf_list_length, 0,
566 "List of configured VRFs is not empty: %s != 0" % vrf_list_length)
Jane546d3b2016-12-08 13:10:03 +0100567
568if __name__ == '__main__':
569 unittest.main(testRunner=VppTestRunner)