summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIdo Barnea <ibarnea@cisco.com>2016-02-21 18:36:02 +0200
committerIdo Barnea <ibarnea@cisco.com>2016-02-21 18:36:02 +0200
commit9264010486847b599cc31ef56f146a4d73737135 (patch)
treec12fec7e6ecb940b69dc49e4edbe7e108ddc50e9
parentd126c3bc9ab8d5e2008fbf7dfc7740b51bdd1640 (diff)
parent8fd2c69a3ba37d88949dc487f3851f84b81007a0 (diff)
Merge branch 'master' of csi-sceasr-b32:/auto/proj-pcube-b/apps/PL-b/tools/repo//trex-core
-rwxr-xr-xscripts/automation/regression/unit_tests/functional_tests/hltapi_stream_builder_test.py133
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py155
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py6
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py5
-rw-r--r--src/stateless/cp/trex_stream_vm.h16
5 files changed, 208 insertions, 107 deletions
diff --git a/scripts/automation/regression/unit_tests/functional_tests/hltapi_stream_builder_test.py b/scripts/automation/regression/unit_tests/functional_tests/hltapi_stream_builder_test.py
index 1f276cff..df93aba1 100755
--- a/scripts/automation/regression/unit_tests/functional_tests/hltapi_stream_builder_test.py
+++ b/scripts/automation/regression/unit_tests/functional_tests/hltapi_stream_builder_test.py
@@ -38,11 +38,10 @@ class CTRexHltApi_Test(unittest.TestCase):
with self.assertRaises(Exception):
STLHltStream(l2_encap = 'ethernet_sdfgsdfg')
# all default values
- test_stream = STLHltStream(name = 'stream-0')
+ test_stream = STLHltStream()
self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location())
self.golden_yaml = '''
-- name: stream-0
- stream:
+- stream:
action_count: 0
enabled: true
flags: 3
@@ -61,10 +60,10 @@ class CTRexHltApi_Test(unittest.TestCase):
split_by_var: ''
'''
- # Eth/IP/TCP, test L2 fields, wait for masking of variables for MAC
+ # Eth/IP/TCP, test MAC fields VM, wait for masking of variables for MAC
@nottest
- def test_l2_basic(self):
- test_stream = STLHltStream(name = 'stream-0')
+ def test_macs_vm(self):
+ test_stream = STLHltStream(name = 'stream-0', )
self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location())
self.golden_yaml = '''
TBD
@@ -93,10 +92,10 @@ TBD
ip_dst_addr = '5.5.5.5',
ip_dst_count = 2,
ip_dst_mode = 'random',
- name = 'stream-0')
+ name = 'test_ip_ranges')
self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location())
self.golden_yaml = '''
-- name: stream-0
+- name: test_ip_ranges
stream:
action_count: 0
enabled: true
@@ -151,10 +150,10 @@ TBD
tcp_dst_port_mode = 'random',
tcp_dst_port_count = 10,
tcp_dst_port = 1234,
- name = 'stream-0')
+ name = 'test_tcp_ranges')
self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location())
self.golden_yaml = '''
-- name: stream-0
+- name: test_tcp_ranges
stream:
action_count: 0
enabled: true
@@ -228,10 +227,10 @@ TBD
udp_dst_port_mode = 'increment',
udp_dst_port_count = 10,
udp_dst_port = 1234,
- name = 'stream-0')
+ name = 'test_udp_ranges')
self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location())
self.golden_yaml = '''
-- name: stream-0
+- name: test_udp_ranges
stream:
action_count: 0
enabled: true
@@ -288,10 +287,10 @@ TBD
test_stream = STLHltStream(length_mode = 'decrement',
frame_size_min = 100,
frame_size_max = 3000,
- name = 'stream-0')
+ name = 'test_pkt_len_by_framesize')
self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location())
self.golden_yaml = '''
-- name: stream-0
+- name: test_pkt_len_by_framesize
stream:
action_count: 0
enabled: true
@@ -334,10 +333,10 @@ TBD
length_mode = 'random',
l3_length_min = 100,
l3_length_max = 400,
- name = 'stream-0')
+ name = 'test_pkt_len_by_l3length')
self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location())
self.golden_yaml = '''
-- name: stream-0
+- name: test_pkt_len_by_l3length
stream:
action_count: 0
enabled: true
@@ -387,11 +386,11 @@ TBD
test_stream = STLHltStream(l2_encap = 'ethernet_ii')
assert ':802.1Q:' not in test_stream.get_pkt_type(), 'Default packet should not include dot1q'
- test_stream = STLHltStream(name = 'stream-0', l2_encap = 'ethernet_ii_vlan')
+ test_stream = STLHltStream(name = 'test_vlan_basic', l2_encap = 'ethernet_ii_vlan')
assert ':802.1Q:' in test_stream.get_pkt_type(), 'No dot1q in packet with encap ethernet_ii_vlan'
self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location())
self.golden_yaml = '''
-- name: stream-0
+- name: test_vlan_basic
stream:
action_count: 0
enabled: true
@@ -416,12 +415,14 @@ TBD
# default frame size should be not enough
with self.assertRaises(Exception):
STLHltStream(vlan_id = [1, 2, 3, 4])
- test_stream = STLHltStream(name = 'stream-0', frame_size = 100, vlan_id = [1, 2, 3, 4], vlan_protocol_tag_id = '8100 0x8100')
+ test_stream = STLHltStream(name = 'test_vlan_multiple', frame_size = 100,
+ vlan_id = [1, 2, 3, 4], # can be either array or string separated by spaces
+ vlan_protocol_tag_id = '8100 0x8100')
pkt_layers = test_stream.get_pkt_type()
- assert ':802.1Q:802.1Q:802.1Q:802.1Q:' in pkt_layers, 'No four dot1q layers in packet: %s' % pkt_layers
+ assert '802.1Q:' * 4 in pkt_layers, 'No four dot1q layers in packet: %s' % pkt_layers
self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location())
self.golden_yaml = '''
-- name: stream-0
+- name: test_vlan_multiple
stream:
action_count: 0
enabled: true
@@ -441,6 +442,84 @@ TBD
split_by_var: ''
'''
+ # Eth/IP/TCP, with 5 vlans and VMs on vlan_id
+ def test_vlan_vm(self):
+ test_stream = STLHltStream(name = 'test_vlan_vm', frame_size = 100,
+ vlan_id = '1 2 1000 4 5', # 5 vlans
+ vlan_id_mode = 'increment fixed decrement random', # 5th vlan will be default fixed
+ vlan_id_step = 2, # 1st vlan step will be 2, others - default 1
+ vlan_id_count = [4, 1, 10], # 4th independent on count, 5th will be fixed
+ )
+ pkt_layers = test_stream.get_pkt_type()
+ self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location())
+ assert '802.1Q:' * 5 in pkt_layers, 'No five dot1q layers in packet: %s' % pkt_layers
+ self.golden_yaml = '''
+- name: test_vlan_vm
+ stream:
+ action_count: 0
+ enabled: true
+ flags: 3
+ isg: 0.0
+ mode:
+ pps: 1
+ type: continuous
+ packet:
+ binary: AAAAAAAAAAABAAABgQAwAYEAMAKBADPogQAwBIEAMAUIAEUAAEIAAAAAQAa6tQAAAADAAAABBAAAUAAAAAEAAAABUAAP5SzkAAAhISEhISEhISEhISEhISEhISEhISEhISEhIQ==
+ meta: ''
+ rx_stats:
+ enabled: false
+ self_start: true
+ vm:
+ instructions:
+ - init_value: 1
+ max_value: 7
+ min_value: 1
+ name: vlan_id0
+ op: inc
+ size: 2
+ step: 2
+ type: flow_var
+ - is_big_endian: true
+ mask: 4095
+ name: vlan_id0
+ pkt_cast_size: 2
+ pkt_offset: 14
+ shift: 0
+ type: write_mask_flow_var
+ - init_value: 1000
+ max_value: 1000
+ min_value: 991
+ name: vlan_id2
+ op: dec
+ size: 2
+ step: 1
+ type: flow_var
+ - is_big_endian: true
+ mask: 4095
+ name: vlan_id2
+ pkt_cast_size: 2
+ pkt_offset: 22
+ shift: 0
+ type: write_mask_flow_var
+ - init_value: 0
+ max_value: 65535
+ min_value: 0
+ name: vlan_id3
+ op: random
+ size: 2
+ step: 1
+ type: flow_var
+ - is_big_endian: true
+ mask: 4095
+ name: vlan_id3
+ pkt_cast_size: 2
+ pkt_offset: 26
+ shift: 0
+ type: write_mask_flow_var
+ split_by_var: vlan_id2
+'''
+
+
# Eth/IPv6/TCP, no VM
def test_ipv6_basic(self):
# default frame size should be not enough
@@ -451,10 +530,10 @@ TBD
# error should affect
with self.assertRaises(Exception):
STLHltStream(l3_protocol = 'ipv6', ipv6_src_addr = 'asdfasdfasgasdf')
- test_stream = STLHltStream(name = 'stream-0', l3_protocol = 'ipv6', length_mode = 'fixed', l3_length = 150, )
+ test_stream = STLHltStream(name = 'test_ipv6_basic', l3_protocol = 'ipv6', length_mode = 'fixed', l3_length = 150, )
self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location())
self.golden_yaml = '''
-- name: stream-0
+- name: test_ipv6_basic
stream:
action_count: 0
enabled: true
@@ -476,7 +555,7 @@ TBD
# Eth/IPv6/UDP, VM on ipv6 fields
def test_ipv6_src_dst_ranges(self):
- test_stream = STLHltStream(name = 'stream-0', l3_protocol = 'ipv6', l3_length = 150, l4_protocol = 'udp',
+ test_stream = STLHltStream(name = 'test_ipv6_src_dst_ranges', l3_protocol = 'ipv6', l3_length = 150, l4_protocol = 'udp',
ipv6_src_addr = '1111:2222:3333:4444:5555:6666:7777:8888',
ipv6_dst_addr = '1111:1111:1111:1111:1111:1111:1111:1111',
ipv6_src_mode = 'increment', ipv6_src_step = 5, ipv6_src_count = 10,
@@ -484,7 +563,7 @@ TBD
)
self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location())
self.golden_yaml = '''
-- name: stream-0
+- name: test_ipv6_src_dst_ranges
stream:
action_count: 0
enabled: true
@@ -502,7 +581,7 @@ TBD
vm:
instructions:
- init_value: 2004322440
- max_value: 2004322489
+ max_value: 2004322485
min_value: 2004322440
name: ipv6_src
op: inc
@@ -516,7 +595,7 @@ TBD
type: write_flow_var
- init_value: 286331153
max_value: 286331153
- min_value: 286328604
+ min_value: 286328620
name: ipv6_dst
op: dec
size: 4
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 a3d4e319..60654f0a 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
@@ -756,18 +756,18 @@ def generate_packet(**user_kwargs):
# Eth VM
# WIP!!! Need 8 bytes mask and vars
if kwargs['mac_src_mode'] != 'fixed':
- mac_src_count = kwargs['mac_src_count']
- if mac_src_count < 1:
+ mac_src_count = kwargs['mac_src_count'] - 1
+ if mac_src_count < 0:
raise STLError('mac_src_count has to be at least 1')
- if mac_src_count > 1:
+ if mac_src_count > 0:
mac_src = mac_str_to_num(mac2str(kwargs['mac_src']))
if kwargs['mac_src_mode'] == 'increment':
vm_cmds.append(CTRexVmDescFlowVar(name = 'mac_src', size = 4, op = 'inc', step = kwargs['mac_src_step'],
min_value = mac_src,
- max_value = mac_src + mac_src_count * kwargs['mac_src_step'] - 1))
+ max_value = mac_src + mac_src_count * kwargs['mac_src_step']))
elif kwargs['mac_src_mode'] == 'decrement':
vm_cmds.append(CTRexVmDescFlowVar(name = 'mac_src', size = 4, op = 'dec', step = kwargs['mac_src_step'],
- min_value = mac_src - mac_src_count * kwargs['mac_src_step'] + 1,
+ min_value = mac_src - mac_src_count * kwargs['mac_src_step'],
max_value = mac_src))
elif kwargs['mac_src_mode'] == 'random':
vm_cmds.append(CTRexVmDescFlowVar(name = 'mac_src', size = 4, op = 'random', min_value = 0, max_value = 0xffffffffffffffff))
@@ -782,8 +782,9 @@ def generate_packet(**user_kwargs):
# BitField("vlan", 1, 12),
# XShortEnumField("type", 0x0000, ETHER_TYPES) ]
for i, vlan_kwargs in enumerate(split_vlan_args(kwargs)):
+ vlan_id = int(vlan_kwargs['vlan_id'])
dot1q_kwargs = {'prio': vlan_kwargs['vlan_user_priority'],
- 'vlan': vlan_kwargs['vlan_id'],
+ 'vlan': vlan_id,
'id': vlan_kwargs['vlan_cfi']}
vlan_protocol_tag_id = vlan_kwargs['vlan_protocol_tag_id']
if vlan_protocol_tag_id is not None:
@@ -793,26 +794,28 @@ def generate_packet(**user_kwargs):
l2_layer /= Dot1Q(**dot1q_kwargs)
# vlan VM
- if vlan_kwargs['vlan_id_mode'] != 'fixed':
- vlan_id_count = vlan_kwargs['vlan_id_count']
- if vlan_id_count < 1:
+ vlan_id_mode = vlan_kwargs['vlan_id_mode']
+ if vlan_id_mode != 'fixed':
+ vlan_id_count = int(vlan_kwargs['vlan_id_count']) - 1
+ if vlan_id_count < 0:
raise STLError('vlan_id_count has to be at least 1')
- if vlan_id_count > 1:
+ if vlan_id_count > 0 or vlan_id_mode == 'random':
var_name = 'vlan_id%s' % i
- if kwargs['vlan_id_mode'] == 'increment':
- vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'inc', step = vlan_kwargs['vlan_id_step'],
- min_value = kwargs['vlan_id'],
- max_value = kwargs['vlan_id'] + vlan_id_count * vlan_kwargs['vlan_id_step'] - 1))
- elif kwargs['vlan_id_mode'] == 'decrement':
- vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'dec', step = vlan_kwargs['vlan_id_step'],
- min_value = kwargs['vlan_id'] - vlan_id_count * vlan_kwargs['vlan_id_step'] + 1,
- max_value = kwargs['vlan_id']))
- elif kwargs['vlan_id_mode'] == 'random':
+ step = int(vlan_kwargs['vlan_id_step'])
+ if vlan_id_mode == 'increment':
+ vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'inc', step = step,
+ min_value = vlan_id,
+ max_value = vlan_id + vlan_id_count * step))
+ elif vlan_id_mode == 'decrement':
+ vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'dec', step = step,
+ min_value = vlan_id - vlan_id_count * step,
+ max_value = vlan_id))
+ elif vlan_id_mode == 'random':
vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'random', min_value = 0, max_value = 0xffff))
else:
- raise STLError('vlan_id_mode %s is not supported' % kwargs['vlan_id_mode'])
- vm_cmds.append(STLVmWrMaskFlowVar(fv_name = var_name, pkt_offset = 'Dot1Q:%s.vlan' % i,
- pkt_cast_size = 2, mask = 0x0fff))
+ raise STLError('vlan_id_mode %s is not supported' % vlan_id_mode)
+ vm_cmds.append(STLVmWrMaskFlowVar(fv_name = var_name, pkt_offset = '802|1Q:%s.vlan' % i,
+ pkt_cast_size = 2, mask = 0xfff))
else:
raise NotImplementedError("l2_encap does not support the desired encapsulation '%s'" % kwargs['l2_encap'])
@@ -847,20 +850,25 @@ def generate_packet(**user_kwargs):
)
# IPv4 VM
if kwargs['ip_src_mode'] != 'fixed':
- ip_src_count = kwargs['ip_src_count']
- if ip_src_count < 1:
+ ip_src_count = kwargs['ip_src_count'] - 1
+ if ip_src_count < 0:
raise STLError('ip_src_count has to be at least 1')
- if ip_src_count > 1:
+ if ip_src_count > 0:
fix_ipv4_checksum = True
- ip_src_addr_num = ipv4_str_to_num(is_valid_ipv4(kwargs['ip_src_addr']))
+ ip_src_addr = kwargs['ip_src_addr']
+ if type(ip_src_addr) is str:
+ ip_src_addr = ipv4_str_to_num(is_valid_ipv4(ip_src_addr))
+ ip_src_step = kwargs['ip_src_step']
+ if type(ip_src_step) is str:
+ ip_src_step = ipv4_str_to_num(is_valid_ipv4(ip_src_step))
if kwargs['ip_src_mode'] == 'increment':
- vm_cmds.append(CTRexVmDescFlowVar(name = 'ip_src', size = 4, op = 'inc', step = kwargs['ip_src_step'],
- min_value = ip_src_addr_num,
- max_value = ip_src_addr_num + ip_src_count * kwargs['ip_src_step'] - 1))
+ vm_cmds.append(CTRexVmDescFlowVar(name = 'ip_src', size = 4, op = 'inc', step = ip_src_step,
+ min_value = ip_src_addr,
+ max_value = ip_src_addr + ip_src_count * ip_src_step))
elif kwargs['ip_src_mode'] == 'decrement':
- vm_cmds.append(CTRexVmDescFlowVar(name = 'ip_src', size = 4, op = 'dec', step = kwargs['ip_src_step'],
- min_value = ip_src_addr_num - ip_src_count * kwargs['ip_src_step'] + 1,
- max_value = ip_src_addr_num))
+ vm_cmds.append(CTRexVmDescFlowVar(name = 'ip_src', size = 4, op = 'dec', step = ip_src_step,
+ min_value = ip_src_addr - ip_src_count * ip_src_step,
+ max_value = ip_src_addr))
elif kwargs['ip_src_mode'] == 'random':
vm_cmds.append(CTRexVmDescFlowVar(name = 'ip_src', size = 4, op = 'random', min_value = 0, max_value = 0xffffffff))
else:
@@ -868,20 +876,25 @@ def generate_packet(**user_kwargs):
vm_cmds.append(CTRexVmDescWrFlowVar(fv_name='ip_src', pkt_offset = 'IP.src'))
if kwargs['ip_dst_mode'] != 'fixed':
- ip_dst_count = kwargs['ip_dst_count']
- if ip_dst_count < 1:
+ ip_dst_count = kwargs['ip_dst_count'] - 1
+ if ip_dst_count < 0:
raise STLError('ip_dst_count has to be at least 1')
- if ip_dst_count > 1:
+ if ip_dst_count > 0:
fix_ipv4_checksum = True
- ip_dst_addr_num = ipv4_str_to_num(is_valid_ipv4(kwargs['ip_dst_addr']))
+ ip_dst_addr = kwargs['ip_dst_addr']
+ if type(ip_dst_addr) is str:
+ ip_dst_addr = ipv4_str_to_num(is_valid_ipv4(ip_dst_addr))
+ ip_dst_step = kwargs['ip_dst_step']
+ if type(ip_dst_step) is str:
+ ip_dst_step = ipv4_str_to_num(is_valid_ipv4(ip_dst_step))
if kwargs['ip_dst_mode'] == 'increment':
- vm_cmds.append(CTRexVmDescFlowVar(name = 'ip_dst', size = 4, op = 'inc', step = kwargs['ip_dst_step'],
- min_value = ip_dst_addr_num,
- max_value = ip_dst_addr_num + ip_dst_count * kwargs['ip_dst_step'] - 1))
+ vm_cmds.append(CTRexVmDescFlowVar(name = 'ip_dst', size = 4, op = 'inc', step = ip_dst_step,
+ min_value = ip_dst_addr,
+ max_value = ip_dst_addr + ip_dst_count * ip_dst_step))
elif kwargs['ip_dst_mode'] == 'decrement':
- vm_cmds.append(CTRexVmDescFlowVar(name = 'ip_dst', size = 4, op = 'dec', step = kwargs['ip_dst_step'],
- min_value = ip_dst_addr_num - ip_dst_count * kwargs['ip_dst_step'] + 1,
- max_value = ip_dst_addr_num))
+ vm_cmds.append(CTRexVmDescFlowVar(name = 'ip_dst', size = 4, op = 'dec', step = ip_dst_step,
+ min_value = ip_dst_addr - ip_dst_count * ip_dst_step,
+ max_value = ip_dst_addr))
elif kwargs['ip_dst_mode'] == 'random':
vm_cmds.append(CTRexVmDescFlowVar(name = 'ip_dst', size = 4, op = 'random', min_value = 0, max_value = 0xffffffff))
else:
@@ -909,9 +922,10 @@ def generate_packet(**user_kwargs):
# IPv6 VM
if kwargs['ipv6_src_mode'] != 'fixed':
- if kwargs['ipv6_src_count'] < 1:
+ ipv6_src_count = kwargs['ipv6_src_count'] - 1
+ if ipv6_src_count < 0:
raise STLError('ipv6_src_count has to be at least 1')
- if kwargs['ipv6_src_count'] > 1:
+ if ipv6_src_count > 0:
ipv6_src_addr_num = ipv4_str_to_num(is_valid_ipv6(kwargs['ipv6_src_addr'])[-4:])
ipv6_src_step = kwargs['ipv6_src_step']
if type(ipv6_src_step) is str: # convert ipv6 step to number
@@ -919,10 +933,10 @@ def generate_packet(**user_kwargs):
if kwargs['ipv6_src_mode'] == 'increment':
vm_cmds.append(CTRexVmDescFlowVar(name = 'ipv6_src', size = 4, op = 'inc', step = ipv6_src_step,
min_value = ipv6_src_addr_num,
- max_value = ipv6_src_addr_num + kwargs['ipv6_src_count'] * ipv6_src_step - 1))
+ max_value = ipv6_src_addr_num + ipv6_src_count * ipv6_src_step))
elif kwargs['ipv6_src_mode'] == 'decrement':
vm_cmds.append(CTRexVmDescFlowVar(name = 'ipv6_src', size = 4, op = 'dec', step = ipv6_src_step,
- min_value = ipv6_src_addr_num - kwargs['ipv6_src_count'] * ipv6_src_step + 1,
+ min_value = ipv6_src_addr_num - ipv6_src_count * ipv6_src_step,
max_value = ipv6_src_addr_num))
elif kwargs['ipv6_src_mode'] == 'random':
vm_cmds.append(CTRexVmDescFlowVar(name = 'ipv6_src', size = 4, op = 'random', min_value = 0, max_value = 0xffffffff))
@@ -931,9 +945,10 @@ def generate_packet(**user_kwargs):
vm_cmds.append(CTRexVmDescWrFlowVar(fv_name='ipv6_src', pkt_offset = 'IPv6.src', offset_fixup = 12))
if kwargs['ipv6_dst_mode'] != 'fixed':
- if kwargs['ipv6_dst_count'] < 1:
+ ipv6_dst_count = kwargs['ipv6_dst_count'] - 1
+ if ipv6_dst_count < 0:
raise STLError('ipv6_dst_count has to be at least 1')
- if kwargs['ipv6_dst_count'] > 1:
+ if ipv6_dst_count > 0:
ipv6_dst_addr_num = ipv4_str_to_num(is_valid_ipv6(kwargs['ipv6_dst_addr'])[-4:])
ipv6_dst_step = kwargs['ipv6_dst_step']
if type(ipv6_dst_step) is str: # convert ipv6 step to number
@@ -941,10 +956,10 @@ def generate_packet(**user_kwargs):
if kwargs['ipv6_dst_mode'] == 'increment':
vm_cmds.append(CTRexVmDescFlowVar(name = 'ipv6_dst', size = 4, op = 'inc', step = ipv6_dst_step,
min_value = ipv6_dst_addr_num,
- max_value = ipv6_dst_addr_num + kwargs['ipv6_dst_count'] * ipv6_dst_step - 1))
+ max_value = ipv6_dst_addr_num + ipv6_dst_count * ipv6_dst_step))
elif kwargs['ipv6_dst_mode'] == 'decrement':
vm_cmds.append(CTRexVmDescFlowVar(name = 'ipv6_dst', size = 4, op = 'dec', step = ipv6_dst_step,
- min_value = ipv6_dst_addr_num - kwargs['ipv6_dst_count'] * ipv6_dst_step + 1,
+ min_value = ipv6_dst_addr_num - ipv6_dst_count * ipv6_dst_step,
max_value = ipv6_dst_addr_num))
elif kwargs['ipv6_dst_mode'] == 'random':
vm_cmds.append(CTRexVmDescFlowVar(name = 'ipv6_dst', size = 4, op = 'random', min_value = 0, max_value = 0xffffffff))
@@ -988,18 +1003,18 @@ def generate_packet(**user_kwargs):
)
# TCP VM
if kwargs['tcp_src_port_mode'] != 'fixed':
- tcp_src_port_count = kwargs['tcp_src_port_count']
- if tcp_src_port_count < 1:
+ tcp_src_port_count = kwargs['tcp_src_port_count'] - 1
+ if tcp_src_port_count < 0:
raise STLError('tcp_src_port_count has to be at least 1')
- if tcp_src_port_count > 1:
+ if tcp_src_port_count > 0:
fix_ipv4_checksum = True
if kwargs['tcp_src_port_mode'] == 'increment':
vm_cmds.append(CTRexVmDescFlowVar(name = 'tcp_src', size = 2, op = 'inc', step = kwargs['tcp_src_port_step'],
min_value = kwargs['tcp_src_port'],
- max_value = kwargs['tcp_src_port'] + tcp_src_port_count * kwargs['tcp_src_port_step'] - 1))
+ max_value = kwargs['tcp_src_port'] + tcp_src_port_count * kwargs['tcp_src_port_step']))
elif kwargs['tcp_src_port_mode'] == 'decrement':
vm_cmds.append(CTRexVmDescFlowVar(name = 'tcp_src', size = 2, op = 'dec', step = kwargs['tcp_src_port_step'],
- min_value = kwargs['tcp_src_port'] - tcp_src_port_count * kwargs['tcp_src_port_step'] + 1,
+ min_value = kwargs['tcp_src_port'] - tcp_src_port_count * kwargs['tcp_src_port_step'],
max_value = kwargs['tcp_src_port']))
elif kwargs['tcp_src_port_mode'] == 'random':
vm_cmds.append(CTRexVmDescFlowVar(name = 'tcp_src', size = 2, op = 'random', min_value = 0, max_value = 0xffff))
@@ -1008,18 +1023,18 @@ def generate_packet(**user_kwargs):
vm_cmds.append(CTRexVmDescWrFlowVar(fv_name='tcp_src', pkt_offset = 'TCP.sport'))
if kwargs['tcp_dst_port_mode'] != 'fixed':
- tcp_dst_port_count = kwargs['tcp_dst_port_count']
- if tcp_dst_port_count < 1:
+ tcp_dst_port_count = kwargs['tcp_dst_port_count'] - 1
+ if tcp_dst_port_count < 0:
raise STLError('tcp_dst_port_count has to be at least 1')
- if tcp_dst_port_count > 1:
+ if tcp_dst_port_count > 0:
fix_ipv4_checksum = True
if kwargs['tcp_dst_port_mode'] == 'increment':
vm_cmds.append(CTRexVmDescFlowVar(name = 'tcp_dst', size = 2, op = 'inc', step = kwargs['tcp_dst_port_step'],
min_value = kwargs['tcp_dst_port'],
- max_value = kwargs['tcp_dst_port'] + tcp_dst_port_count * kwargs['tcp_dst_port_step'] - 1))
+ max_value = kwargs['tcp_dst_port'] + tcp_dst_port_count * kwargs['tcp_dst_port_step']))
elif kwargs['tcp_dst_port_mode'] == 'decrement':
vm_cmds.append(CTRexVmDescFlowVar(name = 'tcp_dst', size = 2, op = 'dec', step = kwargs['tcp_dst_port_step'],
- min_value = kwargs['tcp_dst_port'] - tcp_dst_port_count * kwargs['tcp_dst_port_step'] + 1,
+ min_value = kwargs['tcp_dst_port'] - tcp_dst_port_count * kwargs['tcp_dst_port_step'],
max_value = kwargs['tcp_dst_port']))
elif kwargs['tcp_dst_port_mode'] == 'random':
vm_cmds.append(CTRexVmDescFlowVar(name = 'tcp_dst', size = 2, op = 'random', min_value = 0, max_value = 0xffff))
@@ -1037,18 +1052,18 @@ def generate_packet(**user_kwargs):
len = kwargs['udp_length'], chksum = None)
# UDP VM
if kwargs['udp_src_port_mode'] != 'fixed':
- udp_src_port_count = kwargs['udp_src_port_count']
- if udp_src_port_count < 1:
+ udp_src_port_count = kwargs['udp_src_port_count'] - 1
+ if udp_src_port_count < 0:
raise STLError('udp_src_port_count has to be at least 1')
- if udp_src_port_count > 1:
+ if udp_src_port_count > 0:
fix_ipv4_checksum = True
if kwargs['udp_src_port_mode'] == 'increment':
vm_cmds.append(CTRexVmDescFlowVar(name = 'udp_src', size = 2, op = 'inc', step = kwargs['udp_src_port_step'],
min_value = kwargs['udp_src_port'],
- max_value = kwargs['udp_src_port'] + udp_src_port_count * kwargs['udp_src_port_step'] - 1))
+ max_value = kwargs['udp_src_port'] + udp_src_port_count * kwargs['udp_src_port_step']))
elif kwargs['udp_src_port_mode'] == 'decrement':
vm_cmds.append(CTRexVmDescFlowVar(name = 'udp_src', size = 2, op = 'dec', step = kwargs['udp_src_port_step'],
- min_value = kwargs['udp_src_port'] - udp_src_port_count * kwargs['udp_src_port_step'] + 1,
+ min_value = kwargs['udp_src_port'] - udp_src_port_count * kwargs['udp_src_port_step'],
max_value = kwargs['udp_src_port']))
elif kwargs['udp_src_port_mode'] == 'random':
vm_cmds.append(CTRexVmDescFlowVar(name = 'udp_src', size = 2, op = 'random', min_value = 0, max_value = 0xffff))
@@ -1057,18 +1072,18 @@ def generate_packet(**user_kwargs):
vm_cmds.append(CTRexVmDescWrFlowVar(fv_name='udp_src', pkt_offset = 'UDP.sport'))
if kwargs['udp_dst_port_mode'] != 'fixed':
- udp_dst_port_count = kwargs['udp_dst_port_count']
- if udp_dst_port_count < 1:
+ udp_dst_port_count = kwargs['udp_dst_port_count'] - 1
+ if udp_dst_port_count < 0:
raise STLError('udp_dst_port_count has to be at least 1')
- if udp_dst_port_count > 1:
+ if udp_dst_port_count > 0:
fix_ipv4_checksum = True
if kwargs['udp_dst_port_mode'] == 'increment':
vm_cmds.append(CTRexVmDescFlowVar(name = 'udp_dst', size = 2, op = 'inc', step = kwargs['udp_dst_port_step'],
min_value = kwargs['udp_dst_port'],
- max_value = kwargs['udp_dst_port'] + udp_dst_port_count * kwargs['udp_dst_port_step'] - 1))
+ max_value = kwargs['udp_dst_port'] + udp_dst_port_count * kwargs['udp_dst_port_step']))
elif kwargs['udp_dst_port_mode'] == 'decrement':
vm_cmds.append(CTRexVmDescFlowVar(name = 'udp_dst', size = 2, op = 'dec', step = kwargs['udp_dst_port_step'],
- min_value = kwargs['udp_dst_port'] - udp_dst_port_count * kwargs['udp_dst_port_step'] + 1,
+ min_value = kwargs['udp_dst_port'] - udp_dst_port_count * kwargs['udp_dst_port_step'],
max_value = kwargs['udp_dst_port']))
elif kwargs['udp_dst_port_mode'] == 'random':
vm_cmds.append(CTRexVmDescFlowVar(name = 'udp_dst', size = 2, op = 'random', min_value = 0, max_value = 0xffff))
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 fc4750c3..713769b6 100644
--- 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
@@ -222,12 +222,16 @@ class CTRexVmInsFlowVar(CTRexVmInsBase):
self.op = op
self.init_value = init_value
assert type(init_value)==int, 'type of init_value is not int'
+ assert init_value >= 0, 'init_value (%s) is negative' % init_value
self.min_value=min_value
assert type(min_value)==int, 'type of min_value is not int'
+ assert min_value >= 0, 'min_value (%s) is negative' % min_value
self.max_value=max_value
- assert type(max_value)==int, 'type of min_value is not int'
+ assert type(max_value)==int, 'type of max_value is not int'
+ assert max_value >= 0, 'max_value (%s) is negative' % max_value
self.step=step
assert type(step)==int, 'type of step should be int'
+ assert step >= 0, 'step (%s) is negative' % step
class CTRexVmInsWrFlowVar(CTRexVmInsBase):
def __init__(self, fv_name, pkt_offset, add_value=0, is_big_endian=True):
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py
index 0a6e64fb..aa09b0a1 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py
@@ -2,6 +2,7 @@
from collections import namedtuple
from utils.text_opts import *
from trex_stl_exceptions import *
+import types
RpcCmdData = namedtuple('RpcCmdData', ['method', 'params'])
TupleRC = namedtuple('RC', ['rc', 'data', 'is_warn'])
@@ -102,7 +103,9 @@ def RC_WARN (warn):
def validate_type(arg_name, arg, valid_types):
if type(valid_types) is list:
valid_types = tuple(valid_types)
- if type(valid_types) is type or type(valid_types) is tuple:
+ if (type(valid_types) is type or # single type, not array of types
+ type(valid_types) is tuple or # several valid types as tuple
+ type(valid_types) is types.ClassType): # old style class
if isinstance(arg, valid_types):
return
raise STLTypeError(arg_name, type(arg), valid_types)
diff --git a/src/stateless/cp/trex_stream_vm.h b/src/stateless/cp/trex_stream_vm.h
index 13504703..023286d0 100644
--- a/src/stateless/cp/trex_stream_vm.h
+++ b/src/stateless/cp/trex_stream_vm.h
@@ -227,7 +227,7 @@ public:
inline void run_inc(uint8_t * flow_var) {
uint8_t *p = (flow_var + m_flow_offset);
- if (*p >= (m_max_val-m_step)) {
+ if (*p > (m_max_val-m_step)) {
*p = m_min_val;
} else {
*p = *p + m_step;
@@ -236,7 +236,7 @@ public:
inline void run_dec(uint8_t * flow_var) {
uint8_t *p = (flow_var + m_flow_offset);
- if (*p <= (m_min_val+m_step)) {
+ if (*p < (m_min_val+m_step)) {
*p = m_max_val;
} else {
*p = *p - m_step;
@@ -257,7 +257,7 @@ public:
inline void run_inc(uint8_t * flow_var) {
uint16_t *p = (uint16_t *)(flow_var + m_flow_offset);
- if (*p >= (m_max_val-m_step)) {
+ if (*p > (m_max_val-m_step)) {
*p = m_min_val;
} else {
*p = *p + m_step;
@@ -266,7 +266,7 @@ public:
inline void run_dec(uint8_t * flow_var) {
uint16_t *p = (uint16_t *)(flow_var + m_flow_offset);
- if (*p <= (m_min_val+m_step)) {
+ if (*p < (m_min_val+m_step)) {
*p = m_max_val;
} else {
*p = *p - m_step;
@@ -286,7 +286,7 @@ public:
inline void run_inc(uint8_t * flow_var) {
uint32_t *p = (uint32_t *)(flow_var + m_flow_offset);
- if (*p >= (m_max_val-m_step)) {
+ if (*p > (m_max_val-m_step)) {
*p = m_min_val;
} else {
*p = *p + m_step;
@@ -295,7 +295,7 @@ public:
inline void run_dec(uint8_t * flow_var) {
uint32_t *p = (uint32_t *)(flow_var + m_flow_offset);
- if (*p <= (m_min_val+m_step)) {
+ if (*p < (m_min_val+m_step)) {
*p = m_max_val;
} else {
*p = *p - m_step;
@@ -315,7 +315,7 @@ public:
inline void run_inc(uint8_t * flow_var) {
uint64_t *p = (uint64_t *)(flow_var + m_flow_offset);
- if (*p >= (m_max_val-m_step) ) {
+ if (*p > (m_max_val-m_step) ) {
*p = m_min_val;
} else {
*p = *p + m_step;
@@ -324,7 +324,7 @@ public:
inline void run_dec(uint8_t * flow_var) {
uint64_t *p = (uint64_t *)(flow_var + m_flow_offset);
- if (*p <= m_min_val+m_step) {
+ if (*p < m_min_val+m_step) {
*p = m_max_val;
} else {
*p = *p - m_step;