/etc/trex_cfg.yaml allow MAC as string "12:34:56:78:9a:bc" etc.
authorYaroslav Brustinov <[email protected]>
Tue, 27 Sep 2016 06:08:57 +0000 (09:08 +0300)
committerYaroslav Brustinov <[email protected]>
Tue, 27 Sep 2016 06:08:57 +0000 (09:08 +0300)
dpdk_setup_ports: fix create config in case of VM & passthrough

scripts/dpdk_setup_ports.py
src/common/c_common.h
src/platform_cfg.cpp
src/utl_yaml.cpp
src/utl_yaml.h

index 4abb2e5..5e3e9a3 100755 (executable)
@@ -135,10 +135,12 @@ class ConfigCreator(object):
                 lcores_pool = sorted([lcore for lcores in self.lcores_per_numa.values() for lcore in lcores])
                 config_str += ' '*6 + 'master_thread_id: %s\n' % (0 if self.has_zero_lcore else lcores_pool.pop())
                 config_str += ' '*6 + 'latency_thread_id: %s\n' % lcores_pool.pop(0)
+                lcores_per_dual_if = int(len(lcores_pool) / len(self.interfaces))
                 config_str += ' '*6 + 'dual_if:\n'
                 for i in range(0, len(self.interfaces), 2):
+                    lcores_for_this_dual_if = [str(lcores_pool.pop(0)) for _ in range(lcores_per_dual_if)]
                     config_str += ' '*8 + '- socket: 0\n'
-                    config_str += ' '*10 + 'threads: [%s]\n\n' % lcores_pool.pop(0)
+                    config_str += ' '*10 + 'threads: [%s]\n\n' % ','.join(lcores_for_this_dual_if)
             else:
                 # we will take common minimum among all NUMAs, to satisfy all
                 lcores_per_dual_if = 99
index 3e43644..8a970e6 100755 (executable)
@@ -50,3 +50,5 @@ typedef void*           c_pvoid;
 #endif
 
 #endif
+
+#define ASSERT_MSG(cond, msg) if (!(cond)) {std::cerr << msg << std::endl; exit(-1);}
index e11b0fb..64bbb71 100755 (executable)
@@ -24,6 +24,7 @@ limitations under the License.
 #include <stdlib.h>
 #include "common/basic_utils.h"
 #include "platform_cfg.h"
+#include "utl_yaml.h"
 
 void CPlatformMemoryYamlInfo::reset(){
        int i;
@@ -171,31 +172,47 @@ void CMacYamlInfo::Dump(FILE *fd){
         return;
     }
     if (m_src_base.size() != 6) {
-        fprintf(fd,"ERROR in dest mac addr \n");
+        fprintf(fd,"ERROR in src mac addr \n");
         return;
     }
     fprintf (fd," src     : ");
-    dump_mac_vector( m_dest_base,fd);
-    fprintf (fd," dest    : ");
     dump_mac_vector( m_src_base,fd);
+    fprintf (fd," dest    : ");
+    dump_mac_vector( m_dest_base,fd);
 
 }
 
 void operator >> (const YAML::Node& node, CMacYamlInfo & mac_info) {
+    uint32_t fi;
+    bool res;
+    std::string mac_str;
+
     const YAML::Node& dmac = node["dest_mac"];
-    for(unsigned i=0;i<dmac.size();i++) {
-        uint32_t fi;
-        const YAML::Node & node =dmac;
-        node[i]  >> fi;
-        mac_info.m_dest_base.push_back(fi);
+    if (dmac.Type() == YAML::NodeType::Sequence) { // [1,2,3,4,5,6]
+        ASSERT_MSG(dmac.size() == 6, "Array of dest MAC should have 6 elements.");
+        for(unsigned i=0;i<dmac.size();i++) {
+            dmac[i]  >> fi;
+            mac_info.m_dest_base.push_back(fi);
+        }
+    }
+    else if (dmac.Type() == YAML::NodeType::Scalar) { // "12:34:56:78:9a:bc"
+        dmac >> mac_str;
+        res = mac2vect(mac_str, mac_info.m_dest_base);
+        ASSERT_MSG(res && mac_info.m_dest_base.size() == 6, "String of dest MAC should be in format '12:34:56:78:9a:bc'.");
     }
 
     const YAML::Node& smac = node["src_mac"];
-    for(unsigned i=0;i<dmac.size();i++) {
-        uint32_t fi;
-        const YAML::Node & node =smac;
-        node[i]  >> fi;
-        mac_info.m_src_base.push_back(fi);
+    if (smac.Type() == YAML::NodeType::Sequence) {
+        ASSERT_MSG(smac.size() == 6, "Array of src MAC should have 6 elements.");
+        for(unsigned i=0;i<smac.size();i++) {
+            smac[i]  >> fi;
+            mac_info.m_src_base.push_back(fi);
+        }
+    }
+    else if (smac.Type() == YAML::NodeType::Scalar) {
+        smac >> mac_str;
+        res = mac2vect(mac_str, mac_info.m_src_base);
+        ASSERT_MSG(res && mac_info.m_src_base.size() == 6, "String of src MAC should be in format '12:34:56:78:9a:bc'.");
     }
 }
 
index 8352e88..864c86f 100755 (executable)
@@ -155,6 +155,28 @@ static bool mac2uint64(const std::string &mac_str, uint64_t &mac_num) {
     return true;
 }
 
+bool mac2vect(const std::string &mac_str, std::vector<uint8_t> &mac) {
+    std::vector<std::string> tokens;
+
+    split_str_by_delimiter(mac_str, ':', tokens);
+    if (tokens.size() != 6) {
+        return false;
+    }
+
+    for (int i = 0; i < 6 ; i++) {
+        char *endptr = NULL;
+        unsigned long octet = strtoul(tokens[i].c_str(), &endptr, 16);
+
+        if ( (*endptr != 0) || (octet > 0xff) ) {
+            return false;
+        }
+
+        mac.push_back(octet);
+    }
+
+    return true;
+}
+
 /************************
  * YAML Parser Wrapper
  *
index 59104b2..ed7d66d 100755 (executable)
@@ -23,6 +23,7 @@ limitations under the License.
 
 
 #include <stdint.h>
+#include <vector>
 #include <yaml-cpp/yaml.h>
 
 
@@ -39,6 +40,8 @@ bool utl_yaml_read_uint16(const YAML::Node& node,
                           const std::string &name,
                           uint16_t & val);
 
+bool mac2vect(const std::string &mac_str, std::vector<uint8_t> &mac);
+
 /* a thin wrapper to customize errors */
 class YAMLParserWrapper {
 public: