From f94815cf46928df34dbf7af095f8b4ff32f73fc5 Mon Sep 17 00:00:00 2001 From: Tobias Waldekranz Date: Fri, 17 May 2024 07:49:22 +0000 Subject: [PATCH] test: case: static_multicast_filters: Speed up positive reception tests Use must{,_not}_receive instead of the general sniffer, so that we can continue the test as soon as we see the transmission at the receiver, rather than always waiting the full 5s. While we're here: - Show the port mappings in the top block-comment - Define a few more steps to show the user what is going on - Avoid global variable references in set_static_multicast_filter() --- .../static_multicast_filters.py | 126 +++++++++--------- 1 file changed, 61 insertions(+), 65 deletions(-) diff --git a/test/case/infix_interfaces/static_multicast_filters.py b/test/case/infix_interfaces/static_multicast_filters.py index 40cfc017..eb75998f 100755 --- a/test/case/infix_interfaces/static_multicast_filters.py +++ b/test/case/infix_interfaces/static_multicast_filters.py @@ -1,18 +1,20 @@ #!/usr/bin/env python3 -# 10.0.0.1 -# +--------------+ -# | DUT | -# | | -# +----------+---\ -# | | \ -# | | \ -# | | \ -# | | \ -# 10.0.0.2 | 10.0.0.3| \ 10.0.0.4 -# +----------+ +---+------+ \ +-------------+ -# | msend | | Static | + no join | -# +----------+ | MC-filter| +-------------+ -# +----------+ +# +# Add static filter on DUT for 224.1.1.1 containing only data1. Send +# to that group from `msend`, verify that `mrecv` receives it and that +# `!memb` does not. +# +# .1 +# .---------------------------. +# | DUT | +# '-data0-----data1-----data2-' +# | | | +# | | | 10.0.0.0/24 +# | | | +# .-data0-. .-data1-. .-data2-. +# | msend | | mrecv | | !memb | +# '-------' '-------' '-------' +# .2 .3 .4 import infamy import time @@ -20,32 +22,31 @@ import infamy.multicast as mcast import infamy.iface as iface from infamy.util import until -def set_static_multicast_filter(target, address): - target.put_config_dict("ietf-interfaces", - { - "interfaces": { - "interface": [ - { - "name": "br0", - "infix-interfaces:bridge": { - "multicast-filters": { - "multicast-filter": [ - { - "group": "224.1.1.1", - "ports": [ - { - "port": mreceive - } - ] - - } - ], - }, - } +def set_static_multicast_filter(target, address, port): + target.put_config_dict("ietf-interfaces", { + "interfaces": { + "interface": [ + { + "name": "br0", + "infix-interfaces:bridge": { + "multicast-filters": { + "multicast-filter": [ + { + "group": address, + "ports": [ + { + "port": port, } - ] - } - }) + ] + } + ], + }, + } + } + ] + } + }) + with infamy.Test() as test: with test.step("Initialize"): env = infamy.Env(infamy.std_topology("1x4")) @@ -54,7 +55,7 @@ with infamy.Test() as test: _, mreceive = env.ltop.xlate("target", "data1") _, nojoin = env.ltop.xlate("target", "data2") - with test.step("Configure device"): + with test.step("Configure device without static filter"): target.put_config_dict("ietf-interfaces", { "interfaces": { @@ -103,13 +104,14 @@ with infamy.Test() as test: } }) - with test.step("Check multicast receieved on correct port"): - _, hsend = env.ltop.xlate("host", "data0") - _, hreceive = env.ltop.xlate("host", "data1") - _, hnojoin = env.ltop.xlate("host", "data2") - with infamy.IsolatedMacVlan(hsend) as send_ns, \ - infamy.IsolatedMacVlan(hreceive) as receive_ns, \ - infamy.IsolatedMacVlan(hnojoin) as nojoin_ns: + _, hsend = env.ltop.xlate("host", "data0") + _, hreceive = env.ltop.xlate("host", "data1") + _, hnojoin = env.ltop.xlate("host", "data2") + with infamy.IsolatedMacVlan(hsend) as send_ns, \ + infamy.IsolatedMacVlan(hreceive) as receive_ns, \ + infamy.IsolatedMacVlan(hnojoin) as nojoin_ns: + + with test.step("Setup sender and receivers"): send_ns.addip("10.0.0.2") receive_ns.addip("10.0.0.3") nojoin_ns.addip("10.0.0.4") @@ -117,26 +119,20 @@ with infamy.Test() as test: receive_ns.must_reach("10.0.0.1") nojoin_ns.must_reach("10.0.0.1") - sender = mcast.MCastSender(send_ns, "224.1.1.1") - snif_nojoin = infamy.Sniffer(nojoin_ns, "host 224.1.1.1") - snif_receiver = infamy.Sniffer(receive_ns, "host 224.1.1.1") - with sender: - with snif_receiver: - time.sleep(5) - with snif_nojoin: - time.sleep(5) - assert(snif_receiver.packets() != "") - assert(snif_nojoin.packets() != "") - print("As expected, unregistered multicast is received on both ports") + print("Starting sender") + with mcast.MCastSender(send_ns, "224.1.1.1"): + with test.step("Verify that the group is flooded on all ports"): + infamy.parallel(lambda: receive_ns.must_receive("ip dst 224.1.1.1"), + lambda: nojoin_ns.must_receive("ip dst 224.1.1.1")) - set_static_multicast_filter(target, "224.1.1.1") + with test.step("Install group filter"): + set_static_multicast_filter(target, "224.1.1.1", mreceive) until(lambda: iface.exist_bridge_multicast_filter(target, "224.1.1.1", mreceive, "br0")) - with snif_receiver,snif_nojoin: - time.sleep(5) - assert(snif_nojoin.packets() == "") - print("As expected, registered multicast is NOT forwarded to non-member port") - assert(snif_receiver.packets() != "") - print("As expected, registered multicast is forwarded to the member port") + with test.step("Verify that the group is still forwarded to the member"): + receive_ns.must_receive("ip dst 224.1.1.1") + + with test.step("Verify that the group is no longer forwarded to the non-member"): + nojoin_ns.must_not_receive("ip dst 224.1.1.1") test.succeed()