summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2016-09-27 09:08:57 +0300
committerYaroslav Brustinov <ybrustin@cisco.com>2016-09-27 09:08:57 +0300
commit1e6b2bf6001275bdd2ab0691f335bbb7966bf619 (patch)
treecd601fa51b2645f9a21ed1cbad5c76da13e01cc3
parent9ff1f808edcc9289d297b3a6cf34b1e5590ecf85 (diff)
/etc/trex_cfg.yaml allow MAC as string "12:34:56:78:9a:bc" etc.
dpdk_setup_ports: fix create config in case of VM & passthrough
-rwxr-xr-xscripts/dpdk_setup_ports.py4
-rwxr-xr-xsrc/common/c_common.h2
-rwxr-xr-xsrc/platform_cfg.cpp43
-rwxr-xr-xsrc/utl_yaml.cpp22
-rwxr-xr-xsrc/utl_yaml.h3
5 files changed, 60 insertions, 14 deletions
diff --git a/scripts/dpdk_setup_ports.py b/scripts/dpdk_setup_ports.py
index 4abb2e53..5e3e9a3f 100755
--- a/scripts/dpdk_setup_ports.py
+++ b/scripts/dpdk_setup_ports.py
@@ -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
diff --git a/src/common/c_common.h b/src/common/c_common.h
index 3e43644f..8a970e6e 100755
--- a/src/common/c_common.h
+++ b/src/common/c_common.h
@@ -50,3 +50,5 @@ typedef void* c_pvoid;
#endif
#endif
+
+#define ASSERT_MSG(cond, msg) if (!(cond)) {std::cerr << msg << std::endl; exit(-1);}
diff --git a/src/platform_cfg.cpp b/src/platform_cfg.cpp
index e11b0fb5..64bbb71b 100755
--- a/src/platform_cfg.cpp
+++ b/src/platform_cfg.cpp
@@ -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'.");
}
}
diff --git a/src/utl_yaml.cpp b/src/utl_yaml.cpp
index 8352e887..864c86f8 100755
--- a/src/utl_yaml.cpp
+++ b/src/utl_yaml.cpp
@@ -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
*
diff --git a/src/utl_yaml.h b/src/utl_yaml.h
index 59104b21..ed7d66d6 100755
--- a/src/utl_yaml.h
+++ b/src/utl_yaml.h
@@ -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: