From 68ebd739646a27f1bb92ce8eacb5bb76f6399580 Mon Sep 17 00:00:00 2001 From: Hanoh Haim Date: Tue, 23 Feb 2016 15:30:41 +0200 Subject: [PATCH] fix ipv4 checksum error in case of pkt_size>128 and field offset less than ip-header (fd.io issue - Miro) --- .../unit_tests/functional_tests/stl_basic_tests.py | 6 ++- scripts/exp/udp_1pkt_simple_test.pcap | Bin 0 -> 1474 bytes scripts/exp/udp_1pkt_simple_test2.pcap | Bin 0 -> 1474 bytes scripts/stl/udp_1pkt_simple_test.py | 43 +++++++++++++++++++++ scripts/stl/udp_1pkt_simple_test2.py | 43 +++++++++++++++++++++ src/stateless/cp/trex_stream.cpp | 2 + src/stateless/cp/trex_stream.h | 12 ++++-- src/stateless/cp/trex_stream_vm.cpp | 22 ++++++++++- src/stateless/cp/trex_stream_vm.h | 6 +++ 9 files changed, 126 insertions(+), 8 deletions(-) create mode 100644 scripts/exp/udp_1pkt_simple_test.pcap create mode 100644 scripts/exp/udp_1pkt_simple_test2.pcap create mode 100644 scripts/stl/udp_1pkt_simple_test.py create mode 100644 scripts/stl/udp_1pkt_simple_test2.py diff --git a/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py b/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py index e6a82cf1..6fb012ca 100644 --- a/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py +++ b/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py @@ -181,13 +181,15 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test): ["udp_1pkt_mac_step.py","-m 1 -l 20 ",True], ["udp_1pkt_mac_mask1.py","-m 1 -l 20 ",True] , ["udp_1pkt_mac_mask2.py","-m 1 -l 20 ",True], - ["udp_1pkt_mac_mask3.py","-m 1 -l 20 ",True] + ["udp_1pkt_mac_mask3.py","-m 1 -l 20 ",True], + ["udp_1pkt_simple_test2.py","-m 1 -l 10 ",True], # test split of packet with ip option + ["udp_1pkt_simple_test.py","-m 1 -l 10 ",True] ]; - p1 = [ ["udp_1pkt_mpls_vm.py","-m 1 ",True] ] + p1 = [ ["udp_1pkt_simple_test.py","-m 1 -l 10 ",True] ] for obj in p: diff --git a/scripts/exp/udp_1pkt_simple_test.pcap b/scripts/exp/udp_1pkt_simple_test.pcap new file mode 100644 index 0000000000000000000000000000000000000000..2eeec46275af4e2cba04aca240b2dfe3ff4a48d0 GIT binary patch literal 1474 zcmca|c+)~A1{MYwxWLZ9zzE|2=|(6P00Rjy;9ziLU?>JDa}cyG=K^Xl0Ae6uU}0q7 zVTgWSn3$BDlA4yDk(rg9lbe@cP*_x4Qd(ACQCa2a7_MFv<#m4&tDLgE)wFP(IK>oOEyyC$SF7 L13HL{4h{kUVYPRa literal 0 HcmV?d00001 diff --git a/scripts/exp/udp_1pkt_simple_test2.pcap b/scripts/exp/udp_1pkt_simple_test2.pcap new file mode 100644 index 0000000000000000000000000000000000000000..002d77dcbe23c7b428547e931d93c03f8f08ade2 GIT binary patch literal 1474 zcmca|c+)~A1{MYwxWLZ9zzE|2=|(6P00Rjy;9ziNU?>JDbI`O(5CCd00OACYE^`(K z5QPMokk}w5qZ?2aSg)Y%W-h2+Mn*;k7Dfgh2Ki+_5|ffsQq$5iGPAOCa`W;F3X6(M zO3TV&j-si9HUS;P1o8|K4uW}%rViQ&bPzL<4q}FeG)*0}0q7tWA{_)vRWx62 * */ + static inline uint16_t calc_writable_mbuf_size(uint16_t max_offset_writable, uint16_t pkt_size){ - if ( pkt_size<=64 ){ - return (pkt_size); - } if (pkt_size<=128) { return (pkt_size); } //pkt_size> 128 + // if reside is less than 64 keep it as a single packet uint16_t non_writable = pkt_size - (max_offset_writable +1) ; if ( non_writable<64 ) { return (pkt_size); } - return(max_offset_writable+1); + + // keep the r/w at least 60 byte + if ((max_offset_writable+1)<=60) { + return 60; + } + return max_offset_writable+1; } diff --git a/src/stateless/cp/trex_stream_vm.cpp b/src/stateless/cp/trex_stream_vm.cpp index f83025dd..b0cadfb6 100644 --- a/src/stateless/cp/trex_stream_vm.cpp +++ b/src/stateless/cp/trex_stream_vm.cpp @@ -396,8 +396,6 @@ void StreamVm::build_program(){ if (ins_type == StreamVmInstruction::itFIX_IPV4_CS) { StreamVmInstructionFixChecksumIpv4 *lpFix =(StreamVmInstructionFixChecksumIpv4 *)inst; - add_field_cnt(lpFix->m_pkt_offset +12); - if ( (lpFix->m_pkt_offset + IPV4_HDR_LEN) > m_pkt_size ) { std::stringstream ss; @@ -405,6 +403,26 @@ void StreamVm::build_program(){ err(ss.str()); } + uint16_t offset_next_layer = IPV4_HDR_LEN; + + if ( m_pkt ){ + IPHeader * ipv4= (IPHeader *)(m_pkt+lpFix->m_pkt_offset); + offset_next_layer = ipv4->getSize(); + } + + if (offset_next_layerm_pkt_offset + offset_next_layer) > m_pkt_size ) { + + std::stringstream ss; + ss << "instruction id '" << ins_id << "' fix ipv4 command offset " << lpFix->m_pkt_offset << "plus "<m_pkt_offset + offset_next_layer); + StreamDPOpIpv4Fix ipv_fix; ipv_fix.m_offset = lpFix->m_pkt_offset; ipv_fix.m_op = StreamDPVmInstructions::ditFIX_IPV4_CS; diff --git a/src/stateless/cp/trex_stream_vm.h b/src/stateless/cp/trex_stream_vm.h index 13504703..c16545d9 100644 --- a/src/stateless/cp/trex_stream_vm.h +++ b/src/stateless/cp/trex_stream_vm.h @@ -1408,6 +1408,7 @@ public: m_split_instr=NULL; m_is_compiled = false; + m_pkt=0; } @@ -1511,6 +1512,10 @@ public: /* raise exception */ void err(const std::string &err); + void set_pkt(uint8_t *pkt){ + m_pkt=pkt; + } + /** * return a pointer to a flow var / client var @@ -1565,6 +1570,7 @@ private: StreamDPVmInstructions m_instructions; StreamVmInstructionVar *m_split_instr; + uint8_t *m_pkt; -- 2.16.6