diff options
author | Hanoh Haim <hhaim@cisco.com> | 2016-02-03 16:40:50 +0200 |
---|---|---|
committer | Hanoh Haim <hhaim@cisco.com> | 2016-02-03 16:40:50 +0200 |
commit | 7447c92021d7ce3fc0fe115109b54a2f681f2392 (patch) | |
tree | b8020e34ee7eb1df3aba498f04d71ebcc927b8f5 /scripts/automation/regression/unit_tests | |
parent | 06facf16e0cc39f976bbd2896eb677a66e4f5c1a (diff) |
scapy with random packet size
Diffstat (limited to 'scripts/automation/regression/unit_tests')
-rw-r--r-- | scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py | 31 |
1 files changed, 31 insertions, 0 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): |