From 301d6ca6e36efdc5a1534615d57f3527560befad Mon Sep 17 00:00:00 2001 From: Yaroslav Brustinov Date: Tue, 23 Feb 2016 11:23:08 -0500 Subject: hltapi: add line rate and bps support --- .../stl/trex_stl_lib/trex_stl_hltapi.py | 40 ++++++++++++++-------- .../stl/trex_stl_lib/trex_stl_streams.py | 15 ++++---- 2 files changed, 32 insertions(+), 23 deletions(-) (limited to 'scripts/automation/trex_control_plane/stl') diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py index 581ea418..593c4c47 100755 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py @@ -27,9 +27,9 @@ traffic_config_kwargs = { 'port_handle2': None, # stream builder parameters 'transmit_mode': 'continuous', # ( continuous | multi_burst | single_burst ) - 'rate_pps': 1, # TODO: support bps and percent once stateless API will, use rate_percent by default + 'rate_pps': None, 'rate_bps': None, - 'rate_percent': 100, + 'rate_percent': 10, 'stream_id': None, 'name': None, 'bidirectional': 0, @@ -663,55 +663,67 @@ class CTRexHltApi(object): def STLHltStream(**user_kwargs): kwargs = merge_kwargs(traffic_config_kwargs, user_kwargs) + # verify rate is given by at most one arg + rate_args = set(['rate_pps', 'rate_bps', 'rate_percent']) + intersect_rate_args = list(rate_args & set(user_kwargs.keys())) + if len(intersect_rate_args) > 1: + raise STLError('More than one rate argument specified: %s' % intersect_rate_args) + try: + rate_key = intersect_rate_args[0] + except IndexError: + rate_key = 'rate_percent' + if kwargs['length_mode'] == 'imix': # several streams with given length streams_arr = [] user_kwargs['length_mode'] = 'fixed' if kwargs['l3_imix1_size'] < 32 or kwargs['l3_imix2_size'] < 32 or kwargs['l3_imix3_size'] < 32 or kwargs['l3_imix4_size'] < 32: raise STLError('l3_imix*_size should be at least 32') - total_rate = kwargs['l3_imix1_ratio'] + kwargs['l3_imix2_ratio'] + kwargs['l3_imix3_ratio'] + kwargs['l3_imix4_ratio'] - if total_rate == 0: + total_ratio = kwargs['l3_imix1_ratio'] + kwargs['l3_imix2_ratio'] + kwargs['l3_imix3_ratio'] + kwargs['l3_imix4_ratio'] + if total_ratio == 0: raise STLError('Used length_mode imix, but all the ratios are 0') save_to_yaml = kwargs.get('save_to_yaml') - rate_pps = float(kwargs['rate_pps']) + total_rate = float(kwargs[rate_key]) if kwargs['l3_imix1_ratio'] > 0: if save_to_yaml and type(save_to_yaml) is str: user_kwargs['save_to_yaml'] = save_to_yaml.replace('.yaml', '_imix1.yaml') user_kwargs['frame_size'] = kwargs['l3_imix1_size'] - user_kwargs['rate_pps'] = rate_pps * kwargs['l3_imix1_ratio'] / total_rate + user_kwargs[rate_key] = total_rate * kwargs['l3_imix1_ratio'] / total_ratio streams_arr.append(STLHltStream(**user_kwargs)) if kwargs['l3_imix2_ratio'] > 0: if save_to_yaml and type(save_to_yaml) is str: user_kwargs['save_to_yaml'] = save_to_yaml.replace('.yaml', '_imix2.yaml') user_kwargs['frame_size'] = kwargs['l3_imix2_size'] - user_kwargs['rate_pps'] = rate_pps * kwargs['l3_imix2_ratio'] / total_rate + user_kwargs[rate_key] = total_rate * kwargs['l3_imix2_ratio'] / total_ratio streams_arr.append(STLHltStream(**user_kwargs)) if kwargs['l3_imix3_ratio'] > 0: if save_to_yaml and type(save_to_yaml) is str: user_kwargs['save_to_yaml'] = save_to_yaml.replace('.yaml', '_imix3.yaml') user_kwargs['frame_size'] = kwargs['l3_imix3_size'] - user_kwargs['rate_pps'] = rate_pps * kwargs['l3_imix3_ratio'] / total_rate + user_kwargs[rate_key] = total_rate * kwargs['l3_imix3_ratio'] / total_ratio streams_arr.append(STLHltStream(**user_kwargs)) if kwargs['l3_imix4_ratio'] > 0: if save_to_yaml and type(save_to_yaml) is str: user_kwargs['save_to_yaml'] = save_to_yaml.replace('.yaml', '_imix4.yaml') user_kwargs['frame_size'] = kwargs['l3_imix4_size'] - user_kwargs['rate_pps'] = rate_pps * kwargs['l3_imix4_ratio'] / total_rate + user_kwargs[rate_key] = total_rate * kwargs['l3_imix4_ratio'] / total_ratio streams_arr.append(STLHltStream(**user_kwargs)) return streams_arr # packet generation packet = generate_packet(**user_kwargs) try: + # TODO: verify if bps is L1 or L2, use L2 for now + rate_types_dict = {'rate_pps': 'pps', 'rate_bps': 'bps_L2', 'rate_percent': 'percentage'} + rate_stateless = {rate_types_dict[rate_key]: float(kwargs[rate_key])} transmit_mode = kwargs['transmit_mode'] - rate_pps = kwargs['rate_pps'] pkts_per_burst = kwargs['pkts_per_burst'] if transmit_mode == 'continuous': - transmit_mode_class = STLTXCont(pps = rate_pps) + transmit_mode_class = STLTXCont(**rate_stateless) elif transmit_mode == 'single_burst': - transmit_mode_class = STLTXSingleBurst(pps = rate_pps, total_pkts = pkts_per_burst) + transmit_mode_class = STLTXSingleBurst(total_pkts = pkts_per_burst, **rate_stateless) elif transmit_mode == 'multi_burst': - transmit_mode_class = STLTXMultiBurst(pps = rate_pps, total_pkts = pkts_per_burst, - count = int(kwargs['burst_loop_count']), ibg = kwargs['inter_burst_gap']) + transmit_mode_class = STLTXMultiBurst(total_pkts = pkts_per_burst, count = int(kwargs['burst_loop_count']), + ibg = kwargs['inter_burst_gap'], **rate_stateless) else: raise STLError('transmit_mode %s not supported/implemented') except Exception as e: diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py index f79d25c3..df30db5f 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py @@ -64,9 +64,9 @@ class STLTXMode(object): # continuous mode class STLTXCont(STLTXMode): - def __init__ (self, pps = None, bps_L1 = None, bps_L2 = None, percentage = None): + def __init__ (self, **kwargs): - super(STLTXCont, self).__init__(pps, bps_L1, bps_L2, percentage) + super(STLTXCont, self).__init__(**kwargs) self.fields['type'] = 'continuous' @@ -76,12 +76,12 @@ class STLTXCont(STLTXMode): # single burst mode class STLTXSingleBurst(STLTXMode): - def __init__ (self, total_pkts = 1, pps = None, bps_L1 = None, bps_L2 = None, percentage = None): + def __init__ (self, total_pkts = 1, **kwargs): if not isinstance(total_pkts, int): raise STLArgumentError('total_pkts', total_pkts) - super(STLTXSingleBurst, self).__init__(pps, bps_L1, bps_L2, percentage) + super(STLTXSingleBurst, self).__init__(**kwargs) self.fields['type'] = 'single_burst' self.fields['total_pkts'] = total_pkts @@ -96,10 +96,7 @@ class STLTXMultiBurst(STLTXMode): pkts_per_burst = 1, ibg = 0.0, # usec not SEC count = 1, - pps = None, - bps_L1 = None, - bps_L2 = None, - percentage = None): + **kwargs): if not isinstance(pkts_per_burst, int): raise STLArgumentError('pkts_per_burst', pkts_per_burst) @@ -110,7 +107,7 @@ class STLTXMultiBurst(STLTXMode): if not isinstance(count, int): raise STLArgumentError('count', count) - super(STLTXMultiBurst, self).__init__(pps, bps_L1, bps_L2, percentage) + super(STLTXMultiBurst, self).__init__(**kwargs) self.fields['type'] = 'multi_burst' self.fields['pkts_per_burst'] = pkts_per_burst -- cgit 1.2.3-korg