source: tools/tracereport/flow_report.c @ 734dfb1

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

Add trace summary

  • Property mode set to 100644
File size: 1.3 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 "tree.h"
8
9static tree_t *flows=NULL;
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(const void *a, const void *b)
21{
22        const struct fivetuple_t *as=a;
23        const struct fivetuple_t *bs=b;
24        if (as->ipa != bs->ipa) return as->ipa-bs->ipa;
25        if (as->ipb != bs->ipb) return as->ipb-bs->ipb;
26        if (as->porta != bs->porta) return as->porta-bs->porta;
27        if (as->portb != bs->portb) return as->portb-bs->portb;
28        return as->porta - as->portb;
29}
30
31void flow_per_packet(struct libtrace_packet_t *packet)
32{
33        struct libtrace_ip *ip = trace_get_ip(packet);
34        struct fivetuple_t *ftp;
35        if (!ip)
36                return;
37        ftp=malloc(sizeof(struct fivetuple_t));
38        ftp->ipa=ip->ip_src.s_addr;
39        ftp->ipb=ip->ip_dst.s_addr;
40        ftp->porta=trace_get_source_port(packet);
41        ftp->portb=trace_get_destination_port(packet);
42
43        stat_t *stat=tree_find(&flows,ftp,fivetuplecmp);
44        if (!stat) {
45                stat=calloc(1,sizeof(stat_t));
46                ++flow_count;
47        }
48
49        ++stat->count;
50        stat->bytes+=trace_get_wire_length(packet);
51
52        if (tree_replace(&flows,ftp,fivetuplecmp,stat)) {
53                free(ftp);
54        }
55}
56
57void flow_report(void)
58{
59        printf("# Flows:\n");
60        printf("Flows: %" PRIu64 "\n",flow_count);
61}
Note: See TracBrowser for help on using the repository browser.