source: tools/tracereport/flow_report.c @ a8f2692

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since a8f2692 was a8f2692, checked in by Perry Lorier <perry@…>, 11 years ago

Tidy up a bazillion tiny warnings

  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include <netdb.h>
2#include <inttypes.h>
3#include <lt_inttypes.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include "libtrace.h"
7#include "tracereport.h"
8#include "contain.h"
9#include "report.h"
10
11static uint64_t flow_count=0;
12
13struct fivetuple_t {
14        uint32_t ipa;
15        uint32_t ipb;
16        uint16_t porta;
17        uint16_t portb;
18        uint8_t prot;
19};
20
21static int fivetuplecmp(struct fivetuple_t a, struct fivetuple_t b)
22{
23        if (a.porta != b.porta) return a.porta-b.porta;
24        if (a.portb != b.portb) return a.portb-b.portb;
25        if (a.ipa != b.ipa) return a.ipa-b.ipa;
26        if (a.ipb != b.ipb) return a.ipb-b.ipb;
27        return a.prot - b.prot;
28}
29
30static int flowset_cmp(const splay *a, const splay *b);
31SET_CREATE(flowset,struct fivetuple_t,fivetuplecmp)
32
33void flow_per_packet(struct libtrace_packet_t *packet)
34{
35        struct libtrace_ip *ip = trace_get_ip(packet);
36        struct fivetuple_t ft;
37        if (!ip)
38                return;
39        ft.ipa=ip->ip_src.s_addr;
40        ft.ipb=ip->ip_dst.s_addr;
41        ft.porta=trace_get_source_port(packet);
42        ft.portb=trace_get_destination_port(packet);
43
44        if (!SET_CONTAINS(flowset,ft)) {
45                SET_INSERT(flowset,ft);
46                flow_count++;
47        }
48}
49
50void flow_report(void)
51{
52        FILE *out = fopen("flows.rpt", "w");
53        if (!out) {
54                perror("fopen");
55                return;
56        }
57        fprintf(out, "Flows: %" PRIu64 "\n",flow_count);
58        fclose(out);
59}
Note: See TracBrowser for help on using the repository browser.