diff options
author | Hanoh Haim <hhaim@cisco.com> | 2016-09-13 13:08:10 +0300 |
---|---|---|
committer | Hanoh Haim <hhaim@cisco.com> | 2016-09-13 19:37:29 +0300 |
commit | d510a8b0bbd930f062e2a8b03fad842e9905c259 (patch) | |
tree | 82ceee0004de8d6dc9100c8d68eb448b67cc8154 /scripts/automation | |
parent | 5defb8688cbd2dfda774ba1affff8392d7507429 (diff) |
add min/max to repeatable random inst
Diffstat (limited to 'scripts/automation')
-rwxr-xr-x | scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py index b97cc5f8..b6744d6a 100755 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py @@ -664,6 +664,66 @@ class STLVmFlowVar(CTRexVmDescBase): def get_var_name(self): return [self.name] +class STLVmFlowVarRepetableRandom(CTRexVmDescBase): + + def __init__(self, name, size=4, limit=100, seed=None): + """ + Flow variable instruction for repeatable random with limit number of generating numbers. Allocates memory on a stream context. + The size argument determines the variable size. Could be 1,2,,4 or 8 + + :parameters: + name : string + Name of the stream variable + + size : int + Number of bytes of the variable. Possible values: 1,2,4,8 for uint8_t, uint16_t, uint32_t, uint64_t + + limit : int + The number of distinct repetable random number + + seed : int + For deterministic result, you can set this to a uint16_t number + + .. code-block:: python + :caption: Example1 + + + # input , 1 byte or random with limit of 5 + STLVmFlowVarRepetableRandom("var1",size=1,limit=5) + + # output 255,1,7,129,8,255,1,7,129,8 + + """ + super(STLVmFlowVar, self).__init__() + self.name = name; + validate_type('name', name, str) + self.size =size + valid_fv_size(size) + self.limit =limit + + if seed == None: + self.seed = random.randint(1, 32000) + else: + self.seed = seed + + # choose default value for init val + if init_value == None: + init_value = max_value if op == "dec" else min_value + + self.init_value = convert_val (init_value) + self.min_value = convert_val (min_value); + self.max_value = convert_val (max_value) + self.step = convert_val (step) + + if self.min_value > self.max_value : + raise CTRexPacketBuildException(-11,("max %d is lower than min %d ") % (self.max_value,self.min_value) ); + + def get_obj (self): + return CTRexVmInsFlowVar(self.name,self.size,self.op,self.init_value,self.min_value,self.max_value,self.step); + + def get_var_name(self): + return [self.name] + class STLVmFixIpv4(CTRexVmDescBase): def __init__(self, offset): |