Code Review
/
csit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
feat(astf): Support framesizes for ASTF
[csit.git]
/
GPL
/
traffic_profiles
/
trex
/
profile_trex_astf_base_class.py
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
e36e52c
..
cb8fd76
100644
(file)
--- 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) 202
1
Cisco and/or its affiliates.
+# Copyright (c) 202
2
Cisco and/or its affiliates.
#
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
#
#
# 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):
@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
: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.
: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
# 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:
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
:returns: IP generator and profile templates or list of pcap files for
- traffic generator.
+
traffic generator.
:rtype: tuple
"""
raise NotImplementedError
:rtype: tuple
"""
raise NotImplementedError
@@
-108,15
+109,14
@@
class TrafficProfileBaseClass:
:returns: Traffic profile.
:rtype: trex.astf.trex_astf_profile.ASTFProfile
"""
: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,
profile = ASTFProfile(
default_ip_gen=ip_gen,
templates=templates,
- cap_list=cap_list
+ **kwargs
)
return profile
)
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
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"]
: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"
)
self._pcap_dir = kwargs.get(
u"pcap_dir", u"/opt/trex-core-2.88/scripts/avl"
)