| 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 |
#include <fcntl.h> |
| 30 |
#include <math.h> |
| 31 |
#include <string.h> |
| 32 |
#include <stdlib.h> |
| 33 |
#include <stdio.h> |
| 34 |
#include <fstream> |
| 35 |
#include <iostream> |
| 36 |
#include "../common/debug.h" |
| 37 |
#include "../common/ITG.h" |
| 38 |
|
| 39 |
using namespace std; |
| 40 |
|
| 41 |
#ifdef V23 |
| 42 |
#define ADDRESSLEN 16 |
| 43 |
#else |
| 44 |
#if V21 |
| 45 |
#pragma pack(1) |
| 46 |
#define ADDRESSLEN 15 |
| 47 |
#else |
| 48 |
#define ADDRESSLEN 46 |
| 49 |
#endif |
| 50 |
#endif |
| 51 |
|
| 52 |
#define MaxNumFlow 1000 |
| 53 |
#define fileNameSize 200 |
| 54 |
|
| 55 |
typedef char address[ADDRESSLEN]; |
| 56 |
|
| 57 |
struct stflowinfo { |
| 58 |
unsigned int flowId; |
| 59 |
double byterecv; |
| 60 |
unsigned long int pktrecv; |
| 61 |
double avdelay; |
| 62 |
double delvariation; |
| 63 |
double secfirstline; |
| 64 |
double seclastline; |
| 65 |
double maxdelay; |
| 66 |
double mindelay; |
| 67 |
address srcaddress; |
| 68 |
unsigned int srcport; |
| 69 |
address destaddress; |
| 70 |
unsigned int destport; |
| 71 |
double lastdelay; |
| 72 |
double avjitter; |
| 73 |
unsigned long int pktloss; |
| 74 |
unsigned int lastpktnum; |
| 75 |
unsigned int pktdup; |
| 76 |
unsigned int maxSeq; |
| 77 |
unsigned int minSeq; |
| 78 |
unsigned int lossEvents; |
| 79 |
}; |
| 80 |
|
| 81 |
struct gestioneFileLog { |
| 82 |
unsigned int flowId; |
| 83 |
unsigned int srcPort; |
| 84 |
unsigned int destPort; |
| 85 |
address destAddr; |
| 86 |
address srcAddr; |
| 87 |
ofstream FileId; |
| 88 |
FILE *tempfile; |
| 89 |
FILE *tempfile_bit; |
| 90 |
FILE *tempfile_jit; |
| 91 |
FILE *tempfile_del; |
| 92 |
FILE *tempfile_pkt; |
| 93 |
char FileName[fileNameSize]; |
| 94 |
char FileNWE[fileNameSize]; |
| 95 |
}; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
double deltatime(double time1, double time2); |
| 114 |
ofstream *FlowPresent(unsigned int flowId, char *destAddr, char *srcAddr, unsigned int srcPort, unsigned int destPort); |
| 115 |
struct info *readline(ifstream *fbin, FILE *ftxt, int filetype); |
| 116 |
struct info* found(unsigned int flowId, char *srcAddr, char *destAddr, unsigned int srcPort, unsigned int destPort, unsigned int seqNum); |
| 117 |
void split(); |
| 118 |
void writeline(int filetype); |
| 119 |
void printhelp(); |
| 120 |
void setline(double txTime, double rxTime); |
| 121 |
void elabsplit(int flagbit, int flagjit, int flagdel, int flagpkt); |
| 122 |
void merge(int type); |
| 123 |
void mergeCombined(); |
| 124 |
void mark(); |
| 125 |
|
| 126 |
|
| 127 |
ifstream inbin; |
| 128 |
ofstream outbin; |
| 129 |
ifstream sendlog; |
| 130 |
FILE *intxt; |
| 131 |
FILE *outtxt; |
| 132 |
int size, flagfilter, flagwinlin; |
| 133 |
unsigned int flownum; |
| 134 |
double msbitrate, msjitter, mspktloss, msdelay, mscombinedstats, secfirstline_gl; |
| 135 |
gestioneFileLog memFile[MaxNumFlow]; |
| 136 |
struct stflowinfo *flowinfo = (struct stflowinfo *) malloc(sizeof(struct stflowinfo)); |
| 137 |
struct info *infos = (struct info *) malloc(sizeof(struct info)); |
| 138 |
|
| 139 |
char senderlogname[fileNameSize]; |
| 140 |
|
| 141 |
char bitratefile[fileNameSize] = "bitrate.dat"; |
| 142 |
char jitterfile[fileNameSize] = "jitter.dat"; |
| 143 |
char pktlossfile[fileNameSize] = "packetloss.dat"; |
| 144 |
char delayfile[fileNameSize] = "delay.dat"; |
| 145 |
char combinedstatsfile[fileNameSize] = "combined_stats.dat"; |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
int main(int argc, char *argv[]) |
| 150 |
{ |
| 151 |
|
| 152 |
|
| 153 |
FILE *octavefpout = 0; |
| 154 |
FILE *delayfpout = 0; |
| 155 |
FILE *jitterfpout = 0; |
| 156 |
char loginname[fileNameSize]; |
| 157 |
char userstring[10]; |
| 158 |
char logoutname[fileNameSize]; |
| 159 |
char octavename[fileNameSize]; |
| 160 |
char delayfpname[fileNameSize]; |
| 161 |
char jitterfpname[fileNameSize]; |
| 162 |
double sectxTime = 0, secrxTime = 0, avjitter = 0, lastdelay = 0, avdelay = 0, delvariation = 0; |
| 163 |
int flagdelay = 0, flagjitter = 0, flagbitrate = 0, flagpktloss = 0, flagcombinedstats = 0, elab_type = 0; |
| 164 |
int flaglogout = 0, flagsplit = 0, flagps = 0, flagidt = 0; |
| 165 |
int flagoctave = 0, flagfirstline = 0, flagreconstruct = 0, flageachdj = 0; |
| 166 |
int logintype = 0, logouttype = 0, errornum = 0, i = 0; |
| 167 |
unsigned long int pkterr = 0, pktvalid = 0; |
| 168 |
unsigned int flownumsel = 0, z = 0; |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
flagdelay = 0; |
| 174 |
flagjitter = 0; |
| 175 |
flagbitrate = 0; |
| 176 |
flagpktloss = 0; |
| 177 |
flagcombinedstats = 0; |
| 178 |
elab_type = 0; |
| 179 |
flaglogout = 0; |
| 180 |
flagoctave = 0; |
| 181 |
flagfilter = 0; |
| 182 |
flagsplit = 0; |
| 183 |
flagidt = 0; |
| 184 |
flagps = 0; |
| 185 |
flagreconstruct = 0; |
| 186 |
flagwinlin = 0; |
| 187 |
flageachdj = 0; |
| 188 |
flownum = 0; |
| 189 |
pkterr = 0; |
| 190 |
pktvalid = 0; |
| 191 |
logintype = 0; |
| 192 |
logouttype = 0; |
| 193 |
flagfirstline = 1; |
| 194 |
avjitter = 0; |
| 195 |
secfirstline_gl = 90000; |
| 196 |
avdelay = 0; |
| 197 |
delvariation = 0; |
| 198 |
|
| 199 |
printVersion("ITGDec"); |
| 200 |
|
| 201 |
|
| 202 |
if (argc <= 1) { |
| 203 |
printf("\nMissing filename!!!\nTry ITGDec -h or --help for more informations\n"); |
| 204 |
exit(1); |
| 205 |
} else if (argv[1][0] == '-' && (argv[1][1] == 'h' || argv[1][1] == '-')) { |
| 206 |
printhelp(); |
| 207 |
exit(1); |
| 208 |
} |
| 209 |
strncpy(loginname, argv[1], fileNameSize); |
| 210 |
argv += 2; |
| 211 |
argc -= 2; |
| 212 |
while (argc > 0) { |
| 213 |
if (argv[0][0] == '-') { |
| 214 |
if (argv[0][1] == '\0') { |
| 215 |
printf("Invalid option!!\n"); |
| 216 |
printf("Use -h or --help for usage\n"); |
| 217 |
exit(1); |
| 218 |
} else { |
| 219 |
switch (argv[0][1]) { |
| 220 |
case 'd': |
| 221 |
if ((argc < 2) || (argv[1][0] == '-')) { |
| 222 |
printf("Error 1 on delay time\n"); |
| 223 |
argc -= 1; |
| 224 |
argv += 1; |
| 225 |
} else { |
| 226 |
msdelay = (double) atof(argv[1]); |
| 227 |
if (msdelay <= 0) { |
| 228 |
printf("Error 2 on delay time\n"); |
| 229 |
exit(1); |
| 230 |
} else { |
| 231 |
|
| 232 |
|
| 233 |
flagdelay = 1; |
| 234 |
argv += 2; |
| 235 |
argc -= 2; |
| 236 |
} |
| 237 |
if (argc && argv[0][0] != '-') { |
| 238 |
strncpy(delayfile, argv[0], fileNameSize); |
| 239 |
argc--; |
| 240 |
argv++; |
| 241 |
} |
| 242 |
} |
| 243 |
break; |
| 244 |
case 'b': |
| 245 |
if ((argc < 2) || (argv[1][0] == '-')) { |
| 246 |
printf("Error 1 on bitrate time\n"); |
| 247 |
argc -= 1; |
| 248 |
argv += 1; |
| 249 |
} else { |
| 250 |
msbitrate = (double) atof(argv[1]); |
| 251 |
if (msbitrate <= 0) { |
| 252 |
printf("Error 2 on bitrate time\n"); |
| 253 |
exit(1); |
| 254 |
} else { |
| 255 |
flagbitrate = 1; |
| 256 |
argv += 2; |
| 257 |
argc -= 2; |
| 258 |
} |
| 259 |
if (argc && argv[0][0] != '-') { |
| 260 |
strncpy(bitratefile, argv[0], fileNameSize); |
| 261 |
argc--; |
| 262 |
argv++; |
| 263 |
} |
| 264 |
} |
| 265 |
break; |
| 266 |
case 'j': |
| 267 |
if ((argc < 2) || (argv[1][0] == '-')) { |
| 268 |
printf("Error 1 on jitter time\n"); |
| 269 |
argc -= 1; |
| 270 |
argv += 1; |
| 271 |
} else { |
| 272 |
msjitter = (double) atof(argv[1]); |
| 273 |
if (msjitter <= 0) { |
| 274 |
printf("Error 2 on jitter time\n"); |
| 275 |
exit(1); |
| 276 |
} else { |
| 277 |
flagjitter = 1; |
| 278 |
argv += 2; |
| 279 |
argc -= 2; |
| 280 |
} |
| 281 |
if (argc && argv[0][0] != '-') { |
| 282 |
strncpy(jitterfile, argv[0], fileNameSize); |
| 283 |
argc--; |
| 284 |
argv++; |
| 285 |
} |
| 286 |
} |
| 287 |
break; |
| 288 |
case 'p': |
| 289 |
if ((argc < 2) || (argv[1][0] == '-')) { |
| 290 |
printf("Error 1 on packet loss time\n"); |
| 291 |
argc -= 1; |
| 292 |
argv += 1; |
| 293 |
} else { |
| 294 |
mspktloss = (double) atof(argv[1]); |
| 295 |
if (mspktloss <= 0) { |
| 296 |
printf("Error 2 on packet loss time\n"); |
| 297 |
exit(1); |
| 298 |
} else { |
| 299 |
flagpktloss = 1; |
| 300 |
argv += 2; |
| 301 |
argc -= 2; |
| 302 |
} |
| 303 |
if (argc && argv[0][0] != '-') { |
| 304 |
strncpy(pktlossfile, argv[0], fileNameSize); |
| 305 |
argc--; |
| 306 |
argv++; |
| 307 |
} |
| 308 |
} |
| 309 |
break; |
| 310 |
case 'c': |
| 311 |
if ((argc < 2) || (argv[1][0] == '-')) { |
| 312 |
printf("Error 1 on interval value\n"); |
| 313 |
argc -= 1; |
| 314 |
argv += 1; |
| 315 |
} else { |
| 316 |
mscombinedstats = (double) atof(argv[1]); |
| 317 |
if (mscombinedstats <= 0) { |
| 318 |
printf("Error 2 on interval value\n"); |
| 319 |
exit(1); |
| 320 |
} else { |
| 321 |
|
| 322 |
flagdelay = 1; msdelay = mscombinedstats; |
| 323 |
flagbitrate = 1; msbitrate = mscombinedstats; |
| 324 |
flagjitter = 1; msjitter = mscombinedstats; |
| 325 |
flagpktloss = 1; mspktloss = mscombinedstats; |
| 326 |
|
| 327 |
|
| 328 |
flagcombinedstats = 1; |
| 329 |
argv += 2; |
| 330 |
argc -= 2; |
| 331 |
} |
| 332 |
if (argc && argv[0][0] != '-') { |
| 333 |
strncpy(combinedstatsfile, argv[0], fileNameSize); |
| 334 |
argc--; |
| 335 |
argv++; |
| 336 |
} |
| 337 |
} |
| 338 |
break; |
| 339 |
case 'h': |
| 340 |
printhelp(); |
| 341 |
exit(1); |
| 342 |
break; |
| 343 |
case '-': |
| 344 |
printhelp(); |
| 345 |
exit(1); |
| 346 |
break; |
| 347 |
case 'v': |
| 348 |
elab_type = 1; |
| 349 |
argv += 1; |
| 350 |
argc -= 1; |
| 351 |
break; |
| 352 |
case 't': |
| 353 |
logintype = 1; |
| 354 |
argv += 1; |
| 355 |
argc -= 1; |
| 356 |
break; |
| 357 |
case 'w': |
| 358 |
flagwinlin = 1; |
| 359 |
argv += 1; |
| 360 |
argc -= 1; |
| 361 |
break; |
| 362 |
case 'P': |
| 363 |
flagps = 1; |
| 364 |
argv += 1; |
| 365 |
argc -= 1; |
| 366 |
break; |
| 367 |
case 'I': |
| 368 |
flagidt = 1; |
| 369 |
argv += 1; |
| 370 |
argc -= 1; |
| 371 |
break; |
| 372 |
case 'l': |
| 373 |
flaglogout = 1; |
| 374 |
if ((argc < 2) || (argv[1][0] == '-')) { |
| 375 |
printf("Error on output log file name\n"); |
| 376 |
exit(1); |
| 377 |
} else { |
| 378 |
strncpy(logoutname, argv[1], fileNameSize); |
| 379 |
argc -= 2; |
| 380 |
argv += 2; |
| 381 |
} |
| 382 |
break; |
| 383 |
case 'r': |
| 384 |
flagreconstruct = 1; |
| 385 |
flaglogout = 1; |
| 386 |
if ((argc < 2) || (argv[1][0] == '-')) { |
| 387 |
printf("Error on sender log file name\n"); |
| 388 |
exit(1); |
| 389 |
} else { |
| 390 |
strncpy(senderlogname, argv[1], fileNameSize); |
| 391 |
logouttype = 1; |
| 392 |
argc -= 2; |
| 393 |
argv += 2; |
| 394 |
} |
| 395 |
if (argc && argv[0][0] != '-') { |
| 396 |
strncpy(logoutname, argv[0], fileNameSize); |
| 397 |
argc--; |
| 398 |
argv++; |
| 399 |
} else { |
| 400 |
strncpy(logoutname, "reconstructed.dat", fileNameSize); |
| 401 |
} |
| 402 |
break; |
| 403 |
case 'x': |
| 404 |
flageachdj = 1; |
| 405 |
strcpy(delayfpname, "eachdelay"); |
| 406 |
strcpy(jitterfpname, "eachjitter"); |
| 407 |
if ((argc < 2) || (argv[1][0] == '-')) { |
| 408 |
strcat(delayfpname, ".dat"); |
| 409 |
strcat(jitterfpname, ".dat"); |
| 410 |
argc -= 1; |
| 411 |
argv += 1; |
| 412 |
} else { |
| 413 |
strcat(delayfpname, "_"); |
| 414 |
strcat(jitterfpname, "_"); |
| 415 |
strcat(delayfpname, argv[1]); |
| 416 |
strcat(jitterfpname, argv[1]); |
| 417 |
strcat(delayfpname, ".dat"); |
| 418 |
strcat(jitterfpname, ".dat"); |
| 419 |
argc -= 2; |
| 420 |
argv += 2; |
| 421 |
} |
| 422 |
break; |
| 423 |
case 's': |
| 424 |
flagsplit = 1; |
| 425 |
if ((argc < 2) || (argv[1][0] == '-')) { |
| 426 |
strcpy(userstring, "log"); |
| 427 |
argc -= 1; |
| 428 |
argv += 1; |
| 429 |
} else { |
| 430 |
strncpy(userstring, argv[1], 10); |
| 431 |
argc -= 2; |
| 432 |
argv += 2; |
| 433 |
} |
| 434 |
break; |
| 435 |
case 'i': |
| 436 |
elab_type = 2; |
| 437 |
argv += 1; |
| 438 |
argc -= 1; |
| 439 |
break; |
| 440 |
case 'o': |
| 441 |
flagoctave = 1; |
| 442 |
if ((argc < 2) || (argv[1][0] == '-')) { |
| 443 |
printf("Error on output octave file name\n"); |
| 444 |
exit(1); |
| 445 |
} else { |
| 446 |
strncpy(octavename, argv[1], fileNameSize); |
| 447 |
argc -= 2; |
| 448 |
argv += 2; |
| 449 |
} |
| 450 |
break; |
| 451 |
case 'f': |
| 452 |
if ((argc < 2) || (argv[1][0] == '-')) { |
| 453 |
printf("Error 1 flow number\n"); |
| 454 |
argc -= 1; |
| 455 |
argv += 1; |
| 456 |
} else { |
| 457 |
if (argv[1][0] == 't') { |
| 458 |
flagfilter = 2; |
| 459 |
argv += 2; |
| 460 |
argc -= 2; |
| 461 |
} else { |
| 462 |
flownumsel = atoi(argv[1]); |
| 463 |
if (flownumsel <= 0) { |
| 464 |
printf("Error 2 on flow number\n"); |
| 465 |
exit(1); |
| 466 |
} else { |
| 467 |
flagfilter = 1; |
| 468 |
argv += 2; |
| 469 |
argc -= 2; |
| 470 |
} |
| 471 |
} |
| 472 |
} |
| 473 |
break; |
| 474 |
default: |
| 475 |
printf("Invalid option!!\n"); |
| 476 |
printf("Use -h or --help for usage\n"); |
| 477 |
exit(1); |
| 478 |
elab_type = 1; |
| 479 |
break; |
| 480 |
} |
| 481 |
} |
| 482 |
} |
| 483 |
else { |
| 484 |
printf("Invalid option!!\n"); |
| 485 |
printf("Use -h or --help for usage\n"); |
| 486 |
exit(1); |
| 487 |
} |
| 488 |
} |
| 489 |
if (!((flagdelay) || (flagjitter) || (flagps) || (flagidt) || (flagbitrate) || (elab_type) || (flaglogout) || (flagpktloss) |
| 490 |
|| (flagoctave) || (flagsplit) || (flagreconstruct))) |
| 491 |
elab_type = 1; |
| 492 |
|
| 493 |
|
| 494 |
if (logintype == 0) { |
| 495 |
|
| 496 |
intxt = fopen(loginname, "rb"); |
| 497 |
if (intxt == NULL) { |
| 498 |
printf("\n Error opening log file '%s'\n", loginname); |
| 499 |
perror("error "); |
| 500 |
exit(1); |
| 501 |
} |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
} else { |
| 508 |
|
| 509 |
intxt = fopen(loginname, "r"); |
| 510 |
if (intxt == NULL) { |
| 511 |
printf("\n Error opening log file '%s'\n", loginname); |
| 512 |
perror("error "); |
| 513 |
exit(1); |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
if (flaglogout) { |
| 518 |
if (logouttype == 0) { |
| 519 |
|
| 520 |
if ((outtxt = fopen(logoutname, "w")) == NULL) { |
| 521 |
printf("\nError opening file '%s' for write\n", logoutname); |
| 522 |
perror("error "); |
| 523 |
exit(1); |
| 524 |
} |
| 525 |
} else { |
| 526 |
|
| 527 |
outbin.open(logoutname, ios::out | ios::binary | ios::trunc); |
| 528 |
if (!outbin.is_open()) { |
| 529 |
printf("\nError opening file '%s' for write\n", logoutname); |
| 530 |
perror("error "); |
| 531 |
exit(1); |
| 532 |
} |
| 533 |
} |
| 534 |
} |
| 535 |
if (flagoctave) { |
| 536 |
if ((octavefpout = fopen(octavename, "w")) == NULL) { |
| 537 |
printf("Error opening file '%s' for write", octavename); |
| 538 |
perror("error "); |
| 539 |
exit(1); |
| 540 |
} |
| 541 |
} |
| 542 |
if (flagbitrate || flagdelay || flagjitter || flagpktloss || flagsplit) { |
| 543 |
for (int j = 0; j < MaxNumFlow; j++) |
| 544 |
memFile[j].flowId = (unsigned int) -1; |
| 545 |
} |
| 546 |
|
| 547 |
if (flageachdj) { |
| 548 |
if ((delayfpout = fopen(delayfpname, "w")) == NULL) { |
| 549 |
printf("Error opening file '%s' for write", delayfpname); |
| 550 |
perror("error "); |
| 551 |
exit(1); |
| 552 |
} |
| 553 |
if ((jitterfpout = fopen(jitterfpname, "w")) == NULL) { |
| 554 |
printf("Error opening file '%s' for write", jitterfpname); |
| 555 |
perror("error "); |
| 556 |
exit(1); |
| 557 |
} |
| 558 |
} |
| 559 |
|
| 560 |
size = 1; |
| 561 |
while (size > 0) { |
| 562 |
infos = readline(&inbin, intxt, logintype); |
| 563 |
if (size > 0) { |
| 564 |
mark(); |
| 565 |
if (flagreconstruct) { |
| 566 |
struct info *send_info = found((*infos).flowId, (*infos).srcAddr, (*infos).destAddr, (*infos).srcPort, |
| 567 |
(*infos).destPort, (*infos).seqNum); |
| 568 |
if (send_info == NULL) { |
| 569 |
printf("Error, unable to find correspondent line in sender log file\n"); |
| 570 |
exit(1); |
| 571 |
} else { |
| 572 |
(*infos).txTime1 = (*send_info).txTime1; |
| 573 |
(*infos).txTime2 = (*send_info).txTime2; |
| 574 |
(*infos).txTime3 = (*send_info).txTime3; |
| 575 |
|
| 576 |
} |
| 577 |
} |
| 578 |
if (flagps) |
| 579 |
printf("%u\n", (*infos).size); |
| 580 |
if (!flagfirstline) |
| 581 |
if (flagidt) |
| 582 |
printf("%lf\n", ((double) (*infos).rxTime1 * 3600 + (double) (*infos).rxTime2 * 60 |
| 583 |
+ (*infos).rxTime3) - secrxTime); |
| 584 |
if (flaglogout) |
| 585 |
writeline(logouttype); |
| 586 |
if (flagoctave) { |
| 587 |
fprintf(octavefpout, "%7u ", (*infos).seqNum); |
| 588 |
fprintf(octavefpout, "%u %u %lf ", (*infos).txTime1, (*infos).txTime2, (*infos).txTime3); |
| 589 |
fprintf(octavefpout, "%u %u %lf ", (*infos).rxTime1, (*infos).rxTime2, (*infos).rxTime3); |
| 590 |
fprintf(octavefpout, "%u\n", (*infos).size); |
| 591 |
fflush(octavefpout); |
| 592 |
} |
| 593 |
|
| 594 |
|
| 595 |
errornum = 0; |
| 596 |
if (((*infos).txTime1 > 24) || ((*infos).txTime1 < 0)) |
| 597 |
errornum = 1; |
| 598 |
if (((*infos).txTime2 > 59) || ((*infos).txTime2 < 0)) |
| 599 |
errornum = 2; |
| 600 |
if (((*infos).txTime3 > (double) (59.999999)) || ((*infos).txTime3 < 0)) |
| 601 |
errornum = 3; |
| 602 |
if (((*infos).rxTime1 > 24) || ((*infos).rxTime1 < 0)) |
| 603 |
errornum = 4; |
| 604 |
if (((*infos).rxTime2 > 59) || ((*infos).rxTime2 < 0)) |
| 605 |
errornum = 5; |
| 606 |
if (((*infos).rxTime3 > (double) (59.999999)) || ((*infos).rxTime3 < 0)) |
| 607 |
errornum = 6; |
| 608 |
if ((flagfilter == 1) && ((*infos).flowId > flownumsel)) |
| 609 |
errornum = 7; |
| 610 |
if (errornum > 0) { |
| 611 |
pkterr++; |
| 612 |
|
| 613 |
} else { |
| 614 |
|
| 615 |
if (flagfilter == 2) { |
| 616 |
strcpy((*infos).srcAddr, "127.0.0.1"); |
| 617 |
strcpy((*infos).destAddr, "127.0.0.1"); |
| 618 |
(*infos).srcPort = 9999; |
| 619 |
(*infos).destPort = 8999; |
| 620 |
(*infos).flowId = 1; |
| 621 |
} |
| 622 |
pktvalid++; |
| 623 |
if (flagbitrate || flagjitter || flagdelay || flagpktloss || flagsplit) |
| 624 |
split(); |
| 625 |
sectxTime = ((double) (*infos).txTime1 * 3600 + (double) (*infos).txTime2 * 60 + (*infos).txTime3); |
| 626 |
secrxTime = ((double) (*infos).rxTime1 * 3600 + (double) (*infos).rxTime2 * 60 + (*infos).rxTime3); |
| 627 |
if (flageachdj) { |
| 628 |
fprintf(delayfpout, "%lf\n", deltatime(sectxTime, secrxTime)); |
| 629 |
if (!flagfirstline) |
| 630 |
fprintf(jitterfpout, "%lf\n", fabs(lastdelay - deltatime(sectxTime, secrxTime))); |
| 631 |
} |
| 632 |
|
| 633 |
setline(sectxTime, secrxTime); |
| 634 |
|
| 635 |
avdelay = avdelay + deltatime(sectxTime, secrxTime); |
| 636 |
delvariation = delvariation + ((deltatime(sectxTime, secrxTime)) * (deltatime(sectxTime, secrxTime))); |
| 637 |
if (secrxTime < secfirstline_gl) |
| 638 |
secfirstline_gl = secrxTime; |
| 639 |
|
| 640 |
if (flagfirstline) { |
| 641 |
flagfirstline = 0; |
| 642 |
lastdelay = deltatime(sectxTime, secrxTime); |
| 643 |
} else { |
| 644 |
avjitter = avjitter + fabs(lastdelay - deltatime(sectxTime, secrxTime)); |
| 645 |
lastdelay = deltatime(sectxTime, secrxTime); |
| 646 |
} |
| 647 |
|
| 648 |
} |
| 649 |
} |
| 650 |
} |
| 651 |
|
| 652 |
if (pktvalid == 0) { |
| 653 |
printf("Empty log file\n"); |
| 654 |
|
| 655 |
} |
| 656 |
|
| 657 |
if (flagbitrate || flagdelay || flagjitter || flagpktloss || flagsplit) { |
| 658 |
|
| 659 |
i = 0; |
| 660 |
while ((int) memFile[i].flowId != -1) { |
| 661 |
memFile[i].FileId.close(); |
| 662 |
i++; |
| 663 |
} |
| 664 |
} |
| 665 |
|
| 666 |
if (flagbitrate || flagdelay || flagjitter || flagpktloss) { |
| 667 |
|
| 668 |
elabsplit(flagbitrate, flagjitter, flagdelay, flagpktloss); |
| 669 |
|
| 670 |
|
| 671 |
char tempfilename[fileNameSize] = ""; |
| 672 |
|
| 673 |
if (flagbitrate && !flagcombinedstats) { |
| 674 |
merge(1); |
| 675 |
} |
| 676 |
if (flagjitter && !flagcombinedstats) { |
| 677 |
merge(2); |
| 678 |
} |
| 679 |
if (flagdelay && !flagcombinedstats) { |
| 680 |
merge(3); |
| 681 |
} |
| 682 |
if (flagpktloss && !flagcombinedstats) { |
| 683 |
merge(4); |
| 684 |
} |
| 685 |
if (flagcombinedstats) { |
| 686 |
mergeCombined(); |
| 687 |
} |
| 688 |
|
| 689 |
if (flagbitrate) { |
| 690 |
i = 0; |
| 691 |
while ((int) memFile[i].flowId != -1) { |
| 692 |
strcpy(tempfilename, memFile[i].FileName); |
| 693 |
strcat(tempfilename, ".bit"); |
| 694 |
if (remove(tempfilename) == -1) { |
| 695 |
printf("Unable to remove file '%s'\n", tempfilename); |
| 696 |
perror("error "); |
| 697 |
} |
| 698 |
i++; |
| 699 |
} |
| 700 |
} |
| 701 |
if (flagjitter) { |
| 702 |
i = 0; |
| 703 |
while ((int) memFile[i].flowId != -1) { |
| 704 |
strcpy(tempfilename, memFile[i].FileName); |
| 705 |
strcat(tempfilename, ".jit"); |
| 706 |
if (remove(tempfilename) == -1) { |
| 707 |
printf("Unable to remove file '%s'\n", tempfilename); |
| 708 |
perror("error "); |
| 709 |
} |
| 710 |
i++; |
| 711 |
} |
| 712 |
} |
| 713 |
if (flagdelay) { |
| 714 |
i = 0; |
| 715 |
while ((int) memFile[i].flowId != -1) { |
| 716 |
strcpy(tempfilename, memFile[i].FileName); |
| 717 |
strcat(tempfilename, ".del"); |
| 718 |
if (remove(tempfilename) == -1) { |
| 719 |
printf("Unable to remove file '%s'\n", tempfilename); |
| 720 |
perror("error "); |
| 721 |
} |
| 722 |
i++; |
| 723 |
} |
| 724 |
} |
| 725 |
if (flagpktloss) { |
| 726 |
i = 0; |
| 727 |
while ((int) memFile[i].flowId != -1) { |
| 728 |
strcpy(tempfilename, memFile[i].FileName); |
| 729 |
strcat(tempfilename, ".pkt"); |
| 730 |
if (remove(tempfilename) == -1) { |
| 731 |
printf("Unable to remove file '%s'\n", tempfilename); |
| 732 |
perror("error "); |
| 733 |
} |
| 734 |
i++; |
| 735 |
} |
| 736 |
} |
| 737 |
} |
| 738 |
|
| 739 |
if ((flagbitrate || flagdelay || flagjitter || flagpktloss) && (!flagsplit)) { |
| 740 |
i = 0; |
| 741 |
while ((int) memFile[i].flowId != -1) { |
| 742 |
if (remove(memFile[i].FileName) == -1) { |
| 743 |
printf("Unable to remove file '%s'\n", memFile[i].FileName); |
| 744 |
perror("error "); |
| 745 |
} |
| 746 |
i++; |
| 747 |
} |
| 748 |
} |
| 749 |
if (flagsplit) { |
| 750 |
i = 0; |
| 751 |
char strappo[230]; |
| 752 |
while ((int) memFile[i].flowId != -1) { |
| 753 |
strcpy(strappo, memFile[i].FileNWE); |
| 754 |
strcat(strappo, "."); |
| 755 |
strcat(strappo, userstring); |
| 756 |
strcat(strappo, ".dat"); |
| 757 |
if (rename(memFile[i].FileName, strappo) == -1) { |
| 758 |
printf("Unable to rename file '%s'\n", memFile[i].FileName); |
| 759 |
perror("error "); |
| 760 |
} |
| 761 |
i++; |
| 762 |
} |
| 763 |
} |
| 764 |
|
| 765 |
if (elab_type == 1) { |
| 766 |
|
| 767 |
double seclastline = 0, pktrecv = 0, byterecv = 0; |
| 768 |
double maxdelay = -86400, mindelay = 90000; |
| 769 |
double totaltime = 0; |
| 770 |
unsigned int pktloss = 0, lossEvents = 0; |
| 771 |
for (z = 0; z < flownum; z++) { |
| 772 |
totaltime = deltatime(flowinfo[z].secfirstline, flowinfo[z].seclastline); |
| 773 |
pktrecv = pktrecv + flowinfo[z].pktrecv; |
| 774 |
byterecv = byterecv + flowinfo[z].byterecv; |
| 775 |
pktloss = pktloss + flowinfo[z].pktloss; |
| 776 |
lossEvents = lossEvents + flowinfo[z].lossEvents; |
| 777 |
if (seclastline < flowinfo[z].seclastline) |
| 778 |
seclastline = flowinfo[z].seclastline; |
| 779 |
if (maxdelay < flowinfo[z].maxdelay) |
| 780 |
maxdelay = flowinfo[z].maxdelay; |
| 781 |
if (mindelay > flowinfo[z].mindelay) |
| 782 |
mindelay = flowinfo[z].mindelay; |
| 783 |
flowinfo[z].avdelay = flowinfo[z].avdelay / (double) flowinfo[z].pktrecv; |
| 784 |
flowinfo[z].delvariation = flowinfo[z].delvariation / (double) flowinfo[z].pktrecv; |
| 785 |
flowinfo[z].delvariation = flowinfo[z].delvariation - (flowinfo[z].avdelay * flowinfo[z].avdelay); |
| 786 |
if (flowinfo[z].delvariation > 0) |
| 787 |
flowinfo[z].delvariation = sqrt(flowinfo[z].delvariation); |
| 788 |
else |
| 789 |
flowinfo[z].delvariation = 0; |
| 790 |
if (flowinfo[z].pktrecv > 1) |
| 791 |
flowinfo[z].avjitter = flowinfo[z].avjitter / (double) (flowinfo[z].pktrecv - 1); |
| 792 |
else |
| 793 |
flowinfo[z].avjitter = 0; |
| 794 |
printf("----------------------------------------------------------\n"); |
| 795 |
printf("Flow number: %u\n", flowinfo[z].flowId); |
| 796 |
printf("From %s:%u", flowinfo[z].srcaddress, flowinfo[z].srcport); |
| 797 |
printf("\nTo %s:%u\n", flowinfo[z].destaddress, flowinfo[z].destport); |
| 798 |
printf("----------------------------------------------------------\n"); |
| 799 |
printf("Total time = %13.6lf s\n", totaltime); |
| 800 |
printf("Total packets = %13lu\n", flowinfo[z].pktrecv); |
| 801 |
printf("Minimum delay = %13.6lf s\n", flowinfo[z].mindelay); |
| 802 |
printf("Maximum delay = %13.6lf s\n", flowinfo[z].maxdelay); |
| 803 |
printf("Average delay = %13.6lf s\n", flowinfo[z].avdelay); |
| 804 |
printf("Average jitter = %13.6lf s\n", flowinfo[z].avjitter); |
| 805 |
printf("Delay standard deviation = %13.6lf s\n", flowinfo[z].delvariation); |
| 806 |
printf("Bytes received = %13.0lf\n", flowinfo[z].byterecv); |
| 807 |
if (totaltime > 0) { |
| 808 |
printf("Average bitrate = %13.6lf Kbit/s\n", flowinfo[z].byterecv * 8 / 1000 / totaltime); |
| 809 |
printf("Average packet rate = %13.6lf pkt/s\n", (double) flowinfo[z].pktrecv / totaltime); |
| 810 |
} else { |
| 811 |
printf("Average bitrate = %13.6lf Kbit/s\n", (double) 0); |
| 812 |
printf("Average packet rate = %13.6lf pkt/s\n", (double) 0); |
| 813 |
} |
| 814 |
if (flowinfo[z].pktrecv > 0 && flowinfo[z].pktloss > 0) { |
| 815 |
printf("Packets dropped = %13lu (%3.2lf %%)\n", flowinfo[z].pktloss, (double) 100 |
| 816 |
* flowinfo[z].pktloss / (flowinfo[z].pktrecv + flowinfo[z].pktloss)); |
| 817 |
printf("Average loss-burst size = %13lf pkt\n", (double) flowinfo[z].pktloss / flowinfo[z].lossEvents); |
| 818 |
} else { |
| 819 |
printf("Packets dropped = %13lu (%3.2lf %%)\n", (long unsigned int) 0, (double) 0); |
| 820 |
printf("Average loss-burst size = %13lf pkt\n", (double) 0); |
| 821 |
} |
| 822 |
PRINTD(1,"Packets duplicated = %13u \n",flowinfo[z].pktdup); |
| 823 |
PRINTD(1,"First sequence number = %13u \n",flowinfo[z].minSeq); |
| 824 |
PRINTD(1,"Last sequence number = %13u \n",flowinfo[z].maxSeq); |
| 825 |
PRINTD(1,"Loss Events = %13u \n",flowinfo[z].lossEvents); |
| 826 |
printf("----------------------------------------------------------\n"); |
| 827 |
} |
| 828 |
totaltime = deltatime(secfirstline_gl, seclastline); |
| 829 |
avdelay = avdelay / (double) pktrecv; |
| 830 |
delvariation = delvariation / (double) pktrecv; |
| 831 |
delvariation = delvariation - (avdelay * avdelay); |
| 832 |
if (delvariation > 0) |
| 833 |
delvariation = sqrt(delvariation); |
| 834 |
else |
| 835 |
delvariation = 0; |
| 836 |
if (pktrecv > 1) |
| 837 |
avjitter = avjitter / (pktrecv - 1); |
| 838 |
else |
| 839 |
avjitter = 0; |
| 840 |
printf("\n__________________________________________________________\n"); |
| 841 |
printf("**************** TOTAL RESULTS ******************\n"); |
| 842 |
printf("__________________________________________________________\n"); |
| 843 |
printf("Number of flows = %13u\n", flownum); |
| 844 |
printf("Total time = %13.6lf s\n", totaltime); |
| 845 |
printf("Total packets = %13.0lf\n", pktrecv); |
| 846 |
printf("Minimum delay = %13.6lf s\n", mindelay); |
| 847 |
printf("Maximum delay = %13.6lf s\n", maxdelay); |
| 848 |
printf("Average delay = %13.6lf s\n", avdelay); |
| 849 |
printf("Average jitter = %13.6lf s\n", avjitter); |
| 850 |
printf("Delay standard deviation = %13.6lf s\n", delvariation); |
| 851 |
printf("Bytes received = %13.0lf\n", byterecv); |
| 852 |
if (totaltime > 0) { |
| 853 |
printf("Average bitrate = %13.6lf Kbit/s\n", byterecv * 8 / 1000 / totaltime); |
| 854 |
printf("Average packet rate = %13.6lf pkt/s\n", pktrecv / totaltime); |
| 855 |
} else { |
| 856 |
printf("Average bitrate = %13.6lf Kbit/s\n", (double) 0); |
| 857 |
printf("Average packet rate = %13.6lf pkt/s\n", (double) 0); |
| 858 |
} |
| 859 |
if (pktrecv > 0 && pktloss > 0) { |
| 860 |
printf("Packets dropped = %13.0u (%3.2lf %%)\n", pktloss, (double) (100 * pktloss / (pktrecv + pktloss))); |
| 861 |
printf("Average loss-burst size = %13lf pkt\n", (double) pktloss / lossEvents); |
| 862 |
} else { |
| 863 |
printf("Packets dropped = %13.0lf (%3.2lf %%)\n", (double) 0, (double) 0); |
| 864 |
printf("Average loss-burst size = %13.0lf pkt\n", (double) 0); |
| 865 |
} |
| 866 |
printf("Error lines = %13lu\n", pkterr); |
| 867 |
printf("----------------------------------------------------------\n"); |
| 868 |
} |
| 869 |
|
| 870 |
|
| 871 |
if (logintype == 0) |
| 872 |
|
| 873 |
|
| 874 |
fclose(intxt); |
| 875 |
else |
| 876 |
fclose(intxt); |
| 877 |
if (flaglogout) { |
| 878 |
if (logouttype == 0) |
| 879 |
fclose(outtxt); |
| 880 |
else |
| 881 |
outbin.close(); |
| 882 |
} |
| 883 |
if (flagoctave) |
| 884 |
fclose(octavefpout); |
| 885 |
|
| 886 |
if (flageachdj) { |
| 887 |
fclose(delayfpout); |
| 888 |
fclose(jitterfpout); |
| 889 |
} |
| 890 |
exit(0); |
| 891 |
} |
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
ofstream *FlowPresent(unsigned int flowId, char *destAddr, char *srcAddr, unsigned int srcPort, unsigned int destPort) |
| 898 |
{ |
| 899 |
int i = 0; |
| 900 |
while (i < MaxNumFlow) { |
| 901 |
if ((memFile[i].flowId == flowId) && (strcmp(memFile[i].srcAddr, srcAddr) == 0) && (strcmp(memFile[i].destAddr, destAddr) |
| 902 |
== 0) && (memFile[i].srcPort == srcPort) && (memFile[i].destPort == destPort)) |
| 903 |
break; |
| 904 |
i++; |
| 905 |
} |
| 906 |
if (i != MaxNumFlow) |
| 907 |
return &memFile[i].FileId; |
| 908 |
else |
| 909 |
return NULL; |
| 910 |
} |
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
double deltatime(double time1, double time2) |
| 915 |
{ |
| 916 |
if (time2 < time1) |
| 917 |
return time2 - time1; |
| 918 |
else |
| 919 |
return time2 - time1; |
| 920 |
} |
| 921 |
|
| 922 |
|
| 923 |
struct info *found(unsigned int flowId, char *srcAddr, char *destAddr, unsigned int srcPort, unsigned int destPort, unsigned int seqNum) |
| 924 |
{ |
| 925 |
int flagfound = 0; |
| 926 |
struct info *infos_loc = (struct info *) malloc(sizeof(struct info)); |
| 927 |
sendlog.open(senderlogname, ios::in | ios::binary); |
| 928 |
if (!sendlog.is_open()) { |
| 929 |
printf("\n Error opening log file '%s'\n", senderlogname); |
| 930 |
perror("error "); |
| 931 |
exit(1); |
| 932 |
} |
| 933 |
while (sendlog.good() && (!flagfound)) { |
| 934 |
sendlog.read((char *) infos_loc, sizeof(struct info)); |
| 935 |
if (((*infos_loc).flowId == flowId) && (strcmp((*infos_loc).srcAddr, srcAddr) == 0) && (strcmp((*infos_loc).destAddr, |
| 936 |
destAddr) == 0) && ((*infos_loc).srcPort == srcPort) && ((*infos_loc).destPort == destPort) && ((*infos_loc).seqNum |
| 937 |
== seqNum)) |
| 938 |
flagfound = 1; |
| 939 |
} |
| 940 |
if (flagfound) { |
| 941 |
sendlog.close(); |
| 942 |
return infos_loc; |
| 943 |
} else { |
| 944 |
return NULL; |
| 945 |
} |
| 946 |
|
| 947 |
} |
| 948 |
|
| 949 |
|
| 950 |
void mark() |
| 951 |
{ |
| 952 |
static int i = 0; |
| 953 |
static char chr[] = "|\\-/"; |
| 954 |
fprintf(stderr, "\b%c", chr[i++]); |
| 955 |
if (i > 3) |
| 956 |
i = 0; |
| 957 |
fflush(stderr); |
| 958 |
} |
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
struct info *readline(ifstream *fbin, FILE *ftxt, int filetype) |
| 963 |
{ |
| 964 |
|
| 965 |
struct info *infos_loc = (struct info *) malloc(sizeof(struct info)); |
| 966 |
|
| 967 |
if (filetype == 0) { |
| 968 |
|
| 969 |
|
| 970 |
size = fread(infos_loc, sizeof(struct info), 1, ftxt); |
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
} else { |
| 976 |
|
| 977 |
char buffer; |
| 978 |
if (fscanf(ftxt, "Flow>%04u ", &(*infos_loc).flowId) != EOF) { |
| 979 |
fscanf(ftxt, "Seq>%7u ", &(*infos_loc).seqNum); |
| 980 |
#ifdef V23 |
| 981 |
fscanf(ftxt, "Src>%1c%15c/%u ", &buffer, (*infos_loc).srcAddr,&(*infos_loc).srcPort); |
| 982 |
fscanf(ftxt, "Dest>%1c%15c/%u ", &buffer, (*infos_loc).destAddr,&(*infos_loc).destPort); |
| 983 |
fscanf(ftxt, "TxTime>%ld:%ld:%lf ", &(*infos_loc).txTime1, &(*infos_loc).txTime2,&(*infos_loc).txTime3); |
| 984 |
fscanf(ftxt, "RxTime>%ld:%ld:%lf ", &(*infos_loc).rxTime1, &(*infos_loc).rxTime2,&(*infos_loc).rxTime3); |
| 985 |
#else |
| 986 |
#ifdef V21 |
| 987 |
fscanf(ftxt, "Src>%1c%15c/%u ", &buffer, (*infos_loc).srcAddr,&(*infos_loc).srcPort); |
| 988 |
fscanf(ftxt, "Dest>%1c%15c/%u ", &buffer, (*infos_loc).destAddr,&(*infos_loc).destPort); |
| 989 |
fscanf(ftxt, "TxTime>%ld:%ld:%lf ", &(*infos_loc).txTime1, &(*infos_loc).txTime2,&(*infos_loc).txTime3); |
| 990 |
fscanf(ftxt, "RxTime>%ld:%ld:%lf ", &(*infos_loc).rxTime1, &(*infos_loc).rxTime2,&(*infos_loc).rxTime3); |
| 991 |
#else |
| 992 |
fscanf(ftxt, "Src>%1c%45c/%u ", &buffer, (*infos_loc).srcAddr, &(*infos_loc).srcPort); |
| 993 |
fscanf(ftxt, "Dest>%1c%45c/%u ", &buffer, (*infos_loc).destAddr, &(*infos_loc).destPort); |
| 994 |
fscanf(ftxt, "txTime>%u:%u:%lf ", &(*infos_loc).txTime1, &(*infos_loc).txTime2, &(*infos_loc).txTime3); |
| 995 |
fscanf(ftxt, "rxTime>%u:%u:%lf ", &(*infos_loc).rxTime1, &(*infos_loc).rxTime2, &(*infos_loc).rxTime3); |
| 996 |
#endif |
| 997 |
#endif |
| 998 |
fscanf(ftxt, "Size>%5u\n", &(*infos_loc).size); |
| 999 |
if ((*infos_loc).flowId == 0) { |
| 1000 |
printf("\n Error reading input file\n"); |
| 1001 |
size = 0; |
| 1002 |
} else { |
| 1003 |
size = 1; |
| 1004 |
} |
| 1005 |
} else |
| 1006 |
size = 0; |
| 1007 |
} |
| 1008 |
return infos_loc; |
| 1009 |
} |
| 1010 |
|
| 1011 |
void writeline(int filetype) |
| 1012 |
{ |
| 1013 |
if (filetype == 0) { |
| 1014 |
|
| 1015 |
fprintf(outtxt, "Flow>%04u ", (*infos).flowId); |
| 1016 |
fprintf(outtxt, "Seq>%7u ", (*infos).seqNum); |
| 1017 |
#ifdef V23 |
| 1018 |
fprintf (outtxt, "Src>%16s/%hu ",(*infos).srcAddr,(*infos).srcPort); |
| 1019 |
fprintf (outtxt, "Dest>%16s/%hu ",(*infos).destAddr,(*infos).destPort); |
| 1020 |
#else |
| 1021 |
fprintf(outtxt, "Src>%46s/%hu ", (*infos).srcAddr, (*infos).srcPort); |
| 1022 |
fprintf(outtxt, "Dest>%46s/%hu ", (*infos).destAddr, (*infos).destPort); |
| 1023 |
#endif |
| 1024 |
fprintf(outtxt, "txTime>%u:%u:%lf ", (*infos).txTime1, (*infos).txTime2, (*infos).txTime3); |
| 1025 |
fprintf(outtxt, "rxTime>%u:%u:%lf ", (*infos).rxTime1, (*infos).rxTime2, (*infos).rxTime3); |
| 1026 |
fprintf(outtxt, "Size>%5u\n", (*infos).size); |
| 1027 |
} else { |
| 1028 |
|
| 1029 |
outbin.write((char *) infos, sizeof(struct info)); |
| 1030 |
} |
| 1031 |
} |
| 1032 |
|
| 1033 |
void setline(double txTime, double rxTime) |
| 1034 |
{ |
| 1035 |
double currentdelay = deltatime(txTime, rxTime); |
| 1036 |
if (flownum == 0) { |
| 1037 |
flownum = 1; |
| 1038 |
flowinfo[0].flowId = (*infos).flowId; |
| 1039 |
flowinfo[0].byterecv = (*infos).size; |
| 1040 |
flowinfo[0].pktrecv = 1; |
| 1041 |
flowinfo[0].avdelay = currentdelay; |
| 1042 |
flowinfo[0].delvariation = currentdelay * currentdelay; |
| 1043 |
flowinfo[0].maxdelay = currentdelay; |
| 1044 |
flowinfo[0].mindelay = currentdelay; |
| 1045 |
flowinfo[0].secfirstline = rxTime; |
| 1046 |
flowinfo[0].seclastline = rxTime; |
| 1047 |
strncpy(flowinfo[0].srcaddress, (*infos).srcAddr, ADDRESSLEN); |
| 1048 |
flowinfo[0].srcport = (*infos).srcPort; |
| 1049 |
strncpy(flowinfo[0].destaddress, (*infos).destAddr, ADDRESSLEN); |
| 1050 |
flowinfo[0].destport = (*infos).destPort; |
| 1051 |
flowinfo[0].lastdelay = currentdelay; |
| 1052 |
flowinfo[0].avjitter = 0; |
| 1053 |
flowinfo[0].pktloss = 0; |
| 1054 |
flowinfo[0].lastpktnum = (*infos).seqNum; |
| 1055 |
flowinfo[0].pktdup = 0; |
| 1056 |
flowinfo[0].maxSeq = infos->seqNum; |
| 1057 |
flowinfo[0].minSeq = 1; |
| 1058 |
flowinfo[0].lossEvents = 0; |
| 1059 |
PRINTD(2,"Flow=%d Seq=%u pktrecv=%lu pktloss=%lu pktdup=%u\n", |
| 1060 |
infos->flowId, infos->seqNum, flowinfo[0].pktrecv, flowinfo[0].pktloss, flowinfo[0].pktdup); |
| 1061 |
} else { |
| 1062 |
int found = 0; |
| 1063 |
int index = 0; |
| 1064 |
if (flagfilter == 2) { |
| 1065 |
found = 1; |
| 1066 |
index = 0; |
| 1067 |
} else { |
| 1068 |
for (unsigned int z = 0; z < flownum; z++) |
| 1069 |
if ((flowinfo[z].flowId == (*infos).flowId) && (strcmp(flowinfo[z].srcaddress, (*infos).srcAddr) == 0) |
| 1070 |
&& (strcmp(flowinfo[z].destaddress, (*infos).destAddr) == 0) && (flowinfo[z].srcport |
| 1071 |
== (*infos).srcPort) && (flowinfo[z].destport == (*infos).destPort)) { |
| 1072 |
found = 1; |
| 1073 |
index = z; |
| 1074 |
} |
| 1075 |
} |
| 1076 |
if (found) { |
| 1077 |
|
| 1078 |
flowinfo[index].byterecv += (*infos).size; |
| 1079 |
flowinfo[index].pktrecv++; |
| 1080 |
flowinfo[index].avdelay = flowinfo[index].avdelay + currentdelay; |
| 1081 |
flowinfo[index].delvariation = flowinfo[index].delvariation + (currentdelay * currentdelay); |
| 1082 |
if (currentdelay > flowinfo[index].maxdelay) { |
| 1083 |
flowinfo[index].maxdelay = currentdelay; |
| 1084 |
} |
| 1085 |
if (currentdelay < flowinfo[index].mindelay) |
| 1086 |
flowinfo[index].mindelay = currentdelay; |
| 1087 |
if (rxTime < flowinfo[index].secfirstline) |
| 1088 |
flowinfo[index].secfirstline = rxTime; |
| 1089 |
if (rxTime > flowinfo[index].seclastline) |
| 1090 |
flowinfo[index].seclastline = rxTime; |
| 1091 |
double jittemp = fabs(flowinfo[index].lastdelay - currentdelay); |
| 1092 |
flowinfo[index].avjitter = flowinfo[index].avjitter + jittemp; |
| 1093 |
flowinfo[index].lastpktnum = (*infos).seqNum; |
| 1094 |
flowinfo[index].lastdelay = currentdelay; |
| 1095 |
if (infos->seqNum > flowinfo[index].maxSeq) { |
| 1096 |
flowinfo[index].maxSeq = infos->seqNum; |
| 1097 |
} |
| 1098 |
if (infos->seqNum > (flowinfo[index].pktloss + flowinfo[index].pktrecv)) |
| 1099 |
flowinfo[index].lossEvents++; |
| 1100 |
if ((flowinfo[index].maxSeq - flowinfo[index].minSeq + 1) < (flowinfo[index].pktrecv - flowinfo[index].pktdup)) { |
| 1101 |
flowinfo[index].pktdup = -flowinfo[index].maxSeq + flowinfo[index].minSeq + flowinfo[index].pktrecv - 1; |
| 1102 |
flowinfo[index].pktloss = 0; |
| 1103 |
} else { |
| 1104 |
|
| 1105 |
if ((flowinfo[index].maxSeq - flowinfo[index].minSeq - flowinfo[index].pktrecv + flowinfo[index].pktdup + 1) |
| 1106 |
< flowinfo[index].pktloss) |
| 1107 |
flowinfo[index].lossEvents--; |
| 1108 |
|
| 1109 |
flowinfo[index].pktloss = flowinfo[index].maxSeq - flowinfo[index].minSeq - flowinfo[index].pktrecv |
| 1110 |
+ flowinfo[index].pktdup + 1; |
| 1111 |
} |
| 1112 |
PRINTD(2,"Flow=%d Seq=%d pktrecv=%ld pktloss=%ld pktdup=%d lossEvents=%d\n", |
| 1113 |
infos->flowId, infos->seqNum, flowinfo[index].pktrecv, flowinfo[index].pktloss, |
| 1114 |
flowinfo[index].pktdup, flowinfo[index].lossEvents); |
| 1115 |
} else { |
| 1116 |
|
| 1117 |
flownum++; |
| 1118 |
flowinfo = (struct stflowinfo *) realloc(flowinfo, (flownum + 1) * sizeof(struct stflowinfo)); |
| 1119 |
flowinfo[flownum - 1].flowId = (*infos).flowId; |
| 1120 |
flowinfo[flownum - 1].byterecv = (*infos).size; |
| 1121 |
flowinfo[flownum - 1].pktrecv = 1; |
| 1122 |
flowinfo[flownum - 1].avdelay = currentdelay; |
| 1123 |
flowinfo[flownum - 1].delvariation = currentdelay * currentdelay; |
| 1124 |
flowinfo[flownum - 1].maxdelay = currentdelay; |
| 1125 |
flowinfo[flownum - 1].mindelay = currentdelay; |
| 1126 |
flowinfo[flownum - 1].secfirstline = rxTime; |
| 1127 |
flowinfo[flownum - 1].seclastline = rxTime; |
| 1128 |
strncpy(flowinfo[flownum - 1].srcaddress, (*infos).srcAddr, ADDRESSLEN); |
| 1129 |
flowinfo[flownum - 1].srcport = (*infos).srcPort; |
| 1130 |
strncpy(flowinfo[flownum - 1].destaddress, (*infos).destAddr, ADDRESSLEN); |
| 1131 |
flowinfo[flownum - 1].destport = (*infos).destPort; |
| 1132 |
flowinfo[flownum - 1].lastdelay = currentdelay; |
| 1133 |
flowinfo[flownum - 1].avjitter = 0; |
| 1134 |
flowinfo[flownum - 1].pktloss = 0; |
| 1135 |
flowinfo[flownum - 1].lastpktnum = (*infos).seqNum; |
| 1136 |
flowinfo[flownum - 1].pktdup = 0; |
| 1137 |
flowinfo[flownum - 1].maxSeq = infos->seqNum; |
| 1138 |
flowinfo[flownum - 1].minSeq = 1; |
| 1139 |
flowinfo[flownum - 1].lossEvents = 0; |
| 1140 |
PRINTD(2,"Flow=%d Seq=%d pktrecv=%ld pktloss=%ld pktdup=%d lossEvents=%d\n", |
| 1141 |
infos->flowId, infos->seqNum, flowinfo[flownum-1].pktrecv, |
| 1142 |
flowinfo[flownum-1].pktloss, flowinfo[flownum-1].pktdup, flowinfo[flownum-1].lossEvents); |
| 1143 |
} |
| 1144 |
} |
| 1145 |
} |
| 1146 |
|
| 1147 |
|
| 1148 |
void split() |
| 1149 |
{ |
| 1150 |
int i = 0; |
| 1151 |
ofstream *IdFile; |
| 1152 |
|
| 1153 |
IdFile = FlowPresent((*infos).flowId, (*infos).destAddr, (*infos).srcAddr, (*infos).srcPort, (*infos).destPort); |
| 1154 |
if (IdFile != NULL) { |
| 1155 |
(*IdFile).write((char *) infos, sizeof(struct info)); |
| 1156 |
if (!(*IdFile)) { |
| 1157 |
printf("Unable to write file \n"); |
| 1158 |
perror("Split : "); |
| 1159 |
exit(1); |
| 1160 |
} |
| 1161 |
} else { |
| 1162 |
i = 0; |
| 1163 |
while ((memFile[i].flowId != (unsigned int) -1) && (i < MaxNumFlow)) { |
| 1164 |
i++; |
| 1165 |
} |
| 1166 |
char buffer1[fileNameSize] = ""; |
| 1167 |
char buffer2[fileNameSize] = ""; |
| 1168 |
char* nameFileLog = buffer2; |
| 1169 |
char flowIdString[33]; |
| 1170 |
sprintf(flowIdString, "%u", (*infos).flowId); |
| 1171 |
strcat(nameFileLog, flowIdString); |
| 1172 |
strcat(nameFileLog, "-"); |
| 1173 |
strcat(nameFileLog, (*infos).srcAddr); |
| 1174 |
strcat(nameFileLog, "-"); |
| 1175 |
strcat(nameFileLog, (*infos).destAddr); |
| 1176 |
strcpy(buffer1, buffer2); |
| 1177 |
strcat(nameFileLog, ".dat"); |
| 1178 |
|
| 1179 |
memFile[i].FileId.open(buffer2, ios::out | ios::binary | ios::trunc); |
| 1180 |
if (!memFile[i].FileId.is_open()) { |
| 1181 |
printf("Unable to open file %s \n", buffer2); |
| 1182 |
perror("ITGSplit main: "); |
| 1183 |
exit(1); |
| 1184 |
} |
| 1185 |
|
| 1186 |
memFile[i].flowId = (*infos).flowId; |
| 1187 |
memFile[i].srcPort = (*infos).srcPort; |
| 1188 |
memFile[i].destPort = (*infos).destPort; |
| 1189 |
strncpy(memFile[i].srcAddr, (*infos).srcAddr, ADDRESSLEN); |
| 1190 |
strncpy(memFile[i].destAddr, (*infos).destAddr, ADDRESSLEN); |
| 1191 |
strcpy(memFile[i].FileName, buffer2); |
| 1192 |
strcpy(memFile[i].FileNWE, buffer1); |
| 1193 |
memFile[i].FileId.write((char *) infos, sizeof(struct info)); |
| 1194 |
if (!memFile[i].FileId) { |
| 1195 |
printf("Unable to write into file %s \n", buffer2); |
| 1196 |
perror("Split main: "); |
| 1197 |
exit(1); |
| 1198 |
} |
| 1199 |
} |
| 1200 |
} |
| 1201 |
|
| 1202 |
void elabsplit(int flagbit, int flagjit, int flagdel, int flagpkt) |
| 1203 |
{ |
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
int i = 0, flagfirstline; |
| 1208 |
double secrxTime, secfirstline_loc = 90000; |
| 1209 |
double secinitbitrate = 0, tempbitrate = 0; |
| 1210 |
double secinitjitter = 0, tempjitter = 0, lastdelay = 0, currentdelay = 0; |
| 1211 |
double secinitdelay = 0, tempdelay = 0; |
| 1212 |
double secinitpktloss = 0; |
| 1213 |
unsigned long int intclosedbit = 0, intclosedjit = 0, intcloseddel = 0, intclosedpkt = 0, z = 0; |
| 1214 |
unsigned long int pktjitter = 0, pktdelay = 0; |
| 1215 |
unsigned long int pktrecv = 0, pktloss = 0, pktdup = 0; |
| 1216 |
unsigned long int temppktloss = 0, pktpktloss = 0, totalpktloss = 0; |
| 1217 |
|
| 1218 |
|
| 1219 |
FILE *inputfilec = 0; |
| 1220 |
FILE *outfilebit = 0; |
| 1221 |
FILE *outfilejit = 0; |
| 1222 |
FILE *outfiledel = 0; |
| 1223 |
FILE *outfilepkt = 0; |
| 1224 |
char outfilename[fileNameSize]; |
| 1225 |
|
| 1226 |
|
| 1227 |
while (memFile[i].flowId != (unsigned int) -1) { |
| 1228 |
|
| 1229 |
|
| 1230 |
if (flagbit) { |
| 1231 |
strcpy(outfilename, ""); |
| 1232 |
strcpy(outfilename, memFile[i].FileName); |
| 1233 |
strcat(outfilename, ".bit"); |
| 1234 |
if ((outfilebit = fopen(outfilename, "w")) == NULL) { |
| 1235 |
printf("Error opening file %s for write \n", outfilename); |
| 1236 |
perror("error "); |
| 1237 |
exit(1); |
| 1238 |
} |
| 1239 |
} |
| 1240 |
if (flagjit) { |
| 1241 |
strcpy(outfilename, ""); |
| 1242 |
strcpy(outfilename, memFile[i].FileName); |
| 1243 |
strcat(outfilename, ".jit"); |
| 1244 |
if ((outfilejit = fopen(outfilename, "w")) == NULL) { |
| 1245 |
printf("Error opening file %s for write \n", outfilename); |
| 1246 |
perror("error "); |
| 1247 |
exit(1); |
| 1248 |
} |
| 1249 |
} |
| 1250 |
if (flagdel) { |
| 1251 |
strcpy(outfilename, ""); |
| 1252 |
strcpy(outfilename, memFile[i].FileName); |
| 1253 |
strcat(outfilename, ".del"); |
| 1254 |
if ((outfiledel = fopen(outfilename, "w")) == NULL) { |
| 1255 |
printf("Error opening file %s for write \n", outfilename); |
| 1256 |
perror("error "); |
| 1257 |
exit(1); |
| 1258 |
} |
| 1259 |
} |
| 1260 |
if (flagpkt) { |
| 1261 |
strcpy(outfilename, ""); |
| 1262 |
strcpy(outfilename, memFile[i].FileName); |
| 1263 |
strcat(outfilename, ".pkt"); |
| 1264 |
if ((outfilepkt = fopen(outfilename, "w")) == NULL) { |
| 1265 |
printf("Error opening file %s for write \n", outfilename); |
| 1266 |
perror("error "); |
| 1267 |
exit(1); |
| 1268 |
} |
| 1269 |
} |
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
inputfilec = fopen(memFile[i].FileName, "rb"); |
| 1275 |
PRINTD(1,"File %s aperto\n", memFile[i].FileName); |
| 1276 |
if (inputfilec == 0) { |
| 1277 |
printf("Error opening file for aftersplit \n"); |
| 1278 |
perror("error "); |
| 1279 |
exit(1); |
| 1280 |
} else { |
| 1281 |
if (flagbit) { |
| 1282 |
intclosedbit = 0; |
| 1283 |
tempbitrate = 0; |
| 1284 |
} |
| 1285 |
if (flagjit) { |
| 1286 |
intclosedjit = 0; |
| 1287 |
tempjitter = 0; |
| 1288 |
pktjitter = 0; |
| 1289 |
} |
| 1290 |
if (flagdel) { |
| 1291 |
pktdelay = 0; |
| 1292 |
intcloseddel = 0; |
| 1293 |
tempdelay = 0; |
| 1294 |
} |
| 1295 |
if (flagpkt) { |
| 1296 |
intclosedpkt = 0; |
| 1297 |
temppktloss = 0; |
| 1298 |
pktpktloss = 0; |
| 1299 |
totalpktloss = 0; |
| 1300 |
} |
| 1301 |
flagfirstline = 0; |
| 1302 |
pktloss = 0; |
| 1303 |
pktdup = 0; |
| 1304 |
pktrecv = 0; |
| 1305 |
while (1) { |
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
PRINTD(1,"Prima di leggere le info dal file %s con puntantore %p\n", |
| 1310 |
memFile[i].FileName, inputfilec); |
| 1311 |
|
| 1312 |
size = fread(infos, sizeof(struct info), 1, inputfilec); |
| 1313 |
PRINTD(1,"Info lette dal file %s\n", memFile[i].FileName); |
| 1314 |
if (size == 0) { |
| 1315 |
if (flagbit) |
| 1316 |
fprintf(outfilebit, "%lf %lf\n", intclosedbit * (double) msbitrate / 1000, tempbitrate * 8 |
| 1317 |
/ msbitrate); |
| 1318 |
if (flagjit) |
| 1319 |
fprintf(outfilejit, "%lf %lf\n", intclosedjit * (double) msjitter / 1000, tempjitter |
| 1320 |
/ (double) (pktjitter - 1)); |
| 1321 |
if (flagdel) |
| 1322 |
fprintf(outfiledel, "%lf %lf\n", intcloseddel * (double) msdelay / 1000, tempdelay |
| 1323 |
/ (double) pktdelay); |
| 1324 |
if (flagpkt) |
| 1325 |
fprintf(outfilepkt, "%lf %lu\n", intclosedpkt * (double) mspktloss / 1000, temppktloss); |
| 1326 |
break; |
| 1327 |
} else { |
| 1328 |
pktrecv++; |
| 1329 |
if ((*infos).seqNum > (pktrecv + pktloss - pktdup)) { |
| 1330 |
pktloss = (*infos).seqNum - pktrecv; |
| 1331 |
} else if ((*infos).seqNum < (pktrecv + pktloss - pktdup)) { |
| 1332 |
pktdup++; |
| 1333 |
|
| 1334 |
} |
| 1335 |
secrxTime = (double) ((*infos).rxTime1 * 3600) + (double) ((*infos).rxTime2 * 60) |
| 1336 |
+ (*infos).rxTime3; |
| 1337 |
currentdelay = deltatime(((double) (*infos).txTime1 * 3600) + ((double) (*infos).txTime2 * 60) |
| 1338 |
+ ((*infos).txTime3), secrxTime); |
| 1339 |
if (!flagfirstline) { |
| 1340 |
flagfirstline = 1; |
| 1341 |
secfirstline_loc = secrxTime; |
| 1342 |
if (flagbit) { |
| 1343 |
secinitbitrate = secfirstline_gl; |
| 1344 |
} |
| 1345 |
if (flagjit) { |
| 1346 |
secinitjitter = secfirstline_gl; |
| 1347 |
lastdelay = currentdelay; |
| 1348 |
} |
| 1349 |
if (flagdel) { |
| 1350 |
secinitdelay = secfirstline_gl; |
| 1351 |
} |
| 1352 |
if (flagpkt) { |
| 1353 |
secinitpktloss = secfirstline_gl; |
| 1354 |
} |
| 1355 |
} |
| 1356 |
if (flagbit) { |
| 1357 |
if ((secrxTime - secinitbitrate) > (msbitrate / 1000)) { |
| 1358 |
|
| 1359 |
double temporary = deltatime(secfirstline_gl, secrxTime) * 1000 / msbitrate; |
| 1360 |
unsigned long int inttoclose = (unsigned long int) (ceil(temporary) - intclosedbit |
| 1361 |
- 1); |
| 1362 |
if (inttoclose > 0) { |
| 1363 |
|
| 1364 |
for (z = 1; z <= inttoclose; z++) { |
| 1365 |
|
| 1366 |
if (((double) ((intclosedbit + 1) * msbitrate / 1000) |
| 1367 |
+ secfirstline_gl) < secfirstline_loc) { |
| 1368 |
fprintf(outfilebit, "%lf %lf\n", intclosedbit |
| 1369 |
* (double) msbitrate / 1000, (double) 0); |
| 1370 |
} else { |
| 1371 |
fprintf(outfilebit, "%lf %lf\n", intclosedbit |
| 1372 |
* (double) msbitrate / 1000, tempbitrate * 8 |
| 1373 |
/ msbitrate); |
| 1374 |
tempbitrate = 0; |
| 1375 |
} |
| 1376 |
intclosedbit++; |
| 1377 |
} |
| 1378 |
} |
| 1379 |
secinitbitrate = (intclosedbit * msbitrate) / 1000 + secfirstline_gl; |
| 1380 |
} |
| 1381 |
|
| 1382 |
tempbitrate += (double) (*infos).size; |
| 1383 |
} |
| 1384 |
|
| 1385 |
if (flagjit) { |
| 1386 |
if ((secrxTime - secinitjitter) > (msjitter / 1000)) { |
| 1387 |
|
| 1388 |
double temporary = deltatime(secfirstline_gl, secrxTime) * 1000 / msjitter; |
| 1389 |
unsigned long int inttoclose = (unsigned long int) (ceil(temporary) - intclosedjit |
| 1390 |
- 1); |
| 1391 |
if (inttoclose > 0) { |
| 1392 |
|
| 1393 |
for (z = 1; z <= inttoclose; z++) { |
| 1394 |
|
| 1395 |
if (((double) ((intclosedjit + 1) * msjitter / 1000) |
| 1396 |
+ secfirstline_gl) < secfirstline_loc) { |
| 1397 |
fprintf(outfilejit, "%lf %lf\n", intclosedjit |
| 1398 |
* (double) msjitter / 1000, (double) 0); |
| 1399 |
} else { |
| 1400 |
if (pktjitter > 1) { |
| 1401 |
fprintf(outfilejit, "%lf %lf\n", intclosedjit |
| 1402 |
* (double) msjitter / 1000, tempjitter |
| 1403 |
/ (double) (pktjitter - 1)); |
| 1404 |
pktjitter = 1; |
| 1405 |
} else |
| 1406 |
fprintf(outfilejit, "%lf %lf\n", intclosedjit |
| 1407 |
* (double) msjitter / 1000, (double) 0); |
| 1408 |
tempjitter = 0; |
| 1409 |
|
| 1410 |
} |
| 1411 |
intclosedjit++; |
| 1412 |
} |
| 1413 |
} |
| 1414 |
secinitjitter = intclosedjit * msjitter / 1000 + secfirstline_gl; |
| 1415 |
} |
| 1416 |
tempjitter = tempjitter + fabs(currentdelay - lastdelay); |
| 1417 |
pktjitter++; |
| 1418 |
lastdelay = currentdelay; |
| 1419 |
} |
| 1420 |
|
| 1421 |
if (flagdel) { |
| 1422 |
if ((secrxTime - secinitdelay) > (msdelay / 1000)) { |
| 1423 |
|
| 1424 |
double temporary = deltatime(secfirstline_gl, secrxTime) * 1000 / msdelay; |
| 1425 |
unsigned long int inttoclose = (unsigned long int) (ceil(temporary) - intcloseddel |
| 1426 |
- 1); |
| 1427 |
if (inttoclose > 0) { |
| 1428 |
|
| 1429 |
for (z = 1; z <= inttoclose; z++) { |
| 1430 |
|
| 1431 |
if (((double) ((intcloseddel + 1) * (msdelay / 1000)) |
| 1432 |
+ secfirstline_gl) < secfirstline_loc) |
| 1433 |
fprintf(outfiledel, "%lf %lf\n", intcloseddel |
| 1434 |
* (double) msdelay / 1000, (double) 0); |
| 1435 |
else { |
| 1436 |
if (pktdelay > 0) { |
| 1437 |
fprintf(outfiledel, "%lf %lf\n", intcloseddel |
| 1438 |
* (double) msdelay / 1000, tempdelay |
| 1439 |
/ (double) pktdelay); |
| 1440 |
tempdelay = 0; |
| 1441 |
pktdelay = 0; |
| 1442 |
} else { |
| 1443 |
fprintf(outfiledel, "%lf %lf\n", intcloseddel |
| 1444 |
* (double) msdelay / 1000, (double) 0); |
| 1445 |
} |
| 1446 |
} |
| 1447 |
intcloseddel++; |
| 1448 |
} |
| 1449 |
} |
| 1450 |
secinitdelay = intcloseddel * msdelay / 1000 + secfirstline_gl; |
| 1451 |
} |
| 1452 |
tempdelay = tempdelay + currentdelay; |
| 1453 |
pktdelay++; |
| 1454 |
} |
| 1455 |
|
| 1456 |
if (flagpkt) { |
| 1457 |
if ((secrxTime - secinitpktloss) > (mspktloss / 1000)) { |
| 1458 |
|
| 1459 |
double temporary = deltatime(secfirstline_gl, secrxTime) * 1000 / mspktloss; |
| 1460 |
unsigned long int inttoclose = (unsigned long int) (ceil(temporary) - intclosedpkt |
| 1461 |
- 1); |
| 1462 |
if (inttoclose > 0) { |
| 1463 |
|
| 1464 |
for (z = 1; z <= inttoclose; z++) { |
| 1465 |
|
| 1466 |
if (((double) ((intclosedpkt + 1) * mspktloss / 1000) |
| 1467 |
+ secfirstline_gl) < secfirstline_loc) |
| 1468 |
fprintf(outfilepkt, "%lf %lu\n", intclosedpkt |
| 1469 |
* (double) mspktloss / 1000, (unsigned long int) 0); |
| 1470 |
else { |
| 1471 |
fprintf(outfilepkt, "%lf %lu\n", intclosedpkt |
| 1472 |
* (double) mspktloss / 1000, temppktloss); |
| 1473 |
temppktloss = 0; |
| 1474 |
} |
| 1475 |
intclosedpkt++; |
| 1476 |
} |
| 1477 |
} |
| 1478 |
secinitpktloss = intclosedpkt * mspktloss / 1000 + secfirstline_gl; |
| 1479 |
} |
| 1480 |
pktpktloss++; |
| 1481 |
if ((*infos).seqNum > (pktpktloss + totalpktloss)) { |
| 1482 |
temppktloss = temppktloss + (*infos).seqNum - pktpktloss - totalpktloss; |
| 1483 |
totalpktloss = (*infos).seqNum - pktpktloss; |
| 1484 |
} |
| 1485 |
} |
| 1486 |
} |
| 1487 |
} |
| 1488 |
} |
| 1489 |
i++; |
| 1490 |
|
| 1491 |
|
| 1492 |
fclose(inputfilec); |
| 1493 |
|
| 1494 |
if (flagbit) |
| 1495 |
fclose(outfilebit); |
| 1496 |
if (flagjit) |
| 1497 |
fclose(outfilejit); |
| 1498 |
if (flagdel) |
| 1499 |
fclose(outfiledel); |
| 1500 |
if (flagpkt) |
| 1501 |
fclose(outfilepkt); |
| 1502 |
} |
| 1503 |
} |
| 1504 |
|
| 1505 |
|
| 1506 |
void merge(int type) |
| 1507 |
{ |
| 1508 |
|
| 1509 |
|
| 1510 |
int i = 0, finishedfiles, flagfirstfile; |
| 1511 |
unsigned int flagbreak; |
| 1512 |
FILE *fpout = 0; |
| 1513 |
double time, value, valuesum; |
| 1514 |
char extension[5] = ""; |
| 1515 |
char colname[fileNameSize] = ""; |
| 1516 |
|
| 1517 |
|
| 1518 |
switch (type) { |
| 1519 |
case 1: |
| 1520 |
strcpy(extension, ".bit\0"); |
| 1521 |
if ((fpout = fopen(bitratefile, "w")) == NULL) { |
| 1522 |
printf("Error opening file 'bitrate.dat' for write"); |
| 1523 |
perror("error "); |
| 1524 |
exit(1); |
| 1525 |
} |
| 1526 |
break; |
| 1527 |
case 2: |
| 1528 |
strcpy(extension, ".jit\0"); |
| 1529 |
if ((fpout = fopen(jitterfile, "w")) == NULL) { |
| 1530 |
printf("Error opening file 'jitter.dat' for write"); |
| 1531 |
perror("error "); |
| 1532 |
exit(1); |
| 1533 |
} |
| 1534 |
break; |
| 1535 |
case 3: |
| 1536 |
strcpy(extension, ".del\0"); |
| 1537 |
if ((fpout = fopen(delayfile, "w")) == NULL) { |
| 1538 |
printf("Error opening file 'delay.dat' for write"); |
| 1539 |
perror("error "); |
| 1540 |
exit(1); |
| 1541 |
} |
| 1542 |
break; |
| 1543 |
case 4: |
| 1544 |
strcpy(extension, ".pkt\0"); |
| 1545 |
if ((fpout = fopen(pktlossfile, "w")) == NULL) { |
| 1546 |
printf("Error opening file 'pktloss.dat' for write"); |
| 1547 |
perror("error "); |
| 1548 |
exit(1); |
| 1549 |
} |
| 1550 |
break; |
| 1551 |
} |
| 1552 |
|
| 1553 |
fprintf(fpout, "Time"); |
| 1554 |
|
| 1555 |
while (memFile[i].flowId != (unsigned int) -1) { |
| 1556 |
char tempfilename[fileNameSize] = ""; |
| 1557 |
strcat(tempfilename, memFile[i].FileName); |
| 1558 |
strcat(tempfilename, extension); |
| 1559 |
if ((memFile[i].tempfile = fopen(tempfilename, "r")) == NULL) { |
| 1560 |
printf("\n Error opening log file '%s'\n", tempfilename); |
| 1561 |
perror("error "); |
| 1562 |
exit(1); |
| 1563 |
} |
| 1564 |
|
| 1565 |
sprintf(colname, "%u", memFile[i].flowId); |
| 1566 |
strcat(colname, "-"); |
| 1567 |
strcat(colname, memFile[i].srcAddr); |
| 1568 |
strcat(colname, "-"); |
| 1569 |
strcat(colname, memFile[i].destAddr); |
| 1570 |
fprintf(fpout, " %s", colname); |
| 1571 |
strcpy(colname, ""); |
| 1572 |
|
| 1573 |
i++; |
| 1574 |
} |
| 1575 |
fprintf(fpout, " Aggregate-Flow\n"); |
| 1576 |
while (1) { |
| 1577 |
flagfirstfile = 0; |
| 1578 |
i = 0; |
| 1579 |
flagbreak = 0; |
| 1580 |
finishedfiles = 0; |
| 1581 |
valuesum = 0; |
| 1582 |
while (memFile[i].flowId != (unsigned int) -1) { |
| 1583 |
if (fscanf(memFile[i].tempfile, "%lf %lf\n", &time, &value) == EOF) { |
| 1584 |
flagbreak++; |
| 1585 |
finishedfiles++; |
| 1586 |
} else { |
| 1587 |
valuesum = valuesum + value; |
| 1588 |
if (!flagfirstfile) { |
| 1589 |
flagfirstfile = 1; |
| 1590 |
fprintf(fpout, "%lf", time); |
| 1591 |
} |
| 1592 |
while (finishedfiles > 0) { |
| 1593 |
fprintf(fpout, " %lf", (double) 0); |
| 1594 |
finishedfiles--; |
| 1595 |
} |
| 1596 |
fprintf(fpout, " %lf", value); |
| 1597 |
} |
| 1598 |
i++; |
| 1599 |
if ((memFile[i].flowId == (unsigned int) -1) && (flagbreak != flownum)) { |
| 1600 |
|
| 1601 |
while (finishedfiles > 0) { |
| 1602 |
fprintf(fpout, " %lf", (double) 0); |
| 1603 |
finishedfiles--; |
| 1604 |
} |
| 1605 |
fprintf(fpout, " %lf\n", valuesum); |
| 1606 |
} |
| 1607 |
} |
| 1608 |
if (flagbreak == flownum) |
| 1609 |
break; |
| 1610 |
} |
| 1611 |
i = 0; |
| 1612 |
while (memFile[i].flowId != (unsigned int) -1) { |
| 1613 |
fclose(memFile[i].tempfile); |
| 1614 |
i++; |
| 1615 |
} |
| 1616 |
fclose(fpout); |
| 1617 |
} |
| 1618 |
|
| 1619 |
void mergeCombined() { |
| 1620 |
int i = 0, flagfirstfile; |
| 1621 |
unsigned int flagbreak; |
| 1622 |
FILE *fpout = 0; |
| 1623 |
double time, value, valuesum_bit, valuesum_del, valuesum_jit, valuesum_pkt; |
| 1624 |
char tempfilename[fileNameSize] = ""; |
| 1625 |
|
| 1626 |
if ((fpout = fopen(combinedstatsfile, "w")) == NULL) { |
| 1627 |
printf("Error opening file 'combinedstatsfile.txt' for write"); |
| 1628 |
perror("error "); |
| 1629 |
exit(1); |
| 1630 |
} |
| 1631 |
|
| 1632 |
while (memFile[i].flowId != (unsigned int) -1) { |
| 1633 |
strcpy(tempfilename, ""); |
| 1634 |
strcat(tempfilename, memFile[i].FileName); |
| 1635 |
strcat(tempfilename, ".bit\0"); |
| 1636 |
if ((memFile[i].tempfile_bit = fopen(tempfilename, "r")) == NULL) { |
| 1637 |
printf("\n Error opening log file '%s'\n", tempfilename); |
| 1638 |
perror("error "); |
| 1639 |
exit(1); |
| 1640 |
} |
| 1641 |
|
| 1642 |
strcpy(tempfilename, ""); |
| 1643 |
strcat(tempfilename, memFile[i].FileName); |
| 1644 |
strcat(tempfilename, ".del\0"); |
| 1645 |
if ((memFile[i].tempfile_del = fopen(tempfilename, "r")) == NULL) { |
| 1646 |
printf("\n Error opening log file '%s'\n", tempfilename); |
| 1647 |
perror("error "); |
| 1648 |
exit(1); |
| 1649 |
} |
| 1650 |
|
| 1651 |
strcpy(tempfilename, ""); |
| 1652 |
strcat(tempfilename, memFile[i].FileName); |
| 1653 |
strcat(tempfilename, ".jit\0"); |
| 1654 |
if ((memFile[i].tempfile_jit = fopen(tempfilename, "r")) == NULL) { |
| 1655 |
printf("\n Error opening log file '%s'\n", tempfilename); |
| 1656 |
perror("error "); |
| 1657 |
exit(1); |
| 1658 |
} |
| 1659 |
|
| 1660 |
strcpy(tempfilename, ""); |
| 1661 |
strcat(tempfilename, memFile[i].FileName); |
| 1662 |
strcat(tempfilename, ".pkt\0"); |
| 1663 |
if ((memFile[i].tempfile_pkt = fopen(tempfilename, "r")) == NULL) { |
| 1664 |
printf("\n Error opening log file '%s'\n", tempfilename); |
| 1665 |
perror("error "); |
| 1666 |
exit(1); |
| 1667 |
} |
| 1668 |
i++; |
| 1669 |
} |
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
while (1) { |
| 1675 |
flagfirstfile = 0; |
| 1676 |
i = 0; |
| 1677 |
flagbreak = 0; |
| 1678 |
valuesum_bit = 0; |
| 1679 |
valuesum_del = 0; |
| 1680 |
valuesum_jit = 0; |
| 1681 |
valuesum_pkt = 0; |
| 1682 |
while (memFile[i].flowId != (unsigned int) -1) { |
| 1683 |
|
| 1684 |
value = -1; |
| 1685 |
if (fscanf(memFile[i].tempfile_bit, "%lf %lf\n", &time, &value) == EOF) { |
| 1686 |
flagbreak++; |
| 1687 |
} else { |
| 1688 |
if (!flagfirstfile) { |
| 1689 |
flagfirstfile = 1; |
| 1690 |
fprintf(fpout, "%lf", time); |
| 1691 |
} |
| 1692 |
valuesum_bit += value; |
| 1693 |
|
| 1694 |
|
| 1695 |
value = -1; |
| 1696 |
fscanf(memFile[i].tempfile_del, "%lf %lf\n", &time, &value); |
| 1697 |
valuesum_del += value; |
| 1698 |
|
| 1699 |
|
| 1700 |
value = -1; |
| 1701 |
fscanf(memFile[i].tempfile_jit, "%lf %lf\n", &time, &value); |
| 1702 |
valuesum_jit += value; |
| 1703 |
|
| 1704 |
|
| 1705 |
value = -1; |
| 1706 |
fscanf(memFile[i].tempfile_pkt, "%lf %lf\n", &time, &value); |
| 1707 |
valuesum_pkt += value; |
| 1708 |
} |
| 1709 |
i++; |
| 1710 |
|
| 1711 |
if ((memFile[i].flowId == (unsigned int) -1) && (flagbreak != flownum)) { |
| 1712 |
fprintf(fpout, " %lf %lf %lf %lf\n", valuesum_bit, valuesum_del, valuesum_jit, valuesum_pkt); |
| 1713 |
} |
| 1714 |
} |
| 1715 |
if (flagbreak == flownum) |
| 1716 |
break; |
| 1717 |
} |
| 1718 |
|
| 1719 |
|
| 1720 |
i = 0; |
| 1721 |
while (memFile[i].flowId != (unsigned int) -1) { |
| 1722 |
fclose(memFile[i].tempfile_bit); |
| 1723 |
fclose(memFile[i].tempfile_del); |
| 1724 |
fclose(memFile[i].tempfile_jit); |
| 1725 |
fclose(memFile[i].tempfile_pkt); |
| 1726 |
i++; |
| 1727 |
} |
| 1728 |
fclose(fpout); |
| 1729 |
} |
| 1730 |
|
| 1731 |
void printhelp() |
| 1732 |
{ |
| 1733 |
cout << "\nITGDec - Decoder component of D-ITG platform\n"; |
| 1734 |
|
| 1735 |
cout << "\n Synopsis\n\n"; |
| 1736 |
|
| 1737 |
cout << " ./ITGDec <logfile> [options]\n"; |
| 1738 |
|
| 1739 |
cout << "\n Options\n\n" |
| 1740 |
|
| 1741 |
" -v Print standard summary to stdout (default).\n\n" |
| 1742 |
|
| 1743 |
" -l <txtlog> Print to <txtlog> the decoded log in text format.\n\n" |
| 1744 |
|
| 1745 |
" -t Interpret <logfile> as in text format.\n\n" |
| 1746 |
|
| 1747 |
" -o <outfile> Print to <outfile> the decoded log for Octave/Matlab import.\n\n" |
| 1748 |
|
| 1749 |
" -r <sender_log> Generate combined log file starting from receiver- and sender-side log files\n" |
| 1750 |
" [combined_log] (default filename: 'combined.dat').\n\n" |
| 1751 |
|
| 1752 |
" -d <DT> [filename] Print average delay to file every <DT> milliseconds\n" |
| 1753 |
" (default filename: 'delay.dat').\n\n" |
| 1754 |
|
| 1755 |
" -j <JT> [filename] Print average jitter to file every <JT> milliseconds\n" |
| 1756 |
" (default filename: 'jitter.dat').\n\n" |
| 1757 |
|
| 1758 |
" -b <BT> [filename] Print average bitrate to file every <BT> milliseconds\n" |
| 1759 |
" (default filename: 'bitrate.dat').\n\n" |
| 1760 |
|
| 1761 |
" -p <PT> [filename] Print average packet loss to file every <PT> milliseconds\n" |
| 1762 |
" (default filename: 'packetloss.dat').\n\n" |
| 1763 |
|
| 1764 |
" -c <CT> [filename] Print all average metrics to file every <CT> milliseconds\n" |
| 1765 |
" (default filename: 'combined_stats.dat').\n\n" |
| 1766 |
|
| 1767 |
" -s <suffix> Generate a separate log file for each flow adding a suffix to its name\n" |
| 1768 |
" (default suffix: log).\n\n" |
| 1769 |
|
| 1770 |
" -f <flownum> Consider only flows with number <= <flownum>.\n" |
| 1771 |
" Setting <flownum> to 't' all packets are considered as part of the same flow.\n\n" |
| 1772 |
|
| 1773 |
" -P Print to stdout the size of each packet.\n\n" |
| 1774 |
|
| 1775 |
" -I Print to stdout the inter departure time between each packet pair.\n\n" |
| 1776 |
|
| 1777 |
|
| 1778 |
" -h | --help Display this help and exit\n\n"; |
| 1779 |
|
| 1780 |
cout << "\nFor more information please refer to the manual.\n"; |
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
} |