diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/internal_api/trex_platform_api.h | 10 | ||||
-rw-r--r-- | src/main_dpdk.cpp | 15 | ||||
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmd_general.cpp | 37 | ||||
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmds.h | 1 | ||||
-rw-r--r-- | src/rpc-server/trex_rpc_cmds_table.cpp | 2 | ||||
-rw-r--r-- | src/stateless/cp/trex_stateless_port.cpp | 14 | ||||
-rw-r--r-- | src/stateless/cp/trex_stateless_port.h | 13 | ||||
-rw-r--r-- | src/stateless/dp/trex_stateless_dp_core.cpp | 29 | ||||
-rw-r--r-- | src/stateless/rx/trex_stateless_rx_defs.h | 9 | ||||
-rw-r--r-- | src/trex_port_attr.cpp | 71 | ||||
-rwxr-xr-x | src/trex_port_attr.h | 75 |
11 files changed, 182 insertions, 94 deletions
diff --git a/src/internal_api/trex_platform_api.h b/src/internal_api/trex_platform_api.h index 1445d3e9..5723503c 100644 --- a/src/internal_api/trex_platform_api.h +++ b/src/internal_api/trex_platform_api.h @@ -113,19 +113,13 @@ public: IF_STAT_RX_BYTES_COUNT = 8, // Card support counting rx bytes }; - struct mac_cfg_st { - uint8_t hw_macaddr[6]; - uint8_t src_macaddr[6]; - uint8_t dst_macaddr[6]; - }; - /** * interface static info * */ struct intf_info_st { std::string driver_name; - mac_cfg_st mac_info; + uint8_t hw_macaddr[6]; std::string pci_addr; int numa_node; bool has_crc; @@ -235,7 +229,7 @@ public: info.has_crc = true; info.numa_node = 0; - memset(&info.mac_info, 0, sizeof(info.mac_info)); + memset(&info.hw_macaddr, 0, sizeof(info.hw_macaddr)); } virtual void get_interface_stats(uint8_t interface_id, TrexPlatformInterfaceStats &stats) const { diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp index 8f887006..fed7a348 100644 --- a/src/main_dpdk.cpp +++ b/src/main_dpdk.cpp @@ -1659,7 +1659,7 @@ bool DpdkTRexPortAttr::get_promiscuous(){ } -void DpdkTRexPortAttr::macaddr_get(struct ether_addr *mac_addr){ +void DpdkTRexPortAttr::get_hw_src_mac(struct ether_addr *mac_addr){ rte_eth_macaddr_get(m_port_id , mac_addr); } @@ -6502,19 +6502,10 @@ TrexDpdkPlatformApi::get_interface_info(uint8_t interface_id, intf_info_st &info /* mac INFO */ /* hardware */ - g_trex.m_ports[interface_id].get_port_attr()->macaddr_get(&rte_mac_addr); + g_trex.m_ports[interface_id].get_port_attr()->get_hw_src_mac(&rte_mac_addr); assert(ETHER_ADDR_LEN == 6); - /* software */ - uint8_t sw_macaddr[12]; - memcpy(sw_macaddr, CGlobalInfo::m_options.get_dst_src_mac_addr(interface_id), 12); - - for (int i = 0; i < 6; i++) { - info.mac_info.hw_macaddr[i] = rte_mac_addr.addr_bytes[i]; - info.mac_info.dst_macaddr[i] = sw_macaddr[i]; - info.mac_info.src_macaddr[i] = sw_macaddr[6 + i]; - - } + memcpy(info.hw_macaddr, rte_mac_addr.addr_bytes, 6); info.numa_node = g_trex.m_ports[interface_id].m_dev_info.pci_dev->numa_node; struct rte_pci_addr *loc = &g_trex.m_ports[interface_id].m_dev_info.pci_dev->addr; diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp index 8d61ecba..e7f0de7b 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp @@ -846,8 +846,12 @@ TrexRpcCmdGetRxQueuePkts::_run(const Json::Value ¶ms, Json::Value &result) { TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id); try { - RxPacketBuffer *pkt_buffer = port->get_rx_queue_pkts(); - result["result"]["pkts"] = pkt_buffer->to_json(); + const RxPacketBuffer *pkt_buffer = port->get_rx_queue_pkts(); + if (pkt_buffer) { + result["result"]["pkts"] = pkt_buffer->to_json(); + } else { + result["result"]["pkts"] = Json::arrayValue; + } } catch (const TrexException &ex) { generate_execute_err(result, ex.what()); @@ -856,3 +860,32 @@ TrexRpcCmdGetRxQueuePkts::_run(const Json::Value ¶ms, Json::Value &result) { return (TREX_RPC_CMD_OK); } + +trex_rpc_cmd_rc_e +TrexRpcCmdSetARPRes::_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); + + const std::string ipv4_str = parse_string(params, "ipv4", result); + const std::string mac_str = parse_string(params, "mac", result); + + uint32_t ipv4_addr; + if (!utl_ipv4_to_uint32(ipv4_str.c_str(), ipv4_addr)) { + std::stringstream ss; + ss << "invalid IPv4 address: '" << ipv4_str << "'"; + generate_parse_err(result, ss.str()); + } + + uint8_t mac[6]; + if (!utl_str_to_macaddr(mac_str, mac)) { + std::stringstream ss; + ss << "'invalid MAC address: '" << mac_str << "'"; + generate_parse_err(result, ss.str()); + } + + port->getPortAttrObj()->get_dest().set_dest_ipv4(ipv4_addr, mac); + + 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 9fb4d551..fab81f67 100644 --- a/src/rpc-server/commands/trex_rpc_cmds.h +++ b/src/rpc-server/commands/trex_rpc_cmds.h @@ -162,6 +162,7 @@ TREX_RPC_CMD_DEFINE_EXTENDED(TrexRpcCmdSetRxFeature, "set_rx_feature", 3, false, ); TREX_RPC_CMD_DEFINE(TrexRpcCmdGetRxQueuePkts, "get_rx_queue_pkts", 2, false, APIClass::API_CLASS_TYPE_CORE); +TREX_RPC_CMD_DEFINE(TrexRpcCmdSetARPRes, "set_arp_resolution", 2, 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 f006a4cd..919be1f1 100644 --- a/src/rpc-server/trex_rpc_cmds_table.cpp +++ b/src/rpc-server/trex_rpc_cmds_table.cpp @@ -74,6 +74,8 @@ TrexRpcCommandsTable::TrexRpcCommandsTable() { register_command(new TrexRpcCmdSetRxFeature()); register_command(new TrexRpcCmdGetRxQueuePkts()); + + register_command(new TrexRpcCmdSetARPRes()); } diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp index ff83087c..d4bc5c36 100644 --- a/src/stateless/cp/trex_stateless_port.cpp +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -888,16 +888,6 @@ TrexStatelessPort::get_port_effective_rate(double &pps, } void -TrexStatelessPort::get_macaddr(std::string &hw_macaddr, - std::string &src_macaddr, - std::string &dst_macaddr) { - - utl_macaddr_to_str(m_api_info.mac_info.hw_macaddr, hw_macaddr); - utl_macaddr_to_str(m_api_info.mac_info.src_macaddr, src_macaddr); - utl_macaddr_to_str(m_api_info.mac_info.dst_macaddr, dst_macaddr); -} - -void TrexStatelessPort::get_pci_info(std::string &pci_addr, int &numa_node) { pci_addr = m_api_info.pci_addr; numa_node = m_api_info.numa_node; @@ -980,6 +970,10 @@ TrexStatelessPort::stop_rx_queue() { RxPacketBuffer * TrexStatelessPort::get_rx_queue_pkts() { + if (m_rx_features_info.m_rx_queue_info.is_empty()) { + return NULL; + } + /* ask RX core for the pkt queue */ TrexStatelessMsgReply<RxPacketBuffer *> msg_reply; diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h index d71ba932..cf6b2716 100644 --- a/src/stateless/cp/trex_stateless_port.h +++ b/src/stateless/cp/trex_stateless_port.h @@ -362,11 +362,6 @@ public: double &bps_L2, double &percentage); - - void get_macaddr(std::string &hw_macaddr, - std::string &src_macaddr, - std::string &dst_macaddr); - void get_pci_info(std::string &pci_addr, int &numa_node); @@ -413,6 +408,14 @@ public: */ RxPacketBuffer *get_rx_queue_pkts(); + /** + * return the port attribute object + * + */ + TRexPortAttr *getPortAttrObj() { + return m_platform_api->getPortAttrObj(m_port_id); + } + private: bool is_core_active(int core_id); diff --git a/src/stateless/dp/trex_stateless_dp_core.cpp b/src/stateless/dp/trex_stateless_dp_core.cpp index 857ac8f9..43b77bee 100644 --- a/src/stateless/dp/trex_stateless_dp_core.cpp +++ b/src/stateless/dp/trex_stateless_dp_core.cpp @@ -26,7 +26,7 @@ limitations under the License. #include "trex_stream_node.h" #include "trex_streams_compiler.h" #include "mbuf.h" - +#include "trex_stateless.h" @@ -495,12 +495,14 @@ bool TrexStatelessDpPerPort::push_pcap(uint8_t port_id, /* main port */ uint8_t mac_addr[12]; - m_core->m_node_gen.m_v_if->update_mac_addr_from_global_cfg(dir, mac_addr); - + TRexPortAttr *master_port_attr = get_stateless_obj()->get_platform_api()->getPortAttrObj(port_id); + master_port_attr->update_src_dst_mac(mac_addr); + /* for dual */ uint8_t slave_mac_addr[12]; - m_core->m_node_gen.m_v_if->update_mac_addr_from_global_cfg(dir ^ 0x1, slave_mac_addr); - + TRexPortAttr *slave_port_attr = get_stateless_obj()->get_platform_api()->getPortAttrObj(port_id ^ 0x1); + slave_port_attr->update_src_dst_mac(slave_mac_addr); + bool rc = pcap_node->create(port_id, dir, socket_id, @@ -823,8 +825,9 @@ void TrexStatelessDpCore::update_mac_addr(TrexStream * stream, CGenNodeStateless *node, pkt_dir_t dir, char *raw_pkt){ - bool ov_src = stream->get_override_src_mac_by_pkt_data(); - TrexStream::stream_dst_mac_t ov_dst = stream->get_override_dst_mac_mode(); + + bool ov_src = stream->get_override_src_mac_by_pkt_data(); + TrexStream::stream_dst_mac_t ov_dst = stream->get_override_dst_mac_mode(); if ( (ov_src == true) && (ov_dst == TrexStream::stPKT) ) { @@ -832,11 +835,13 @@ void TrexStatelessDpCore::update_mac_addr(TrexStream * stream, return; } - /* take from cfg_file */ + TRexPortAttr *port_attr = get_stateless_obj()->get_platform_api()->getPortAttrObj(node->get_port_id()); + + /* take from cfg_file */ if ( (ov_src == false) && (ov_dst == TrexStream::stCFG_FILE) ){ - - m_core->m_node_gen.m_v_if->update_mac_addr_from_global_cfg(dir,(uint8_t*)raw_pkt); + + port_attr->update_src_dst_mac((uint8_t *)raw_pkt); return; } @@ -844,8 +849,8 @@ void TrexStatelessDpCore::update_mac_addr(TrexStream * stream, char tmp_pkt[12]; memcpy(tmp_pkt,raw_pkt,12); - m_core->m_node_gen.m_v_if->update_mac_addr_from_global_cfg(dir,(uint8_t*)raw_pkt); - + port_attr->update_src_dst_mac((uint8_t *)raw_pkt); + if ((ov_src == true) && (ov_dst == TrexStream::stCFG_FILE)) { memcpy(raw_pkt+6,tmp_pkt+6,6); } diff --git a/src/stateless/rx/trex_stateless_rx_defs.h b/src/stateless/rx/trex_stateless_rx_defs.h index bdd86a72..7b1e0f32 100644 --- a/src/stateless/rx/trex_stateless_rx_defs.h +++ b/src/stateless/rx/trex_stateless_rx_defs.h @@ -79,6 +79,10 @@ public: m_limit = 0; } + bool is_empty() const { + return (m_shared_counter == 0); + } + void to_json(Json::Value &output) const { output["is_active"] = m_is_active; if (m_is_active) { @@ -114,7 +118,10 @@ public: m_size = 0; } - + bool is_empty() const { + return (m_shared_counter == 0); + } + void to_json(Json::Value &output) const { output["is_active"] = m_is_active; if (m_is_active) { diff --git a/src/trex_port_attr.cpp b/src/trex_port_attr.cpp new file mode 100644 index 00000000..08e151b6 --- /dev/null +++ b/src/trex_port_attr.cpp @@ -0,0 +1,71 @@ +/* +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_port_attr.h" +#include "bp_sim.h" + +const uint8_t DestAttr::g_dummy_mac[6] = {0x0,0x0,0x0,0x1,0x0,0x0}; + + +const uint8_t * +TRexPortAttr::get_src_mac() const { + return CGlobalInfo::m_options.get_src_mac_addr(m_port_id); +} + + +std::string +TRexPortAttr::get_rx_filter_mode() const { + switch (m_rx_filter_mode) { + case RX_FILTER_MODE_ALL: + return "all"; + case RX_FILTER_MODE_HW: + return "hw"; + default: + assert(0); + } +} + + +void +TRexPortAttr::to_json(Json::Value &output) { + + output["src_mac"] = utl_macaddr_to_str(get_src_mac()); + output["promiscuous"]["enabled"] = get_promiscuous(); + output["link"]["up"] = is_link_up(); + output["speed"] = get_link_speed(); + output["rx_filter_mode"] = get_rx_filter_mode(); + + if (get_src_ipv4() != 0) { + output["src_ipv4"] = utl_uint32_to_ipv4(get_src_ipv4()); + } else { + output["src_ipv4"] = "none"; + } + + + int mode; + get_flow_ctrl(mode); + output["fc"]["mode"] = mode; + + m_dest.to_json(output["dest"]); + +} + +void +TRexPortAttr::update_src_dst_mac(uint8_t *raw_pkt) { + memcpy(raw_pkt, get_dest().get_dest_mac(), 6); + memcpy(raw_pkt + 6, get_src_mac(), 6); +} + diff --git a/src/trex_port_attr.h b/src/trex_port_attr.h index cdbb466c..68f9f82e 100755 --- a/src/trex_port_attr.h +++ b/src/trex_port_attr.h @@ -22,18 +22,21 @@ limitations under the License. #include "rte_ethdev_includes.h" #include "trex_defs.h" #include "common/basic_utils.h" +#include <json/json.h> +#include "trex_stateless_rx_defs.h" /** * destination port attribute * */ class DestAttr { +private: + static const uint8_t g_dummy_mac[6]; public: DestAttr() { /* use a dummy MAC as default */ - uint8_t dummy_mac [] = {0xff,0xff,0xff,0xff,0xff,0xff}; - set_dest_mac(dummy_mac); + set_dest_mac(g_dummy_mac); } enum dest_type_e { @@ -90,6 +93,20 @@ public: } /** + * get the dest mac + * if no MAC is configured and dest was not resolved + * will return a dummy + */ + const uint8_t *get_dest_mac() { + + if (is_resolved()) { + return m_mac; + } else { + return g_dummy_mac; + } + } + + /** * when link gets down - this should be called * */ @@ -149,7 +166,7 @@ public: /* GETTERS */ virtual bool get_promiscuous() = 0; - virtual void macaddr_get(struct ether_addr *mac_addr) = 0; + virtual void get_hw_src_mac(struct ether_addr *mac_addr) = 0; virtual uint32_t get_link_speed() { return m_link.link_speed; } // L1 Mbps virtual bool is_link_duplex() { return (m_link.link_duplex ? true : false); } virtual bool is_link_autoneg() { return (m_link.link_autoneg ? true : false); } @@ -163,21 +180,16 @@ public: virtual bool is_link_change_supported() { return flag_is_link_change_supported; } virtual void get_description(std::string &description) { description = intf_info_st.description; } virtual void get_supported_speeds(supp_speeds_t &supp_speeds) = 0; + uint32_t get_src_ipv4() {return m_src_ipv4;} DestAttr & get_dest() {return m_dest;} - virtual std::string get_rx_filter_mode() { - switch (m_rx_filter_mode) { - case RX_FILTER_MODE_ALL: - return "all"; - case RX_FILTER_MODE_HW: - return "hw"; - default: - assert(0); - } - } - + const uint8_t *get_src_mac() const; + std::string get_rx_filter_mode() const; + /* for a raw packet, write the src/dst MACs */ + void update_src_dst_mac(uint8_t *raw_pkt); + /* SETTERS */ virtual int set_promiscuous(bool enabled) = 0; virtual int add_mac(char * mac) = 0; @@ -190,37 +202,12 @@ public: m_src_ipv4 = addr; } -/* DUMPS */ + /* DUMPS */ virtual void dump_link(FILE *fd) = 0; /* dump object status to JSON */ - void to_json(Json::Value &output) { - struct ether_addr dpdk_mac_addr; - macaddr_get(&dpdk_mac_addr); - - uint8_t mac_addr[6]; - memcpy(mac_addr, dpdk_mac_addr.addr_bytes, 6); - - output["src_mac"] = utl_macaddr_to_str(mac_addr); - output["promiscuous"]["enabled"] = get_promiscuous(); - output["link"]["up"] = is_link_up(); - output["speed"] = get_link_speed(); - output["rx_filter_mode"] = get_rx_filter_mode(); - - if (get_src_ipv4() != 0) { - output["src_ipv4"] = utl_uint32_to_ipv4(get_src_ipv4()); - } else { - output["src_ipv4"] = "none"; - } - - - int mode; - get_flow_ctrl(mode); - output["fc"]["mode"] = mode; - - m_dest.to_json(output["dest"]); - - } + void to_json(Json::Value &output); + protected: @@ -273,7 +260,7 @@ public: /* GETTERS */ virtual bool get_promiscuous(); - virtual void macaddr_get(struct ether_addr *mac_addr); + virtual void get_hw_src_mac(struct ether_addr *mac_addr); virtual int get_xstats_values(xstats_values_t &xstats_values); virtual int get_xstats_names(xstats_names_t &xstats_names); virtual int get_flow_ctrl(int &mode); @@ -319,7 +306,7 @@ public: void reset_xstats() {} void update_description() {} bool get_promiscuous() { return false; } - void macaddr_get(struct ether_addr *mac_addr) {} + void get_hw_src_mac(struct ether_addr *mac_addr) {} int get_xstats_values(xstats_values_t &xstats_values) { return -ENOTSUP; } int get_xstats_names(xstats_names_t &xstats_names) { return -ENOTSUP; } int get_flow_ctrl(int &mode) { return -ENOTSUP; } |