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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
/*
Hanoh Haim
Cisco Systems, Inc.
*/
/*
Copyright (c) 2015-2015 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.
*/
#include "bp_sim.h"
#include <common/gtest.h>
#include <common/basic_utils.h>
#define EXPECT_EQ_UINT32(a,b) EXPECT_EQ((uint32_t)(a),(uint32_t)(b))
// one stream info with const packet , no VM
class CTRexDpStatelessVM {
};
//- add dump function
// - check one object
// create frame work
class CTRexDpStreamModeContinues{
public:
void set_pps(double pps){
m_pps=pps;
}
double get_pps(){
return (m_pps);
}
void dump(FILE *fd);
private:
double m_pps;
};
void CTRexDpStreamModeContinues::dump(FILE *fd){
fprintf (fd," pps : %f \n",m_pps);
}
class CTRexDpStreamModeSingleBurst{
public:
void set_pps(double pps){
m_pps=pps;
}
double get_pps(){
return (m_pps);
}
void set_total_packets(uint64_t total_packets){
m_total_packets =total_packets;
}
uint64_t get_total_packets(){
return (m_total_packets);
}
void dump(FILE *fd);
private:
double m_pps;
uint64_t m_total_packets;
};
void CTRexDpStreamModeSingleBurst::dump(FILE *fd){
fprintf (fd," pps : %f \n",m_pps);
fprintf (fd," total_packets : %llu \n",m_total_packets);
}
class CTRexDpStreamModeMultiBurst{
public:
void set_pps(double pps){
m_pps=pps;
}
double get_pps(){
return (m_pps);
}
void set_pkts_per_burst(uint64_t pkts_per_burst){
m_pkts_per_burst =pkts_per_burst;
}
uint64_t get_pkts_per_burst(){
return (m_pkts_per_burst);
}
void set_ibg(double ibg){
m_ibg = ibg;
}
double get_ibg(){
return ( m_ibg );
}
void set_number_of_bursts(uint32_t number_of_bursts){
m_number_of_bursts = number_of_bursts;
}
uint32_t get_number_of_bursts(){
return (m_number_of_bursts);
}
void dump(FILE *fd);
private:
double m_pps;
double m_ibg; // inter burst gap
uint64_t m_pkts_per_burst;
uint32_t m_number_of_bursts;
};
void CTRexDpStreamModeMultiBurst::dump(FILE *fd){
fprintf (fd," pps : %f \n",m_pps);
fprintf (fd," total_packets : %llu \n",m_pkts_per_burst);
fprintf (fd," ibg : %f \n",m_ibg);
fprintf (fd," num_of_bursts : %llu \n",m_number_of_bursts);
}
class CTRexDpStreamMode {
public:
enum MODES {
moCONTINUES = 0x0,
moSINGLE_BURST = 0x1,
moMULTI_BURST = 0x2
} ;
typedef uint8_t MODE_TYPE_t;
void reset();
void set_mode(MODE_TYPE_t mode ){
m_type = mode;
}
MODE_TYPE_t get_mode(){
return (m_type);
}
CTRexDpStreamModeContinues & cont(void){
return (m_data.m_cont);
}
CTRexDpStreamModeSingleBurst & single_burst(void){
return (m_data.m_signle_burst);
}
CTRexDpStreamModeMultiBurst & multi_burst(void){
return (m_data.m_multi_burst);
}
void dump(FILE *fd);
private:
uint8_t m_type;
union Data {
CTRexDpStreamModeContinues m_cont;
CTRexDpStreamModeSingleBurst m_signle_burst;
CTRexDpStreamModeMultiBurst m_multi_burst;
} m_data;
};
void CTRexDpStreamMode::reset(){
m_type =CTRexDpStreamMode::moCONTINUES;
memset(&m_data,0,sizeof(m_data));
}
void CTRexDpStreamMode::dump(FILE *fd){
const char * table[3] = {"CONTINUES","SINGLE_BURST","MULTI_BURST"};
fprintf(fd," mode : %s \n", (char*)table[m_type]);
switch (m_type) {
case CTRexDpStreamMode::moCONTINUES :
cont().dump(fd);
break;
case CTRexDpStreamMode::moSINGLE_BURST :
single_burst().dump(fd);
break;
case CTRexDpStreamMode::moMULTI_BURST :
multi_burst().dump(fd);
break;
default:
fprintf(fd," ERROR type if not valid %d \n",m_type);
break;
}
}
class CTRexDpStatelessStream {
public:
enum FLAGS_0{
_ENABLE = 0,
_SELF_START = 1,
_VM_ENABLE =2,
_END_STREAM =-1
};
CTRexDpStatelessStream(){
reset();
}
void reset(){
m_packet =0;
m_vm=0;
m_flags=0;
m_isg_sec=0.0;
m_next_stream = CTRexDpStatelessStream::_END_STREAM ; // END
m_mode.reset();
}
void set_enable(bool enable){
btSetMaskBit32(m_flags,_ENABLE,_ENABLE,enable?1:0);
}
bool get_enabled(){
return (btGetMaskBit32(m_flags,_ENABLE,_ENABLE)?true:false);
}
void set_self_start(bool enable){
btSetMaskBit32(m_flags,_SELF_START,_SELF_START,enable?1:0);
}
bool get_self_start(bool enable){
return (btGetMaskBit32(m_flags,_SELF_START,_SELF_START)?true:false);
}
/* if we don't have VM we could just replicate the mbuf and allocate it once */
void set_vm_enable(bool enable){
btSetMaskBit32(m_flags,_VM_ENABLE,_VM_ENABLE,enable?1:0);
}
bool get_vm_enabled(bool enable){
return (btGetMaskBit32(m_flags,_VM_ENABLE,_VM_ENABLE)?true:false);
}
void set_inter_stream_gap(double isg_sec){
m_isg_sec =isg_sec;
}
double get_inter_stream_gap(){
return (m_isg_sec);
}
CTRexDpStreamMode & get_mode();
// CTRexDpStatelessStream::_END_STREAM for END
void set_next_stream(int32_t next_stream){
m_next_stream =next_stream;
}
int32_t get_next_stream(void){
return ( m_next_stream );
}
void dump(FILE *fd);
private:
char * m_packet;
CTRexDpStatelessVM * m_vm;
uint32_t m_flags;
double m_isg_sec; // in second
CTRexDpStreamMode m_mode;
int32_t m_next_stream; // next stream id
};
//- list of streams info with const packet , no VM
// - object that include the stream /scheduler/ packet allocation / need to create an object for one thread that works for test
// generate pcap file and compare it
void CTRexDpStatelessStream::dump(FILE *fd){
fprintf(fd," enabled : %d \n",get_enabled()?1:0);
fprintf(fd," self_start : %d \n",get_self_start()?1:0);
fprintf(fd," vm : %d \n",get_vm_enabled()?1:0);
fprintf(" isg : %f \n",m_isg_sec);
m_mode.dump(fd);
if (m_next_stream == CTRexDpStatelessStream::_END_STREAM ) {
fprintf(fd," action : End of Stream \n");
}else{
fprintf(" next : %d \n",m_next_stream);
}
}
class CTRexStatelessBasic {
public:
CTRexStatelessBasic(){
m_threads=1;
}
bool init(void){
return (true);
}
public:
bool m_threads;
};
/* stateless basic */
class dp_sl_basic : public testing::Test {
protected:
virtual void SetUp() {
}
virtual void TearDown() {
}
public:
};
TEST_F(dp_sl_basic, test1) {
CTRexDpStatelessStream s1;
s1.set_enable(true);
s1.set_self_start(true);
s1.set_inter_stream_gap(0.77);
s1.get_mode().set_mode(CTRexDpStreamMode::moCONTINUES);
s1.get_mode().cont().set_pps(100.2);
s1.dump(stdout);
}
|