X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=GPL%2Ftraffic_profiles%2Ftrex%2Fprofile_trex_astf_base_class.py;h=cb8fd763e641e397063cfae6848599d7fe7b7bd0;hp=e36e52c2c1cc5291725950786d1039822b83d2a0;hb=1daa6fdc0bae284dee1b61f34534e59b60b7526a;hpb=cd417be7f836eb9346fad4f87bd4f75dc1d9a429 diff --git a/GPL/traffic_profiles/trex/profile_trex_astf_base_class.py b/GPL/traffic_profiles/trex/profile_trex_astf_base_class.py index e36e52c2c1..cb8fd763e6 100644 --- a/GPL/traffic_profiles/trex/profile_trex_astf_base_class.py +++ b/GPL/traffic_profiles/trex/profile_trex_astf_base_class.py @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Cisco and/or its affiliates. +# Copyright (c) 2022 Cisco and/or its affiliates. # # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later # @@ -46,13 +46,9 @@ class TrafficProfileBaseClass: ] } - def __init__(self): - # Default values of required parameters; can be overwritten in - # "get_profile" method. - self.framesize = 64 - self._pcap_dir = u"" - - # If needed, add your own parameters. + # TODO: Declare and document fields in a contructor to make pylint happier. + # TODO: Consider passing the values to define_profile(), + # instead of keeping (and documenting) them as instance fields here. @property def pcap_dir(self): @@ -72,7 +68,7 @@ class TrafficProfileBaseClass: :param current_length: Current length of the packet. :param required_length: Required length of the packet. If set to 0 then - self.framesize value is used. + self.framesize value is used. :type current_length: int :type required_length: int :returns: The generated padding. @@ -82,20 +78,25 @@ class TrafficProfileBaseClass: # use random.randrange(0, len(self.STREAM_TABLE[self.framesize])) ? if not required_length: required_length = self.framesize - - return str(choices(ascii_letters, k=required_length - current_length)) + missing = required_length - current_length + if missing < 0: + msg = f"Cannot to pad from {current_length} to {required_length}." + raise RuntimeError(msg) + padding = u"".join(choices(ascii_letters, k=missing)) + return padding def define_profile(self): """Define profile to be used by T-Rex astf traffic generator. This method MUST return: - return ip_gen, templates, cap_list + return ip_gen, templates, kwargs - templates or cap_list CAN be None. + templates or kwargs CAN be None. + Kwargs can be used to define PCAP file, set MSS, ... :returns: IP generator and profile templates or list of pcap files for - traffic generator. + traffic generator. :rtype: tuple """ raise NotImplementedError @@ -108,15 +109,14 @@ class TrafficProfileBaseClass: :returns: Traffic profile. :rtype: trex.astf.trex_astf_profile.ASTFProfile """ - ip_gen, templates, cap_list = self.define_profile() - - # In most cases you will not have to change the code below: + ip_gen, templates, kwargs = self.define_profile() + if kwargs is None: + kwargs = dict() - # profile profile = ASTFProfile( default_ip_gen=ip_gen, templates=templates, - cap_list=cap_list + **kwargs ) return profile @@ -127,11 +127,13 @@ class TrafficProfileBaseClass: If needed, add your own parameters. :param kwargs: Key-value pairs used by "create_profile" method while - creating the profile. + creating the profile. + :type kwargs: dict :returns: Traffic profile. :rtype: trex.astf.trex_astf_profile.ASTFProfile """ self.framesize = kwargs[u"framesize"] + self.n_data_frames = kwargs[u"n_data_frames"] self._pcap_dir = kwargs.get( u"pcap_dir", u"/opt/trex-core-2.88/scripts/avl" )