diff options
author | Ido Barnea <ibarnea@cisco.com> | 2016-11-20 14:06:38 +0200 |
---|---|---|
committer | Ido Barnea <ibarnea@cisco.com> | 2016-11-21 12:56:28 +0200 |
commit | fb823791cf8794dc367640a1f46ea051a0c79ccc (patch) | |
tree | 930830c09477242cb2cc530bdcec2fc11c68b3b0 | |
parent | bf83f301e4fdbf333240af7f316735e35634c5fd (diff) |
Seperating ClientCfgDirBase/Ext and ClientCfgBase/Ext to save memory
Signed-off-by: Ido Barnea <ibarnea@cisco.com>
-rwxr-xr-x | src/bp_sim.cpp | 4 | ||||
-rwxr-xr-x | src/bp_sim.h | 4 | ||||
-rw-r--r-- | src/main_dpdk.cpp | 10 | ||||
-rw-r--r-- | src/trex_client_config.cpp | 51 | ||||
-rw-r--r-- | src/trex_client_config.h | 167 | ||||
-rwxr-xr-x | src/tuple_gen.cpp | 2 | ||||
-rwxr-xr-x | src/tuple_gen.h | 12 |
7 files changed, 148 insertions, 102 deletions
diff --git a/src/bp_sim.cpp b/src/bp_sim.cpp index cb1c58e6..fc6281cc 100755 --- a/src/bp_sim.cpp +++ b/src/bp_sim.cpp @@ -5248,11 +5248,11 @@ void CErfIF::add_vlan(uint16_t vlan_id) { m_raw->pkt_len += 4; } -void CErfIF::apply_client_config(const ClientCfg *cfg, pkt_dir_t dir) { +void CErfIF::apply_client_config(const ClientCfgBase *cfg, pkt_dir_t dir) { assert(cfg); uint8_t *p = (uint8_t *)m_raw->raw; - const ClientCfgDir &cfg_dir = ( (dir == CLIENT_SIDE) ? cfg->m_initiator : cfg->m_responder); + const ClientCfgDirBase &cfg_dir = ( (dir == CLIENT_SIDE) ? cfg->m_initiator : cfg->m_responder); /* dst mac */ if (cfg_dir.has_dst_mac_addr()) { diff --git a/src/bp_sim.h b/src/bp_sim.h index 77d2aa81..73914b69 100755 --- a/src/bp_sim.h +++ b/src/bp_sim.h @@ -1524,7 +1524,7 @@ public: uint32_t m_nat_tcp_seq_diff_server; // And some do seq num randomization for server->client also uint16_t m_nat_external_port; // NAT client port uint16_t m_nat_pad[1]; - const ClientCfg *m_client_cfg; + const ClientCfgBase *m_client_cfg; uint32_t m_src_idx; uint32_t m_dest_idx; uint32_t m_end_of_cache_line[6]; @@ -1888,7 +1888,7 @@ public: protected: void add_vlan(uint16_t vlan_id); - void apply_client_config(const ClientCfg *cfg, pkt_dir_t dir); + void apply_client_config(const ClientCfgBase *cfg, pkt_dir_t dir); virtual void fill_raw_packet(rte_mbuf_t * m,CGenNode * node,pkt_dir_t dir); CFileWriterBase * m_writer; diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp index fcafd322..0c35fcd6 100644 --- a/src/main_dpdk.cpp +++ b/src/main_dpdk.cpp @@ -1964,7 +1964,7 @@ public: __attribute__ ((noinline)) void handle_rx_queue(); __attribute__ ((noinline)) void handle_slowpath_features(CGenNode *node, rte_mbuf_t *m, uint8_t *p, pkt_dir_t dir); - void apply_client_cfg(const ClientCfg *cfg, rte_mbuf_t *m, pkt_dir_t dir, uint8_t *p); + void apply_client_cfg(const ClientCfgBase *cfg, rte_mbuf_t *m, pkt_dir_t dir, uint8_t *p); bool process_rx_pkt(pkt_dir_t dir,rte_mbuf_t * m); @@ -2355,12 +2355,12 @@ int CCoreEthIFStateless::handle_slow_path_node(CGenNode * no) { return (-1); } -void CCoreEthIF::apply_client_cfg(const ClientCfg *cfg, rte_mbuf_t *m, pkt_dir_t dir, uint8_t *p) { +void CCoreEthIF::apply_client_cfg(const ClientCfgBase *cfg, rte_mbuf_t *m, pkt_dir_t dir, uint8_t *p) { assert(cfg); /* take the right direction config */ - const ClientCfgDir &cfg_dir = ( (dir == CLIENT_SIDE) ? cfg->m_initiator : cfg->m_responder); + const ClientCfgDirBase &cfg_dir = ( (dir == CLIENT_SIDE) ? cfg->m_initiator : cfg->m_responder); /* dst mac */ if (cfg_dir.has_dst_mac_addr()) { @@ -3191,8 +3191,6 @@ void CGlobalTRex::pre_test() { memcpy(port_macs[port_id], CGlobalInfo::m_options.m_mac_addr[port_id].u.m_mac.src, ETHER_ADDR_LEN); } - m_fl.dump_client_config(stdout); // remove ??? - printf("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&1\n"); for (std::vector<ClientCfgCompactEntry *>::iterator it = conf.begin(); it != conf.end(); it++) { uint8_t port = (*it)->get_port(); uint16_t vlan = (*it)->get_vlan(); @@ -5558,7 +5556,7 @@ int main_test(int argc , char * argv[]){ } // in case of client config, we already run pretest - if (CGlobalInfo::m_options.preview.get_is_client_cfg_enable()) { + if (! CGlobalInfo::m_options.preview.get_is_client_cfg_enable()) { g_trex.pre_test(); } diff --git a/src/trex_client_config.cpp b/src/trex_client_config.cpp index df5164d6..826e049b 100644 --- a/src/trex_client_config.cpp +++ b/src/trex_client_config.cpp @@ -30,18 +30,7 @@ limitations under the License. #include "common/basic_utils.h" #include "bp_sim.h" -bool ClientCfgDir::need_resolve() const { - if (has_next_hop() || has_ipv6_next_hop()) - return true; - else - return false; -} - -void ClientCfgDir::set_no_resolve_needed() { - m_bitfield &= ~(HAS_DST_MAC | HAS_IPV6_NEXT_HOP | HAS_NEXT_HOP); -} - -void ClientCfgDir::dump(FILE *fd) const { +void ClientCfgDirBase::dump(FILE *fd) const { if (has_src_mac_addr()) { fprintf(fd, " src MAC:%s\n", utl_macaddr_to_str(m_src_mac.GetConstBuffer()).c_str()); } else { @@ -57,6 +46,33 @@ void ClientCfgDir::dump(FILE *fd) const { } else { fprintf(fd, " No vlan\n"); } +} + +void ClientCfgDirBase::update(uint32_t index, const ClientCfgDirExt &cfg) { + if (has_src_mac_addr()) { + m_src_mac += index; + } + + if (has_dst_mac_addr() || cfg.has_next_hop() || cfg.has_ipv6_next_hop()) { + m_dst_mac = cfg.get_resolved_mac(index); + m_bitfield |= HAS_DST_MAC; + } +} + +bool ClientCfgDirExt::need_resolve() const { + if (has_next_hop() || has_ipv6_next_hop()) + return true; + else + return false; +} + +void ClientCfgDirExt::set_no_resolve_needed() { + m_bitfield &= ~(HAS_DST_MAC | HAS_IPV6_NEXT_HOP | HAS_NEXT_HOP); +} + +void ClientCfgDirExt::dump(FILE *fd) const { + ClientCfgDirBase::dump(fd); + if (has_next_hop()) { fprintf(fd, " next hop:%s\n", ip_to_str(m_next_hop).c_str()); } else { @@ -76,7 +92,7 @@ void ClientCfgDir::dump(FILE *fd) const { } } -void ClientCfgDir::set_resolved_macs(CManyIPInfo &pretest_result, uint16_t count) { +void ClientCfgDirExt::set_resolved_macs(CManyIPInfo &pretest_result, uint16_t count) { uint16_t vlan = has_vlan() ? m_vlan : 0; MacAddress base_mac = m_dst_mac; m_resolved_macs.resize(count); @@ -98,6 +114,11 @@ void ClientCfgDir::set_resolved_macs(CManyIPInfo &pretest_result, uint16_t count } } +void ClientCfgBase::update(uint32_t index, const ClientCfgExt *cfg) { + m_initiator.update(index, cfg->m_initiator); + m_responder.update(index, cfg->m_responder); +} + void ClientCfgEntry::dump(FILE *fd) const { @@ -113,7 +134,7 @@ void ClientCfgEntry::set_resolved_macs(CManyIPInfo &pretest_result) { m_cfg.m_responder.set_resolved_macs(pretest_result, m_count); } -void ClientCfgCompactEntry::fill_from_dir(ClientCfgDir cfg, uint8_t port_id) { +void ClientCfgCompactEntry::fill_from_dir(ClientCfgDirExt cfg, uint8_t port_id) { m_port = port_id; if (cfg.has_next_hop()) { m_next_hop_base.ip = cfg.m_next_hop; @@ -271,7 +292,7 @@ ClientCfgDB::parse_single_group(YAMLParserWrapper &parser, const YAML::Node &nod } void -ClientCfgDB::parse_dir(YAMLParserWrapper &parser, const YAML::Node &node, ClientCfgDir &dir) { +ClientCfgDB::parse_dir(YAMLParserWrapper &parser, const YAML::Node &node, ClientCfgDirExt &dir) { if (node.FindValue("src_ip")) { dir.set_src_ip(parser.parse_ip(node, "src_ip")); } diff --git a/src/trex_client_config.h b/src/trex_client_config.h index 1122c6f9..972f84fa 100644 --- a/src/trex_client_config.h +++ b/src/trex_client_config.h @@ -29,16 +29,19 @@ limitations under the License. class YAMLParserWrapper; struct CTupleGenYamlInfo; +class ClientCfgDirExt; +// To save memory, we use here the ClientCfgExt and ClientCfgDirExt, +// and in tuple_gen the ClientCfgBase and ClientCfgDirBase /** * client configuration per direction * * @author imarom (29-Jun-16) */ -class ClientCfgDir { +class ClientCfgDirBase { friend class ClientCfgCompactEntry; -private: + protected: enum { HAS_SRC_MAC = 0x1, HAS_DST_MAC = 0x2, @@ -49,31 +52,36 @@ private: HAS_SRC_IPV6 = 0x40, }; - //???? do we need to save memory? Maybe do another class that inherit from ClientCfgDir to be used here? - uint32_t m_next_hop; - uint32_t m_src_ip; - uint16_t m_src_ipv6[8]; - uint16_t m_ipv6_next_hop[8]; MacAddress m_src_mac; MacAddress m_dst_mac; uint16_t m_vlan; uint8_t m_bitfield; - std::vector <MacAddress> m_resolved_macs; -public: - ClientCfgDir() { + public: + ClientCfgDirBase() { m_bitfield = 0; } - void dump(FILE *fd) const; - void set_resolved_macs(CManyIPInfo &pretest_result, uint16_t count); - bool need_resolve() const; - void set_no_resolve_needed(); - + virtual void dump(FILE *fd) const; bool has_src_mac_addr() const { return (m_bitfield & HAS_SRC_MAC); } + void set_src_mac_addr(uint64_t mac_addr) { + m_src_mac.set(mac_addr); + m_bitfield |= HAS_SRC_MAC; + } + + void set_dst_mac_addr(uint64_t mac_addr) { + m_dst_mac.set(mac_addr); + m_bitfield |= HAS_DST_MAC; + } + + void set_vlan(uint16_t vlan_id) { + m_vlan = vlan_id; + m_bitfield |= HAS_VLAN; + } + bool has_dst_mac_addr() const { return (m_bitfield & HAS_DST_MAC); } @@ -81,35 +89,65 @@ public: return (m_bitfield & HAS_VLAN); } - bool has_next_hop() const { - return (m_bitfield & HAS_NEXT_HOP); + const uint8_t *get_src_mac_addr() const { + assert(has_src_mac_addr()); + return m_src_mac.GetConstBuffer(); } - bool has_ipv6_next_hop() const { - return (m_bitfield & HAS_IPV6_NEXT_HOP); + const uint8_t *get_dst_mac_addr() const { + assert(has_dst_mac_addr()); + return m_dst_mac.GetConstBuffer(); } - bool has_src_ip() const { - return (m_bitfield & HAS_SRC_IP); + uint16_t get_vlan() const { + assert(has_vlan()); + return m_vlan; } - bool has_src_ipv6() const { - return (m_bitfield & HAS_SRC_IPV6); + /* updates a configuration with a group index member */ + void update(uint32_t index, const ClientCfgDirExt &cfg); +}; + +class ClientCfgDirExt : public ClientCfgDirBase { + friend class ClientCfgCompactEntry; + +private: + enum { + HAS_SRC_MAC = 0x1, + HAS_DST_MAC = 0x2, + HAS_VLAN = 0x4, + HAS_NEXT_HOP = 0x8, + HAS_IPV6_NEXT_HOP = 0x10, + HAS_SRC_IP = 0x20, + HAS_SRC_IPV6 = 0x40, + }; + + uint32_t m_next_hop; + uint32_t m_src_ip; + uint16_t m_src_ipv6[8]; + uint16_t m_ipv6_next_hop[8]; + std::vector <MacAddress> m_resolved_macs; + +public: + void dump(FILE *fd) const; + void set_resolved_macs(CManyIPInfo &pretest_result, uint16_t count); + bool need_resolve() const; + void set_no_resolve_needed(); + + bool has_ipv6_next_hop() const { + return (m_bitfield & HAS_IPV6_NEXT_HOP); } - void set_src_mac_addr(uint64_t mac_addr) { - m_src_mac.set(mac_addr); - m_bitfield |= HAS_SRC_MAC; + bool has_next_hop() const { + return (m_bitfield & HAS_NEXT_HOP); } - void set_dst_mac_addr(uint64_t mac_addr) { - m_dst_mac.set(mac_addr); - m_bitfield |= HAS_DST_MAC; + bool has_src_ip() const { + return (m_bitfield & HAS_SRC_IP); } - void set_vlan(uint16_t vlan_id) { - m_vlan = vlan_id; - m_bitfield |= HAS_VLAN; + bool has_src_ipv6() const { + return (m_bitfield & HAS_SRC_IPV6); } void set_src_ip(uint32_t src_ip) { @@ -136,56 +174,45 @@ public: m_bitfield |= HAS_IPV6_NEXT_HOP; } - /* updates a configuration with a group index member */ - - void update(uint32_t index, const ClientCfgDir &cfg) { - if (has_src_mac_addr()) { - m_src_mac += index; - } - - if (has_dst_mac_addr() || has_next_hop() || has_ipv6_next_hop()) { - m_dst_mac = cfg.m_resolved_macs[index]; - m_bitfield |= HAS_DST_MAC; - } - } - - const uint8_t *get_src_mac_addr() const { - assert(has_src_mac_addr()); - return m_src_mac.GetConstBuffer(); - } - - const uint8_t *get_dst_mac_addr() const { - assert(has_dst_mac_addr()); - return m_dst_mac.GetConstBuffer(); + virtual MacAddress get_resolved_mac(uint16_t index) const { + return m_resolved_macs[index]; } - uint16_t get_vlan() const { - assert(has_vlan()); - return m_vlan; - } }; +class ClientCfgExt; + /** * single client config * */ -class ClientCfg { +class ClientCfgBase { public: - - void dump (FILE *fd) const { + virtual void dump (FILE *fd) const { fprintf(fd, "initiator:\n"); m_initiator.dump(fd); fprintf(fd, "responder:\n"); m_responder.dump(fd); } - void update(uint32_t index, const ClientCfg &cfg) { - m_initiator.update(index, cfg.m_initiator); - m_responder.update(index, cfg.m_responder); + virtual void update(uint32_t index, const ClientCfgExt *cfg); + + public: + ClientCfgDirBase m_initiator; + ClientCfgDirBase m_responder; +}; + +class ClientCfgExt : public ClientCfgBase { +public: + virtual void dump (FILE *fd) const { + fprintf(fd, "initiator:\n"); + m_initiator.dump(fd); + fprintf(fd, "responder:\n"); + m_responder.dump(fd); } - ClientCfgDir m_initiator; - ClientCfgDir m_responder; + ClientCfgDirExt m_initiator; + ClientCfgDirExt m_responder; }; class ClientCfgCompactEntry { @@ -201,7 +228,7 @@ class ClientCfgCompactEntry { uint16_t *get_src_ipv6() {return m_src_ip.ipv6;} public: - void fill_from_dir(ClientCfgDir cfg, uint8_t port_id); + void fill_from_dir(ClientCfgDirExt cfg, uint8_t port_id); private: uint16_t m_count; @@ -253,9 +280,9 @@ public: * * @param info */ - void assign(ClientCfg &info) { + void assign(ClientCfgBase &info) { info = m_cfg; - info.update(m_iterator, m_cfg); + info.update(m_iterator, &m_cfg); /* advance for the next assign */ m_iterator = (m_iterator + 1) % m_count; @@ -265,7 +292,7 @@ public: uint32_t m_ip_start; uint32_t m_ip_end; - ClientCfg m_cfg; + ClientCfgExt m_cfg; uint32_t m_count; @@ -320,7 +347,7 @@ public: private: void parse_single_group(YAMLParserWrapper &parser, const YAML::Node &node); - void parse_dir(YAMLParserWrapper &parser, const YAML::Node &node, ClientCfgDir &dir); + void parse_dir(YAMLParserWrapper &parser, const YAML::Node &node, ClientCfgDirExt &dir); /** * verify the YAML file loaded in valid diff --git a/src/tuple_gen.cpp b/src/tuple_gen.cpp index f91a71a2..a4509580 100755 --- a/src/tuple_gen.cpp +++ b/src/tuple_gen.cpp @@ -133,7 +133,7 @@ void CClientPool::allocate_configured_clients(uint32_t min_ip, throw std::runtime_error(ss.str()); } - ClientCfg info; + ClientCfgBase info; group->assign(info); if (is_long_range) { diff --git a/src/tuple_gen.h b/src/tuple_gen.h index 8525a8e3..e9dc8d4e 100755 --- a/src/tuple_gen.h +++ b/src/tuple_gen.h @@ -85,15 +85,15 @@ public: void setClientPort(uint16_t port) { m_client_port = port; } - void setClientCfg(ClientCfg *cfg) { + void setClientCfg(ClientCfgBase *cfg) { m_client_cfg = cfg; } - ClientCfg *getClientCfg() { + ClientCfgBase *getClientCfg() { return m_client_cfg; } - void setClientTuple(uint32_t ip, ClientCfg *cfg, uint16_t port) { + void setClientTuple(uint32_t ip, ClientCfgBase *cfg, uint16_t port) { setClient(ip); setClientPort(port); setClientCfg(cfg); @@ -125,7 +125,7 @@ private: uint32_t m_server_ip; uint32_t m_server_idx; - ClientCfg *m_client_cfg; + ClientCfgBase *m_client_cfg; uint16_t m_client_port; uint16_t m_server_port; @@ -337,7 +337,7 @@ template <typename T> class CConfiguredClientInfo : public T { public: - CConfiguredClientInfo(uint32_t ip, const ClientCfg &cfg) : m_cfg(cfg) { + CConfiguredClientInfo(uint32_t ip, const ClientCfgBase &cfg) : m_cfg(cfg) { T::set_ip(ip); } @@ -348,7 +348,7 @@ public: } private: - ClientCfg m_cfg; + ClientCfgBase m_cfg; }; |