+ def get_tx_pps_dropped_pps(self, tx_rate):
+ """Get actual tx packets based on requested tx rate.
+
+ :param tx_rate: requested TX rate with unit ('40%', '1Mbps', '1000pps')
+
+ :return: the actual TX pps and the dropped pps corresponding to the requested TX rate
+ """
+ dr, tx = self.__get_dr_actual_tx(tx_rate)
+ actual_tx_bps = utils.load_to_bps(tx, self.intf_speed)
+ avg_packet_size = utils.get_average_packet_size(self.l2_frame_size)
+ tx_packets = utils.bps_to_pps(actual_tx_bps, avg_packet_size)
+
+ dropped = tx_packets * dr / 100
+ # print '===get_tx_pkts_dropped_pkts req tex=', tx_rate, 'dr=', dr,
+ # 'actual tx rate=', tx, 'actual tx pkts=', tx_packets, 'dropped=', dropped
+ return int(tx_packets), int(dropped)
+
+ def set_response_curve(self, lr_dr=0, ndr=100, max_actual_tx=100, max_11_tx=100):
+ """Set traffic gen response characteristics.
+
+ Specifies the drop rate curve and the actual TX curve
+ :param float lr_dr: The actual drop rate at TX line rate (in %, 0..100)
+ :param float ndr: The true NDR (0 packet drop) in % (0..100) of line rate"
+ :param float max_actual_tx: highest actual TX when requested TX is 100%
+ :param float max_11_tx: highest requested TX that results in same actual TX
+ """
+ self.target_ndr = ndr
+ if ndr < 100:
+ self.dr_slope = float(lr_dr) / (100 - ndr)
+ else:
+ self.dr_slope = 0
+ self.max_11_tx = max_11_tx
+ self.max_actual_tx = max_actual_tx
+ if max_11_tx < 100:
+ self.tx_slope = float(max_actual_tx - max_11_tx) / (100 - max_11_tx)
+ else:
+ self.tx_slope = 0
+
+ def __get_dr_actual_tx(self, requested_tx_rate):
+ """Get drop rate at given requested tx rate.
+
+ :param float requested_tx_rate: requested tx rate in % (0..100)
+ :return: the drop rate and actual tx rate at that requested_tx_rate in % (0..100)
+ """
+ if requested_tx_rate <= self.max_11_tx:
+ actual_tx = requested_tx_rate
+ else:
+ actual_tx = self.max_11_tx + (requested_tx_rate - self.max_11_tx) * self.tx_slope
+ if actual_tx <= self.target_ndr:
+ dr = 0.0
+ else:
+ dr = (actual_tx - self.target_ndr) * self.dr_slope
+ return dr, actual_tx