X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=nfvbench%2Ftraffic_gen%2Ftraffic_base.py;h=df28772af9fe5be1cf361070688ab1ed8a938ff7;hb=94845d2bf7416d8b59e2eaf017244832cf3277f4;hp=abf5a22af2b78002863db1f89852601f3b4fcc1c;hpb=64579b717d47ab7f654c574794831be984bf32e1;p=nfvbench.git diff --git a/nfvbench/traffic_gen/traffic_base.py b/nfvbench/traffic_gen/traffic_base.py index abf5a22..df28772 100644 --- a/nfvbench/traffic_gen/traffic_base.py +++ b/nfvbench/traffic_gen/traffic_base.py @@ -15,6 +15,8 @@ import abc import sys +import bitmath + from nfvbench.log import LOG from . import traffic_utils @@ -126,3 +128,32 @@ class AbstractTrafficGenerator(object): return: a list of speed in Gbps indexed by the port# """ + + def get_theoretical_rates(self, avg_packet_size): + + result = {} + + intf_speeds = self.get_port_speed_gbps() + tg_if_speed = bitmath.parse_string(str(intf_speeds[0]) + 'Gb').bits + intf_speed = tg_if_speed + + if hasattr(self.config, 'intf_speed') and self.config.intf_speed is not None: + # in case of limitation due to config, TG speed is not accurate + # value is overridden by conf + if self.config.intf_speed != tg_if_speed: + intf_speed = bitmath.parse_string(self.config.intf_speed.replace('ps', '')).bits + + if hasattr(self.config, 'user_info') and self.config.user_info is not None: + if "extra_encapsulation_bytes" in self.config.user_info: + frame_size_full_encapsulation = avg_packet_size + self.config.user_info[ + "extra_encapsulation_bytes"] + result['theoretical_tx_rate_pps'] = traffic_utils.bps_to_pps( + intf_speed, frame_size_full_encapsulation) * 2 + result['theoretical_tx_rate_bps'] = traffic_utils.pps_to_bps( + result['theoretical_tx_rate_pps'], avg_packet_size) + else: + result['theoretical_tx_rate_pps'] = traffic_utils.bps_to_pps(intf_speed, + avg_packet_size) * 2 + result['theoretical_tx_rate_bps'] = traffic_utils.pps_to_bps( + result['theoretical_tx_rate_pps'], avg_packet_size) + return result