more info for ports (API and TUI)
authorimarom <[email protected]>
Sun, 28 Feb 2016 12:32:57 +0000 (14:32 +0200)
committerimarom <[email protected]>
Sun, 28 Feb 2016 12:33:26 +0000 (14:33 +0200)
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py
src/common/basic_utils.cpp
src/common/basic_utils.h
src/internal_api/trex_platform_api.h
src/main_dpdk.cpp
src/rpc-server/commands/trex_rpc_cmd_general.cpp
src/stateless/cp/trex_stateless_port.cpp
src/stateless/cp/trex_stateless_port.h

index a241fe1..3cfef08 100644 (file)
@@ -663,17 +663,13 @@ class STLClient(object):
 
         # create ports
         for port_id in xrange(self.system_info["port_count"]):
-            speed   = self.system_info['ports'][port_id]['speed']
-            driver  = self.system_info['ports'][port_id]['driver']
-            macaddr = self.system_info['ports'][port_id]['macaddr']
+            info = self.system_info['ports'][port_id]
 
             self.ports[port_id] = Port(port_id,
-                                       speed,
-                                       driver,
-                                       macaddr,
                                        self.username,
                                        self.comm_link,
-                                       self.session_id)
+                                       self.session_id,
+                                       info)
 
 
         # sync the ports
index f2d4cd9..6aa1884 100644 (file)
@@ -41,7 +41,7 @@ class Port(object):
                   STATE_PAUSE: "PAUSE"}
 
 
-    def __init__ (self, port_id, speed, driver, macaddr, user, comm_link, session_id):
+    def __init__ (self, port_id, user, comm_link, session_id, info):
         self.port_id = port_id
         self.state = self.STATE_IDLE
         self.handler = None
@@ -49,9 +49,9 @@ class Port(object):
         self.transmit = comm_link.transmit
         self.transmit_batch = comm_link.transmit_batch
         self.user = user
-        self.driver = driver
-        self.speed = speed
-        self.macaddr = macaddr
+
+        self.info = dict(info)
+
         self.streams = {}
         self.profile = None
         self.session_id = session_id
@@ -69,7 +69,7 @@ class Port(object):
         return RC_OK(data)
 
     def get_speed_bps (self):
-        return (self.speed * 1000 * 1000 * 1000)
+        return (self.info['speed'] * 1000 * 1000 * 1000)
 
     # take the port
     def acquire(self, force = False):
@@ -520,11 +520,9 @@ class Port(object):
 
     # generate port info
     def get_info (self):
-        info = {}
-        info['speed']   = self.speed
-        info['driver']  = self.driver
-        info['status']  = self.get_port_state_name()
-        info['macaddr'] = self.macaddr
+        info = dict(self.info)
+
+        info['status']       = self.get_port_state_name()
 
         if self.attr.get('promiscuous'):
             info['prom'] = "on" if self.attr['promiscuous']['enabled'] else "off"
@@ -545,8 +543,14 @@ class Port(object):
 
         info = self.get_info()
 
