X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=test%2Ftest_l2_fib.py;h=9ce289f1652f9523cc8bafc830a954db81f9a883;hb=0f8d10035;hp=a75672ab0791cd5c5f5fe0a574846c36a3168e54;hpb=7f9b7f9f492d1748d8ba025b3a713058fdb1943d;p=vpp.git diff --git a/test/test_l2_fib.py b/test/test_l2_fib.py index a75672ab079..9ce289f1652 100644 --- a/test/test_l2_fib.py +++ b/test/test_l2_fib.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """L2 FIB Test Case HLD: **config 1** @@ -69,12 +69,7 @@ from scapy.layers.inet import IP, UDP from framework import VppTestCase, VppTestRunner from util import Host, ppp -from vpp_papi import mac_pton - -# from src/vnet/l2/l2_fib.h -MAC_EVENT_ACTION_ADD = 0 -MAC_EVENT_ACTION_DELETE = 1 -MAC_EVENT_ACTION_MOVE = 2 +from vpp_papi import mac_pton, VppEnum class TestL2fib(VppTestCase): @@ -145,11 +140,13 @@ class TestL2fib(VppTestCase): """ super(TestL2fib, self).tearDown() if not self.vpp_dead: - self.logger.info(self.vapi.ppcli("show l2fib verbose")) for bd_id in self.n_brs: self.logger.info(self.vapi.ppcli("show bridge-domain %s detail" % bd_id)) + def show_commands_at_teardown(self): + self.logger.info(self.vapi.ppcli("show l2fib verbose")) + def create_hosts(self, n_hosts_per_if, subnet): """ Create required number of host MAC addresses and distribute them among @@ -323,7 +320,7 @@ class TestL2fib(VppTestCase): self.assertEqual(ip.dst, saved_packet[IP].dst) self.assertEqual(udp.sport, saved_packet[UDP].sport) self.assertEqual(udp.dport, saved_packet[UDP].dport) - except: + except BaseException: self.logger.error(ppp("Unexpected or invalid packet:", packet)) raise for i in self.pg_interfaces: @@ -492,14 +489,38 @@ class TestL2fib(VppTestCase): self.sleep(1) self.logger.info(self.vapi.ppcli("show l2fib")) evs = self.vapi.collect_events() + action = VppEnum.vl_api_mac_event_action_t.MAC_EVENT_ACTION_API_ADD learned_macs = { - e.mac[i].mac_addr for e in evs for i in range(e.n_macs) - if e.mac[i].action == MAC_EVENT_ACTION_ADD} + e.mac[i].mac_addr.packed for e in evs for i in range(e.n_macs) + if e.mac[i].action == action} macs = {h.bin_mac for swif in self.bd_ifs(bd1) for h in hosts[self.pg_interfaces[swif].sw_if_index]} self.vapi.want_l2_macs_events(enable_disable=0) self.assertEqual(len(learned_macs ^ macs), 0) + def test_l2_fib_mac_learn_evs2(self): + """ L2 FIB - mac learning events using want_l2_macs_events2 + """ + bd1 = 1 + hosts = self.create_hosts(10, subnet=39) + + self.vapi.l2fib_set_scan_delay(scan_delay=10) + self.vapi.want_l2_macs_events2() + self.sleep(1) + self.learn_hosts(bd1, hosts) + + self.sleep(1) + self.logger.info(self.vapi.ppcli("show l2fib")) + evs = self.vapi.collect_events() + action = VppEnum.vl_api_mac_event_action_t.MAC_EVENT_ACTION_API_ADD + learned_macs = { + e.mac[i].mac_addr.packed for e in evs for i in range(e.n_macs) + if e.mac[i].action == action} + macs = {h.bin_mac for swif in self.bd_ifs(bd1) + for h in hosts[self.pg_interfaces[swif].sw_if_index]} + self.vapi.want_l2_macs_events2(enable_disable=0) + self.assertEqual(len(learned_macs ^ macs), 0) + def test_l2_fib_macs_learn_max(self): """ L2 FIB - mac learning max macs in event """ @@ -516,9 +537,39 @@ class TestL2fib(VppTestCase): self.vapi.want_l2_macs_events(enable_disable=0) self.assertGreater(len(evs), 0) + action = VppEnum.vl_api_mac_event_action_t.MAC_EVENT_ACTION_API_ADD + learned_macs = { + e.mac[i].mac_addr.packed for e in evs for i in range(e.n_macs) + if e.mac[i].action == action} + macs = {h.bin_mac for swif in self.bd_ifs(bd1) + for h in hosts[self.pg_interfaces[swif].sw_if_index]} + + for e in evs: + self.assertLess(len(e), ev_macs * 10) + self.assertEqual(len(learned_macs ^ macs), 0) + + def test_l2_fib_macs_learn_max2(self): + """ L2 FIB - mac learning max macs in event using want_l2_macs_events2 + """ + bd1 = 1 + hosts = self.create_hosts(10, subnet=40) + + ev_macs = 1 + self.vapi.l2fib_set_scan_delay(scan_delay=10) + self.vapi.want_l2_macs_events2(max_macs_in_event=ev_macs) + self.sleep(1) + self.learn_hosts(bd1, hosts) + + self.sleep(1) + self.logger.info(self.vapi.ppcli("show l2fib")) + evs = self.vapi.collect_events() + self.vapi.want_l2_macs_events2(enable_disable=0) + + self.assertGreater(len(evs), 0) + action = VppEnum.vl_api_mac_event_action_t.MAC_EVENT_ACTION_API_ADD learned_macs = { - e.mac[i].mac_addr for e in evs for i in range(e.n_macs) - if e.mac[i].action == MAC_EVENT_ACTION_ADD} + e.mac[i].mac_addr.packed for e in evs for i in range(e.n_macs) + if e.mac[i].action == action} macs = {h.bin_mac for swif in self.bd_ifs(bd1) for h in hosts[self.pg_interfaces[swif].sw_if_index]}