diff options
Diffstat (limited to 'src')
23 files changed, 816 insertions, 156 deletions
diff --git a/src/debug.cpp b/src/debug.cpp index 542d2fa1..3a9cd506 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -213,8 +213,11 @@ int CTrexDebug::test_send_pkts(rte_mbuf_t *m, uint16_t queue_id, int num_pkts, i int CTrexDebug::set_promisc_all(bool enable) { int i; for (i=0; i < m_max_ports; i++) { - CPhyEthIF *_if = &m_ports[i]; - _if->set_promiscuous(enable); + if (enable) { + rte_eth_promiscuous_enable(i); + }else{ + rte_eth_promiscuous_disable(i); + } } return 0; diff --git a/src/dpdk/drivers/net/virtio/virtio_ethdev.c b/src/dpdk/drivers/net/virtio/virtio_ethdev.c index 07d64497..35e67b90 100644 --- a/src/dpdk/drivers/net/virtio/virtio_ethdev.c +++ b/src/dpdk/drivers/net/virtio/virtio_ethdev.c @@ -1550,6 +1550,8 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) dev_info->default_txconf = (struct rte_eth_txconf) { .txq_flags = ETH_TXQ_FLAGS_NOOFFLOADS }; + /* TRex patch */ + dev_info->speed_capa = ETH_LINK_SPEED_10G; } /* diff --git a/src/dpdk/drivers/net/vmxnet3/vmxnet3_ethdev.c b/src/dpdk/drivers/net/vmxnet3/vmxnet3_ethdev.c index 58742153..47fdc3ec 100644 --- a/src/dpdk/drivers/net/vmxnet3/vmxnet3_ethdev.c +++ b/src/dpdk/drivers/net/vmxnet3/vmxnet3_ethdev.c @@ -706,6 +706,8 @@ vmxnet3_dev_info_get(__attribute__((unused))struct rte_eth_dev *dev, dev_info->min_rx_bufsize = 1518 + RTE_PKTMBUF_HEADROOM; dev_info->max_rx_pktlen = 16384; /* includes CRC, cf MAXFRS register */ dev_info->max_mac_addrs = VMXNET3_MAX_MAC_ADDRS; + /* TRex patch */ + dev_info->speed_capa = ETH_LINK_SPEED_10G; dev_info->default_txconf.txq_flags = ETH_TXQ_FLAGS_NOXSUMSCTP; dev_info->flow_type_rss_offloads = VMXNET3_RSS_OFFLOAD_ALL; diff --git a/src/inet_pton.cpp b/src/inet_pton.cpp new file mode 100644 index 00000000..3a4a12d7 --- /dev/null +++ b/src/inet_pton.cpp @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996,1999 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <string.h> + +typedef unsigned char u_char; +typedef unsigned int u_int; +/* int + * inet_pton4(src, dst) + * like inet_aton() but without all the hexadecimal and shorthand. + * return: + * 1 if `src' is a valid dotted quad, else 0. + * notice: + * does not touch `dst' unless it's returning 1. + * author: + * Paul Vixie, 1996. + */ +int +my_inet_pton4(const char *src, u_char *dst) +{ + static const char digits[] = "0123456789"; + int saw_digit, octets, ch; +#define NS_INADDRSZ 4 + u_char tmp[NS_INADDRSZ], *tp; + + saw_digit = 0; + octets = 0; + *(tp = tmp) = 0; + while ((ch = *src++) != '\0') { + const char *pch; + + if ((pch = strchr(digits, ch)) != NULL) { + u_int new_d = *tp * 10 + (pch - digits); + + if (saw_digit && *tp == 0) + return (0); + if (new_d > 255) + return (0); + *tp = new_d; + if (!saw_digit) { + if (++octets > 4) + return (0); + saw_digit = 1; + } + } else if (ch == '.' && saw_digit) { + if (octets == 4) + return (0); + *++tp = 0; + saw_digit = 0; + } else + return (0); + } + if (octets < 4) + return (0); + memcpy(dst, tmp, NS_INADDRSZ); + return (1); +} + +/* int + * inet_pton6(src, dst) + * convert presentation level address to network order binary form. + * return: + * 1 if `src' is a valid [RFC1884 2.2] address, else 0. + * notice: + * (1) does not touch `dst' unless it's returning 1. + * (2) :: in a full address is silently ignored. + * credit: + * inspired by Mark Andrews. + * author: + * Paul Vixie, 1996. + */ +int +my_inet_pton6(const char *src, u_char *dst) +{ + static const char xdigits_l[] = "0123456789abcdef", + xdigits_u[] = "0123456789ABCDEF"; +#define NS_IN6ADDRSZ 16 +#define NS_INT16SZ 2 + u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp; + const char *xdigits, *curtok; + int ch, seen_xdigits; + u_int val; + + memset((tp = tmp), '\0', NS_IN6ADDRSZ); + endp = tp + NS_IN6ADDRSZ; + colonp = NULL; + /* Leading :: requires some special handling. */ + if (*src == ':') + if (*++src != ':') + return (0); + curtok = src; + seen_xdigits = 0; + val = 0; + while ((ch = *src++) != '\0') { + const char *pch; + + if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) + pch = strchr((xdigits = xdigits_u), ch); + if (pch != NULL) { + val <<= 4; + val |= (pch - xdigits); + if (++seen_xdigits > 4) + return (0); + continue; + } + if (ch == ':') { + curtok = src; + if (!seen_xdigits) { + if (colonp) + return (0); + colonp = tp; + continue; + } else if (*src == '\0') { + return (0); + } + if (tp + NS_INT16SZ > endp) + return (0); + *tp++ = (u_char) (val >> 8) & 0xff; + *tp++ = (u_char) val & 0xff; + seen_xdigits = 0; + val = 0; + continue; + } + if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) && + my_inet_pton4(curtok, tp) > 0) { + tp += NS_INADDRSZ; + seen_xdigits = 0; + break; /*%< '\\0' was seen by inet_pton4(). */ + } + return (0); + } + if (seen_xdigits) { + if (tp + NS_INT16SZ > endp) + return (0); + *tp++ = (u_char) (val >> 8) & 0xff; + *tp++ = (u_char) val & 0xff; + } + if (colonp != NULL) { + /* + * Since some memmove()'s erroneously fail to handle + * overlapping regions, we'll do the shift by hand. + */ + const int n = tp - colonp; + int i; + + if (tp == endp) + return (0); + for (i = 1; i <= n; i++) { + endp[- i] = colonp[n - i]; + colonp[n - i] = 0; + } + tp = endp; + } + if (tp != endp) + return (0); + memcpy(dst, tmp, NS_IN6ADDRSZ); + return (1); +} diff --git a/src/internal_api/trex_platform_api.h b/src/internal_api/trex_platform_api.h index a55e8cd7..631f9a3e 100644 --- a/src/internal_api/trex_platform_api.h +++ b/src/internal_api/trex_platform_api.h @@ -28,6 +28,7 @@ limitations under the License. #include <string.h> #include "flow_stat_parser.h" #include "trex_defs.h" +#include "trex_port_attr.h" #include <json/json.h> /** @@ -123,7 +124,6 @@ public: */ struct intf_info_st { std::string driver_name; - uint32_t speed; mac_cfg_st mac_info; std::string pci_addr; int numa_node; @@ -137,6 +137,7 @@ public: virtual void get_interface_info(uint8_t interface_id, intf_info_st &info) const = 0; virtual void publish_async_data_now(uint32_t key, bool baseline) const = 0; + virtual void publish_async_port_attr_changed(uint8_t port_id) const = 0; virtual uint8_t get_dp_core_count() const = 0; virtual void get_interface_stat_info(uint8_t interface_id, uint16_t &num_counters, uint16_t &capabilities) const =0; virtual int get_flow_stats(uint8_t port_id, void *stats, void *tx_stats, int min, int max, bool reset @@ -149,14 +150,15 @@ public: , uint8_t ipv6_next_h, uint16_t id) const = 0; virtual int del_rx_flow_stat_rule(uint8_t port_id, uint16_t l3_type, uint8_t l4_proto , uint8_t ipv6_next_h, 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 void flush_dp_messages() const = 0; virtual int get_active_pgids(flow_stat_active_t &result) const = 0; virtual int get_cpu_util_full(cpu_util_full_t &result) const = 0; virtual int get_mbuf_util(Json::Value &result) const = 0; virtual CFlowStatParser *get_flow_stat_parser() const = 0; + virtual TRexPortAttr *getPortAttrObj(uint8_t port_id) const = 0; virtual void mark_for_shutdown() const = 0; + virtual int get_xstats_values(uint8_t port_id, xstats_values_t &xstats_values) const = 0; + virtual int get_xstats_names(uint8_t port_id, xstats_names_t &xstats_names) const = 0; virtual ~TrexPlatformApi() {} }; @@ -176,6 +178,7 @@ public: void get_interface_info(uint8_t interface_id, intf_info_st &info) const; void publish_async_data_now(uint32_t key, bool baseline) const; + void publish_async_port_attr_changed(uint8_t port_id) 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; int get_flow_stats(uint8_t port_id, void *stats, void *tx_stats, int min, int max, bool reset @@ -188,14 +191,16 @@ public: , uint8_t ipv6_next_h, uint16_t id) const; virtual int del_rx_flow_stat_rule(uint8_t port_id, uint16_t l3_type, uint8_t l4_proto , uint8_t ipv6_next_h, uint16_t id) const; - void set_promiscuous(uint8_t port_id, bool enabled) const; - bool get_promiscuous(uint8_t port_id) const; void flush_dp_messages() const; int get_active_pgids(flow_stat_active_t &result) const; int get_cpu_util_full(cpu_util_full_t &result) const; int get_mbuf_util(Json::Value &result) const; void mark_for_shutdown() const; CFlowStatParser *get_flow_stat_parser() const; + TRexPortAttr *getPortAttrObj(uint8_t port_id) const; + + int get_xstats_values(uint8_t port_id, xstats_values_t &xstats_values) const; + int get_xstats_names(uint8_t port_id, xstats_names_t &xstats_names) const; }; @@ -209,6 +214,11 @@ public: SimPlatformApi(int dp_core_count) { m_dp_core_count = dp_core_count; + m_port_attr = new SimTRexPortAttr(); + } + + ~SimPlatformApi() { + delete m_port_attr; } virtual uint8_t get_dp_core_count() const { @@ -221,7 +231,6 @@ public: virtual void get_interface_info(uint8_t interface_id, intf_info_st &info) const { info.driver_name = "TEST"; - info.speed = 10000; info.has_crc = true; info.numa_node = 0; @@ -241,6 +250,10 @@ public: virtual void publish_async_data_now(uint32_t key, bool baseline) const { } + + virtual void publish_async_port_attr_changed(uint8_t port_id) const { + } + int get_flow_stats(uint8_t port_id, void *stats, void *tx_stats, int min, int max, bool reset , TrexPlatformApi::driver_stat_cap_e type) const {return 0;}; virtual int get_rfc2544_info(void *rfc2544_info, int min, int max, bool reset) const {return 0;}; @@ -251,11 +264,6 @@ public: , uint8_t ipv6_next_h, uint16_t id) const {return 0;}; virtual int del_rx_flow_stat_rule(uint8_t port_id, uint16_t l3_type, uint8_t l4_proto , uint8_t ipv6_next_h, 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; - } void flush_dp_messages() const { } @@ -263,11 +271,15 @@ public: int get_cpu_util_full(cpu_util_full_t &result) const {return 0;} int get_mbuf_util(Json::Value &result) const {return 0;} CFlowStatParser *get_flow_stat_parser() const {return new CFlowStatParser();} + TRexPortAttr *getPortAttrObj(uint8_t port_id) const {return m_port_attr;} void mark_for_shutdown() const {} + int get_xstats_values(uint8_t port_id, xstats_values_t &xstats_values) const {return 0;}; + int get_xstats_names(uint8_t port_id, xstats_names_t &xstats_names) const {return 0;}; private: int m_dp_core_count; + SimTRexPortAttr * m_port_attr; }; #endif /* __TREX_PLATFORM_API_H__ */ diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp index 46fa7335..fbd55173 100644 --- a/src/main_dpdk.cpp +++ b/src/main_dpdk.cpp @@ -77,6 +77,7 @@ extern "C" { #include "stateful_rx_core.h" #include "debug.h" #include "pkt_gen.h" +#include "trex_port_attr.h" #include "internal_api/trex_platform_api.h" #include "main_dpdk.h" #include "trex_watchdog.h" @@ -120,6 +121,15 @@ static inline int get_is_rx_thread_enabled() { struct port_cfg_t; +#define MAX_DPDK_ARGS 40 +static CPlatformYamlInfo global_platform_cfg_info; +static int global_dpdk_args_num ; +static char * global_dpdk_args[MAX_DPDK_ARGS]; +static char global_cores_str[100]; +static char global_prefix_str[100]; +static char global_loglevel_str[20]; + + class CTRexExtendedDriverBase { public: @@ -147,7 +157,6 @@ public: virtual void clear_extended_stats(CPhyEthIF * _if)=0; virtual int wait_for_stable_link(); virtual void wait_after_link_up(); - virtual bool flow_control_disable_supported(){return true;} virtual bool hw_rx_stat_supported(){return false;} virtual int get_rx_stats(CPhyEthIF * _if, uint32_t *pkts, uint32_t *prev_pkts, uint32_t *bytes, uint32_t *prev_bytes , int min, int max) {return -1;} @@ -158,6 +167,7 @@ public: virtual int verify_fw_ver(int i) {return 0;} virtual CFlowStatParser *get_flow_stat_parser(); virtual int set_rcv_all(CPhyEthIF * _if, bool set_on)=0; + virtual TRexPortAttr * create_port_attr(uint8_t port_id) = 0; }; @@ -167,6 +177,10 @@ public: CTRexExtendedDriverBase1G(){ } + TRexPortAttr * create_port_attr(uint8_t port_id) { + return new DpdkTRexPortAttr(port_id, false, true); + } + static CTRexExtendedDriverBase * create(){ return ( new CTRexExtendedDriverBase1G() ); } @@ -212,6 +226,10 @@ public: CGlobalInfo::m_options.preview.set_vm_one_queue_enable(true); } + TRexPortAttr * create_port_attr(uint8_t port_id) { + return new DpdkTRexPortAttr(port_id, true, true); + } + virtual bool has_crc_added() { return false; } @@ -257,6 +275,10 @@ public: CTRexExtendedDriverBase10G(){ } + TRexPortAttr * create_port_attr(uint8_t port_id) { + return new DpdkTRexPortAttr(port_id, false, true); + } + static CTRexExtendedDriverBase * create(){ return ( new CTRexExtendedDriverBase10G() ); } @@ -298,6 +320,11 @@ public: m_if_per_card = 4; } + TRexPortAttr * create_port_attr(uint8_t port_id) { + // disabling flow control on 40G using DPDK API causes the interface to malfunction + return new DpdkTRexPortAttr(port_id, false, false); + } + static CTRexExtendedDriverBase * create(){ return ( new CTRexExtendedDriverBase40G() ); } @@ -325,8 +352,6 @@ public: return TrexPlatformApi::IF_STAT_IPV4_ID | TrexPlatformApi::IF_STAT_PAYLOAD; } virtual int wait_for_stable_link(); - // disabling flow control on 40G using DPDK API causes the interface to malfunction - virtual bool flow_control_disable_supported(){return false;} virtual bool hw_rx_stat_supported(){return true;} virtual int verify_fw_ver(int i); virtual CFlowStatParser *get_flow_stat_parser(); @@ -347,6 +372,10 @@ public: CTRexExtendedDriverBaseVIC(){ } + TRexPortAttr * create_port_attr(uint8_t port_id) { + return new DpdkTRexPortAttr(port_id, false, false); + } + static CTRexExtendedDriverBase * create(){ return ( new CTRexExtendedDriverBaseVIC() ); } @@ -357,8 +386,6 @@ public: virtual int verify_fw_ver(int i) {return 0;} - bool flow_control_disable_supported(){return false;} - virtual void update_configuration(port_cfg_t * cfg); }; @@ -413,12 +440,12 @@ private: register_driver(std::string("rte_ixgbe_pmd"),CTRexExtendedDriverBase10G::create); register_driver(std::string("rte_igb_pmd"),CTRexExtendedDriverBase1G::create); register_driver(std::string("rte_i40e_pmd"),CTRexExtendedDriverBase40G::create); + register_driver(std::string("rte_enic_pmd"),CTRexExtendedDriverBaseVIC::create); /* virtual devices */ register_driver(std::string("rte_em_pmd"),CTRexExtendedDriverBase1GVm::create); register_driver(std::string("rte_vmxnet3_pmd"),CTRexExtendedDriverBase1GVm::create); register_driver(std::string("rte_virtio_pmd"),CTRexExtendedDriverBase1GVm::create); - register_driver(std::string("rte_enic_pmd"),CTRexExtendedDriverBaseVIC::create); @@ -488,14 +515,6 @@ static inline int get_min_sample_rate(void){ return ( get_ex_drv()->get_min_sample_rate()); } -#define MAX_DPDK_ARGS 40 -static CPlatformYamlInfo global_platform_cfg_info; -static int global_dpdk_args_num ; -static char * global_dpdk_args[MAX_DPDK_ARGS]; -static char global_cores_str[100]; -static char global_prefix_str[100]; -static char global_loglevel_str[20]; - // cores =0==1,1*2,2,3,4,5,6 // An enum for all the option types enum { OPT_HELP, @@ -589,6 +608,7 @@ static CSimpleOpt::SOption parser_options[] = { OPT_NO_FLOW_CONTROL, "--no-flow-control-change", SO_NONE }, { OPT_VLAN, "--vlan", SO_NONE }, { OPT_CLIENT_CFG_FILE, "--client_cfg", SO_REQ_SEP }, + { OPT_CLIENT_CFG_FILE, "--client-cfg", SO_REQ_SEP }, { OPT_NO_KEYBOARD_INPUT ,"--no-key", SO_NONE }, { OPT_VIRT_ONE_TX_RX_QUEUE, "--vm-sim", SO_NONE }, { OPT_PREFIX, "--prefix", SO_REQ_SEP }, @@ -1443,9 +1463,107 @@ void CPhyEthIF::disable_flow_control(){ ret, m_port_id); } +/* +Get user frienly devices description from saved env. var +Changes certain attributes based on description +*/ +void DpdkTRexPortAttr::update_description(){ + struct rte_pci_addr pci_addr; + char pci[16]; + char * envvar; + std::string pci_envvar_name; + pci_addr = rte_eth_devices[m_port_id].pci_dev->addr; + snprintf(pci, sizeof(pci), "%04x:%02x:%02x.%d", pci_addr.domain, pci_addr.bus, pci_addr.devid, pci_addr.function); + intf_info_st.pci_addr = pci; + pci_envvar_name = "pci" + intf_info_st.pci_addr; + std::replace(pci_envvar_name.begin(), pci_envvar_name.end(), ':', '_'); + std::replace(pci_envvar_name.begin(), pci_envvar_name.end(), '.', '_'); + envvar = std::getenv(pci_envvar_name.c_str()); + if (envvar) { + intf_info_st.description = envvar; + } else { + intf_info_st.description = "Unknown"; + } + if (intf_info_st.description.find("82599ES") != std::string::npos) { // works for 82599EB etc. DPDK does not distinguish them + flag_is_link_change_supported = false; + } + if (intf_info_st.description.find("82545EM") != std::string::npos) { // in virtual E1000, DPDK claims fc is supported, but it's not + flag_is_fc_change_supported = false; + flag_is_led_change_supported = false; + } + if ( CGlobalInfo::m_options.preview.getVMode() > 0){ + printf("port %d desc: %s\n", m_port_id, intf_info_st.description.c_str()); + } +} + +int DpdkTRexPortAttr::set_led(bool on){ + if (on) { + return rte_eth_led_on(m_port_id); + }else{ + return rte_eth_led_off(m_port_id); + } +} + +int DpdkTRexPortAttr::get_flow_ctrl(int &mode) { + int ret = rte_eth_dev_flow_ctrl_get(m_port_id, &fc_conf_tmp); + if (ret) { + return ret; + } + mode = (int) fc_conf_tmp.mode; + return 0; +} + +int DpdkTRexPortAttr::set_flow_ctrl(int mode) { + if (!flag_is_fc_change_supported) { + return -ENOTSUP; + } + int ret = rte_eth_dev_flow_ctrl_get(m_port_id, &fc_conf_tmp); + if (ret) { + return ret; + } + fc_conf_tmp.mode = (enum rte_eth_fc_mode) mode; + return rte_eth_dev_flow_ctrl_set(m_port_id, &fc_conf_tmp); +} + +void DpdkTRexPortAttr::reset_xstats() { + rte_eth_xstats_reset(m_port_id); +} + +int DpdkTRexPortAttr::get_xstats_values(xstats_values_t &xstats_values) { + int size = rte_eth_xstats_get(m_port_id, NULL, 0); + if (size < 0) { + return size; + } + xstats_values_tmp.resize(size); + xstats_values.resize(size); + size = rte_eth_xstats_get(m_port_id, xstats_values_tmp.data(), size); + if (size < 0) { + return size; + } + for (int i=0; i<size; i++) { + xstats_values[xstats_values_tmp[i].id] = xstats_values_tmp[i].value; + } + return 0; +} +int DpdkTRexPortAttr::get_xstats_names(xstats_names_t &xstats_names){ + int size = rte_eth_xstats_get_names(m_port_id, NULL, 0); + if (size < 0) { + return size; + } + xstats_names_tmp.resize(size); + xstats_names.resize(size); + size = rte_eth_xstats_get_names(m_port_id, xstats_names_tmp.data(), size); + if (size < 0) { + return size; + } + for (int i=0; i<size; i++) { + xstats_names[i] = xstats_names_tmp[i].name; + } + return 0; +} -void CPhyEthIF::dump_link(FILE *fd){ +void DpdkTRexPortAttr::dump_link(FILE *fd){ fprintf(fd,"port : %d \n",(int)m_port_id); fprintf(fd,"------------\n"); @@ -1461,32 +1579,66 @@ void CPhyEthIF::dump_link(FILE *fd){ fprintf(fd,"promiscuous : %d \n",get_promiscuous()); } -void CPhyEthIF::update_link_status(){ +void DpdkTRexPortAttr::update_device_info(){ + rte_eth_dev_info_get(m_port_id, &dev_info); +} + +void DpdkTRexPortAttr::get_supported_speeds(supp_speeds_t &supp_speeds){ + uint32_t speed_capa = dev_info.speed_capa; + if (speed_capa & ETH_LINK_SPEED_1G) + supp_speeds.push_back(ETH_SPEED_NUM_1G); + if (speed_capa & ETH_LINK_SPEED_10G) + supp_speeds.push_back(ETH_SPEED_NUM_10G); + if (speed_capa & ETH_LINK_SPEED_40G) + supp_speeds.push_back(ETH_SPEED_NUM_40G); + if (speed_capa & ETH_LINK_SPEED_100G) + supp_speeds.push_back(ETH_SPEED_NUM_100G); +} + +void DpdkTRexPortAttr::update_link_status(){ rte_eth_link_get(m_port_id, &m_link); } -void CPhyEthIF::update_link_status_nowait(){ - rte_eth_link_get_nowait(m_port_id, &m_link); +bool DpdkTRexPortAttr::update_link_status_nowait(){ + rte_eth_link new_link; + bool changed = false; + rte_eth_link_get_nowait(m_port_id, &new_link); + if (new_link.link_speed != m_link.link_speed || + new_link.link_duplex != m_link.link_duplex || + new_link.link_autoneg != m_link.link_autoneg || + new_link.link_status != m_link.link_status) { + changed = true; + } + m_link = new_link; + return changed; } -void CPhyEthIF::add_mac(char * mac){ +int DpdkTRexPortAttr::add_mac(char * mac){ struct ether_addr mac_addr; - int i=0; - for (i=0; i<6;i++) { + for (int i=0; i<6;i++) { mac_addr.addr_bytes[i] =mac[i]; } - rte_eth_dev_mac_addr_add(m_port_id, &mac_addr,0); + return rte_eth_dev_mac_addr_add(m_port_id, &mac_addr,0); } -void CPhyEthIF::set_promiscuous(bool enable){ +int DpdkTRexPortAttr::set_promiscuous(bool enable){ if (enable) { rte_eth_promiscuous_enable(m_port_id); }else{ rte_eth_promiscuous_disable(m_port_id); } + return 0; +} + +int DpdkTRexPortAttr::set_link_up(bool up){ + if (up) { + return rte_eth_dev_set_link_up(m_port_id); + }else{ + return rte_eth_dev_set_link_down(m_port_id); + } } -bool CPhyEthIF::get_promiscuous(){ +bool DpdkTRexPortAttr::get_promiscuous(){ int ret=rte_eth_promiscuous_get(m_port_id); if (ret<0) { rte_exit(EXIT_FAILURE, "rte_eth_promiscuous_get: " @@ -1498,7 +1650,7 @@ bool CPhyEthIF::get_promiscuous(){ } -void CPhyEthIF::macaddr_get(struct ether_addr *mac_addr){ +void DpdkTRexPortAttr::macaddr_get(struct ether_addr *mac_addr){ rte_eth_macaddr_get(m_port_id , mac_addr); } @@ -1929,12 +2081,22 @@ int CCoreEthIF::send_pkt_lat(CCorePerPort *lp_port, rte_mbuf_t *m, CVirtualIFPer int ret = lp_port->m_port->tx_burst(lp_port->m_tx_queue_id_lat, &m, 1); +#ifdef DELAY_IF_NEEDED while ( unlikely( ret != 1 ) ){ rte_delay_us(1); lp_stats->m_tx_queue_full += 1; ret = lp_port->m_port->tx_burst(lp_port->m_tx_queue_id_lat, &m, 1); } +#else + if ( unlikely( ret != 1 ) ) { + lp_stats->m_tx_drop ++; + rte_pktmbuf_free(m); + return 0; + } + +#endif + return ret; } @@ -2826,6 +2988,7 @@ public: void publish_async_data(bool sync_now, bool baseline = false); void publish_async_barrier(uint32_t key); + void publish_async_port_attr_changed(uint8_t port_id); void dump_stats(FILE *fd, CGlobalStats::DumpFormat format); @@ -2867,6 +3030,7 @@ public: CLatencyManager m_mg; // statefull RX core CRxCoreStateless m_rx_sl; // stateless RX core CTrexGlobalIoMode m_io_modes; + CTRexExtendedDriverBase * m_drv; private: CLatencyHWPort m_latency_vports[TREX_MAX_PORTS]; /* read hardware driver */ @@ -2920,7 +3084,7 @@ void CGlobalTRex::pre_test() { do { ret = pretest.resolve_all(); count++; - } while ((ret != true) && (count < 3)); + } while ((ret != true) && (count < 10)); if ( CGlobalInfo::m_options.preview.getVMode() > 0) { pretest.dump(stdout); @@ -3000,11 +3164,11 @@ bool CGlobalTRex::is_all_links_are_up(bool dump){ int i; for (i=0; i<m_max_ports; i++) { CPhyEthIF * _if=&m_ports[i]; - _if->update_link_status(); + _if->get_port_attr()->update_link_status(); if ( dump ){ _if->dump_stats(stdout); } - if ( _if->is_link_up() == false){ + if ( _if->get_port_attr()->is_link_up() == false){ all_link_are=false; break; } @@ -3234,11 +3398,11 @@ int CGlobalTRex::ixgbe_start(void){ _if->configure_rx_duplicate_rules(); if ( ! get_vm_one_queue_enable() && ! CGlobalInfo::m_options.preview.get_is_disable_flow_control_setting() - && get_ex_drv()->flow_control_disable_supported()) { + && _if->get_port_attr()->is_fc_change_supported()) { _if->disable_flow_control(); } - _if->add_mac((char *)CGlobalInfo::m_options.get_src_mac_addr(i)); + _if->get_port_attr()->add_mac((char *)CGlobalInfo::m_options.get_src_mac_addr(i)); fflush(stdout); } @@ -3247,7 +3411,7 @@ int CGlobalTRex::ixgbe_start(void){ /* wait for ports to be stable */ get_ex_drv()->wait_for_stable_link(); - if ( !is_all_links_are_up(true) ){ + if ( !is_all_links_are_up(true) /*&& !get_is_stateless()*/ ){ // disable start with link down for now dump_links_status(stdout); rte_exit(EXIT_FAILURE, " " " one of the link is down \n"); @@ -3478,10 +3642,11 @@ int CGlobalTRex::ixgbe_prob_init(void){ } CTRexExtendedDriverDb::Ins()->set_driver_name(dev_info.driver_name); + m_drv = CTRexExtendedDriverDb::Ins()->get_drv(); // check if firmware version is new enough for (i = 0; i < m_max_ports; i++) { - if (CTRexExtendedDriverDb::Ins()->get_drv()->verify_fw_ver(i) < 0) { + if (m_drv->verify_fw_ver(i) < 0) { // error message printed by verify_fw_ver exit(1); } @@ -3552,9 +3717,8 @@ void CGlobalTRex::dump_config(FILE *fd){ void CGlobalTRex::dump_links_status(FILE *fd){ for (int i=0; i<m_max_ports; i++) { - CPhyEthIF * _if=&m_ports[i]; - _if->update_link_status_nowait(); - _if->dump_link(fd); + m_ports[i].get_port_attr()->update_link_status_nowait(); + m_ports[i].get_port_attr()->dump_link(fd); } } @@ -4001,11 +4165,37 @@ CGlobalTRex::publish_async_barrier(uint32_t key) { m_zmq_publisher.publish_barrier(key); } +void +CGlobalTRex:: publish_async_port_attr_changed(uint8_t port_id) { + Json::Value data; + data["port_id"] = port_id; + TRexPortAttr * _attr = m_ports[port_id].get_port_attr(); + + /* attributes */ + data["attr"]["speed"] = _attr->get_link_speed(); + data["attr"]["promiscuous"]["enabled"] = _attr->get_promiscuous(); + data["attr"]["link"]["up"] = _attr->is_link_up(); + int mode; + int ret = _attr->get_flow_ctrl(mode); + if (ret != 0) { + mode = -1; + } + data["attr"]["fc"]["mode"] = mode; + + m_zmq_publisher.publish_event(TrexPublisher::EVENT_PORT_ATTR_CHANGED, data); +} void CGlobalTRex::handle_slow_path() { m_stats_cnt+=1; + // update speed, link up/down etc. + for (int i=0; i<m_max_ports; i++) { + bool changed = m_ports[i].get_port_attr()->update_link_status_nowait(); + if (changed) { + publish_async_port_attr_changed(i); + } + } if ( CGlobalInfo::m_options.preview.get_no_keyboard() ==false ) { if ( m_io_modes.handle_io_modes() ) { @@ -4487,6 +4677,7 @@ bool CPhyEthIF::Create(uint8_t portid) { m_last_rx_rate = 0.0; m_last_tx_rate = 0.0; m_last_tx_pps = 0.0; + m_port_attr = g_trex.m_drv->create_port_attr(portid); return true; } @@ -6203,6 +6394,15 @@ static void trex_termination_handler(int signum) { * TODO: REMOVE THIS TO A SEPERATE FILE * **********************************************************/ +int TrexDpdkPlatformApi::get_xstats_values(uint8_t port_id, xstats_values_t &xstats_values) const { + return g_trex.m_ports[port_id].get_port_attr()->get_xstats_values(xstats_values); +} + +int TrexDpdkPlatformApi::get_xstats_names(uint8_t port_id, xstats_names_t &xstats_names) const { + return g_trex.m_ports[port_id].get_port_attr()->get_xstats_names(xstats_names); +} + + void TrexDpdkPlatformApi::get_port_num(uint8_t &port_num) const { port_num = g_trex.m_max_ports; } @@ -6248,19 +6448,18 @@ TrexDpdkPlatformApi::port_id_to_cores(uint8_t port_id, std::vector<std::pair<uin cores_id_list = lpt->get_core_list(); } + void TrexDpdkPlatformApi::get_interface_info(uint8_t interface_id, intf_info_st &info) const { struct ether_addr rte_mac_addr; info.driver_name = CTRexExtendedDriverDb::Ins()->get_driver_name(); - g_trex.m_ports[interface_id].update_link_status_nowait(); - g_trex.m_ports[interface_id].get_link_speed(&info.speed); info.has_crc = CTRexExtendedDriverDb::Ins()->get_drv()->has_crc_added(); /* mac INFO */ /* hardware */ - g_trex.m_ports[interface_id].macaddr_get(&rte_mac_addr); + g_trex.m_ports[interface_id].get_port_attr()->macaddr_get(&rte_mac_addr); assert(ETHER_ADDR_LEN == 6); /* software */ @@ -6268,6 +6467,7 @@ TrexDpdkPlatformApi::get_interface_info(uint8_t interface_id, intf_info_st &info 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]; @@ -6289,6 +6489,11 @@ TrexDpdkPlatformApi::publish_async_data_now(uint32_t key, bool baseline) const { } void +TrexDpdkPlatformApi::publish_async_port_attr_changed(uint8_t port_id) const { + g_trex.publish_async_port_attr_changed(port_id); +} + +void TrexDpdkPlatformApi::get_interface_stat_info(uint8_t interface_id, uint16_t &num_counters, uint16_t &capabilities) const { num_counters = CTRexExtendedDriverDb::Ins()->get_drv()->get_stat_counters_num(); capabilities = CTRexExtendedDriverDb::Ins()->get_drv()->get_rx_stat_capabilities(); @@ -6329,14 +6534,6 @@ int TrexDpdkPlatformApi::del_rx_flow_stat_rule(uint8_t port_id, uint16_t l3_type ->add_del_rx_flow_stat_rule(port_id, RTE_ETH_FILTER_DELETE, l3_type, l4_proto, ipv6_next_h, 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(); -} - void TrexDpdkPlatformApi::flush_dp_messages() const { g_trex.check_for_dp_messages(); } @@ -6376,6 +6573,10 @@ CFlowStatParser *TrexDpdkPlatformApi::get_flow_stat_parser() const { return CTRexExtendedDriverDb::Ins()->get_drv()->get_flow_stat_parser(); } +TRexPortAttr *TrexDpdkPlatformApi::getPortAttrObj(uint8_t port_id) const { + return g_trex.m_ports[port_id].get_port_attr(); +} + /** * marks the control plane for a total server shutdown * diff --git a/src/main_dpdk.h b/src/main_dpdk.h index 97994c47..6402d106 100644 --- a/src/main_dpdk.h +++ b/src/main_dpdk.h @@ -87,7 +87,6 @@ class CPhyEthIF { void configure(uint16_t nb_rx_queue, uint16_t nb_tx_queue, const struct rte_eth_conf *eth_conf); - void macaddr_get(struct ether_addr *mac_addr); void get_stats(CPhyEthIFStats *stats); int dump_fdir_global_stats(FILE *fd); int reset_hw_flow_stats(); @@ -106,19 +105,7 @@ class CPhyEthIF { void configure_rx_duplicate_rules(); void start(); void stop(); - void update_link_status(); - void update_link_status_nowait(); - bool is_link_up(){ - return (m_link.link_status?true:false); - } - void get_link_speed(uint32_t *link_speed){ - *link_speed = m_link.link_speed; - } - void dump_link(FILE *fd); void disable_flow_control(); - void set_promiscuous(bool enable); - void add_mac(char * mac); - bool get_promiscuous(); void dump_stats(FILE *fd); void set_ignore_stats_base(CPreTestStats &pre_stats); void update_counters(); @@ -180,9 +167,9 @@ class CPhyEthIF { int get_rx_stat_capabilities(); const std::vector<std::pair<uint8_t, uint8_t>> & get_core_list(); + TRexPortAttr * get_port_attr() { return m_port_attr; } private: - struct rte_eth_link m_link; uint8_t m_port_id; uint8_t m_rx_queue; uint64_t m_sw_try_tx_pkt; @@ -193,6 +180,7 @@ class CPhyEthIF { CPPSMeasure m_pps_rx; CPhyEthIFStats m_stats; CPhyEthIgnoreStats m_ignore_stats; + TRexPortAttr *m_port_attr; float m_last_tx_rate; float m_last_rx_rate; float m_last_tx_pps; diff --git a/src/pal/linux/rte_ethdev_includes.h b/src/pal/linux/rte_ethdev_includes.h new file mode 100644 index 00000000..e957b68b --- /dev/null +++ b/src/pal/linux/rte_ethdev_includes.h @@ -0,0 +1,27 @@ +#ifndef __RTE_ETHDEV_INCLUDES_H__ +#define __RTE_ETHDEV_INCLUDES_H__ + +struct rte_eth_link { + int link_autoneg; + int link_speed; + int link_duplex; + int link_status; +}; + + +enum rte_eth_fc_mode { +}; + +struct rte_eth_xstat { +}; + +struct rte_eth_xstat_name { +}; + +struct rte_eth_fc_conf { +}; + +struct rte_eth_dev_info { +}; + +#endif /* __RTE_ETHDEV_INCLUDES_H__ */ diff --git a/src/pal/linux_dpdk/rte_ethdev_includes.h b/src/pal/linux_dpdk/rte_ethdev_includes.h new file mode 100644 index 00000000..0429fe44 --- /dev/null +++ b/src/pal/linux_dpdk/rte_ethdev_includes.h @@ -0,0 +1,6 @@ +#ifndef __RTE_ETHDEV_INCLUDES_H__ +#define __RTE_ETHDEV_INCLUDES_H__ + +#include <rte_ethdev.h> + +#endif /* __RTE_ETHDEV_INCLUDES_H__ */
\ No newline at end of file diff --git a/src/publisher/trex_publisher.h b/src/publisher/trex_publisher.h index fb7226c4..522c8c69 100644 --- a/src/publisher/trex_publisher.h +++ b/src/publisher/trex_publisher.h @@ -49,6 +49,7 @@ public: EVENT_PORT_ACQUIRED = 5, EVENT_PORT_RELEASED = 6, EVENT_PORT_ERROR = 7, + EVENT_PORT_ATTR_CHANGED = 8, EVENT_SERVER_STOPPED = 100, diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp index 342ec594..109cc1a4 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp @@ -295,6 +295,8 @@ TrexRpcCmdGetSysInfo::_run(const Json::Value ¶ms, Json::Value &result) { string src_macaddr; string dst_macaddr; string pci_addr; + string description; + supp_speeds_t supp_speeds; int numa; TrexStatelessPort *port = main->get_port_by_id(i); @@ -302,10 +304,13 @@ TrexRpcCmdGetSysInfo::_run(const Json::Value ¶ms, Json::Value &result) { port->get_macaddr(hw_macaddr, src_macaddr, dst_macaddr); port->get_pci_info(pci_addr, numa); + main->get_platform_api()->getPortAttrObj(i)->get_description(description); + main->get_platform_api()->getPortAttrObj(i)->get_supported_speeds(supp_speeds); section["ports"][i]["index"] = i; section["ports"][i]["driver"] = driver; + section["ports"][i]["description"] = description; section["ports"][i]["hw_macaddr"] = hw_macaddr; section["ports"][i]["src_macaddr"] = src_macaddr; section["ports"][i]["dst_macaddr"] = dst_macaddr; @@ -326,6 +331,14 @@ TrexRpcCmdGetSysInfo::_run(const Json::Value ¶ms, Json::Value &result) { } section["ports"][i]["rx"]["counters"] = port->get_rx_count_num(); section["ports"][i]["speed"] = (uint16_t) speed / 1000; + section["ports"][i]["is_fc_supported"] = get_stateless_obj()->get_platform_api()->getPortAttrObj(i)->is_fc_change_supported(); + section["ports"][i]["is_led_supported"] = get_stateless_obj()->get_platform_api()->getPortAttrObj(i)->is_led_change_supported(); + section["ports"][i]["is_link_supported"] = get_stateless_obj()->get_platform_api()->getPortAttrObj(i)->is_link_change_supported(); + section["ports"][i]["is_virtual"] = get_stateless_obj()->get_platform_api()->getPortAttrObj(i)->is_virtual(); + section["ports"][i]["supp_speeds"] = Json::arrayValue; + for (int speed_id=0; speed_id<supp_speeds.size(); speed_id++) { + section["ports"][i]["supp_speeds"].append(supp_speeds[speed_id]); + } } @@ -346,19 +359,45 @@ trex_rpc_cmd_rc_e TrexRpcCmdSetPortAttr::_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 Json::Value &attr = parse_object(params, "attr", result); - + int ret = 0; + bool changed = false; /* 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); + ret = get_stateless_obj()->get_platform_api()->getPortAttrObj(port_id)->set_promiscuous(enabled); + } + else if (name == "link_status") { + bool up = parse_bool(attr[name], "up", result); + ret = get_stateless_obj()->get_platform_api()->getPortAttrObj(port_id)->set_link_up(up); + } + else if (name == "led_status") { + bool on = parse_bool(attr[name], "on", result); + ret = get_stateless_obj()->get_platform_api()->getPortAttrObj(port_id)->set_led(on); + } else if (name == "flow_ctrl_mode") { + int mode = parse_int(attr[name], "mode", result); + ret = get_stateless_obj()->get_platform_api()->getPortAttrObj(port_id)->set_flow_ctrl(mode); + } else { + generate_execute_err(result, "Not recognized attribute: " + name); + break; + } + if (ret != 0){ + if ( ret == -ENOTSUP ) { + generate_execute_err(result, "Error applying " + name + ": operation is not supported for this NIC."); + } + else if (ret) { + generate_execute_err(result, "Error applying " + name + " attribute, return value: " + to_string(ret)); + } + break; + } else { + changed = true; } } + if (changed) { + get_stateless_obj()->get_platform_api()->publish_async_port_attr_changed(port_id); + } result["result"] = Json::objectValue; return (TREX_RPC_CMD_OK); @@ -437,6 +476,60 @@ TrexRpcCmdRelease::_run(const Json::Value ¶ms, Json::Value &result) { } /** + * get port extended stats names (keys of dict) + * + */ +trex_rpc_cmd_rc_e +TrexRpcCmdGetPortXStatsNames::_run(const Json::Value ¶ms, Json::Value &result) { + + uint8_t port_id = parse_port(params, result); + xstats_names_t xstats_names; + + int ret = get_stateless_obj()->get_platform_api()->get_xstats_names(port_id, xstats_names); + if (ret < 0) { + if ( ret == -ENOTSUP ) { + generate_execute_err(result, "Operation not supported"); + } + else if (ret) { + generate_execute_err(result, "Operation failed, error code: " + to_string(ret)); + } + } else { + for (int i=0; i<xstats_names.size(); i++) { + result["result"]["xstats_names"].append(xstats_names[i]); + } + } + + return (TREX_RPC_CMD_OK); +} + +/** + * get port extended stats (values of dict) + * + */ +trex_rpc_cmd_rc_e +TrexRpcCmdGetPortXStatsValues::_run(const Json::Value ¶ms, Json::Value &result) { + + uint8_t port_id = parse_port(params, result); + xstats_values_t xstats_values; + + int ret = get_stateless_obj()->get_platform_api()->get_xstats_values(port_id, xstats_values); + if (ret < 0) { + if ( ret == -ENOTSUP ) { + generate_execute_err(result, "Operation not supported"); + } + else if (ret) { + generate_execute_err(result, "Operation failed, error code: " + to_string(ret)); + } + } else { + for (int i=0; i<xstats_values.size(); i++) { + result["result"]["xstats_values"].append((Json::Value::UInt64) xstats_values[i]); + } + } + + return (TREX_RPC_CMD_OK); +} + +/** * get port stats * */ @@ -475,9 +568,17 @@ 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"]["speed"] = get_stateless_obj()->get_platform_api()->getPortAttrObj(port_id)->get_link_speed(); /* attributes */ - result["result"]["attr"]["promiscuous"]["enabled"] = port->get_promiscuous(); + result["result"]["attr"]["promiscuous"]["enabled"] = get_stateless_obj()->get_platform_api()->getPortAttrObj(port_id)->get_promiscuous(); + result["result"]["attr"]["link"]["up"] = get_stateless_obj()->get_platform_api()->getPortAttrObj(port_id)->is_link_up(); + int mode; + int ret = get_stateless_obj()->get_platform_api()->getPortAttrObj(port_id)->get_flow_ctrl(mode); + if (ret != 0) { + mode = -1; + } + result["result"]["attr"]["fc"]["mode"] = mode; 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 a68796ae..5fde1d0c 100644 --- a/src/rpc-server/commands/trex_rpc_cmds.h +++ b/src/rpc-server/commands/trex_rpc_cmds.h @@ -87,9 +87,11 @@ TREX_RPC_CMD_DEFINE(TrexRpcCmdRelease, "release", 1, true, APIClass: /** * port commands */ -TREX_RPC_CMD_DEFINE(TrexRpcCmdGetPortStats, "get_port_stats", 1, false, APIClass::API_CLASS_TYPE_CORE); -TREX_RPC_CMD_DEFINE(TrexRpcCmdGetPortStatus, "get_port_status", 1, false, APIClass::API_CLASS_TYPE_CORE); -TREX_RPC_CMD_DEFINE(TrexRpcCmdSetPortAttr, "set_port_attr", 3, false, APIClass::API_CLASS_TYPE_CORE); +TREX_RPC_CMD_DEFINE(TrexRpcCmdGetPortStats, "get_port_stats", 1, false, APIClass::API_CLASS_TYPE_CORE); +TREX_RPC_CMD_DEFINE(TrexRpcCmdGetPortStatus, "get_port_status", 1, false, APIClass::API_CLASS_TYPE_CORE); +TREX_RPC_CMD_DEFINE(TrexRpcCmdSetPortAttr, "set_port_attr", 2, true, APIClass::API_CLASS_TYPE_CORE); +TREX_RPC_CMD_DEFINE(TrexRpcCmdGetPortXStatsValues, "get_port_xstats_values", 1, false, APIClass::API_CLASS_TYPE_CORE); +TREX_RPC_CMD_DEFINE(TrexRpcCmdGetPortXStatsNames, "get_port_xstats_names", 1, false, APIClass::API_CLASS_TYPE_CORE); /** * stream cmds diff --git a/src/rpc-server/trex_rpc_cmd.cpp b/src/rpc-server/trex_rpc_cmd.cpp index 28145f13..265d426b 100644 --- a/src/rpc-server/trex_rpc_cmd.cpp +++ b/src/rpc-server/trex_rpc_cmd.cpp @@ -87,7 +87,7 @@ TrexRpcCommand::check_param_count(const Json::Value ¶ms, int expected, Json: if (params.size() < expected) { std::stringstream ss; - ss << "method expects at least '" << expected << "' parameter(s), '" << params.size() << "' provided"; + ss << "method '" << m_name << "' expects at least " << expected << " parameter(s), " << params.size() << " provided"; generate_parse_err(result, ss.str()); } } diff --git a/src/rpc-server/trex_rpc_cmds_table.cpp b/src/rpc-server/trex_rpc_cmds_table.cpp index 762dd614..cddf19b9 100644 --- a/src/rpc-server/trex_rpc_cmds_table.cpp +++ b/src/rpc-server/trex_rpc_cmds_table.cpp @@ -47,6 +47,8 @@ TrexRpcCommandsTable::TrexRpcCommandsTable() { register_command(new TrexRpcCmdGetPortStats()); register_command(new TrexRpcCmdGetPortStatus()); register_command(new TrexRpcCmdSetPortAttr()); + register_command(new TrexRpcCmdGetPortXStatsValues()); + register_command(new TrexRpcCmdGetPortXStatsNames()); /* stream commands */ diff --git a/src/rpc-server/trex_rpc_jsonrpc_v2_parser.cpp b/src/rpc-server/trex_rpc_jsonrpc_v2_parser.cpp index 9d9de53a..4fa2447d 100644 --- a/src/rpc-server/trex_rpc_jsonrpc_v2_parser.cpp +++ b/src/rpc-server/trex_rpc_jsonrpc_v2_parser.cpp @@ -192,7 +192,9 @@ void TrexJsonRpcV2Parser::parse_single_request(Json::Value &request, /* lookup the method in the DB */ TrexRpcCommand * rpc_cmd = TrexRpcCommandsTable::get_instance().lookup(method_name); if (!rpc_cmd) { - commands.push_back(new JsonRpcError(msg_id, JSONRPC_V2_ERR_METHOD_NOT_FOUND, "Method not registered")); + std::stringstream err; + err << "Method " << method_name << " not registered"; + commands.push_back(new JsonRpcError(msg_id, JSONRPC_V2_ERR_METHOD_NOT_FOUND, err.str())); return; } diff --git a/src/stateless/cp/trex_stateless.cpp b/src/stateless/cp/trex_stateless.cpp index 22389d6a..6029cbd5 100644 --- a/src/stateless/cp/trex_stateless.cpp +++ b/src/stateless/cp/trex_stateless.cpp @@ -152,10 +152,8 @@ TrexStateless::get_dp_core_count() { void TrexStateless::encode_stats(Json::Value &global) { - const TrexPlatformApi *api = get_stateless_obj()->get_platform_api(); - TrexPlatformGlobalStats stats; - api->get_global_stats(stats); + m_platform_api->get_global_stats(stats); global["cpu_util"] = stats.m_stats.m_cpu_util; global["rx_cpu_util"] = stats.m_stats.m_rx_cpu_util; diff --git a/src/stateless/cp/trex_stateless.h b/src/stateless/cp/trex_stateless.h index 7ea669df..3a1a2c24 100644 --- a/src/stateless/cp/trex_stateless.h +++ b/src/stateless/cp/trex_stateless.h @@ -137,6 +137,18 @@ public: void shutdown(); /** + * fetch xstats names (keys of dict) + * + */ + void encode_xstats_names(Json::Value &global); + + /** + * fetch xstats values + * + */ + void encode_xstats_values(Json::Value &global); + + /** * fetch all the stats * */ diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp index 58410fea..9bb20990 100644 --- a/src/stateless/cp/trex_stateless_port.cpp +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -158,6 +158,7 @@ TrexStatelessPort::TrexStatelessPort(uint8_t port_id, const TrexPlatformApi *api m_port_id = port_id; m_port_state = PORT_STATE_IDLE; + m_platform_api = api; /* get the platform specific data */ api->get_interface_info(port_id, m_api_info); @@ -252,6 +253,11 @@ TrexStatelessPort::start_traffic(const TrexPortMultiplier &mul, double duration, /* on start - we can only provide absolute values */ assert(mul.m_op == TrexPortMultiplier::OP_ABS); + /* check link state */ + if ( !m_platform_api->getPortAttrObj(m_port_id)->is_link_up() && !force ) { + throw TrexException("Link state is DOWN."); + } + /* caclulate the effective factor for DP */ double factor = calculate_effective_factor(mul, force); @@ -278,7 +284,7 @@ TrexStatelessPort::start_traffic(const TrexPortMultiplier &mul, double duration, feeder.set_status(true); - /* generate a message to all the relevant DP cores to start transmitting */ + /* generate a message to all the relevant DP cores to stop transmitting */ assert(m_pending_async_stop_event == TrexDpPortEvents::INVALID_ID); m_pending_async_stop_event = m_dp_events.create_event(new AsyncStopEvent()); @@ -581,7 +587,7 @@ void TrexStatelessPort::get_properties(std::string &driver, uint32_t &speed) { driver = m_api_info.driver_name; - speed = m_api_info.speed; + speed = m_platform_api->getPortAttrObj(m_port_id)->get_link_speed(); } bool @@ -609,10 +615,8 @@ TrexStatelessPort::change_state(port_state_e new_state) { void TrexStatelessPort::encode_stats(Json::Value &port) { - const TrexPlatformApi *api = get_stateless_obj()->get_platform_api(); - TrexPlatformInterfaceStats stats; - api->get_interface_stats(m_port_id, stats); + m_platform_api->get_interface_stats(m_port_id, stats); port["tx_bps"] = stats.m_stats.m_tx_bps; port["rx_bps"] = stats.m_stats.m_rx_bps; @@ -664,7 +668,7 @@ TrexStatelessPort::send_message_to_rx(TrexStatelessCpToRxMsgBase *msg) { uint64_t TrexStatelessPort::get_port_speed_bps() const { - return (uint64_t) m_api_info.speed * 1000 * 1000; + return (uint64_t) m_platform_api->getPortAttrObj(m_port_id)->get_link_speed() * 1000 * 1000; } static inline double @@ -687,6 +691,20 @@ TrexStatelessPort::calculate_effective_factor(const TrexPortMultiplier &mul, boo throw TrexException(ss.str()); } + /* L1 BW must be positive */ + if (expected_l1_rate <= 0){ + stringstream ss; + ss << "Effective bandwidth must be positive, got: " << expected_l1_rate; + throw TrexException(ss.str()); + } + + /* factor must be positive */ + if (factor <= 0) { + stringstream ss; + ss << "Factor must be positive, got: " << factor; + throw TrexException(ss.str()); + } + return factor; } @@ -869,18 +887,6 @@ 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::get_macaddr(std::string &hw_macaddr, std::string &src_macaddr, diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h index 147efc70..e2a2aeba 100644 --- a/src/stateless/cp/trex_stateless_port.h +++ b/src/stateless/cp/trex_stateless_port.h @@ -363,14 +363,6 @@ public: double &percentage); - /** - * set port promiscuous on/off - * - * @param enabled - */ - void set_promiscuous(bool enabled); - bool get_promiscuous(); - void get_macaddr(std::string &hw_macaddr, std::string &src_macaddr, std::string &dst_macaddr); @@ -443,6 +435,7 @@ private: port_state_e m_port_state; TrexPlatformApi::intf_info_st m_api_info; + const TrexPlatformApi *m_platform_api; uint16_t m_rx_count_num; uint16_t m_rx_caps; diff --git a/src/stateless/cp/trex_streams_compiler.h b/src/stateless/cp/trex_streams_compiler.h index c944df4a..43fee09b 100644 --- a/src/stateless/cp/trex_streams_compiler.h +++ b/src/stateless/cp/trex_streams_compiler.h @@ -309,7 +309,7 @@ public: } double get_factor_pps(double req_pps) const { - if ( (req_pps - m_fixed.m_pps) <= 0 ) { + if ( (req_pps - m_fixed.m_pps) < 0 ) { std::stringstream ss; ss << "current stream configuration enforces a minimum rate of '" << m_fixed.m_pps << "' pps"; throw TrexException(ss.str()); @@ -319,7 +319,7 @@ public: } double get_factor_bps_l1(double req_bps_l1) const { - if ( (req_bps_l1 - m_fixed.m_bps_l1) <= 0 ) { + if ( (req_bps_l1 - m_fixed.m_bps_l1) < 0 ) { std::stringstream ss; ss << "current stream configuration enforces a minimum rate of '" << m_fixed.m_bps_l1 << "' BPS L1"; throw TrexException(ss.str()); @@ -329,7 +329,7 @@ public: } double get_factor_bps_l2(double req_bps_l2) const { - if ( (req_bps_l2 - m_fixed.m_bps_l2) <= 0 ) { + if ( (req_bps_l2 - m_fixed.m_bps_l2) < 0 ) { std::stringstream ss; ss << "current stream configuration enforces a minimum rate of '" << m_fixed.m_bps_l2 << "' BPS L2"; throw TrexException(ss.str()); diff --git a/src/trex_defs.h b/src/trex_defs.h index c659c337..8a4bf664 100644 --- a/src/trex_defs.h +++ b/src/trex_defs.h @@ -16,6 +16,7 @@ limitations under the License. #include <set> #include <queue> #include <vector> +#include <string> #ifndef __TREX_DEFS_H__ #define __TREX_DEFS_H__ @@ -52,5 +53,8 @@ struct cpu_vct_st { typedef std::set<uint32_t> flow_stat_active_t; typedef std::set<uint32_t>::iterator flow_stat_active_it_t; typedef std::vector<cpu_vct_st> cpu_util_full_t; +typedef std::vector<std::string> xstats_names_t; +typedef std::vector<uint64_t> xstats_values_t; +typedef std::vector<uint32_t> supp_speeds_t; #endif diff --git a/src/trex_port_attr.h b/src/trex_port_attr.h new file mode 100755 index 00000000..9231e263 --- /dev/null +++ b/src/trex_port_attr.h @@ -0,0 +1,164 @@ +/* +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 __TREX_PORT_ATTR_H__ +#define __TREX_PORT_ATTR_H__ + +#include <string> +#include <vector> +#include "rte_ethdev_includes.h" +#include "trex_defs.h" + + +class TRexPortAttr { +public: + virtual ~TRexPortAttr(){} + +/* UPDATES */ + virtual void update_link_status() = 0; + virtual bool update_link_status_nowait() = 0; // returns true if the status was changed + virtual void update_device_info() = 0; + virtual void reset_xstats() = 0; + virtual void update_description() = 0; + +/* GETTERS */ + virtual bool get_promiscuous() = 0; + virtual void macaddr_get(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); } + virtual bool is_link_up() { return (m_link.link_status ? true : false); } + virtual int get_xstats_values(xstats_values_t &xstats_values) = 0; + virtual int get_xstats_names(xstats_names_t &xstats_names) = 0; + virtual int get_flow_ctrl(int &mode) = 0; + virtual bool is_virtual() { return flag_is_virtual; } + virtual bool is_fc_change_supported() { return flag_is_fc_change_supported; } + virtual bool is_led_change_supported() { return flag_is_led_change_supported; } + 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; + +/* SETTERS */ + virtual int set_promiscuous(bool enabled) = 0; + virtual int add_mac(char * mac) = 0; + virtual int set_link_up(bool up) = 0; + virtual int set_flow_ctrl(int mode) = 0; + virtual int set_led(bool on) = 0; + +/* DUMPS */ + virtual void dump_link(FILE *fd) = 0; + +protected: + uint8_t m_port_id; + rte_eth_link m_link; + struct rte_eth_dev_info dev_info; + bool flag_is_virtual; + bool flag_is_fc_change_supported; + bool flag_is_led_change_supported; + bool flag_is_link_change_supported; + + struct intf_info_st { + std::string pci_addr; + std::string description; + int numa_node; + }intf_info_st; + +}; + +class DpdkTRexPortAttr : public TRexPortAttr { +public: + + DpdkTRexPortAttr(uint8_t port_id, bool is_virtual, bool fc_change_allowed) { + m_port_id = port_id; + flag_is_virtual = is_virtual; + int tmp; + flag_is_fc_change_supported = fc_change_allowed && (get_flow_ctrl(tmp) != -ENOTSUP); + flag_is_led_change_supported = (set_led(true) != -ENOTSUP); + flag_is_link_change_supported = (set_link_up(true) != -ENOTSUP); + update_description(); + update_device_info(); + } + +/* UPDATES */ + virtual void update_link_status(); + virtual bool update_link_status_nowait(); // returns true if the status was changed + virtual void update_device_info(); + virtual void reset_xstats(); + virtual void update_description(); + +/* GETTERS */ + virtual bool get_promiscuous(); + virtual void macaddr_get(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); + virtual void get_supported_speeds(supp_speeds_t &supp_speeds); + +/* SETTERS */ + virtual int set_promiscuous(bool enabled); + virtual int add_mac(char * mac); + virtual int set_link_up(bool up); + virtual int set_flow_ctrl(int mode); + virtual int set_led(bool on); + + +/* DUMPS */ + virtual void dump_link(FILE *fd); + +private: + rte_eth_fc_conf fc_conf_tmp; + std::vector <struct rte_eth_xstat> xstats_values_tmp; + std::vector <struct rte_eth_xstat_name> xstats_names_tmp; + +}; + + +class SimTRexPortAttr : public TRexPortAttr { +public: + SimTRexPortAttr() { + m_link.link_speed = 10000; + m_link.link_duplex = 1; + m_link.link_autoneg = 0; + m_link.link_status = 1; + flag_is_virtual = true; + flag_is_fc_change_supported = false; + flag_is_led_change_supported = false; + flag_is_link_change_supported = false; + } + + /* DUMMY */ + void update_link_status() {} + bool update_link_status_nowait() { return false; } + void update_device_info() {} + void reset_xstats() {} + void update_description() {} + bool get_promiscuous() { return false; } + void macaddr_get(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; } + void get_description(std::string &description) {} + void get_supported_speeds(supp_speeds_t &supp_speeds) {} + int set_promiscuous(bool enabled) { return -ENOTSUP; } + int add_mac(char * mac) { return -ENOTSUP; } + int set_link_up(bool up) { return -ENOTSUP; } + int set_flow_ctrl(int mode) { return -ENOTSUP; } + int set_led(bool on) { return -ENOTSUP; } + void dump_link(FILE *fd) {} +}; + + +#endif /* __TREX_PORT_ATTR_H__ */ diff --git a/src/utl_yaml.cpp b/src/utl_yaml.cpp index 864c86f8..094a3de8 100755 --- a/src/utl_yaml.cpp +++ b/src/utl_yaml.cpp @@ -27,44 +27,8 @@ limitations under the License. #define INADDRSZ 4 -static int my_inet_pton4(const char *src, unsigned char *dst) -{ - static const char digits[] = "0123456789"; - int saw_digit, octets, ch; - unsigned char tmp[INADDRSZ], *tp; - - saw_digit = 0; - octets = 0; - *(tp = tmp) = 0; - while ((ch = *src++) != '\0') { - const char *pch; - - if ((pch = strchr(digits, ch)) != NULL) { - unsigned int _new = *tp * 10 + (pch - digits); - - if (_new > 255) - return (0); - if (! saw_digit) { - if (++octets > 4) - return (0); - saw_digit = 1; - } - *tp = (unsigned char)_new; - } else if (ch == '.' && saw_digit) { - if (octets == 4) - return (0); - *++tp = 0; - saw_digit = 0; - } else - return (0); - } - if (octets < 4) - return (0); - - memcpy(dst, tmp, INADDRSZ); - return (1); -} - +extern int my_inet_pton4(const char *src, unsigned char *dst); +extern int my_inet_pton6(const char *src, unsigned char *dst); bool utl_yaml_read_ip_addr(const YAML::Node& node, const std::string &name, @@ -270,8 +234,6 @@ YAMLParserWrapper::parse_map(const YAML::Node &node, const std::string &name) { uint32_t YAMLParserWrapper::parse_ip(const YAML::Node &node, const std::string &name) { - - try { std::string ip_str; uint32_t ip_num; |