Debian Codegraph @

src/ITGSend/traffic.cpp

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 * Component of the D-ITG 2.8.1 (r1023) platform (http://traffic.comics.unina.it/software/ITG)
3 *
4 * Copyright : (C) 2004-2013 by Alessio Botta, Walter de Donato, Alberto Dainotti,
5 * Stefano Avallone, Antonio Pescape' (PI)
6 * COMICS (COMputer for Interaction and CommunicationS) Group
7 * Department of Electrical Engineering and Information Technologies
8 * University of Napoli "Federico II".
9 * email : [email protected], [email protected], [email protected],
10 * [email protected], [email protected]
11 *
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 *
25 * For commercial use please refer to D-ITG Professional.
26 */
27
28
29
30 #include "../common/ITG.h"
31 #include "newran/newran.h"
32
33 #ifdef UNIX
34 #include <netdb.h>
35 #include <sys/wait.h>
36 #include <math.h>
37 #include <netinet/tcp.h>
38 #include <netinet/ip.h>
39 #include <sys/shm.h>
40 #include <pthread.h>
41 #include <sys/msg.h>
42 #include <sys/ipc.h>
43 #endif
44 #ifdef WIN32
45 #include <math.h>
46 #include <sys/timeb.h>
47 #include <time.h>
48 #include <signal.h>
49 #endif
50
51 #include "traffic.h"
52 #include "ITGSend.h"
53
54 const char *DistroStrings[] = { "Constant", "Uniform", "Exponential", "Pareto",
55 "Cauchy", "Normal", "Poisson", "Gamma", "Weibull",
56 "Telnet", "AoM", "Discrete", "Extreme_Largest", "Quake3", "Student", "Counterstrike active", "Counterstrike inactive" };
57
58 const unsigned int DefaultPktPerSec = 1000;
59 const unsigned int DefaultPktSize = 512;
60 const unsigned long DefaultDuration = 10000;
61 const unsigned long DefaultDelay = 0;
62
63
64 Constant *ConstantRV;
65 Uniform *UniformRV;
66 Exponential *ExponentialRV;
67 Pareto *ParetoRV;
68 Cauchy *CauchyRV;
69 Normal *NormalRV;
70 Poisson *PoissonRV;
71 Gamma *GammaRV;
72
73 Weibull *WeibullRV;
74
75 DiscreteGen *DiscreteRV;
76 MixedRandom *MixedRV;
77 Extreme_Largest *Extreme_LargestRV;
78 Student *StudentRV;
79 MixedRandom *Mixed_rv;
80 DiscreteGen *Discrete_rv;
81
82 void telnetParser(SumRandom ** pIntArriv, SumRandom ** pPktSize, TDistro & IntArrivDistro,
83 TDistro & PktSizeDistro)
84 {
85 int numval = 15;
86 Real prob[] =
87 { 0.65, 0.13, 0.07, 0.05, 0.03, 0.01, 0.01, 0.01, 0.01, 0.005, 0.005, 0.005, 0.005,
88 0.005, 0.005 };
89
90 ParetoRV = new Pareto(0.95);
91 IntArrivDistro = pdPareto;
92 delete(*pIntArriv);
93 *pIntArriv = new SumRandom(1.1 * (*ParetoRV));
94
95 PktSizeDistro = pdTelnet;
96 delete(*pPktSize);
97 static DiscreteGen D(numval, prob);
98 *pPktSize = new SumRandom(D + 21);
99 }
100
101 void voIPParser(int h, char *argv[], int &argc, unsigned int flowId, SumRandom ** pIntArriv,
102 SumRandom ** pPktSize, TDistro & IntArrivDistro, TDistro & PktSizeDistro)
103 {
104 char codec[10];
105
106 strcpy(codec, "G.711.1");
107 Real samples = 1.0;
108 Real framesize = 80.0;
109 Real VAD = 1.0;
110 Real header = 12.0;
111 Real pkts = 100.0;
112 argv++;
113 argc--;
114 while (argc > 0) {
115 if (argv[h][0] == '-') {
116 char *tail;
117 switch (argv[h][1]) {
118 case 'x':
119 if (argc < 2)
120 ReportErrorAndExit("VoIP parser", "Invalid Codec Type",
121 programName, flowId);
122 if (strcmp(argv[h + 1], "G.711.1") == 0) {
123 strcpy(codec, "G.711");
124 framesize = 80.0;
125 samples = 1.0;
126 pkts = 100.0;
127 } else if (strcmp(argv[h + 1], "G.711.2") == 0) {
128 strcpy(codec, "G.711");
129 framesize = 80.0;
130 samples = 2.0;
131 pkts = 50.0;
132 } else if (strcmp(argv[h + 1], "G.729.2") == 0) {
133 strcpy(codec, "G.729");
134 framesize = 10.0;
135 samples = 2.0;
136 pkts = 50.0;
137 } else if (strcmp(argv[h + 1], "G.729.3") == 0) {
138 strcpy(codec, "G.729");
139 framesize = 10.0;
140 samples = 3.0;
141 pkts = 33.0;
142 } else if (strcmp(argv[h + 1], "G.723.1") == 0) {
143 strcpy(codec, argv[h + 1]);
144 framesize = 30.0;
145 samples = 1.0;
146 pkts = 26.0;
147 } else
148 ReportErrorAndExit("VoIP parser", "Invalid Codec Type",
149 programName, flowId);
150
151 h += 2;
152 argc -= 2;
153 break;
154 case 'h':
155 if (argc < 2)
156 ReportErrorAndExit("VoIP parser", "Invalid Protocol Type",
157 programName, flowId);
158 if (strcmp(argv[h + 1], "RTP") == 0)
159 header = 12.0;
160 else if (strcmp(argv[h + 1], "CRTP") == 0)
161 header = 2;
162 else
163 ReportErrorAndExit("VoIP parser",
164 "Invalid Protocol Type (RTP or CRTP)", programName,
165 flowId);
166 h += 2;
167 argc -= 2;
168 break;
169 case 'V':
170 if ((argv[h][2] == 'A') && (argv[h][3] == 'D'))
171 VAD = 0.65;
172 else
173 ReportErrorAndExit("VoIP parser", "Invalid Option (VAD)",
174 programName, flowId);
175 h += 1;
176 argc -= 1;
177 break;
178 default:
179 tail = (char *) malloc(sizeof("Unknown option ") + sizeof(argv[0]));
180 ReportErrorAndExit("VoIP parser",
181 strcat(strcpy(tail, "Unknown option "), argv[0]),
182 programName, flowId);
183 break;
184 }
185 } else {
186 char temp[sizeof("What is ?") + sizeof(argv[h])];
187 ReportErrorAndExit("VoIP parser",
188 strcat(strcat(strcpy(temp, "What is "), argv[0]), " ?"),
189 programName, flowId);
190 }
191 }
192 delete(*pPktSize);
193 PktSizeDistro = pdConstant;
194 ConstantRV = new Constant(1);
195 *pPktSize = new SumRandom((VAD * framesize * samples) * (*ConstantRV) + header);
196 delete(*pIntArriv);
197 IntArrivDistro = pdConstant;
198 ConstantRV = new Constant(1);
199 *pIntArriv = new SumRandom(1000.0 / pkts * (*ConstantRV));
200 printf
201 ("Voice Codec: %s\t\nFramesize: %4.2f\t\nSamples: %4.0f\t\nPackets per sec.: %4.0f\t\n",
202 codec, framesize, samples, pkts);
203 if (VAD == 1)
204 printf("VAD: No\n");
205 else
206 printf("VAD: Si\n");
207 }
208
209 void dnsParser(SumRandom ** pIntArriv, SumRandom ** pPktSize, TDistro & IntArrivDistro,
210 TDistro & PktSizeDistro)
211 {
212
213 delete(*pIntArriv);
214 IntArrivDistro = pdConstant;
215 ConstantRV = new Constant(1);
216 *pIntArriv = new SumRandom(1000.0 / 0.56 * (*ConstantRV));
217
218
219 delete(*pPktSize);
220 PktSizeDistro = pdUniform;
221 UniformRV = new Uniform;
222 *pPktSize = new SumRandom(220.0 * (*UniformRV) + 100.0);
223 }
224
225
226
227
228 void CSParsera(SumRandom ** pIntArriv, SumRandom ** pPktSize, TDistro & IntArrivDistro, TDistro & PktSizeDistro){
229
230 delete(*pIntArriv);
231
232 IntArrivDistro = pdStudent;
233 StudentRV = new Student(41.6994, 0.104821, 0.704073);
234 *pIntArriv = new SumRandom(1 * (*StudentRV));
235
236
237 delete(*pPktSize);
238
239 Real prob_PS[2];
240 Random *pDis_PS[2];
241 PktSizeDistro=pdCSa;
242
243 Normal *normal_1=new Normal;
244 SumRandom *normal_11=new SumRandom(34.8352 + (4.3915 * (*normal_1)));
245
246 Normal *normal_2=new Normal;
247 SumRandom *normal_22=new SumRandom(49.4904 + (3.6186 * (*normal_2)));
248
249
250 prob_PS[0]=0.3732;
251 prob_PS[1]=0.6268;
252
253 pDis_PS[0]=(Random*)normal_11;
254 pDis_PS[1]=(Random*)normal_22;
255
256
257 MixedRandom *mix_rv=new MixedRandom(2,prob_PS,pDis_PS);
258
259
260 *pPktSize = new SumRandom(1 * (*mix_rv));
261 }
262
263 void CSParseri(SumRandom ** pIntArriv, SumRandom ** pPktSize, TDistro &
264 IntArrivDistro, TDistro & PktSizeDistro){
265
266 delete(*pIntArriv);
267
268 IntArrivDistro = pdStudent;
269 Student *Student_rv = new Student(41.6858, 0.0694393, 1.08341);
270 *pIntArriv = new SumRandom(1 * (*Student_rv));
271
272
273 delete(*pPktSize);
274
275
276 PktSizeDistro=pdDiscrete;
277
278 Real val[8];
279 Real prob[8];
280
281 val[0]=27;
282 prob[0]=0.8312;
283
284 val[1]=28;
285 prob[1]=0.0018;
286
287 val[2]=29;
288 prob[2]=0.0453;
289
290 val[3]=30;
291 prob[3]=0.0195;
292
293 val[4]=31;
294 prob[4]=0.0879;
295
296 val[5]=32;
297 prob[5]=0.0024;
298
299 val[6]=33;
300 prob[6]=0.0106;
301
302 val[7]=35;
303 prob[7]=0.0013;
304
305 static DiscreteGen P(8,prob,val);
306
307 *pPktSize = new SumRandom(1 * P);
308 }
309
310
311 void QuakeParser(SumRandom ** pIntArriv, SumRandom ** pPktSize, TDistro & IntArrivDistro, TDistro & PktSizeDistro)
312 {
313
314 delete (*pIntArriv);
315 IntArrivDistro=pdQuake;
316 Constant *constant_rv=new Constant(10.75);
317
318 ExponentialRV= new Exponential(4.29);
319
320 Real prob[2];
321
322 prob[0]=0.6;
323 prob[1]=0.4;
324
325 Random *pDis_IAT[2];
326
327 pDis_IAT[0]=(Random*)ExponentialRV;
328 pDis_IAT[1]=(Random*)constant_rv;
329
330 Mixed_rv=new MixedRandom(2,prob,pDis_IAT);
331
332 *pIntArriv = new SumRandom(1 * (*Mixed_rv));
333
334
335 delete (*pPktSize);
336 PktSizeDistro=pdNormal;
337 NormalRV=new Normal;
338 *pPktSize=new SumRandom(3.2035755 * (*NormalRV) + 64.151757);
339
340 }
341
342
343 #ifdef BURSTY
344 void burstyParser(int &h, char *argv[], int &argc, unsigned int flowId, SumRandom ** OnPeriod,
345 SumRandom ** OffPeriod, TDistro & OnPeriodDistro, TDistro & OffPeriodDistro)
346 {
347
348 Real a, b;
349 switch (argv[h][0]) {
350 case 'C':
351 if ((argc < 4) || (strtod(argv[h + 1],NULL) <= 0.))
352 ReportErrorAndExit("Protocol Parser",
353 "Invalid settings for the On/Off periods", programName, flowId);
354 delete (*OnPeriod);
355 OnPeriodDistro = pdConstant;
356 ConstantRV = new Constant(1);
357 *OnPeriod = new SumRandom(atoi(argv[h + 1]) * (*ConstantRV));
358 h += 2;
359 argc -= 2;
360 break;
361 case 'U':
362 if ((argc < 5) || (strtod(argv[h+1],NULL) <= 0.)
363 || (strtod(argv[h+2],NULL) <= strtod(argv[h+1],NULL)) )
364 ReportErrorAndExit("Protocol Parser",
365 "Invalid settings for the On/Off periods", programName, flowId);
366 delete (*OnPeriod);
367 OnPeriodDistro = pdUniform;
368 a = strtod(argv[h+2],NULL);
369 b = strtod(argv[h+1],NULL) - a ;
370 UniformRV = new Uniform;
371 *OnPeriod = new SumRandom( b * (*UniformRV) + a);
372 h += 3;
373 argc -= 3;
374 break;
375 case 'E':
376 if ((argc < 4) || (strtod(argv[h+1],NULL) <= 0.))
377 ReportErrorAndExit("Protocol Parser",
378 "Invalid settings for the On/Off periods", programName, flowId);
379 delete (*OnPeriod);
380 OnPeriodDistro = pdExponential;
381 ExponentialRV = new Exponential;
382 *OnPeriod =
383 new SumRandom(strtod(argv[h+1],NULL) * (*ExponentialRV));
384 h += 2;
385 argc -= 2;
386 break;
387 case 'V':
388 if ((argc < 5) || (strtod(argv[h + 1], NULL) <= 0)
389 || (strtod(argv[h + 2], NULL) <= 0))
390 ReportErrorAndExit("Protocol Parser",
391 "Invalid settings for the On/Off periods", programName, flowId);
392 a = (Real) strtod(argv[h + 1], NULL);
393 b = (Real) strtod(argv[h + 2], NULL);
394 ParetoRV = new Pareto(a);
395 delete (*OnPeriod);
396 OnPeriodDistro = pdPareto;
397 *OnPeriod = new SumRandom(b * (*ParetoRV));
398 h += 3;
399 argc -= 3;
400 break;
401 case 'Y':
402 if ((argc < 5) || (strtod(argv[h + 2], NULL) <= 0))
403 ReportErrorAndExit("Protocol Parser",
404 "Invalid settings for the On/Off periods", programName, flowId);
405 b = strtod(argv[h + 1], NULL);
406 a = strtod(argv[h + 2], NULL);
407 CauchyRV = new Cauchy;
408 delete (*OnPeriod);
409 OnPeriodDistro = pdCauchy;
410 *OnPeriod = new SumRandom(a * (*CauchyRV) + b);
411 h += 3;
412 argc -= 3;
413 break;
414 case 'N':
415 if ((argc < 5) || (argv[h + 2] <= 0))
416 ReportErrorAndExit("Protocol Parser",
417 "Invalid settings for the On/Off periods", programName, flowId);
418 b = strtod(argv[h + 1], NULL);
419 a = strtod(argv[h + 2], NULL);
420 delete (*OnPeriod);
421 OnPeriodDistro = pdNormal;
422 NormalRV = new Normal;
423 *OnPeriod = new SumRandom(a * (*NormalRV) + b);
424 h += 3;
425 argc -= 3;
426 break;
427 case 'O':
428 if ((argc < 4) || (strtod(argv[h + 1], NULL) <= 0))
429 ReportErrorAndExit("Protocol Parser",
430 "Invalid settings for the On/Off periods", programName, flowId);
431 a = strtod(argv[h + 1], NULL);
432 delete (*OnPeriod);
433
434 PoissonRV = new Poisson(a);
435 OnPeriodDistro = pdPoisson;
436 *OnPeriod = new SumRandom( 1 * (*PoissonRV));
437 h += 2;
438 argc -= 2;
439 break;
440 case 'G':
441 if ((argc < 5) || (strtod(argv[h + 1], NULL) <= 0) || (strtod(argv[h + 2], NULL) <= 0))
442 ReportErrorAndExit("Protocol Parser",
443 "Invalid settings for the On/Off periods", programName, flowId);
444 a = (Real) strtod(argv[h + 1], NULL);
445 b = (Real) strtod(argv[h + 2], NULL);
446 delete (*OnPeriod);
447
448 GammaRV = new Gamma(a);
449 OnPeriodDistro = pdGamma;
450 *OnPeriod = new SumRandom(b * (*GammaRV));
451 h += 3;
452 argc -= 3;
453 break;
454 case 'W':
455 if ((argc < 5) || (strtod(argv[h + 1], NULL) <= 0) ||
456 (strtod(argv[h + 2], NULL) <= 0))
457 ReportErrorAndExit("Protocol Parser",
458 "Invalid settings for the On/Off periods", programName, flowId);
459 a = (Real) strtod(argv[h+1],NULL);
460 b = (Real) strtod(argv[h+2],NULL);
461 delete (*OnPeriod);
462 WeibullRV = new Weibull(a,b);
463 OnPeriodDistro = pdWeibull;
464 *OnPeriod = new SumRandom( 1 * (*WeibullRV));
465 h += 3;
466 argc -= 3;
467 break;
468 default:
469 ReportErrorAndExit("Protocol Parser",
470 "Invalid settings for the On/Off periods", programName, flowId);
471 break;
472 }
473
474
475 switch (argv[h][0]) {
476 case 'C':
477 if ((argc < 2) || (strtod(argv[h + 1],NULL) <= 0.))
478 ReportErrorAndExit("Protocol Parser",
479 "Invalid settings for the Off/Off periods", programName, flowId);
480 delete (*OffPeriod);
481 OffPeriodDistro = pdConstant;
482 ConstantRV = new Constant(1);
483 *OffPeriod = new SumRandom(atoi(argv[h + 1]) * (*ConstantRV));
484 h += 2;
485 argc -= 2;
486 break;
487 case 'U':
488 if ((argc < 3) || (strtod(argv[h+1],NULL) <= 0.)
489 || (strtod(argv[h+2],NULL) <= strtod(argv[h+1],NULL)) )
490 ReportErrorAndExit("Protocol Parser",
491 "Invalid settings for the Off/Off periods", programName, flowId);
492 delete (*OffPeriod);
493 OffPeriodDistro = pdUniform;
494 a = strtod(argv[h+2],NULL);
495 b = strtod(argv[h+1],NULL) - a ;
496 UniformRV = new Uniform;
497 *OffPeriod = new SumRandom( b * (*UniformRV) + a);
498 h += 3;
499 argc -= 3;
500 break;
501 case 'E':
502 if ((argc < 2) || (strtod(argv[h+1],NULL) <= 0.))
503 ReportErrorAndExit("Protocol Parser",
504 "Invalid settings for the Off/Off periods", programName, flowId);
505 delete (*OffPeriod);
506 OffPeriodDistro = pdExponential;
507 ExponentialRV = new Exponential;
508 *OffPeriod =
509 new SumRandom(strtod(argv[h+1],NULL) * (*ExponentialRV));
510 h += 2;
511 argc -= 2;
512 break;
513 case 'V':
514 if ((argc < 3) || (strtod(argv[h + 1], NULL) <= 0)
515 || (strtod(argv[h + 2], NULL) <= 0))
516 ReportErrorAndExit("Protocol Parser",
517 "Invalid settings for the Off/Off periods", programName, flowId);
518 a = (Real) strtod(argv[h + 1], NULL);
519 b = (Real) strtod(argv[h + 2], NULL);
520 ParetoRV = new Pareto(a);
521 delete (*OffPeriod);
522 OffPeriodDistro = pdPareto;
523 *OffPeriod = new SumRandom(b * (*ParetoRV));
524 h += 3;
525 argc -= 3;
526 break;
527 case 'Y':
528 if ((argc < 3) || (strtod(argv[h + 2], NULL) <= 0))
529 ReportErrorAndExit("Protocol Parser",
530 "Invalid settings for the Off/Off periods", programName, flowId);
531 b = strtod(argv[h + 1], NULL);
532 a = strtod(argv[h + 2], NULL);
533 CauchyRV = new Cauchy;
534 delete (*OffPeriod);
535 OffPeriodDistro = pdCauchy;
536 *OffPeriod = new SumRandom(a * (*CauchyRV) + b);
537 h += 3;
538 argc -= 3;
539 break;
540 case 'N':
541 if ((argc < 3) || (argv[h + 2] <= 0))
542 ReportErrorAndExit("Protocol Parser",
543 "Invalid settings for the Off/Off periods", programName, flowId);
544 b = strtod(argv[h + 1], NULL);
545 a = strtod(argv[h + 2], NULL);
546 delete (*OffPeriod);
547 OffPeriodDistro = pdNormal;
548 NormalRV = new Normal;
549 *OffPeriod = new SumRandom(a * (*NormalRV) + b);
550 h += 3;
551 argc -= 3;
552 break;
553 case 'O':
554 if ((argc < 2) || (strtod(argv[h + 1], NULL) <= 0))
555 ReportErrorAndExit("Protocol Parser",
556 "Invalid settings for the Off/Off periods", programName, flowId);
557 a = strtod(argv[h + 1], NULL);
558 delete (*OffPeriod);
559
560 PoissonRV = new Poisson(a);
561 OffPeriodDistro = pdPoisson;
562 *OffPeriod = new SumRandom( 1 * (*PoissonRV));
563 h += 2;
564 argc -= 2;
565 break;
566 case 'G':
567 if ((argc < 3) || (strtod(argv[h + 1], NULL) <= 0) || (strtod(argv[h + 2], NULL) <= 0))
568 ReportErrorAndExit("Protocol Parser",
569 "Invalid settings for the Off/Off periods", programName, flowId);
570 a = (Real) strtod(argv[h + 1], NULL);
571 b = (Real) strtod(argv[h + 2], NULL);
572 delete (*OffPeriod);
573
574 GammaRV = new Gamma(a);
575 OffPeriodDistro = pdGamma;
576 *OffPeriod = new SumRandom(b * (*GammaRV));
577 h += 3;
578 argc -= 3;
579 break;
580 case 'W':
581 if ((argc < 3) || (strtod(argv[h + 1], NULL) <= 0) ||
582 (strtod(argv[h + 2], NULL) <= 0))
583 ReportErrorAndExit("Protocol Parser",
584 "Invalid settings for the On/Off periods", programName, flowId);
585 a = (Real) strtod(argv[h+1],NULL);
586 b = (Real) strtod(argv[h+2],NULL);
587 delete (*OffPeriod);
588 WeibullRV = new Weibull(a,b);
589 OffPeriodDistro = pdWeibull;
590 *OffPeriod = new SumRandom( 1 * (*WeibullRV));
591 h += 3;
592 argc -= 3;
593 break;
594 default:
595 ReportErrorAndExit("Protocol Parser",
596 "Invalid settings for the On/Off periods", programName, flowId);
597 break;
598 }
599
600
601 }
602 #endif
603