source: tools/tracereport/flow_report.c @ 8e11beb

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivendag_formatrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 8e11beb was ee6e802, checked in by Shane Alcock <salcock@…>, 5 years ago

Updated copyright blurb on all source files

In some cases, this meant adding copyright blurbs to files that
had never had them before.

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[ee6e802]1/*
2 *
3 * Copyright (c) 2007-2016 The University of Waikato, Hamilton, New Zealand.
4 * All rights reserved.
5 *
6 * This file is part of libtrace.
7 *
8 * This code has been developed by the University of Waikato WAND
9 * research group. For further information please see http://www.wand.net.nz/
10 *
11 * libtrace is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * libtrace is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 *
24 *
25 */
26
27
[d3ff1fb]28#include <netdb.h>
29#include <inttypes.h>
[e3b0188]30#include <lt_inttypes.h>
[d3ff1fb]31#include <stdio.h>
32#include <stdlib.h>
33#include "libtrace.h"
34#include "tracereport.h"
[49ce177]35#include "contain.h"
[466aed6]36#include "report.h"
[d3ff1fb]37
38static uint64_t flow_count=0;
39
40struct fivetuple_t {
41        uint32_t ipa;
42        uint32_t ipb;
43        uint16_t porta;
44        uint16_t portb;
45        uint8_t prot;
46};
47
[49ce177]48static int fivetuplecmp(struct fivetuple_t a, struct fivetuple_t b)
[d3ff1fb]49{
[49ce177]50        if (a.porta != b.porta) return a.porta-b.porta;
51        if (a.portb != b.portb) return a.portb-b.portb;
52        if (a.ipa != b.ipa) return a.ipa-b.ipa;
53        if (a.ipb != b.ipb) return a.ipb-b.ipb;
54        return a.prot - b.prot;
[d3ff1fb]55}
56
[a8f2692]57static int flowset_cmp(const splay *a, const splay *b);
[49ce177]58SET_CREATE(flowset,struct fivetuple_t,fivetuplecmp)
59
[d3ff1fb]60void flow_per_packet(struct libtrace_packet_t *packet)
61{
62        struct libtrace_ip *ip = trace_get_ip(packet);
[49ce177]63        struct fivetuple_t ft;
[d3ff1fb]64        if (!ip)
65                return;
[49ce177]66        ft.ipa=ip->ip_src.s_addr;
67        ft.ipb=ip->ip_dst.s_addr;
68        ft.porta=trace_get_source_port(packet);
69        ft.portb=trace_get_destination_port(packet);
[ddab7f9]70        ft.prot = 0;
[49ce177]71
72        if (!SET_CONTAINS(flowset,ft)) {
73                SET_INSERT(flowset,ft);
74                flow_count++;
[d3ff1fb]75        }
76}
77
78void flow_report(void)
79{
[bd4bec9]80        FILE *out = fopen("flows.rpt", "w");
[e991529]81        if (!out) {
82                perror("fopen");
83                return;
84        }
85        fprintf(out, "Flows: %" PRIu64 "\n",flow_count);
86        fclose(out);
[d3ff1fb]87}
Note: See TracBrowser for help on using the repository browser.