Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 2 | """L2 FIB Test Case HLD: |
| 3 | |
| 4 | **config 1** |
| 5 | - add 4 pg-l2 interfaces |
| 6 | - configure them into l2bd |
| 7 | - configure 100 MAC entries in L2 fib - 25 MACs per interface |
| 8 | - L2 MAC learning and unknown unicast flooding disabled in l2bd |
| 9 | - configure 100 MAC entries in L2 fib - 25 MACs per interface |
| 10 | |
| 11 | **test 1** |
| 12 | - send L2 MAC frames between all 4 pg-l2 interfaces for all of 100 MAC \ |
| 13 | entries in the FIB |
| 14 | |
| 15 | **verify 1** |
| 16 | - all packets received correctly |
| 17 | |
| 18 | **config 2** |
| 19 | - delete 12 MAC entries - 3 MACs per interface |
| 20 | |
| 21 | **test 2a** |
| 22 | - send L2 MAC frames between all 4 pg-l2 interfaces for non-deleted MAC \ |
| 23 | entries |
| 24 | |
| 25 | **verify 2a** |
| 26 | - all packets received correctly |
| 27 | |
| 28 | **test 2b** |
| 29 | - send L2 MAC frames between all 4 pg-l2 interfaces for all of 12 deleted \ |
| 30 | MAC entries |
| 31 | |
| 32 | **verify 2b** |
| 33 | - no packet received on all 4 pg-l2 interfaces |
| 34 | |
| 35 | **config 3** |
| 36 | - configure new 100 MAC entries in L2 fib - 25 MACs per interface |
| 37 | |
| 38 | **test 3** |
| 39 | - send L2 MAC frames between all 4 pg-l2 interfaces for all of 188 MAC \ |
| 40 | entries in the FIB |
| 41 | |
| 42 | **verify 3** |
| 43 | - all packets received correctly |
| 44 | |
| 45 | **config 4** |
| 46 | - delete 160 MAC entries, 40 MACs per interface |
| 47 | |
| 48 | **test 4a** |
| 49 | - send L2 MAC frames between all 4 pg-l2 interfaces for all of 28 \ |
| 50 | non-deleted MAC entries |
| 51 | |
| 52 | **verify 4a** |
| 53 | - all packets received correctly |
| 54 | |
| 55 | **test 4b** |
| 56 | - try send L2 MAC frames between all 4 pg-l2 interfaces for all of 172 \ |
| 57 | deleted MAC entries |
| 58 | |
| 59 | **verify 4b** |
| 60 | - no packet received on all 4 pg-l2 interfaces |
| 61 | """ |
| 62 | |
| 63 | import unittest |
| 64 | import random |
| 65 | |
| 66 | from scapy.packet import Raw |
| 67 | from scapy.layers.l2 import Ether |
| 68 | from scapy.layers.inet import IP, UDP |
| 69 | |
| 70 | from framework import VppTestCase, VppTestRunner |
Klement Sekera | 9225dee | 2016-12-12 08:36:58 +0100 | [diff] [blame] | 71 | from util import Host, ppp |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 72 | from vpp_papi import mac_pton, VppEnum |
John Lo | e23c99e | 2018-03-13 21:53:18 -0400 | [diff] [blame] | 73 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 74 | |
| 75 | class TestL2fib(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 76 | """L2 FIB Test Case""" |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 77 | |
| 78 | @classmethod |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 79 | def bd_ifs(cls, bd_id): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 80 | return range((bd_id - 1) * cls.n_ifs_per_bd, bd_id * cls.n_ifs_per_bd - 1) |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 81 | |
| 82 | @classmethod |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 83 | def setUpClass(cls): |
| 84 | """ |
| 85 | Perform standard class setup (defined by class method setUpClass in |
| 86 | class VppTestCase) before running the test case, set test case related |
| 87 | variables and configure VPP. |
| 88 | |
| 89 | :var int bd_id: Bridge domain ID. |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 90 | """ |
| 91 | super(TestL2fib, cls).setUpClass() |
| 92 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 93 | try: |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 94 | n_brs = cls.n_brs = range(1, 3) |
| 95 | cls.n_ifs_per_bd = 4 |
| 96 | n_ifs = range(cls.n_ifs_per_bd * len(cls.n_brs)) |
Pavel Kotucek | 7303ee8 | 2018-11-21 13:20:41 +0100 | [diff] [blame] | 97 | # Create pg interfaces |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 98 | cls.create_pg_interfaces(n_ifs) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 99 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 100 | cls.flows = dict() |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 101 | for bd_id in n_brs: |
| 102 | # Packet flows mapping pg0 -> pg1, pg2, pg3 etc. |
| 103 | ifs = cls.bd_ifs(bd_id) |
| 104 | for j in ifs: |
| 105 | cls.flows[cls.pg_interfaces[j]] = [ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 106 | cls.pg_interfaces[x] for x in ifs if x != j |
| 107 | ] |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 108 | |
| 109 | # Packet sizes |
| 110 | cls.pg_if_packet_sizes = [64, 512, 1518, 9018] |
| 111 | |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 112 | for bd_id in n_brs: |
| 113 | # Create BD with MAC learning and unknown unicast flooding |
| 114 | # disabled and put interfaces to this BD |
Laszlo Kiraly | 0f8f435 | 2022-09-16 13:20:07 +0200 | [diff] [blame] | 115 | cls.vapi.bridge_domain_add_del_v2( |
| 116 | bd_id=bd_id, is_add=1, uu_flood=0, learn=0, flood=1, forward=1 |
| 117 | ) |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 118 | ifs = [cls.pg_interfaces[i] for i in cls.bd_ifs(bd_id)] |
| 119 | for pg_if in ifs: |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 120 | cls.vapi.sw_interface_set_l2_bridge( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 121 | rx_sw_if_index=pg_if.sw_if_index, bd_id=bd_id |
| 122 | ) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 123 | |
| 124 | # Set up all interfaces |
| 125 | for i in cls.pg_interfaces: |
| 126 | i.admin_up() |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 127 | except Exception: |
| 128 | super(TestL2fib, cls).tearDownClass() |
| 129 | raise |
| 130 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 131 | @classmethod |
| 132 | def tearDownClass(cls): |
| 133 | super(TestL2fib, cls).tearDownClass() |
| 134 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 135 | def setUp(self): |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 136 | super(TestL2fib, self).setUp() |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 137 | self.reset_packet_infos() |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 138 | |
| 139 | def tearDown(self): |
| 140 | """ |
| 141 | Show various debug prints after each test. |
| 142 | """ |
| 143 | super(TestL2fib, self).tearDown() |
| 144 | if not self.vpp_dead: |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 145 | for bd_id in self.n_brs: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 146 | self.logger.info( |
| 147 | self.vapi.ppcli("show bridge-domain %s detail" % bd_id) |
| 148 | ) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 149 | |
Paul Vinciguerra | 90cf21b | 2019-03-13 09:23:05 -0700 | [diff] [blame] | 150 | def show_commands_at_teardown(self): |
| 151 | self.logger.info(self.vapi.ppcli("show l2fib verbose")) |
| 152 | |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 153 | def create_hosts(self, n_hosts_per_if, subnet): |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 154 | """ |
| 155 | Create required number of host MAC addresses and distribute them among |
| 156 | interfaces. Create host IPv4 address for every host MAC address. |
| 157 | |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 158 | :param int n_hosts_per_if: Number of per interface hosts to |
Dave Wallace | d170681 | 2021-08-12 18:36:02 -0400 | [diff] [blame] | 159 | create MAC/IPv4 addresses for. |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 160 | """ |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 161 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 162 | hosts = dict() |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 163 | for pg_if in self.pg_interfaces: |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 164 | swif = pg_if.sw_if_index |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 165 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 166 | def mac(j): |
| 167 | return "00:00:%02x:ff:%02x:%02x" % (subnet, swif, j) |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 168 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 169 | def ip(j): |
| 170 | return "172.%02u.1%02x.%u" % (subnet, swif, j) |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 171 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 172 | def h(j): |
| 173 | return Host(mac(j), ip(j)) |
| 174 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 175 | hosts[swif] = [h(j) for j in range(n_hosts_per_if)] |
| 176 | return hosts |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 177 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 178 | def split_hosts(self, hosts, n): |
| 179 | splits = dict() |
| 180 | for pg_if in self.pg_interfaces: |
| 181 | swif = pg_if.sw_if_index |
| 182 | splits[swif] = hosts[swif][:n] |
| 183 | hosts[swif] = hosts[swif][n:] |
| 184 | return splits |
| 185 | |
| 186 | def learn_hosts(self, bd_id, hosts): |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 187 | """ |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 188 | Create and send per interface L2 MAC broadcast packet stream to |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 189 | let the bridge domain learn these MAC addresses. |
| 190 | |
| 191 | :param int bd_id: BD to teach |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 192 | :param dict hosts: dict of hosts per interface |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 193 | """ |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 194 | self.vapi.bridge_flags(bd_id=bd_id, is_set=1, flags=1) |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 195 | ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)] |
| 196 | for pg_if in ifs: |
| 197 | swif = pg_if.sw_if_index |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 198 | packets = [ |
| 199 | Ether(dst="ff:ff:ff:ff:ff:ff", src=host.mac) for host in hosts[swif] |
| 200 | ] |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 201 | pg_if.add_stream(packets) |
| 202 | self.logger.info("Sending broadcast eth frames for MAC learning") |
| 203 | self.pg_start() |
| 204 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 205 | def config_l2_fib_entries(self, bd_id, hosts): |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 206 | """ |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 207 | Config required number of L2 FIB entries. |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 208 | |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 209 | :param int bd_id: BD's id |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 210 | :param int count: Number of L2 FIB entries to be created. |
| 211 | :param int start: Starting index of the host list. (Default value = 0) |
| 212 | """ |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 213 | ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)] |
| 214 | for pg_if in ifs: |
| 215 | swif = pg_if.sw_if_index |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 216 | for host in hosts[swif]: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 217 | self.vapi.l2fib_add_del(mac_pton(host.mac), bd_id, swif, static_mac=1) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 218 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 219 | def delete_l2_fib_entry(self, bd_id, hosts): |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 220 | """ |
| 221 | Delete required number of L2 FIB entries. |
| 222 | |
| 223 | :param int count: Number of L2 FIB entries to be created. |
| 224 | """ |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 225 | ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)] |
| 226 | for pg_if in ifs: |
| 227 | swif = pg_if.sw_if_index |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 228 | for host in hosts[swif]: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 229 | self.vapi.l2fib_add_del(mac_pton(host.mac), bd_id, swif, is_add=0) |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 230 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 231 | def flush_int(self, swif, learned_hosts): |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 232 | """ |
| 233 | Flush swif L2 FIB entries. |
| 234 | |
| 235 | :param int swif: sw if index. |
| 236 | """ |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 237 | flushed = dict() |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 238 | self.vapi.l2fib_flush_int(swif) |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 239 | flushed[swif] = learned_hosts[swif] |
| 240 | learned_hosts[swif] = [] |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 241 | return flushed |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 242 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 243 | def flush_bd(self, bd_id, learned_hosts): |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 244 | """ |
| 245 | Flush bd_id L2 FIB entries. |
| 246 | |
| 247 | :param int bd_id: Bridge Domain id. |
| 248 | """ |
| 249 | self.vapi.l2fib_flush_bd(bd_id) |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 250 | flushed = dict() |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 251 | ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)] |
| 252 | for pg_if in ifs: |
| 253 | swif = pg_if.sw_if_index |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 254 | flushed[swif] = learned_hosts[swif] |
| 255 | learned_hosts[swif] = [] |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 256 | return flushed |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 257 | |
| 258 | def flush_all(self): |
| 259 | """ |
| 260 | Flush All L2 FIB entries. |
| 261 | """ |
| 262 | self.vapi.l2fib_flush_all() |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 263 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 264 | def create_stream(self, src_if, packet_sizes, if_src_hosts, if_dst_hosts): |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 265 | """ |
| 266 | Create input packet stream for defined interface using hosts or |
| 267 | deleted_hosts list. |
| 268 | |
| 269 | :param object src_if: Interface to create packet stream for. |
| 270 | :param list packet_sizes: List of required packet sizes. |
| 271 | :param boolean deleted: Set to True if deleted_hosts list required. |
| 272 | :return: Stream of packets. |
| 273 | """ |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 274 | src_hosts = if_src_hosts[src_if.sw_if_index] |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 275 | if not src_hosts: |
| 276 | return [] |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 277 | pkts = [] |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 278 | for dst_if in self.flows[src_if]: |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 279 | dst_swif = dst_if.sw_if_index |
| 280 | if dst_swif not in if_dst_hosts: |
| 281 | continue |
| 282 | dst_hosts = if_dst_hosts[dst_swif] |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 283 | for dst_host in dst_hosts: |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 284 | src_host = random.choice(src_hosts) |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 285 | pkt_info = self.create_packet_info(src_if, dst_if) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 286 | payload = self.info_to_payload(pkt_info) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 287 | p = ( |
| 288 | Ether(dst=dst_host.mac, src=src_host.mac) |
| 289 | / IP(src=src_host.ip4, dst=dst_host.ip4) |
| 290 | / UDP(sport=1234, dport=1234) |
| 291 | / Raw(payload) |
| 292 | ) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 293 | pkt_info.data = p.copy() |
| 294 | size = random.choice(packet_sizes) |
| 295 | self.extend_packet(p, size) |
| 296 | pkts.append(p) |
| 297 | return pkts |
| 298 | |
| 299 | def verify_capture(self, pg_if, capture): |
| 300 | """ |
| 301 | Verify captured input packet stream for defined interface. |
| 302 | |
| 303 | :param object pg_if: Interface to verify captured packet stream for. |
| 304 | :param list capture: Captured packet stream. |
| 305 | """ |
| 306 | last_info = dict() |
| 307 | for i in self.pg_interfaces: |
| 308 | last_info[i.sw_if_index] = None |
| 309 | dst_sw_if_index = pg_if.sw_if_index |
| 310 | for packet in capture: |
Paul Vinciguerra | eaea421 | 2019-03-06 11:58:06 -0800 | [diff] [blame] | 311 | payload_info = self.payload_to_info(packet[Raw]) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 312 | try: |
| 313 | ip = packet[IP] |
| 314 | udp = packet[UDP] |
| 315 | packet_index = payload_info.index |
| 316 | self.assertEqual(payload_info.dst, dst_sw_if_index) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 317 | self.logger.debug( |
| 318 | "Got packet on port %s: src=%u (id=%u)" |
| 319 | % (pg_if.name, payload_info.src, packet_index) |
| 320 | ) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 321 | next_info = self.get_next_packet_info_for_interface2( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 322 | payload_info.src, dst_sw_if_index, last_info[payload_info.src] |
| 323 | ) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 324 | last_info[payload_info.src] = next_info |
| 325 | self.assertTrue(next_info is not None) |
| 326 | self.assertEqual(packet_index, next_info.index) |
| 327 | saved_packet = next_info.data |
| 328 | # Check standard fields |
| 329 | self.assertEqual(ip.src, saved_packet[IP].src) |
| 330 | self.assertEqual(ip.dst, saved_packet[IP].dst) |
| 331 | self.assertEqual(udp.sport, saved_packet[UDP].sport) |
| 332 | self.assertEqual(udp.dport, saved_packet[UDP].dport) |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 333 | except BaseException: |
Klement Sekera | 9225dee | 2016-12-12 08:36:58 +0100 | [diff] [blame] | 334 | self.logger.error(ppp("Unexpected or invalid packet:", packet)) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 335 | raise |
| 336 | for i in self.pg_interfaces: |
| 337 | remaining_packet = self.get_next_packet_info_for_interface2( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 338 | i, dst_sw_if_index, last_info[i.sw_if_index] |
| 339 | ) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 340 | self.assertTrue( |
| 341 | remaining_packet is None, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 342 | "Port %u: Packet expected from source %u didn't arrive" |
| 343 | % (dst_sw_if_index, i.sw_if_index), |
| 344 | ) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 345 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 346 | def run_verify_test(self, bd_id, src_hosts, dst_hosts): |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 347 | # Test |
| 348 | # Create incoming packet streams for packet-generator interfaces |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 349 | self.reset_packet_infos() |
| 350 | ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)] |
| 351 | for i in ifs: |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 352 | pkts = self.create_stream( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 353 | i, |
| 354 | self.pg_if_packet_sizes, |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 355 | if_src_hosts=src_hosts, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 356 | if_dst_hosts=dst_hosts, |
| 357 | ) |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 358 | if pkts: |
| 359 | i.add_stream(pkts) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 360 | |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 361 | self.vapi.bridge_flags(bd_id=bd_id, is_set=0, flags=1) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 362 | # Enable packet capture and start packet sending |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 363 | self.pg_enable_capture(ifs) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 364 | self.pg_start() |
| 365 | |
| 366 | # Verify |
| 367 | # Verify outgoing packet streams per packet-generator interface |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 368 | for i in ifs: |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 369 | if not dst_hosts[i.sw_if_index]: |
| 370 | continue |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 371 | capture = i.get_capture() |
| 372 | self.logger.info("Verifying capture on interface %s" % i.name) |
| 373 | self.verify_capture(i, capture) |
| 374 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 375 | def run_verify_negat_test(self, bd_id, src_hosts, dst_hosts): |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 376 | # Test |
| 377 | # Create incoming packet streams for packet-generator interfaces for |
| 378 | # deleted MAC addresses |
Klement Sekera | dab231a | 2016-12-21 08:50:14 +0100 | [diff] [blame] | 379 | self.reset_packet_infos() |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 380 | ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)] |
| 381 | for i in ifs: |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 382 | pkts = self.create_stream( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 383 | i, |
| 384 | self.pg_if_packet_sizes, |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 385 | if_src_hosts=src_hosts, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 386 | if_dst_hosts=dst_hosts, |
| 387 | ) |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 388 | if pkts: |
| 389 | i.add_stream(pkts) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 390 | |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 391 | self.vapi.bridge_flags(bd_id=bd_id, is_set=0, flags=1) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 392 | # Enable packet capture and start packet sending |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 393 | self.pg_enable_capture(ifs) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 394 | self.pg_start() |
| 395 | |
| 396 | # Verify |
| 397 | # Verify outgoing packet streams per packet-generator interface |
Neale Ranns | 4b8d3be | 2017-05-22 02:46:01 -0700 | [diff] [blame] | 398 | timeout = 1 |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 399 | for i in ifs: |
Neale Ranns | 4b8d3be | 2017-05-22 02:46:01 -0700 | [diff] [blame] | 400 | i.get_capture(0, timeout=timeout) |
Klement Sekera | 9225dee | 2016-12-12 08:36:58 +0100 | [diff] [blame] | 401 | i.assert_nothing_captured(remark="outgoing interface") |
Neale Ranns | 4b8d3be | 2017-05-22 02:46:01 -0700 | [diff] [blame] | 402 | timeout = 0.1 |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 403 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 404 | def test_l2_fib_program100(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 405 | """L2 FIB - program 100 MACs""" |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 406 | bd_id = 1 |
| 407 | hosts = self.create_hosts(100, subnet=17) |
| 408 | self.config_l2_fib_entries(bd_id, hosts) |
| 409 | self.run_verify_test(bd_id, hosts, hosts) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 410 | |
Pavel Kotucek | 7303ee8 | 2018-11-21 13:20:41 +0100 | [diff] [blame] | 411 | def test_l2_fib_program100_delete12(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 412 | """L2 FIB - program 100, delete 12 MACs""" |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 413 | bd_id = 1 |
| 414 | hosts = self.create_hosts(100, subnet=17) |
| 415 | self.config_l2_fib_entries(bd_id, hosts) |
| 416 | del_hosts = self.split_hosts(hosts, 12) |
| 417 | self.delete_l2_fib_entry(bd_id, del_hosts) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 418 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 419 | self.run_verify_test(bd_id, hosts, hosts) |
| 420 | self.run_verify_negat_test(bd_id, hosts, del_hosts) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 421 | |
Pavel Kotucek | 7303ee8 | 2018-11-21 13:20:41 +0100 | [diff] [blame] | 422 | def test_l2_fib_program100_add100(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 423 | """L2 FIB - program 100, add 100 MACs""" |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 424 | bd_id = 1 |
| 425 | hosts = self.create_hosts(100, subnet=17) |
| 426 | self.config_l2_fib_entries(bd_id, hosts) |
| 427 | hosts2 = self.create_hosts(100, subnet=22) |
| 428 | self.config_l2_fib_entries(bd_id, hosts2) |
| 429 | self.run_verify_test(bd_id, hosts, hosts2) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 430 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 431 | def test_l2_fib_program10_learn10(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 432 | """L2 FIB - program 10 MACs, learn 10""" |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 433 | hosts = self.create_hosts(20, subnet=35) |
| 434 | lhosts = self.split_hosts(hosts, 10) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 435 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 436 | bd1 = 1 |
| 437 | bd2 = 2 |
| 438 | self.learn_hosts(bd1, lhosts) |
| 439 | self.learn_hosts(bd2, lhosts) |
| 440 | self.config_l2_fib_entries(bd1, hosts) |
| 441 | self.config_l2_fib_entries(bd2, hosts) |
| 442 | self.run_verify_test(bd1, lhosts, hosts) |
| 443 | self.run_verify_test(bd2, lhosts, hosts) |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 444 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 445 | def test_l2_fib_flush_int(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 446 | """L2 FIB - flush interface""" |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 447 | hosts = self.create_hosts(20, subnet=36) |
| 448 | lhosts = self.split_hosts(hosts, 10) |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 449 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 450 | bd1 = 1 |
| 451 | self.learn_hosts(bd1, lhosts) |
| 452 | self.config_l2_fib_entries(bd1, hosts) |
| 453 | self.run_verify_test(bd1, lhosts, hosts) |
| 454 | flushed = self.flush_int(self.pg_interfaces[0].sw_if_index, lhosts) |
| 455 | self.run_verify_test(bd1, hosts, lhosts) |
| 456 | self.run_verify_negat_test(bd1, hosts, flushed) |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 457 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 458 | def test_l2_fib_flush_bd(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 459 | """L2 FIB - flush BD""" |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 460 | hosts = self.create_hosts(20, subnet=37) |
| 461 | lhosts = self.split_hosts(hosts, 10) |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 462 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 463 | bd1 = 1 |
| 464 | self.learn_hosts(bd1, lhosts) |
| 465 | self.config_l2_fib_entries(bd1, hosts) |
| 466 | self.run_verify_test(bd1, lhosts, hosts) |
| 467 | flushed = self.flush_bd(bd1, lhosts) |
| 468 | self.run_verify_negat_test(bd1, hosts, flushed) |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 469 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 470 | def test_l2_fib_flush_all(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 471 | """L2 FIB - flush all""" |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 472 | hosts = self.create_hosts(20, subnet=38) |
| 473 | lhosts = self.split_hosts(hosts, 10) |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 474 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 475 | bd1 = 1 |
| 476 | bd2 = 2 |
| 477 | self.learn_hosts(bd1, lhosts) |
| 478 | self.learn_hosts(bd2, lhosts) |
| 479 | self.config_l2_fib_entries(bd1, hosts) |
| 480 | self.config_l2_fib_entries(bd2, hosts) |
| 481 | self.run_verify_test(bd1, hosts, lhosts) |
| 482 | self.run_verify_test(bd2, hosts, lhosts) |
Eyal Bari | 521202b | 2017-05-24 10:11:20 +0300 | [diff] [blame] | 483 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 484 | self.flush_all() |
| 485 | |
| 486 | self.run_verify_negat_test(bd1, hosts, lhosts) |
| 487 | self.run_verify_negat_test(bd2, hosts, lhosts) |
| 488 | |
| 489 | def test_l2_fib_mac_learn_evs(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 490 | """L2 FIB - mac learning events""" |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 491 | bd1 = 1 |
| 492 | hosts = self.create_hosts(10, subnet=39) |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 493 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 494 | self.vapi.want_l2_macs_events() |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 495 | self.learn_hosts(bd1, hosts) |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 496 | |
Benoît Ganne | 56eccdb | 2021-08-20 09:18:31 +0200 | [diff] [blame] | 497 | self.virtual_sleep(1) |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 498 | self.logger.info(self.vapi.ppcli("show l2fib")) |
| 499 | evs = self.vapi.collect_events() |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 500 | action = VppEnum.vl_api_mac_event_action_t.MAC_EVENT_ACTION_API_ADD |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 501 | learned_macs = { |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 502 | e.mac[i].mac_addr.packed |
| 503 | for e in evs |
| 504 | for i in range(e.n_macs) |
| 505 | if e.mac[i].action == action |
| 506 | } |
| 507 | macs = { |
| 508 | h.bin_mac |
| 509 | for swif in self.bd_ifs(bd1) |
| 510 | for h in hosts[self.pg_interfaces[swif].sw_if_index] |
| 511 | } |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 512 | self.vapi.want_l2_macs_events(enable_disable=0) |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 513 | self.assertEqual(len(learned_macs ^ macs), 0) |
| 514 | |
Jerome Tollet | 0f8d100 | 2021-01-07 12:44:17 +0100 | [diff] [blame] | 515 | def test_l2_fib_mac_learn_evs2(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 516 | """L2 FIB - mac learning events using want_l2_macs_events2""" |
Jerome Tollet | 0f8d100 | 2021-01-07 12:44:17 +0100 | [diff] [blame] | 517 | bd1 = 1 |
| 518 | hosts = self.create_hosts(10, subnet=39) |
| 519 | |
| 520 | self.vapi.l2fib_set_scan_delay(scan_delay=10) |
| 521 | self.vapi.want_l2_macs_events2() |
| 522 | self.sleep(1) |
| 523 | self.learn_hosts(bd1, hosts) |
| 524 | |
Benoît Ganne | 56eccdb | 2021-08-20 09:18:31 +0200 | [diff] [blame] | 525 | self.virtual_sleep(1) |
Jerome Tollet | 0f8d100 | 2021-01-07 12:44:17 +0100 | [diff] [blame] | 526 | self.logger.info(self.vapi.ppcli("show l2fib")) |
| 527 | evs = self.vapi.collect_events() |
| 528 | action = VppEnum.vl_api_mac_event_action_t.MAC_EVENT_ACTION_API_ADD |
| 529 | learned_macs = { |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 530 | e.mac[i].mac_addr.packed |
| 531 | for e in evs |
| 532 | for i in range(e.n_macs) |
| 533 | if e.mac[i].action == action |
| 534 | } |
| 535 | macs = { |
| 536 | h.bin_mac |
| 537 | for swif in self.bd_ifs(bd1) |
| 538 | for h in hosts[self.pg_interfaces[swif].sw_if_index] |
| 539 | } |
Jerome Tollet | 0f8d100 | 2021-01-07 12:44:17 +0100 | [diff] [blame] | 540 | self.vapi.want_l2_macs_events2(enable_disable=0) |
| 541 | self.assertEqual(len(learned_macs ^ macs), 0) |
| 542 | |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 543 | def test_l2_fib_macs_learn_max(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 544 | """L2 FIB - mac learning max macs in event""" |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 545 | bd1 = 1 |
| 546 | hosts = self.create_hosts(10, subnet=40) |
eyal bari | c6038c9 | 2017-10-03 12:25:07 +0300 | [diff] [blame] | 547 | |
| 548 | ev_macs = 1 |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 549 | self.vapi.want_l2_macs_events(max_macs_in_event=ev_macs) |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 550 | self.learn_hosts(bd1, hosts) |
eyal bari | c6038c9 | 2017-10-03 12:25:07 +0300 | [diff] [blame] | 551 | |
| 552 | self.sleep(1) |
| 553 | self.logger.info(self.vapi.ppcli("show l2fib")) |
| 554 | evs = self.vapi.collect_events() |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 555 | self.vapi.want_l2_macs_events(enable_disable=0) |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 556 | |
| 557 | self.assertGreater(len(evs), 0) |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 558 | action = VppEnum.vl_api_mac_event_action_t.MAC_EVENT_ACTION_API_ADD |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 559 | learned_macs = { |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 560 | e.mac[i].mac_addr.packed |
| 561 | for e in evs |
| 562 | for i in range(e.n_macs) |
| 563 | if e.mac[i].action == action |
| 564 | } |
| 565 | macs = { |
| 566 | h.bin_mac |
| 567 | for swif in self.bd_ifs(bd1) |
| 568 | for h in hosts[self.pg_interfaces[swif].sw_if_index] |
| 569 | } |
Eyal Bari | 755b140 | 2017-10-08 15:53:34 +0300 | [diff] [blame] | 570 | |
eyal bari | c6038c9 | 2017-10-03 12:25:07 +0300 | [diff] [blame] | 571 | for e in evs: |
| 572 | self.assertLess(len(e), ev_macs * 10) |
| 573 | self.assertEqual(len(learned_macs ^ macs), 0) |
| 574 | |
Jerome Tollet | 0f8d100 | 2021-01-07 12:44:17 +0100 | [diff] [blame] | 575 | def test_l2_fib_macs_learn_max2(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 576 | """L2 FIB - mac learning max macs in event using want_l2_macs_events2""" |
Jerome Tollet | 0f8d100 | 2021-01-07 12:44:17 +0100 | [diff] [blame] | 577 | bd1 = 1 |
| 578 | hosts = self.create_hosts(10, subnet=40) |
| 579 | |
| 580 | ev_macs = 1 |
| 581 | self.vapi.l2fib_set_scan_delay(scan_delay=10) |
| 582 | self.vapi.want_l2_macs_events2(max_macs_in_event=ev_macs) |
| 583 | self.sleep(1) |
| 584 | self.learn_hosts(bd1, hosts) |
| 585 | |
Benoît Ganne | 56eccdb | 2021-08-20 09:18:31 +0200 | [diff] [blame] | 586 | self.virtual_sleep(1) |
Jerome Tollet | 0f8d100 | 2021-01-07 12:44:17 +0100 | [diff] [blame] | 587 | self.logger.info(self.vapi.ppcli("show l2fib")) |
| 588 | evs = self.vapi.collect_events() |
| 589 | self.vapi.want_l2_macs_events2(enable_disable=0) |
| 590 | |
| 591 | self.assertGreater(len(evs), 0) |
| 592 | action = VppEnum.vl_api_mac_event_action_t.MAC_EVENT_ACTION_API_ADD |
| 593 | learned_macs = { |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 594 | e.mac[i].mac_addr.packed |
| 595 | for e in evs |
| 596 | for i in range(e.n_macs) |
| 597 | if e.mac[i].action == action |
| 598 | } |
| 599 | macs = { |
| 600 | h.bin_mac |
| 601 | for swif in self.bd_ifs(bd1) |
| 602 | for h in hosts[self.pg_interfaces[swif].sw_if_index] |
| 603 | } |
Jerome Tollet | 0f8d100 | 2021-01-07 12:44:17 +0100 | [diff] [blame] | 604 | |
| 605 | for e in evs: |
| 606 | self.assertLess(len(e), ev_macs * 10) |
| 607 | self.assertEqual(len(learned_macs ^ macs), 0) |
| 608 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 609 | |
| 610 | if __name__ == "__main__": |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 611 | unittest.main(testRunner=VppTestRunner) |