From b77fef12a08d6d964e522eea6b2d846dfcc98b08 Mon Sep 17 00:00:00 2001 From: imarom Date: Mon, 26 Oct 2015 18:13:18 +0200 Subject: RPC control plane now integarted with DPDK --- src/mock/trex_platform_api_mock.cpp | 49 +++++++++++++++++ src/mock/trex_rpc_server_mock.cpp | 104 +++++++++++++++++++++++++++++++----- 2 files changed, 140 insertions(+), 13 deletions(-) create mode 100644 src/mock/trex_platform_api_mock.cpp (limited to 'src/mock') diff --git a/src/mock/trex_platform_api_mock.cpp b/src/mock/trex_platform_api_mock.cpp new file mode 100644 index 00000000..54f71e10 --- /dev/null +++ b/src/mock/trex_platform_api_mock.cpp @@ -0,0 +1,49 @@ +/* + Itay Marom + Cisco Systems, Inc. +*/ + +/* +Copyright (c) 2015-2015 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include + +void +TrexMockPlatformApi::get_global_stats(TrexPlatformGlobalStats &stats) const { + + stats.m_stats.m_cpu_util = 0; + + stats.m_stats.m_tx_bps = 0; + stats.m_stats.m_tx_pps = 0; + stats.m_stats.m_total_tx_pkts = 0; + stats.m_stats.m_total_tx_bytes = 0; + + stats.m_stats.m_rx_bps = 0; + stats.m_stats.m_rx_pps = 0; + stats.m_stats.m_total_rx_pkts = 0; + stats.m_stats.m_total_rx_bytes = 0; +} + +void +TrexMockPlatformApi::get_interface_stats(uint8_t interface_id, TrexPlatformInterfaceStats &stats) const { + +} + +uint8_t +TrexMockPlatformApi::get_dp_core_count() const { + return (1); +} + diff --git a/src/mock/trex_rpc_server_mock.cpp b/src/mock/trex_rpc_server_mock.cpp index de43f92f..6e14390a 100644 --- a/src/mock/trex_rpc_server_mock.cpp +++ b/src/mock/trex_rpc_server_mock.cpp @@ -23,10 +23,65 @@ limitations under the License. #include #include +#include #include +#include +#include using namespace std; +static TrexStateless *g_trex_stateless; +static uint16_t g_rpc_port; + +static bool +verify_tcp_port_is_free(uint16_t port) { + void *m_context = zmq_ctx_new(); + void *m_socket = zmq_socket (m_context, ZMQ_REP); + std::stringstream ss; + ss << "tcp://*:"; + ss << port; + + int rc = zmq_bind (m_socket, ss.str().c_str()); + + zmq_close(m_socket); + zmq_term(m_context); + + return (rc == 0); +} + +static uint16_t +find_free_tcp_port(uint16_t start_port = 5050) { + void *m_context = zmq_ctx_new(); + void *m_socket = zmq_socket (m_context, ZMQ_REP); + + uint16_t port = start_port; + while (true) { + std::stringstream ss; + ss << "tcp://*:"; + ss << port; + + int rc = zmq_bind (m_socket, ss.str().c_str()); + if (rc == 0) { + break; + } + + port++; + } + + zmq_close(m_socket); + zmq_term(m_context); + + return port; +} + +TrexStateless * get_stateless_obj() { + return g_trex_stateless; +} + +uint16_t gtest_get_mock_server_port() { + return g_rpc_port; +} + /** * on simulation this is not rebuild every version * (improved stub) @@ -42,44 +97,66 @@ extern "C" const char * get_build_time(void){ int gtest_main(int argc, char **argv); -int main(int argc, char *argv[]) { +static bool parse_uint16(const string arg, uint16_t &port) { + stringstream ss(arg); + + bool x = (ss >> port); + + return (x); +} +int main(int argc, char *argv[]) { bool is_gtest = false; // gtest ? if (argc > 1) { - if (string(argv[1]) != "--ut") { - cout << "\n[Usage] " << argv[0] << ": " << " [--ut]\n\n"; + string arg = string(argv[1]); + + if (arg == "--ut") { + g_rpc_port = find_free_tcp_port(); + is_gtest = true; + } else if (parse_uint16(arg, g_rpc_port)) { + bool rc = verify_tcp_port_is_free(g_rpc_port); + if (!rc) { + cout << "port " << g_rpc_port << " is not available to use\n"; + exit(-1); + } + } else { + + cout << "\n[Usage] " << argv[0] << ": " << " [--ut] or [port number < 65535]\n\n"; exit(-1); } - is_gtest = true; + + } else { + g_rpc_port = find_free_tcp_port(); } /* configure the stateless object with 4 ports */ TrexStatelessCfg cfg; - TrexRpcServerConfig rpc_req_resp_cfg(TrexRpcServerConfig::RPC_PROT_TCP, 5050); - TrexRpcServerConfig rpc_async_cfg(TrexRpcServerConfig::RPC_PROT_TCP, 5051); + TrexRpcServerConfig rpc_req_resp_cfg(TrexRpcServerConfig::RPC_PROT_TCP, g_rpc_port); + //TrexRpcServerConfig rpc_async_cfg(TrexRpcServerConfig::RPC_PROT_TCP, 5051); cfg.m_port_count = 4; - cfg.m_dp_core_count = 2; cfg.m_rpc_req_resp_cfg = &rpc_req_resp_cfg; - cfg.m_rpc_async_cfg = &rpc_async_cfg; + cfg.m_rpc_async_cfg = NULL; cfg.m_rpc_server_verbose = (is_gtest ? false : true); + cfg.m_platform_api = new TrexMockPlatformApi(); - TrexStateless::configure(cfg); + g_trex_stateless = new TrexStateless(cfg); - TrexStateless::get_instance().launch_control_plane(); + g_trex_stateless->launch_control_plane(); /* gtest handling */ if (is_gtest) { int rc = gtest_main(argc, argv); - TrexStateless::destroy(); + delete g_trex_stateless; + g_trex_stateless = NULL; return rc; } cout << "\n-= Starting RPC Server Mock =-\n\n"; - cout << "Listening on tcp://localhost:5050 [ZMQ]\n\n"; + cout << "Listening on tcp://localhost:" << g_rpc_port << " [ZMQ]\n\n"; cout << "Server Started\n\n"; @@ -87,6 +164,7 @@ int main(int argc, char *argv[]) { sleep(1); } - TrexStateless::destroy(); + delete g_trex_stateless; + g_trex_stateless = NULL; } -- cgit From ea0b6efc3a41f425e46d81f4b6b8bbbf3238add1 Mon Sep 17 00:00:00 2001 From: imarom Date: Tue, 27 Oct 2015 19:25:03 +0200 Subject: working cont. stream on 1 core --- src/mock/trex_rpc_server_mock.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/mock') diff --git a/src/mock/trex_rpc_server_mock.cpp b/src/mock/trex_rpc_server_mock.cpp index 6e14390a..6642e50e 100644 --- a/src/mock/trex_rpc_server_mock.cpp +++ b/src/mock/trex_rpc_server_mock.cpp @@ -82,6 +82,24 @@ uint16_t gtest_get_mock_server_port() { return g_rpc_port; } +void delay(int msec){ + + if (msec == 0) + {//user that requested that probebly wanted the minimal delay + //but because of scaling problem he have got 0 so we will give the min delay + //printf("\n\n\nERROR-Task delay ticks == 0 found in task %s task id = %d\n\n\n\n", + // SANB_TaskName(SANB_TaskIdSelf()), SANB_TaskIdSelf()); + msec =1; + + } + + struct timespec time1, remain; // 2 sec max delay + time1.tv_sec=msec/1000; + time1.tv_nsec=(msec - (time1.tv_sec*1000))*1000000; + + nanosleep(&time1,&remain); +} + /** * on simulation this is not rebuild every version * (improved stub) -- cgit From 788ba38b545be2f76f290f73b16cbfc37f4fa187 Mon Sep 17 00:00:00 2001 From: imarom Date: Wed, 28 Oct 2015 14:47:56 +0200 Subject: moved all stream compiling phase to a new file trex_streams_compiler.cpp --- src/mock/trex_rpc_server_mock.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/mock') diff --git a/src/mock/trex_rpc_server_mock.cpp b/src/mock/trex_rpc_server_mock.cpp index 6642e50e..8bbcbf5b 100644 --- a/src/mock/trex_rpc_server_mock.cpp +++ b/src/mock/trex_rpc_server_mock.cpp @@ -21,12 +21,16 @@ limitations under the License. #include #include +#include + +#include #include #include #include #include #include +#include using namespace std; @@ -123,9 +127,30 @@ static bool parse_uint16(const string arg, uint16_t &port) { return (x); } +static void +run_dummy_core() { + //TODO: connect this to the scheduler + + //CFlowGenList fl; + //fl.Create(); + //CFlowGenListPerThread *lp = new CFlowGenListPerThread(); + //lp->Create(0, 0, NULL, 0); + //TrexStatelessDpCore dummy_core(0, lp); + //lp->start_stateless_daemon(); +} + int main(int argc, char *argv[]) { bool is_gtest = false; + time_init(); + CGlobalInfo::m_socket.Create(0); + + CGlobalInfo::init_pools(1000); + assert( CMsgIns::Ins()->Create(1)); + + std::thread *m_thread = new std::thread(run_dummy_core); + (void)m_thread; + // gtest ? if (argc > 1) { string arg = string(argv[1]); -- cgit From ee2c7f45e0bf973443b70eb8329811bcad44f83a Mon Sep 17 00:00:00 2001 From: imarom Date: Sun, 1 Nov 2015 14:28:28 +0200 Subject: stateless cores starts on IDLE - and starts the scheduler only when traffic is being transmitted if the traffic stops completely on the core - back to IDLE state --- src/mock/trex_rpc_server_mock.cpp | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'src/mock') diff --git a/src/mock/trex_rpc_server_mock.cpp b/src/mock/trex_rpc_server_mock.cpp index 8bbcbf5b..0bdf6cf1 100644 --- a/src/mock/trex_rpc_server_mock.cpp +++ b/src/mock/trex_rpc_server_mock.cpp @@ -86,24 +86,6 @@ uint16_t gtest_get_mock_server_port() { return g_rpc_port; } -void delay(int msec){ - - if (msec == 0) - {//user that requested that probebly wanted the minimal delay - //but because of scaling problem he have got 0 so we will give the min delay - //printf("\n\n\nERROR-Task delay ticks == 0 found in task %s task id = %d\n\n\n\n", - // SANB_TaskName(SANB_TaskIdSelf()), SANB_TaskIdSelf()); - msec =1; - - } - - struct timespec time1, remain; // 2 sec max delay - time1.tv_sec=msec/1000; - time1.tv_nsec=(msec - (time1.tv_sec*1000))*1000000; - - nanosleep(&time1,&remain); -} - /** * on simulation this is not rebuild every version * (improved stub) -- cgit