source: tools/tracereport/flow_report.c @ 051618c

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 051618c was d4336d5, checked in by Shane Alcock <salcock@…>, 15 years ago

Updated tracereport to include all the work Josef has done

  • Property mode set to 100644
File size: 1.1 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
10static uint64_t flow_count=0;
11
12struct fivetuple_t {
13        uint32_t ipa;
14        uint32_t ipb;
15        uint16_t porta;
16        uint16_t portb;
17        uint8_t prot;
18};
19
20static int fivetuplecmp(struct fivetuple_t a, struct fivetuple_t b)
21{
22        if (a.porta != b.porta) return a.porta-b.porta;
23        if (a.portb != b.portb) return a.portb-b.portb;
24        if (a.ipa != b.ipa) return a.ipa-b.ipa;
25        if (a.ipb != b.ipb) return a.ipb-b.ipb;
26        return a.prot - b.prot;
27}
28
29SET_CREATE(flowset,struct fivetuple_t,fivetuplecmp)
30
31void flow_per_packet(struct libtrace_packet_t *packet)
32{
33        struct libtrace_ip *ip = trace_get_ip(packet);
34        struct fivetuple_t ft;
35        if (!ip)
36                return;
37        ft.ipa=ip->ip_src.s_addr;
38        ft.ipb=ip->ip_dst.s_addr;
39        ft.porta=trace_get_source_port(packet);
40        ft.portb=trace_get_destination_port(packet);
41
42        if (!SET_CONTAINS(flowset,ft)) {
43                SET_INSERT(flowset,ft);
44                flow_count++;
45        }
46}
47
48void flow_report(void)
49{
50        printf("# Flows:\n");
51        printf("Flows: %" PRIu64 "\n",flow_count);
52}
Note: See TracBrowser for help on using the repository browser.