Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions tests/fdb/test_fdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
DUMMY_MAC_PREFIX = "02:11:22:33"
DUMMY_MAC_COUNT = 10
FDB_POPULATE_SLEEP_TIMEOUT = 2
FDB_CLEAN_UP_SLEEP_TIMEOUT = 2
FDB_WAIT_EXPECTED_PACKET_TIMEOUT = 5
PKT_TYPES = ["ethernet", "arp_request", "arp_reply"]
PKT_TYPES = ["ethernet", "arp_request", "arp_reply", "cleanup"]

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -150,25 +151,46 @@ def setup_fdb(ptfadapter, vlan_table, router_mac, pkt_type):
time.sleep(FDB_POPULATE_SLEEP_TIMEOUT)
# Flush dataplane
ptfadapter.dataplane.flush()

return fdb


@pytest.fixture
def get_fdb_dynamic_mac_count(duthost):
res = duthost.command('show mac')
logger.info('"show mac" output on DUT:\n{}'.format(pprint.pformat(res['stdout_lines'])))
total_mac_count = 0
for l in res['stdout_lines']:
if "dynamic" in l.lower():
total_mac_count += 1
return total_mac_count


def fdb_cleanup(duthosts, rand_one_dut_hostname):
""" cleanup FDB before and after test run """
duthost = duthosts[rand_one_dut_hostname]
try:
duthost.command('sonic-clear fdb all')
yield
finally:
# in any case clear fdb after test
total_dyn_mac_count = get_fdb_dynamic_mac_count(duthost)
if total_dyn_mac_count == 0:
return
else:
done = False
duthost.command('sonic-clear fdb all')
while not done:
total_dyn_mac_count = get_fdb_dynamic_mac_count(duthost)
if total_dyn_mac_count != 0:
time.sleep(FDB_CLEAN_UP_SLEEP_TIMEOUT)
else:
return
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this section could be refactored to use wait_until. This does require us to set an upper-bound on how long we'll poll, but I think that's probably a good thing to have in the (hopefully unlikely 😄) case we hit some bug and the dynamic MAC count never hits 0.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daall Agreed. I have made the changes to use wait_until() and pytest_assert().



@pytest.mark.bsl
@pytest.mark.usefixtures('fdb_cleanup')
@pytest.mark.parametrize("pkt_type", PKT_TYPES)
def test_fdb(ansible_adhoc, ptfadapter, duthosts, rand_one_dut_hostname, ptfhost, pkt_type):

# Perform FDB clean up before each test and at the end of the final test
fdb_cleanup(duthosts, rand_one_dut_hostname)
if pkt_type == "cleanup":
return

"""
1. verify fdb forwarding.
2. verify show mac command on DUT for learned mac.
Expand Down