Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 2 | """IP6 VRF Multi-instance Test Case HLD: |
| 3 | |
| 4 | **NOTES:** |
| 5 | - higher number of pg-ip6 interfaces causes problems => only 15 pg-ip6 \ |
Dave Wallace | d170681 | 2021-08-12 18:36:02 -0400 | [diff] [blame] | 6 | interfaces in 5 VRFs are tested |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 7 | - jumbo packets in configuration with 15 pg-ip6 interfaces leads to \ |
Dave Wallace | d170681 | 2021-08-12 18:36:02 -0400 | [diff] [blame] | 8 | problems too |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 9 | |
| 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 Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 20 | - check VRF data by parsing output of ip_route_dump API command |
Dave Wallace | d170681 | 2021-08-12 18:36:02 -0400 | [diff] [blame] | 21 | - all packets received correctly in case of pg-ip6 interfaces in the |
| 22 | same VRF |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 23 | - no packet received in case of pg-ip6 interfaces not in VRF |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 24 | - no packet received in case of pg-ip6 interfaces in different VRFs |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 25 | |
| 26 | **config 2** |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 27 | - reset 2 VRFs |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 28 | |
| 29 | **test 2** |
| 30 | - send IP6 packets between all pg-ip6 interfaces in all VRF groups |
| 31 | |
| 32 | **verify 2** |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 33 | - check VRF data by parsing output of ip_route_dump API command |
Dave Wallace | d170681 | 2021-08-12 18:36:02 -0400 | [diff] [blame] | 34 | - all packets received correctly in case of pg-ip6 interfaces in the |
| 35 | same VRF |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 36 | - no packet received in case of pg-ip6 interfaces not in VRF |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 37 | - no packet received in case of pg-ip6 interfaces in different VRFs |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 38 | |
| 39 | **config 3** |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 40 | - add 1 of reset VRFs and 1 new VRF |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 41 | |
| 42 | **test 3** |
| 43 | - send IP6 packets between all pg-ip6 interfaces in all VRF groups |
| 44 | |
| 45 | **verify 3** |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 46 | - check VRF data by parsing output of ip_route_dump API command |
Dave Wallace | d170681 | 2021-08-12 18:36:02 -0400 | [diff] [blame] | 47 | - all packets received correctly in case of pg-ip6 interfaces in the |
| 48 | same VRF |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 49 | - no packet received in case of pg-ip6 interfaces not in VRF |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 50 | - no packet received in case of pg-ip6 interfaces in different VRFs |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 51 | |
| 52 | **config 4** |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 53 | - reset all VRFs (i.e. no VRF except VRF=0 created) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 54 | |
| 55 | **test 4** |
| 56 | - send IP6 packets between all pg-ip6 interfaces in all VRF groups |
| 57 | |
| 58 | **verify 4** |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 59 | - check VRF data by parsing output of ip_route_dump API command |
Dave Wallace | d170681 | 2021-08-12 18:36:02 -0400 | [diff] [blame] | 60 | - all packets received correctly in case of pg-ip6 interfaces in the |
| 61 | same VRF |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 62 | - no packet received in case of pg-ip6 interfaces not in VRF |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 63 | - no packet received in case of pg-ip6 interfaces in different VRFs |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 64 | """ |
| 65 | |
| 66 | import unittest |
| 67 | import random |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 68 | import socket |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 69 | |
| 70 | from scapy.packet import Raw |
| 71 | from scapy.layers.l2 import Ether |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 72 | from scapy.layers.inet6 import ( |
| 73 | UDP, |
| 74 | IPv6, |
| 75 | ICMPv6ND_NS, |
| 76 | ICMPv6ND_RA, |
| 77 | RouterAlert, |
| 78 | IPv6ExtHdrHopByHop, |
| 79 | ) |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 80 | from scapy.utils6 import in6_ismaddr, in6_isllsnmaddr, in6_getAddrType |
| 81 | from scapy.pton_ntop import inet_ntop |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 82 | |
| 83 | from framework import VppTestCase, VppTestRunner |
| 84 | from util import ppp |
Jan Gelety | 95c87b5 | 2017-02-27 10:46:14 +0100 | [diff] [blame] | 85 | from vrf import VRFState |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 86 | |
| 87 | |
| 88 | def is_ipv6_misc_ext(p): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 89 | """Is packet one of uninteresting IPv6 broadcasts (extended to filter out |
| 90 | ICMPv6 Neighbor Discovery - Neighbor Advertisement packets too)?""" |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 91 | if p.haslayer(ICMPv6ND_RA): |
| 92 | if in6_ismaddr(p[IPv6].dst): |
| 93 | return True |
| 94 | if p.haslayer(ICMPv6ND_NS): |
| 95 | if in6_isllsnmaddr(p[IPv6].dst): |
| 96 | return True |
| 97 | if p.haslayer(IPv6ExtHdrHopByHop): |
| 98 | for o in p[IPv6ExtHdrHopByHop].options: |
| 99 | if isinstance(o, RouterAlert): |
| 100 | return True |
| 101 | return False |
| 102 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 103 | |
| 104 | class TestIP6VrfMultiInst(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 105 | """IP6 VRF Multi-instance Test Case""" |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 106 | |
| 107 | @classmethod |
| 108 | def setUpClass(cls): |
| 109 | """ |
| 110 | Perform standard class setup (defined by class method setUpClass in |
| 111 | class VppTestCase) before running the test case, set test case related |
| 112 | variables and configure VPP. |
| 113 | """ |
| 114 | super(TestIP6VrfMultiInst, cls).setUpClass() |
| 115 | |
| 116 | # Test variables |
| 117 | cls.hosts_per_pg = 5 |
| 118 | cls.nr_of_vrfs = 5 |
| 119 | cls.pg_ifs_per_vrf = 3 |
| 120 | |
| 121 | try: |
| 122 | # Create pg interfaces |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 123 | cls.create_pg_interfaces(range(cls.nr_of_vrfs * cls.pg_ifs_per_vrf)) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 124 | |
| 125 | # Packet flows mapping pg0 -> pg1, pg2 etc. |
| 126 | cls.flows = dict() |
| 127 | for i in range(len(cls.pg_interfaces)): |
Ole Troan | 1975733 | 2019-10-18 14:54:30 +0200 | [diff] [blame] | 128 | multiplicand = i // cls.pg_ifs_per_vrf |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 129 | pg_list = [ |
| 130 | cls.pg_interfaces[multiplicand * cls.pg_ifs_per_vrf + j] |
| 131 | for j in range(cls.pg_ifs_per_vrf) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 132 | if (multiplicand * cls.pg_ifs_per_vrf + j) != i |
| 133 | ] |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 134 | cls.flows[cls.pg_interfaces[i]] = pg_list |
| 135 | |
| 136 | # Packet sizes - jumbo packet (9018 bytes) skipped |
| 137 | cls.pg_if_packet_sizes = [64, 512, 1518] |
| 138 | |
| 139 | # Set up all interfaces |
| 140 | for pg_if in cls.pg_interfaces: |
| 141 | pg_if.admin_up() |
| 142 | pg_if.generate_remote_hosts(cls.hosts_per_pg) |
| 143 | |
| 144 | # Create list of VRFs |
| 145 | cls.vrf_list = list() |
| 146 | |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 147 | # Create list of reset VRFs |
| 148 | cls.vrf_reset_list = list() |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 149 | |
| 150 | # Create list of pg_interfaces in VRFs |
| 151 | cls.pg_in_vrf = list() |
| 152 | |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 153 | # Create list of pg_interfaces not in VRFs |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 154 | cls.pg_not_in_vrf = [pg_if for pg_if in cls.pg_interfaces] |
| 155 | |
| 156 | # Create mapping of pg_interfaces to VRF IDs |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 157 | cls.pg_if_sets = dict() |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 158 | for i in range(cls.nr_of_vrfs): |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 159 | set_id = i + 1 |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 160 | pg_list = [ |
| 161 | cls.pg_interfaces[i * cls.pg_ifs_per_vrf + j] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 162 | for j in range(cls.pg_ifs_per_vrf) |
| 163 | ] |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 164 | cls.pg_if_sets[set_id] = pg_list |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 165 | |
| 166 | except Exception: |
| 167 | super(TestIP6VrfMultiInst, cls).tearDownClass() |
| 168 | raise |
| 169 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 170 | @classmethod |
| 171 | def tearDownClass(cls): |
| 172 | super(TestIP6VrfMultiInst, cls).tearDownClass() |
| 173 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 174 | def setUp(self): |
| 175 | """ |
| 176 | Clear trace and packet infos before running each test. |
| 177 | """ |
| 178 | super(TestIP6VrfMultiInst, self).setUp() |
| 179 | self.reset_packet_infos() |
| 180 | |
| 181 | def tearDown(self): |
| 182 | """ |
| 183 | Show various debug prints after each test. |
| 184 | """ |
| 185 | super(TestIP6VrfMultiInst, self).tearDown() |
Paul Vinciguerra | 90cf21b | 2019-03-13 09:23:05 -0700 | [diff] [blame] | 186 | |
| 187 | def show_commands_at_teardown(self): |
| 188 | self.logger.info(self.vapi.ppcli("show ip6 fib")) |
| 189 | self.logger.info(self.vapi.ppcli("show ip6 neighbors")) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 190 | |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 191 | def _assign_interfaces(self, vrf_id, if_set_id): |
| 192 | for i in range(self.pg_ifs_per_vrf): |
| 193 | pg_if = self.pg_if_sets[if_set_id][i] |
| 194 | pg_if.set_table_ip6(vrf_id) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 195 | self.logger.info( |
| 196 | "pg-interface %s added to IPv6 VRF ID %d" % (pg_if.name, vrf_id) |
| 197 | ) |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 198 | if pg_if not in self.pg_in_vrf: |
| 199 | self.pg_in_vrf.append(pg_if) |
| 200 | if pg_if in self.pg_not_in_vrf: |
| 201 | self.pg_not_in_vrf.remove(pg_if) |
| 202 | pg_if.config_ip6() |
| 203 | pg_if.disable_ipv6_ra() |
| 204 | pg_if.configure_ipv6_neighbors() |
| 205 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 206 | def create_vrf_and_assign_interfaces(self, count, start=1): |
| 207 | """ |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 208 | Create required number of FIB tables / VRFs, put 3 pg-ip6 interfaces |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 209 | to every FIB table / VRF. |
| 210 | |
| 211 | :param int count: Number of FIB tables / VRFs to be created. |
| 212 | :param int start: Starting number of the FIB table / VRF ID. \ |
| 213 | (Default value = 1) |
| 214 | """ |
| 215 | for i in range(count): |
| 216 | vrf_id = i + start |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 217 | self.vapi.ip_table_add_del( |
| 218 | is_add=1, table={"table_id": vrf_id, "is_ip6": 1} |
| 219 | ) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 220 | self.logger.info("IPv6 VRF ID %d created" % vrf_id) |
| 221 | if vrf_id not in self.vrf_list: |
| 222 | self.vrf_list.append(vrf_id) |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 223 | if vrf_id in self.vrf_reset_list: |
| 224 | self.vrf_reset_list.remove(vrf_id) |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 225 | self._assign_interfaces(vrf_id, vrf_id) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 226 | self.logger.debug(self.vapi.ppcli("show ip6 fib")) |
| 227 | self.logger.debug(self.vapi.ppcli("show ip6 neighbors")) |
| 228 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 229 | def create_vrf_by_id_and_assign_interfaces(self, set_id, vrf_id=0xFFFFFFFF): |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 230 | """ |
| 231 | Create a FIB table / VRF by vrf_id, put 3 pg-ip6 interfaces |
| 232 | to FIB table / VRF. |
| 233 | |
| 234 | :param int vrf_id: Required table ID / VRF ID. \ |
| 235 | (Default value = 0xffffffff, ID will be selected automatically) |
| 236 | """ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 237 | ret = self.vapi.ip_table_allocate(table={"table_id": vrf_id, "is_ip6": 1}) |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 238 | vrf_id = ret.table.table_id |
| 239 | self.logger.info("IPv6 VRF ID %d created" % vrf_id) |
| 240 | if vrf_id not in self.vrf_list: |
| 241 | self.vrf_list.append(vrf_id) |
| 242 | if vrf_id in self.vrf_reset_list: |
| 243 | self.vrf_reset_list.remove(vrf_id) |
| 244 | self._assign_interfaces(vrf_id, set_id) |
| 245 | self.logger.debug(self.vapi.ppcli("show ip6 fib")) |
| 246 | self.logger.debug(self.vapi.ppcli("show ip6 neighbors")) |
| 247 | |
| 248 | return vrf_id |
| 249 | |
| 250 | def reset_vrf_and_remove_from_vrf_list(self, vrf_id, if_set_id=None): |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 251 | """ |
Jan Gelety | 95c87b5 | 2017-02-27 10:46:14 +0100 | [diff] [blame] | 252 | Reset required FIB table / VRF and remove it from VRF list. |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 253 | |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 254 | :param int vrf_id: The FIB table / VRF ID to be reset. |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 255 | """ |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 256 | if if_set_id is None: |
| 257 | if_set_id = vrf_id |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 258 | self.vapi.ip_table_flush(table={"table_id": vrf_id, "is_ip6": 1}) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 259 | if vrf_id in self.vrf_list: |
| 260 | self.vrf_list.remove(vrf_id) |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 261 | if vrf_id not in self.vrf_reset_list: |
| 262 | self.vrf_reset_list.append(vrf_id) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 263 | for j in range(self.pg_ifs_per_vrf): |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 264 | pg_if = self.pg_if_sets[if_set_id][j] |
Neale Ranns | 4008ac9 | 2017-02-13 23:20:04 -0800 | [diff] [blame] | 265 | pg_if.unconfig_ip6() |
Nathan Skrzypczak | a424dd1 | 2021-08-20 15:53:43 +0200 | [diff] [blame] | 266 | pg_if.set_table_ip6(0) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 267 | if pg_if in self.pg_in_vrf: |
| 268 | self.pg_in_vrf.remove(pg_if) |
| 269 | if pg_if not in self.pg_not_in_vrf: |
| 270 | self.pg_not_in_vrf.append(pg_if) |
Jan Gelety | 95c87b5 | 2017-02-27 10:46:14 +0100 | [diff] [blame] | 271 | self.logger.info("IPv6 VRF ID %d reset finished" % vrf_id) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 272 | self.logger.debug(self.vapi.ppcli("show ip6 fib")) |
| 273 | self.logger.debug(self.vapi.ppcli("show ip6 neighbors")) |
Nathan Skrzypczak | a424dd1 | 2021-08-20 15:53:43 +0200 | [diff] [blame] | 274 | |
| 275 | def delete_vrf(self, vrf_id): |
| 276 | if vrf_id in self.vrf_list: |
| 277 | self.vrf_list.remove(vrf_id) |
| 278 | if vrf_id in self.vrf_reset_list: |
| 279 | self.vrf_reset_list.remove(vrf_id) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 280 | self.vapi.ip_table_add_del(is_add=0, table={"table_id": vrf_id, "is_ip6": 1}) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 281 | |
| 282 | def create_stream(self, src_if, packet_sizes): |
| 283 | """ |
| 284 | Create input packet stream for defined interface using hosts list. |
| 285 | |
| 286 | :param object src_if: Interface to create packet stream for. |
| 287 | :param list packet_sizes: List of required packet sizes. |
| 288 | :return: Stream of packets. |
| 289 | """ |
| 290 | pkts = [] |
| 291 | src_hosts = src_if.remote_hosts |
| 292 | for dst_if in self.flows[src_if]: |
| 293 | for dst_host in dst_if.remote_hosts: |
| 294 | src_host = random.choice(src_hosts) |
| 295 | pkt_info = self.create_packet_info(src_if, dst_if) |
| 296 | payload = self.info_to_payload(pkt_info) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 297 | p = ( |
| 298 | Ether(dst=src_if.local_mac, src=src_host.mac) |
| 299 | / IPv6(src=src_host.ip6, dst=dst_host.ip6) |
| 300 | / UDP(sport=1234, dport=1234) |
| 301 | / Raw(payload) |
| 302 | ) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 303 | pkt_info.data = p.copy() |
| 304 | size = random.choice(packet_sizes) |
| 305 | self.extend_packet(p, size) |
| 306 | pkts.append(p) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 307 | self.logger.debug( |
| 308 | "Input stream created for port %s. Length: %u pkt(s)" |
| 309 | % (src_if.name, len(pkts)) |
| 310 | ) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 311 | return pkts |
| 312 | |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 313 | def create_stream_crosswise_vrf(self, src_if, vrf_id, packet_sizes): |
| 314 | """ |
| 315 | Create input packet stream for negative test for leaking across |
| 316 | different VRFs for defined interface using hosts list. |
| 317 | |
| 318 | :param object src_if: Interface to create packet stream for. |
| 319 | :param int vrf_id: The FIB table / VRF ID where src_if is assigned. |
| 320 | :param list packet_sizes: List of required packet sizes. |
| 321 | :return: Stream of packets. |
| 322 | """ |
| 323 | pkts = [] |
| 324 | src_hosts = src_if.remote_hosts |
| 325 | vrf_lst = list(self.vrf_list) |
| 326 | vrf_lst.remove(vrf_id) |
| 327 | for vrf in vrf_lst: |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 328 | for dst_if in self.pg_if_sets[vrf]: |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 329 | for dst_host in dst_if.remote_hosts: |
| 330 | src_host = random.choice(src_hosts) |
| 331 | pkt_info = self.create_packet_info(src_if, dst_if) |
| 332 | payload = self.info_to_payload(pkt_info) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 333 | p = ( |
| 334 | Ether(dst=src_if.local_mac, src=src_host.mac) |
| 335 | / IPv6(src=src_host.ip6, dst=dst_host.ip6) |
| 336 | / UDP(sport=1234, dport=1234) |
| 337 | / Raw(payload) |
| 338 | ) |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 339 | pkt_info.data = p.copy() |
| 340 | size = random.choice(packet_sizes) |
| 341 | self.extend_packet(p, size) |
| 342 | pkts.append(p) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 343 | self.logger.debug( |
| 344 | "Input stream created for port %s. Length: %u pkt(s)" |
| 345 | % (src_if.name, len(pkts)) |
| 346 | ) |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 347 | return pkts |
| 348 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 349 | def verify_capture(self, pg_if, capture): |
| 350 | """ |
| 351 | Verify captured input packet stream for defined interface. |
| 352 | |
| 353 | :param object pg_if: Interface to verify captured packet stream for. |
| 354 | :param list capture: Captured packet stream. |
| 355 | """ |
| 356 | last_info = dict() |
| 357 | for i in self.pg_interfaces: |
| 358 | last_info[i.sw_if_index] = None |
| 359 | dst_sw_if_index = pg_if.sw_if_index |
| 360 | for packet in capture: |
| 361 | try: |
| 362 | ip = packet[IPv6] |
| 363 | udp = packet[UDP] |
Paul Vinciguerra | eaea421 | 2019-03-06 11:58:06 -0800 | [diff] [blame] | 364 | payload_info = self.payload_to_info(packet[Raw]) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 365 | packet_index = payload_info.index |
| 366 | self.assertEqual(payload_info.dst, dst_sw_if_index) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 367 | self.logger.debug( |
| 368 | "Got packet on port %s: src=%u (id=%u)" |
| 369 | % (pg_if.name, payload_info.src, packet_index) |
| 370 | ) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 371 | next_info = self.get_next_packet_info_for_interface2( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 372 | payload_info.src, dst_sw_if_index, last_info[payload_info.src] |
| 373 | ) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 374 | last_info[payload_info.src] = next_info |
| 375 | self.assertIsNotNone(next_info) |
| 376 | self.assertEqual(packet_index, next_info.index) |
| 377 | saved_packet = next_info.data |
| 378 | # Check standard fields |
| 379 | self.assertEqual(ip.src, saved_packet[IPv6].src) |
| 380 | self.assertEqual(ip.dst, saved_packet[IPv6].dst) |
| 381 | self.assertEqual(udp.sport, saved_packet[UDP].sport) |
| 382 | self.assertEqual(udp.dport, saved_packet[UDP].dport) |
| 383 | except: |
| 384 | self.logger.error(ppp("Unexpected or invalid packet:", packet)) |
| 385 | raise |
| 386 | for i in self.pg_interfaces: |
| 387 | remaining_packet = self.get_next_packet_info_for_interface2( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 388 | i, dst_sw_if_index, last_info[i.sw_if_index] |
| 389 | ) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 390 | self.assertIsNone( |
| 391 | remaining_packet, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 392 | "Port %u: Packet expected from source %u didn't arrive" |
| 393 | % (dst_sw_if_index, i.sw_if_index), |
| 394 | ) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 395 | |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 396 | def verify_vrf(self, vrf_id, if_set_id=None): |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 397 | """ |
| 398 | Check if the FIB table / VRF ID is configured. |
| 399 | |
| 400 | :param int vrf_id: The FIB table / VRF ID to be verified. |
| 401 | :return: 1 if the FIB table / VRF ID is configured, otherwise return 0. |
| 402 | """ |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 403 | if if_set_id is None: |
| 404 | if_set_id = vrf_id |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 405 | ip6_fib_dump = self.vapi.ip_route_dump(vrf_id, True) |
| 406 | vrf_exist = len(ip6_fib_dump) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 407 | vrf_count = 0 |
| 408 | for ip6_fib_details in ip6_fib_dump: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 409 | addr = ip6_fib_details.route.prefix.network_address |
| 410 | found = False |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 411 | for pg_if in self.pg_if_sets[if_set_id]: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 412 | if found: |
| 413 | break |
| 414 | for host in pg_if.remote_hosts: |
| 415 | if str(addr) == host.ip6: |
| 416 | vrf_count += 1 |
| 417 | found = True |
Jan Gelety | 95c87b5 | 2017-02-27 10:46:14 +0100 | [diff] [blame] | 418 | break |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 419 | if not vrf_exist and vrf_count == 0: |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 420 | self.logger.info("IPv6 VRF ID %d is not configured" % vrf_id) |
Jan Gelety | 95c87b5 | 2017-02-27 10:46:14 +0100 | [diff] [blame] | 421 | return VRFState.not_configured |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 422 | elif vrf_exist and vrf_count == 0: |
| 423 | self.logger.info("IPv6 VRF ID %d has been reset" % vrf_id) |
Jan Gelety | 95c87b5 | 2017-02-27 10:46:14 +0100 | [diff] [blame] | 424 | return VRFState.reset |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 425 | else: |
| 426 | self.logger.info("IPv6 VRF ID %d is configured" % vrf_id) |
Jan Gelety | 95c87b5 | 2017-02-27 10:46:14 +0100 | [diff] [blame] | 427 | return VRFState.configured |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 428 | |
| 429 | def run_verify_test(self): |
| 430 | """ |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 431 | Create packet streams for all configured pg interfaces, send all \ |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 432 | prepared packet streams and verify that: |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 433 | - all packets received correctly on all pg-ip6 interfaces assigned |
| 434 | to VRFs |
| 435 | - no packet received on all pg-ip6 interfaces not assigned to VRFs |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 436 | |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 437 | :raise RuntimeError: If no packet captured on pg-ip6 interface assigned |
| 438 | to VRF or if any packet is captured on pg-ip6 interface not |
| 439 | assigned to VRF. |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 440 | """ |
| 441 | # Test |
| 442 | # Create incoming packet streams for packet-generator interfaces |
| 443 | for pg_if in self.pg_interfaces: |
| 444 | pkts = self.create_stream(pg_if, self.pg_if_packet_sizes) |
| 445 | pg_if.add_stream(pkts) |
| 446 | |
| 447 | # Enable packet capture and start packet sending |
| 448 | self.pg_enable_capture(self.pg_interfaces) |
| 449 | self.pg_start() |
| 450 | |
| 451 | # Verify |
| 452 | # Verify outgoing packet streams per packet-generator interface |
| 453 | for pg_if in self.pg_interfaces: |
| 454 | if pg_if in self.pg_in_vrf: |
| 455 | capture = pg_if.get_capture(remark="interface is in VRF") |
| 456 | self.verify_capture(pg_if, capture) |
| 457 | elif pg_if in self.pg_not_in_vrf: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 458 | pg_if.assert_nothing_captured( |
| 459 | remark="interface is not in VRF", filter_out_fn=is_ipv6_misc_ext |
| 460 | ) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 461 | self.logger.debug("No capture for interface %s" % pg_if.name) |
| 462 | else: |
| 463 | raise Exception("Unknown interface: %s" % pg_if.name) |
| 464 | |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 465 | def run_crosswise_vrf_test(self): |
| 466 | """ |
| 467 | Create packet streams for every pg-ip6 interface in VRF towards all |
Dave Wallace | d170681 | 2021-08-12 18:36:02 -0400 | [diff] [blame] | 468 | pg-ip6 interfaces in other VRFs, send all prepared packet streams and |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 469 | verify that: |
Dave Wallace | d170681 | 2021-08-12 18:36:02 -0400 | [diff] [blame] | 470 | |
| 471 | - no packet received on all configured pg-ip6 interfaces |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 472 | |
| 473 | :raise RuntimeError: If any packet is captured on any pg-ip6 interface. |
| 474 | """ |
| 475 | # Test |
| 476 | # Create incoming packet streams for packet-generator interfaces |
| 477 | for vrf_id in self.vrf_list: |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 478 | for pg_if in self.pg_if_sets[vrf_id]: |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 479 | pkts = self.create_stream_crosswise_vrf( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 480 | pg_if, vrf_id, self.pg_if_packet_sizes |
| 481 | ) |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 482 | pg_if.add_stream(pkts) |
| 483 | |
| 484 | # Enable packet capture and start packet sending |
| 485 | self.pg_enable_capture(self.pg_interfaces) |
| 486 | self.pg_start() |
| 487 | |
| 488 | # Verify |
| 489 | # Verify outgoing packet streams per packet-generator interface |
| 490 | for pg_if in self.pg_interfaces: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 491 | pg_if.assert_nothing_captured( |
| 492 | remark="interface is in other VRF", filter_out_fn=is_ipv6_misc_ext |
| 493 | ) |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 494 | self.logger.debug("No capture for interface %s" % pg_if.name) |
| 495 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 496 | def test_ip6_vrf_01(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 497 | """IP6 VRF Multi-instance test 1 - create 4 VRFs""" |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 498 | # Config 1 |
| 499 | # Create 4 VRFs |
| 500 | self.create_vrf_and_assign_interfaces(4) |
| 501 | |
| 502 | # Verify 1 |
| 503 | for vrf_id in self.vrf_list: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 504 | self.assert_equal(self.verify_vrf(vrf_id), VRFState.configured, VRFState) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 505 | |
| 506 | # Test 1 |
| 507 | self.run_verify_test() |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 508 | self.run_crosswise_vrf_test() |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 509 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 510 | def test_ip6_vrf_02(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 511 | """IP6 VRF Multi-instance test 2 - reset 2 VRFs""" |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 512 | # Config 2 |
| 513 | # Delete 2 VRFs |
Jan Gelety | 95c87b5 | 2017-02-27 10:46:14 +0100 | [diff] [blame] | 514 | self.reset_vrf_and_remove_from_vrf_list(1) |
| 515 | self.reset_vrf_and_remove_from_vrf_list(2) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 516 | |
| 517 | # Verify 2 |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 518 | for vrf_id in self.vrf_reset_list: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 519 | self.assert_equal(self.verify_vrf(vrf_id), VRFState.reset, VRFState) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 520 | for vrf_id in self.vrf_list: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 521 | self.assert_equal(self.verify_vrf(vrf_id), VRFState.configured, VRFState) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 522 | |
| 523 | # Test 2 |
| 524 | self.run_verify_test() |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 525 | self.run_crosswise_vrf_test() |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 526 | |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 527 | # Reset routes learned from ICMPv6 Neighbor Discovery |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 528 | # for vrf_id in self.vrf_reset_list: |
| 529 | # self.reset_vrf_and_remove_from_vrf_list(vrf_id) |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 530 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 531 | def test_ip6_vrf_03(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 532 | """IP6 VRF Multi-instance 3 - add 2 VRFs""" |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 533 | # Config 3 |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 534 | # Add 1 of reset VRFs and 1 new VRF |
| 535 | self.create_vrf_and_assign_interfaces(1) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 536 | self.create_vrf_and_assign_interfaces(1, start=5) |
| 537 | |
| 538 | # Verify 3 |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 539 | for vrf_id in self.vrf_reset_list: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 540 | self.assert_equal(self.verify_vrf(vrf_id), VRFState.reset, VRFState) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 541 | for vrf_id in self.vrf_list: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 542 | self.assert_equal(self.verify_vrf(vrf_id), VRFState.configured, VRFState) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 543 | |
| 544 | # Test 3 |
| 545 | self.run_verify_test() |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 546 | self.run_crosswise_vrf_test() |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 547 | |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 548 | # Reset routes learned from ICMPv6 Neighbor Discovery |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 549 | # for vrf_id in self.vrf_reset_list: |
| 550 | # self.reset_vrf_and_remove_from_vrf_list(vrf_id) |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 551 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 552 | def test_ip6_vrf_04(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 553 | """IP6 VRF Multi-instance test 4 - reset 4 VRFs""" |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 554 | # Config 4 |
Jan Gelety | 95c87b5 | 2017-02-27 10:46:14 +0100 | [diff] [blame] | 555 | # Reset all VRFs (i.e. no VRF except VRF=0 configured) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 556 | for i in range(len(self.vrf_list)): |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 557 | # This call removes the first item of vrf_list as a side effect |
Jan Gelety | 95c87b5 | 2017-02-27 10:46:14 +0100 | [diff] [blame] | 558 | self.reset_vrf_and_remove_from_vrf_list(self.vrf_list[0]) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 559 | |
| 560 | # Verify 4 |
Jan Gelety | b5b2ef5 | 2017-02-23 15:01:29 +0100 | [diff] [blame] | 561 | for vrf_id in self.vrf_reset_list: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 562 | self.assert_equal(self.verify_vrf(vrf_id), VRFState.reset, VRFState) |
Jan Gelety | 95c87b5 | 2017-02-27 10:46:14 +0100 | [diff] [blame] | 563 | vrf_list_length = len(self.vrf_list) |
| 564 | self.assertEqual( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 565 | vrf_list_length, |
| 566 | 0, |
| 567 | "List of configured VRFs is not empty: %s != 0" % vrf_list_length, |
| 568 | ) |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 569 | |
| 570 | # Test 4 |
| 571 | self.run_verify_test() |
Jan Gelety | d16ba62 | 2018-06-21 16:57:47 +0200 | [diff] [blame] | 572 | self.run_crosswise_vrf_test() |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 573 | |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 574 | def test_ip6_vrf_05(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 575 | """IP6 VRF Multi-instance test 5 - auto allocate vrf id""" |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 576 | # Config 5 |
| 577 | # Create several VRFs |
| 578 | # Set vrf_id manually first |
| 579 | self.create_vrf_by_id_and_assign_interfaces(1, 10) |
| 580 | # Set vrf_id automatically a few times |
| 581 | auto_vrf_id = [ |
| 582 | self.create_vrf_by_id_and_assign_interfaces(i) for i in range(2, 5) |
| 583 | ] |
| 584 | |
| 585 | # Verify 5 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 586 | self.assert_equal(self.verify_vrf(10, 1), VRFState.configured, VRFState) |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 587 | for i, vrf in enumerate(auto_vrf_id): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 588 | self.assert_equal( |
| 589 | self.verify_vrf(vrf, i + 2), VRFState.configured, VRFState |
| 590 | ) |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 591 | |
| 592 | # Test 5 |
| 593 | self.run_verify_test() |
| 594 | |
| 595 | # Config 5.1 |
| 596 | # Reset VRFs |
| 597 | self.reset_vrf_and_remove_from_vrf_list(10, 1) |
| 598 | for i, vrf in enumerate(auto_vrf_id): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 599 | self.reset_vrf_and_remove_from_vrf_list(vrf, i + 2) |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 600 | |
| 601 | # Verify 5.1 |
| 602 | self.assert_equal(self.verify_vrf(10, 1), VRFState.reset, VRFState) |
| 603 | for i, vrf in enumerate(auto_vrf_id): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 604 | self.assert_equal(self.verify_vrf(vrf, i + 2), VRFState.reset, VRFState) |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 605 | |
| 606 | vrf_list_length = len(self.vrf_list) |
| 607 | self.assertEqual( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 608 | vrf_list_length, |
| 609 | 0, |
| 610 | "List of configured VRFs is not empty: %s != 0" % vrf_list_length, |
| 611 | ) |
Aloys Augustin | 6e4cfb5 | 2021-09-16 20:53:14 +0200 | [diff] [blame] | 612 | |
Nathan Skrzypczak | a424dd1 | 2021-08-20 15:53:43 +0200 | [diff] [blame] | 613 | # Cleanup our extra created VRFs |
| 614 | for vrf in auto_vrf_id: |
| 615 | self.delete_vrf(vrf) |
| 616 | self.delete_vrf(5) |
| 617 | self.delete_vrf(10) |
| 618 | |
Nathan Skrzypczak | 275bd79 | 2021-09-17 17:29:14 +0200 | [diff] [blame] | 619 | def test_ip6_vrf_06(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 620 | """IP6 VRF Multi-instance test 6 - recreate 4 VRFs""" |
Nathan Skrzypczak | 275bd79 | 2021-09-17 17:29:14 +0200 | [diff] [blame] | 621 | # Reconfigure all the VRFs |
| 622 | self.create_vrf_and_assign_interfaces(4) |
| 623 | # Verify |
| 624 | for vrf_id in self.vrf_list: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 625 | self.assert_equal(self.verify_vrf(vrf_id), VRFState.configured, VRFState) |
Nathan Skrzypczak | 275bd79 | 2021-09-17 17:29:14 +0200 | [diff] [blame] | 626 | # Test |
| 627 | self.run_verify_test() |
| 628 | self.run_crosswise_vrf_test() |
| 629 | # Cleanup |
| 630 | for i in range(len(self.vrf_list)): |
| 631 | self.reset_vrf_and_remove_from_vrf_list(self.vrf_list[0]) |
| 632 | # Verify |
| 633 | for vrf_id in self.vrf_reset_list: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 634 | self.assert_equal(self.verify_vrf(vrf_id), VRFState.reset, VRFState) |
Nathan Skrzypczak | 275bd79 | 2021-09-17 17:29:14 +0200 | [diff] [blame] | 635 | vrf_list_length = len(self.vrf_list) |
| 636 | self.assertEqual( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 637 | vrf_list_length, |
| 638 | 0, |
| 639 | "List of configured VRFs is not empty: %s != 0" % vrf_list_length, |
| 640 | ) |
Nathan Skrzypczak | 275bd79 | 2021-09-17 17:29:14 +0200 | [diff] [blame] | 641 | # Test |
| 642 | self.run_verify_test() |
| 643 | self.run_crosswise_vrf_test() |
| 644 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 645 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 646 | if __name__ == "__main__": |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 647 | unittest.main(testRunner=VppTestRunner) |