blob: fe1ea4581820ff33d09dc8c953cce6d474251ac8 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Jan4af521d2016-11-15 17:05:00 +01002"""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
63import unittest
64import random
65
66from scapy.packet import Raw
67from scapy.layers.l2 import Ether
68from scapy.layers.inet import IP, UDP
69
70from framework import VppTestCase, VppTestRunner
Klement Sekera9225dee2016-12-12 08:36:58 +010071from util import Host, ppp
Jakub Grajciar145e3302019-10-24 13:52:42 +020072from vpp_papi import mac_pton, VppEnum
John Loe23c99e2018-03-13 21:53:18 -040073
Jan4af521d2016-11-15 17:05:00 +010074
75class TestL2fib(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020076 """L2 FIB Test Case"""
Jan4af521d2016-11-15 17:05:00 +010077
78 @classmethod
Eyal Bari93b503e2017-05-15 10:13:15 +030079 def bd_ifs(cls, bd_id):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020080 return range((bd_id - 1) * cls.n_ifs_per_bd, bd_id * cls.n_ifs_per_bd - 1)
Eyal Bari93b503e2017-05-15 10:13:15 +030081
82 @classmethod
Jan4af521d2016-11-15 17:05:00 +010083 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.
Jan4af521d2016-11-15 17:05:00 +010090 """
91 super(TestL2fib, cls).setUpClass()
92
Jan4af521d2016-11-15 17:05:00 +010093 try:
Eyal Bari93b503e2017-05-15 10:13:15 +030094 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 Kotucek7303ee82018-11-21 13:20:41 +010097 # Create pg interfaces
Eyal Bari93b503e2017-05-15 10:13:15 +030098 cls.create_pg_interfaces(n_ifs)
Jan4af521d2016-11-15 17:05:00 +010099
Jan4af521d2016-11-15 17:05:00 +0100100 cls.flows = dict()
Eyal Bari93b503e2017-05-15 10:13:15 +0300101 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 Sekerad9b0c6f2022-04-26 19:02:15 +0200106 cls.pg_interfaces[x] for x in ifs if x != j
107 ]
Jan4af521d2016-11-15 17:05:00 +0100108
109 # Packet sizes
110 cls.pg_if_packet_sizes = [64, 512, 1518, 9018]
111
Eyal Bari93b503e2017-05-15 10:13:15 +0300112 for bd_id in n_brs:
113 # Create BD with MAC learning and unknown unicast flooding
114 # disabled and put interfaces to this BD
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200115 cls.vapi.bridge_domain_add_del(bd_id=bd_id, uu_flood=0, learn=0)
Eyal Bari93b503e2017-05-15 10:13:15 +0300116 ifs = [cls.pg_interfaces[i] for i in cls.bd_ifs(bd_id)]
117 for pg_if in ifs:
Ole Troana5b2eec2019-03-11 19:23:25 +0100118 cls.vapi.sw_interface_set_l2_bridge(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200119 rx_sw_if_index=pg_if.sw_if_index, bd_id=bd_id
120 )
Jan4af521d2016-11-15 17:05:00 +0100121
122 # Set up all interfaces
123 for i in cls.pg_interfaces:
124 i.admin_up()
Jan4af521d2016-11-15 17:05:00 +0100125 except Exception:
126 super(TestL2fib, cls).tearDownClass()
127 raise
128
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700129 @classmethod
130 def tearDownClass(cls):
131 super(TestL2fib, cls).tearDownClass()
132
Jan4af521d2016-11-15 17:05:00 +0100133 def setUp(self):
Jan4af521d2016-11-15 17:05:00 +0100134 super(TestL2fib, self).setUp()
Klement Sekeradab231a2016-12-21 08:50:14 +0100135 self.reset_packet_infos()
Jan4af521d2016-11-15 17:05:00 +0100136
137 def tearDown(self):
138 """
139 Show various debug prints after each test.
140 """
141 super(TestL2fib, self).tearDown()
142 if not self.vpp_dead:
Eyal Bari93b503e2017-05-15 10:13:15 +0300143 for bd_id in self.n_brs:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200144 self.logger.info(
145 self.vapi.ppcli("show bridge-domain %s detail" % bd_id)
146 )
Jan4af521d2016-11-15 17:05:00 +0100147
Paul Vinciguerra90cf21b2019-03-13 09:23:05 -0700148 def show_commands_at_teardown(self):
149 self.logger.info(self.vapi.ppcli("show l2fib verbose"))
150
Eyal Bari93b503e2017-05-15 10:13:15 +0300151 def create_hosts(self, n_hosts_per_if, subnet):
Jan4af521d2016-11-15 17:05:00 +0100152 """
153 Create required number of host MAC addresses and distribute them among
154 interfaces. Create host IPv4 address for every host MAC address.
155
Eyal Bari93b503e2017-05-15 10:13:15 +0300156 :param int n_hosts_per_if: Number of per interface hosts to
Dave Wallaced1706812021-08-12 18:36:02 -0400157 create MAC/IPv4 addresses for.
Jan4af521d2016-11-15 17:05:00 +0100158 """
Eyal Bari93b503e2017-05-15 10:13:15 +0300159
Eyal Bari755b1402017-10-08 15:53:34 +0300160 hosts = dict()
Jan4af521d2016-11-15 17:05:00 +0100161 for pg_if in self.pg_interfaces:
Eyal Bari93b503e2017-05-15 10:13:15 +0300162 swif = pg_if.sw_if_index
Jan4af521d2016-11-15 17:05:00 +0100163
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200164 def mac(j):
165 return "00:00:%02x:ff:%02x:%02x" % (subnet, swif, j)
Eyal Bari93b503e2017-05-15 10:13:15 +0300166
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200167 def ip(j):
168 return "172.%02u.1%02x.%u" % (subnet, swif, j)
Eyal Bari93b503e2017-05-15 10:13:15 +0300169
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200170 def h(j):
171 return Host(mac(j), ip(j))
172
Eyal Bari755b1402017-10-08 15:53:34 +0300173 hosts[swif] = [h(j) for j in range(n_hosts_per_if)]
174 return hosts
Eyal Bari93b503e2017-05-15 10:13:15 +0300175
Eyal Bari755b1402017-10-08 15:53:34 +0300176 def split_hosts(self, hosts, n):
177 splits = dict()
178 for pg_if in self.pg_interfaces:
179 swif = pg_if.sw_if_index
180 splits[swif] = hosts[swif][:n]
181 hosts[swif] = hosts[swif][n:]
182 return splits
183
184 def learn_hosts(self, bd_id, hosts):
Eyal Bari521202b2017-05-24 10:11:20 +0300185 """
Eyal Bari755b1402017-10-08 15:53:34 +0300186 Create and send per interface L2 MAC broadcast packet stream to
Eyal Bari521202b2017-05-24 10:11:20 +0300187 let the bridge domain learn these MAC addresses.
188
189 :param int bd_id: BD to teach
Eyal Bari755b1402017-10-08 15:53:34 +0300190 :param dict hosts: dict of hosts per interface
Eyal Bari521202b2017-05-24 10:11:20 +0300191 """
Ole Troana5b2eec2019-03-11 19:23:25 +0100192 self.vapi.bridge_flags(bd_id=bd_id, is_set=1, flags=1)
Eyal Bari521202b2017-05-24 10:11:20 +0300193 ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)]
194 for pg_if in ifs:
195 swif = pg_if.sw_if_index
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200196 packets = [
197 Ether(dst="ff:ff:ff:ff:ff:ff", src=host.mac) for host in hosts[swif]
198 ]
Eyal Bari521202b2017-05-24 10:11:20 +0300199 pg_if.add_stream(packets)
200 self.logger.info("Sending broadcast eth frames for MAC learning")
201 self.pg_start()
202
Eyal Bari755b1402017-10-08 15:53:34 +0300203 def config_l2_fib_entries(self, bd_id, hosts):
Jan4af521d2016-11-15 17:05:00 +0100204 """
Eyal Bari93b503e2017-05-15 10:13:15 +0300205 Config required number of L2 FIB entries.
Jan4af521d2016-11-15 17:05:00 +0100206
Eyal Bari93b503e2017-05-15 10:13:15 +0300207 :param int bd_id: BD's id
Jan4af521d2016-11-15 17:05:00 +0100208 :param int count: Number of L2 FIB entries to be created.
209 :param int start: Starting index of the host list. (Default value = 0)
210 """
Eyal Bari93b503e2017-05-15 10:13:15 +0300211 ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)]
212 for pg_if in ifs:
213 swif = pg_if.sw_if_index
Eyal Bari755b1402017-10-08 15:53:34 +0300214 for host in hosts[swif]:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200215 self.vapi.l2fib_add_del(mac_pton(host.mac), bd_id, swif, static_mac=1)
Jan4af521d2016-11-15 17:05:00 +0100216
Eyal Bari755b1402017-10-08 15:53:34 +0300217 def delete_l2_fib_entry(self, bd_id, hosts):
Jan4af521d2016-11-15 17:05:00 +0100218 """
219 Delete required number of L2 FIB entries.
220
221 :param int count: Number of L2 FIB entries to be created.
222 """
Eyal Bari93b503e2017-05-15 10:13:15 +0300223 ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)]
224 for pg_if in ifs:
225 swif = pg_if.sw_if_index
Eyal Bari755b1402017-10-08 15:53:34 +0300226 for host in hosts[swif]:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200227 self.vapi.l2fib_add_del(mac_pton(host.mac), bd_id, swif, is_add=0)
Eyal Bari93b503e2017-05-15 10:13:15 +0300228
Eyal Bari755b1402017-10-08 15:53:34 +0300229 def flush_int(self, swif, learned_hosts):
Eyal Bari93b503e2017-05-15 10:13:15 +0300230 """
231 Flush swif L2 FIB entries.
232
233 :param int swif: sw if index.
234 """
Eyal Bari521202b2017-05-24 10:11:20 +0300235 flushed = dict()
Eyal Bari93b503e2017-05-15 10:13:15 +0300236 self.vapi.l2fib_flush_int(swif)
Eyal Bari755b1402017-10-08 15:53:34 +0300237 flushed[swif] = learned_hosts[swif]
238 learned_hosts[swif] = []
Eyal Bari521202b2017-05-24 10:11:20 +0300239 return flushed
Eyal Bari93b503e2017-05-15 10:13:15 +0300240
Eyal Bari755b1402017-10-08 15:53:34 +0300241 def flush_bd(self, bd_id, learned_hosts):
Eyal Bari93b503e2017-05-15 10:13:15 +0300242 """
243 Flush bd_id L2 FIB entries.
244
245 :param int bd_id: Bridge Domain id.
246 """
247 self.vapi.l2fib_flush_bd(bd_id)
Eyal Bari521202b2017-05-24 10:11:20 +0300248 flushed = dict()
Eyal Bari93b503e2017-05-15 10:13:15 +0300249 ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)]
250 for pg_if in ifs:
251 swif = pg_if.sw_if_index
Eyal Bari755b1402017-10-08 15:53:34 +0300252 flushed[swif] = learned_hosts[swif]
253 learned_hosts[swif] = []
Eyal Bari521202b2017-05-24 10:11:20 +0300254 return flushed
Eyal Bari93b503e2017-05-15 10:13:15 +0300255
256 def flush_all(self):
257 """
258 Flush All L2 FIB entries.
259 """
260 self.vapi.l2fib_flush_all()
Jan4af521d2016-11-15 17:05:00 +0100261
Eyal Bari755b1402017-10-08 15:53:34 +0300262 def create_stream(self, src_if, packet_sizes, if_src_hosts, if_dst_hosts):
Jan4af521d2016-11-15 17:05:00 +0100263 """
264 Create input packet stream for defined interface using hosts or
265 deleted_hosts list.
266
267 :param object src_if: Interface to create packet stream for.
268 :param list packet_sizes: List of required packet sizes.
269 :param boolean deleted: Set to True if deleted_hosts list required.
270 :return: Stream of packets.
271 """
Eyal Bari521202b2017-05-24 10:11:20 +0300272 src_hosts = if_src_hosts[src_if.sw_if_index]
Eyal Bari93b503e2017-05-15 10:13:15 +0300273 if not src_hosts:
274 return []
Jan4af521d2016-11-15 17:05:00 +0100275 pkts = []
Jan4af521d2016-11-15 17:05:00 +0100276 for dst_if in self.flows[src_if]:
Eyal Bari521202b2017-05-24 10:11:20 +0300277 dst_swif = dst_if.sw_if_index
278 if dst_swif not in if_dst_hosts:
279 continue
280 dst_hosts = if_dst_hosts[dst_swif]
Eyal Bari755b1402017-10-08 15:53:34 +0300281 for dst_host in dst_hosts:
Jan4af521d2016-11-15 17:05:00 +0100282 src_host = random.choice(src_hosts)
Klement Sekeradab231a2016-12-21 08:50:14 +0100283 pkt_info = self.create_packet_info(src_if, dst_if)
Jan4af521d2016-11-15 17:05:00 +0100284 payload = self.info_to_payload(pkt_info)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200285 p = (
286 Ether(dst=dst_host.mac, src=src_host.mac)
287 / IP(src=src_host.ip4, dst=dst_host.ip4)
288 / UDP(sport=1234, dport=1234)
289 / Raw(payload)
290 )
Jan4af521d2016-11-15 17:05:00 +0100291 pkt_info.data = p.copy()
292 size = random.choice(packet_sizes)
293 self.extend_packet(p, size)
294 pkts.append(p)
295 return pkts
296
297 def verify_capture(self, pg_if, capture):
298 """
299 Verify captured input packet stream for defined interface.
300
301 :param object pg_if: Interface to verify captured packet stream for.
302 :param list capture: Captured packet stream.
303 """
304 last_info = dict()
305 for i in self.pg_interfaces:
306 last_info[i.sw_if_index] = None
307 dst_sw_if_index = pg_if.sw_if_index
308 for packet in capture:
Paul Vinciguerraeaea4212019-03-06 11:58:06 -0800309 payload_info = self.payload_to_info(packet[Raw])
Jan4af521d2016-11-15 17:05:00 +0100310 try:
311 ip = packet[IP]
312 udp = packet[UDP]
313 packet_index = payload_info.index
314 self.assertEqual(payload_info.dst, dst_sw_if_index)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200315 self.logger.debug(
316 "Got packet on port %s: src=%u (id=%u)"
317 % (pg_if.name, payload_info.src, packet_index)
318 )
Jan4af521d2016-11-15 17:05:00 +0100319 next_info = self.get_next_packet_info_for_interface2(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200320 payload_info.src, dst_sw_if_index, last_info[payload_info.src]
321 )
Jan4af521d2016-11-15 17:05:00 +0100322 last_info[payload_info.src] = next_info
323 self.assertTrue(next_info is not None)
324 self.assertEqual(packet_index, next_info.index)
325 saved_packet = next_info.data
326 # Check standard fields
327 self.assertEqual(ip.src, saved_packet[IP].src)
328 self.assertEqual(ip.dst, saved_packet[IP].dst)
329 self.assertEqual(udp.sport, saved_packet[UDP].sport)
330 self.assertEqual(udp.dport, saved_packet[UDP].dport)
Jakub Grajciar145e3302019-10-24 13:52:42 +0200331 except BaseException:
Klement Sekera9225dee2016-12-12 08:36:58 +0100332 self.logger.error(ppp("Unexpected or invalid packet:", packet))
Jan4af521d2016-11-15 17:05:00 +0100333 raise
334 for i in self.pg_interfaces:
335 remaining_packet = self.get_next_packet_info_for_interface2(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200336 i, dst_sw_if_index, last_info[i.sw_if_index]
337 )
Jan4af521d2016-11-15 17:05:00 +0100338 self.assertTrue(
339 remaining_packet is None,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200340 "Port %u: Packet expected from source %u didn't arrive"
341 % (dst_sw_if_index, i.sw_if_index),
342 )
Jan4af521d2016-11-15 17:05:00 +0100343
Eyal Bari755b1402017-10-08 15:53:34 +0300344 def run_verify_test(self, bd_id, src_hosts, dst_hosts):
Jan4af521d2016-11-15 17:05:00 +0100345 # Test
346 # Create incoming packet streams for packet-generator interfaces
Eyal Bari93b503e2017-05-15 10:13:15 +0300347 self.reset_packet_infos()
348 ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)]
349 for i in ifs:
Eyal Bari521202b2017-05-24 10:11:20 +0300350 pkts = self.create_stream(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200351 i,
352 self.pg_if_packet_sizes,
Eyal Bari755b1402017-10-08 15:53:34 +0300353 if_src_hosts=src_hosts,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200354 if_dst_hosts=dst_hosts,
355 )
Eyal Bari755b1402017-10-08 15:53:34 +0300356 if pkts:
357 i.add_stream(pkts)
Jan4af521d2016-11-15 17:05:00 +0100358
Ole Troana5b2eec2019-03-11 19:23:25 +0100359 self.vapi.bridge_flags(bd_id=bd_id, is_set=0, flags=1)
Jan4af521d2016-11-15 17:05:00 +0100360 # Enable packet capture and start packet sending
Eyal Bari93b503e2017-05-15 10:13:15 +0300361 self.pg_enable_capture(ifs)
Jan4af521d2016-11-15 17:05:00 +0100362 self.pg_start()
363
364 # Verify
365 # Verify outgoing packet streams per packet-generator interface
Eyal Bari93b503e2017-05-15 10:13:15 +0300366 for i in ifs:
Eyal Bari521202b2017-05-24 10:11:20 +0300367 if not dst_hosts[i.sw_if_index]:
368 continue
Jan4af521d2016-11-15 17:05:00 +0100369 capture = i.get_capture()
370 self.logger.info("Verifying capture on interface %s" % i.name)
371 self.verify_capture(i, capture)
372
Eyal Bari755b1402017-10-08 15:53:34 +0300373 def run_verify_negat_test(self, bd_id, src_hosts, dst_hosts):
Jan4af521d2016-11-15 17:05:00 +0100374 # Test
375 # Create incoming packet streams for packet-generator interfaces for
376 # deleted MAC addresses
Klement Sekeradab231a2016-12-21 08:50:14 +0100377 self.reset_packet_infos()
Eyal Bari93b503e2017-05-15 10:13:15 +0300378 ifs = [self.pg_interfaces[i] for i in self.bd_ifs(bd_id)]
379 for i in ifs:
Eyal Bari521202b2017-05-24 10:11:20 +0300380 pkts = self.create_stream(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200381 i,
382 self.pg_if_packet_sizes,
Eyal Bari755b1402017-10-08 15:53:34 +0300383 if_src_hosts=src_hosts,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200384 if_dst_hosts=dst_hosts,
385 )
Eyal Bari93b503e2017-05-15 10:13:15 +0300386 if pkts:
387 i.add_stream(pkts)
Jan4af521d2016-11-15 17:05:00 +0100388
Ole Troana5b2eec2019-03-11 19:23:25 +0100389 self.vapi.bridge_flags(bd_id=bd_id, is_set=0, flags=1)
Jan4af521d2016-11-15 17:05:00 +0100390 # Enable packet capture and start packet sending
Eyal Bari93b503e2017-05-15 10:13:15 +0300391 self.pg_enable_capture(ifs)
Jan4af521d2016-11-15 17:05:00 +0100392 self.pg_start()
393
394 # Verify
395 # Verify outgoing packet streams per packet-generator interface
Neale Ranns4b8d3be2017-05-22 02:46:01 -0700396 timeout = 1
Eyal Bari93b503e2017-05-15 10:13:15 +0300397 for i in ifs:
Neale Ranns4b8d3be2017-05-22 02:46:01 -0700398 i.get_capture(0, timeout=timeout)
Klement Sekera9225dee2016-12-12 08:36:58 +0100399 i.assert_nothing_captured(remark="outgoing interface")
Neale Ranns4b8d3be2017-05-22 02:46:01 -0700400 timeout = 0.1
Jan4af521d2016-11-15 17:05:00 +0100401
Eyal Bari755b1402017-10-08 15:53:34 +0300402 def test_l2_fib_program100(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200403 """L2 FIB - program 100 MACs"""
Eyal Bari755b1402017-10-08 15:53:34 +0300404 bd_id = 1
405 hosts = self.create_hosts(100, subnet=17)
406 self.config_l2_fib_entries(bd_id, hosts)
407 self.run_verify_test(bd_id, hosts, hosts)
Jan4af521d2016-11-15 17:05:00 +0100408
Pavel Kotucek7303ee82018-11-21 13:20:41 +0100409 def test_l2_fib_program100_delete12(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200410 """L2 FIB - program 100, delete 12 MACs"""
Eyal Bari755b1402017-10-08 15:53:34 +0300411 bd_id = 1
412 hosts = self.create_hosts(100, subnet=17)
413 self.config_l2_fib_entries(bd_id, hosts)
414 del_hosts = self.split_hosts(hosts, 12)
415 self.delete_l2_fib_entry(bd_id, del_hosts)
Jan4af521d2016-11-15 17:05:00 +0100416
Eyal Bari755b1402017-10-08 15:53:34 +0300417 self.run_verify_test(bd_id, hosts, hosts)
418 self.run_verify_negat_test(bd_id, hosts, del_hosts)
Jan4af521d2016-11-15 17:05:00 +0100419
Pavel Kotucek7303ee82018-11-21 13:20:41 +0100420 def test_l2_fib_program100_add100(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200421 """L2 FIB - program 100, add 100 MACs"""
Eyal Bari755b1402017-10-08 15:53:34 +0300422 bd_id = 1
423 hosts = self.create_hosts(100, subnet=17)
424 self.config_l2_fib_entries(bd_id, hosts)
425 hosts2 = self.create_hosts(100, subnet=22)
426 self.config_l2_fib_entries(bd_id, hosts2)
427 self.run_verify_test(bd_id, hosts, hosts2)
Jan4af521d2016-11-15 17:05:00 +0100428
Eyal Bari755b1402017-10-08 15:53:34 +0300429 def test_l2_fib_program10_learn10(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200430 """L2 FIB - program 10 MACs, learn 10"""
Eyal Bari755b1402017-10-08 15:53:34 +0300431 hosts = self.create_hosts(20, subnet=35)
432 lhosts = self.split_hosts(hosts, 10)
Jan4af521d2016-11-15 17:05:00 +0100433
Eyal Bari755b1402017-10-08 15:53:34 +0300434 bd1 = 1
435 bd2 = 2
436 self.learn_hosts(bd1, lhosts)
437 self.learn_hosts(bd2, lhosts)
438 self.config_l2_fib_entries(bd1, hosts)
439 self.config_l2_fib_entries(bd2, hosts)
440 self.run_verify_test(bd1, lhosts, hosts)
441 self.run_verify_test(bd2, lhosts, hosts)
Eyal Bari93b503e2017-05-15 10:13:15 +0300442
Eyal Bari755b1402017-10-08 15:53:34 +0300443 def test_l2_fib_flush_int(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200444 """L2 FIB - flush interface"""
Eyal Bari755b1402017-10-08 15:53:34 +0300445 hosts = self.create_hosts(20, subnet=36)
446 lhosts = self.split_hosts(hosts, 10)
Eyal Bari93b503e2017-05-15 10:13:15 +0300447
Eyal Bari755b1402017-10-08 15:53:34 +0300448 bd1 = 1
449 self.learn_hosts(bd1, lhosts)
450 self.config_l2_fib_entries(bd1, hosts)
451 self.run_verify_test(bd1, lhosts, hosts)
452 flushed = self.flush_int(self.pg_interfaces[0].sw_if_index, lhosts)
453 self.run_verify_test(bd1, hosts, lhosts)
454 self.run_verify_negat_test(bd1, hosts, flushed)
Eyal Bari521202b2017-05-24 10:11:20 +0300455
Eyal Bari755b1402017-10-08 15:53:34 +0300456 def test_l2_fib_flush_bd(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200457 """L2 FIB - flush BD"""
Eyal Bari755b1402017-10-08 15:53:34 +0300458 hosts = self.create_hosts(20, subnet=37)
459 lhosts = self.split_hosts(hosts, 10)
Eyal Bari521202b2017-05-24 10:11:20 +0300460
Eyal Bari755b1402017-10-08 15:53:34 +0300461 bd1 = 1
462 self.learn_hosts(bd1, lhosts)
463 self.config_l2_fib_entries(bd1, hosts)
464 self.run_verify_test(bd1, lhosts, hosts)
465 flushed = self.flush_bd(bd1, lhosts)
466 self.run_verify_negat_test(bd1, hosts, flushed)
Eyal Bari521202b2017-05-24 10:11:20 +0300467
Eyal Bari755b1402017-10-08 15:53:34 +0300468 def test_l2_fib_flush_all(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200469 """L2 FIB - flush all"""
Eyal Bari755b1402017-10-08 15:53:34 +0300470 hosts = self.create_hosts(20, subnet=38)
471 lhosts = self.split_hosts(hosts, 10)
Eyal Bari521202b2017-05-24 10:11:20 +0300472
Eyal Bari755b1402017-10-08 15:53:34 +0300473 bd1 = 1
474 bd2 = 2
475 self.learn_hosts(bd1, lhosts)
476 self.learn_hosts(bd2, lhosts)
477 self.config_l2_fib_entries(bd1, hosts)
478 self.config_l2_fib_entries(bd2, hosts)
479 self.run_verify_test(bd1, hosts, lhosts)
480 self.run_verify_test(bd2, hosts, lhosts)
Eyal Bari521202b2017-05-24 10:11:20 +0300481
Eyal Bari755b1402017-10-08 15:53:34 +0300482 self.flush_all()
483
484 self.run_verify_negat_test(bd1, hosts, lhosts)
485 self.run_verify_negat_test(bd2, hosts, lhosts)
486
487 def test_l2_fib_mac_learn_evs(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200488 """L2 FIB - mac learning events"""
Eyal Bari755b1402017-10-08 15:53:34 +0300489 bd1 = 1
490 hosts = self.create_hosts(10, subnet=39)
Eyal Bari24db0ec2017-09-27 21:43:51 +0300491
Ole Troane1ade682019-03-04 23:55:43 +0100492 self.vapi.want_l2_macs_events()
Eyal Bari755b1402017-10-08 15:53:34 +0300493 self.learn_hosts(bd1, hosts)
Eyal Bari24db0ec2017-09-27 21:43:51 +0300494
Benoît Ganne56eccdb2021-08-20 09:18:31 +0200495 self.virtual_sleep(1)
Eyal Bari24db0ec2017-09-27 21:43:51 +0300496 self.logger.info(self.vapi.ppcli("show l2fib"))
497 evs = self.vapi.collect_events()
Jakub Grajciar145e3302019-10-24 13:52:42 +0200498 action = VppEnum.vl_api_mac_event_action_t.MAC_EVENT_ACTION_API_ADD
Eyal Bari24db0ec2017-09-27 21:43:51 +0300499 learned_macs = {
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200500 e.mac[i].mac_addr.packed
501 for e in evs
502 for i in range(e.n_macs)
503 if e.mac[i].action == action
504 }
505 macs = {
506 h.bin_mac
507 for swif in self.bd_ifs(bd1)
508 for h in hosts[self.pg_interfaces[swif].sw_if_index]
509 }
Ole Troane1ade682019-03-04 23:55:43 +0100510 self.vapi.want_l2_macs_events(enable_disable=0)
Eyal Bari24db0ec2017-09-27 21:43:51 +0300511 self.assertEqual(len(learned_macs ^ macs), 0)
512
Jerome Tollet0f8d1002021-01-07 12:44:17 +0100513 def test_l2_fib_mac_learn_evs2(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200514 """L2 FIB - mac learning events using want_l2_macs_events2"""
Jerome Tollet0f8d1002021-01-07 12:44:17 +0100515 bd1 = 1
516 hosts = self.create_hosts(10, subnet=39)
517
518 self.vapi.l2fib_set_scan_delay(scan_delay=10)
519 self.vapi.want_l2_macs_events2()
520 self.sleep(1)
521 self.learn_hosts(bd1, hosts)
522
Benoît Ganne56eccdb2021-08-20 09:18:31 +0200523 self.virtual_sleep(1)
Jerome Tollet0f8d1002021-01-07 12:44:17 +0100524 self.logger.info(self.vapi.ppcli("show l2fib"))
525 evs = self.vapi.collect_events()
526 action = VppEnum.vl_api_mac_event_action_t.MAC_EVENT_ACTION_API_ADD
527 learned_macs = {
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200528 e.mac[i].mac_addr.packed
529 for e in evs
530 for i in range(e.n_macs)
531 if e.mac[i].action == action
532 }
533 macs = {
534 h.bin_mac
535 for swif in self.bd_ifs(bd1)
536 for h in hosts[self.pg_interfaces[swif].sw_if_index]
537 }
Jerome Tollet0f8d1002021-01-07 12:44:17 +0100538 self.vapi.want_l2_macs_events2(enable_disable=0)
539 self.assertEqual(len(learned_macs ^ macs), 0)
540
Eyal Bari755b1402017-10-08 15:53:34 +0300541 def test_l2_fib_macs_learn_max(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200542 """L2 FIB - mac learning max macs in event"""
Eyal Bari755b1402017-10-08 15:53:34 +0300543 bd1 = 1
544 hosts = self.create_hosts(10, subnet=40)
eyal baric6038c92017-10-03 12:25:07 +0300545
546 ev_macs = 1
Ole Troane1ade682019-03-04 23:55:43 +0100547 self.vapi.want_l2_macs_events(max_macs_in_event=ev_macs)
Eyal Bari755b1402017-10-08 15:53:34 +0300548 self.learn_hosts(bd1, hosts)
eyal baric6038c92017-10-03 12:25:07 +0300549
550 self.sleep(1)
551 self.logger.info(self.vapi.ppcli("show l2fib"))
552 evs = self.vapi.collect_events()
Ole Troane1ade682019-03-04 23:55:43 +0100553 self.vapi.want_l2_macs_events(enable_disable=0)
Eyal Bari755b1402017-10-08 15:53:34 +0300554
555 self.assertGreater(len(evs), 0)
Jakub Grajciar145e3302019-10-24 13:52:42 +0200556 action = VppEnum.vl_api_mac_event_action_t.MAC_EVENT_ACTION_API_ADD
Eyal Bari755b1402017-10-08 15:53:34 +0300557 learned_macs = {
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200558 e.mac[i].mac_addr.packed
559 for e in evs
560 for i in range(e.n_macs)
561 if e.mac[i].action == action
562 }
563 macs = {
564 h.bin_mac
565 for swif in self.bd_ifs(bd1)
566 for h in hosts[self.pg_interfaces[swif].sw_if_index]
567 }
Eyal Bari755b1402017-10-08 15:53:34 +0300568
eyal baric6038c92017-10-03 12:25:07 +0300569 for e in evs:
570 self.assertLess(len(e), ev_macs * 10)
571 self.assertEqual(len(learned_macs ^ macs), 0)
572
Jerome Tollet0f8d1002021-01-07 12:44:17 +0100573 def test_l2_fib_macs_learn_max2(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200574 """L2 FIB - mac learning max macs in event using want_l2_macs_events2"""
Jerome Tollet0f8d1002021-01-07 12:44:17 +0100575 bd1 = 1
576 hosts = self.create_hosts(10, subnet=40)
577
578 ev_macs = 1
579 self.vapi.l2fib_set_scan_delay(scan_delay=10)
580 self.vapi.want_l2_macs_events2(max_macs_in_event=ev_macs)
581 self.sleep(1)
582 self.learn_hosts(bd1, hosts)
583
Benoît Ganne56eccdb2021-08-20 09:18:31 +0200584 self.virtual_sleep(1)
Jerome Tollet0f8d1002021-01-07 12:44:17 +0100585 self.logger.info(self.vapi.ppcli("show l2fib"))
586 evs = self.vapi.collect_events()
587 self.vapi.want_l2_macs_events2(enable_disable=0)
588
589 self.assertGreater(len(evs), 0)
590 action = VppEnum.vl_api_mac_event_action_t.MAC_EVENT_ACTION_API_ADD
591 learned_macs = {
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200592 e.mac[i].mac_addr.packed
593 for e in evs
594 for i in range(e.n_macs)
595 if e.mac[i].action == action
596 }
597 macs = {
598 h.bin_mac
599 for swif in self.bd_ifs(bd1)
600 for h in hosts[self.pg_interfaces[swif].sw_if_index]
601 }
Jerome Tollet0f8d1002021-01-07 12:44:17 +0100602
603 for e in evs:
604 self.assertLess(len(e), ev_macs * 10)
605 self.assertEqual(len(learned_macs ^ macs), 0)
606
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200607
608if __name__ == "__main__":
Jan4af521d2016-11-15 17:05:00 +0100609 unittest.main(testRunner=VppTestRunner)