source: tools/tracereport/flow_report.c @ bf7018a

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

Added:

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