diff mbox

[LNST,internal] recipes: switchdev: RedTestLib: Check actual send rate

Message ID 1525007852-35182-1-git-send-email-nogahf@mellanox.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Nogah Frankel April 29, 2018, 1:17 p.m. UTC
Check the actual send rate when sending traffic. If it is much lower than
the wanted one, fail the test.
Note that this fail means that the setup isn't strong enough to run the RED
tests, not that they found a problem.

Signed-off-by: Nogah Frankel <nogahf@mellanox.com>
---
 recipes/switchdev/RedTestLib.py | 9 +++++++++
 1 file changed, 9 insertions(+)
diff mbox

Patch

diff --git a/recipes/switchdev/RedTestLib.py b/recipes/switchdev/RedTestLib.py
index 56fad43..45ac907 100644
--- a/recipes/switchdev/RedTestLib.py
+++ b/recipes/switchdev/RedTestLib.py
@@ -9,6 +9,7 @@  nogahf@mellanox.com (Nogah Frankel)
 """
 
 from time import sleep
+import datetime
 import logging
 from lnst.Controller.Task import ctl
 
@@ -201,8 +202,16 @@  class RedTestLib:
         if self.router:
             args["dst"] = self.links[self.egress_port].get_ip()
             args["dst_mac"] = self.ingress_port.get_hwaddr()
+        start_time = datetime.datetime.now()
         self.tl.pktgen(self.links[self.ingress_port],
                        self.links[self.egress_port], pkt_size, **args)
+        end_time = datetime.datetime.now()
+        # Approximate rate in mega bits per second
+        actual_rate = int(pkt_size) * 8./(end_time - start_time).total_seconds()
+        if actual_rate < self.rate * 0.8:
+            raise Exception("Actual send rate %d is much lower then asked for %d\n"
+                            "Please run on stronger machine" % (actual_rate,
+                            self.rate))
         sleep(3)
 
         rx_after = self.ingress_port.link_stats()["rx_packets"]