source: tools/tracereport/tos_report.c @ e78e408

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivendag_formatrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since e78e408 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.3 KB
Line 
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#include <netdb.h>
28#include <inttypes.h>
29#include <lt_inttypes.h>
30#include <stdio.h>
31#include "libtrace.h"
32#include "tracereport.h"
33#include "report.h"
34
35static stat_t tos_stat[3][256] = {{{0,0}}} ;
36static bool suppress[3] = {true,true,true};
37
38void tos_per_packet(struct libtrace_packet_t *packet)
39{
40        struct libtrace_ip *ip = trace_get_ip(packet);
41        libtrace_direction_t dir = trace_get_direction(packet);
42       
43        if (!ip)
44                return;
45       
46        if (dir != TRACE_DIR_INCOMING && dir != TRACE_DIR_OUTGOING)
47                dir = TRACE_DIR_OTHER;
48       
49        tos_stat[dir][ip->ip_tos].count++;
50        tos_stat[dir][ip->ip_tos].bytes+=trace_get_wire_length(packet);
51        suppress[dir] = false;
52}
53
54
55void tos_report(void)
56{
57        int i,j;
58        FILE *out = fopen("tos.rpt", "w");
59        if (!out) {
60                perror("fopen");
61                return;
62        }
63       
64        fprintf(out, "%-12s\t%10s\t%16s %16s\n",
65                        "TOS",
66                        "DIRECTION",
67                        "BYTES",
68                        "PACKETS");
69       
70       
71        for(i=0;i<256;++i) {
72                if (tos_stat[0][i].count==0 && 
73                        tos_stat[1][i].count==0 && tos_stat[2][i].count==0)
74                        continue;
75                fprintf(out, "%12i:",i);
76                for(j=0;j<3;j++){
77                        if (j != 0) {
78                                fprintf(out, "%12s", " ");
79                        }
80                        switch(j) {
81                                case 0:
82                                        fprintf(out, "\t%10s", "Outbound");
83                                        break;
84                                case 1:
85                                        fprintf(out, "\t%10s", "Inbound");
86                                        break;
87                                case 2:
88                                        fprintf(out, "\t%10s", "Unknown");
89                                        break;
90                        }
91                        fprintf(out, "\t%16" PRIu64 " %16" PRIu64 "\n",
92                                tos_stat[j][i].bytes,
93                                tos_stat[j][i].count);
94                }
95        }
96        fclose(out);
97}
Note: See TracBrowser for help on using the repository browser.