1 | #include <inttypes.h> |
---|
2 | #include <stdio.h> |
---|
3 | #include <stdbool.h> |
---|
4 | #include <time.h> |
---|
5 | #include <string.h> |
---|
6 | #include "libtrace.h" |
---|
7 | #include "tracereport.h" |
---|
8 | #include "report.h" |
---|
9 | |
---|
10 | static uint64_t received_packets = 0; |
---|
11 | static uint64_t filtered_packets = 0; |
---|
12 | static uint64_t dropped_packets = 0; |
---|
13 | static uint64_t accepted_packets = 0; |
---|
14 | |
---|
15 | static bool has_received=false; |
---|
16 | static bool has_filtered=false; |
---|
17 | static bool has_dropped=false; |
---|
18 | static bool has_accepted=false; |
---|
19 | |
---|
20 | void drops_per_trace(libtrace_t *trace) |
---|
21 | { |
---|
22 | uint64_t packets; |
---|
23 | |
---|
24 | packets = trace_get_received_packets(trace); |
---|
25 | if (packets != UINT64_MAX) { |
---|
26 | received_packets+=packets; |
---|
27 | has_received=true; |
---|
28 | } |
---|
29 | |
---|
30 | packets = trace_get_filtered_packets(trace); |
---|
31 | if (packets != UINT64_MAX) { |
---|
32 | filtered_packets+=packets; |
---|
33 | has_filtered=true; |
---|
34 | } |
---|
35 | |
---|
36 | packets = trace_get_dropped_packets(trace); |
---|
37 | if (packets != UINT64_MAX) { |
---|
38 | dropped_packets+=packets; |
---|
39 | has_dropped=true; |
---|
40 | } |
---|
41 | |
---|
42 | packets = trace_get_accepted_packets(trace); |
---|
43 | if (packets != UINT64_MAX) { |
---|
44 | accepted_packets+=packets; |
---|
45 | has_accepted=true; |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | void drops_report(void) |
---|
51 | { |
---|
52 | FILE *out = fopen("drop.rpt", "w"); |
---|
53 | if (!out) { |
---|
54 | perror("fopen"); |
---|
55 | return; |
---|
56 | } |
---|
57 | if (has_received) |
---|
58 | fprintf(out, "Received Packets: %" PRIu64 "\n", received_packets); |
---|
59 | if (has_filtered) |
---|
60 | fprintf(out, "Filtered Packets: %" PRIu64 "\n", filtered_packets); |
---|
61 | if (has_dropped) |
---|
62 | fprintf(out, "Dropped Packets: %" PRIu64 "\n", dropped_packets); |
---|
63 | |
---|
64 | if (has_accepted) |
---|
65 | fprintf(out, "Accepted Packets: %" PRIu64 "\n", accepted_packets); |
---|
66 | fclose(out); |
---|
67 | } |
---|