diff options
-rw-r--r-- | scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py | 7 | ||||
-rw-r--r-- | scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py | 3 | ||||
-rw-r--r-- | scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py | 14 | ||||
-rw-r--r-- | src/internal_api/trex_platform_api.h | 12 | ||||
-rw-r--r-- | src/main_dpdk.cpp | 206 | ||||
-rw-r--r-- | src/main_dpdk.h | 2 | ||||
-rw-r--r-- | src/pal/linux_dpdk/rte_ethdev_includes.h | 5 | ||||
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmd_general.cpp | 28 | ||||
-rw-r--r-- | src/stateless/cp/trex_stateless.cpp | 4 | ||||
-rw-r--r-- | src/stateless/cp/trex_stateless.h | 2 | ||||
-rw-r--r-- | src/stateless/cp/trex_stateless_port.cpp | 11 | ||||
-rw-r--r-- | src/stateless/cp/trex_stateless_port.h | 2 | ||||
-rwxr-xr-x | src/trex_port_attr.h | 164 |
13 files changed, 263 insertions, 197 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py index 1ce21973..cec3761f 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py @@ -669,10 +669,7 @@ class Port(object): else: info['prom'] = "N/A" - if 'description' in info: - if len(info['description']) > 18: - info['description'] = info['description'][:18] - else: + if 'description' not in info: info['description'] = "N/A" if 'is_fc_supported' in info: @@ -710,7 +707,7 @@ class Port(object): info = self.get_info() return {"driver": info['driver'], - "description": info.get('description', 'N/A'), + "description": info.get('description', 'N/A')[:18], "HW src mac": info['hw_macaddr'], "SW src mac": info['src_macaddr'], "SW dst mac": info['dst_macaddr'], diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py index 915eabb2..875ad24e 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py @@ -539,8 +539,7 @@ class CTRexInfoGenerator(object): stats_table.set_cols_dtype(['t'] * (len(relevant_ports) + 1)) for key, arr in xstats_data.items(): if include_zero_lines or list(filter(None, arr)): - if len(key) > 28: - key = key[:28] + key = key[:28] stats_table.add_row([key] + arr) return {'xstats:': ExportableStats(None, stats_table)} diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py index 0214d7d7..72ee8972 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/common.py @@ -27,9 +27,9 @@ def user_input(): return raw_input() -def random_id_gen_unsafe(length=8): +class random_id_gen: """ - A generator for creating a random chars id of specific length + Emulated generator for creating a random chars id of specific length :parameters: length : int @@ -40,16 +40,6 @@ def random_id_gen_unsafe(length=8): :return: a random id with each next() request. """ - id_chars = string.ascii_lowercase + string.digits - while True: - return_id = '' - for i in range(length): - return_id += random.choice(id_chars) - yield return_id - - -class random_id_gen: - """ Thread safe version of random_id_gen_unsafe """ def __init__(self, length=8): self.id_chars = string.ascii_lowercase + string.digits self.length = length diff --git a/src/internal_api/trex_platform_api.h b/src/internal_api/trex_platform_api.h index 0141186e..631f9a3e 100644 --- a/src/internal_api/trex_platform_api.h +++ b/src/internal_api/trex_platform_api.h @@ -155,7 +155,7 @@ public: 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() 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; @@ -197,7 +197,7 @@ public: int get_mbuf_util(Json::Value &result) const; void mark_for_shutdown() const; CFlowStatParser *get_flow_stat_parser() const; - TRexPortAttr *getPortAttrObj() 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; @@ -214,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 { @@ -266,7 +271,7 @@ 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() const {printf("Port attributes should not be used in simulation\n"); return NULL;} // dummy + 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;}; @@ -274,6 +279,7 @@ public: 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 8810880a..995f6a4c 100644 --- a/src/main_dpdk.cpp +++ b/src/main_dpdk.cpp @@ -159,7 +159,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 m_port_attr->is_fc_change_supported();} 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;} @@ -170,7 +169,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; - TRexPortAttr * m_port_attr; + virtual TRexPortAttr * create_port_attr(uint8_t port_id) = 0; }; @@ -178,7 +177,10 @@ class CTRexExtendedDriverBase1G : public CTRexExtendedDriverBase { public: CTRexExtendedDriverBase1G(){ - m_port_attr = new TRexPortAttr(global_platform_cfg_info.m_if_list.size(), false, true); + } + + TRexPortAttr * create_port_attr(uint8_t port_id) { + return new DpdkTRexPortAttr(port_id, false, true); } static CTRexExtendedDriverBase * create(){ @@ -224,7 +226,10 @@ public: CTRexExtendedDriverBase1GVm(){ /* we are working in mode that we have 1 queue for rx and one queue for tx*/ CGlobalInfo::m_options.preview.set_vm_one_queue_enable(true); - m_port_attr = new TRexPortAttr(global_platform_cfg_info.m_if_list.size(), true, true); + } + + TRexPortAttr * create_port_attr(uint8_t port_id) { + return new DpdkTRexPortAttr(port_id, true, true); } virtual bool has_crc_added() { @@ -270,7 +275,10 @@ public: class CTRexExtendedDriverBase10G : public CTRexExtendedDriverBase { public: CTRexExtendedDriverBase10G(){ - m_port_attr = new TRexPortAttr(global_platform_cfg_info.m_if_list.size(), false, true); + } + + TRexPortAttr * create_port_attr(uint8_t port_id) { + return new DpdkTRexPortAttr(port_id, false, true); } static CTRexExtendedDriverBase * create(){ @@ -312,8 +320,11 @@ public: // If we want to support more counters in case of card having less interfaces, we // Will have to identify the number of interfaces dynamically. 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 - m_port_attr = new TRexPortAttr(global_platform_cfg_info.m_if_list.size(), false, false); + return new DpdkTRexPortAttr(port_id, false, false); } static CTRexExtendedDriverBase * create(){ @@ -361,7 +372,10 @@ private: class CTRexExtendedDriverBaseVIC : public CTRexExtendedDriverBase40G { public: CTRexExtendedDriverBaseVIC(){ - m_port_attr = new TRexPortAttr(global_platform_cfg_info.m_if_list.size(), false, false); + } + + TRexPortAttr * create_port_attr(uint8_t port_id) { + return new DpdkTRexPortAttr(port_id, false, false); } static CTRexExtendedDriverBase * create(){ @@ -1455,47 +1469,45 @@ void CPhyEthIF::disable_flow_control(){ Get user frienly devices description from saved env. var Changes certain attributes based on description */ -void TRexPortAttr::update_descriptions(){ +void DpdkTRexPortAttr::update_description(){ struct rte_pci_addr pci_addr; char pci[16]; char * envvar; std::string pci_envvar_name; - for (uint8_t port_id=0; port_id<total_ports; port_id++) { - pci_addr = rte_eth_devices[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[port_id].pci_addr = pci; - pci_envvar_name = "pci" + intf_info_st[port_id].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[port_id].description = envvar; - } else { - intf_info_st[port_id].description = "Unknown"; - } - if (intf_info_st[port_id].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[port_id].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", port_id, intf_info_st[port_id].description.c_str()); - } + 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 TRexPortAttr::set_led(uint8_t port_id, bool on){ +int DpdkTRexPortAttr::set_led(bool on){ if (on) { - return rte_eth_led_on(port_id); + return rte_eth_led_on(m_port_id); }else{ - return rte_eth_led_off(port_id); + return rte_eth_led_off(m_port_id); } } -int TRexPortAttr::get_flow_ctrl(uint8_t port_id, int &mode) { - int ret = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf_tmp); +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; } @@ -1503,30 +1515,30 @@ int TRexPortAttr::get_flow_ctrl(uint8_t port_id, int &mode) { return 0; } -int TRexPortAttr::set_flow_ctrl(uint8_t port_id, int mode) { +int DpdkTRexPortAttr::set_flow_ctrl(int mode) { if (!flag_is_fc_change_supported) { return -ENOTSUP; } - int ret = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf_tmp); + 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(port_id, &fc_conf_tmp); + return rte_eth_dev_flow_ctrl_set(m_port_id, &fc_conf_tmp); } -void TRexPortAttr::reset_xstats(uint8_t port_id) { - rte_eth_xstats_reset(port_id); +void DpdkTRexPortAttr::reset_xstats() { + rte_eth_xstats_reset(m_port_id); } -int TRexPortAttr::get_xstats_values(uint8_t port_id, xstats_values_t &xstats_values) { - int size = rte_eth_xstats_get(port_id, NULL, 0); +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(port_id, xstats_values_tmp.data(), size); + size = rte_eth_xstats_get(m_port_id, xstats_values_tmp.data(), size); if (size < 0) { return size; } @@ -1536,14 +1548,14 @@ int TRexPortAttr::get_xstats_values(uint8_t port_id, xstats_values_t &xstats_val return 0; } -int TRexPortAttr::get_xstats_names(uint8_t port_id, xstats_names_t &xstats_names){ - int size = rte_eth_xstats_get_names(port_id, NULL, 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(port_id, xstats_names_tmp.data(), size); + size = rte_eth_xstats_get_names(m_port_id, xstats_names_tmp.data(), size); if (size < 0) { return size; } @@ -1553,28 +1565,28 @@ int TRexPortAttr::get_xstats_names(uint8_t port_id, xstats_names_t &xstats_names return 0; } -void TRexPortAttr::dump_link(uint8_t port_id, FILE *fd){ - fprintf(fd,"port : %d \n",(int)port_id); +void DpdkTRexPortAttr::dump_link(FILE *fd){ + fprintf(fd,"port : %d \n",(int)m_port_id); fprintf(fd,"------------\n"); fprintf(fd,"link : "); - if (m_link[port_id].link_status) { + if (m_link.link_status) { fprintf(fd," link : Link Up - speed %u Mbps - %s\n", - (unsigned) m_link[port_id].link_speed, - (m_link[port_id].link_duplex == ETH_LINK_FULL_DUPLEX) ? + (unsigned) m_link.link_speed, + (m_link.link_duplex == ETH_LINK_FULL_DUPLEX) ? ("full-duplex") : ("half-duplex\n")); } else { fprintf(fd," Link Down\n"); } - fprintf(fd,"promiscuous : %d \n",get_promiscuous(port_id)); + fprintf(fd,"promiscuous : %d \n",get_promiscuous()); } -void TRexPortAttr::update_device_info(uint8_t port_id){ - rte_eth_dev_info_get(port_id, &dev_info[port_id]); +void DpdkTRexPortAttr::update_device_info(){ + rte_eth_dev_info_get(m_port_id, &dev_info); } -void TRexPortAttr::get_supported_speeds(uint8_t port_id, supp_speeds_t &supp_speeds){ - uint32_t speed_capa = dev_info[port_id].speed_capa; +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) @@ -1585,63 +1597,63 @@ void TRexPortAttr::get_supported_speeds(uint8_t port_id, supp_speeds_t &supp_spe supp_speeds.push_back(ETH_SPEED_NUM_100G); } -void TRexPortAttr::update_link_status(uint8_t port_id){ - rte_eth_link_get(port_id, &m_link[port_id]); +void DpdkTRexPortAttr::update_link_status(){ + rte_eth_link_get(m_port_id, &m_link); } -bool TRexPortAttr::update_link_status_nowait(uint8_t port_id){ +bool DpdkTRexPortAttr::update_link_status_nowait(){ rte_eth_link new_link; bool changed = false; - rte_eth_link_get_nowait(port_id, &new_link); - if (new_link.link_speed != m_link[port_id].link_speed || - new_link.link_duplex != m_link[port_id].link_duplex || - new_link.link_autoneg != m_link[port_id].link_autoneg || - new_link.link_status != m_link[port_id].link_status) { + 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[port_id] = new_link; + m_link = new_link; return changed; } -int TRexPortAttr::add_mac(uint8_t port_id, char * mac){ +int DpdkTRexPortAttr::add_mac(char * mac){ struct ether_addr mac_addr; for (int i=0; i<6;i++) { mac_addr.addr_bytes[i] =mac[i]; } - return rte_eth_dev_mac_addr_add(port_id, &mac_addr,0); + return rte_eth_dev_mac_addr_add(m_port_id, &mac_addr,0); } -int TRexPortAttr::set_promiscuous(uint8_t port_id, bool enable){ +int DpdkTRexPortAttr::set_promiscuous(bool enable){ if (enable) { - rte_eth_promiscuous_enable(port_id); + rte_eth_promiscuous_enable(m_port_id); }else{ - rte_eth_promiscuous_disable(port_id); + rte_eth_promiscuous_disable(m_port_id); } return 0; } -int TRexPortAttr::set_link_up(uint8_t port_id, bool up){ +int DpdkTRexPortAttr::set_link_up(bool up){ if (up) { - return rte_eth_dev_set_link_up(port_id); + return rte_eth_dev_set_link_up(m_port_id); }else{ - return rte_eth_dev_set_link_down(port_id); + return rte_eth_dev_set_link_down(m_port_id); } } -bool TRexPortAttr::get_promiscuous(uint8_t port_id){ - int ret=rte_eth_promiscuous_get(port_id); +bool DpdkTRexPortAttr::get_promiscuous(){ + int ret=rte_eth_promiscuous_get(m_port_id); if (ret<0) { rte_exit(EXIT_FAILURE, "rte_eth_promiscuous_get: " "err=%d, port=%u\n", - ret, port_id); + ret, m_port_id); } return ( ret?true:false); } -void TRexPortAttr::macaddr_get(uint8_t port_id, struct ether_addr *mac_addr){ - rte_eth_macaddr_get(port_id , mac_addr); +void DpdkTRexPortAttr::macaddr_get(struct ether_addr *mac_addr){ + rte_eth_macaddr_get(m_port_id , mac_addr); } int CPhyEthIF::dump_fdir_global_stats(FILE *fd) { @@ -3021,7 +3033,6 @@ public: CRxCoreStateless m_rx_sl; // stateless RX core CTrexGlobalIoMode m_io_modes; CTRexExtendedDriverBase * m_drv; - TRexPortAttr * m_port_attr; private: CLatencyHWPort m_latency_vports[TREX_MAX_PORTS]; /* read hardware driver */ @@ -3155,11 +3166,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]; - m_port_attr->update_link_status(i); + _if->get_port_attr()->update_link_status(); if ( dump ){ _if->dump_stats(stdout); } - if ( m_port_attr->is_link_up(i) == false){ + if ( _if->get_port_attr()->is_link_up() == false){ all_link_are=false; break; } @@ -3389,11 +3400,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(); } - m_port_attr->add_mac(i, (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); } @@ -3634,7 +3645,6 @@ int CGlobalTRex::ixgbe_prob_init(void){ CTRexExtendedDriverDb::Ins()->set_driver_name(dev_info.driver_name); m_drv = CTRexExtendedDriverDb::Ins()->get_drv(); - m_port_attr = m_drv->m_port_attr; // check if firmware version is new enough for (i = 0; i < m_max_ports; i++) { @@ -3709,8 +3719,8 @@ void CGlobalTRex::dump_config(FILE *fd){ void CGlobalTRex::dump_links_status(FILE *fd){ for (int i=0; i<m_max_ports; i++) { - m_port_attr->update_link_status_nowait(i); - m_port_attr->dump_link(i, fd); + m_ports[i].get_port_attr()->update_link_status_nowait(); + m_ports[i].get_port_attr()->dump_link(fd); } } @@ -4161,13 +4171,14 @@ 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"] = m_port_attr->get_link_speed(port_id); - data["attr"]["promiscuous"]["enabled"] = m_port_attr->get_promiscuous(port_id); - data["attr"]["link"]["up"] = m_port_attr->is_link_up(port_id); + 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 = get_stateless_obj()->get_platform_api()->getPortAttrObj()->get_flow_ctrl(port_id, mode); + int ret = _attr->get_flow_ctrl(mode); if (ret != 0) { mode = -1; } @@ -4182,7 +4193,7 @@ CGlobalTRex::handle_slow_path() { // update speed, link up/down etc. for (int i=0; i<m_max_ports; i++) { - bool changed = m_port_attr->update_link_status_nowait(i); + bool changed = m_ports[i].get_port_attr()->update_link_status_nowait(); if (changed) { publish_async_port_attr_changed(i); } @@ -4668,6 +4679,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; } @@ -6385,11 +6397,11 @@ static void trex_termination_handler(int signum) { * **********************************************************/ int TrexDpdkPlatformApi::get_xstats_values(uint8_t port_id, xstats_values_t &xstats_values) const { - return g_trex.m_port_attr->get_xstats_values(port_id, xstats_values); + 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_port_attr->get_xstats_names(port_id, xstats_names); + return g_trex.m_ports[port_id].get_port_attr()->get_xstats_names(xstats_names); } @@ -6449,7 +6461,7 @@ TrexDpdkPlatformApi::get_interface_info(uint8_t interface_id, intf_info_st &info /* mac INFO */ /* hardware */ - g_trex.m_port_attr->macaddr_get(interface_id, &rte_mac_addr); + g_trex.m_ports[interface_id].get_port_attr()->macaddr_get(&rte_mac_addr); assert(ETHER_ADDR_LEN == 6); /* software */ @@ -6563,8 +6575,8 @@ CFlowStatParser *TrexDpdkPlatformApi::get_flow_stat_parser() const { return CTRexExtendedDriverDb::Ins()->get_drv()->get_flow_stat_parser(); } -TRexPortAttr *TrexDpdkPlatformApi::getPortAttrObj() const { - return g_trex.m_port_attr; +TRexPortAttr *TrexDpdkPlatformApi::getPortAttrObj(uint8_t port_id) const { + return g_trex.m_ports[port_id].get_port_attr(); } /** diff --git a/src/main_dpdk.h b/src/main_dpdk.h index 640c73e4..6402d106 100644 --- a/src/main_dpdk.h +++ b/src/main_dpdk.h @@ -167,6 +167,7 @@ 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: uint8_t m_port_id; @@ -179,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_dpdk/rte_ethdev_includes.h b/src/pal/linux_dpdk/rte_ethdev_includes.h index 025ce8fc..0429fe44 100644 --- a/src/pal/linux_dpdk/rte_ethdev_includes.h +++ b/src/pal/linux_dpdk/rte_ethdev_includes.h @@ -1 +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/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp index e4510a0a..109cc1a4 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp @@ -304,8 +304,8 @@ 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()->get_description(i, description); - main->get_platform_api()->getPortAttrObj()->get_supported_speeds(i, supp_speeds); + 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; @@ -331,10 +331,10 @@ 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()->is_fc_change_supported(); - section["ports"][i]["is_led_supported"] = get_stateless_obj()->get_platform_api()->getPortAttrObj()->is_led_change_supported(); - section["ports"][i]["is_link_supported"] = get_stateless_obj()->get_platform_api()->getPortAttrObj()->is_link_change_supported(); - section["ports"][i]["is_virtual"] = get_stateless_obj()->get_platform_api()->getPortAttrObj()->is_virtual(); + 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]); @@ -367,18 +367,18 @@ TrexRpcCmdSetPortAttr::_run(const Json::Value ¶ms, Json::Value &result) { for (const std::string &name : attr.getMemberNames()) { if (name == "promiscuous") { bool enabled = parse_bool(attr[name], "enabled", result); - ret = get_stateless_obj()->get_platform_api()->getPortAttrObj()->set_promiscuous(port_id, 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()->set_link_up(port_id, up); + 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()->set_led(port_id, on); + 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()->set_flow_ctrl(port_id, mode); + ret = get_stateless_obj()->get_platform_api()->getPortAttrObj(port_id)->set_flow_ctrl(mode); } else { generate_execute_err(result, "Not recognized attribute: " + name); break; @@ -568,13 +568,13 @@ 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()->get_link_speed(port_id); + result["result"]["speed"] = get_stateless_obj()->get_platform_api()->getPortAttrObj(port_id)->get_link_speed(); /* attributes */ - result["result"]["attr"]["promiscuous"]["enabled"] = get_stateless_obj()->get_platform_api()->getPortAttrObj()->get_promiscuous(port_id); - result["result"]["attr"]["link"]["up"] = get_stateless_obj()->get_platform_api()->getPortAttrObj()->is_link_up(port_id); + 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()->get_flow_ctrl(port_id, mode); + int ret = get_stateless_obj()->get_platform_api()->getPortAttrObj(port_id)->get_flow_ctrl(mode); if (ret != 0) { mode = -1; } 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 070cd6de..3a1a2c24 100644 --- a/src/stateless/cp/trex_stateless.h +++ b/src/stateless/cp/trex_stateless.h @@ -91,7 +91,7 @@ public: } const TrexRpcServerConfig *m_rpc_req_resp_cfg; - TrexPlatformApi *m_platform_api; + const TrexPlatformApi *m_platform_api; bool m_rpc_server_verbose; uint8_t m_port_count; TrexPublisher *m_publisher; diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp index 53a225f6..9bb20990 100644 --- a/src/stateless/cp/trex_stateless_port.cpp +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -153,11 +153,12 @@ private: * trex stateless port * **************************/ -TrexStatelessPort::TrexStatelessPort(uint8_t port_id, const TrexPlatformApi *api) : platform_api(api), m_dp_events(this) { +TrexStatelessPort::TrexStatelessPort(uint8_t port_id, const TrexPlatformApi *api) : m_dp_events(this) { std::vector<std::pair<uint8_t, uint8_t>> core_pair_list; 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); @@ -253,7 +254,7 @@ TrexStatelessPort::start_traffic(const TrexPortMultiplier &mul, double duration, assert(mul.m_op == TrexPortMultiplier::OP_ABS); /* check link state */ - if ( !platform_api->getPortAttrObj()->is_link_up(m_port_id) && !force ) { + if ( !m_platform_api->getPortAttrObj(m_port_id)->is_link_up() && !force ) { throw TrexException("Link state is DOWN."); } @@ -586,7 +587,7 @@ void TrexStatelessPort::get_properties(std::string &driver, uint32_t &speed) { driver = m_api_info.driver_name; - speed = platform_api->getPortAttrObj()->get_link_speed(m_port_id); + speed = m_platform_api->getPortAttrObj(m_port_id)->get_link_speed(); } bool @@ -615,7 +616,7 @@ void TrexStatelessPort::encode_stats(Json::Value &port) { TrexPlatformInterfaceStats stats; - platform_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; @@ -667,7 +668,7 @@ TrexStatelessPort::send_message_to_rx(TrexStatelessCpToRxMsgBase *msg) { uint64_t TrexStatelessPort::get_port_speed_bps() const { - return (uint64_t) platform_api->getPortAttrObj()->get_link_speed(m_port_id) * 1000 * 1000; + return (uint64_t) m_platform_api->getPortAttrObj(m_port_id)->get_link_speed() * 1000 * 1000; } static inline double diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h index 00139973..e2a2aeba 100644 --- a/src/stateless/cp/trex_stateless_port.h +++ b/src/stateless/cp/trex_stateless_port.h @@ -435,7 +435,7 @@ private: port_state_e m_port_state; TrexPlatformApi::intf_info_st m_api_info; - const TrexPlatformApi *platform_api; + const TrexPlatformApi *m_platform_api; uint16_t m_rx_count_num; uint16_t m_rx_caps; diff --git a/src/trex_port_attr.h b/src/trex_port_attr.h index cc267104..9231e263 100755 --- a/src/trex_port_attr.h +++ b/src/trex_port_attr.h @@ -25,83 +25,139 @@ limitations under the License. class TRexPortAttr { public: - TRexPortAttr(uint8_t total_ports, bool is_virtual, bool fc_change_allowed) : total_ports(total_ports) { - flag_is_virtual = is_virtual; - m_link.resize(total_ports); - intf_info_st.resize(total_ports); - dev_info.resize(total_ports); - int tmp; - flag_is_fc_change_supported = fc_change_allowed && (get_flow_ctrl(0, tmp) != -ENOTSUP); - flag_is_led_change_supported = (set_led(0, true) != -ENOTSUP); - flag_is_link_change_supported = (set_link_up(0, true) != -ENOTSUP); - update_descriptions(); - for (int i=0; i<total_ports; i++) { - update_device_info(i); - } - } + virtual ~TRexPortAttr(){} /* UPDATES */ - virtual void update_link_status(uint8_t port_id); - virtual bool update_link_status_nowait(uint8_t port_id); // returns true if the status was changed - virtual void update_device_info(uint8_t port_id); - virtual void reset_xstats(uint8_t port_id); - virtual void update_descriptions(); + 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(uint8_t port_id); - virtual void macaddr_get(uint8_t port_id, struct ether_addr *mac_addr); - virtual uint32_t get_link_speed(uint8_t port_id) { return m_link[port_id].link_speed; } // L1 Mbps - virtual bool is_link_duplex(uint8_t port_id) { return (m_link[port_id].link_duplex ? true : false); } - virtual bool is_link_autoneg(uint8_t port_id) { return (m_link[port_id].link_autoneg ? true : false); } - virtual bool is_link_up(uint8_t port_id) { return (m_link[port_id].link_status ? true : false); } - virtual int get_xstats_values(uint8_t port_id, xstats_values_t &xstats_values); - virtual int get_xstats_names(uint8_t port_id, xstats_names_t &xstats_names); - virtual int get_flow_ctrl(uint8_t port_id, int &mode); + 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(uint8_t port_id, std::string &description) { description = intf_info_st[port_id].description; } - virtual void get_supported_speeds(uint8_t port_id, supp_speeds_t &supp_speeds); + 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(uint8_t port_id, bool enabled); - virtual int add_mac(uint8_t port_id, char * mac); - virtual int set_link_up(uint8_t port_id, bool up); - virtual int set_flow_ctrl(uint8_t port_id, int mode); - virtual int set_led(uint8_t port_id, bool on); - + 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(uint8_t port_id, FILE *fd); + virtual void dump_link(FILE *fd) = 0; -private: - const uint8_t total_ports; - rte_eth_fc_conf fc_conf_tmp; - std::vector<rte_eth_link> m_link; - std::vector<struct rte_eth_dev_info> dev_info; - std::vector<struct rte_eth_xstat> xstats_values_tmp; - std::vector<struct rte_eth_xstat_name> xstats_names_tmp; +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 mac_cfg_st { - uint8_t hw_macaddr[6]; - uint8_t src_macaddr[6]; - uint8_t dst_macaddr[6]; - }; - - struct intf_info_st_type { - mac_cfg_st mac_info; + 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); - std::vector <intf_info_st_type> intf_info_st; +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) {} }; |