-        return {"type": info['driver'],
-                "macaddr": info['macaddr'],
+        return {"driver":        info['driver'],
+                "HW src mac":  info['hw_macaddr'],
+                "SW src mac":  info['src_macaddr'],
+                "SW dst mac":  info['dst_macaddr'],
+                "PCI Address": info['pci_addr'],
+                "NUMA Node":   info['numa'],
+                "--": "",
+                "---": "",
                 "maximum": "{speed} Gb/s".format(speed=info['speed']),
                 "status": info['status'],
                 "promiscuous" : info['prom']
index ec5435a..620ccac 100644 (file)
@@ -180,11 +180,17 @@ class CTRexInfoGenerator(object):
         relevant_ports = self.__get_relevant_ports(port_id_list)
 
         return_stats_data = {}
-        per_field_status = OrderedDict([("macaddr", []),
-                                        ("type", []),
+        per_field_status = OrderedDict([("driver", []),
                                         ("maximum", []),
                                         ("status", []),
                                         ("promiscuous", []),
+                                        ("--", []),
+                                         ("HW src mac", []),
+                                        ("SW src mac", []),
+                                        ("SW dst mac", []),
+                                        ("---", []),
+                                        ("PCI Address", []),
+                                        ("NUMA Node", []),
                                         ]
                                        )
 
index 1cd5ce8..34c3775 100755 (executable)
@@ -160,4 +160,18 @@ void TestDump(void){
     utl_DumpBuffer2(stdout,buffer,31,1,4,SHOW_BUFFER_ADDR_EN |SHOW_BUFFER_CHAR);
 }
 
+void utl_macaddr_to_str(const uint8_t *macaddr, std::string &output) {
+    
+    for (int i = 0; i < 6; i++) {
+        char formatted[4];
+
+        if (i == 0) {
+            snprintf(formatted, sizeof(formatted), "%02x", macaddr[i]);
+        } else {
+            snprintf(formatted, sizeof(formatted), ":%02x", macaddr[i]);
+        }
 
+        output += formatted;
+    }
+
+}
index 4bd208d..77282ee 100755 (executable)
@@ -85,6 +85,7 @@ inline void utl_swap(T& a, T& b) {
 
 bool utl_is_file_exists (const std::string& name) ;
 
+void utl_macaddr_to_str(const uint8_t *macaddr, std::string &output);
 
 #endif
 
index 5d5f438..847611e 100644 (file)
@@ -113,13 +113,30 @@ public:
         SPEED_40G,
     };
 
+    struct mac_cfg_st {
+        uint8_t hw_macaddr[6];
+        uint8_t src_macaddr[6];
+        uint8_t dst_macaddr[6];
+    };
+
+    /**
+     * interface static info
+     * 
+     */
+    struct intf_info_st {
+        std::string     driver_name;
+        driver_speed_e  speed;
+        mac_cfg_st      mac_info;
+        std::string     pci_addr;
+        int             numa_node;
+        bool            has_crc;
+    };
+
     virtual void port_id_to_cores(uint8_t port_id, std::vector<std::pair<uint8_t, uint8_t>> &cores_id_list) const = 0;
     virtual void get_global_stats(TrexPlatformGlobalStats &stats) const = 0;
     virtual void get_interface_stats(uint8_t interface_id, TrexPlatformInterfaceStats &stats) const = 0;
 
-    virtual void get_interface_info(uint8_t interface_id, std::string &driver_name,
-                                    driver_speed_e &speed,
-                                    bool &has_crc) const = 0;
+    virtual void get_interface_info(uint8_t interface_id, intf_info_st &info) const = 0;
 
     virtual void publish_async_data_now(uint32_t key) const = 0;
     virtual uint8_t get_dp_core_count() const = 0;
@@ -130,7 +147,6 @@ public:
     virtual int del_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const = 0;
     virtual void set_promiscuous(uint8_t port_id, bool enabled) const = 0;
     virtual bool get_promiscuous(uint8_t port_id) const = 0;
-    virtual void get_macaddr(uint8_t port_id, uint8_t *macaddr) const = 0;
 
     virtual ~TrexPlatformApi() {}
 };
@@ -147,10 +163,7 @@ public:
     void get_global_stats(TrexPlatformGlobalStats &stats) const;
     void get_interface_stats(uint8_t interface_id, TrexPlatformInterfaceStats &stats) const;
 
-    void get_interface_info(uint8_t interface_id,
-                            std::string &driver_name,
-                            driver_speed_e &speed,
-                            bool &has_crc) const;
+    void get_interface_info(uint8_t interface_id, intf_info_st &info) const;
 
     void publish_async_data_now(uint32_t key) const;
     uint8_t get_dp_core_count() const;
@@ -161,7 +174,6 @@ public:
     int del_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const;
     void set_promiscuous(uint8_t port_id, bool enabled) const;
     bool get_promiscuous(uint8_t port_id) const;
-    void get_macaddr(uint8_t port_id, uint8_t *macaddr) const;
 };
 
 
@@ -184,13 +196,14 @@ public:
     virtual void get_global_stats(TrexPlatformGlobalStats &stats) const {
     }
 
-    virtual void get_interface_info(uint8_t interface_id,
-                                    std::string &driver_name,
-                                    driver_speed_e &speed,
-                                    bool &has_crc) const {
-        driver_name = "TEST";
-        speed = TrexPlatformApi::SPEED_10G;
-        has_crc = true;
+    virtual void get_interface_info(uint8_t interface_id, intf_info_st &info) const {
+
+        info.driver_name = "TEST";
+        info.speed = TrexPlatformApi::SPEED_10G;
+        info.has_crc = true;
+        info.numa_node = 0;
+
+        memset(&info.mac_info, 0, sizeof(info.mac_info));
     }
 
     virtual void get_interface_stats(uint8_t interface_id, TrexPlatformInterfaceStats &stats) const {
@@ -218,10 +231,6 @@ public:
         return false;
     }
 
-    void get_macaddr(uint8_t port_id, uint8_t *macaddr) const {
-        memset(macaddr, 0, 6);
-    }
-
 private:
     int m_dp_core_count;
 };
index 79f3d62..1b5b82f 100644 (file)
@@ -1517,6 +1517,7 @@ void CPhyEthIF::macaddr_get(struct ether_addr *mac_addr){
        rte_eth_macaddr_get(m_port_id , mac_addr);
 }
 
+
 void CPhyEthIF::get_stats_1g(CPhyEthIFStats *stats){ 
 
    stats->ipackets     +=  pci_reg_read(E1000_GPRC) ;
@@ -5121,14 +5122,39 @@ TrexDpdkPlatformApi::port_id_to_cores(uint8_t port_id, std::vector<std::pair<uin
 }
 
 void
-TrexDpdkPlatformApi::get_interface_info(uint8_t port_id,
-                                        std::string &driver_name,
-                                        driver_speed_e &speed,
-                                        bool &has_crc) const {
+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();
+    info.speed       = CTRexExtendedDriverDb::Ins()->get_drv()->get_driver_speed(interface_id);
+    info.has_crc     = CTRexExtendedDriverDb::Ins()->get_drv()->has_crc_added();
+
+    /* mac INFO */
+
+    /* hardware */
+    g_trex.m_ports[interface_id].macaddr_get(&rte_mac_addr);
+    assert(ETHER_ADDR_LEN == 6);
+    for (int i = 0; i < 6; i++) {
+        info.mac_info.hw_macaddr[i] = rte_mac_addr.addr_bytes[i];
+    }
+
+    /* software */
+    uint8_t sw_macaddr[12];
+    memcpy(sw_macaddr, CGlobalInfo::m_options.get_dst_src_mac_addr(interface_id), 12);
+
+    for (int i = 0; i < 6; i++) {
+        info.mac_info.dst_macaddr[i] = sw_macaddr[i];
+        info.mac_info.src_macaddr[i] = sw_macaddr[6 + i];
+        
+    }
+
+    info.numa_node =  g_trex.m_ports[interface_id].m_dev_info.pci_dev->numa_node;
+    struct rte_pci_addr *loc = &g_trex.m_ports[interface_id].m_dev_info.pci_dev->addr;
+
+    char pci_addr[50];
+    snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT, loc->domain, loc->bus, loc->devid, loc->function);
+    info.pci_addr = pci_addr;
 
-    driver_name = CTRexExtendedDriverDb::Ins()->get_driver_name();
-    speed       = CTRexExtendedDriverDb::Ins()->get_drv()->get_driver_speed(port_id);
-    has_crc     = CTRexExtendedDriverDb::Ins()->get_drv()->has_crc_added();
 }
 
 void
@@ -5165,14 +5191,4 @@ bool TrexDpdkPlatformApi::get_promiscuous(uint8_t port_id) const {
     return g_trex.m_ports[port_id].get_promiscuous();
 }
 
-void TrexDpdkPlatformApi::get_macaddr(uint8_t port_id, uint8_t *macaddr) const {
-    struct ether_addr rte_mac_addr;
-
-    g_trex.m_ports[port_id].macaddr_get(&rte_mac_addr);
 
-    assert(ETHER_ADDR_LEN == 6);
-    for (int i = 0; i < 6; i++) {
-        macaddr[i] = rte_mac_addr.addr_bytes[i];
-    }
-
-}
index 47569bd..88ead3c 100644 (file)
@@ -168,16 +168,29 @@ TrexRpcCmdGetSysInfo::_run(const Json::Value &params, Json::Value &result) {
     section["ports"] = Json::arrayValue;
 
     for (int i = 0; i < main->get_port_count(); i++) {
-        string driver;
         TrexPlatformApi::driver_speed_e speed;
-
+        string driver;
+        string hw_macaddr;
+        string src_macaddr;
+        string dst_macaddr;
+        string pci_addr;
+        int numa;
+        
         TrexStatelessPort *port = main->get_port_by_id(i);
         port->get_properties(driver, speed);
+        port->get_macaddr(hw_macaddr, src_macaddr, dst_macaddr);
+
+        port->get_pci_info(pci_addr, numa);
 
         section["ports"][i]["index"]   = i;
 
-        section["ports"][i]["driver"]  = driver;
-        section["ports"][i]["macaddr"] = port->get_macaddr();
+        section["ports"][i]["driver"]       = driver;
+        section["ports"][i]["hw_macaddr"]   = hw_macaddr;
+        section["ports"][i]["src_macaddr"]  = src_macaddr;
+        section["ports"][i]["dst_macaddr"]  = dst_macaddr;
+
+        section["ports"][i]["pci_addr"]     = pci_addr;
+        section["ports"][i]["numa"]         = numa;
 
         section["ports"][i]["rx"]["caps"]      = port->get_rx_caps();
         section["ports"][i]["rx"]["counters"]  = port->get_rx_count_num();
index 0173311..c60b0e8 100644 (file)
@@ -23,6 +23,7 @@ limitations under the License.
 #include <trex_stateless_port.h>
 #include <trex_stateless_messaging.h>
 #include <trex_streams_compiler.h>
+#include <common/basic_utils.h>
 
 #include <string>
 
@@ -58,7 +59,7 @@ TrexStatelessPort::TrexStatelessPort(uint8_t port_id, const TrexPlatformApi *api
     m_port_state = PORT_STATE_IDLE;
 
     /* get the platform specific data */
-    api->get_interface_info(port_id, m_driver_name, m_speed, m_has_crc);
+    api->get_interface_info(port_id, m_api_info);
 
     /* get RX caps */
     api->get_interface_stat_info(port_id, m_rx_count_num, m_rx_caps);
@@ -372,8 +373,8 @@ TrexStatelessPort::get_max_stream_id() const {
 void
 TrexStatelessPort::get_properties(std::string &driver, TrexPlatformApi::driver_speed_e &speed) {
 
-    driver = m_driver_name;
-    speed  = m_speed;
+    driver = m_api_info.driver_name;
+    speed  = m_api_info.speed;
 }
 
 bool
@@ -460,7 +461,7 @@ TrexStatelessPort::on_dp_event_occured(TrexDpPortEvent::event_e event_type) {
 
 uint64_t
 TrexStatelessPort::get_port_speed_bps() const {
-    switch (m_speed) {
+    switch (m_api_info.speed) {
     case TrexPlatformApi::SPEED_1G:
         return (1LLU * 1000 * 1000 * 1000);
 
@@ -679,27 +680,20 @@ TrexStatelessPort::get_promiscuous() {
 }
 
 
-std::string
-TrexStatelessPort::get_macaddr() {
-    uint8_t macaddr[6];
-    std::string output;
-
-    get_stateless_obj()->get_platform_api()->get_macaddr(m_port_id, macaddr);
-
-    for (int i = 0; i < 6; i++) {
-        char formatted[4];
-
-        if (i == 0) {
-            snprintf(formatted, sizeof(formatted), "%02x", macaddr[i]);
-        } else {
-            snprintf(formatted, sizeof(formatted), ":%02x", macaddr[i]);
-        }
+void
+TrexStatelessPort::get_macaddr(std::string &hw_macaddr,
+                               std::string &src_macaddr,
+                               std::string &dst_macaddr) {
 
-        output += formatted;
-    }
-    
-    return output;
+    utl_macaddr_to_str(m_api_info.mac_info.hw_macaddr, hw_macaddr);
+    utl_macaddr_to_str(m_api_info.mac_info.src_macaddr, src_macaddr);
+    utl_macaddr_to_str(m_api_info.mac_info.dst_macaddr, dst_macaddr);
+}
 
+void
+TrexStatelessPort::get_pci_info(std::string &pci_addr, int &numa_node) {
+    pci_addr  = m_api_info.pci_addr;
+    numa_node = m_api_info.numa_node;
 }
 
 void
index 0d62637..192d0d1 100644 (file)
@@ -304,7 +304,7 @@ public:
      * @return bool 
      */
     bool has_crc_added() const {
-        return m_has_crc;
+        return m_api_info.has_crc;
     }
 
     TrexPortOwner & get_owner() {
@@ -331,7 +331,12 @@ public:
      */
     void set_promiscuous(bool enabled);
     bool get_promiscuous();
-    std::string get_macaddr();
+
+    void get_macaddr(std::string &hw_macaddr,
+                     std::string &src_macaddr,
+                     std::string &dst_macaddr);
+
+    void get_pci_info(std::string &pci_addr, int &numa_node);
 
 private:
 
@@ -396,13 +401,12 @@ private:
     TrexStreamTable    m_stream_table;
     uint8_t            m_port_id;
     port_state_e       m_port_state;
-    std::string        m_driver_name;
-    bool               m_has_crc;
+
+    TrexPlatformApi::intf_info_st m_api_info;
+
     uint16_t           m_rx_count_num;
     uint16_t           m_rx_caps;
 
-    TrexPlatformApi::driver_speed_e m_speed;
-
     /* holds the DP cores associated with this port */
     std::vector<int>   m_cores_id_list;