summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHanoh Haim <hhaim@cisco.com>2016-02-03 16:40:50 +0200
committerHanoh Haim <hhaim@cisco.com>2016-02-03 16:40:50 +0200
commit7447c92021d7ce3fc0fe115109b54a2f681f2392 (patch)
treeb8020e34ee7eb1df3aba498f04d71ebcc927b8f5
parent06facf16e0cc39f976bbd2896eb677a66e4f5c1a (diff)
scapy with random packet size
-rw-r--r--scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py31
-rw-r--r--scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py5
2 files changed, 34 insertions, 2 deletions
diff --git a/scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py b/scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py
index e288e548..6b4c9002 100644
--- a/scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py
+++ b/scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py
@@ -215,7 +215,38 @@ class CTRexPktBuilderSanitySCapy_Test(pkt_bld_general_test.CGeneralPktBld_Test):
assert_equal(d['instructions'][1]['pkt_offset'],30)
assert_equal(d['instructions'][3]['pkt_offset'],38)
+ def test_simple_random_pkt_size(self):
+
+ ip_pkt_size = 9*1024
+ p_l2 = Ether();
+ p_l3 = IP(src="16.0.0.1",dst="48.0.0.1")
+ p_l4 = UDP(dport=12,sport=1025)
+ pyld_size = ip_pkt_size-len(p_l3/p_l4);
+
+ pkt =p_l2/p_l3/p_l4/('\x55'*(pyld_size))
+
+ l3_len_fix =-(len(p_l2));
+ l4_len_fix =-(len(p_l2/p_l3));
+
+ vm = CTRexScRaw( [ CTRexVmDescFlowVar(name="fv_rand", min_value=64, max_value=len(pkt), size=2, op="random"),
+ CTRexVmDescTrimPktSize("fv_rand"), # total packet size
+ CTRexVmDescWrFlowVar(fv_name="fv_rand", pkt_offset= "IP.len", add_val=l3_len_fix),
+ CTRexVmDescFixIpv4(offset = "IP"), # fix checksum
+ CTRexVmDescWrFlowVar(fv_name="fv_rand", pkt_offset= "UDP.len", add_val=l4_len_fix)
+ ]
+ )
+ pkt_builder = CScapyTRexPktBuilder();
+
+ # set packet
+ pkt_builder.set_packet(pkt);
+ pkt_builder.add_command ( vm )
+ pkt_builder.compile();
+ d= pkt_builder.get_vm_data()
+ pkt_builder.dump_vm_data_as_yaml()
+ assert_equal(d['instructions'][0]['max_value'],9230)
+ assert_equal(d['instructions'][2]['pkt_offset'],16)
+ assert_equal(d['instructions'][4]['pkt_offset'],38)
def tearDown(self):
diff --git a/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py b/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py
index 0dbb9826..d3a5605b 100644
--- a/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py
+++ b/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py
@@ -501,7 +501,7 @@ class CTRexVmDescFlowVar(CTRexVmDescBase):
return CTRexVmInsFlowVar(self.name,self.size,self.op,self.init_value,self.min_value,self.max_value);
def get_var_name(self):
- return (self.name)
+ return [self.name]
class CTRexVmDescFixIpv4(CTRexVmDescBase):
@@ -572,7 +572,7 @@ class CTRexVmDescTupleGen(CTRexVmDescBase):
check_for_int(flags)
def get_var_name(self):
- return (self.name+".ip",self.name+".port")
+ return [self.name+".ip",self.name+".port"]
def get_obj (self):
return CTRexVmInsTupleGen(self.name, self.ip_min, self.ip_max, self.port_min, self.port_max, self.limit_flows, self.flags);
@@ -689,6 +689,7 @@ class CScapyTRexPktBuilder(object):
var_names = desc.get_var_name()
if var_names :
+ print var_names
for var_name in var_names:
if vars.has_key(var_name):
raise CTRexPacketBuildException(-11,("variable %s define twice ") % (var_name) );