[V1,1/1] framework/pktgen: fix rfc2544 zero loss rate return value
diff mbox series

Message ID 20200807045953.31955-2-yufengx.mo@intel.com
State Superseded
Headers show
Series
  • framework/pktgen: fix rfc2544 zero loss rate return value error.
Related show

Commit Message

Mo, YufengX Aug. 7, 2020, 4:59 a.m. UTC
error.

fix rfc2544 zero loss rate return value error when rfc2544 loss rate not hit condition.

Signed-off-by: yufengmx <yufengx.mo@intel.com>
---
 framework/pktgen_base.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/framework/pktgen_base.py b/framework/pktgen_base.py
index 049142f..768362d 100644
--- a/framework/pktgen_base.py
+++ b/framework/pktgen_base.py
@@ -508,6 +508,7 @@  class PacketGenerator(object):
         # traffic parameters for dichotomy algorithm
         loss_rate_table = []
         hit_result = None
+        hit_rate = 0
         rate = traffic_rate_max = max_rate
         traffic_rate_min = min_rate
         while True:
@@ -523,6 +524,7 @@  class PacketGenerator(object):
             # if upper bound rate percent hit, quit the left flow
             if rate == max_rate and status:
                 hit_result = result
+                hit_rate = rate
                 break
             # if lower bound rate percent not hit, quit the left flow
             if rate == min_rate and not status:
@@ -530,6 +532,7 @@  class PacketGenerator(object):
             if status:
                 traffic_rate_min = rate
                 hit_result = result
+                hit_rate = rate
             else:
                 traffic_rate_max = rate
             if traffic_rate_max - traffic_rate_min < accuracy:
@@ -549,7 +552,7 @@  class PacketGenerator(object):
                 ret_value = 0, result[0][0][1], result[0][0][2], 0
             else:
                 self.logger.debug(pformat(loss_rate_table))
-                ret_value = rate, hit_result[0][0][1], hit_result[0][0][2], hit_result[1][1]
+                ret_value = hit_rate, hit_result[0][0][1], hit_result[0][0][2], hit_result[1][1]
         else:
             if not hit_result:
                 msg = ('expected permit loss rate <{0}> '
@@ -560,7 +563,7 @@  class PacketGenerator(object):
                 ret_value = 0, result[0][1], result[0][2]
             else:
                 self.logger.debug(pformat(loss_rate_table))
-                ret_value = rate, hit_result[0][1], hit_result[0][2]
+                ret_value = hit_rate, hit_result[0][1], hit_result[0][2]
         self.logger.info("zero loss rate is %f" % rate)
 
         return ret_value