-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.c
1851 lines (1600 loc) · 62.7 KB
/
output.c
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
* 2002, 2003, 2004
* Ohio University.
*
* ---
*
* Starting with the release of tcptrace version 6 in 2001, tcptrace
* is licensed under the GNU General Public License (GPL). We believe
* that, among the available licenses, the GPL will do the best job of
* allowing tcptrace to continue to be a valuable, freely-available
* and well-maintained tool for the networking community.
*
* Previous versions of tcptrace were released under a license that
* was much less restrictive with respect to how tcptrace could be
* used in commercial products. Because of this, I am willing to
* consider alternate license arrangements as allowed in Section 10 of
* the GNU GPL. Before I would consider licensing tcptrace under an
* alternate agreement with a particular individual or company,
* however, I would have to be convinced that such an alternative
* would be to the greater benefit of the networking community.
*
* ---
*
* This file is part of Tcptrace.
*
* Tcptrace was originally written and continues to be maintained by
* Shawn Ostermann with the help of a group of devoted students and
* users (see the file 'THANKS'). The work on tcptrace has been made
* possible over the years through the generous support of NASA GRC,
* the National Science Foundation, and Sun Microsystems.
*
* Tcptrace is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Tcptrace is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tcptrace (in the file 'COPYING'); if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Author: Shawn Ostermann
* School of Electrical Engineering and Computer Science
* Ohio University
* Athens, OH
* http://www.tcptrace.org/
*/
#include "tcptrace.h"
static char const GCC_UNUSED copyright[] =
"@(#)Copyright (c) 2004 -- Ohio University.\n";
static char const GCC_UNUSED rcsid[] =
"@(#)$Header: /usr/local/cvs/tcptrace/output.c,v 5.25 2003/11/19 14:38:04 sdo Exp $";
#include "gcache.h"
/* local routines */
static double Average(double, int);
static double Stdev(double, double, int);
static void StatLineP(char *, char *, char *, void *, void *);
static void StatLineI_L(char *, char *, u_long, u_long);
#ifdef HAVE_LONG_LONG
static void StatLineI_LL(char *, char *, u_llong, u_llong);
static void StatLineFieldL(char *, char *, char *, u_llong, int);
#endif /* HAVE_LONG_LONG */
static void StatLineF(char *, char *, char *, double, double);
static void StatLineField(char *, char *, char *, u_long, int);
static void StatLineFieldF(char *, char *, char *, double, int);
static void StatLineOne(char *, char *, char *);
static char *FormatBrief(tcp_pair *ptp);
static char *UDPFormatBrief(udp_pair *pup);
/* locally global variables*/
static u_int sv_print_count = 0;
static u_int sv_expected_count = 0;
/* global variables */
char *sp; /* Separator used for long output with <SP>-separated-values */
/* to support some of the counters being long long on some platforms, use this */
/* macro... */
#ifdef HAVE_LONG_LONG
#define StatLineI(label,units,ul1,ul2) \
(sizeof((ul1)) == SIZEOF_UNSIGNED_LONG_LONG_INT)?\
StatLineI_LL((label),(units),(ul1),(ul2)):\
StatLineI_L ((label),(units),(ul1),(ul2))
#else /* HAVE_LONG_LONG */
#define StatLineI StatLineI_L
#endif /* HAVE_LONG_LONG */
/*TCP specific funcions */
u_int
SynCount(
tcp_pair *ptp)
{
tcb *pab = &ptp->a2b;
tcb *pba = &ptp->b2a;
return(((pab->syn_count >= 1)?1:0) +
((pba->syn_count >= 1)?1:0));
}
u_int
FinCount(
tcp_pair *ptp)
{
tcb *pab = &ptp->a2b;
tcb *pba = &ptp->b2a;
return(((pab->fin_count >= 1)?1:0) +
((pba->fin_count >= 1)?1:0));
}
int
ConnComplete(
tcp_pair *ptp)
{
return(SynCount(ptp) >= 2 && FinCount(ptp) >= 2);
}
int
ConnReset(
tcp_pair *ptp)
{
return(ptp->a2b.reset_count + ptp->b2a.reset_count != 0);
}
/*SCTP specific funcions */
data_info
GetDataInfo(
tcb *thisdir,
tt_uint16 streamid)
{
stream_info* current_stream;
current_stream = thisdir->stream_list;
data_info not_found;
not_found.data_count = 0;
if(current_stream == NULL)
return not_found;
while(current_stream != NULL){
if(current_stream->stream_id == streamid)
return current_stream->datainfo;
current_stream = current_stream->pnext;
}
return not_found;
}
u_int
InitCount(
tcp_pair *ptp)
{
tcb *pab = &ptp->a2b;
tcb *pba = &ptp->b2a;
return(((pab->init_count >= 1)?1:0) +
((pba->init_count >= 1)?1:0));
}
u_int
ShutdownCount(
tcp_pair *ptp)
{
tcb *pab = &ptp->a2b;
tcb *pba = &ptp->b2a;
return(((pab->shutdown_count >= 1)?1:0) +
((pba->shutdown_count >= 1)?1:0));
}
int
SctpConnComplete(
tcp_pair *ptp)
{
tcb *pab = &ptp->a2b;
tcb *pba = &ptp->b2a;
return((pab->shutdown_complete_count >= 1 ||
pba->shutdown_complete_count >= 1)?1:0);
}
int
ConnAbort(
tcp_pair *ptp)
{
return(ptp->a2b.abort_count + ptp->b2a.abort_count != 0);
}
u_llong
UniqueStreamCounter(
tcp_pair *ptp,
stream_info **unique_stream_list)
{
u_llong unique = ptp->a2b.stream_count;
u_llong unique2 = ptp->b2a.stream_count;
stream_info *b2aTemp = ptp->b2a.stream_list;
stream_info *a2bTemp = ptp->a2b.stream_list;
stream_info *last;
while(a2bTemp != NULL){
b2aTemp = ptp->b2a.stream_list;
while(b2aTemp != NULL){
if (b2aTemp->stream_id == a2bTemp->stream_id){
unique2--;
}
b2aTemp = b2aTemp->pnext;
}
if (*unique_stream_list == NULL ){
*unique_stream_list = malloc(sizeof(stream_info));
(*unique_stream_list)->pnext = NULL;
(*unique_stream_list)->stream_id = a2bTemp->stream_id;
last = *unique_stream_list;
}
else{
stream_info *si = malloc(sizeof(stream_info));
last->pnext = si;
si->stream_id = a2bTemp->stream_id;
si->pnext = NULL;
last = si;
}
a2bTemp = a2bTemp->pnext;
}
return unique + unique2;
}
static double
Average(
double sum,
int count)
{
return((double) sum / ((double)count+.0001));
}
static double
Stdev(
double sum,
double sum2,
int n)
{
double term;
double term1;
double term2;
double retval;
if (n<=2)
return(0.0);
term1 = sum2;
term2 = (sum * sum) / (double)n;
term = term1-term2;
term /= (double)(n-1);
retval = sqrt(term);
/* printf("Stdev(%f,%f,%d) is %f\n", sum,sum2,n,retval); */
return(retval);
}
static char *
FormatBrief(
tcp_pair *ptp)
{
tcb *pab = &ptp->a2b;
tcb *pba = &ptp->b2a;
static char infobuf[100];
snprintf(infobuf,sizeof(infobuf),"%s - %s (%s2%s)",
ptp->a_endpoint, ptp->b_endpoint,
pab->host_letter, pba->host_letter);
return(infobuf);
}
void
PrintTrace(
tcp_pair *ptp)
{
double etime;
u_long etime_secs;
u_long etime_usecs;
double etime_data1;
double etime_data2;
tcb *pab = &ptp->a2b;
tcb *pba = &ptp->b2a;
char *host1 = pab->host_letter;
char *host2 = pba->host_letter;
char bufl[40],bufr[40];
/*print which print-function we are using*/
printf("\n----------------TCP-PRINT----------------\n");
/* counters to use for seq. space wrap around calculations
*/
u_llong stream_length_pab=0, stream_length_pba=0;
u_long pab_last, pba_last;
/* Reset the counter for each connection */
sv_print_count = 1; /* The first field (conn_#) gets printed in trace.c */
/* calculate elapsed time */
etime = elapsed(ptp->first_time,ptp->last_time);
etime_secs = etime / 1000000.0;
etime_usecs = 1000000 * (etime/1000000.0 - (double)etime_secs);
/* Check if comma-separated-values or tab-separated-values
* has been requested.
*/
if(csv || tsv || (sv != NULL)) {
fprintf(stdout,"%s%s%s%s%s%s%s%s",
ptp->a_hostname, sp, ptp->b_hostname, sp,
ptp->a_portname, sp, ptp->b_portname, sp);
sv_print_count += 4;
/* Print the start and end times. In other words,
* print the time of the first and the last packet
*/
fprintf(stdout,"%ld.%ld %s %ld.%ld %s",
(long)ptp->first_time.tv_sec, (long)ptp->first_time.tv_usec, sp,
(long)ptp->last_time.tv_sec, (long)ptp->last_time.tv_usec, sp);
sv_print_count += 2;
}
else {
fprintf(stdout,"\thost %-4s %s\n",
(snprintf(bufl,sizeof(bufl),"%s:", host1),bufl), ptp->a_endpoint);
fprintf(stdout,"\thost %-4s %s\n",
(snprintf(bufl,sizeof(bufl),"%s:", host2),bufl), ptp->b_endpoint);
fprintf(stdout,"\tcomplete conn: %s",
ConnReset(ptp)?"RESET":(
ConnComplete(ptp)?"yes":"no"));
if (ConnComplete(ptp))
fprintf(stdout,"\n");
else
fprintf(stdout,"\t(SYNs: %u) (FINs: %u)\n",
SynCount(ptp), FinCount(ptp));
fprintf(stdout,"\tfirst packet: %s\n", ts2ascii(&ptp->first_time));
fprintf(stdout,"\tlast packet: %s\n", ts2ascii(&ptp->last_time));
fprintf(stdout,"\telapsed time: %s\n", elapsed2str(etime));
fprintf(stdout,"\ttotal packets: %" FS_ULL "\n", ptp->packets);
fprintf(stdout,"\tfilename: %s\n", ptp->filename);
fprintf(stdout," %s->%s: %s->%s:\n",
host1,host2,host2,host1);
}
StatLineI("total packets","", pab->packets, pba->packets);
if (pab->reset_count || pba->reset_count || csv || tsv || (sv != NULL))
StatLineI("resets sent","", pab->reset_count, pba->reset_count);
StatLineI("ack pkts sent","", pab->ack_pkts, pba->ack_pkts);
StatLineI("pure acks sent","", pab->pureack_pkts, pba->pureack_pkts);
StatLineI("sack pkts sent","", pab->num_sacks, pba->num_sacks);
StatLineI("dsack pkts sent","", pab->num_dsacks, pba->num_dsacks);
StatLineI("max sack blks/ack","", pab->max_sack_blocks, pba->max_sack_blocks);
StatLineI("unique bytes sent","",
pab->unique_bytes, pba->unique_bytes);
StatLineI("actual data pkts","", pab->data_pkts, pba->data_pkts);
StatLineI("actual data bytes","", pab->data_bytes, pba->data_bytes);
StatLineI("rexmt data pkts","", pab->rexmit_pkts, pba->rexmit_pkts);
StatLineI("rexmt data bytes","",
pab->rexmit_bytes, pba->rexmit_bytes);
StatLineI("zwnd probe pkts","",
pab->num_zwnd_probes, pba->num_zwnd_probes);
StatLineI("zwnd probe bytes","",
pab->zwnd_probe_bytes, pba->zwnd_probe_bytes);
StatLineI("outoforder pkts","",
pab->out_order_pkts, pba->out_order_pkts);
StatLineI("pushed data pkts","", pab->data_pkts_push, pba->data_pkts_push);
StatLineP("SYN/FIN pkts sent","","%s",
(snprintf(bufl,sizeof(bufl),"%d/%d",
pab->syn_count, pab->fin_count),bufl),
(snprintf(bufr,sizeof(bufr),"%d/%d",
pba->syn_count, pba->fin_count),bufr));
if (pab->f1323_ws || pba->f1323_ws || pab->f1323_ts || pba->f1323_ts || csv || tsv || (sv != NULL)) {
StatLineP("req 1323 ws/ts","","%s",
(snprintf(bufl,sizeof(bufl),"%c/%c",
pab->f1323_ws?'Y':'N',pab->f1323_ts?'Y':'N'),bufl),
(snprintf(bufr,sizeof(bufr),"%c/%c",
pba->f1323_ws?'Y':'N',pba->f1323_ts?'Y':'N'),bufr));
}
if (pab->f1323_ws || pba->f1323_ws || csv || tsv || (sv != NULL)) {
StatLineI("adv wind scale","",
(u_long)pab->window_scale, (u_long)pba->window_scale);
}
if (pab->fsack_req || pba->fsack_req || csv || tsv || (sv != NULL)) {
StatLineP("req sack","","%s",
pab->fsack_req?"Y":"N",
pba->fsack_req?"Y":"N");
StatLineI("sacks sent","",
pab->sacks_sent,
pba->sacks_sent);
}
StatLineI("urgent data pkts", "pkts",
pab->urg_data_pkts,
pba->urg_data_pkts);
StatLineI("urgent data bytes", "bytes",
pab->urg_data_bytes,
pba->urg_data_bytes);
StatLineI("mss requested","bytes", pab->mss, pba->mss);
StatLineI("max segm size","bytes",
pab->max_seg_size,
pba->max_seg_size);
StatLineI("min segm size","bytes",
pab->min_seg_size,
pba->min_seg_size);
StatLineI("avg segm size","bytes",
(int)((double)pab->data_bytes / ((double)pab->data_pkts+.001)),
(int)((double)pba->data_bytes / ((double)pba->data_pkts+.001)));
StatLineI("max win adv","bytes", pab->win_max, pba->win_max);
StatLineI("min win adv","bytes", pab->win_min, pba->win_min);
StatLineI("zero win adv","times",
pab->win_zero_ct, pba->win_zero_ct);
// Average window advertisement is calculated only for window scaled pkts
// if we have seen this connection using window scaling.
// Otherwise, it is just the regular way of dividing the sum of
// all window advertisements by the total number of packets.
if (pab->window_stats_updated_for_scaling &&
pba->window_stats_updated_for_scaling)
StatLineI("avg win adv","bytes",
pab->win_scaled_pkts==0?0:
(pab->win_tot/pab->win_scaled_pkts),
pba->win_scaled_pkts==0?0:
(pba->win_tot/pba->win_scaled_pkts));
else
StatLineI("avg win adv","bytes",
pab->packets==0?0:pab->win_tot/pab->packets,
pba->packets==0?0:pba->win_tot/pba->packets);
if (print_owin) {
StatLineI("max owin","bytes", pab->owin_max, pba->owin_max);
StatLineI("min non-zero owin","bytes", pab->owin_min, pba->owin_min);
StatLineI("avg owin","bytes",
pab->owin_count==0?0:pab->owin_tot/pab->owin_count,
pba->owin_count==0?0:pba->owin_tot/pba->owin_count);
if (etime == 0.0) {
StatLineP("wavg owin", "", "%s", "NA", "NA");
}
else {
StatLineI("wavg owin","bytes",
(u_llong)(pab->owin_wavg/((double)etime/1000000)),
(u_llong)(pba->owin_wavg/((double)etime/1000000)));
}
}
StatLineI("initial window","bytes",
pab->initialwin_bytes, pba->initialwin_bytes);
StatLineI("initial window","pkts",
pab->initialwin_segs, pba->initialwin_segs);
/* compare to theoretical length of the stream (not just what
we saw) using the SYN and FIN
* Seq. Space wrap around calculations:
* Calculate stream length using last_seq_num seen, first_seq_num
* seen and wrap_count.
* first_seq_num = syn
* If reset_set, last_seq_num = latest_seq
* else last_seq_num = fin
*/
pab_last = (pab->reset_count>0)?pab->latest_seq:pab->fin;
pba_last = (pba->reset_count>0)?pba->latest_seq:pba->fin;
/* calculating stream length for direction pab */
if ((pab->syn_count > 0) && (pab->fin_count > 0)) {
if (pab->seq_wrap_count > 0) {
if (pab_last > pab->syn) {
stream_length_pab = pab_last + (MAX_32 * pab->seq_wrap_count) - pab->syn - 1;
}
else {
stream_length_pab = pab_last + (MAX_32 * (pab->seq_wrap_count+1)) - pab->syn - 1;
}
}
else {
if (pab_last > pab->syn) {
stream_length_pab = pab_last - pab->syn - 1;
}
else {
stream_length_pab = MAX_32 + pab_last - pab->syn - 1;
}
}
}
/* calculating stream length for direction pba */
if ((pba->syn_count > 0) && (pba->fin_count > 0)) {
if (pba->seq_wrap_count > 0) {
if (pba_last > pba->syn) {
stream_length_pba = pba_last + (MAX_32 * pba->seq_wrap_count) - pba->syn - 1;
}
else {
stream_length_pba = pba_last + (MAX_32 * (pba->seq_wrap_count+1)) - pba->syn - 1;
}
}
else {
if (pba_last > pba->syn) {
stream_length_pba = pba_last - pba->syn - 1;
}
else {
stream_length_pba = MAX_32 + pba_last - pba->syn - 1;
}
}
}
/* print out values */
if ((pab->fin_count > 0) && (pab->syn_count > 0)) {
char *format = "%8" FS_ULL;
StatLineFieldL("ttl stream length", "bytes", format, stream_length_pab, 0);
}
else {
StatLineField("ttl stream length", "", "%s", (u_long)"NA", 0);
}
if ((pba->fin_count > 0) && (pba->syn_count > 0)) {
char *format = "%8" FS_ULL;
StatLineFieldL("ttl stream length", "bytes", format, stream_length_pba, 1);
}
else {
StatLineField("ttl stream length", "", "%s", (u_long)"NA", 1);
}
if ((pab->fin_count > 0) && (pab->syn_count > 0)) {
char *format = "%8" FS_ULL;
StatLineFieldL("missed data", "bytes", format, (stream_length_pab - pab->unique_bytes), 0);
}
else {
StatLineField("missed data", "", "%s", (u_long)"NA", 0);
}
if ((pba->fin_count > 0) && (pba->syn_count > 0)) {
char *format = "%8" FS_ULL;
StatLineFieldL("missed data", "bytes", format, (stream_length_pba - pba->unique_bytes), 1);
}
else {
StatLineField("missed data", "", "%s", (u_long)"NA", 1);
}
/* tell how much data was NOT captured in the files */
StatLineI("truncated data","bytes",
pab->trunc_bytes, pba->trunc_bytes);
StatLineI("truncated packets","pkts",
pab->trunc_segs, pba->trunc_segs);
/* stats on just the data */
etime_data1 = elapsed(pab->first_data_time,
pab->last_data_time); /* in usecs */
etime_data2 = elapsed(pba->first_data_time,
pba->last_data_time); /* in usecs */
/* fix from Rob Austein */
StatLineF("data xmit time","secs","%7.3f",
etime_data1 / 1000000.0,
etime_data2 / 1000000.0);
StatLineP("idletime max","ms","%s",
ZERO_TIME(&pab->last_time)?"NA":
(snprintf(bufl,sizeof(bufl),"%8.1f",(double)pab->idle_max/1000.0),bufl),
ZERO_TIME(&pba->last_time)?"NA":
(snprintf(bufr,sizeof(bufr),"%8.1f",(double)pba->idle_max/1000.0),bufr));
if ((pab->num_hardware_dups != 0) || (pba->num_hardware_dups != 0) || csv || tsv || (sv != NULL)) {
StatLineI("hardware dups","segs",
pab->num_hardware_dups, pba->num_hardware_dups);
if(!(csv || tsv || (sv != NULL)))
fprintf(stdout,
" ** WARNING: presence of hardware duplicates makes these figures suspect!\n");
}
/* do the throughput calcs */
etime /= 1000000.0; /* convert to seconds */
if (etime == 0.0)
StatLineP("throughput","","%s","NA","NA");
else
StatLineF("throughput","Bps","%8.0f",
(double) (pab->unique_bytes) / etime,
(double) (pba->unique_bytes) / etime);
if (print_rtt) {
if(!(csv || tsv || (sv != NULL)))
fprintf(stdout,"\n");
StatLineI("RTT samples","", pab->rtt_count, pba->rtt_count);
StatLineF("RTT min","ms","%8.1f",
(double)pab->rtt_min/1000.0,
(double)pba->rtt_min/1000.0);
StatLineF("RTT max","ms","%8.1f",
(double)pab->rtt_max/1000.0,
(double)pba->rtt_max/1000.0);
StatLineF("RTT avg","ms","%8.1f",
Average(pab->rtt_sum, pab->rtt_count) / 1000.0,
Average(pba->rtt_sum, pba->rtt_count) / 1000.0);
StatLineF("RTT stdev","ms","%8.1f",
Stdev(pab->rtt_sum, pab->rtt_sum2, pab->rtt_count) / 1000.0,
Stdev(pba->rtt_sum, pba->rtt_sum2, pba->rtt_count) / 1000.0);
if(!(csv || tsv || (sv != NULL)))
fprintf(stdout,"\n");
StatLineF("RTT from 3WHS","ms","%8.1f",
(double)pab->rtt_3WHS/1000.0,
(double)pba->rtt_3WHS/1000.0);
if(!(csv || tsv || (sv != NULL)))
fprintf(stdout,"\n");
StatLineI("RTT full_sz smpls","",
pab->rtt_full_count, pba->rtt_full_count);
StatLineF("RTT full_sz min","ms","%8.1f",
(double)pab->rtt_full_min/1000.0,
(double)pba->rtt_full_min/1000.0);
StatLineF("RTT full_sz max","ms","%8.1f",
(double)pab->rtt_full_max/1000.0,
(double)pba->rtt_full_max/1000.0);
StatLineF("RTT full_sz avg","ms","%8.1f",
Average(pab->rtt_full_sum, pab->rtt_full_count) / 1000.0,
Average(pba->rtt_full_sum, pba->rtt_full_count) / 1000.0);
StatLineF("RTT full_sz stdev","ms","%8.1f",
Stdev(pab->rtt_full_sum, pab->rtt_full_sum2, pab->rtt_full_count) / 1000.0,
Stdev(pba->rtt_full_sum, pba->rtt_full_sum2, pba->rtt_full_count) / 1000.0);
if(!(csv || tsv || (sv != NULL)))
fprintf(stdout,"\n");
StatLineI("post-loss acks","",
pab->rtt_nosample, pba->rtt_nosample);
if (pab->rtt_amback || pba->rtt_amback || csv || tsv || (sv != NULL)) {
if(!(csv || tsv || (sv != NULL)))
fprintf(stdout, "\
\t For the following 5 RTT statistics, only ACKs for\n\
\t multiply-transmitted segments (ambiguous ACKs) were\n\
\t considered. Times are taken from the last instance\n\
\t of a segment.\n\
");
StatLineI("ambiguous acks","",
pab->rtt_amback, pba->rtt_amback);
StatLineF("RTT min (last)","ms","%8.1f",
(double)pab->rtt_min_last/1000.0,
(double)pba->rtt_min_last/1000.0);
StatLineF("RTT max (last)","ms","%8.1f",
(double)pab->rtt_max_last/1000.0,
(double)pba->rtt_max_last/1000.0);
StatLineF("RTT avg (last)","ms","%8.1f",
Average(pab->rtt_sum_last, pab->rtt_count_last) / 1000.0,
Average(pba->rtt_sum_last, pba->rtt_count_last) / 1000.0);
StatLineF("RTT sdv (last)","ms","%8.1f",
Stdev(pab->rtt_sum_last, pab->rtt_sum2_last, pab->rtt_count_last) / 1000.0,
Stdev(pba->rtt_sum_last, pba->rtt_sum2_last, pba->rtt_count_last) / 1000.0);
}
StatLineI("segs cum acked","",
pab->rtt_cumack, pba->rtt_cumack);
StatLineI("duplicate acks","",
pab->rtt_dupack, pba->rtt_dupack);
StatLineI("triple dupacks","",
pab->rtt_triple_dupack, pba->rtt_triple_dupack);
if (debug)
StatLineI("unknown acks:","",
pab->rtt_unkack, pba->rtt_unkack);
StatLineI("max # retrans","",
pab->retr_max, pba->retr_max);
StatLineF("min retr time","ms","%8.1f",
(double)((double)pab->retr_min_tm/1000.0),
(double)((double)pba->retr_min_tm/1000.0));
StatLineF("max retr time","ms","%8.1f",
(double)((double)pab->retr_max_tm/1000.0),
(double)((double)pba->retr_max_tm/1000.0));
StatLineF("avg retr time","ms","%8.1f",
Average(pab->retr_tm_sum, pab->retr_tm_count) / 1000.0,
Average(pba->retr_tm_sum, pba->retr_tm_count) / 1000.0);
StatLineF("sdv retr time","ms","%8.1f",
Stdev(pab->retr_tm_sum, pab->retr_tm_sum2,
pab->retr_tm_count) / 1000.0,
Stdev(pba->retr_tm_sum, pba->retr_tm_sum2,
pba->retr_tm_count) / 1000.0);
}
if(csv || tsv || (sv != NULL)) {
printf("\n");
/* Error checking: print an error message if the count of printed fields
* doesn't correspond to the actual fields expected.
*/
if(sv_print_count != sv_expected_count) {
fprintf(stderr, "output.c: Count of printed fields does not correspond to count of header fields for long output with comma/tab/<SP>-separated values.\n");
fprintf(stderr,"sv_print_count=%u, sv_expected_count=%u\n",
sv_print_count, sv_expected_count);
exit(-1);
}
}
}
/*Look for an id in the tcb, return the address if found, else return NULL*/
stream_info* findStream(tcb* way, tt_uint16 id)
{
stream_info* temp = way->stream_list;
while(temp != NULL)
{
if(temp->stream_id == id)
return temp;
temp = temp -> pnext;
}
return NULL;
}
void
SctpPrintTrace(
tcp_pair *ptp)
{
double etime;
u_long etime_secs;
u_long etime_usecs;
double etime_data1;
double etime_data2;
tcb *pab = &ptp->a2b;
tcb *pba = &ptp->b2a;
char *host1;
char *host2;
char bufl[40],bufr[40];
stream_info *unique_stream_list = NULL;
/* Add path data to association */
tcp_pair *tmpptr = ptp->next;
while(tmpptr != NULL)
{
pab->packets += tmpptr->a2b.packets;
pba->packets += tmpptr->b2a.packets;
pab->abort_count += tmpptr->a2b.abort_count;
pba->abort_count += tmpptr->b2a.abort_count;
pab->chunk_count += tmpptr->a2b.chunk_count;
pba->chunk_count += tmpptr->b2a.chunk_count;
pab->data_count += tmpptr->a2b.data_count;
pba->data_count += tmpptr->b2a.data_count;
pab->cookie_echo_count += tmpptr->a2b.cookie_echo_count;
pba->cookie_echo_count += tmpptr->b2a.cookie_echo_count;
pab->cookie_ack_count += tmpptr->a2b.cookie_ack_count;
pba->cookie_ack_count += tmpptr->b2a.cookie_ack_count;
pab->data_bytes += tmpptr->a2b.data_bytes;
pba->data_bytes += tmpptr->b2a.data_bytes;
pab->auth_count += tmpptr->a2b.auth_count;
pba->auth_count += tmpptr->b2a.auth_count;
pab->cwr_count += tmpptr->a2b.cwr_count;
pba->cwr_count += tmpptr->b2a.cwr_count;
pab->ecne_count += tmpptr->a2b.ecne_count;
pba->ecne_count += tmpptr->b2a.ecne_count;
pab->heartbeat_count += tmpptr->a2b.heartbeat_count;
pba->heartbeat_count += tmpptr->b2a.heartbeat_count;
pab->heartbeat_ack_count += tmpptr->a2b.heartbeat_ack_count;
pba->heartbeat_ack_count += tmpptr->b2a.heartbeat_ack_count;
pab->init_ack_count += tmpptr->a2b.init_ack_count;
pba->init_ack_count += tmpptr->b2a.init_ack_count;
pab->init_count += tmpptr->a2b.init_count;
pba->init_count += tmpptr->b2a.init_count;
pab->other_count += tmpptr->a2b.other_count;
pba->other_count += tmpptr->b2a.other_count;
pab->out_order_pkts += tmpptr->a2b.out_order_pkts;
pba->out_order_pkts += tmpptr->b2a.out_order_pkts;
pab->pureack_pkts += tmpptr->a2b.pureack_pkts;
pba->pureack_pkts += tmpptr->b2a.pureack_pkts;
pab->rexmit_pkts += tmpptr->a2b.rexmit_pkts;
pba->rexmit_pkts += tmpptr->b2a.rexmit_pkts;
pab->rexmit_bytes += tmpptr->a2b.rexmit_bytes;
pba->rexmit_bytes += tmpptr->b2a.rexmit_bytes;
pab->sack_count += tmpptr->a2b.sack_count;
pba->sack_count += tmpptr->b2a.sack_count;
pab->shutdown_count += tmpptr->a2b.shutdown_count;
pba->shutdown_count += tmpptr->b2a.shutdown_count;
pab->shutdown_ack_count += tmpptr->a2b.shutdown_ack_count;
pba->shutdown_ack_count += tmpptr->b2a.shutdown_ack_count;
pab->shutdown_complete_count += tmpptr->a2b.shutdown_complete_count;
pba->shutdown_complete_count += tmpptr->b2a.shutdown_complete_count;
/*Add all streams to the association*/
stream_info* pStream = tmpptr->a2b.stream_list;
stream_info* aStream;
while(pStream != NULL ){
aStream = findStream(pab,pStream->stream_id);
if(aStream == NULL){
aStream = malloc(sizeof(stream_info));
aStream->stream_id = pStream->stream_id;
aStream->datainfo.data_bytes = pStream->datainfo.data_bytes;
aStream->datainfo.data_count = pStream->datainfo.data_count;
aStream->datainfo.rexmit_bytes = pStream->datainfo.rexmit_bytes;
aStream->datainfo.rexmit_pkts = pStream->datainfo.rexmit_bytes;
aStream->datainfo.unique_bytes = pStream->datainfo.unique_bytes;
aStream->pnext = NULL;
if(pab->stream_list == NULL){
pab->stream_list = aStream;
}
else
{
stream_info *temp3 = pab->stream_list;
while(temp3->pnext!=NULL){
temp3 = temp3->pnext;
}
temp3->pnext = aStream;
}
}
else
{
aStream->datainfo.data_bytes += pStream->datainfo.data_bytes;
aStream->datainfo.data_count += pStream->datainfo.data_count;
aStream->datainfo.rexmit_bytes += pStream->datainfo.rexmit_bytes;
aStream->datainfo.rexmit_pkts += pStream->datainfo.rexmit_bytes;
aStream->datainfo.unique_bytes += pStream->datainfo.unique_bytes;
}
pStream = pStream->pnext;
}
pStream = tmpptr->b2a.stream_list;
while(pStream != NULL ){
aStream = findStream(pba,pStream->stream_id);
if(aStream == NULL){
aStream = malloc(sizeof(stream_info));
aStream->stream_id = pStream->stream_id;
aStream->datainfo.data_bytes = pStream->datainfo.data_bytes;
aStream->datainfo.data_count = pStream->datainfo.data_count;
aStream->datainfo.rexmit_bytes = pStream->datainfo.rexmit_bytes;
aStream->datainfo.rexmit_pkts = pStream->datainfo.rexmit_bytes;
aStream->datainfo.unique_bytes = pStream->datainfo.unique_bytes;
aStream->pnext = NULL;
if(pba->stream_list == NULL){
pba->stream_list = aStream;
}
else
{
stream_info *temp3 = pba->stream_list;
while(temp3->pnext!=NULL){
temp3 = temp3->pnext;
}
temp3->pnext = aStream;
}
}
else
{
aStream->datainfo.data_bytes += pStream->datainfo.data_bytes;
aStream->datainfo.data_count += pStream->datainfo.data_count;
aStream->datainfo.rexmit_bytes += pStream->datainfo.rexmit_bytes;
aStream->datainfo.rexmit_pkts += pStream->datainfo.rexmit_bytes;
aStream->datainfo.unique_bytes += pStream->datainfo.unique_bytes;
}
pStream = pStream->pnext;
}
/* Initiate time */
if (ZERO_TIME(&ptp->first_time)) {
ptp->first_time = tmpptr->first_time;
ptp->last_time = tmpptr->last_time;
}
/* Set earlier and later times if found */
else if(!ZERO_TIME(&tmpptr->first_time)) //prevent to accidentaly add faulty times
{
if(LESS_TIME(&tmpptr->first_time, &ptp->first_time))
{ptp->first_time = tmpptr->first_time;}
if(LESS_TIME(&ptp->last_time, &tmpptr->first_time))
{ptp->last_time = tmpptr->last_time;}
}
tmpptr = tmpptr->next;
}
ptp->packets += (pab->packets + pba->packets);
int pathNumber = 1;
int isPath = 0;
do
{
pab = &ptp->a2b;
pba = &ptp->b2a;
host1 = pab->host_letter;
host2 = pba->host_letter;
if(pab->packets == 0 && pba->packets == 0)
{
ptp = ptp->next;
if(ptp == NULL)
break;
continue;
}
/* counters to use for seq. space wrap around calculations
*/
u_llong stream_length_pab=0, stream_length_pba=0;
u_long pab_last, pba_last;
/* Reset the counter for each connection */
sv_print_count = 1; /* The first field (conn_#) gets printed in trace.c */
/* calculate elapsed time */
etime = elapsed(ptp->first_time,ptp->last_time);
etime_secs = etime / 1000000.0;
etime_usecs = 1000000 * (etime/1000000.0 - (double)etime_secs);
/* Check if comma-separated-values or tab-separated-values
* has been requested.
*/
if(isPath)
fprintf(stdout,"\n\n\t\t\t\tPath %d \n\n", pathNumber++);
if(csv || tsv || (sv != NULL)) {
fprintf(stdout,"%s%s%s%s%s%s%s%s",
ptp->a_hostname, sp, ptp->b_hostname, sp,
ptp->a_portname, sp, ptp->b_portname, sp);
sv_print_count += 4;
/* Print the start and end times. In other words,
* print the time of the first and the last packet
*/
fprintf(stdout,"%ld.%ld %s %ld.%ld %s",
(long)ptp->first_time.tv_sec, (long)ptp->first_time.tv_usec, sp,
(long)ptp->last_time.tv_sec, (long)ptp->last_time.tv_usec, sp);
sv_print_count += 2;
}
else {
fprintf(stdout,"\thost %-4s %s\n",
(snprintf(bufl,sizeof(bufl),"%s:", host1),bufl), ptp->a_endpoint);
fprintf(stdout,"\thost %-4s %s\n",
(snprintf(bufl,sizeof(bufl),"%s:", host2),bufl), ptp->b_endpoint);
if(!isPath){
fprintf(stdout,"\tcomplete assoc: %s",
ConnAbort(ptp)?"RESET":(
SctpConnComplete(ptp)?"yes":"no"));
if (SctpConnComplete(ptp))
fprintf(stdout,"\n");
else
fprintf(stdout,"\t(INITs: %u) (SHUTDOWNs: %u)\n",
InitCount(ptp), ShutdownCount(ptp));
}
fprintf(stdout,"\tfirst packet: %s\n", ts2ascii(&ptp->first_time));
fprintf(stdout,"\tlast packet: %s\n", ts2ascii(&ptp->last_time));
fprintf(stdout,"\telapsed time: %s\n", elapsed2str(etime));
fprintf(stdout,"\ttotal packets: %" FS_ULL "\n", ptp->packets);
UniqueStreamCounter(ptp, &unique_stream_list);
fprintf(stdout,"\tfilename: %s\n\n", ptp->filename);
if(!isPath)
fprintf(stdout,"\t\t\t\tTotal association statistics\n");
fprintf(stdout," %s->%s: %s->%s:\n",
host1,host2,host2,host1);
}
StatLineI("total packets","", pab->packets, pba->packets);
if (pab->abort_count || pba->abort_count || csv || tsv || (sv != NULL))
StatLineI("resets sent","", pab->abort_count, pba->abort_count);
StatLineI("total chunks","", pab->chunk_count, pba->chunk_count);
StatLineI("sack's sent","", pab->sack_count, pba->sack_count);
StatLineI("init ack's sent","", pab->init_ack_count, pba->init_ack_count);