diff options
author | Hanoh Haim <hhaim@cisco.com> | 2015-10-18 16:16:39 +0300 |
---|---|---|
committer | Hanoh Haim <hhaim@cisco.com> | 2015-10-18 16:16:39 +0300 |
commit | cf5dc18ecbeca6b4be9a171d996bba1cba9c3679 (patch) | |
tree | 435a2e1643b06fa4a0f5310e440e362f9e3d3b46 /src | |
parent | ba9973506c1de58c87ccaa59798fb4e6252a186e (diff) |
another small fix for trex-130
Diffstat (limited to 'src')
-rwxr-xr-x | src/bp_sim.cpp | 158 | ||||
-rwxr-xr-x | src/platform_cfg.cpp | 87 | ||||
-rwxr-xr-x | src/tuple_gen.cpp | 30 | ||||
-rwxr-xr-x | src/utl_yaml.cpp | 18 |
4 files changed, 117 insertions, 176 deletions
diff --git a/src/bp_sim.cpp b/src/bp_sim.cpp index fcefa50c..c3581c55 100755 --- a/src/bp_sim.cpp +++ b/src/bp_sim.cpp @@ -2350,21 +2350,13 @@ void operator >> (const YAML::Node& node, CFlowYamlDpPkt & fi) { void operator >> (const YAML::Node& node, CVlanYamlInfo & fi) { uint32_t tmp; - try { - node["enable"] >> tmp ; - fi.m_enable=tmp; - }catch ( const std::exception& e ) { - - } - - try { - node["vlan0"] >> tmp; - fi.m_vlan_per_port[0] = tmp; - node["vlan1"] >> tmp; - fi.m_vlan_per_port[1] = tmp; - }catch ( const std::exception& e ) { - // there is a default - + if ( node.FindValue("enable") ){ + node["enable"] >> tmp ; + fi.m_enable=tmp; + node["vlan0"] >> tmp; + fi.m_vlan_per_port[0] = tmp; + node["vlan1"] >> tmp; + fi.m_vlan_per_port[1] = tmp; } } @@ -2372,15 +2364,15 @@ void operator >> (const YAML::Node& node, CVlanYamlInfo & fi) { void operator >> (const YAML::Node& node, CFlowYamlInfo & fi) { node["name"] >> fi.m_name; - - try { + + if ( node.FindValue("client_pool") ){ node["client_pool"] >> fi.m_client_pool_name; - } catch ( const std::exception& e ) { + }else{ fi.m_client_pool_name = "default"; } - try { + if ( node.FindValue("server_pool") ){ node["server_pool"] >> fi.m_server_pool_name; - } catch ( const std::exception& e ) { + }else{ fi.m_server_pool_name = "default"; } @@ -2393,37 +2385,38 @@ void operator >> (const YAML::Node& node, CFlowYamlInfo & fi) { fi.m_rtt_sec = t/1000000.0; node["w"] >> fi.m_w; - try { + if ( node.FindValue("cap_ipg") ){ node["cap_ipg"] >> fi.m_cap_mode; fi.m_cap_mode_was_set =true; - } catch ( const std::exception& e ) { + }else{ fi.m_cap_mode_was_set =false; } - try { + if ( node.FindValue("wlength") ){ node["wlength"] >> fi.m_wlength; fi.m_wlength_set=true; - } catch ( const std::exception& e ) { + }else{ fi.m_wlength_set=false; fi.m_wlength =500; } - try { + if ( node.FindValue("limit") ){ node["limit"] >> fi.m_limit; fi.m_limit_was_set = true; - } catch ( const std::exception& e ) { + }else{ fi.m_limit_was_set = false; fi.m_limit = 0; } - try { + if ( node.FindValue("plugin_id") ){ uint32_t plugin_val; node["plugin_id"] >> plugin_val; fi.m_plugin_id=plugin_val; - } catch ( const std::exception& e ) { + }else{ fi.m_plugin_id=0; } + fi.m_one_app_server_was_set = false; fi.m_one_app_server = false; if ( utl_yaml_read_ip_addr(node, @@ -2446,30 +2439,26 @@ void operator >> (const YAML::Node& node, CFlowYamlInfo & fi) { } - try { - int i; - const YAML::Node& dyn_pyload = node["dyn_pyload"]; - for(unsigned i=0;i<dyn_pyload.size();i++) { - CFlowYamlDpPkt fd; - dyn_pyload[i] >> fd; - if ( fi.m_dpPkt == 0 ){ - fi.m_dpPkt = new CFlowYamlDynamicPyloadPlugin(); - if (fi.m_plugin_id == 0) { - fi.m_plugin_id = mpDYN_PYLOAD; - }else{ - fprintf(stderr," plugin should be zero with dynamic pyload program"); - exit(-1); - } - } - - fd.Dump(stdout); - - fi.m_dpPkt->Add(fd); - printf(" here "); - } - } catch ( const std::exception& e ) { - fi.m_dpPkt=0; - } + if ( node.FindValue("dyn_pyload") ){ + int i; + const YAML::Node& dyn_pyload = node["dyn_pyload"]; + for(unsigned i=0;i<dyn_pyload.size();i++) { + CFlowYamlDpPkt fd; + dyn_pyload[i] >> fd; + if ( fi.m_dpPkt == 0 ){ + fi.m_dpPkt = new CFlowYamlDynamicPyloadPlugin(); + if (fi.m_plugin_id == 0) { + fi.m_plugin_id = mpDYN_PYLOAD; + }else{ + fprintf(stderr," plugin should be zero with dynamic pyload program"); + exit(-1); + } + } + fi.m_dpPkt->Add(fd); + } + }else{ + fi.m_dpPkt=0; + } } @@ -2478,13 +2467,12 @@ void operator >> (const YAML::Node& node, CFlowsYamlInfo & flows_info) { node["duration"] >> flows_info.m_duration_sec; - try { - node["generator"] >> flows_info.m_tuple_gen; - flows_info.m_tuple_gen_was_set =true; - } catch ( const std::exception& e ) { - flows_info.m_tuple_gen_was_set =false; + if ( node.FindValue("generator") ) { + node["generator"] >> flows_info.m_tuple_gen; + flows_info.m_tuple_gen_was_set =true; + }else{ + flows_info.m_tuple_gen_was_set =false; } - // m_ipv6_set will be true if and only if both src_ipv6 // and dst_ipv6 are provided. These are used to set @@ -2500,7 +2488,8 @@ void operator >> (const YAML::Node& node, CFlowsYamlInfo & flows_info) { // formed by providing src_ipv6,dst_ipv6 and specifying // {0,0,0,0,0,0xffff} flows_info.m_ipv6_set=true; - try { + + if ( node.FindValue("src_ipv6") ) { const YAML::Node& src_ipv6_info = node["src_ipv6"]; if (src_ipv6_info.size() == 6 ){ for(unsigned i=0;i<src_ipv6_info.size();i++) { @@ -2509,14 +2498,13 @@ void operator >> (const YAML::Node& node, CFlowsYamlInfo & flows_info) { node[i] >> fi; flows_info.m_src_ipv6.push_back(fi); } - }else{ - flows_info.m_ipv6_set=false; } - } catch ( const std::exception& e ) { + }else{ flows_info.m_ipv6_set=false; } - try { + + if ( node.FindValue("dst_ipv6") ) { const YAML::Node& dst_ipv6_info = node["dst_ipv6"]; if (dst_ipv6_info.size() == 6 ){ for(unsigned i=0;i<dst_ipv6_info.size();i++) { @@ -2525,67 +2513,65 @@ void operator >> (const YAML::Node& node, CFlowsYamlInfo & flows_info) { node[i] >> fi; flows_info.m_dst_ipv6.push_back(fi); } - }else{ - flows_info.m_ipv6_set=false; } - } catch ( const std::exception& e ) { + }else{ flows_info.m_ipv6_set=false; } - try { + if ( node.FindValue("cap_ipg") ) { node["cap_ipg"] >> flows_info.m_cap_mode; flows_info.m_cap_mode_set=true; - } catch ( const std::exception& e ) { + }else{ flows_info.m_cap_mode=false; flows_info.m_cap_mode_set=false; } - double t; - try { + double t=0.0; + + if ( node.FindValue("cap_ipg_min") ) { node["cap_ipg_min"] >> t ; flows_info.m_cap_ipg_min = t/1000000.0; flows_info.m_cap_ipg_min_set=true; - } catch ( const std::exception& e ) { + }else{ flows_info.m_cap_ipg_min_set=false; flows_info.m_cap_ipg_min = 20; } - try { + if ( node.FindValue("cap_override_ipg") ) { node["cap_override_ipg"] >> t; flows_info.m_cap_overide_ipg = t/1000000.0; flows_info.m_cap_overide_ipg_set = true; - } catch ( const std::exception& e ) { + }else{ flows_info.m_cap_overide_ipg_set = false; flows_info.m_cap_overide_ipg = 0; } - try { + if (node.FindValue("wlength")) { node["wlength"] >> flows_info.m_wlength; flows_info.m_wlength_set=true; - } catch ( const std::exception& e ) { + }else{ flows_info.m_wlength_set=false; flows_info.m_wlength =100; } - try { + if (node.FindValue("one_app_server")) { node["one_app_server"] >> flows_info.m_one_app_server; flows_info.m_one_app_server_was_set=true; - } catch ( const std::exception& e ) { + }else{ flows_info.m_one_app_server =false; flows_info.m_one_app_server_was_set=false; } - try { - node["vlan"] >> flows_info.m_vlan_info; - } catch ( const std::exception& e ) { - } - try { - node["mac_override_by_ip"] >> flows_info.m_mac_replace_by_ip; - } catch ( const std::exception& e ) { - flows_info.m_mac_replace_by_ip =false; + if (node.FindValue("vlan")) { + node["vlan"] >> flows_info.m_vlan_info; } + if (node.FindValue("mac_override_by_ip")) { + node["mac_override_by_ip"] >> flows_info.m_mac_replace_by_ip; + }else{ + flows_info.m_mac_replace_by_ip =false; + } const YAML::Node& mac_info = node["mac"]; for(unsigned i=0;i<mac_info.size();i++) { @@ -2593,7 +2579,7 @@ void operator >> (const YAML::Node& node, CFlowsYamlInfo & flows_info) { const YAML::Node & node =mac_info; node[i] >> fi; flows_info.m_mac_base.push_back(fi); - } + } const YAML::Node& cap_info = node["cap_info"]; for(unsigned i=0;i<cap_info.size();i++) { diff --git a/src/platform_cfg.cpp b/src/platform_cfg.cpp index db563cc9..f0911611 100755 --- a/src/platform_cfg.cpp +++ b/src/platform_cfg.cpp @@ -189,95 +189,72 @@ void operator >> (const YAML::Node& node, CMacYamlInfo & mac_info) { } void operator >> (const YAML::Node& node, CPlatformMemoryYamlInfo & plat_info) { - try { - node["mbuf_64"] >> plat_info.m_mbuf[MBUF_64]; - } catch ( const std::exception& e ) { + + if ( node.FindValue("mbuf_64") ){ + node["mbuf_64"] >> plat_info.m_mbuf[MBUF_64]; } - try { - node["mbuf_128"] >> plat_info.m_mbuf[MBUF_128]; - } catch ( const std::exception& e ) { + if ( node.FindValue("mbuf_128") ){ + node["mbuf_128"] >> plat_info.m_mbuf[MBUF_128]; } - try { - node["mbuf_256"] >> plat_info.m_mbuf[MBUF_256]; - } catch ( const std::exception& e ) { + if ( node.FindValue("mbuf_256") ){ + node["mbuf_256"] >> plat_info.m_mbuf[MBUF_256]; } - try { - node["mbuf_512"] >> plat_info.m_mbuf[MBUF_512]; - } catch ( const std::exception& e ) { + if ( node.FindValue("mbuf_512") ){ + node["mbuf_512"] >> plat_info.m_mbuf[MBUF_512]; } - try { - node["mbuf_1024"] >> plat_info.m_mbuf[MBUF_1024]; - } catch ( const std::exception& e ) { + if ( node.FindValue("mbuf_1024") ){ + node["mbuf_1024"] >> plat_info.m_mbuf[MBUF_1024]; } - try { - node["mbuf_2048"] >> plat_info.m_mbuf[MBUF_2048]; - } catch ( const std::exception& e ) { + if ( node.FindValue("mbuf_2048") ){ + node["mbuf_2048"] >> plat_info.m_mbuf[MBUF_2048]; } - try { - node["traffic_mbuf_64"] >> plat_info.m_mbuf[TRAFFIC_MBUF_64]; - } catch ( const std::exception& e ) { + if ( node.FindValue("traffic_mbuf_64") ){ + node["traffic_mbuf_64"] >> plat_info.m_mbuf[TRAFFIC_MBUF_64]; } - try { - node["traffic_mbuf_128"] >> plat_info.m_mbuf[TRAFFIC_MBUF_128]; - } catch ( const std::exception& e ) { + if ( node.FindValue("traffic_mbuf_128") ){ + node["traffic_mbuf_128"] >> plat_info.m_mbuf[TRAFFIC_MBUF_128]; } - try { - node["traffic_mbuf_256"] >> plat_info.m_mbuf[TRAFFIC_MBUF_256]; - } catch ( const std::exception& e ) { + if ( node.FindValue("traffic_mbuf_256") ){ + node["traffic_mbuf_256"] >> plat_info.m_mbuf[TRAFFIC_MBUF_256]; } - try { - node["traffic_mbuf_512"] >> plat_info.m_mbuf[TRAFFIC_MBUF_512]; - } catch ( const std::exception& e ) { + if ( node.FindValue("traffic_mbuf_512") ){ + node["traffic_mbuf_512"] >> plat_info.m_mbuf[TRAFFIC_MBUF_512]; } - try { - node["traffic_mbuf_1024"] >> plat_info.m_mbuf[TRAFFIC_MBUF_1024]; - } catch ( const std::exception& e ) { + if ( node.FindValue("traffic_mbuf_1024") ){ + node["traffic_mbuf_1024"] >> plat_info.m_mbuf[TRAFFIC_MBUF_1024]; } - try { - node["traffic_mbuf_2048"] >> plat_info.m_mbuf[TRAFFIC_MBUF_2048]; - } catch ( const std::exception& e ) { + if ( node.FindValue("traffic_mbuf_2048") ){ + node["traffic_mbuf_2048"] >> plat_info.m_mbuf[TRAFFIC_MBUF_2048]; } - try { - node["dp_flows"] >> plat_info.m_mbuf[MBUF_DP_FLOWS]; - } catch ( const std::exception& e ) { + if ( node.FindValue("dp_flows") ){ + node["dp_flows"] >> plat_info.m_mbuf[MBUF_DP_FLOWS]; } - try { - node["global_flows"] >> plat_info.m_mbuf[MBUF_GLOBAL_FLOWS]; - } catch ( const std::exception& e ) { + if ( node.FindValue("global_flows") ){ + node["global_flows"] >> plat_info.m_mbuf[MBUF_GLOBAL_FLOWS]; } + } void operator >> (const YAML::Node& node, CPlatformYamlInfo & plat_info) { - - try { - const YAML::Node& interface_mask = node["interface_mask"]; - for(unsigned i=0;i<interface_mask.size();i++) { - std::string fi; - const YAML::Node & node = interface_mask; - node[i] >> fi; - plat_info.m_if_mask.push_back(fi); - } - plat_info.m_if_mask_exist=true; - } catch ( const std::exception& e ) { - + if (node.FindValue("interface_mask")) { + printf("WARNING interface_mask in not used any more !\n"); } - /* must have interfaces */ const YAML::Node& interfaces = node["interfaces"]; for(unsigned i=0;i<interfaces.size();i++) { diff --git a/src/tuple_gen.cpp b/src/tuple_gen.cpp index 3a477338..3c05cf05 100755 --- a/src/tuple_gen.cpp +++ b/src/tuple_gen.cpp @@ -245,30 +245,12 @@ void operator >> (const YAML::Node& node, CTupleGenPoolYaml & fi) { fi.m_tcp_aging_sec = 0; fi.m_udp_aging_sec = 0; fi.m_dual_interface_mask = 0; - try { - utl_yaml_read_uint32(node,"clients_per_gb",fi.m_number_of_clients_per_gb); - } catch ( const std::exception& e ) { - ;} - try { - utl_yaml_read_uint32(node,"min_clients",fi.m_min_clients); - } catch ( const std::exception& e ) { - ;} - try { - utl_yaml_read_ip_addr(node,"dual_port_mask",fi.m_dual_interface_mask); - } catch ( const std::exception& e ) { - ;} - try { - utl_yaml_read_uint16(node,"tcp_aging",fi.m_tcp_aging_sec); - } catch ( const std::exception& e ) { - ;} - try { - utl_yaml_read_uint16(node,"udp_aging",fi.m_udp_aging_sec); - } catch ( const std::exception& e ) { - ;} - try { - node["track_ports"] >> fi.m_is_bundling; - } catch ( const std::exception& e ) { - ;} + utl_yaml_read_uint32(node,"clients_per_gb",fi.m_number_of_clients_per_gb); + utl_yaml_read_uint32(node,"min_clients",fi.m_min_clients); + utl_yaml_read_ip_addr(node,"dual_port_mask",fi.m_dual_interface_mask); + utl_yaml_read_uint16(node,"tcp_aging",fi.m_tcp_aging_sec); + utl_yaml_read_uint16(node,"udp_aging",fi.m_udp_aging_sec); + utl_yaml_read_bool(node,"track_ports",fi.m_is_bundling); } void copy_global_pool_para(CTupleGenPoolYaml & src, CTupleGenPoolYaml & dst) { if (src.m_number_of_clients_per_gb == 0) diff --git a/src/utl_yaml.cpp b/src/utl_yaml.cpp index 237e85af..5f3ca735 100755 --- a/src/utl_yaml.cpp +++ b/src/utl_yaml.cpp @@ -70,13 +70,15 @@ bool utl_yaml_read_ip_addr(const YAML::Node& node, std::string tmp; uint32_t ip; bool res=false; - try { + if ( node.FindValue(name) ) { node[name] >> tmp ; if ( my_inet_pton4((char *)tmp.c_str(), (unsigned char *)&ip) ){ val=PKT_NTOHL(ip); res=true; + }else{ + printf(" ERROR not a valid ip %s \n",(char *)tmp.c_str()); + exit(-1); } - }catch ( const std::exception& e ) { } return (res); } @@ -85,14 +87,11 @@ bool utl_yaml_read_uint32(const YAML::Node& node, std::string name, uint32_t & val){ bool res=false; - - try { + if ( node.FindValue(name) ) { node[name] >> val ; res=true; - }catch ( const std::exception& e ) { } return (res); - } bool utl_yaml_read_uint16(const YAML::Node& node, @@ -100,12 +99,10 @@ bool utl_yaml_read_uint16(const YAML::Node& node, uint16_t & val){ uint32_t val_tmp; bool res=false; - - try { + if ( node.FindValue(name) ) { node[name] >> val_tmp ; val = (uint16_t)val_tmp; res=true; - }catch ( const std::exception& e ) { } } @@ -113,10 +110,9 @@ bool utl_yaml_read_bool(const YAML::Node& node, std::string name, bool & val){ bool res=false; - try { + if ( node.FindValue(name) ) { node[name] >> val ; res=true; - }catch ( const std::exception& e ) { } return( res); } |