support for mac addr query
authorimarom <[email protected]>
Sun, 28 Feb 2016 09:30:11 +0000 (04:30 -0500)
committerimarom <[email protected]>
Sun, 28 Feb 2016 09:30:58 +0000 (04:30 -0500)
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/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 6dd7a6d..a241fe1 100644 (file)
@@ -663,12 +663,14 @@ 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']
+            speed   = self.system_info['ports'][port_id]['speed']
+            driver  = self.system_info['ports'][port_id]['driver']
+            macaddr = self.system_info['ports'][port_id]['macaddr']
 
             self.ports[port_id] = Port(port_id,
                                        speed,
                                        driver,
+                                       macaddr,
                                        self.username,
                                        self.comm_link,
                                        self.session_id)
index ef454b8..f2d4cd9 100644 (file)
@@ -41,7 +41,7 @@ class Port(object):
                   STATE_PAUSE: "PAUSE"}
 
 
-    def __init__ (self, port_id, speed, driver, user, comm_link, session_id):
+    def __init__ (self, port_id, speed, driver, macaddr, user, comm_link, session_id):
         self.port_id = port_id
         self.state = self.STATE_IDLE
         self.handler = None
@@ -51,6 +51,7 @@ class Port(object):
         self.user = user
         self.driver = driver
         self.speed = speed
+        self.macaddr = macaddr
         self.streams = {}
         self.profile = None
         self.session_id = session_id
@@ -520,9 +521,10 @@ 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['speed']   = self.speed
+        info['driver']  = self.driver
+        info['status']  = self.get_port_state_name()
+        info['macaddr'] = self.macaddr
 
         if self.attr.get('promiscuous'):
             info['prom'] = "on" if self.attr['promiscuous']['enabled'] else "off"
@@ -544,6 +546,7 @@ class Port(object):
         info = self.get_info()
 
         return {"type": info['driver'],
+                "macaddr": info['macaddr'],
                 "maximum": "{speed} Gb/s".format(speed=info['speed']),
                 "status": info['status'],
                 "promiscuous" : info['prom']
index 353d2ef..ec5435a 100644 (file)
@@ -180,7 +180,8 @@ class CTRexInfoGenerator(object):
         relevant_ports = self.__get_relevant_ports(port_id_list)
 
         return_stats_data = {}
-        per_field_status = OrderedDict([("type", []),
+        per_field_status = OrderedDict([("macaddr", []),
+                                        ("type", []),
                                         ("maximum", []),
                                         ("status", []),
                                         ("promiscuous", []),
index 249adb2..5d5f438 100644 (file)
@@ -25,6 +25,7 @@ limitations under the License.
 #include <stdint.h>
 #include <vector>
 #include <string>
+#include <string.h>
 
 /**
  * Global stats
@@ -129,6 +130,7 @@ 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() {}
 };
@@ -159,6 +161,7 @@ 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;
 };
 
 
@@ -215,6 +218,10 @@ 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 c23e27d..cdf4f6f 100644 (file)
@@ -5180,3 +5180,14 @@ 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 0556517..47569bd 100644 (file)
@@ -177,6 +177,7 @@ TrexRpcCmdGetSysInfo::_run(const Json::Value &params, Json::Value &result) {
         section["ports"][i]["index"]   = i;
 
         section["ports"][i]["driver"]  = driver;
+        section["ports"][i]["macaddr"] = port->get_macaddr();
 
         section["ports"][i]["rx"]["caps"]      = port->get_rx_caps();
         section["ports"][i]["rx"]["counters"]  = port->get_rx_count_num();
index 43f32d2..0173311 100644 (file)
@@ -679,7 +679,28 @@ 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]);
+        }
+
+        output += formatted;
+    }
+    
+    return output;
+
+}
 
 void
 TrexStatelessPort::add_stream(TrexStream *stream) {
index 1d3eebc..0d62637 100644 (file)
@@ -331,6 +331,7 @@ public:
      */
     void set_promiscuous(bool enabled);
     bool get_promiscuous();
+    std::string get_macaddr();
 
 private: