1 | #include <netdb.h> |
---|
2 | #include <inttypes.h> |
---|
3 | #include <lt_inttypes.h> |
---|
4 | #include <stdio.h> |
---|
5 | #include "libtrace.h" |
---|
6 | #include "tracereport.h" |
---|
7 | #include "report.h" |
---|
8 | |
---|
9 | static stat_t ecn_stat[3][4] = {{{0,0}}} ; |
---|
10 | |
---|
11 | void ecn_per_packet(struct libtrace_packet_t *packet) |
---|
12 | { |
---|
13 | struct libtrace_ip *ip = trace_get_ip(packet); |
---|
14 | libtrace_direction_t dir = trace_get_direction(packet); |
---|
15 | int ecn; |
---|
16 | |
---|
17 | if (!ip) |
---|
18 | return; |
---|
19 | |
---|
20 | if (dir != TRACE_DIR_INCOMING && dir != TRACE_DIR_OUTGOING) |
---|
21 | dir = TRACE_DIR_OTHER; |
---|
22 | |
---|
23 | ecn = ip->ip_tos & 0x2; |
---|
24 | ecn_stat[dir][ecn].count++; |
---|
25 | ecn_stat[dir][ecn].bytes+=trace_get_wire_length(packet); |
---|
26 | } |
---|
27 | |
---|
28 | void ecn_report(void) |
---|
29 | { |
---|
30 | int i,j; |
---|
31 | int total = 0; |
---|
32 | |
---|
33 | FILE *out = fopen("ecn.rpt", "w"); |
---|
34 | if (!out) { |
---|
35 | perror("fopen"); |
---|
36 | return; |
---|
37 | } |
---|
38 | |
---|
39 | /* Put some headings up for human-readability */ |
---|
40 | fprintf(out, "%-12s\t%10s\t%16s %16s\n", |
---|
41 | "ECN", |
---|
42 | "DIRECTION", |
---|
43 | "BYTES", |
---|
44 | "PACKETS"); |
---|
45 | |
---|
46 | for(i=0;i<4;++i) { |
---|
47 | if (ecn_stat[0][i].count==0 && |
---|
48 | ecn_stat[1][i].count==0 && ecn_stat[2][i].count==0) |
---|
49 | continue; |
---|
50 | switch(i){ |
---|
51 | case 1: |
---|
52 | fprintf(out, "%12s", "ECN CAPE |"); |
---|
53 | break; |
---|
54 | case 2: |
---|
55 | fprintf(out, "%12s", "ECN CAPE |"); |
---|
56 | break; |
---|
57 | case 3: |
---|
58 | fprintf(out, "%12s", "CONG EXP |"); |
---|
59 | break; |
---|
60 | default: |
---|
61 | fprintf(out, "%12s", "NO ECN |"); |
---|
62 | } |
---|
63 | |
---|
64 | for(j=0;j<3;j++){ |
---|
65 | if (j != 0) { |
---|
66 | fprintf(out, "%12s", " |"); |
---|
67 | } |
---|
68 | |
---|
69 | switch (j) { |
---|
70 | case 0: |
---|
71 | fprintf(out, "\t%10s", "Outbound"); |
---|
72 | break; |
---|
73 | case 1: |
---|
74 | fprintf(out, "\t%10s", "Inbound"); |
---|
75 | break; |
---|
76 | case 2: |
---|
77 | fprintf(out, "\t%10s", "Unknown"); |
---|
78 | break; |
---|
79 | } |
---|
80 | fprintf(out, "\t%16" PRIu64 " %16" PRIu64 "\n", |
---|
81 | ecn_stat[j][i].bytes, |
---|
82 | ecn_stat[j][i].count); |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | for(i=0;i<4;i++){ |
---|
87 | for(j=1;j<4;j++) |
---|
88 | total += ecn_stat[i][j].count; |
---|
89 | } |
---|
90 | fprintf(out, "%s: %i\n", "Total ECN", total); |
---|
91 | fclose(out); |
---|
92 | } |
---|