1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
/*
Copyright (c) 2017-2017 Cisco Systems, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _BP_GTEST_H_
#define _BP_GTEST_H_
#define EXPECT_EQ_UINT32(a,b) EXPECT_EQ((uint32_t)(a),(uint32_t)(b))
class trexTest : public testing::Test {
protected:
virtual void SetUp() {
CGlobalInfo::m_options.reset();
}
virtual void TearDown() {
}
public:
};
class CTestBasic {
public:
CTestBasic() {
m_threads=1;
m_time_diff=0.001;
m_req_ports=0;
m_dump_json=false;
}
bool init(void) {
uint16 * ports = NULL;
CTupleBase tuple;
CErfIF erf_vif;
fl.Create();
m_saved_packet_padd_offset=0;
fl.load_from_yaml(CGlobalInfo::m_options.cfg_file,m_threads);
if (CGlobalInfo::m_options.client_cfg_file != "") {
try {
fl.load_client_config_file(CGlobalInfo::m_options.client_cfg_file);
// The simulator only test MAC address configs, so this parameter is not used
CManyIPInfo pretest_result;
fl.set_client_config_resolved_macs(pretest_result);
} catch (const std::runtime_error &e) {
std::cout << "\n*** " << e.what() << "\n\n";
exit(-1);
}
CGlobalInfo::m_options.preview.set_client_cfg_enable(true);
}
fl.generate_p_thread_info(m_threads);
fl.m_threads_info[0]->set_vif(&erf_vif);
CErfCmp cmp;
cmp.dump = 1;
bool res = true;
int i;
CFlowGenListPerThread * lpt;
for (i=0; i<m_threads; i++) {
lpt=fl.m_threads_info[i];
CFlowPktInfo * pkt=lpt->m_cap_gen[0]->m_flow_info->GetPacket(0);
m_saved_packet_padd_offset = pkt->m_pkt_indication.m_packet_padding;
char buf[100];
char buf_ex[100];
sprintf(buf,"%s-%d.erf", CGlobalInfo::m_options.out_file.c_str(), i);
sprintf(buf_ex,"%s-%d-ex.erf", CGlobalInfo::m_options.out_file.c_str(), i);
if ( m_req_ports ) {
/* generate from first template m_req_ports ports */
int i;
CTupleTemplateGeneratorSmart * lpg=&lpt->m_cap_gen[0]->tuple_gen;
ports = new uint16_t[m_req_ports];
lpg->GenerateTuple(tuple);
for (i=0 ; i<m_req_ports;i++) {
ports[i]=lpg->GenerateOneSourcePort();
}
}
CGlobalInfo::m_options.m_run_mode = CParserOption::RUN_MODE_BATCH;
lpt->start_generate_stateful(buf,CGlobalInfo::m_options.preview);
lpt->m_node_gen.DumpHist(stdout);
cmp.d_sec = m_time_diff;
//compare generated file to expected file
if ( cmp.compare(std::string(buf), std::string(buf_ex)) != true ) {
res=false;
}
}
if ( m_dump_json ) {
printf(" dump json ...........\n");
std::string s;
fl.m_threads_info[0]->m_node_gen.dump_json(s);
printf(" %s \n",s.c_str());
}
if ( m_req_ports ) {
int i;
fl.m_threads_info[0]->m_smart_gen.FreePort(0, tuple.getClientId(),tuple.getClientPort());
for (i=0 ; i < m_req_ports; i++) {
fl.m_threads_info[0]->m_smart_gen.FreePort(0,tuple.getClientId(),ports[i]);
}
delete []ports;
}
printf(" active %d \n", fl.m_threads_info[0]->m_smart_gen.ActiveSockets());
EXPECT_EQ_UINT32(fl.m_threads_info[0]->m_smart_gen.ActiveSockets(),0);
fl.Delete();
return (res);
}
uint16_t get_padd_offset_first_packet() {
return (m_saved_packet_padd_offset);
}
public:
int m_req_ports;
int m_threads;
double m_time_diff;
bool m_dump_json;
uint16_t m_saved_packet_padd_offset;
CFlowGenList fl;
};
#endif
|