diff options
-rwxr-xr-x | src/bp_sim.cpp | 28 | ||||
-rwxr-xr-x | src/bp_sim.h | 5 | ||||
-rwxr-xr-x | src/gtest/tuple_gen_test.cpp | 4 | ||||
-rw-r--r-- | src/mac_mapping.h | 60 | ||||
-rwxr-xr-x | src/main_dpdk.cpp | 4 | ||||
-rwxr-xr-x | src/tuple_gen.cpp | 19 | ||||
-rwxr-xr-x | src/tuple_gen.h | 305 |
7 files changed, 249 insertions, 176 deletions
diff --git a/src/bp_sim.cpp b/src/bp_sim.cpp index 7cbeb09d..fcefa50c 100755 --- a/src/bp_sim.cpp +++ b/src/bp_sim.cpp @@ -3177,7 +3177,7 @@ bool CFlowGenListPerThread::Create(uint32_t thread_id, /* split the clients to threads */ CTupleGenYamlInfo * tuple_gen = &m_flow_list->m_yaml_info.m_tuple_gen; - m_smart_gen.Create(0,m_thread_id,m_flow_list->is_mac_info_configured); + m_smart_gen.Create(0,m_thread_id,m_flow_list->get_is_mac_conf()); /* split the clients to threads using the mask */ CIpPortion portion; @@ -3191,7 +3191,7 @@ bool CFlowGenListPerThread::Create(uint32_t thread_id, portion.m_ip_end, get_longest_flow(i,true), get_total_kcps(i,true)*1000, - m_flow_list, + &m_flow_list->m_mac_info, tuple_gen->m_client_pool[i].m_tcp_aging_sec, tuple_gen->m_client_pool[i].m_udp_aging_sec ); @@ -3962,7 +3962,7 @@ int CFlowGenList::load_from_mac_file(std::string file_name) { printf(" ERROR no mac_file is set, file %s does not exist \n",file_name.c_str()); exit(-1); } - is_mac_info_configured = true; + m_mac_info.set_configured(true); try { std::ifstream fin((char *)file_name.c_str()); @@ -3970,7 +3970,7 @@ int CFlowGenList::load_from_mac_file(std::string file_name) { YAML::Node doc; parser.GetNextDocument(doc); - doc[0] >> m_mac_info; + doc[0] >> m_mac_info.get_mac_info(); } catch ( const std::exception& e ) { std::cout << e.what() << "\n"; m_mac_info.clear(); @@ -3982,7 +3982,6 @@ int CFlowGenList::load_from_mac_file(std::string file_name) { int CFlowGenList::load_from_yaml(std::string file_name, uint32_t num_threads){ - is_mac_info_configured = false; uint8_t idx; m_yaml_info.load_from_yaml_file(file_name); if (m_yaml_info.verify_correctness(num_threads) ==false){ @@ -6643,25 +6642,6 @@ void CFlowYamlDynamicPyloadPlugin::Dump(FILE *fd){ } } -bool is_mac_info_conf(CFlowGenList *fl_list) { - if (fl_list) { - return fl_list->is_mac_info_configured; - } - return false; -} - -mac_addr_align_t * get_mac_addr_by_ip(CFlowGenList *fl_list, - uint32_t ip) { - if (fl_list && - fl_list->is_mac_info_configured && - fl_list->m_mac_info.count(ip)>0) { - return &fl_list->m_mac_info[ip]; - } - return NULL; -} - - - uint16_t CSimplePacketParser::getPktSize(){ uint16_t ip_len=0; if (m_ipv4) { diff --git a/src/bp_sim.h b/src/bp_sim.h index 29b9a724..675e88b4 100755 --- a/src/bp_sim.h +++ b/src/bp_sim.h @@ -3430,6 +3430,7 @@ inline void CFlowGenListPerThread::free_last_flow_node(CGenNode *p){ free_node( p); } + class CFlowGenList { public: @@ -3457,12 +3458,12 @@ public: double get_total_tx_bps(); uint32_t get_total_repeat_flows(); double get_delta_flow_is_sec(); + bool get_is_mac_conf() { return m_mac_info.is_configured();} public: std::vector<CFlowGeneratorRec *> m_cap_gen; /* global info */ CFlowsYamlInfo m_yaml_info; /* global yaml*/ std::vector<CFlowGenListPerThread *> m_threads_info; - bool is_mac_info_configured; - std::map<uint32_t, mac_addr_align_t> m_mac_info; /* global mac info loaded form mac_file*/ + CFlowGenListMac m_mac_info; }; diff --git a/src/gtest/tuple_gen_test.cpp b/src/gtest/tuple_gen_test.cpp index 8791b67d..8a774e38 100755 --- a/src/gtest/tuple_gen_test.cpp +++ b/src/gtest/tuple_gen_test.cpp @@ -334,7 +334,8 @@ TEST(tuple_gen,GenerateTupleMac) { CClientPool gen; gen.Create(cdSEQ_DIST, - 0x10000001, 0x1000000f, 64000,2, &fl,true,0,0); + 0x10000001, 0x1000000f, 64000,2, &fl.m_mac_info,true,0,0); + CTupleBase result; uint32_t result_src; uint16_t result_port; @@ -348,6 +349,7 @@ TEST(tuple_gen,GenerateTupleMac) { result_mac = result.getClientMac(); EXPECT_EQ(result_src, (uint32_t)(0x10000001+i%2)); EXPECT_EQ(result_port, 1024+i/2); + printf("i:%d,mac:%d\n",i,result_mac->mac[3]); if (i%2==0) EXPECT_EQ(result_mac->mac[3], 5); else diff --git a/src/mac_mapping.h b/src/mac_mapping.h new file mode 100644 index 00000000..84151e8c --- /dev/null +++ b/src/mac_mapping.h @@ -0,0 +1,60 @@ +#ifndef MAC_MAPPING_H_ +#define MAC_MAPPING_H_ + +#define INUSED 0 +#define UNUSED 1 +typedef struct mac_addr_align_ { +public: + uint8_t mac[6]; + uint8_t inused; + uint8_t pad; +} mac_addr_align_t; + +typedef struct mac_mapping_ { + mac_addr_align_t mac; + uint32_t ip; +} mac_mapping_t; + +class CFlowGenListMac { +public: + CFlowGenListMac() { + set_configured(false); + } + + std::map<uint32_t, mac_addr_align_t> & + get_mac_info () { + return m_mac_info; + } + + bool is_configured() { + return is_mac_info_configured; + } + + void set_configured(bool is_conf) { + is_mac_info_configured = is_conf; + } + + void clear() { + set_configured(false); + m_mac_info.clear(); + } + + uint32_t is_mac_exist(uint32_t ip) { + if (is_configured()) { + return m_mac_info.count(ip); + } else { + return 0; + } + } + mac_addr_align_t* get_mac_addr_by_ip(uint32_t ip) { + if (is_mac_exist(ip)!=0) { + return &(m_mac_info[ip]); + } + return NULL; + } +private: + bool is_mac_info_configured; + std::map<uint32_t, mac_addr_align_t> m_mac_info; /* global mac info loaded form mac_file*/ +}; + +#endif //MAC_MAPPING_H_ diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp index 820fb3fa..0d03a207 100755 --- a/src/main_dpdk.cpp +++ b/src/main_dpdk.cpp @@ -4100,9 +4100,9 @@ int CGlobalPortCfg::start_send_master(){ if (CGlobalInfo::m_options.mac_file != "") { CGlobalInfo::m_options.preview.set_mac_ip_mapping_enable(true); m_fl.load_from_mac_file(CGlobalInfo::m_options.mac_file); - m_fl.is_mac_info_configured = true; + m_fl.m_mac_info.set_configured(true); } else { - m_fl.is_mac_info_configured = false; + m_fl.m_mac_info.set_configured(false); } m_expected_pps = m_fl.get_total_pps(); diff --git a/src/tuple_gen.cpp b/src/tuple_gen.cpp index e408f275..3a477338 100755 --- a/src/tuple_gen.cpp +++ b/src/tuple_gen.cpp @@ -57,7 +57,7 @@ void CClientPool::Create(IP_DIST_t dist_value, uint32_t max_ip, double l_flow, double t_cps, - CFlowGenList* fl_list, + CFlowGenListMac* mac_info, bool has_mac_map, uint16_t tcp_aging, uint16_t udp_aging) { @@ -65,10 +65,10 @@ void CClientPool::Create(IP_DIST_t dist_value, set_dist(dist_value); uint32_t total_ip = max_ip - min_ip +1; uint32_t avail_ip = total_ip; - if (has_mac_map && (fl_list!=NULL)) { + if (has_mac_map && (mac_info!=NULL)) { for(int idx=0;idx<total_ip;idx++){ mac_addr_align_t *mac_adr = NULL; - mac_adr = get_mac_addr_by_ip(fl_list, min_ip+idx); + mac_adr = mac_info->get_mac_addr_by_ip(min_ip+idx); if (mac_adr == NULL) { avail_ip--; } @@ -86,7 +86,7 @@ void CClientPool::Create(IP_DIST_t dist_value, if (has_mac_map) { for(int idx=0;idx<total_ip;idx++){ mac_addr_align_t *mac_adr = NULL; - mac_adr = get_mac_addr_by_ip(fl_list, min_ip+idx); + mac_adr = mac_info->get_mac_addr_by_ip( min_ip+idx); if (mac_adr != NULL) { m_ip_info[idx] = new CClientInfoL(has_mac_map); m_ip_info[idx]->set_ip(min_ip+idx); @@ -103,7 +103,7 @@ void CClientPool::Create(IP_DIST_t dist_value, if (has_mac_map) { for(int idx=0;idx<total_ip;idx++){ mac_addr_align_t *mac_adr = NULL; - mac_adr = get_mac_addr_by_ip(fl_list, min_ip+idx); + mac_adr = mac_info->get_mac_addr_by_ip(min_ip+idx); if (mac_adr != NULL) { m_ip_info[idx] = new CClientInfo(has_mac_map); m_ip_info[idx]->set_ip(min_ip+idx); @@ -123,20 +123,19 @@ void CClientPool::Create(IP_DIST_t dist_value, CreateBase(); } -void delay(int msec); bool CTupleGeneratorSmart::add_client_pool(IP_DIST_t client_dist, uint32_t min_client, uint32_t max_client, double l_flow, double t_cps, - CFlowGenList* fl_list, + CFlowGenListMac* mac_info, uint16_t tcp_aging, uint16_t udp_aging){ assert(max_client>=min_client); CClientPool* pool = new CClientPool(); pool->Create(client_dist, min_client, max_client, - l_flow, t_cps, fl_list, has_mac_mapping, + l_flow, t_cps, mac_info, m_has_mac_mapping, tcp_aging, udp_aging); m_client_pool.push_back(pool); @@ -171,13 +170,13 @@ bool CTupleGeneratorSmart::Create(uint32_t _id, m_thread_id = thread_id; m_id = _id; m_was_init=true; - has_mac_mapping = has_mac; + m_has_mac_mapping = has_mac; return(true); } void CTupleGeneratorSmart::Delete(){ m_was_init=false; - has_mac_mapping = false; + m_has_mac_mapping = false; for (int idx=0;idx<m_client_pool.size();idx++) { m_client_pool[idx]->Delete(); diff --git a/src/tuple_gen.h b/src/tuple_gen.h index fb856538..4b181ad5 100755 --- a/src/tuple_gen.h +++ b/src/tuple_gen.h @@ -37,10 +37,97 @@ limitations under the License. #include "common/c_common.h" #include <bitset> #include <yaml-cpp/yaml.h> - +#include <mac_mapping.h> #include <random> +class CTupleBase { +public: + CTupleBase() { + m_client_mac.inused = UNUSED; + } + uint32_t getClient() { + return m_client_ip; + } + void setClient(uint32_t ip) { + m_client_ip = ip; + } + uint32_t getClientId() { + return m_client_idx; + } + void setClientId(uint32_t id) { + m_client_idx = id; + } + + uint32_t getServer(){ + return m_server_ip; + } + void setServer(uint32_t ip) { + m_server_ip = ip; + } + uint32_t getServerId(){ + return m_server_idx; + } + void setServerId(uint32_t id) { + m_server_idx = id; + } + uint16_t getServerPort() { + return m_server_port; + } + void setServerPort(uint16_t port) { + m_server_port = port; + } + uint16_t getClientPort() { + return m_client_port; + } + void setClientPort(uint16_t port) { + m_client_port = port; + } + mac_addr_align_t* getClientMac() { + return &m_client_mac; + } + void setClientMac(mac_addr_align_t* mac_info) { + if (mac_info != NULL) { + memcpy(&m_client_mac, mac_info, sizeof(mac_addr_align_t)); + m_client_mac.inused = INUSED; + } else { + m_client_mac.inused = UNUSED; + } + } + void setClientTuple(uint32_t ip,mac_addr_align_t*mac,uint16_t port) { + setClient(ip); + setClientMac(mac); + setClientPort(port); + } + void setClientAll2(uint32_t id, uint32_t ip,uint16_t port) { + setClientId(id); + setClient(ip); + setClientPort(port); + } + + void setServerAll(uint32_t id, uint32_t ip) { + setServerId(id); + setServer(ip); + } + void getClientAll(uint32_t & id, uint32_t & ip, uint32_t & port) { + id = getClientId(); + ip = getClient(); + port = getClientPort(); + } + void getServerAll(uint32_t & id, uint32_t & ip) { + id = getServerId(); + ip = getServer(); + } +private: + uint32_t m_client_ip; + uint32_t m_client_idx; + uint32_t m_server_ip; + uint32_t m_server_idx; + mac_addr_align_t m_client_mac; + uint16_t m_client_port; + uint16_t m_server_port; +}; + /* @@ -59,9 +146,8 @@ limitations under the License. #define FOREACH(vector) for(int i=0;i<vector.size();i++) -/* Client distribution */ - +/* Client distribution */ typedef enum { cdSEQ_DIST = 0, cdRANDOM_DIST = 1, @@ -69,22 +155,6 @@ typedef enum { cdMAX_DIST = 3 } IP_DIST_t ; -#define INUSED 0 -#define UNUSED 1 -typedef struct mac_addr_align_ { -public: - uint8_t mac[6]; - uint8_t inused; - uint8_t pad; -} mac_addr_align_t; - -typedef struct mac_mapping_ { - mac_addr_align_t mac; - uint32_t ip; -} mac_mapping_t; - - - /* For type 1, we generator port by maintaining a 64K bit array for each port. * In this case, we cannot support large number of clients due to memory exhausted. * @@ -99,13 +169,13 @@ typedef struct mac_mapping_ { #define TYPE2 1 #define MAX_TYPE 3 - class CIpInfoBase { public: virtual mac_addr_align_t* get_mac() { return NULL;} virtual void set_mac(mac_addr_align_t*){;} virtual uint16_t get_new_free_port() = 0; virtual void return_port(uint16_t a) = 0; + virtual void generate_tuple(CTupleBase & tuple) = 0; virtual void return_all_ports() = 0; uint32_t get_ip() { return m_ip; @@ -113,7 +183,7 @@ class CIpInfoBase { void set_ip(uint32_t ip) { m_ip = ip; } - public: + protected: uint32_t m_ip; }; @@ -233,31 +303,37 @@ class CIpInfo : public CIpInfoBase { }; class CClientInfo : public CIpInfo { - public: - CClientInfo (bool has_mac) { - if (has_mac==true) { - m_mac = new mac_addr_align_t(); - } else { - m_mac = NULL; - } - } - CClientInfo () { +public: + CClientInfo (bool has_mac) { + if (has_mac==true) { + m_mac = new mac_addr_align_t(); + } else { m_mac = NULL; } - - mac_addr_align_t* get_mac() { - return m_mac; - } - void set_mac(mac_addr_align_t *mac) { - memcpy(m_mac, mac, sizeof(mac_addr_align_t)); - } - ~CClientInfo() { - if (m_mac!=NULL){ - delete m_mac; - } + } + CClientInfo () { + m_mac = NULL; + } + + mac_addr_align_t* get_mac() { + return m_mac; + } + void set_mac(mac_addr_align_t *mac) { + memcpy(m_mac, mac, sizeof(mac_addr_align_t)); + } + ~CClientInfo() { + if (m_mac!=NULL){ + delete m_mac; + m_mac=NULL; } - private: - mac_addr_align_t *m_mac; + } + + void generate_tuple(CTupleBase & tuple) { + tuple.setClientTuple(m_ip, m_mac, + get_new_free_port()); + } +private: + mac_addr_align_t *m_mac; }; class CClientInfoL : public CIpInfoL { @@ -272,100 +348,44 @@ public: CClientInfoL () { m_mac = NULL; } - + mac_addr_align_t* get_mac() { return m_mac; } + void set_mac(mac_addr_align_t *mac) { memcpy(m_mac, mac, sizeof(mac_addr_align_t)); } + ~CClientInfoL() { - if (m_mac!=NULL) { + if (m_mac!=NULL){ delete m_mac; + m_mac=NULL; } } + + void generate_tuple(CTupleBase & tuple) { + tuple.setClientTuple(m_ip, m_mac, + get_new_free_port()); + } private: mac_addr_align_t *m_mac; }; class CServerInfo : public CIpInfo { - ; + void generate_tuple(CTupleBase & tuple) { + tuple.setServer(m_ip); + } }; class CServerInfoL : public CIpInfoL { - ; -}; - - -class CTupleBase { -public: - CTupleBase() { - m_client_mac.inused = UNUSED; - } - uint32_t getClient() { - return m_client_ip; - } - void setClient(uint32_t ip) { - m_client_ip = ip; - } - uint32_t getClientId() { - return m_client_idx; - } - void setClientId(uint32_t id) { - m_client_idx = id; - } - - uint32_t getServer(){ - return m_server_ip; - } - void setServer(uint32_t ip) { - m_server_ip = ip; - } - uint32_t getServerId(){ - return m_server_idx; - } - void setServerId(uint32_t id) { - m_server_idx = id; - } - uint16_t getServerPort() { - return m_server_port; - } - void setServerPort(uint16_t port) { - m_server_port = port; - } - uint16_t getClientPort() { - return m_client_port; - } - void setClientPort(uint16_t port) { - m_client_port = port; - } - mac_addr_align_t* getClientMac() { - return &m_client_mac; - } - void setClientMac(mac_addr_align_t* mac_info) { - if (mac_info != NULL) { - memcpy(&m_client_mac, mac_info, sizeof(mac_addr_align_t)); - m_client_mac.inused = INUSED; - } else { - m_client_mac.inused = UNUSED; - } - } -private: - uint32_t m_client_ip; - uint32_t m_client_idx; - uint32_t m_server_ip; - uint32_t m_server_idx; - mac_addr_align_t m_client_mac; - uint16_t m_client_port; - uint16_t m_server_port; + void generate_tuple(CTupleBase & tuple) { + tuple.setServer(m_ip); + } }; -class CFlowGenList; -mac_addr_align_t * get_mac_addr_by_ip(CFlowGenList *fl_list, - uint32_t ip); -bool is_mac_info_conf(CFlowGenList *fl_list); class CIpPool { public: @@ -381,7 +401,8 @@ class CIpPool { m_active_alloc++; return (port); } - bool is_valid_ip(uint32_t ip){ + + bool is_valid_ip(uint32_t ip){ CIpInfoBase* ip_front = m_ip_info.front(); CIpInfoBase* ip_back = m_ip_info.back(); if ((ip>=ip_front->get_ip()) && @@ -422,6 +443,9 @@ class CIpPool { inc_cur_idx(); return res_idx; } + + + void set_dist(IP_DIST_t dist) { if (dist>=cdMAX_DIST) { m_dist = cdSEQ_DIST; @@ -491,13 +515,20 @@ class CIpPool { class CClientPool : public CIpPool { public: - void GenerateTuple(CTupleBase & tuple) { - uint32_t idx = generate_ip(); - tuple.setClientId(idx); - tuple.setClient(get_ip(idx)); - tuple.setClientMac(get_mac(idx)); - tuple.setClientPort(GenerateOnePort(idx)); + + uint32_t GenerateTuple(CTupleBase & tuple) { + uint32_t idx = generate_ip(); + CIpInfoBase* ip_info = m_ip_info[idx]; + ip_info->generate_tuple(tuple); + + tuple.setClientId(idx); + if (tuple.getClientPort()==ILLEGAL_PORT) { + m_port_allocation_error++; + } + m_active_alloc++; + return idx; } + uint16_t get_tcp_aging() { return m_tcp_aging; } @@ -509,10 +540,11 @@ public: uint32_t max_ip, double l_flow, double t_cps, - CFlowGenList* fl_list, + CFlowGenListMac* mac_info, bool has_mac_map, uint16_t tcp_aging, uint16_t udp_aging); + public: uint16_t m_tcp_aging; uint16_t m_udp_aging; @@ -568,11 +600,9 @@ private: class CServerPool : public CServerPoolBase { public: - CIpPool *gen; void GenerateTuple(CTupleBase & tuple) { uint32_t idx = gen->generate_ip(); - tuple.setServerId(idx); - tuple.setServer(gen->get_ip(idx)); + tuple.setServerAll(idx, gen->get_ip(idx)); } uint16_t GenerateOnePort(uint32_t idx) { return gen->GenerateOnePort(idx); @@ -587,11 +617,14 @@ public: if (gen!=NULL) { gen->Delete(); delete gen; + gen=NULL; } } uint32_t get_total_ips() { return gen->m_ip_info.size(); } +private: + CIpPool *gen; }; /* generate for each template */ @@ -648,7 +681,7 @@ public: public: CTupleGeneratorSmart(){ m_was_init=false; - has_mac_mapping = false; + m_has_mac_mapping = false; } bool Create(uint32_t _id, uint32_t thread_id, bool has_mac=false); @@ -672,7 +705,7 @@ public: uint32_t max_client, double l_flow, double t_cps, - CFlowGenList* fl_list, + CFlowGenListMac* mac_info, uint16_t tcp_aging, uint16_t udp_aging); bool add_server_pool(IP_DIST_t server_dist, @@ -699,7 +732,7 @@ private: std::vector<CClientPool*> m_client_pool; std::vector<CServerPoolBase*> m_server_pool; bool m_was_init; - bool has_mac_mapping; + bool m_has_mac_mapping; }; class CTupleTemplateGeneratorSmart { @@ -718,15 +751,13 @@ public: m_server_gen->GenerateTuple(tuple); m_cache_client_ip = tuple.getClient(); m_cache_client_idx = tuple.getClientId(); - m_cache_server_ip = tuple.getServer(); - m_cache_server_idx = tuple.getServerId(); + tuple.getServerAll(m_cache_server_idx, m_cache_server_ip); }else{ - tuple.setServer(m_cache_server_ip); - tuple.setServerId(m_cache_server_idx); - tuple.setClient(m_cache_client_ip); - tuple.setClientId(m_cache_client_idx); - tuple.setClientPort( - m_client_gen->GenerateOnePort(m_cache_client_idx)); + tuple.setServerAll(m_cache_server_idx, + m_cache_server_ip); + tuple.setClientAll2(m_cache_client_idx, + m_cache_client_ip, + m_client_gen->GenerateOnePort(m_cache_client_idx)); } m_cnt++; if (m_cnt>=m_w) { |