18b52a31eSHanoh Haim/*
28b52a31eSHanoh Haim Hanoh Haim
38b52a31eSHanoh Haim Cisco Systems, Inc.
48b52a31eSHanoh Haim*/
58b52a31eSHanoh Haim
68b52a31eSHanoh Haim/*
722bed39aSIdo BarneaCopyright (c) 2015-2016 Cisco Systems, Inc.
88b52a31eSHanoh Haim
98b52a31eSHanoh HaimLicensed under the Apache License, Version 2.0 (the "License");
108b52a31eSHanoh Haimyou may not use this file except in compliance with the License.
118b52a31eSHanoh HaimYou may obtain a copy of the License at
128b52a31eSHanoh Haim
138b52a31eSHanoh Haim    http://www.apache.org/licenses/LICENSE-2.0
148b52a31eSHanoh Haim
158b52a31eSHanoh HaimUnless required by applicable law or agreed to in writing, software
168b52a31eSHanoh Haimdistributed under the License is distributed on an "AS IS" BASIS,
178b52a31eSHanoh HaimWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
188b52a31eSHanoh HaimSee the License for the specific language governing permissions and
198b52a31eSHanoh Haimlimitations under the License.
208b52a31eSHanoh Haim*/
218b52a31eSHanoh Haim
228b52a31eSHanoh Haim#include <fstream>
2322bed39aSIdo Barnea#include <iostream>
2422bed39aSIdo Barnea#include <stdlib.h>
2522bed39aSIdo Barnea#include "common/basic_utils.h"
26af781231SIdo Barnea#include "utl_yaml.h"
2722bed39aSIdo Barnea#include "platform_cfg.h"
281e6b2bf6SYaroslav Brustinov#include "utl_yaml.h"
298b52a31eSHanoh Haim
308b52a31eSHanoh Haimvoid CPlatformMemoryYamlInfo::reset(){
318b52a31eSHanoh Haim       int i;
3222bed39aSIdo Barnea       i=0;
33392f47fbSHanoh Haim       for (i=0; i<MBUF_ELM_SIZE; i++) {
348b52a31eSHanoh Haim           m_mbuf[i] = CONST_NB_MBUF_2_10G;
358b52a31eSHanoh Haim       }
368b52a31eSHanoh Haim       m_mbuf[MBUF_64]           = m_mbuf[MBUF_64]*2;
37392f47fbSHanoh Haim
388b52a31eSHanoh Haim       m_mbuf[MBUF_2048]         = CONST_NB_MBUF_2_10G/2;
398b52a31eSHanoh Haim
40a1364603SHanoh Haim       m_mbuf[MBUF_4096]         = 128;
41a1364603SHanoh Haim       m_mbuf[MBUF_9k]           = 512;
42a1364603SHanoh Haim
43a1364603SHanoh Haim
44a48cd647Simarom       m_mbuf[TRAFFIC_MBUF_64]           = m_mbuf[MBUF_64] * 4;
45392f47fbSHanoh Haim       m_mbuf[TRAFFIC_MBUF_128]           = m_mbuf[MBUF_128] * 4;
46392f47fbSHanoh Haim
47a48cd647Simarom       m_mbuf[TRAFFIC_MBUF_2048]         = CONST_NB_MBUF_2_10G * 8;
488b52a31eSHanoh Haim
49a1364603SHanoh Haim       m_mbuf[TRAFFIC_MBUF_4096]         = 128;
50a1364603SHanoh Haim       m_mbuf[TRAFFIC_MBUF_9k]           = 512;
51a1364603SHanoh Haim
52a1364603SHanoh Haim
538b52a31eSHanoh Haim       m_mbuf[MBUF_DP_FLOWS]     = (1024*1024/2);
548b52a31eSHanoh Haim       m_mbuf[MBUF_GLOBAL_FLOWS] =(10*1024/2);
558b52a31eSHanoh Haim}
5622bed39aSIdo Barnea
578b52a31eSHanoh Haimconst std::string names []={
588b52a31eSHanoh Haim                   "MBUF_64",
598b52a31eSHanoh Haim                   "MBUF_128",
608b52a31eSHanoh Haim                   "MBUF_256",
6122bed39aSIdo Barnea                   "MBUF_512",
6222bed39aSIdo Barnea                   "MBUF_1024",
6322bed39aSIdo Barnea                   "MBUF_2048",
6422bed39aSIdo Barnea                   "MBUF_4096",
6522bed39aSIdo Barnea                   "MBUF_9K",
668b52a31eSHanoh Haim
678b52a31eSHanoh Haim                   "TRAFFIC_MBUF_64",
688b52a31eSHanoh Haim                   "TRAFFIC_MBUF_128",
698b52a31eSHanoh Haim                   "TRAFFIC_MBUF_256",
7022bed39aSIdo Barnea                   "TRAFFIC_MBUF_512",
7122bed39aSIdo Barnea                   "TRAFFIC_MBUF_1024",
7222bed39aSIdo Barnea                   "TRAFFIC_MBUF_2048",
7322bed39aSIdo Barnea                   "TRAFFIC_MBUF_4096",
7422bed39aSIdo Barnea                   "TRAFFIC_MBUF_9K",
75a1364603SHanoh Haim
7622bed39aSIdo Barnea                   "MBUF_DP_FLOWS",
778b52a31eSHanoh Haim                   "MBUF_GLOBAL_FLOWS"
788b52a31eSHanoh Haim
7922bed39aSIdo Barnea};
808b52a31eSHanoh Haim
818b52a31eSHanoh Haimconst std::string * get_mbuf_names(void){
828b52a31eSHanoh Haim  return names;
838b52a31eSHanoh Haim}
848b52a31eSHanoh Haim
858b52a31eSHanoh Haimvoid CPlatformDualIfYamlInfo::Dump(FILE *fd){
868b52a31eSHanoh Haim    fprintf(fd,"    socket  : %d  \n",m_socket);
878b52a31eSHanoh Haim    int i;
888b52a31eSHanoh Haim    fprintf(fd,"   [  ");
898b52a31eSHanoh Haim    for (i=0; i<m_threads.size(); i++) {
908b52a31eSHanoh Haim        fprintf(fd," %d  ",(int)m_threads[i]);
918b52a31eSHanoh Haim    }
928b52a31eSHanoh Haim    fprintf(fd,"   ]  \n");
938b52a31eSHanoh Haim}
948b52a31eSHanoh Haim
958b52a31eSHanoh Haimvoid CPlatformCoresYamlInfo::Dump(FILE *fd){
968b52a31eSHanoh Haim    if ( m_is_exists == false){
978b52a31eSHanoh Haim       fprintf(fd," no platform info \n");
988b52a31eSHanoh Haim       return;
998b52a31eSHanoh Haim    }
100e33e37efSIdo Barnea    fprintf(fd," master   thread  : %d  \n", m_master_thread);
101e33e37efSIdo Barnea    fprintf(fd," rx  thread  : %d  \n", m_rx_thread);
1028b52a31eSHanoh Haim    int i;
1038b52a31eSHanoh Haim    for (i=0; i<m_dual_if.size(); i++) {
1048b52a31eSHanoh Haim        printf(" dual_if : %d \n",i);
1058b52a31eSHanoh Haim        CPlatformDualIfYamlInfo * lp=&m_dual_if[i];
1068b52a31eSHanoh Haim        lp->Dump(fd);
1078b52a31eSHanoh Haim    }
1088b52a31eSHanoh Haim}
1098b52a31eSHanoh Haim
1108b52a31eSHanoh Haimvoid operator >> (const YAML::Node& node, CPlatformDualIfYamlInfo & plat_info) {
1118b52a31eSHanoh Haim    node["socket"] >> plat_info.m_socket;
1128b52a31eSHanoh Haim    const YAML::Node& threads = node["threads"];
1138b52a31eSHanoh Haim    /* fill the vector*/
1148b52a31eSHanoh Haim    for(unsigned i=0;i<threads.size();i++) {
1158b52a31eSHanoh Haim        uint32_t fi;
1168b52a31eSHanoh Haim        const YAML::Node & node = threads;
1178b52a31eSHanoh Haim        node[i]  >> fi;
1188b52a31eSHanoh Haim        plat_info.m_threads.push_back(fi);
1198b52a31eSHanoh Haim    }
1208b52a31eSHanoh Haim}
1218b52a31eSHanoh Haim
1228b52a31eSHanoh Haimvoid operator >> (const YAML::Node& node, CPlatformCoresYamlInfo & plat_info) {
1238b52a31eSHanoh Haim     node["master_thread_id"] >> plat_info.m_master_thread;
12422bed39aSIdo Barnea     if (node.FindValue("rx_thread_id")) {
12522bed39aSIdo Barnea         node["rx_thread_id"] >> plat_info.m_rx_thread;
12622bed39aSIdo Barnea     } else {
12722bed39aSIdo Barnea         // Obolete option.
12822bed39aSIdo Barnea         if (node.FindValue("latency_thread_id")) {
12922bed39aSIdo Barnea             node["latency_thread_id"] >> plat_info.m_rx_thread;
13022bed39aSIdo Barnea         } else {
13122bed39aSIdo Barnea             node["rx_thread_id"] >> plat_info.m_rx_thread; // do this to get the error message
13222bed39aSIdo Barnea         }
13322bed39aSIdo Barnea     }
1348b52a31eSHanoh Haim
1358b52a31eSHanoh Haim     const YAML::Node& dual_info = node["dual_if"];
1368b52a31eSHanoh Haim     for(unsigned i=0;i<dual_info.size();i++) {
1378b52a31eSHanoh Haim        CPlatformDualIfYamlInfo  fi;
1388b52a31eSHanoh Haim         dual_info[i]  >> fi;
1398b52a31eSHanoh Haim         plat_info.m_dual_if.push_back(fi);
1408b52a31eSHanoh Haim     }
1418b52a31eSHanoh Haim}
1428b52a31eSHanoh Haim
1438b52a31eSHanoh Haimvoid CPlatformMemoryYamlInfo::Dump(FILE *fd){
1448b52a31eSHanoh Haim    fprintf(fd," memory per 2x10G ports  \n");
1458b52a31eSHanoh Haim    const std::string * names =get_mbuf_names();
1468b52a31eSHanoh Haim
14722bed39aSIdo Barnea    int i=0;
148392f47fbSHanoh Haim    for (i=0; i<MBUF_ELM_SIZE; i++) {
14938dc2db8Simarom        fprintf(fd," %-40s  : %lu \n",names[i].c_str(), (ulong)m_mbuf[i]);
1508b52a31eSHanoh Haim    }
1518b52a31eSHanoh Haim}
1528b52a31eSHanoh Haim
1538b52a31eSHanoh Haimvoid CMacYamlInfo::copy_dest(char *p){
1548b52a31eSHanoh Haim    assert(m_dest_base.size() == 6);
1558b52a31eSHanoh Haim    int i;
1568b52a31eSHanoh Haim    for (i=0; i<m_dest_base.size(); i++) {
1578b52a31eSHanoh Haim        p[i]=m_dest_base[i];
1588b52a31eSHanoh Haim    }
1598b52a31eSHanoh Haim}
1608b52a31eSHanoh Haim
1618b52a31eSHanoh Haimvoid CMacYamlInfo::copy_src(char *p){
1628b52a31eSHanoh Haim        assert(m_src_base.size() == 6);
1638b52a31eSHanoh Haim        int i;
1648b52a31eSHanoh Haim        for (i=0; i<m_src_base.size(); i++) {
1658b52a31eSHanoh Haim            p[i]=m_src_base[i];
1668b52a31eSHanoh Haim        }
1678b52a31eSHanoh Haim}
1688b52a31eSHanoh Haim
169af781231SIdo Barneauint32_t CMacYamlInfo::get_def_gw() {
170af781231SIdo Barnea    return m_def_gw;
171af781231SIdo Barnea}
172af781231SIdo Barnea
173af781231SIdo Barneauint32_t CMacYamlInfo::get_ip() {
174af781231SIdo Barnea    return m_ip;
175af781231SIdo Barnea}
1768b52a31eSHanoh Haim
177a42bf7bcSIdo Barneauint32_t CMacYamlInfo::get_mask() {
178a42bf7bcSIdo Barnea    return m_mask;
179a42bf7bcSIdo Barnea}
180a42bf7bcSIdo Barnea
181a42bf7bcSIdo Barneauint32_t CMacYamlInfo::get_vlan() {
182a42bf7bcSIdo Barnea    return m_vlan;
183a42bf7bcSIdo Barnea}
184a42bf7bcSIdo Barnea
1858b52a31eSHanoh Haimvoid CMacYamlInfo::Dump(FILE *fd){
1868b52a31eSHanoh Haim    if (m_dest_base.size() != 6) {
1878b52a31eSHanoh Haim        fprintf(fd,"ERROR in dest mac addr \n");
1888b52a31eSHanoh Haim        return;
1898b52a31eSHanoh Haim    }
1908b52a31eSHanoh Haim    if (m_src_base.size() != 6) {
1911e6b2bf6SYaroslav Brustinov        fprintf(fd,"ERROR in src mac addr \n");
1928b52a31eSHanoh Haim        return;
1938b52a31eSHanoh Haim    }
19422bed39aSIdo Barnea    fprintf (fd," src     : ");
1958b52a31eSHanoh Haim    dump_mac_vector( m_src_base,fd);
1961e6b2bf6SYaroslav Brustinov    fprintf (fd," dest    : ");
1971e6b2bf6SYaroslav Brustinov    dump_mac_vector( m_dest_base,fd);
1988b52a31eSHanoh Haim
1998b52a31eSHanoh Haim}
2008b52a31eSHanoh Haim
2018b52a31eSHanoh Haimvoid operator >> (const YAML::Node& node, CMacYamlInfo & mac_info) {
2021e6b2bf6SYaroslav Brustinov    uint32_t fi;
2031e6b2bf6SYaroslav Brustinov    bool res;
2041e6b2bf6SYaroslav Brustinov    std::string mac_str;
2051e6b2bf6SYaroslav Brustinov
206af781231SIdo Barnea    if (node.FindValue("dest_mac")) {
207af781231SIdo Barnea        const YAML::Node& dmac = node["dest_mac"];
208af781231SIdo Barnea        if (dmac.Type() == YAML::NodeType::Sequence) { // [1,2,3,4,5,6]
209af781231SIdo Barnea            ASSERT_MSG(dmac.size() == 6, "Array of dest MAC should have 6 elements.");
210af781231SIdo Barnea            for(unsigned i=0;i<dmac.size();i++) {
211af781231SIdo Barnea                dmac[i]  >> fi;
212af781231SIdo Barnea                mac_info.m_dest_base.push_back(fi);
213af781231SIdo Barnea            }
214af781231SIdo Barnea        }
215af781231SIdo Barnea        else if (dmac.Type() == YAML::NodeType::Scalar) { // "12:34:56:78:9a:bc"
216af781231SIdo Barnea            dmac >> mac_str;
217af781231SIdo Barnea            res = mac2vect(mac_str, mac_info.m_dest_base);
218af781231SIdo Barnea            ASSERT_MSG(res && mac_info.m_dest_base.size() == 6
219af781231SIdo Barnea                       , "String of dest MAC should be in format '12:34:56:78:9a:bc'.");
220af781231SIdo Barnea        }
221af781231SIdo Barnea    } else {
222af781231SIdo Barnea        for(unsigned i = 0; i < 6; i++) {
223af781231SIdo Barnea            mac_info.m_dest_base.push_back(0);
2241e6b2bf6SYaroslav Brustinov        }
2258b52a31eSHanoh Haim    }
2268b52a31eSHanoh Haim
227af781231SIdo Barnea    if (node.FindValue("src_mac")) {
228af781231SIdo Barnea        const YAML::Node& smac = node["src_mac"];
229af781231SIdo Barnea        if (smac.Type() == YAML::NodeType::Sequence) {
230af781231SIdo Barnea            ASSERT_MSG(smac.size() == 6, "Array of src MAC should have 6 elements.");
231af781231SIdo Barnea            for(unsigned i=0;i<smac.size();i++) {
232af781231SIdo Barnea                smac[i]  >> fi;
233af781231SIdo Barnea                mac_info.m_src_base.push_back(fi);
234af781231SIdo Barnea            }
235af781231SIdo Barnea        }
236af781231SIdo Barnea        else if (smac.Type() == YAML::NodeType::Scalar) {
237af781231SIdo Barnea            smac >> mac_str;
238af781231SIdo Barnea            res = mac2vect(mac_str, mac_info.m_src_base);
239af781231SIdo Barnea            ASSERT_MSG(res && mac_info.m_src_base.size() == 6
240af781231SIdo Barnea                       , "String of src MAC should be in format '12:34:56:78:9a:bc'.");
241af781231SIdo Barnea        }
242af781231SIdo Barnea    } else {
243af781231SIdo Barnea        for(unsigned i = 0; i < 6; i++) {
244af781231SIdo Barnea            mac_info.m_src_base.push_back(0);
2451e6b2bf6SYaroslav Brustinov        }
2461e6b2bf6SYaroslav Brustinov    }
247af781231SIdo Barnea
248af781231SIdo Barnea    if (! utl_yaml_read_ip_addr(node, "default_gw", mac_info.m_def_gw)) {
249af781231SIdo Barnea        mac_info.m_def_gw = 0;
250af781231SIdo Barnea    }
251af781231SIdo Barnea
252af781231SIdo Barnea    if (! utl_yaml_read_ip_addr(node, "ip", mac_info.m_ip)) {
253af781231SIdo Barnea        mac_info.m_ip = 0;
2548b52a31eSHanoh Haim    }
255a42bf7bcSIdo Barnea    if (! utl_yaml_read_ip_addr(node, "mask", mac_info.m_mask)) {
256a42bf7bcSIdo Barnea        mac_info.m_mask = 0;
257a42bf7bcSIdo Barnea    }
2589218827eSIdo Barnea    if (! utl_yaml_read_uint16(node, "vlan", mac_info.m_vlan, 0, 0xfff)) {
259a42bf7bcSIdo Barnea        mac_info.m_vlan = 0;
260a42bf7bcSIdo Barnea    }
2618b52a31eSHanoh Haim}
2628b52a31eSHanoh Haim
2638b52a31eSHanoh Haimvoid operator >> (const YAML::Node& node, CPlatformMemoryYamlInfo & plat_info) {
264cf5dc18eSHanoh Haim    if ( node.FindValue("mbuf_64") ){
26522bed39aSIdo Barnea        node["mbuf_64"] >> plat_info.m_mbuf[MBUF_64];
2668b52a31eSHanoh Haim    }
2678b52a31eSHanoh Haim
268cf5dc18eSHanoh Haim    if ( node.FindValue("mbuf_128") ){
26922bed39aSIdo Barnea        node["mbuf_128"] >> plat_info.m_mbuf[MBUF_128];
2708b52a31eSHanoh Haim    }
2718b52a31eSHanoh Haim
272cf5dc18eSHanoh Haim    if ( node.FindValue("mbuf_256") ){
27322bed39aSIdo Barnea        node["mbuf_256"] >> plat_info.m_mbuf[MBUF_256];
2748b52a31eSHanoh Haim    }
2758b52a31eSHanoh Haim
276cf5dc18eSHanoh Haim    if ( node.FindValue("mbuf_512") ){
27722bed39aSIdo Barnea        node["mbuf_512"] >> plat_info.m_mbuf[MBUF_512];
2788b52a31eSHanoh Haim    }
2798b52a31eSHanoh Haim
280cf5dc18eSHanoh Haim    if ( node.FindValue("mbuf_1024") ){
28122bed39aSIdo Barnea        node["mbuf_1024"] >> plat_info.m_mbuf[MBUF_1024];
2828b52a31eSHanoh Haim    }
2838b52a31eSHanoh Haim
284cf5dc18eSHanoh Haim    if ( node.FindValue("mbuf_2048") ){
28522bed39aSIdo Barnea        node["mbuf_2048"] >> plat_info.m_mbuf[MBUF_2048];
2868b52a31eSHanoh Haim    }
2878b52a31eSHanoh Haim
288a1364603SHanoh Haim    if ( node.FindValue("mbuf_4096") ){
28922bed39aSIdo Barnea        node["mbuf_4096"] >> plat_info.m_mbuf[MBUF_4096];
290a1364603SHanoh Haim    }
291a1364603SHanoh Haim
292a1364603SHanoh Haim    if ( node.FindValue("mbuf_9k") ){
29322bed39aSIdo Barnea        node["mbuf_9k"] >> plat_info.m_mbuf[MBUF_9k];
294a1364603SHanoh Haim    }
295a1364603SHanoh Haim
296a1364603SHanoh Haim
297cf5dc18eSHanoh Haim    if ( node.FindValue("traffic_mbuf_64") ){
29822bed39aSIdo Barnea        node["traffic_mbuf_64"] >> plat_info.m_mbuf[TRAFFIC_MBUF_64];
2998b52a31eSHanoh Haim    }
3008b52a31eSHanoh Haim
301cf5dc18eSHanoh Haim    if ( node.FindValue("traffic_mbuf_128") ){
30222bed39aSIdo Barnea        node["traffic_mbuf_128"] >> plat_info.m_mbuf[TRAFFIC_MBUF_128];
3038b52a31eSHanoh Haim    }
3048b52a31eSHanoh Haim
305cf5dc18eSHanoh Haim    if ( node.FindValue("traffic_mbuf_256") ){
30622bed39aSIdo Barnea        node["traffic_mbuf_256"] >> plat_info.m_mbuf[TRAFFIC_MBUF_256];
3078b52a31eSHanoh Haim    }
3088b52a31eSHanoh Haim
309cf5dc18eSHanoh Haim    if ( node.FindValue("traffic_mbuf_512") ){
31022bed39aSIdo Barnea        node["traffic_mbuf_512"] >> plat_info.m_mbuf[TRAFFIC_MBUF_512];
3118b52a31eSHanoh Haim    }
3128b52a31eSHanoh Haim
313cf5dc18eSHanoh Haim    if ( node.FindValue("traffic_mbuf_1024") ){
31422bed39aSIdo Barnea        node["traffic_mbuf_1024"] >> plat_info.m_mbuf[TRAFFIC_MBUF_1024];
3158b52a31eSHanoh Haim    }
3168b52a31eSHanoh Haim
317cf5dc18eSHanoh Haim    if ( node.FindValue("traffic_mbuf_2048") ){
31822bed39aSIdo Barnea        node["traffic_mbuf_2048"] >> plat_info.m_mbuf[TRAFFIC_MBUF_2048];
3198b52a31eSHanoh Haim    }
3208b52a31eSHanoh Haim
321a1364603SHanoh Haim    if ( node.FindValue("traffic_mbuf_4096") ){
32222bed39aSIdo Barnea        node["traffic_mbuf_4096"] >> plat_info.m_mbuf[TRAFFIC_MBUF_4096];
323a1364603SHanoh Haim    }
324a1364603SHanoh Haim
325a1364603SHanoh Haim    if ( node.FindValue("traffic_mbuf_9k") ){
32622bed39aSIdo Barnea        node["traffic_mbuf_9k"] >> plat_info.m_mbuf[TRAFFIC_MBUF_9k];
327a1364603SHanoh Haim    }
328a1364603SHanoh Haim
329a1364603SHanoh Haim
330cf5dc18eSHanoh Haim    if ( node.FindValue("dp_flows") ){
33122bed39aSIdo Barnea        node["dp_flows"] >> plat_info.m_mbuf[MBUF_DP_FLOWS];
3328b52a31eSHanoh Haim    }
3338b52a31eSHanoh Haim
334cf5dc18eSHanoh Haim    if ( node.FindValue("global_flows") ){
33522bed39aSIdo Barnea        node["global_flows"] >> plat_info.m_mbuf[MBUF_GLOBAL_FLOWS];
3368b52a31eSHanoh Haim    }
337cf5dc18eSHanoh Haim
3388b52a31eSHanoh Haim}
3398b52a31eSHanoh Haim
3408b52a31eSHanoh Haimvoid operator >> (const YAML::Node& node, CPlatformYamlInfo & plat_info) {
341cf5dc18eSHanoh Haim    if (node.FindValue("interface_mask")) {
342cf5dc18eSHanoh Haim        printf("WARNING interface_mask in not used any more !\n");
3438b52a31eSHanoh Haim    }
3448b52a31eSHanoh Haim
3458b52a31eSHanoh Haim    /* must have interfaces */
3468b52a31eSHanoh Haim    const YAML::Node& interfaces = node["interfaces"];
3477b8fd5a8SYaroslav Brustinov    if ( interfaces.size() > TREX_MAX_PORTS ) {
3480ab32112SYaroslav Brustinov        printf("ERROR: Maximal number of interfaces is: %d, you have specified: %d.\n",
3497b8fd5a8SYaroslav Brustinov                    TREX_MAX_PORTS, (int) interfaces.size());
3507b8fd5a8SYaroslav Brustinov        exit(-1);
3517b8fd5a8SYaroslav Brustinov    }
3520ab32112SYaroslav Brustinov
3538b52a31eSHanoh Haim    for(unsigned i=0;i<interfaces.size();i++) {
3548b52a31eSHanoh Haim        std::string  fi;
3558b52a31eSHanoh Haim        const YAML::Node & node = interfaces;
3568b52a31eSHanoh Haim        node[i]  >> fi;
3578b52a31eSHanoh Haim        plat_info.m_if_list.push_back(fi);
3588b52a31eSHanoh Haim    }
3598b52a31eSHanoh Haim
360ba997350SHanoh Haim
361ba997350SHanoh Haim    if ( node.FindValue("port_limit") ){
36222bed39aSIdo Barnea        node["port_limit"] >> plat_info.m_port_limit;
363ba997350SHanoh Haim        plat_info.m_port_limit_exist=true;
3648b52a31eSHanoh Haim    }
365ba997350SHanoh Haim
366ba997350SHanoh Haim
367ba997350SHanoh Haim    plat_info.m_enable_zmq_pub_exist = true;
368ba997350SHanoh Haim
369ba997350SHanoh Haim    if ( node.FindValue("enable_zmq_pub") ){
37022bed39aSIdo Barnea        node["enable_zmq_pub"] >> plat_info.m_enable_zmq_pub;
371ba997350SHanoh Haim        plat_info.m_enable_zmq_pub_exist = true;
3728b52a31eSHanoh Haim    }
373ba997350SHanoh Haim
374ba997350SHanoh Haim    if ( node.FindValue("zmq_pub_port") ){
37522bed39aSIdo Barnea        node["zmq_pub_port"] >> plat_info.m_zmq_pub_port;
376ba997350SHanoh Haim        plat_info.m_enable_zmq_pub_exist = true;
3778b52a31eSHanoh Haim    }
3788b52a31eSHanoh Haim
379ba997350SHanoh Haim    if ( node.FindValue("prefix") ){
38022bed39aSIdo Barnea        node["prefix"] >> plat_info.m_prefix;
381ba997350SHanoh Haim    }
3828b52a31eSHanoh Haim
383ba997350SHanoh Haim    if ( node.FindValue("limit_memory") ){
38422bed39aSIdo Barnea        node["limit_memory"] >> plat_info.m_limit_memory;
385ba997350SHanoh Haim    }
3868b52a31eSHanoh Haim
387ba997350SHanoh Haim    if ( node.FindValue("c") ){
38822bed39aSIdo Barnea        node["c"] >> plat_info.m_thread_per_dual_if;
3898b52a31eSHanoh Haim    }
3908b52a31eSHanoh Haim
391ba997350SHanoh Haim    if ( node.FindValue("telnet_port") ){
39222bed39aSIdo Barnea        node["telnet_port"] >> plat_info.m_telnet_port;
393ba997350SHanoh Haim        plat_info.m_telnet_exist=true;
394ba997350SHanoh Haim    }
395ba997350SHanoh Haim
396d4828d68SHanoh Haim    if ( node.FindValue("zmq_rpc_port") ){
397d4828d68SHanoh Haim        node["zmq_rpc_port"] >> plat_info.m_zmq_rpc_port;
398d4828d68SHanoh Haim    }
399d4828d68SHanoh Haim
400ba997350SHanoh Haim    if ( node.FindValue("port_bandwidth_gb") ){
401ba997350SHanoh Haim        node["port_bandwidth_gb"] >> plat_info.m_port_bandwidth_gb;
4028b52a31eSHanoh Haim    }
4038b52a31eSHanoh Haim
4048b52a31eSHanoh Haim    if ( node.FindValue("memory") ){
4058b52a31eSHanoh Haim        node["memory"] >> plat_info.m_memory;
4068b52a31eSHanoh Haim    }
4078b52a31eSHanoh Haim
4088b52a31eSHanoh Haim    if ( node.FindValue("platform") ){
4098b52a31eSHanoh Haim        node["platform"] >> plat_info.m_platform;
4108b52a31eSHanoh Haim        plat_info.m_platform.m_is_exists=true;
4118b52a31eSHanoh Haim    }
4128b52a31eSHanoh Haim
413dc66a3a8SHanoh Haim    if ( node.FindValue("tw") ){
414dc66a3a8SHanoh Haim        node["tw"] >> plat_info.m_tw;
415dc66a3a8SHanoh Haim    }
416dc66a3a8SHanoh Haim
417dc66a3a8SHanoh Haim
418ba997350SHanoh Haim    if ( node.FindValue("port_info")  ) {
4198b52a31eSHanoh Haim        const YAML::Node& mac_info = node["port_info"];
4208b52a31eSHanoh Haim        for(unsigned i=0;i<mac_info.size();i++) {
4218b52a31eSHanoh Haim           CMacYamlInfo  fi;
4228b52a31eSHanoh Haim            const YAML::Node & node =mac_info;
4238b52a31eSHanoh Haim            node[i]  >> fi;
4248b52a31eSHanoh Haim            plat_info.m_mac_info.push_back(fi);
4258b52a31eSHanoh Haim        }
4268b52a31eSHanoh Haim        plat_info.m_mac_info_exist = true;
4278b52a31eSHanoh Haim    }
4288b52a31eSHanoh Haim}
4298b52a31eSHanoh Haim
4308b52a31eSHanoh Haimint CPlatformYamlInfo::load_from_yaml_file(std::string file_name){
4318b52a31eSHanoh Haim    reset();
4328b52a31eSHanoh Haim    m_info_exist =true;
4338b52a31eSHanoh Haim
4348b52a31eSHanoh Haim    if ( !utl_is_file_exists(file_name) ){
4358b52a31eSHanoh Haim        printf(" ERROR file %s does not exists \n",file_name.c_str());
4368b52a31eSHanoh Haim        exit(-1);
4378b52a31eSHanoh Haim    }
4388b52a31eSHanoh Haim
4398b52a31eSHanoh Haim    try {
4408b52a31eSHanoh Haim       std::ifstream fin((char *)file_name.c_str());
4418b52a31eSHanoh Haim       YAML::Parser parser(fin);
4428b52a31eSHanoh Haim       YAML::Node doc;
4438b52a31eSHanoh Haim
4448b52a31eSHanoh Haim       parser.GetNextDocument(doc);
4458b52a31eSHanoh Haim       for(unsigned i=0;i<doc.size();i++) {
4468b52a31eSHanoh Haim          doc[i] >> *this;
4478b52a31eSHanoh Haim          break;
4488b52a31eSHanoh Haim       }
4498b52a31eSHanoh Haim    } catch ( const std::exception& e ) {
4508b52a31eSHanoh Haim        std::cout << e.what() << "\n";
4518b52a31eSHanoh Haim        exit(-1);
4528b52a31eSHanoh Haim    }
4538b52a31eSHanoh Haim    return (0);
4548b52a31eSHanoh Haim}
4558b52a31eSHanoh Haim
4568b52a31eSHanoh Haimstd::string CPlatformYamlInfo::get_use_if_comma_seperated(){
4578b52a31eSHanoh Haim    std::string s="";
4588b52a31eSHanoh Haim    int i;
4598b52a31eSHanoh Haim    for (i=0; i<(int)m_if_list.size()-1; i++) {
4608b52a31eSHanoh Haim        s+=m_if_list[i]+",";
4618b52a31eSHanoh Haim    }
4628b52a31eSHanoh Haim    s+=m_if_list[i];
4638b52a31eSHanoh Haim    return (s);
4648b52a31eSHanoh Haim}
4658b52a31eSHanoh Haim
4668b52a31eSHanoh Haimvoid CPlatformYamlInfo::Dump(FILE *fd){
4678b52a31eSHanoh Haim    if ( m_info_exist ==false ){
4688b52a31eSHanoh Haim        fprintf(fd," file info does not exist  \n");
4698b52a31eSHanoh Haim        return;
4708b52a31eSHanoh Haim    }
4718b52a31eSHanoh Haim
4728b52a31eSHanoh Haim    if (m_port_limit_exist && (m_port_limit != 0xffffffff)) {
47322bed39aSIdo Barnea        fprintf(fd," port limit     :  %d \n",m_port_limit);
4748b52a31eSHanoh Haim    }else{
47522bed39aSIdo Barnea        fprintf(fd," port limit     :  not configured \n");
4768b52a31eSHanoh Haim    }
47738dc2db8Simarom    fprintf(fd," port_bandwidth_gb    :  %lu \n", (ulong)m_port_bandwidth_gb);
47822bed39aSIdo Barnea
4798b52a31eSHanoh Haim    if ( m_if_mask_exist && m_if_mask.size() ) {
48022bed39aSIdo Barnea        fprintf(fd," if_mask        : ");
4818b52a31eSHanoh Haim        int i;
4828b52a31eSHanoh Haim        for (i=0; i<(int)m_if_mask.size(); i++) {
4838b52a31eSHanoh Haim            fprintf(fd," %s,",m_if_mask[i].c_str());
4848b52a31eSHanoh Haim        }
48538dc2db8Simarom        fprintf(fd,"\n");
4868b52a31eSHanoh Haim
4878b52a31eSHanoh Haim    }else{
48822bed39aSIdo Barnea        fprintf(fd," if_mask        : None \n");
4898b52a31eSHanoh Haim    }
49022bed39aSIdo Barnea
4918b52a31eSHanoh Haim    if ( m_prefix.length() ){
4928b52a31eSHanoh Haim        fprintf(fd," prefix              : %s \n",m_prefix.c_str());
4938b52a31eSHanoh Haim    }
4948b52a31eSHanoh Haim    if ( m_limit_memory.length() ){
4958b52a31eSHanoh Haim        fprintf(fd," limit_memory        : %s \n",m_limit_memory.c_str());
4968b52a31eSHanoh Haim    }
4978b52a31eSHanoh Haim    fprintf(fd," thread_per_dual_if      : %d \n",(int)m_thread_per_dual_if);
4988b52a31eSHanoh Haim
4998b52a31eSHanoh Haim    fprintf(fd," if        : ");
5008b52a31eSHanoh Haim    int i;
5018b52a31eSHanoh Haim    for (i=0; i<(int)m_if_list.size(); i++) {
5028b52a31eSHanoh Haim        fprintf(fd," %s,",m_if_list[i].c_str());
5038b52a31eSHanoh Haim    }
5048b52a31eSHanoh Haim    fprintf(fd,"\n");
5058b52a31eSHanoh Haim
5068b52a31eSHanoh Haim    if ( m_enable_zmq_pub_exist ){
5078b52a31eSHanoh Haim        fprintf(fd," enable_zmq_pub :  %d \n",m_enable_zmq_pub?1:0);
5088b52a31eSHanoh Haim        fprintf(fd," zmq_pub_port   :  %d \n",m_zmq_pub_port);
5098b52a31eSHanoh Haim    }
5108b52a31eSHanoh Haim    if ( m_telnet_exist ){
5118b52a31eSHanoh Haim        fprintf(fd," telnet_port    :  %d \n",m_telnet_port);
51245b71cffSHanoh Haim
5138b52a31eSHanoh Haim    }
51445b71cffSHanoh Haim    fprintf(fd," m_zmq_rpc_port    :  %d \n",m_zmq_rpc_port);
5158b52a31eSHanoh Haim
5168b52a31eSHanoh Haim    if ( m_mac_info_exist ){
5178b52a31eSHanoh Haim        int i;
5188b52a31eSHanoh Haim        for (i=0; i<(int)m_mac_info.size(); i++) {
5198b52a31eSHanoh Haim            m_mac_info[i].Dump(fd);
5208b52a31eSHanoh Haim        }
5218b52a31eSHanoh Haim    }
5228b52a31eSHanoh Haim    m_memory.Dump(fd);
5238b52a31eSHanoh Haim    m_platform.Dump(fd);
524dc66a3a8SHanoh Haim    m_tw.Dump(fd);
5258b52a31eSHanoh Haim}