From 1e6b2bf6001275bdd2ab0691f335bbb7966bf619 Mon Sep 17 00:00:00 2001 From: Yaroslav Brustinov Date: Tue, 27 Sep 2016 09:08:57 +0300 Subject: /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 --- src/platform_cfg.cpp | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'src/platform_cfg.cpp') 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 #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> 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> 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> 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> 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'."); } } -- cgit 1.2.3-korg