aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--src/akcom-udpecho.c145
1 files changed, 85 insertions, 60 deletions
diff --git a/src/akcom-udpecho.c b/src/akcom-udpecho.c
index 888a2b4..365ca2a 100644
--- a/src/akcom-udpecho.c
+++ b/src/akcom-udpecho.c
@@ -168,6 +168,13 @@ main(
168 char * argv[] ); 168 char * argv[] );
169 169
170 170
171static int
172my_loop(
173 int s,
174 echoplus_t * rcvbuff,
175 echoplus_t * sndbuff );
176
177
171int 178int
172my_socket( 179my_socket(
173 const char * host, 180 const char * host,
@@ -211,25 +218,8 @@ main(
211 int c; 218 int c;
212 int s; 219 int s;
213 int fd; 220 int fd;
214 int rc;
215 int opt_index; 221 int opt_index;
216 uint32_t count;
217 uint32_t rcvd;
218 uint64_t epoch;
219 uint64_t epoch_adj;
220 uint64_t epoch_max;
221 uint64_t delay;
222 uint64_t max;
223 uint64_t max_adj;
224 uint64_t min;
225 uint64_t min_adj;
226 uint64_t avg;
227 uint64_t avg_adj;
228 ssize_t size;
229 char * ptr; 222 char * ptr;
230 struct timespec start;
231 struct timespec now;
232 struct pollfd fds[2];
233 echoplus_t * sndbuff; 223 echoplus_t * sndbuff;
234 echoplus_t * rcvbuff; 224 echoplus_t * rcvbuff;
235 225
@@ -396,6 +386,50 @@ main(
396 free(rcvbuff); 386 free(rcvbuff);
397 return(1); 387 return(1);
398 }; 388 };
389
390 if ((my_loop(s, rcvbuff, sndbuff)))
391 {
392 free(sndbuff);
393 free(rcvbuff);
394 close(s);
395 return(1);
396 };
397
398 // free resources
399 free(sndbuff);
400 free(rcvbuff);
401 close(s);
402
403
404 return(0);
405}
406
407
408int
409my_loop(
410 int s,
411 echoplus_t * rcvbuff,
412 echoplus_t * sndbuff )
413{
414 int rc;
415 uint64_t epoch;
416 uint64_t epoch_adj;
417 uint64_t epoch_max;
418 uint64_t delay;
419 uint32_t stats_sent;
420 uint32_t stats_rcvd;
421 uint64_t stats_max;
422 uint64_t stats_max_adj;
423 uint64_t stats_min;
424 uint64_t stats_min_adj;
425 uint64_t stats_avg;
426 uint64_t stats_avg_adj;
427 ssize_t size;
428 struct pollfd fds[2];
429 struct timespec start;
430 struct timespec now;
431
432 // initialize poller data
399 fds[0].fd = s; 433 fds[0].fd = s;
400 fds[0].events = POLLIN; 434 fds[0].events = POLLIN;
401 fds[0].revents = 0; 435 fds[0].revents = 0;
@@ -404,15 +438,14 @@ main(
404 fds[1].revents = 0; 438 fds[1].revents = 0;
405 439
406 // initialize statistics 440 // initialize statistics
407 count = 0; 441 stats_sent = 0;
408 rcvd = 0; 442 stats_rcvd = 0;
409 min = 0; 443 stats_min = 0;
410 min_adj = 0; 444 stats_min_adj = 0;
411 max = 0; 445 stats_max = 0;
412 max_adj = 0; 446 stats_max_adj = 0;
413 avg = 0; 447 stats_avg = 0;
414 avg_adj = 0; 448 stats_avg_adj = 0;
415
416 449
417 // start clock 450 // start clock
418 clock_gettime(CLOCK_MONOTONIC_RAW, &start); 451 clock_gettime(CLOCK_MONOTONIC_RAW, &start);
@@ -428,19 +461,19 @@ main(
428 epoch -= ((uint64_t)start.tv_sec * 10000) + ((uint64_t)start.tv_nsec / 100000); 461 epoch -= ((uint64_t)start.tv_sec * 10000) + ((uint64_t)start.tv_nsec / 100000);
429 462
430 // trigger stop 463 // trigger stop
431 if ( ((cnf_count)) && (count >= cnf_count) ) 464 if ( ((cnf_count)) && (stats_sent >= cnf_count) )
432 { 465 {
433 epoch_max = cnf_count * (uint64_t)cnf_interval * 10000; 466 epoch_max = cnf_count * (uint64_t)cnf_interval * 10000;
434 epoch_max += (uint64_t)cnf_timeout * 10000; 467 epoch_max += (uint64_t)cnf_timeout * 10000;
435 if (( epoch >= epoch_max) || (rcvd >= count)) 468 if (( epoch >= epoch_max) || (stats_rcvd >= stats_sent))
436 should_stop = 1; 469 should_stop = 1;
437 }; 470 };
438 471
439 // send UDP echo request 472 // send UDP echo request
440 if ((count < (epoch/(10000*cnf_interval))) && ((count < cnf_count) || (!(cnf_count))) ) 473 if ((stats_sent < (epoch/(10000*cnf_interval))) && ((stats_sent < cnf_count) || (!(cnf_count))) )
441 { 474 {
442 count++; 475 stats_sent++;
443 sndbuff->req_sn = htonl(count); 476 sndbuff->req_sn = htonl((uint32_t)stats_sent);
444 send(s, sndbuff, cnf_packetsize, 0); 477 send(s, sndbuff, cnf_packetsize, 0);
445 }; 478 };
446 479
@@ -462,21 +495,21 @@ main(
462 printf(" Failures: %08" PRIx32 "\n", rcvbuff->failures); 495 printf(" Failures: %08" PRIx32 "\n", rcvbuff->failures);
463 printf(" Iteration: %08" PRIx32 "\n", rcvbuff->iteration); 496 printf(" Iteration: %08" PRIx32 "\n", rcvbuff->iteration);
464 }; 497 };
465 rcvd++; 498 stats_rcvd++;
466 delay = rcvbuff->reply_time - rcvbuff->recv_time; 499 delay = rcvbuff->reply_time - rcvbuff->recv_time;
467 delay /= 100000000; 500 delay /= 100000000;
468 epoch -= (rcvbuff->req_sn * 10000); 501 epoch -= (rcvbuff->req_sn * 10000);
469 epoch_adj = epoch - delay; 502 epoch_adj = epoch - delay;
470 avg += epoch; 503 stats_avg += epoch;
471 avg_adj += epoch_adj; 504 stats_avg_adj += epoch_adj;
472 if ( (!(min)) || (epoch < min) ) 505 if ( (!(stats_min)) || (epoch < stats_min) )
473 min = epoch; 506 stats_min = epoch;
474 if ( (!(max)) || (epoch > max) ) 507 if ( (!(stats_max)) || (epoch > stats_max) )
475 max = epoch; 508 stats_max = epoch;
476 if ( (!(min_adj)) || (epoch_adj < min_adj) ) 509 if ( (!(stats_min_adj)) || (epoch_adj < stats_min_adj) )
477 min_adj = epoch_adj; 510 stats_min_adj = epoch_adj;
478 if ( (!(max_adj)) || (epoch_adj > max_adj) ) 511 if ( (!(stats_max_adj)) || (epoch_adj > stats_max_adj) )
479 max_adj = epoch_adj; 512 stats_max_adj = epoch_adj;
480 if ((cnf_echoplus)) 513 if ((cnf_echoplus))
481 { 514 {
482 printf("udpecho_seq=%u failures=%" PRIu32 " time=%" PRIu64 ".%" PRIu64 " ms delay=%" PRIu64 ".%" PRIu64 " ms adj_time=%" PRIu64 ".%" PRIu64 " ms\n", 515 printf("udpecho_seq=%u failures=%" PRIu32 " time=%" PRIu64 ".%" PRIu64 " ms delay=%" PRIu64 ".%" PRIu64 " ms adj_time=%" PRIu64 ".%" PRIu64 " ms\n",
@@ -500,39 +533,31 @@ main(
500 }; 533 };
501 }; 534 };
502 535
503
504 if (!(cnf_silent)) 536 if (!(cnf_silent))
505 { 537 {
506 printf("\n"); 538 printf("\n");
507 printf("--- %s udpecho statistics ---\n", cnf_host); 539 printf("--- %s udpecho statistics ---\n", cnf_host);
508 printf("%i packets transmitted, %i packets received, %i.%i%% packet loss\n", 540 printf("%i packets transmitted, %i packets received, %i.%i%% packet loss\n",
509 count, 541 stats_sent,
510 rcvd, 542 stats_rcvd,
511 ((count - rcvd) * 100) / count, 543 ((stats_sent - stats_rcvd) * 100) / stats_sent,
512 (((count - rcvd) * 1000) / count) % 10 544 (((stats_sent - stats_rcvd) * 1000) / stats_sent) % 10
513 ); 545 );
514 printf("round-trip min/avg/max = %" PRIu64 ".%" PRIu64 "/%" PRIu64 ".%" PRIu64 "/%" PRIu64 ".%" PRIu64 " ms\n", 546 printf("round-trip min/avg/max = %" PRIu64 ".%" PRIu64 "/%" PRIu64 ".%" PRIu64 "/%" PRIu64 ".%" PRIu64 " ms\n",
515 min/10, min%10, 547 stats_min/10, stats_min%10,
516 (avg/rcvd)/10, (avg/rcvd)%10, 548 (stats_avg/stats_rcvd)/10, (stats_avg/stats_rcvd)%10,
517 max/10, max%10 549 stats_max/10, stats_max%10
518 ); 550 );
519 if ((cnf_echoplus)) 551 if ((cnf_echoplus))
520 { 552 {
521 printf("adjusted round-trip min/avg/max = %" PRIu64 ".%" PRIu64 "/%" PRIu64 ".%" PRIu64 "/%" PRIu64 ".%" PRIu64 " ms\n", 553 printf("adjusted round-trip min/avg/max = %" PRIu64 ".%" PRIu64 "/%" PRIu64 ".%" PRIu64 "/%" PRIu64 ".%" PRIu64 " ms\n",
522 min_adj/10, min_adj%10, 554 stats_min_adj/10, stats_min_adj%10,
523 (avg_adj/rcvd)/10, (avg_adj/rcvd)%10, 555 (stats_avg_adj/stats_rcvd)/10, (stats_avg_adj/stats_rcvd)%10,
524 max_adj/10, max_adj%10 556 stats_max_adj/10, stats_max_adj%10
525 ); 557 );
526 }; 558 };
527 }; 559 };
528 560
529
530 // free resources
531 free(sndbuff);
532 free(rcvbuff);
533 close(s);
534
535
536 return(0); 561 return(0);
537} 562}
538 563