summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-02-25 09:54:45 -0500
committerimarom <imarom@cisco.com>2016-02-25 09:57:23 -0500
commitaaef3f95683bfa1574537c543e4ffc86afb0480f (patch)
tree01bf5d21786fb59d13338a75b644eb0fa9a5f20d /src
parented7c04b5d7d5bb15aa13144e62caa786e73f7d05 (diff)
port attributes - promiscuous and etc.
Diffstat (limited to 'src')
-rw-r--r--src/internal_api/trex_platform_api.h76
-rw-r--r--src/main_dpdk.cpp9
-rw-r--r--src/mock/rte_ethdev.h44
-rw-r--r--src/mock/trex_platform_api_mock.cpp54
-rw-r--r--src/mock/trex_rpc_server_mock.cpp191
-rw-r--r--src/rpc-server/commands/trex_rpc_cmd_general.cpp36
-rw-r--r--src/rpc-server/commands/trex_rpc_cmds.h2
-rw-r--r--src/rpc-server/trex_rpc_cmds_table.cpp1
-rw-r--r--src/sim/trex_sim.h45
-rw-r--r--src/stateless/cp/trex_stateless_port.cpp19
-rw-r--r--src/stateless/cp/trex_stateless_port.h9
11 files changed, 126 insertions, 360 deletions
diff --git a/src/internal_api/trex_platform_api.h b/src/internal_api/trex_platform_api.h
index 831fd778..249adb2f 100644
--- a/src/internal_api/trex_platform_api.h
+++ b/src/internal_api/trex_platform_api.h
@@ -127,7 +127,9 @@ public:
virtual void get_port_num(uint8_t &port_num) const = 0;
virtual int add_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const = 0;
virtual int del_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const = 0;
-
+ virtual void set_promiscuous(uint8_t port_id, bool enabled) const = 0;
+ virtual bool get_promiscuous(uint8_t port_id) const = 0;
+
virtual ~TrexPlatformApi() {}
};
@@ -155,36 +157,66 @@ public:
void get_port_num(uint8_t &port_num) const;
int add_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const;
int del_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const;
+ void set_promiscuous(uint8_t port_id, bool enabled) const;
+ bool get_promiscuous(uint8_t port_id) const;
};
+
/**
- * MOCK implementation of the platform API
+ * for simulation
*
- * @author imarom (26-Oct-15)
+ * @author imarom (25-Feb-16)
*/
-class TrexMockPlatformApi : public TrexPlatformApi {
+class SimPlatformApi : public TrexPlatformApi {
public:
- void port_id_to_cores(uint8_t port_id, std::vector<std::pair<uint8_t, uint8_t>> &cores_id_list) const;
- void get_global_stats(TrexPlatformGlobalStats &stats) const;
- void get_interface_stats(uint8_t interface_id, TrexPlatformInterfaceStats &stats) const;
- void get_interface_info(uint8_t interface_id,
- std::string &driver_name,
- driver_speed_e &speed,
- bool &has_crc) const {
- driver_name = "MOCK";
- speed = SPEED_INVALID;
- has_crc = false;
+ SimPlatformApi(int dp_core_count) {
+ m_dp_core_count = dp_core_count;
}
- void publish_async_data_now(uint32_t key) const {}
- uint8_t get_dp_core_count() const;
- void get_interface_stat_info(uint8_t interface_id, uint16_t &num_counters, uint16_t &capabilities) const
- {num_counters = 0; capabilities = 0;}
- int get_rx_stats(uint8_t port_id, uint64_t *stats, int index, bool reset) const {return 0;}
- void get_port_num(uint8_t &port_num) const {port_num = 2;};
- int add_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const {return 0;}
- int del_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const {return 0;}
+ virtual uint8_t get_dp_core_count() const {
+ return m_dp_core_count;
+ }
+
+ virtual void get_global_stats(TrexPlatformGlobalStats &stats) const {
+ }
+
+ virtual void get_interface_info(uint8_t interface_id,
+ std::string &driver_name,
+ driver_speed_e &speed,
+ bool &has_crc) const {
+ driver_name = "TEST";
+ speed = TrexPlatformApi::SPEED_10G;
+ has_crc = true;
+ }
+
+ virtual void get_interface_stats(uint8_t interface_id, TrexPlatformInterfaceStats &stats) const {
+ }
+ virtual void get_interface_stat_info(uint8_t interface_id, uint16_t &num_counters, uint16_t &capabilities) const {num_counters=128; capabilities=0; }
+
+ virtual void port_id_to_cores(uint8_t port_id, std::vector<std::pair<uint8_t, uint8_t>> &cores_id_list) const {
+ for (int i = 0; i < m_dp_core_count; i++) {
+ cores_id_list.push_back(std::make_pair(i, 0));
+ }
+ }
+
+ virtual void publish_async_data_now(uint32_t key) const {
+
+ }
+ virtual int get_rx_stats(uint8_t port_id, uint64_t *stats, int index, bool reset) const {return 0;}
+ virtual void get_port_num(uint8_t &port_num) const {port_num = 2;};
+ virtual int add_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const {return 0;}
+ virtual int del_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const {return 0;}
+
+ void set_promiscuous(uint8_t port_id, bool enabled) const {
+ }
+
+ bool get_promiscuous(uint8_t port_id) const {
+ return false;
+ }
+
+private:
+ int m_dp_core_count;
};
#endif /* __TREX_PLATFORM_API_H__ */
diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp
index 8cc94e7d..25c10e5d 100644
--- a/src/main_dpdk.cpp
+++ b/src/main_dpdk.cpp
@@ -5171,3 +5171,12 @@ int TrexDpdkPlatformApi::del_rx_flow_stat_rule(uint8_t port_id, uint8_t type, ui
return CTRexExtendedDriverDb::Ins()->get_drv()
->add_del_rx_flow_stat_rule(port_id, RTE_ETH_FILTER_DELETE, type, proto, id);
}
+
+void TrexDpdkPlatformApi::set_promiscuous(uint8_t port_id, bool enabled) const {
+ g_trex.m_ports[port_id].set_promiscuous(enabled);
+}
+
+bool TrexDpdkPlatformApi::get_promiscuous(uint8_t port_id) const {
+ return g_trex.m_ports[port_id].get_promiscuous();
+}
+
diff --git a/src/mock/rte_ethdev.h b/src/mock/rte_ethdev.h
deleted file mode 100644
index 046d8366..00000000
--- a/src/mock/rte_ethdev.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- 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.
-*/
-#ifndef __MOCK_FILE_RTE_ETHDEV_H__
-#define __MOCK_FILE_RTE_ETHDEV_H__
-
-#include <string.h>
-
-struct rte_eth_stats {
- uint64_t obytes;
- uint64_t ibytes;
- uint64_t opackets;
- uint64_t ipackets;
-};
-
-static inline void
-rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats) {
- memset(stats, 0, sizeof(rte_eth_stats));
-}
-
-static inline uint16_t
-rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
- struct rte_mbuf **tx_pkts, uint16_t nb_pkts) {
- return (0);
-}
-
-#endif /* __MOCK_FILE_RTE_ETHDEV_H__ */
diff --git a/src/mock/trex_platform_api_mock.cpp b/src/mock/trex_platform_api_mock.cpp
deleted file mode 100644
index 7cacd96c..00000000
--- a/src/mock/trex_platform_api_mock.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- 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 <internal_api/trex_platform_api.h>
-
-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);
-}
-
-void
-TrexMockPlatformApi::port_id_to_cores(uint8_t port_id, std::vector<std::pair<uint8_t, uint8_t>> &cores_id_list) const {
- cores_id_list.push_back(std::make_pair(0, 0));
-}
-
diff --git a/src/mock/trex_rpc_server_mock.cpp b/src/mock/trex_rpc_server_mock.cpp
deleted file mode 100644
index ecfa308d..00000000
--- a/src/mock/trex_rpc_server_mock.cpp
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- 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 <trex_rpc_server_api.h>
-#include <trex_stateless.h>
-#include <trex_stateless_dp_core.h>
-
-#include <msg_manager.h>
-
-#include <iostream>
-#include <sstream>
-#include <unistd.h>
-#include <string.h>
-#include <zmq.h>
-#include <bp_sim.h>
-
-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;
-}
-
-uint16_t gtest_get_mock_server_port() {
- return g_rpc_port;
-}
-
-/**
- * on simulation this is not rebuild every version
- * (improved stub)
- *
- */
-extern "C" const char * get_build_date(void){
- return (__DATE__);
-}
-
-extern "C" const char * get_build_time(void){
- return (__TIME__ );
-}
-
-int gtest_main(int argc, char **argv);
-
-static bool parse_uint16(const string arg, uint16_t &port) {
- stringstream ss(arg);
-
- bool x = (ss >> 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]);
-
- 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);
- }
-
- } 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, g_rpc_port);
- //TrexRpcServerConfig rpc_async_cfg(TrexRpcServerConfig::RPC_PROT_TCP, 5051);
-
- cfg.m_port_count = 4;
- cfg.m_rpc_req_resp_cfg = &rpc_req_resp_cfg;
- cfg.m_rpc_async_cfg = NULL;
- cfg.m_rpc_server_verbose = (is_gtest ? false : true);
- cfg.m_platform_api = new TrexMockPlatformApi();
-
- g_trex_stateless = new TrexStateless(cfg);
-
- g_trex_stateless->launch_control_plane();
-
- /* gtest handling */
- if (is_gtest) {
- int rc = gtest_main(argc, argv);
- delete g_trex_stateless;
- g_trex_stateless = NULL;
- return rc;
- }
-
- cout << "\n-= Starting RPC Server Mock =-\n\n";
- cout << "Listening on tcp://localhost:" << g_rpc_port << " [ZMQ]\n\n";
-
- cout << "Server Started\n\n";
-
- while (true) {
- sleep(1);
- }
-
- delete g_trex_stateless;
- g_trex_stateless = NULL;
-}
-
diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
index 9b3b59a7..05565179 100644
--- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp
+++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
@@ -208,6 +208,39 @@ TrexRpcCmdGetSysInfo::_run(const Json::Value &params, Json::Value &result) {
}
/**
+ * set port commands
+ *
+ * @author imarom (24-Feb-16)
+ *
+ * @param params
+ * @param result
+ *
+ * @return trex_rpc_cmd_rc_e
+ */
+trex_rpc_cmd_rc_e
+TrexRpcCmdSetPortAttr::_run(const Json::Value &params, Json::Value &result) {
+
+ uint8_t port_id = parse_port(params, result);
+ TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
+
+ const Json::Value &attr = parse_object(params, "attr", result);
+
+ /* iterate over all attributes in the dict */
+ for (const std::string &name : attr.getMemberNames()) {
+
+ /* handle promiscuous */
+ if (name == "promiscuous") {
+ bool enabled = parse_bool(attr[name], "enabled", result);
+ port->set_promiscuous(enabled);
+ }
+ }
+
+ result["result"] = Json::objectValue;
+ return (TREX_RPC_CMD_OK);
+}
+
+
+/**
* returns the current owner of the device
*
* @author imarom (08-Sep-15)
@@ -318,6 +351,9 @@ TrexRpcCmdGetPortStatus::_run(const Json::Value &params, Json::Value &result) {
result["result"]["state"] = port->get_state_as_string();
result["result"]["max_stream_id"] = port->get_max_stream_id();
+ /* attributes */
+ result["result"]["attr"]["promiscuous"]["enabled"] = port->get_promiscuous();
+
return (TREX_RPC_CMD_OK);
}
diff --git a/src/rpc-server/commands/trex_rpc_cmds.h b/src/rpc-server/commands/trex_rpc_cmds.h
index 9545e585..ac63e39d 100644
--- a/src/rpc-server/commands/trex_rpc_cmds.h
+++ b/src/rpc-server/commands/trex_rpc_cmds.h
@@ -81,7 +81,7 @@ TREX_RPC_CMD_DEFINE(TrexRpcCmdRelease, "release", 1, true);
*/
TREX_RPC_CMD_DEFINE(TrexRpcCmdGetPortStats, "get_port_stats", 1, false);
TREX_RPC_CMD_DEFINE(TrexRpcCmdGetPortStatus, "get_port_status", 1, false);
-
+TREX_RPC_CMD_DEFINE(TrexRpcCmdSetPortAttr, "set_port_attr", 3, false);
/**
* stream cmds
diff --git a/src/rpc-server/trex_rpc_cmds_table.cpp b/src/rpc-server/trex_rpc_cmds_table.cpp
index 5218cd0a..7b8dfdfc 100644
--- a/src/rpc-server/trex_rpc_cmds_table.cpp
+++ b/src/rpc-server/trex_rpc_cmds_table.cpp
@@ -43,6 +43,7 @@ TrexRpcCommandsTable::TrexRpcCommandsTable() {
register_command(new TrexRpcCmdRelease());
register_command(new TrexRpcCmdGetPortStats());
register_command(new TrexRpcCmdGetPortStatus());
+ register_command(new TrexRpcCmdSetPortAttr());
/* stream commands */
diff --git a/src/sim/trex_sim.h b/src/sim/trex_sim.h
index 6e842eb7..3a3a62ea 100644
--- a/src/sim/trex_sim.h
+++ b/src/sim/trex_sim.h
@@ -40,51 +40,6 @@ in_range(int x, int low, int high) {
return ( (x >= low) && (x <= high) );
}
-/*************** hook for platform API **************/
-class SimPlatformApi : public TrexPlatformApi {
-public:
- SimPlatformApi(int dp_core_count) {
- m_dp_core_count = dp_core_count;
- }
-
- virtual uint8_t get_dp_core_count() const {
- return m_dp_core_count;
- }
-
- virtual void get_global_stats(TrexPlatformGlobalStats &stats) const {
- }
-
- virtual void get_interface_info(uint8_t interface_id,
- std::string &driver_name,
- driver_speed_e &speed,
- bool &has_crc) const {
- driver_name = "TEST";
- speed = TrexPlatformApi::SPEED_10G;
- has_crc = true;
- }
-
- virtual void get_interface_stats(uint8_t interface_id, TrexPlatformInterfaceStats &stats) const {
- }
- virtual void get_interface_stat_info(uint8_t interface_id, uint16_t &num_counters, uint16_t &capabilities) const {num_counters=128; capabilities=0; }
-
- virtual void port_id_to_cores(uint8_t port_id, std::vector<std::pair<uint8_t, uint8_t>> &cores_id_list) const {
- for (int i = 0; i < m_dp_core_count; i++) {
- cores_id_list.push_back(std::make_pair(i, 0));
- }
- }
-
- virtual void publish_async_data_now(uint32_t key) const {
-
- }
- virtual int get_rx_stats(uint8_t port_id, uint64_t *stats, int index, bool reset) const {return 0;}
- virtual void get_port_num(uint8_t &port_num) const {port_num = 2;};
- virtual int add_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const {return 0;}
- virtual int del_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const {return 0;}
-
-private:
- int m_dp_core_count;
-};
-
/**
* interface for a sim target
*
diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp
index d2463925..43f32d22 100644
--- a/src/stateless/cp/trex_stateless_port.cpp
+++ b/src/stateless/cp/trex_stateless_port.cpp
@@ -40,7 +40,6 @@ limitations under the License.
// DPDK c++ issue
#endif
-#include <rte_ethdev.h>
#include <os_time.h>
void
@@ -251,9 +250,9 @@ TrexStatelessPort::common_port_stop_actions(bool event_triggered) {
data["port_id"] = m_port_id;
if (event_triggered) {
- get_stateless_obj()->get_publisher()->publish_event(TrexPublisher::EVENT_PORT_STOPPED, data);
- } else {
get_stateless_obj()->get_publisher()->publish_event(TrexPublisher::EVENT_PORT_FINISHED_TX, data);
+ } else {
+ get_stateless_obj()->get_publisher()->publish_event(TrexPublisher::EVENT_PORT_STOPPED, data);
}
for (auto entry : m_stream_table) {
@@ -668,6 +667,20 @@ TrexStatelessPort::get_port_effective_rate(double &pps,
}
+
+void
+TrexStatelessPort::set_promiscuous(bool enabled) {
+ get_stateless_obj()->get_platform_api()->set_promiscuous(m_port_id, enabled);
+}
+
+bool
+TrexStatelessPort::get_promiscuous() {
+ return get_stateless_obj()->get_platform_api()->get_promiscuous(m_port_id);
+}
+
+
+
+
void
TrexStatelessPort::add_stream(TrexStream *stream) {
diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h
index a956c421..1d3eebc3 100644
--- a/src/stateless/cp/trex_stateless_port.h
+++ b/src/stateless/cp/trex_stateless_port.h
@@ -323,6 +323,15 @@ public:
double &bps_L2,
double &percentage);
+
+ /**
+ * set port promiscuous on/off
+ *
+ * @param enabled
+ */
+ void set_promiscuous(bool enabled);
+ bool get_promiscuous();
+
private: