summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorwenxian li <wenxianl@cisco.com>2015-10-01 22:29:46 -0400
committerwenxian li <wenxianl@cisco.com>2015-10-01 22:29:46 -0400
commit894ec2ddcd9965f60c4bc7a0b48edf41bfc167d8 (patch)
treebe4c2a0a5be24c28d7666b29718877616fa20225 /src
parentdbeb7ecc059bb78db54ec285a4216a661bbedd23 (diff)
Code change according to code review comments after Tuple Generator phase 2 commit.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/bp_sim.cpp28
-rwxr-xr-xsrc/bp_sim.h5
-rwxr-xr-xsrc/gtest/tuple_gen_test.cpp2
-rwxr-xr-xsrc/tuple_gen.cpp14
-rwxr-xr-xsrc/tuple_gen.h104
5 files changed, 98 insertions, 55 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..fd5e9a9a 100755
--- a/src/gtest/tuple_gen_test.cpp
+++ b/src/gtest/tuple_gen_test.cpp
@@ -334,7 +334,7 @@ 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;
diff --git a/src/tuple_gen.cpp b/src/tuple_gen.cpp
index e408f275..d725de44 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);
@@ -130,13 +130,13 @@ bool CTupleGeneratorSmart::add_client_pool(IP_DIST_t client_dist,
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, has_mac_mapping,
tcp_aging, udp_aging);
m_client_pool.push_back(pool);
diff --git a/src/tuple_gen.h b/src/tuple_gen.h
index fb856538..8efa07a4 100755
--- a/src/tuple_gen.h
+++ b/src/tuple_gen.h
@@ -99,6 +99,47 @@ typedef struct mac_mapping_ {
#define TYPE2 1
#define MAX_TYPE 3
+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 get_mac_info_cnt(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 (get_mac_info_cnt(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*/
+};
class CIpInfoBase {
public:
@@ -113,7 +154,7 @@ class CIpInfoBase {
void set_ip(uint32_t ip) {
m_ip = ip;
}
- public:
+ private:
uint32_t m_ip;
};
@@ -254,6 +295,7 @@ class CClientInfo : public CIpInfo {
~CClientInfo() {
if (m_mac!=NULL){
delete m_mac;
+ m_mac=NULL;
}
}
private:
@@ -282,6 +324,7 @@ public:
~CClientInfoL() {
if (m_mac!=NULL) {
delete m_mac;
+ m_mac=NULL;
}
}
private:
@@ -350,6 +393,31 @@ public:
m_client_mac.inused = UNUSED;
}
}
+ void setClientAll(uint32_t id, uint32_t ip,mac_addr_align_t*mac,uint16_t port) {
+ setClientId(id);
+ 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;
@@ -362,10 +430,6 @@ private:
-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:
@@ -493,10 +557,10 @@ 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));
+ tuple.setClientAll(idx,
+ get_ip(idx),
+ get_mac(idx),
+ GenerateOnePort(idx));
}
uint16_t get_tcp_aging() {
return m_tcp_aging;
@@ -509,7 +573,7 @@ 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);
@@ -571,8 +635,7 @@ 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,6 +650,7 @@ public:
if (gen!=NULL) {
gen->Delete();
delete gen;
+ gen=NULL;
}
}
uint32_t get_total_ips() {
@@ -672,7 +736,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,
@@ -718,15 +782,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) {