Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 2 | """L2BD Multi-instance Test Case HLD: |
| 3 | |
| 4 | **NOTES:** |
| 5 | - higher number of pg-l2 interfaces causes problems => only 15 pg-l2 \ |
| 6 | interfaces in 5 bridge domains are tested |
Jan | 65209ed | 2016-12-05 23:29:17 +0100 | [diff] [blame] | 7 | - jumbo packets in configuration with 14 l2-pg interfaces leads to \ |
| 8 | problems too |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 9 | |
| 10 | **config 1** |
| 11 | - add 15 pg-l2 interfaces |
| 12 | - configure one host per pg-l2 interface |
| 13 | - configure 5 bridge domains (BD) |
| 14 | - add 3 pg-l2 interfaces per BD |
| 15 | |
| 16 | **test 1** |
| 17 | - send L2 MAC frames between all pg-l2 interfaces of all BDs |
| 18 | |
| 19 | **verify 1** |
| 20 | - check BD data by parsing output of bridge_domain_dump API command |
| 21 | - all packets received correctly |
| 22 | |
| 23 | **config 2** |
| 24 | - update data of 5 BD |
| 25 | - disable learning, forwarding, flooding and uu_flooding for BD1 |
| 26 | - disable forwarding for BD2 |
| 27 | - disable flooding for BD3 |
| 28 | - disable uu_flooding for BD4 |
| 29 | - disable learning for BD5 |
| 30 | |
| 31 | **verify 2** |
| 32 | - check BD data by parsing output of bridge_domain_dump API command |
| 33 | |
| 34 | **config 3** |
| 35 | - delete 2 BDs |
| 36 | |
| 37 | **test 3** |
| 38 | - send L2 MAC frames between all pg-l2 interfaces of all BDs |
| 39 | - send L2 MAC frames between all pg-l2 interfaces formerly assigned to \ |
| 40 | deleted BDs |
| 41 | |
| 42 | **verify 3** |
| 43 | - check BD data by parsing output of bridge_domain_dump API command |
| 44 | - all packets received correctly on all 3 pg-l2 interfaces assigned to BDs |
| 45 | - no packet received on all 3 pg-l2 interfaces of all deleted BDs |
| 46 | |
| 47 | **config 4** |
| 48 | - add 2 BDs |
| 49 | - add 3 pg-l2 interfaces per BD |
| 50 | |
| 51 | **test 4** |
| 52 | - send L2 MAC frames between all pg-l2 interfaces of all BDs |
| 53 | |
| 54 | **verify 4** |
| 55 | - check BD data by parsing output of bridge_domain_dump API command |
| 56 | - all packets received correctly |
| 57 | |
| 58 | **config 5** |
| 59 | - delete 5 BDs |
| 60 | |
| 61 | **verify 5** |
| 62 | - check BD data by parsing output of bridge_domain_dump API command |
| 63 | """ |
| 64 | |
| 65 | import unittest |
| 66 | import random |
| 67 | |
| 68 | from scapy.packet import Raw |
| 69 | from scapy.layers.l2 import Ether |
| 70 | from scapy.layers.inet import IP, UDP |
| 71 | |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 72 | from framework import VppTestCase |
| 73 | from asfframework import VppTestRunner |
Klement Sekera | 9225dee | 2016-12-12 08:36:58 +0100 | [diff] [blame] | 74 | from util import Host, ppp |
| 75 | |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 76 | |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 77 | class TestL2bdMultiInst(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 78 | """L2BD Multi-instance Test Case""" |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 79 | |
| 80 | @classmethod |
| 81 | def setUpClass(cls): |
| 82 | """ |
| 83 | Perform standard class setup (defined by class method setUpClass in |
| 84 | class VppTestCase) before running the test case, set test case related |
| 85 | variables and configure VPP. |
| 86 | """ |
| 87 | super(TestL2bdMultiInst, cls).setUpClass() |
| 88 | |
| 89 | try: |
| 90 | # Create pg interfaces |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 91 | n_bd = 5 |
| 92 | cls.ifs_per_bd = ifs_per_bd = 3 |
| 93 | n_ifs = n_bd * ifs_per_bd |
| 94 | cls.create_pg_interfaces(range(n_ifs)) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 95 | |
| 96 | # Packet flows mapping pg0 -> pg1, pg2 etc. |
| 97 | cls.flows = dict() |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 98 | for b in range(n_bd): |
| 99 | bd_ifs = cls.bd_if_range(b + 1) |
| 100 | for j in bd_ifs: |
| 101 | cls.flows[cls.pg_interfaces[j]] = [ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 102 | cls.pg_interfaces[x] for x in bd_ifs if x != j |
| 103 | ] |
| 104 | assert len(cls.flows[cls.pg_interfaces[j]]) == ifs_per_bd - 1 |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 105 | |
| 106 | # Mapping between packet-generator index and lists of test hosts |
| 107 | cls.hosts_by_pg_idx = dict() |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 108 | |
| 109 | # Create test host entries |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 110 | cls.create_hosts(5) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 111 | |
Jan | 65209ed | 2016-12-05 23:29:17 +0100 | [diff] [blame] | 112 | # Packet sizes - jumbo packet (9018 bytes) skipped |
| 113 | cls.pg_if_packet_sizes = [64, 512, 1518] |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 114 | |
| 115 | # Set up all interfaces |
| 116 | for i in cls.pg_interfaces: |
| 117 | i.admin_up() |
| 118 | |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 119 | except Exception: |
| 120 | super(TestL2bdMultiInst, cls).tearDownClass() |
| 121 | raise |
| 122 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 123 | @classmethod |
| 124 | def tearDownClass(cls): |
| 125 | super(TestL2bdMultiInst, cls).tearDownClass() |
| 126 | |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 127 | def setUp(self): |
| 128 | """ |
| 129 | Clear trace and packet infos before running each test. |
| 130 | """ |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 131 | self.reset_packet_infos() |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 132 | super(TestL2bdMultiInst, self).setUp() |
Paul Vinciguerra | 548d5ee | 2019-12-16 20:56:00 -0500 | [diff] [blame] | 133 | # Create list of BDs |
| 134 | self.bd_list = [] |
| 135 | |
Laszlo Kiraly | 0f8f435 | 2022-09-16 13:20:07 +0200 | [diff] [blame] | 136 | # Create dict of BDs |
| 137 | self.bd_map = {} |
| 138 | |
Paul Vinciguerra | 548d5ee | 2019-12-16 20:56:00 -0500 | [diff] [blame] | 139 | # Create list of deleted BDs |
| 140 | self.bd_deleted_list = [] |
| 141 | |
| 142 | # Create list of pg_interfaces in BDs |
| 143 | self.pg_in_bd = [] |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 144 | |
| 145 | def tearDown(self): |
| 146 | """ |
| 147 | Show various debug prints after each test. |
| 148 | """ |
| 149 | super(TestL2bdMultiInst, self).tearDown() |
| 150 | if not self.vpp_dead: |
| 151 | self.logger.info(self.vapi.ppcli("show l2fib verbose")) |
| 152 | self.logger.info(self.vapi.ppcli("show bridge-domain")) |
| 153 | |
| 154 | @classmethod |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 155 | def create_hosts(cls, hosts_per_if): |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 156 | """ |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 157 | Create required number of host MAC addresses and distribute them |
| 158 | among interfaces. Create host IPv4 address for every host MAC |
| 159 | address. |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 160 | |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 161 | :param int hosts_per_if: Number of hosts per if to create MAC/IPv4 |
| 162 | addresses for. |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 163 | """ |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 164 | c = hosts_per_if |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 165 | assert not cls.hosts_by_pg_idx |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 166 | for i in range(len(cls.pg_interfaces)): |
| 167 | pg_idx = cls.pg_interfaces[i].sw_if_index |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 168 | cls.hosts_by_pg_idx[pg_idx] = [ |
| 169 | Host( |
| 170 | "00:00:00:ff:%02x:%02x" % (pg_idx, j + 1), |
| 171 | "172.17.1%02u.%u" % (pg_idx, j + 1), |
| 172 | ) |
| 173 | for j in range(c) |
| 174 | ] |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 175 | |
| 176 | @classmethod |
| 177 | def bd_if_range(cls, b): |
| 178 | n = cls.ifs_per_bd |
| 179 | start = (b - 1) * n |
| 180 | return range(start, start + n) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 181 | |
| 182 | def create_bd_and_mac_learn(self, count, start=1): |
Jan | 65209ed | 2016-12-05 23:29:17 +0100 | [diff] [blame] | 183 | """ |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 184 | Create required number of bridge domains with MAC learning enabled, |
| 185 | put 3 l2-pg interfaces to every bridge domain and send MAC learning |
| 186 | packets. |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 187 | |
| 188 | :param int count: Number of bridge domains to be created. |
| 189 | :param int start: Starting number of the bridge domain ID. |
| 190 | (Default value = 1) |
| 191 | """ |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 192 | for b in range(start, start + count): |
Laszlo Kiraly | 0f8f435 | 2022-09-16 13:20:07 +0200 | [diff] [blame] | 193 | if b == start: |
| 194 | self.vapi.bridge_domain_add_del_v2( |
| 195 | bd_id=b, flood=1, uu_flood=1, forward=1, learn=1, is_add=1 |
| 196 | ) |
| 197 | bd_id = b |
| 198 | else: |
| 199 | ret = self.vapi.bridge_domain_add_del_v2( |
| 200 | bd_id=0xFFFFFFFF, flood=1, uu_flood=1, forward=1, learn=1, is_add=1 |
| 201 | ) |
| 202 | bd_id = ret.bd_id |
| 203 | self.logger.info("Bridge domain ID %d created" % bd_id) |
| 204 | if self.bd_list.count(bd_id) == 0: |
| 205 | self.bd_map[b] = bd_id |
| 206 | self.bd_list.append(bd_id) |
| 207 | if self.bd_deleted_list.count(bd_id) == 1: |
| 208 | self.bd_deleted_list.remove(bd_id) |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 209 | for j in self.bd_if_range(b): |
| 210 | pg_if = self.pg_interfaces[j] |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 211 | self.vapi.sw_interface_set_l2_bridge( |
Laszlo Kiraly | 0f8f435 | 2022-09-16 13:20:07 +0200 | [diff] [blame] | 212 | rx_sw_if_index=pg_if.sw_if_index, bd_id=bd_id |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 213 | ) |
| 214 | self.logger.info( |
Laszlo Kiraly | 0f8f435 | 2022-09-16 13:20:07 +0200 | [diff] [blame] | 215 | "pg-interface %s added to bridge domain ID %d" % (pg_if.name, bd_id) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 216 | ) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 217 | self.pg_in_bd.append(pg_if) |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 218 | hosts = self.hosts_by_pg_idx[pg_if.sw_if_index] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 219 | packets = [ |
| 220 | Ether(dst="ff:ff:ff:ff:ff:ff", src=host.mac) for host in hosts |
| 221 | ] |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 222 | pg_if.add_stream(packets) |
| 223 | self.logger.info("Sending broadcast eth frames for MAC learning") |
| 224 | self.pg_start() |
| 225 | self.logger.info(self.vapi.ppcli("show bridge-domain")) |
| 226 | self.logger.info(self.vapi.ppcli("show l2fib")) |
| 227 | |
| 228 | def delete_bd(self, count, start=1): |
Jan | 65209ed | 2016-12-05 23:29:17 +0100 | [diff] [blame] | 229 | """ |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 230 | Delete required number of bridge domains. |
| 231 | |
| 232 | :param int count: Number of bridge domains to be created. |
| 233 | :param int start: Starting number of the bridge domain ID. |
| 234 | (Default value = 1) |
| 235 | """ |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 236 | for b in range(start, start + count): |
Laszlo Kiraly | 0f8f435 | 2022-09-16 13:20:07 +0200 | [diff] [blame] | 237 | bd_id = self.bd_map[b] |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 238 | for j in self.bd_if_range(b): |
| 239 | pg_if = self.pg_interfaces[j] |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 240 | self.vapi.sw_interface_set_l2_bridge( |
Laszlo Kiraly | 0f8f435 | 2022-09-16 13:20:07 +0200 | [diff] [blame] | 241 | rx_sw_if_index=pg_if.sw_if_index, bd_id=bd_id, enable=0 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 242 | ) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 243 | self.pg_in_bd.remove(pg_if) |
Laszlo Kiraly | 0f8f435 | 2022-09-16 13:20:07 +0200 | [diff] [blame] | 244 | self.logger.info( |
| 245 | "pg-interface %s removed from bridge domain ID %d" |
| 246 | % (pg_if.name, bd_id) |
| 247 | ) |
| 248 | self.vapi.bridge_domain_add_del_v2(bd_id=bd_id, is_add=0) |
| 249 | self.bd_map.pop(b) |
| 250 | self.bd_list.remove(bd_id) |
| 251 | self.bd_deleted_list.append(bd_id) |
| 252 | self.logger.info("Bridge domain ID %d deleted" % bd_id) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 253 | |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 254 | def create_stream(self, src_if): |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 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 | """ |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 262 | packet_sizes = self.pg_if_packet_sizes |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 263 | pkts = [] |
| 264 | src_hosts = self.hosts_by_pg_idx[src_if.sw_if_index] |
| 265 | for dst_if in self.flows[src_if]: |
| 266 | dst_hosts = self.hosts_by_pg_idx[dst_if.sw_if_index] |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 267 | for dst_host in dst_hosts: |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 268 | pkt_info = self.create_packet_info(src_if, dst_if) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 269 | payload = self.info_to_payload(pkt_info) |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 270 | src_host = random.choice(src_hosts) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 271 | p = ( |
| 272 | Ether(dst=dst_host.mac, src=src_host.mac) |
| 273 | / IP(src=src_host.ip4, dst=dst_host.ip4) |
| 274 | / UDP(sport=1234, dport=1234) |
| 275 | / Raw(payload) |
| 276 | ) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 277 | pkt_info.data = p.copy() |
| 278 | size = random.choice(packet_sizes) |
| 279 | self.extend_packet(p, size) |
| 280 | pkts.append(p) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 281 | self.logger.debug( |
| 282 | "Input stream created for port %s. Length: %u pkt(s)" |
| 283 | % (src_if.name, len(pkts)) |
| 284 | ) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 285 | return pkts |
| 286 | |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 287 | def verify_capture(self, dst_if): |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 288 | """ |
| 289 | Verify captured input packet stream for defined interface. |
| 290 | |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 291 | :param object dst_if: Interface to verify captured packet stream for. |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 292 | """ |
| 293 | last_info = dict() |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 294 | for i in self.flows[dst_if]: |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 295 | last_info[i.sw_if_index] = None |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 296 | dst = dst_if.sw_if_index |
| 297 | for packet in dst_if.get_capture(): |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 298 | try: |
| 299 | ip = packet[IP] |
| 300 | udp = packet[UDP] |
Paul Vinciguerra | eaea421 | 2019-03-06 11:58:06 -0800 | [diff] [blame] | 301 | info = self.payload_to_info(packet[Raw]) |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 302 | self.assertEqual(info.dst, dst) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 303 | self.logger.debug( |
| 304 | "Got packet on port %s: src=%u (id=%u)" |
| 305 | % (dst_if.name, info.src, info.index) |
| 306 | ) |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 307 | last_info[info.src] = self.get_next_packet_info_for_interface2( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 308 | info.src, dst, last_info[info.src] |
| 309 | ) |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 310 | pkt_info = last_info[info.src] |
| 311 | self.assertTrue(pkt_info is not None) |
| 312 | self.assertEqual(info.index, pkt_info.index) |
| 313 | # Check standard fields against saved data in pkt |
| 314 | saved = pkt_info.data |
| 315 | self.assertEqual(ip.src, saved[IP].src) |
| 316 | self.assertEqual(ip.dst, saved[IP].dst) |
| 317 | self.assertEqual(udp.sport, saved[UDP].sport) |
| 318 | self.assertEqual(udp.dport, saved[UDP].dport) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 319 | except: |
Klement Sekera | 9225dee | 2016-12-12 08:36:58 +0100 | [diff] [blame] | 320 | self.logger.error(ppp("Unexpected or invalid packet:", packet)) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 321 | raise |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 322 | s = "" |
| 323 | remaining = 0 |
| 324 | for src in self.flows[dst_if]: |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 325 | remaining_packet = self.get_next_packet_info_for_interface2( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 326 | src.sw_if_index, dst, last_info[src.sw_if_index] |
| 327 | ) |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 328 | if remaining_packet is None: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 329 | s += "Port %u: Packet expected from source %u didn't arrive\n" % ( |
| 330 | dst, |
| 331 | src.sw_if_index, |
| 332 | ) |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 333 | remaining += 1 |
| 334 | self.assertNotEqual(0, remaining, s) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 335 | |
| 336 | def set_bd_flags(self, bd_id, **args): |
| 337 | """ |
| 338 | Enable/disable defined feature(s) of the bridge domain. |
| 339 | |
| 340 | :param int bd_id: Bridge domain ID. |
Jan | 65209ed | 2016-12-05 23:29:17 +0100 | [diff] [blame] | 341 | :param list args: List of feature/status pairs. Allowed features: \ |
| 342 | learn, forward, flood, uu_flood and arp_term. Status False means \ |
| 343 | disable, status True means enable the feature. |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 344 | :raise: ValueError in case of unknown feature in the input. |
| 345 | """ |
| 346 | for flag in args: |
| 347 | if flag == "learn": |
| 348 | feature_bitmap = 1 << 0 |
| 349 | elif flag == "forward": |
| 350 | feature_bitmap = 1 << 1 |
| 351 | elif flag == "flood": |
| 352 | feature_bitmap = 1 << 2 |
| 353 | elif flag == "uu_flood": |
| 354 | feature_bitmap = 1 << 3 |
| 355 | elif flag == "arp_term": |
| 356 | feature_bitmap = 1 << 4 |
| 357 | else: |
| 358 | raise ValueError("Unknown feature used: %s" % flag) |
| 359 | is_set = 1 if args[flag] else 0 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 360 | self.vapi.bridge_flags(bd_id=bd_id, is_set=is_set, flags=feature_bitmap) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 361 | self.logger.info("Bridge domain ID %d updated" % bd_id) |
| 362 | |
| 363 | def verify_bd(self, bd_id, **args): |
| 364 | """ |
| 365 | Check if the bridge domain is configured and verify expected status |
| 366 | of listed features. |
| 367 | |
| 368 | :param int bd_id: Bridge domain ID. |
Jan | 65209ed | 2016-12-05 23:29:17 +0100 | [diff] [blame] | 369 | :param list args: List of feature/status pairs. Allowed features: \ |
| 370 | learn, forward, flood, uu_flood and arp_term. Status False means \ |
| 371 | disable, status True means enable the feature. |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 372 | :return: 1 if bridge domain is configured, otherwise return 0. |
| 373 | :raise: ValueError in case of unknown feature in the input. |
| 374 | """ |
| 375 | bd_dump = self.vapi.bridge_domain_dump(bd_id) |
| 376 | if len(bd_dump) == 0: |
| 377 | self.logger.info("Bridge domain ID %d is not configured" % bd_id) |
| 378 | return 0 |
| 379 | else: |
| 380 | bd_dump = bd_dump[0] |
| 381 | if len(args) > 0: |
| 382 | for flag in args: |
| 383 | expected_status = 1 if args[flag] else 0 |
| 384 | if flag == "learn": |
| 385 | flag_status = bd_dump[6] |
| 386 | elif flag == "forward": |
| 387 | flag_status = bd_dump[5] |
| 388 | elif flag == "flood": |
| 389 | flag_status = bd_dump[3] |
| 390 | elif flag == "uu_flood": |
| 391 | flag_status = bd_dump[4] |
| 392 | elif flag == "arp_term": |
| 393 | flag_status = bd_dump[7] |
| 394 | else: |
| 395 | raise ValueError("Unknown feature used: %s" % flag) |
| 396 | self.assertEqual(expected_status, flag_status) |
| 397 | return 1 |
| 398 | |
| 399 | def run_verify_test(self): |
| 400 | """ |
Matej Klotton | deb6984 | 2016-12-09 15:05:46 +0100 | [diff] [blame] | 401 | Create packet streams for all configured l2-pg interfaces, send all \ |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 402 | prepared packet streams and verify that: |
Matej Klotton | deb6984 | 2016-12-09 15:05:46 +0100 | [diff] [blame] | 403 | - all packets received correctly on all pg-l2 interfaces assigned |
| 404 | to bridge domains |
| 405 | - no packet received on all pg-l2 interfaces not assigned to |
| 406 | bridge domains |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 407 | |
Matej Klotton | deb6984 | 2016-12-09 15:05:46 +0100 | [diff] [blame] | 408 | :raise RuntimeError: if no packet captured on l2-pg interface assigned |
| 409 | to the bridge domain or if any packet is captured |
| 410 | on l2-pg interface not assigned to the bridge |
| 411 | domain. |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 412 | """ |
| 413 | # Test |
| 414 | # Create incoming packet streams for packet-generator interfaces |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 415 | # for pg_if in self.pg_interfaces: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 416 | assert len(self._packet_count_for_dst_if_idx) == 0 |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 417 | for pg_if in self.pg_in_bd: |
| 418 | pkts = self.create_stream(pg_if) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 419 | pg_if.add_stream(pkts) |
| 420 | |
| 421 | # Enable packet capture and start packet sending |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 422 | self.pg_enable_capture(self.pg_in_bd) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 423 | self.pg_start() |
| 424 | |
| 425 | # Verify |
| 426 | # Verify outgoing packet streams per packet-generator interface |
Eyal Bari | c83c8ed | 2017-05-10 16:08:19 +0300 | [diff] [blame] | 427 | for pg_if in self.pg_in_bd: |
| 428 | self.verify_capture(pg_if) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 429 | |
| 430 | def test_l2bd_inst_01(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 431 | """L2BD Multi-instance test 1 - create 5 BDs""" |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 432 | # Config 1 |
| 433 | # Create 5 BDs, put interfaces to these BDs and send MAC learning |
| 434 | # packets |
| 435 | self.create_bd_and_mac_learn(5) |
| 436 | |
| 437 | # Verify 1 |
| 438 | for bd_id in self.bd_list: |
| 439 | self.assertEqual(self.verify_bd(bd_id), 1) |
| 440 | |
| 441 | # Test 1 |
| 442 | # self.vapi.cli("clear trace") |
| 443 | self.run_verify_test() |
Paul Vinciguerra | 548d5ee | 2019-12-16 20:56:00 -0500 | [diff] [blame] | 444 | self.delete_bd(5) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 445 | |
| 446 | def test_l2bd_inst_02(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 447 | """L2BD Multi-instance test 2 - update data of 5 BDs""" |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 448 | # Config 2 |
| 449 | # Update data of 5 BDs (disable learn, forward, flood, uu-flood) |
Paul Vinciguerra | 548d5ee | 2019-12-16 20:56:00 -0500 | [diff] [blame] | 450 | self.create_bd_and_mac_learn(5) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 451 | self.set_bd_flags( |
| 452 | self.bd_list[0], learn=False, forward=False, flood=False, uu_flood=False |
| 453 | ) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 454 | self.set_bd_flags(self.bd_list[1], forward=False) |
| 455 | self.set_bd_flags(self.bd_list[2], flood=False) |
| 456 | self.set_bd_flags(self.bd_list[3], uu_flood=False) |
| 457 | self.set_bd_flags(self.bd_list[4], learn=False) |
| 458 | |
| 459 | # Verify 2 |
| 460 | # Skipping check of uu_flood as it is not returned by |
| 461 | # bridge_domain_dump api command |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 462 | self.verify_bd( |
| 463 | self.bd_list[0], learn=False, forward=False, flood=False, uu_flood=False |
| 464 | ) |
| 465 | self.verify_bd( |
| 466 | self.bd_list[1], learn=True, forward=False, flood=True, uu_flood=True |
| 467 | ) |
| 468 | self.verify_bd( |
| 469 | self.bd_list[2], learn=True, forward=True, flood=False, uu_flood=True |
| 470 | ) |
| 471 | self.verify_bd( |
| 472 | self.bd_list[3], learn=True, forward=True, flood=True, uu_flood=False |
| 473 | ) |
| 474 | self.verify_bd( |
| 475 | self.bd_list[4], learn=False, forward=True, flood=True, uu_flood=True |
| 476 | ) |
Paul Vinciguerra | 548d5ee | 2019-12-16 20:56:00 -0500 | [diff] [blame] | 477 | self.delete_bd(5) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 478 | |
Eyal Bari | 31a71ab | 2017-06-25 14:42:33 +0300 | [diff] [blame] | 479 | def test_l2bd_inst_03(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 480 | """L2BD Multi-instance test 3 - delete 2 BDs""" |
Eyal Bari | 31a71ab | 2017-06-25 14:42:33 +0300 | [diff] [blame] | 481 | # Config 3 |
| 482 | # Delete 2 BDs |
Paul Vinciguerra | 548d5ee | 2019-12-16 20:56:00 -0500 | [diff] [blame] | 483 | self.create_bd_and_mac_learn(5) |
Eyal Bari | 31a71ab | 2017-06-25 14:42:33 +0300 | [diff] [blame] | 484 | self.delete_bd(2) |
| 485 | |
| 486 | # Verify 3 |
| 487 | for bd_id in self.bd_deleted_list: |
| 488 | self.assertEqual(self.verify_bd(bd_id), 0) |
| 489 | for bd_id in self.bd_list: |
| 490 | self.assertEqual(self.verify_bd(bd_id), 1) |
| 491 | |
| 492 | # Test 3 |
| 493 | self.run_verify_test() |
Paul Vinciguerra | 548d5ee | 2019-12-16 20:56:00 -0500 | [diff] [blame] | 494 | self.delete_bd(3, 3) |
Eyal Bari | 31a71ab | 2017-06-25 14:42:33 +0300 | [diff] [blame] | 495 | |
| 496 | def test_l2bd_inst_04(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 497 | """L2BD Multi-instance test 4 - add 2 BDs""" |
Eyal Bari | 31a71ab | 2017-06-25 14:42:33 +0300 | [diff] [blame] | 498 | # Config 4 |
| 499 | # Create 5 BDs, put interfaces to these BDs and send MAC learning |
| 500 | # packets |
| 501 | self.create_bd_and_mac_learn(2) |
| 502 | |
| 503 | # Verify 4 |
| 504 | for bd_id in self.bd_list: |
| 505 | self.assertEqual(self.verify_bd(bd_id), 1) |
| 506 | |
| 507 | # Test 4 |
| 508 | # self.vapi.cli("clear trace") |
| 509 | self.run_verify_test() |
Paul Vinciguerra | 548d5ee | 2019-12-16 20:56:00 -0500 | [diff] [blame] | 510 | self.delete_bd(2) |
Eyal Bari | 31a71ab | 2017-06-25 14:42:33 +0300 | [diff] [blame] | 511 | |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 512 | def test_l2bd_inst_05(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 513 | """L2BD Multi-instance test 5 - delete 5 BDs""" |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 514 | # Config 5 |
| 515 | # Delete 5 BDs |
Paul Vinciguerra | 548d5ee | 2019-12-16 20:56:00 -0500 | [diff] [blame] | 516 | self.create_bd_and_mac_learn(5) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 517 | self.delete_bd(5) |
| 518 | |
| 519 | # Verify 5 |
| 520 | for bd_id in self.bd_deleted_list: |
| 521 | self.assertEqual(self.verify_bd(bd_id), 0) |
| 522 | for bd_id in self.bd_list: |
| 523 | self.assertEqual(self.verify_bd(bd_id), 1) |
| 524 | |
| 525 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 526 | if __name__ == "__main__": |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 527 | unittest.main(testRunner=VppTestRunner) |