diff options
author | imarom <imarom@cisco.com> | 2017-01-04 18:46:45 +0200 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2017-01-04 18:46:45 +0200 |
commit | 5257dbb8253fe5b70b75f9c064c4593ca7aee99f (patch) | |
tree | f7fa69be359ce165ae992ba0021fd15ca471b818 /src/rpc-server | |
parent | ea10422c22479c8e498d8efb5cb19882e70db9ff (diff) |
draft - unreviewed
Signed-off-by: imarom <imarom@cisco.com>
Diffstat (limited to 'src/rpc-server')
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmd_general.cpp | 143 | ||||
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmds.h | 15 | ||||
-rw-r--r-- | src/rpc-server/trex_rpc_cmds_table.cpp | 3 |
3 files changed, 92 insertions, 69 deletions
diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp index d4854a79..ec5c3158 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp @@ -28,6 +28,7 @@ limitations under the License. #include <internal_api/trex_platform_api.h> #include "trex_stateless_rx_core.h" +#include "trex_stateless_capture.h" #include <fstream> #include <iostream> @@ -339,24 +340,6 @@ TrexRpcCmdGetSysInfo::_run(const Json::Value ¶ms, Json::Value &result) { return (TREX_RPC_CMD_OK); } - -int -TrexRpcCmdSetPortAttr::parse_rx_filter_mode(const Json::Value &msg, uint8_t port_id, Json::Value &result) { - const std::string type = parse_choice(msg, "mode", {"hw", "all"}, result); - - rx_filter_mode_e filter_mode; - if (type == "hw") { - filter_mode = RX_FILTER_MODE_HW; - } else if (type == "all") { - filter_mode = RX_FILTER_MODE_ALL; - } else { - /* can't happen - parsed choice */ - assert(0); - } - - return get_stateless_obj()->get_platform_api()->getPortAttrObj(port_id)->set_rx_filter_mode(filter_mode); -} - /** * set port commands * @@ -399,11 +382,6 @@ TrexRpcCmdSetPortAttr::_run(const Json::Value ¶ms, Json::Value &result) { ret = get_stateless_obj()->get_platform_api()->getPortAttrObj(port_id)->set_flow_ctrl(mode); } - else if (name == "rx_filter_mode") { - const Json::Value &rx = parse_object(attr, name, result); - ret = parse_rx_filter_mode(rx, port_id, result); - } - /* unknown attribute */ else { generate_execute_err(result, "unknown attribute type: '" + name + "'"); @@ -588,7 +566,8 @@ TrexRpcCmdGetPortStatus::_run(const Json::Value ¶ms, Json::Value &result) { result["result"]["owner"] = (port->get_owner().is_free() ? "" : port->get_owner().get_name()); result["result"]["state"] = port->get_state_as_string(); result["result"]["max_stream_id"] = port->get_max_stream_id(); - + result["result"]["service"] = port->is_service_mode_on(); + /* attributes */ get_stateless_obj()->get_platform_api()->getPortAttrObj(port_id)->to_json(result["result"]["attr"]); @@ -660,6 +639,27 @@ TrexRpcCmdPushRemote::_run(const Json::Value ¶ms, Json::Value &result) { } + +/** + * set service mode on/off + * + */ +trex_rpc_cmd_rc_e +TrexRpcCmdSetServiceMode::_run(const Json::Value ¶ms, Json::Value &result) { + uint8_t port_id = parse_port(params, result); + bool enabled = parse_bool(params, "enabled", result); + + TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id); + try { + port->set_service_mode(enabled); + } catch (TrexException &ex) { + generate_execute_err(result, ex.what()); + } + + result["result"] = Json::objectValue; + return (TREX_RPC_CMD_OK); +} + /** * set on/off RX software receive mode * @@ -670,12 +670,14 @@ TrexRpcCmdSetRxFeature::_run(const Json::Value ¶ms, Json::Value &result) { uint8_t port_id = parse_port(params, result); TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id); + if (!port->is_service_mode_on()) { + generate_execute_err(result, "rx_feature - available only under service mode"); + } + /* decide which feature is being set */ - const std::string type = parse_choice(params, "type", {"capture", "queue", "server"}, result); + const std::string type = parse_choice(params, "type", {"queue", "server"}, result); - if (type == "capture") { - parse_capture_msg(params, port, result); - } else if (type == "queue") { + if (type == "queue") { parse_queue_msg(params, port, result); } else if (type == "server") { parse_server_msg(params, port, result); @@ -689,38 +691,6 @@ TrexRpcCmdSetRxFeature::_run(const Json::Value ¶ms, Json::Value &result) { } void -TrexRpcCmdSetRxFeature::parse_capture_msg(const Json::Value &msg, TrexStatelessPort *port, Json::Value &result) { - - bool enabled = parse_bool(msg, "enabled", result); - - if (enabled) { - - std::string pcap_filename = parse_string(msg, "pcap_filename", result); - uint64_t limit = parse_uint32(msg, "limit", result); - - if (limit == 0) { - generate_parse_err(result, "limit cannot be zero"); - } - - try { - port->start_rx_capture(pcap_filename, limit); - } catch (const TrexException &ex) { - generate_execute_err(result, ex.what()); - } - - } else { - - try { - port->stop_rx_capture(); - } catch (const TrexException &ex) { - generate_execute_err(result, ex.what()); - } - - } - -} - -void TrexRpcCmdSetRxFeature::parse_queue_msg(const Json::Value &msg, TrexStatelessPort *port, Json::Value &result) { bool enabled = parse_bool(msg, "enabled", result); @@ -762,8 +732,13 @@ TrexRpcCmdGetRxQueuePkts::_run(const Json::Value ¶ms, Json::Value &result) { TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id); + if (!port->is_service_mode_on()) { + generate_execute_err(result, "get_rx_queue_pkts - available only under service mode"); + } + + try { - const RXPacketBuffer *pkt_buffer = port->get_rx_queue_pkts(); + const TrexPktBuffer *pkt_buffer = port->get_rx_queue_pkts(); if (pkt_buffer) { result["result"]["pkts"] = pkt_buffer->to_json(); delete pkt_buffer; @@ -806,6 +781,7 @@ TrexRpcCmdSetL2::_run(const Json::Value ¶ms, Json::Value &result) { generate_execute_err(result, ex.what()); } + result["result"] = Json::objectValue; return (TREX_RPC_CMD_OK); } @@ -863,7 +839,50 @@ TrexRpcCmdSetL3::_run(const Json::Value ¶ms, Json::Value &result) { } } - + + result["result"] = Json::objectValue; return (TREX_RPC_CMD_OK); } + +/** + * starts PCAP capturing + * + */ +trex_rpc_cmd_rc_e +TrexRpcCmdStartCapture::_run(const Json::Value ¶ms, Json::Value &result) { + + uint32_t limit = parse_uint32(params, "limit", result); + const Json::Value &tx_json = parse_array(params, "tx", result); + const Json::Value &rx_json = parse_array(params, "rx", result); + + CaptureFilter filter; + + std::set<uint8_t> ports; + + /* populate the filter */ + for (int i = 0; i < tx_json.size(); i++) { + uint8_t tx_port = parse_byte(tx_json, i, result); + filter.add_tx(tx_port); + ports.insert(tx_port); + } + + for (int i = 0; i < rx_json.size(); i++) { + uint8_t rx_port = parse_byte(rx_json, i, result); + filter.add_rx(rx_port); + ports.insert(rx_port); + } + + /* check that all ports are under service mode */ + for (uint8_t port_id : ports) { + TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id); + if (!port->is_service_mode_on()) { + generate_parse_err(result, "start_capture is available only under service mode"); + } + } + + get_stateless_obj()->start_capture(filter, limit); + + result["result"] = Json::objectValue; + 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 6639be7b..1ea63cc7 100644 --- a/src/rpc-server/commands/trex_rpc_cmds.h +++ b/src/rpc-server/commands/trex_rpc_cmds.h @@ -94,8 +94,6 @@ TREX_RPC_CMD_DEFINE(TrexRpcCmdGetPortXStatsValues, "get_port_xstats_values", 1, TREX_RPC_CMD_DEFINE(TrexRpcCmdGetPortXStatsNames, "get_port_xstats_names", 1, false, APIClass::API_CLASS_TYPE_CORE); TREX_RPC_CMD_DEFINE_EXTENDED(TrexRpcCmdSetPortAttr, "set_port_attr", 2, true, APIClass::API_CLASS_TYPE_CORE, - - int parse_rx_filter_mode(const Json::Value &msg, uint8_t port_id, Json::Value &result); ); @@ -150,16 +148,19 @@ TREX_RPC_CMD_DEFINE(TrexRpcCmdPushRemote, "push_remote", 6, true, APIClass::API_ TREX_RPC_CMD_DEFINE(TrexRpcCmdShutdown, "shutdown", 2, false, APIClass::API_CLASS_TYPE_CORE); -TREX_RPC_CMD_DEFINE_EXTENDED(TrexRpcCmdSetRxFeature, "set_rx_feature", 3, false, APIClass::API_CLASS_TYPE_CORE, - void parse_capture_msg(const Json::Value &msg, TrexStatelessPort *port, Json::Value &result); +TREX_RPC_CMD_DEFINE_EXTENDED(TrexRpcCmdSetRxFeature, "set_rx_feature", 3, true, APIClass::API_CLASS_TYPE_CORE, void parse_queue_msg(const Json::Value &msg, TrexStatelessPort *port, Json::Value &result); void parse_server_msg(const Json::Value &msg, TrexStatelessPort *port, Json::Value &result); ); -TREX_RPC_CMD_DEFINE(TrexRpcCmdSetL2, "set_l2", 2, false, APIClass::API_CLASS_TYPE_CORE); -TREX_RPC_CMD_DEFINE(TrexRpcCmdSetL3, "set_l3", 3, false, APIClass::API_CLASS_TYPE_CORE); -TREX_RPC_CMD_DEFINE(TrexRpcCmdGetRxQueuePkts, "get_rx_queue_pkts", 2, false, APIClass::API_CLASS_TYPE_CORE); +TREX_RPC_CMD_DEFINE(TrexRpcCmdSetL2, "set_l2", 2, true, APIClass::API_CLASS_TYPE_CORE); +TREX_RPC_CMD_DEFINE(TrexRpcCmdSetL3, "set_l3", 3, true, APIClass::API_CLASS_TYPE_CORE); +TREX_RPC_CMD_DEFINE(TrexRpcCmdGetRxQueuePkts, "get_rx_queue_pkts", 1, true, APIClass::API_CLASS_TYPE_CORE); + +TREX_RPC_CMD_DEFINE(TrexRpcCmdSetServiceMode, "service", 2, true, APIClass::API_CLASS_TYPE_CORE); + +TREX_RPC_CMD_DEFINE(TrexRpcCmdStartCapture, "start_capture", 3, false, APIClass::API_CLASS_TYPE_CORE); #endif /* __TREX_RPC_CMD_H__ */ diff --git a/src/rpc-server/trex_rpc_cmds_table.cpp b/src/rpc-server/trex_rpc_cmds_table.cpp index 94a3e1b9..3d4d5a23 100644 --- a/src/rpc-server/trex_rpc_cmds_table.cpp +++ b/src/rpc-server/trex_rpc_cmds_table.cpp @@ -75,8 +75,11 @@ TrexRpcCommandsTable::TrexRpcCommandsTable() { register_command(new TrexRpcCmdSetRxFeature()); register_command(new TrexRpcCmdGetRxQueuePkts()); + register_command(new TrexRpcCmdSetServiceMode()); register_command(new TrexRpcCmdSetL2()); register_command(new TrexRpcCmdSetL3()); + + register_command(new TrexRpcCmdStartCapture()); } |