diff options
-rwxr-xr-x | scripts/automation/trex_control_plane/console/trex_console.py | 5 | ||||
-rw-r--r-- | scripts/run-gtest-clean | 3 | ||||
-rw-r--r-- | src/gtest/trex_stateless_gtest.cpp | 35 | ||||
-rwxr-xr-x | src/main_dpdk.cpp | 2 | ||||
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmd_stream.cpp | 44 | ||||
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmd_test.cpp | 5 | ||||
-rw-r--r-- | src/rpc-server/trex_rpc_cmd.cpp | 20 | ||||
-rw-r--r-- | src/rpc-server/trex_rpc_cmd_api.h | 3 | ||||
-rw-r--r-- | src/stateless/cp/trex_stream.cpp | 32 | ||||
-rw-r--r-- | src/stateless/cp/trex_stream.h | 6 | ||||
-rw-r--r-- | src/stateless/cp/trex_stream_vm.cpp | 7 | ||||
-rw-r--r-- | src/stateless/cp/trex_stream_vm.h | 10 | ||||
-rw-r--r-- | src/stateless/cp/trex_streams_compiler.cpp | 37 | ||||
-rw-r--r-- | src/stateless/cp/trex_streams_compiler.h | 9 |
14 files changed, 125 insertions, 93 deletions
diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py index 325ba514..f02652d0 100755 --- a/scripts/automation/trex_control_plane/console/trex_console.py +++ b/scripts/automation/trex_control_plane/console/trex_console.py @@ -474,6 +474,11 @@ class TRexConsole(TRexGeneralCmd): self.tui.show() self.stateless_client.set_verbose(save_verbose) + + def help_tui (self): + do_tui("-h") + + # quit function def do_quit(self, line): '''Exit the client\n''' diff --git a/scripts/run-gtest-clean b/scripts/run-gtest-clean index c3f6ef9c..99994e31 100644 --- a/scripts/run-gtest-clean +++ b/scripts/run-gtest-clean @@ -1,2 +1,3 @@ #! /bin/bash -valgrind --leak-check=full --show-reachable=yes ./bp-sim-64 --ut --gtest_filter="basic_stl.*" +valgrind --leak-check=full --show-reachable=yes ./bp-sim-64 --ut --gtest_filter="basic_*" + diff --git a/src/gtest/trex_stateless_gtest.cpp b/src/gtest/trex_stateless_gtest.cpp index 90dea72e..1626ac25 100644 --- a/src/gtest/trex_stateless_gtest.cpp +++ b/src/gtest/trex_stateless_gtest.cpp @@ -183,7 +183,7 @@ TEST_F(basic_vm, vm1) { vm.set_packet_size(128); - vm.compile_next(); + vm.compile(); uint32_t program_size=vm.get_dp_instruction_buffer()->get_program_size(); @@ -208,7 +208,7 @@ TEST_F(basic_vm, vm2) { vm.set_packet_size(128); - vm.compile_next(); + vm.compile(); uint32_t program_size=vm.get_dp_instruction_buffer()->get_program_size(); @@ -286,7 +286,7 @@ TEST_F(basic_vm, vm3) { vm.set_packet_size(128); - vm.compile_next(); + vm.compile(); uint32_t program_size=vm.get_dp_instruction_buffer()->get_program_size(); @@ -371,7 +371,7 @@ TEST_F(basic_vm, vm4) { vm.set_packet_size(128); - vm.compile_next(); + vm.compile(); uint32_t program_size=vm.get_dp_instruction_buffer()->get_program_size(); @@ -468,7 +468,7 @@ TEST_F(basic_vm, vm5) { vm.set_packet_size(128); - vm.compile_next(); + vm.compile(); uint32_t program_size=vm.get_dp_instruction_buffer()->get_program_size(); @@ -610,7 +610,7 @@ TEST_F(basic_vm, vm6) { vm.set_packet_size(128); - vm.compile_next(); + vm.compile(); uint32_t program_size=vm.get_dp_instruction_buffer()->get_program_size(); @@ -678,7 +678,7 @@ TEST_F(basic_vm, vm7) { vm.set_packet_size(128); - vm.compile_next(); + vm.compile(); uint32_t program_size=vm.get_dp_instruction_buffer()->get_program_size(); @@ -744,7 +744,7 @@ TEST_F(basic_vm, vm8) { vm.set_packet_size(128); - vm.compile_next(); + vm.compile(); uint32_t program_size=vm.get_dp_instruction_buffer()->get_program_size(); @@ -784,7 +784,8 @@ TEST_F(basic_vm, vm8) { } static void vm_build_program_seq(StreamVm & vm, - uint16_t packet_size ){ + uint16_t packet_size, + bool should_compile){ vm.add_instruction( new StreamVmInstructionFlowClient( "tuple_gen", 0x10000001, @@ -807,7 +808,9 @@ static void vm_build_program_seq(StreamVm & vm, vm.set_packet_size(packet_size); - vm.compile_next(); + if (should_compile) { + vm.compile(); + } } @@ -816,7 +819,7 @@ TEST_F(basic_vm, vm9) { StreamVm vm; - vm_build_program_seq(vm,128); + vm_build_program_seq(vm,128, true); printf(" max packet update %lu \n",(ulong)vm.get_max_packet_update_offset()); @@ -864,7 +867,7 @@ TEST_F(basic_vm, vm10) { StreamVm vm; - vm_build_program_seq(vm,128); + vm_build_program_seq(vm,128, true); printf(" max packet update %lu \n",(ulong)vm.get_max_packet_update_offset()); @@ -2047,16 +2050,14 @@ void CEnableVm::run(bool full_packet,double duration=10.0){ uint16_t pkt_size=pcap.m_raw.pkt_len; - stream1->m_has_vm = true; - vm_build_program_seq(stream1->m_vm,pkt_size); - stream1->post_vm_compile(); - + vm_build_program_seq(stream1->m_vm,pkt_size, false); + #if 0 if ( full_packet ){ EXPECT_EQ(stream1->m_vm_prefix_size,pkt_size); }else{ EXPECT_EQ(stream1->m_vm_prefix_size,35); } - + #endif streams.push_back(stream1); diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp index fc9dd00e..8c9eb914 100755 --- a/src/main_dpdk.cpp +++ b/src/main_dpdk.cpp @@ -2077,6 +2077,8 @@ int CCoreEthIF::send_pkt(CCorePerPort * lp_port, CVirtualIFPerSideStats * lp_stats ){ + //rte_pktmbuf_dump(stdout,m, rte_pktmbuf_pkt_len(m)); + lp_stats->m_tx_pkt +=1; lp_stats->m_tx_bytes += (rte_pktmbuf_pkt_len(m)+4); diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp index fa3d96b2..8b285c06 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp @@ -29,22 +29,6 @@ limitations under the License. using namespace std; -/** - * simple parser of string to number - * only difference is that it enforces whole number - * and not partial - * - */ -static uint64_t str2num(const string &str) { - size_t index; - - uint64_t num = std::stoull(str, &index, 0); - if (index != str.size()) { - throw invalid_argument("could not parse string to number"); - } - - return (num); -} /*************************** * add new stream @@ -213,31 +197,9 @@ TrexRpcCmdAddStream::parse_vm_instr_flow_var(const Json::Value &inst, TrexStream throw TrexRpcException("internal error"); } - std::string init_value_str = parse_string(inst, "init_value", result); - std::string min_value_str = parse_string(inst, "min_value", result); - std::string max_value_str = parse_string(inst, "max_value", result); - - uint64_t init_value = 0; - uint64_t min_value = 0; - uint64_t max_value = 0; - - try { - init_value = str2num(init_value_str); - } catch (invalid_argument) { - generate_parse_err(result, "failed to parse 'init_value' as a number"); - } - - try { - min_value = str2num(min_value_str); - } catch (invalid_argument) { - generate_parse_err(result, "failed to parse 'min_value' as a number"); - } - - try { - max_value = str2num(max_value_str); - } catch (invalid_argument) { - generate_parse_err(result, "failed to parse 'max_value' as a number"); - } + uint64_t init_value = parse_uint64(inst, "init_value", result); + uint64_t min_value = parse_uint64(inst, "min_value", result); + uint64_t max_value = parse_uint64(inst, "max_value", result); stream->m_vm.add_instruction(new StreamVmInstructionFlowMan(flow_var_name, flow_var_size, diff --git a/src/rpc-server/commands/trex_rpc_cmd_test.cpp b/src/rpc-server/commands/trex_rpc_cmd_test.cpp index 3cdddd31..ad4d3bb1 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_test.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_test.cpp @@ -21,6 +21,7 @@ limitations under the License. #include "trex_rpc_cmds.h" #include <iostream> #include <sstream> +#include <json/json.h> using namespace std; @@ -31,7 +32,7 @@ using namespace std; trex_rpc_cmd_rc_e TrexRpcCmdTestAdd::_run(const Json::Value ¶ms, Json::Value &result) { - result["result"] = parse_int(params, "x", result) + parse_int(params, "y", result); + result["result"] = Json::Value::UInt64(parse_uint64(params, "x", result) + parse_uint64(params, "y", result)); return (TREX_RPC_CMD_OK); } @@ -44,7 +45,7 @@ TrexRpcCmdTestAdd::_run(const Json::Value ¶ms, Json::Value &result) { trex_rpc_cmd_rc_e TrexRpcCmdTestSub::_run(const Json::Value ¶ms, Json::Value &result) { - result["result"] = parse_int(params, "x", result) - parse_int(params, "y", result); + result["result"] = Json::Value::UInt64(parse_uint64(params, "x", result) - parse_uint64(params, "y", result)); return (TREX_RPC_CMD_OK); } diff --git a/src/rpc-server/trex_rpc_cmd.cpp b/src/rpc-server/trex_rpc_cmd.cpp index d4eef1f7..fb31fa9d 100644 --- a/src/rpc-server/trex_rpc_cmd.cpp +++ b/src/rpc-server/trex_rpc_cmd.cpp @@ -98,6 +98,8 @@ TrexRpcCommand::type_to_str(field_type_e type) { return "uint16"; case FIELD_TYPE_UINT32: return "uint32"; + case FIELD_TYPE_UINT64: + return "uint64"; case FIELD_TYPE_BOOL: return "bool"; case FIELD_TYPE_INT: @@ -179,6 +181,18 @@ TrexRpcCommand::parse_uint32(const Json::Value &parent, int index, Json::Value & return parent[index].asUInt(); } +uint64_t +TrexRpcCommand::parse_uint64(const Json::Value &parent, const std::string &name, Json::Value &result) { + check_field_type(parent, name, FIELD_TYPE_UINT64, result); + return parent[name].asUInt64(); +} + +uint64_t +TrexRpcCommand::parse_uint64(const Json::Value &parent, int index, Json::Value &result) { + check_field_type(parent, index, FIELD_TYPE_UINT64, result); + return parent[index].asUInt64(); +} + int TrexRpcCommand::parse_int(const Json::Value &parent, const std::string &name, Json::Value &result) { check_field_type(parent, name, FIELD_TYPE_INT, result); @@ -274,6 +288,12 @@ TrexRpcCommand::check_field_type_common(const Json::Value &field, const std::str } break; + case FIELD_TYPE_UINT64: + if (!field.isInt64()) { + rc = false; + } + break; + case FIELD_TYPE_BOOL: if (!field.isBool()) { rc = false; diff --git a/src/rpc-server/trex_rpc_cmd_api.h b/src/rpc-server/trex_rpc_cmd_api.h index f81981d4..7cbdf4ff 100644 --- a/src/rpc-server/trex_rpc_cmd_api.h +++ b/src/rpc-server/trex_rpc_cmd_api.h @@ -100,6 +100,7 @@ protected: FIELD_TYPE_BYTE, FIELD_TYPE_UINT16, FIELD_TYPE_UINT32, + FIELD_TYPE_UINT64, FIELD_TYPE_INT, FIELD_TYPE_DOUBLE, FIELD_TYPE_BOOL, @@ -138,6 +139,7 @@ protected: uint8_t parse_byte(const Json::Value &parent, const std::string &name, Json::Value &result); uint16_t parse_uint16(const Json::Value &parent, const std::string &name, Json::Value &result); uint32_t parse_uint32(const Json::Value &parent, const std::string &name, Json::Value &result); + uint64_t parse_uint64(const Json::Value &parent, const std::string &name, Json::Value &result); int parse_int(const Json::Value &parent, const std::string &name, Json::Value &result); double parse_double(const Json::Value &parent, const std::string &name, Json::Value &result); bool parse_bool(const Json::Value &parent, const std::string &name, Json::Value &result); @@ -148,6 +150,7 @@ protected: uint8_t parse_byte(const Json::Value &parent, int index, Json::Value &result); uint16_t parse_uint16(const Json::Value &parent, int index, Json::Value &result); uint32_t parse_uint32(const Json::Value &parent, int index, Json::Value &result); + uint64_t parse_uint64(const Json::Value &parent, int index, Json::Value &result); int parse_int(const Json::Value &parent, int index, Json::Value &result); double parse_double(const Json::Value &parent, int index, Json::Value &result); bool parse_bool(const Json::Value &parent, int index, Json::Value &result); diff --git a/src/stateless/cp/trex_stream.cpp b/src/stateless/cp/trex_stream.cpp index ef718529..72e72c7c 100644 --- a/src/stateless/cp/trex_stream.cpp +++ b/src/stateless/cp/trex_stream.cpp @@ -53,19 +53,30 @@ std::string TrexStream::get_stream_type_str(stream_type_t stream_type){ } -void TrexStream::post_vm_compile(){ - /* if VM is enabled */ - if (is_vm()) { - m_vm_dp = m_vm.cloneAsVmDp(); +void +TrexStream::compile() { + /* in case there are no instructions - nothing to do */ + if (m_vm.is_vm_empty()) { + m_has_vm = false; + return; + } - /* calc m_vm_prefix_size which is the size of the writable packet */ - uint16_t max_pkt_offset = m_vm_dp->get_max_packet_update_offset(); - uint16_t pkt_size = m_pkt.len; + m_has_vm = true; - /* calculate the mbuf size that we should allocate */ - m_vm_prefix_size =calc_writable_mbuf_size(max_pkt_offset,pkt_size); - } + m_vm.set_packet_size(m_pkt.len); + + m_vm.compile(); + + m_vm_dp = m_vm.cloneAsVmDp(); + + + /* calc m_vm_prefix_size which is the size of the writable packet */ + uint16_t max_pkt_offset = m_vm_dp->get_max_packet_update_offset(); + uint16_t pkt_size = m_pkt.len; + + /* calculate the mbuf size that we should allocate */ + m_vm_prefix_size = calc_writable_mbuf_size(max_pkt_offset, pkt_size); } @@ -222,3 +233,4 @@ int TrexStreamTable::size() { return m_stream_table.size(); } + diff --git a/src/stateless/cp/trex_stream.h b/src/stateless/cp/trex_stream.h index 53b658fc..720246f6 100644 --- a/src/stateless/cp/trex_stream.h +++ b/src/stateless/cp/trex_stream.h @@ -229,6 +229,12 @@ public: void post_vm_compile(); + /** + * internal compilation of stream (for DP) + * + */ + void compile(); + public: /* basic */ uint8_t m_type; diff --git a/src/stateless/cp/trex_stream_vm.cpp b/src/stateless/cp/trex_stream_vm.cpp index 310a4369..e10e1a81 100644 --- a/src/stateless/cp/trex_stream_vm.cpp +++ b/src/stateless/cp/trex_stream_vm.cpp @@ -595,7 +595,7 @@ void StreamVm::build_bss() { -void StreamVm::compile_next() { +void StreamVm::compile() { /* build flow var offset table */ build_flow_var_table() ; @@ -613,11 +613,6 @@ void StreamVm::compile_next() { } -bool StreamVm::compile() { - - return (false); -} - StreamVm::~StreamVm() { for (auto inst : m_inst_list) { delete inst; diff --git a/src/stateless/cp/trex_stream_vm.h b/src/stateless/cp/trex_stream_vm.h index 0484693f..e65a87e3 100644 --- a/src/stateless/cp/trex_stream_vm.h +++ b/src/stateless/cp/trex_stream_vm.h @@ -927,6 +927,10 @@ public: } + bool is_vm_empty() { + return (m_inst_list.size() == 0); + } + /** * add new instruction to the VM * @@ -961,11 +965,7 @@ public: * return true of success, o.w false * */ - bool compile(); - - - void compile_next(); - + void compile(); ~StreamVm(); diff --git a/src/stateless/cp/trex_streams_compiler.cpp b/src/stateless/cp/trex_streams_compiler.cpp index 478e09f8..c4900e66 100644 --- a/src/stateless/cp/trex_streams_compiler.cpp +++ b/src/stateless/cp/trex_streams_compiler.cpp @@ -376,6 +376,26 @@ TrexStreamsCompiler::compile(uint8_t port_id, double factor, std::string *fail_msg) { + try { + return compile_internal(port_id,streams,objs,dp_core_count,factor,fail_msg); + } catch (const TrexException &ex) { + if (fail_msg) { + *fail_msg = ex.what(); + } else { + std::cout << ex.what(); + } + return false; + } + +} +bool +TrexStreamsCompiler::compile_internal(uint8_t port_id, + const std::vector<TrexStream *> &streams, + std::vector<TrexStreamsCompiledObj *> &objs, + uint8_t dp_core_count, + double factor, + std::string *fail_msg) { + #if 0 for (auto stream : streams) { stream->Dump(stdout); @@ -387,16 +407,7 @@ TrexStreamsCompiler::compile(uint8_t port_id, /* compile checks */ - try { - pre_compile_check(streams, nodes); - } catch (const TrexException &ex) { - if (fail_msg) { - *fail_msg = ex.what(); - } else { - std::cout << ex.what(); - } - return false; - } + pre_compile_check(streams, nodes); /* check if all are cont. streams */ bool all_continues = true; @@ -424,7 +435,6 @@ TrexStreamsCompiler::compile(uint8_t port_id, /* compile a single stream to all cores */ compile_stream(stream, factor, dp_core_count, objs, nodes); - } return true; @@ -457,6 +467,10 @@ TrexStreamsCompiler::compile_stream(const TrexStream *stream, double per_core_rate = (stream->m_pps * (factor / dp_core_count)); int per_core_burst_total_pkts = (stream->m_burst_total_pkts / dp_core_count); + /* compile VM */ + /* fix this const away problem */ + ((TrexStream *)stream)->compile(); + std::vector<TrexStream *> per_core_streams(dp_core_count); /* for each core - creates its own version of the stream */ @@ -486,6 +500,7 @@ TrexStreamsCompiler::compile_stream(const TrexStream *stream, } + /************************************** * streams graph *************************************/ diff --git a/src/stateless/cp/trex_streams_compiler.h b/src/stateless/cp/trex_streams_compiler.h index 7fe2dbf2..d2b0cd1d 100644 --- a/src/stateless/cp/trex_streams_compiler.h +++ b/src/stateless/cp/trex_streams_compiler.h @@ -103,6 +103,13 @@ public: private: + bool compile_internal(uint8_t port_id, + const std::vector<TrexStream *> &streams, + std::vector<TrexStreamsCompiledObj *> &objs, + uint8_t dp_core_count, + double factor, + std::string *fail_msg); + void pre_compile_check(const std::vector<TrexStream *> &streams, GraphNodeMap & nodes); void allocate_pass(const std::vector<TrexStream *> &streams, GraphNodeMap *nodes); @@ -118,6 +125,8 @@ private: std::vector<TrexStreamsCompiledObj *> &objs, GraphNodeMap &nodes); + void compile_stream_vm(TrexStream *stream); + std::vector<std::string> m_warnings; }; |