-
Notifications
You must be signed in to change notification settings - Fork 8
/
read_bbrlog.c
8269 lines (7951 loc) · 238 KB
/
read_bbrlog.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
#include <sys/types.h>
#include <sys/callout.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <sys/errno.h>
#include <sys/param.h>
#include <sys/mbuf.h>
#include <sys/sysctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/tree.h>
#include <sys/tim_filter.h>
#include <sys/osd.h>
#include <getopt.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#define _WANT_INPCB
#include <netinet/in_pcb.h>
#include <netinet/tcp_hpts.h>
#include <dev/tcp_log/tcp_log_dev.h>
#include <netinet/tcp_log_buf.h>
#include <netinet/tcp_seq.h>
#define _WANT_TCPCB
#include <netinet/tcp_var.h>
#include <netinet/tcp_hpts.h>
#include <netinet/tcp_stacks/sack_filter.h>
#include <netinet/tcp_stacks/tcp_bbr.h>
#include <netinet/tcp_stacks/tcp_rack.h>
#include <netinet/tcp_stacks/rack_bbr_common.h>
#include <net/route.h>
#include <assert.h>
static const char *prurequests[] = {
"ATTACH", "DETACH", "BIND", "LISTEN",
"CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN",
"RCVD", "SEND", "ABORT", "CONTROL",
"SENSE", "RCVOOB", "SENDOOB", "SOCKADDR",
"PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO",
"PROTORCV", "PROTOSEND", "SEND_EOF", "SOSETLABEL",
"CLOSE", "FLUSH",
};
#include <bbparse.h>
#define tcp_get_flags(th) __tcp_get_flags(th)
#define tcp_set_flags(th, flags) __tcp_set_flags(th, flags)
static uint32_t lowest_delta = 0xffffffff;
static uint32_t highest_delta = 0;
static int32_t showExtraInfo = 0;
static int32_t file_count_limit = 0;
static int32_t file_count_at = 0;
static int32_t use_relative_seq = 0;
static int32_t change_tracking = 0;
static void
print_pace_size(const struct tcp_log_buffer *, const struct tcp_log_bbr *);
static FILE *dump_out_sack=NULL;
#define MAX_TYPES TCP_LOG_END
static int extra_print = 0;
static int number_flow = 0;
static uint32_t record_num_start = 0;
static uint32_t record_num_end = 0;
static uint8_t num_start_set = 0;
static uint8_t num_end_set = 0;
static uint8_t tag_dumped = 0;
static char log_tag[TCP_LOG_TAG_LEN];
static uint32_t time_in_hot = 0;
static int print_out_the_time = 0;
static int show_all_messages=1;
static uint32_t out_count = 0;
static int display_file_names = 0;
static uint32_t warn_behind=0;
static int irs = 0;
static int irs_set = 0;
static const char *dirname = NULL;
static uint32_t epoch_lost = 0;
static uint32_t epoch_delivered = 0;
static uint32_t first_time=0;
static int first_time_set=0;
static int bbr_first_time_set=0;
static int time_is_relative = 0;
static const struct tcp_log_header *lh = NULL;
static int display_wallclock_time = 0;
static int use_monolithic_time = 0;
static uint32_t prev_sent_bytes = 0;
static uint32_t prev_sn = 0;
static uint64_t prev_sent_time = 0;
static int clear_to_print = 1;
/*#define BBR_RED_BW_CONGSIG 0 We enter recovery and set using b/w */
/*#define BBR_RED_BW_RATECAL 1 We are calculating the loss rate */
/*#define BBR_RED_BW_USELRBW 2 We are dropping the lower b/w with cDR*/
/*#define BBR_RED_BW_SETHIGHLOSS 3 We have set our highloss value at exit from probe-rtt */
/*#define BBR_RED_BW_PE_CLREARLY 4 We have decided to clear the reduction early */
/*#define BBR_RED_BW_PE_CLAFDEL 5 We are clearing it on schedule delayed */
/*#define BBR_RED_BW_REC_ENDCLL 6 Recover exits save high if needed an clear to start measuring */
/*#define BBR_RED_BW_PE_NOEARLY_OUT 7 Set pkt epoch judged that we do not get out of jail early */
static const char *tcp_accounting_names[] = {
"ACK_BEHIND",
"ACK_SACK",
"ACK_CUMACK",
"ACK_CUMACK_SACK",
"ACK_DUPACK",
"ACK_RWND",
"SND_BLOCKED",
"SND_LIMITED",
"SND_OUT_DATA",
"SND_OUT_ACK",
"SND_OUT_FAIL",
"CNT_OF_MSS_OUT",
"CNT_OF_ACKS_IN"
};
static const char *tcp_cycle_names[] = {
"ACK_BEHIND",
"ACK_SACK",
"ACK_CUMACK",
"ACK_CUMACK_SACK",
"ACK_DUPACK",
"ACK_RWND",
"SND_BLOCKED",
"SND_LIMITED",
"SND_OUT_DATA",
"SND_OUT_ACK",
"SND_OUT_FAIL",
"CYC_HANDLE_MAP",
"CYC_HANDLE_ACK"
};
static const char *map_chg_names[] = {
"None",
"Merge",
"Split",
"New",
"SACK_M1",
"SACK_M2",
"SACK_M3",
"SACK_M4",
"SACK_M5",
"Free",
"Trim Head",
"None"
};
#define MAX_RED_BW_REASONS 9
static const char *red_bw_reasons[MAX_RED_BW_REASONS] = {
"Recovery Begins",
"Calculate loss rate",
"Adopt lower red b/w",
"ProbeRTT sets new threshold",
"Clear reduction early",
"Clear reduction on sched",
"Exiting recovery",
"No early out",
"Unknown"
};
#define PACE_TMR_DELACK 0x01 /* Delayed ack timer running */
#define PACE_TMR_RACK 0x02 /* RACK timer running */
#define PACE_TMR_TLP 0x04 /* TLP timer running */
#define PACE_TMR_RXT 0x08 /* Retransmit timer running */
#define PACE_TMR_PERSIT 0x10 /* Persists timer running */
#define PACE_TMR_KEEP 0x20 /* Keep alive timer running */
#define PACE_PKT_OUTPUT 0x40 /* Output Packets being paced */
#define PACE_TMR_MASK (PACE_TMR_KEEP|PACE_TMR_PERSIT|PACE_TMR_RXT|PACE_TMR_TLP|PACE_TMR_RACK|PACE_TMR_DELACK)
static uint64_t under_256 = 0;
static uint64_t over_256 = 0;
static uint64_t at_256 = 0;
static uint64_t under_drain = 0;
static uint64_t under_rtt = 0;
static uint64_t under_subdr = 0;
static uint64_t time_in_state[3];
#define STATE_SS 0
#define STATE_CA 1
#define STATE_REC 2
static uint32_t time_entered = 0;
static int32_t gp_state = 0;
static void
add_time_to_state(uint32_t now, int new_state)
{
if (TSTMP_GT(now, time_entered))
time_in_state[gp_state] += (now - time_entered);
gp_state = new_state;
time_entered = now;
}
static void inline
print_out_space(FILE *outp)
{
fprintf(outp, " ");
}
static struct timeval earliest_time;
static struct timeval connection_begin_time;
static struct timeval last_time;
static int early_filled = 0;
static uint64_t msg_types_list[MAX_TYPES];
static uint16_t last_major_state = 0;
static uint16_t last_minor_state = 0;
static uint64_t total_missed_records = 0;
static const char *log_names[MAX_TYPES] = {
"UNKNOWN ",
"IN ", /* Incoming packet 1 */
"PKT_OUT ", /* Transmit (without other event) 2 */
"RTO ", /* Retransmit timeout 3 */
"SOWAKE ", /* We wokeup a socket buffer 4 */
"TCP_UNUSED_5", /* Detected bad retransmission 5 */
"PRR ", /* Doing PRR 6 */
"TCP_UNUSED_7", /* Detected reorder 7 */
"PACER ", /* Pacer sending a packet 8 */
"BBRUPD ", /* We updated BBR info 9 */
"BBRSND ", /* We did a slot calculation and sending is done 10 */
"ACKCLEAR ", /* A ack clears all outstanding 11 */
"TCP_UNUSED_12", /* The tcb had a packet input to it 12 */
"TIMERSTAR ", /* Start a timer 13 */
"TIMERCANC ", /* Cancel a timer 14 */
"ENTREC ", /* Entered recovery 15 */
"EXITREC ", /* Exited recovery 16 */
"LOG_CWND ", /* Cwnd change 17 */
"BWSAMP ", /* LT B/W sample has been made 18 */
"MSGSIZE ", /* We received a EMSGSIZE error 19 */
"BBRRTT ", /* BBR RTT is updated 20 */
"JUSTRET ", /* We just returned out of output 21 */
"STATE ", /* A BBR state change occured 22 */
"PKT_EPOCH ", /* A packet epoch occured 23 */
"PERSIST ", /* We enter/exit persists 24 */
"FLOWEND ", /* end of a flow 25 */
"RTO ", /* a BBR timeout mark 26 */
"DOSEG_DONE", /* End of pacer do segment 27 */
"EXIT_GAIN ", /* pacer do_segment completes 28 */
"THRESH_CALC",/* log the calculation routine 29 */
"MAP_CHGS", /* Map changes to the sendmap 30 */
"USERSEND ", /* User level sends data 31 */
"RSM_CLEAR ", /* Unused 32 */
"STATE_TARGET", /* Set of state target 33 */
"EPOCH_TIME", /* A timed based Epoch occured 34 */
"LOG_TO_PRO", /* A to was processed 35 */
"TSO_SZ_UPD", /* Update the TSO size 36 */
"PACERDIAG ", /* A pacer diag msg 37 */
"RWND COMP ", /* Log a low gain event 38 */
"PROGRESS ", /* A progress event 39 */
"TCP_OPTION", /* A tcp option is set 40 */
"BBR_LOG_TIMERPREP", /* timing calc check 41 */
"BBR_ENOBUF_JMP", /* 42 */
"BBR_PACING_CALC", /* 43 */
"BBR_RTT_SHRINKS", /* 44 */
"BBR_LOG_BW_RED_EV", /* 45 */
"BBR_STARTUP_LOG", /* 46 */
"TCP_LOG_RTT", /* 47 */
"BBR_SETTINGS", /* 48 */
"TCP_UNUSED_49", /* 49 */
"TCP_LOG_REASS", /* 50 */
"TCP_PACE_SIZE", /* 51 */
"BBR_TCP_HDWR_PACE", /* 52 */
"BBR_LOG_TSTMP_VAL", /* 53 */
"TCP_LOG_CONNEND", /* 54 */
"TCP_LRO_LOG", /* 55 */
"SACK_FILTER_RESULT", /* 56 */
"TCP_UNUSED_57", /* 57 */
"TCP_TIMELY_WORK", /* 58 */
"TCP_UNUSED_59", /* 59 */
"SENDFILE ", /* 60 */
"TCP_LOG_REQ_T", /* 61 */
"TCP_ACCOUNTING", /* 62 */
"TCP_LOG_FSB", /* 63 */
"RACK_DSACK_HANDLING", /* 64 */
"TCP_HYSTART", /* 65 */
"TCP_CHG_QUERY", /* 66 */
"TCP_RACK_LOG_COLLAPSE", /* 67 */
"RACK_TP_TRIGGERED", /* 68 */
"TCP_HYBRID_PACING", /* 69 */
"TCP_LOG_PRU", /* 70 */
};
static uint32_t time_last_setting = 0;
static int last_set_set=0;
static uint32_t last_ack_time = 0;
static uint32_t last_spa_seen = 0;
static uint32_t last_out_time = 0;
static uint32_t last_input_time = 0;
static uint32_t last_pg_chg=0;
static uint32_t opg=0;
static uint32_t last_evt_time=0;
static uint64_t time_avail_zero = 0;
static uint32_t time_saw_avail_zero = 0;
static uint32_t avail_is_zero = 1;
static uint32_t saw_ltbw_set = 0;
#define REASON_MAX 10
static const char *lt_bw_reasons[REASON_MAX] = {
"Stop using lt bw", /* 0 */
"Begin sampling lt bw", /* 1 */
"App Limit reset sample", /* 2 */
"Been too long reset sampling", /* 3 */
"Being Policed use lt bw", /* 4 */
"Saved a lt bw sample", /* 5 */
"Not enough time or loss", /* 6 */
"False detection negative", /* 7 */
"False detection postive", /* 8 */
"Unknown" /* 9 */
};
static FILE *out = NULL;
#include <netinet/tcp_stacks/sack_filter.h>
#include <netinet/tcp_stacks/tcp_bbr.h>
static const char *
evt_name(int id)
{
if (id < 0 || id >= MAX_TYPES) {
static char log_name_foo[65];
sprintf(log_name_foo, "Unknown:%d",
id);
return(log_name_foo);
}
return(log_names[id]);
}
static char *
display_bw(uint64_t bw, int uniq_cpy)
{
static char human_bw[256];
double bw_d;
bw_d = bw * 8.0;
if (bw_d >= 1000000000.0) {
sprintf(human_bw, "%.2f Gbps", (bw_d/1000000000.0));
} else if (bw_d >= 1000000.0) {
sprintf(human_bw, "%.2f Mbps", (bw_d/1000000.0));
} else if (bw_d >= 1000.0) {
sprintf(human_bw, "%.2f kbps", (bw_d/1000.0));
} else {
sprintf(human_bw, "%.2f bps", bw_d);
}
if (uniq_cpy) {
char *cp;
cp = malloc(256);
strcpy(cp, human_bw);
return(cp);
} else {
return(human_bw);
}
}
static void
display_tcp_rto(const struct tcp_log_buffer *l)
{
int what;
int which;
const char *timer_types[] = {
"TT_REXMT",
"TT_PERSIST",
"TT_KEEP",
"TT_2MSL",
"TT_DELACK",
"TT_N"
};
const char *timer_events[] = {
"TT_PROCESSING",
"TT_PROCESSED",
"TT_STARTING",
"TT_STOPPING",
"TT_UNK"
};
what = (l->tlb_flex1 >> 8);
which = (l->tlb_flex1 & 0xff);
if (which > 5)
which = 5;
if (what > 4)
what = 4;
fprintf(out, "Type:%s Event:%s\n",
timer_types[which],
timer_events[what]);
}
static int cg_tk_filled = 0;
static struct tcp_log_buffer last_buffer;
static const char *
show_diff(uint32_t old, uint32_t new)
{
static char print_buffer[100];
uint32_t delta;
if (old > new) {
delta = old - new;
sprintf(print_buffer, "(-%u)",
delta);
} else {
delta = new - old;
sprintf(print_buffer, "(+%u)",
delta);
}
return ((const char *)print_buffer);
}
static void
change_tracking_check(const struct tcp_log_buffer *l)
{
if (cg_tk_filled == 0) {
cg_tk_filled = 1;
memcpy(&last_buffer, l, sizeof(struct tcp_log_buffer));
return;
}
/* Check and display any changes in the current log vs the previous */
if (last_buffer.tlb_stackid != l->tlb_stackid) {
print_out_space(out);
fprintf(out, "CHG tlb_stackid OLD:%u NEW:%u\n",
last_buffer.tlb_stackid,l->tlb_stackid);
}
if (last_buffer.tlb_state != l->tlb_state) {
print_out_space(out);
fprintf(out, "CHG tlb_state OLD:%u NEW:%u\n",
last_buffer.tlb_state, l->tlb_state);
}
if (last_buffer.tlb_flags != l->tlb_flags) {
print_out_space(out);
fprintf(out, "CHG tlb_flags OLD:0x%x NEW:0x%x\n",
last_buffer.tlb_flags, l->tlb_flags);
}
if (last_buffer.tlb_snd_una != l->tlb_snd_una) {
print_out_space(out);
fprintf(out, "CHG tlb_snd_una OLD:%u NEW:%u %s\n",
last_buffer.tlb_snd_una, l->tlb_snd_una,
show_diff(last_buffer.tlb_snd_una, l->tlb_snd_una));
}
if (last_buffer.tlb_snd_max != l->tlb_snd_max) {
print_out_space(out);
fprintf(out, "CHG tlb_snd_max OLD:%u NEW:%u %s\n",
last_buffer.tlb_snd_max, l->tlb_snd_max,
show_diff(last_buffer.tlb_snd_max, l->tlb_snd_max));
}
if (last_buffer.tlb_snd_cwnd != l->tlb_snd_cwnd) {
print_out_space(out);
fprintf(out, "CHG tlb_snd_cwnd OLD:%u NEW:%u %s\n",
last_buffer.tlb_snd_cwnd, l->tlb_snd_cwnd,
show_diff(last_buffer.tlb_snd_cwnd, l->tlb_snd_cwnd));
}
if (last_buffer.tlb_snd_nxt != l->tlb_snd_nxt) {
print_out_space(out);
fprintf(out, "CHG tlb_snd_nxt OLD:%u NEW:%u %s\n",
last_buffer.tlb_snd_nxt, l->tlb_snd_nxt,
show_diff(last_buffer.tlb_snd_nxt, l->tlb_snd_nxt));
}
if (last_buffer.tlb_snd_recover != l->tlb_snd_recover) {
print_out_space(out);
fprintf(out, "CHG tlb_snd_recover OLD:%u NEW:%u %s\n",
last_buffer.tlb_snd_recover, l->tlb_snd_recover,
show_diff(last_buffer.tlb_snd_recover, l->tlb_snd_recover));
}
if (last_buffer.tlb_snd_wnd != l->tlb_snd_wnd) {
print_out_space(out);
fprintf(out, "CHG tlb_snd_wnd OLD:%u NEW:%u %s\n",
last_buffer.tlb_snd_wnd, l->tlb_snd_wnd,
show_diff(last_buffer.tlb_snd_wnd, l->tlb_snd_wnd));
}
if (last_buffer.tlb_snd_ssthresh != l->tlb_snd_ssthresh) {
print_out_space(out);
fprintf(out, "CHG tlb_snd_ssthresh OLD:%u NEW:%u %s\n",
last_buffer.tlb_snd_ssthresh, l->tlb_snd_ssthresh,
show_diff(last_buffer.tlb_snd_ssthresh, l->tlb_snd_ssthresh));
}
if (last_buffer.tlb_srtt != l->tlb_srtt) {
print_out_space(out);
fprintf(out, "CHG tlb_srtt OLD:%u NEW:%u %s\n",
last_buffer.tlb_srtt, l->tlb_srtt,
show_diff(last_buffer.tlb_srtt, l->tlb_srtt));
}
if (last_buffer.tlb_rttvar != l->tlb_rttvar) {
print_out_space(out);
fprintf(out, "CHG tlb_rttvar OLD:%u NEW:%u %s\n",
last_buffer.tlb_rttvar, l->tlb_rttvar,
show_diff(last_buffer.tlb_rttvar, l->tlb_rttvar));
}
if (last_buffer.tlb_rcv_up != l->tlb_rcv_up) {
print_out_space(out);
fprintf(out, "CHG tlb_rcv_up OLD:%u NEW:%u\n",
last_buffer.tlb_rcv_up, l->tlb_rcv_up);
}
if (last_buffer.tlb_rcv_adv != l->tlb_rcv_adv) {
print_out_space(out);
fprintf(out, "CHG tlb_rcv_adv OLD:%u NEW:%u %s\n",
last_buffer.tlb_rcv_adv, l->tlb_rcv_adv,
show_diff(last_buffer.tlb_rcv_adv, l->tlb_rcv_adv));
}
if (last_buffer.tlb_flags2 != l->tlb_flags2) {
print_out_space(out);
fprintf(out, "CHG tlb_flags2 OLD:0x%x NEW:0x%x\n",
last_buffer.tlb_flags2, l->tlb_flags2);
}
if (last_buffer.tlb_rcv_nxt != l->tlb_rcv_nxt) {
print_out_space(out);
fprintf(out, "CHG tlb_rcv_nxt OLD:%u NEW:%u %s\n",
last_buffer.tlb_rcv_nxt, l->tlb_rcv_nxt,
show_diff(last_buffer.tlb_rcv_nxt, l->tlb_rcv_nxt));
}
if (last_buffer.tlb_rcv_wnd != l->tlb_rcv_wnd) {
print_out_space(out);
fprintf(out, "CHG tlb_rcv_wnd OLD:%u NEW:%u %s\n",
last_buffer.tlb_rcv_wnd, l->tlb_rcv_wnd,
show_diff(last_buffer.tlb_rcv_wnd, l->tlb_rcv_wnd));
}
if (last_buffer.tlb_dupacks != l->tlb_dupacks) {
print_out_space(out);
fprintf(out, "CHG tlb_dupacks OLD:%u NEW:%u %s\n",
last_buffer.tlb_dupacks, l->tlb_dupacks,
show_diff(last_buffer.tlb_dupacks, l->tlb_dupacks));
}
if (last_buffer.tlb_segqlen != l->tlb_segqlen) {
print_out_space(out);
fprintf(out, "CHG tlb_segqlen OLD:%u NEW:%u %s\n",
last_buffer.tlb_segqlen, l->tlb_segqlen,
show_diff(last_buffer.tlb_segqlen, l->tlb_segqlen));
}
if (last_buffer.tlb_snd_numholes != l->tlb_snd_numholes) {
print_out_space(out);
fprintf(out, "CHG tlb_snd_numholes OLD:%u NEW:%u\n",
last_buffer.tlb_snd_numholes, l->tlb_snd_numholes);
}
if (last_buffer.tlb_snd_scale != l->tlb_snd_scale) {
print_out_space(out);
fprintf(out, "CHG tlb_snd_scale OLD:%u NEW:%u\n",
last_buffer.tlb_snd_scale, l->tlb_snd_scale);
}
if (last_buffer.tlb_rcv_scale != l->tlb_rcv_scale) {
print_out_space(out);
fprintf(out, "CHG tlb_rcv_scale OLD:%u NEW:%u\n",
last_buffer.tlb_rcv_scale, l->tlb_rcv_scale);
}
memcpy(&last_buffer, l, sizeof(struct tcp_log_buffer));
}
static char *
get_timer_mask(uint32_t tmask)
{
static char mask_value[256];
int outr=0;
memset(mask_value, 0, sizeof(mask_value));
if (tmask & PACE_TMR_DELACK) {
strcat(mask_value, "DACK");
outr = 1;
} else if (tmask & PACE_TMR_RACK) {
strcat(mask_value, "RACK");
outr = 1;
} else if (tmask & PACE_TMR_TLP) {
strcat(mask_value, "TLP");
outr = 1;
} else if (tmask & PACE_TMR_RXT) {
strcat(mask_value, "RXT");
outr = 1;
} else if (tmask & PACE_TMR_PERSIT) {
strcat(mask_value, "PER");
outr = 1;
} else if (tmask & PACE_TMR_KEEP) {
strcat(mask_value, "KEEP");
outr = 1;
}
if (tmask & PACE_PKT_OUTPUT) {
if (outr)
strcat(mask_value, " & OUTPUT");
else
strcat(mask_value, "OUTPUT");
outr++;
}
if (outr == 0)
strcat(mask_value, "NONE");
return(mask_value);
}
static char *
translate_flags(uint16_t flags)
{
static char flagbuf[256];
memset(flagbuf, 0, sizeof(flagbuf));
int buf_at = 0;
if (flags & TH_FIN) {
strcat(flagbuf, "FIN");
buf_at += 3;
}
if (flags & TH_SYN) {
if (buf_at)
strcat(flagbuf, "|");
strcat(flagbuf, "SYN");
buf_at += 3;
}
if (flags & TH_RST) {
if (buf_at)
strcat(flagbuf, "|");
strcat(flagbuf, "RST");
buf_at += 3;
}
if (flags & TH_PUSH) {
if (buf_at)
strcat(flagbuf, "|");
strcat(flagbuf, "PUS");
buf_at += 3;
}
if (flags & TH_ACK) {
if (buf_at)
strcat(flagbuf, "|");
strcat(flagbuf, "ACK");
buf_at += 3;
}
if (flags & TH_URG) {
if (buf_at)
strcat(flagbuf, "|");
strcat(flagbuf, "URG");
buf_at += 3;
}
if (flags & TH_ECE) {
if (buf_at)
strcat(flagbuf, "|");
strcat(flagbuf, "ECE");
buf_at += 3;
}
if (flags & TH_CWR) {
if (buf_at)
strcat(flagbuf, "|");
strcat(flagbuf, "CWR");
buf_at += 3;
}
if (flags & TH_AE) {
if (buf_at)
strcat(flagbuf, "|");
strcat(flagbuf, "AE");
buf_at += 2;
}
if (buf_at == 0)
strcat(flagbuf, "NON");
return(flagbuf);
}
static uint64_t
bbr_get_bw_delay_prod(uint64_t rtt, uint64_t bw)
{
/*
* Calculate the bytes in flight needed give the bw (in bytes per
* second) and the specifyed rtt in useconds. We need to put out the
* returned value per RTT to match that rate. Gain will normaly
* raise it up from there.
*/
uint64_t usec_per_sec, bdp;
usec_per_sec = 1000000;
bdp = (rtt * bw)/usec_per_sec;
return (bdp);
}
static uint32_t
bbr_get_target_cwnd(uint64_t bw, uint64_t rtt, uint32_t gain)
{
uint64_t bdp;
uint32_t cwnd;
#ifdef DO_ROUND
uint32_t mss, even_targ;
#endif
/* Get the bdp from the two values */
bdp = bbr_get_bw_delay_prod(rtt, bw);
/* Now apply the gain */
cwnd = (uint32_t) (((bdp * ((uint64_t) gain)) + (uint64_t) (BBR_UNIT - 1)) / ((uint64_t) BBR_UNIT));
/* round up to then next mss boundary */
#ifdef DO_ROUND
mss = (bbr->rc_tp->t_maxseg - bbr->r_ctl.rc_last_options);
even_targ = (cwnd + (mss - 1)) / mss;
/* Lets make sure its an even number */
if (even_targ & 0x01) {
even_targ++;
}
cwnd = even_targ * mss;
#endif
return (cwnd);
}
static const char *timer_types[7] = {
"UNKN",
"RTO ",
"TLP ",
"RACK",
"KEEP",
"PERS",
"DACK"
};
#define BBR_TO_FRM_TMR 1
#define BBR_TO_FRM_TLP 2
#define BBR_TO_FRM_RACK 3
static const char *major_state[6] = {
"UNKNOWN STATE",
"BBR_STATE_STARTUP",
"BBR_STATE_DRAIN",
"BBR_STATE_PROBE_BW",
"BBR_STATE_PROBE_RTT",
"BBR_STATE_PERSIST_EXIT",
};
static const char *startup_reasons[12] = {
"Back from probe-rtt", /* 0 */
"Not up to speed", /* 1 */
"No loss at target", /* 2 */
"Had large Gain", /* 3 */
"Loss forces exit", /* 4 */
"Record new loss", /* 5 */
"Exit to drain", /* 6 */
"Not enough measurements", /* 7 */
"No exit required", /* 8 */
"No measurements", /* 9 */
"No loss no inc-rtt", /* 10 */
"No loss so stay" /* 11 */
};
/*
* startup = 10
* drain = 20
* probe_rtt = 30
* probe_bw = 40 - 110.
*/
static const char *
state_at_to_state_name(uint32_t st)
{
switch (st) {
case 10:
return ("STARTUP");
case 20:
return ("DRAIN");
case 30:
return ("PROBE_RTT");
case 40:
return ("PROBE_BW GAIN");
case 50:
return ("PROBE_BW DRAIN");
case 60:
return ("PROBE_BW LEVEL1");
case 70:
return ("PROBE_BW LEVEL2");
case 80:
return ("PROBE_BW LEVEL3");
case 90:
return ("PROBE_BW LEVEL4");
case 100:
return ("PROBE_BW LEVEL5");
case 110:
return ("PROBE_BW LEVEL6");
default:
return ("UNKNOWN");
}
}
static const char *
get_progress_event(uint8_t id)
{
static char foobar[64];
const char *ret;
if (id == 1) {
ret = "Dropping conn ";
} else if (id == 2) {
ret = "Updating ticks ";
} else if (id == 3) {
ret = "Stop una = th_ack";
} else if (id == 4) {
ret = "Starting una inc";
} else {
sprintf(foobar, "Unknown:%d", id);
ret = foobar;
}
return(ret);
}
static int
pad_out(int at, int to)
{
int i, cnt=0;
for(i=at; i<to; i++) {
cnt += fprintf(out, " ");
}
return(cnt);
}
static uint32_t state_at = 10;
static uint32_t tlb_sn = 0;
static uint32_t tlb_sn_set = 0;
static uint32_t duplicates=0;
static int old_state = 0;
static uint32_t epoch=0;
static uint32_t epoch_time=0;
static uint64_t del_rate=0;
static uint32_t prev_pkt_epoch=0;
static uint64_t pe_btlbw=0;
static int pg_not_set=1;
static int log_all_state_change = 1;
static uint64_t sent_state[9];
static uint64_t retran_count=0;
static uint32_t time_started_using_ltbw=0;
static int using_lt_bw=0;
static uint64_t total_time_using_lt_bw=0;
static uint64_t total_time_in_trace=0;
static uint32_t last_time_stamp;
static uint64_t total_time_persisting=0;
static uint64_t total_time_app_limited=0;
static uint32_t timeOfAppLimit;
static int is_app_limited=0;
static uint64_t app_limited_transitions=0;
static uint64_t total_time_no_avail=0;
static uint32_t timeOfnoAvail;
static int is_none_avail;
static uint64_t total_time_ltbw_sendok;
static int is_ltbw_sndok=0;
static uint32_t time_data_ltbw;
static uint64_t total_time_no_rwnd=0;
static uint32_t timeOfnoRwnd;
static uint32_t time_ended_using_lt_bw=0;
static int is_none_rwnd;
static uint32_t delivered_at_thresh=0;
static uint32_t lost_at_thresh=0;
static uint32_t policing_on = 0;
static int set_pkt_epoch = 0;
static uint32_t del_at_state=0;
static uint32_t lost_at_state=0;
static uint32_t state_send_count = 0;
static uint32_t state_send_bytes = 0;
static uint32_t max_rtt_in_state = 0;
static uint32_t min_rtt_in_state = 0xffffffff;
#define NUM_PKT_EPOCH_TRK 8
static int32_t pkt_epoch_lost[NUM_PKT_EPOCH_TRK];
static int32_t pkt_epoch_del[NUM_PKT_EPOCH_TRK];
static int32_t num_pkt_ep_filled=0;
static void
display_map_chg(const struct tcp_log_bbr *bbr)
{
if (bbr->flex8 > 11) {
fprintf(out, "Found %u at mapchg?\n",
bbr->flex8);
return;
}
fprintf(out, " - %s line:%d ",
map_chg_names[bbr->flex8], bbr->applimited);
if (bbr->flex7 & 0x4) {
fprintf(out, "pr_s:%u pr_e:%u (%u) ",
bbr->flex1, bbr->flex2,
(bbr->flex2 - bbr->flex1));
}
if (bbr->flex7 & 0x2) {
fprintf(out, "at_s:%u at_e:%u (%u) ",
bbr->flex3, bbr->flex4,
(bbr->flex4 - bbr->flex3));
}
if (bbr->flex7 & 0x1) {
fprintf(out, "nx_s:%u nx_e:%u (%u) ",
bbr->flex5, bbr->flex6,
(bbr->flex6 - bbr->flex5));
}
fprintf(out, " end:%u\n", bbr->pkts_out);
if (extra_print) {
print_out_space(out);
fprintf(out, "prev:0x%lx rsm:0x%lx next:0x%lx\n",
bbr->cur_del_rate,
bbr->delRate,
bbr->rttProp);
}
}
static void
pkt_epoch_track(uint32_t pe, uint32_t lost, uint32_t del)
{
int idx, i;
if (num_pkt_ep_filled >= NUM_PKT_EPOCH_TRK)
idx = NUM_PKT_EPOCH_TRK - 1;
else
idx = (pe - 1) % NUM_PKT_EPOCH_TRK;
for(i=idx; i>0; i--) {
pkt_epoch_del[i] = pkt_epoch_del[(i-1)];
pkt_epoch_lost[i] = pkt_epoch_lost[(i-1)];
}
pkt_epoch_del[0] = del;
pkt_epoch_lost[0] = lost;
if (num_pkt_ep_filled < NUM_PKT_EPOCH_TRK)
num_pkt_ep_filled++;
}
static void
print_epoch_loss(uint32_t pe, uint32_t lost, uint32_t del)
{
int i;
double r, l, d;
l = (100.0 * lost);
d = (1.0 * del);
if (l == 0.0) {
r = 0.0;
} else if (d == 0.0) {
r = 100.0;
} else {
r = l/d;
}
fprintf(out, "LOSS_RATES:(o-a)%2.1f%% ", r);
for(i=0; i<num_pkt_ep_filled; i++) {
l = (100.0 * (lost - pkt_epoch_lost[i]));
d = (1.0 * (del - pkt_epoch_del[i]));
if (l == 0.0) {
r = 0.0;
} else if (d == 0.0) {
r = 100.0;
} else {
r = l/d;
}
fprintf(out, "(%d)%2.1f%% ",
(i+1), r);
}
fprintf(out, "\n");
pkt_epoch_track(pe, lost, del);
}
static void
dump_sack_filter(const struct tcp_log_bbr *bbr)
{
fprintf(out, "%d entries left\n", bbr->flex8);
if (bbr->flex8 > 0) {
print_out_space(out);
fprintf(out, "SACK:%u:%u (%u)\n",
bbr->flex1, bbr->flex2,
(bbr->flex2 - bbr->flex1));
}
if (bbr->flex8 > 1) {
print_out_space(out);
fprintf(out, "SACK:%u:%u (%u)\n",
bbr->flex3, bbr->flex4,
(bbr->flex4 - bbr->flex3));
}
if (bbr->flex8 > 2) {
print_out_space(out);
fprintf(out, "SACK:%u:%u (%u)\n",
bbr->flex5, bbr->flex6,
(bbr->flex6 - bbr->flex5));
}
if (bbr->flex8 > 3) {
print_out_space(out);
fprintf(out, "SACK:%u:%u (%u)\n",
bbr->applimited,
bbr->pkts_out,
(bbr->pkts_out - bbr->applimited));
}
}
static void
sort_sack_blocks(struct sackblk *sack_blocks, int num_sack_blks)
{
struct sackblk low;
int i, sack_pos = 0;
restart:
memcpy(&low, &sack_blocks[sack_pos], sizeof(struct sackblk));
for(i = (sack_pos+1); i < num_sack_blks; i++) {
if (low.start > sack_blocks[i].start) {
/* this one is lower */
memcpy(&sack_blocks[sack_pos],