Currently the function iperf_mc have 3 tasks:
* set up the environment for mc (setting mc enable, sending join requests,
etc.).
* send mc traffic and check who got it.
* compare the results to the expected ones.
Following patches will introduce tests for more complicated scenarios. So
this patch breaks the 3 tasks apart.
The first one will be done in each test. The second remains in iperf_mc
and the third will be done in a new function in Testlib called
mc_ipref_compare_result.
This patch also updates test 20 to keep up with these changes.
Signed-off-by: Nogah Frankel <nogahf(a)mellanox.com>
Reviewed-by: Yotam Gigi <yotamg(a)mellanox.com>
---
recipes/switchdev/TestLib.py | 79 +++++++++++++++-------------------
recipes/switchdev/l2-020-bridge_mdb.py | 31 ++++++++++---
2 files changed, 58 insertions(+), 52 deletions(-)
diff --git a/recipes/switchdev/TestLib.py b/recipes/switchdev/TestLib.py
index e34161c..62db24e 100644
--- a/recipes/switchdev/TestLib.py
+++ b/recipes/switchdev/TestLib.py
@@ -201,75 +201,64 @@ class TestLib:
}
return self._ctl.get_module("Iperf", options = modules_options)
- def iperf_mc(self, sender, listeners, bridged, mc_group, desc=None):
+ def iperf_mc_listen(self, listener, mc_group):
+ host = listener.get_host()
+ srv_m = self._get_iperf_srv_mod(mc_group)
+ proc = host.run(srv_m, bg=True, netns=listener.get_netns())
+ return proc
+
+ def iperf_mc(self, sender, recivers, mc_group, desc=None):
if not desc:
- desc = self._generate_default_desc(sender, listeners)
+ desc = self._generate_default_desc(sender, recivers)
sender.set_mtu(self._mtu)
- sender.enable_multicast()
- map(lambda i:i.enable_multicast(), listeners + bridged)
- map(lambda i:i.set_mtu(self._mtu), listeners + bridged)
+ map(lambda i:i.set_mtu(self._mtu), recivers)
sender_host = sender.get_host()
- listeners_host = map(lambda i:i.get_host(), listeners)
- bridged_host = map(lambda i:i.get_host(), bridged)
+ recivers_host = map(lambda i:i.get_host(), recivers)
map(lambda i:i.sync_resources(modules=["Iperf"]),
- listeners_host + bridged_host)
+ recivers_host)
duration = self._netperf_duration
speed = self._mc_speed
# read link-stats
- sender_stats = sender.link_stats()
- listeners_stats = map(lambda i:i.link_stats(), listeners)
- bridged_stats = map(lambda i:i.link_stats(), bridged)
-
- # Run iperf server for all listeners
- srv_m = self._get_iperf_srv_mod(mc_group)
- s_procs = map(lambda i:i[0].run(srv_m, bg=True, netns=i[1].get_netns()),
- zip(listeners_host, listeners))
- self._ctl.wait(2)
+ sender_stats_before = sender.link_stats()
+ recivers_stats_before = map(lambda i:i.link_stats(), recivers)
# An send traffic to all listeners but bridged
cli_m = self._get_iperf_cli_mod(mc_group, duration, speed)
sender_host.run(cli_m, timeout=duration + 10, desc=desc,
netns=sender.get_netns())
- map(lambda i:i.intr(), s_procs)
- map(lambda i:i.disable_multicast(), listeners + bridged)
- sender.disable_multicast()
# re-read link-stats
- sender_stats1 = sender.link_stats()
- listeners_stats1 = map(lambda i:i.link_stats(), listeners)
- bridged_stats1 = map(lambda i:i.link_stats(), bridged)
-
- # Check that listeners got multi cast traffic
- tx = sender_stats1["tx_bytes"] - sender_stats["tx_bytes"]
- rx = map(lambda i:i[1]["rx_bytes"] - i[0]["rx_bytes"],
- zip(listeners_stats, listeners_stats1))
- err = filter(lambda i:i[0] < self._mc_high_thershold, zip(rx, listeners))
- err_str = map(lambda i:("Traffic isn't received for %s:%s count %d"
%
- (i[1].get_host().get_id(), i[1].get_id(), i[0]),
- i[1]), err)
- for i in err_str:
- self.custom(i[1].get_host(), "iperf_mc", i[0])
- for i in zip(rx, listeners):
+ sender_stats_after = sender.link_stats()
+ recivers_stats_after = map(lambda i:i.link_stats(), recivers)
+
+ # Check that who got multi cast traffic
+ tx = sender_stats_after["tx_bytes"] -
sender_stats_before["tx_bytes"]
+ rx = map(lambda i,l:i["rx_bytes"] - l["rx_bytes"],
+ recivers_stats_after, recivers_stats_before)
+ recivers_result = [rate > self._mc_high_thershold for rate in rx]
+ for i in zip(rx, recivers):
logging.info("Measured traffic on %s:%s is %dMb, bytes lost %d
(%d%%)" %
(i[1].get_host().get_id(), i[1].get_id(),
i[0] / 1000000,
max(tx - i[0], 0),
(max(tx - i[0], 0) * 100) / tx))
-
- # Check that only listeners got traffic
- rx = map(lambda i:i[1]["rx_bytes"] - i[0]["rx_bytes"],
- zip(bridged_stats, bridged_stats1))
- err = filter(lambda i:i[0] > self._mc_low_thershold, zip(rx, bridged))
- err_str = map(lambda i:("Received unwanted traffic for %s:%s count %d"
%
- (i[1].get_host().get_id(), i[1].get_id(), i[0]),
- i[1]), err)
- for i in err_str:
- self.custom(i[1].get_host(), "iperf_mc", i[0])
+ return recivers_result
+
+ def mc_ipref_compare_result(self, ifaces, results, expected):
+ err_indices = [i for i in range(len(results))
+ if results[i] != expected[i]]
+ for i in err_indices:
+ iface, result, expect = ifaces[i], results[i], expected[i]
+ err_str = "interface %s in %s %s traffic, when it %s get" % \
+ (iface.get_id(), iface.get_host().get_id(), \
+ ["didn't get", "got"][result], \
+ ["shouldn't", "should"][expect])
+ self.custom(iface.get_host(), "iperf_mc", err_str)
def pktgen(self, if1, if2, pkt_size, desc=None, thread_option=[], **kwargs):
if1.set_mtu(self._mtu)
diff --git a/recipes/switchdev/l2-020-bridge_mdb.py
b/recipes/switchdev/l2-020-bridge_mdb.py
index 04bcae9..f48d11e 100644
--- a/recipes/switchdev/l2-020-bridge_mdb.py
+++ b/recipes/switchdev/l2-020-bridge_mdb.py
@@ -7,6 +7,7 @@ published by the Free Software Foundation; see COPYING for details.
__author__ = """
eladr(a)mellanox.com (Elad Raz)
jiri(a)mellanox.com (Jiri Pirko)
+nogahf(a)mellanox.com (Nogah Frankel)
"""
from lnst.Controller.Task import ctl
@@ -17,6 +18,16 @@ def test_ip(major, minor):
return ["192.168.10%d.%d/24" % (major, minor),
"2002:%d::%d/64" % (major, minor)]
+def mcgrp(i):
+ return "239.255.1.%d" % i
+
+def test_standard_mutlicast(tl, sender, listeners, bridged, group):
+ s_procs = [tl.iperf_mc_listen(listener, group) for listener in listeners]
+ res = tl.iperf_mc(sender, listeners+ bridged, group)
+ expected = [True for l in listeners] + [False for l in bridged]
+ tl.mc_ipref_compare_result(listeners + bridged, res, expected)
+ map(lambda i:i.intr(), s_procs)
+
def do_task(ctl, hosts, ifaces, aliases):
m1, m2, sw = hosts
m1_if, m2_if, m3_if, m4_if, sw_if1, sw_if2, sw_if3, sw_if4 = ifaces
@@ -25,16 +36,22 @@ def do_task(ctl, hosts, ifaces, aliases):
sw_br = sw.create_bridge(slaves=[sw_if1, sw_if2, sw_if3, sw_if4],
options={"vlan_filtering": 1})
- m1_if.set_addresses(["192.168.101.10/24", "2002::1/64"])
- m2_if.set_addresses(["192.168.101.11/24", "2002::2/64"])
- m3_if.set_addresses(["192.168.101.13/24", "2002::3/64"])
- m4_if.set_addresses(["192.168.101.14/24", "2002::4/64"])
+ m1_if.set_addresses(test_ip(1,1))
+ m2_if.set_addresses(test_ip(1, 2))
+ m3_if.set_addresses(test_ip(1, 3))
+ m4_if.set_addresses(test_ip(1, 4))
sleep(30)
tl = TestLib(ctl, aliases)
- tl.iperf_mc(m1_if, [m2_if, m4_if], [m3_if], "239.255.1.3")
- tl.iperf_mc(m1_if, [m4_if], [], "239.255.1.4")
- tl.iperf_mc(m2_if, [m3_if, m4_if, m1_if] , [], "239.255.1.5")
+
+ for iface in [m1_if, m2_if, m3_if, m4_if]:
+ iface.enable_multicast()
+
+ test_standard_mutlicast(tl, m1_if, [m2_if, m4_if], [m3_if], mcgrp(3))
+ test_standard_mutlicast(tl, m1_if, [m4_if], [m2_if, m3_if], mcgrp(4))
+ test_standard_mutlicast(tl, m2_if, [m3_if, m4_if, m1_if], [], mcgrp(5))
+ for iface in [m1_if, m2_if, m3_if, m4_if]:
+ iface.disable_multicast()
do_task(ctl, [ctl.get_host("machine1"),
ctl.get_host("machine2"),
--
2.4.3