Non Drop Rate Plugin API for ASTF¶
The following snippet shows a simple yet general implementation of the API. From the documentation we know that in case TRex runs into some error in a transmission it counts that transmission as invalid, and starts transmitting at a lower multiplier. However, in case some specific errors happen, there is no point into continuing. We can implement this using the following plugin. Also, we can use the plugin for the purpose of logging the errors.
import astf_path
class ErrorLogger():
def __init__(self, name, allowed_errors):
self.iteration_counter = 0
self.name = name
self.client_allowed_errors = set(allowed_errors['client'])
self.server_allowed_errors = set(allowed_errors['server'])
self.iteration_to_mult_map = {}
self.iteration_to_error_map = {}
def increment_iteration_counter(self):
self.iteration_counter += 1
def log(self, errors):
self.iteration_to_error_map[self.iteration_counter] = errors
def log_multiplier(self, mult):
self.iteration_to_mult_map[self.iteration_counter] = mult
def should_stop(self):
return self.iteration_counter == 5
def invalid_errors(self, errors):
client_errors = set(errors.get('client', []))
server_errors = set(errors.get('server', []))
return not (client_errors.issubset(self.client_allowed_errors) and server_errors.issubset(self.server_allowed_errors))
class ErrorLoggingNDRPlugin():
def __init__(self, **kwargs):
allowed_errors = {'client': {u'tcps_conndrops': u'embryonic connections dropped'},
'server': {u'err_no_template': u"server can't match L7 template",
u'err_no_syn': u'server first flow packet with no SYN'}
}
self.logger = ErrorLogger(name="Plugin Demonstration for ASTF NDR", allowed_errors=allowed_errors)
def pre_iteration(self, run_results=None, **kwargs):
pass
def post_iteration(self, run_results, **kwargs):
if run_results['error_flag']:
self.logger.log(run_results['errors'])
self.logger.log_multiplier(run_results['mult'])
self.logger.increment_iteration_counter()
should_stop = self.logger.should_stop()
invalid_errors = self.logger.invalid_errors(run_results['errors'])
return should_stop, invalid_errors
# dynamic load of python module
def register():
return ErrorLoggingNDRPlugin()
MyNDRPlugin class¶
- class trex.examples.astf.ndr_plugin.MyNDRPlugin[source]¶
- pre_iteration(run_results=None, **kwargs)[source]¶
Function ran before each iteration.
- Parameters
- run_results: dict
- A dictionary that contains the following keys (might be empty in case of first run):
queue_full_percentage: Percentage of packets that are queued.
error_flag: Whether there were errors in the previous run.
errors: The errors in the previous run.
rate_tx_bps: TX rate in bps.
rate_rx_bps: RX rate in bps.
tx_util: TX utilization percentage.
latency: Latency groups.
cpu_util: CPU utilization percentage.
tx_pps: TX in pps.
rx_pps: RX in pps.
tx_bps: TX in bps.
rx_bps: RX in bps.
bw_per_core: Bandwidth per core.
mult_p: Percentage of multiplier in the domain.
mult: Multiplier of CPS.
total_tx_L1: Total TX L1.
total_rx_L1: Total RX L1.
iteration: Iteration number.
Pay attention: The multiplier related fields are of the upcoming iteration. All the rest are of the previous iteration.
- kwargs: dict
List of tunables passed as parameters.
- post_iteration(run_results, **kwargs)[source]¶
Function ran after each iteration.
- Parameters
- run_results: dict
- A dictionary that contains the following keys:
queue_full_percentage: Percentage of packets that are queued.
error_flag: Whether there were errors in the previous run.
errors: The errors in the previous run.
rate_tx_bps: TX rate in bps.
rate_rx_bps: RX rate in bps.
tx_util: TX utilization percentage.
latency: Latency groups.
cpu_util: CPU utilization percentage.
tx_pps: TX in pps.
rx_pps: RX in pps.
tx_bps: TX in bps.
rx_bps: RX in bps.
bw_per_core: Bandwidth per core.
mult_p: Percentage of multiplier in the domain.
mult: Multiplier of CPS.
total_tx_L1: Total TX L1.
total_rx_L1: Total RX L1.
iteration: Iteration number.
- kwargs: dict
List of tunables passed as parameters.
- Returns
tuple of booleans: (should stop the benchmarking or not, invalid errors)