aboutsummaryrefslogtreecommitdiffstats
path: root/GPL/traffic_profiles/trex/profile_trex_astf_base_class.py
diff options
context:
space:
mode:
Diffstat (limited to 'GPL/traffic_profiles/trex/profile_trex_astf_base_class.py')
-rw-r--r--GPL/traffic_profiles/trex/profile_trex_astf_base_class.py44
1 files changed, 23 insertions, 21 deletions
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 427060ffee..55aedd0543 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,13 +127,15 @@ 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.86/scripts/avl"
+ u"pcap_dir", u"/opt/trex-core-3.03/scripts/avl"
)
return self.create_profile()