+def get_load_from_rate(rate_str, avg_frame_size=64, line_rate='10Gbps'):
+ '''From any rate string (with unit) return the corresponding load (in % unit)
+
+ :param str rate_str: the rate to convert - must end with a unit (e.g. 1Mpps, 30%, 1Gbps)
+ :param int avg_frame_size: average frame size in bytes (needed only if pps is given)
+ :param str line_rate: line rate ending with bps unit (e.g. 1Mbps, 10Gbps) is the rate that
+ corresponds to 100% rate
+ :return float: the corresponding rate in % of line rate
+ '''
+ rate_dict = parse_rate_str(rate_str)
+ if 'rate_percent' in rate_dict:
+ return float(rate_dict['rate_percent'])
+ lr_bps = _get_bitmath_rate(line_rate).bits
+ if 'rate_bps' in rate_dict:
+ bps = int(rate_dict['rate_bps'])
+ else:
+ # must be rate_pps
+ pps = rate_dict['rate_pps']
+ bps = pps_to_bps(pps, avg_frame_size)
+ return bps_to_load(bps, lr_bps)