source: tools/tracereport/tcpsegment_report.c

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivendag_formatrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file was ee6e802, checked in by Shane Alcock <salcock@…>, 4 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: 3.1 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
28#include <netdb.h>
29#include <inttypes.h>
30#include <lt_inttypes.h>
31#include <stdio.h>
32#include "libtrace.h"
33#include "tracereport.h"
34#include "report.h"
35
36#define MAX_SEG_SIZE 10000
37
38static stat_t tcpseg_stat[3][MAX_SEG_SIZE + 1] = {{{0,0}}} ;
39static bool suppress[3] = {true,true,true};
40
41void tcpseg_per_packet(struct libtrace_packet_t *packet)
42{
43        struct libtrace_tcp *tcp = trace_get_tcp(packet);
44        libtrace_ip_t *ip = trace_get_ip(packet);
45        libtrace_direction_t dir = trace_get_direction(packet);
46        int ss;
47        uint16_t ip_len ;
48       
49        if (!tcp || !ip)
50                return;
51
52        if (dir != TRACE_DIR_INCOMING && dir != TRACE_DIR_OUTGOING)
53                dir = TRACE_DIR_OTHER;
54       
55        ip_len = ntohs(ip->ip_len);
56        ss = ip_len - (ip->ip_hl * 4);
57
58        if (ss > MAX_SEG_SIZE) {
59                fprintf(stderr, "Maximum segment size %u exceeded - size was %u\n",
60                                MAX_SEG_SIZE, ss);
61                return;
62        }
63
64
65        tcpseg_stat[dir][ss].count++;
66        tcpseg_stat[dir][ss].bytes+=trace_get_wire_length(packet);
67        suppress[dir] = false;
68}
69
70void tcpseg_report(void)
71{
72        int i,j;
73        FILE *out = fopen("tcpseg.rpt", "w");
74        if (!out) {
75                perror("fopen");
76                return;
77        }
78        fprintf(out, "%-16s\t%10s\t%16s %16s\n",
79                        "SEGMENT SIZE",
80                        "DIRECTION",
81                        "BYTES",
82                        "PACKETS");
83       
84        for(i=0;i<2048;++i) {
85                bool indent_needed;
86                if (tcpseg_stat[0][i].count==0 && 
87                        tcpseg_stat[1][i].count==0 && tcpseg_stat[2][i].count==0)
88                        continue;
89                fprintf(out, "%16i:",i);
90                indent_needed=false;
91                for(j=0;j<3;j++){
92                        if (indent_needed) {
93                                fprintf(out, "%16s", " ");
94                        }
95                        if (suppress[j])
96                                continue;
97                        switch (j) {
98                                case 0:
99                                        fprintf(out, "\t%10s", "Outbound");
100                                        break;
101                                case 1:
102                                        fprintf(out, "\t%10s", "Inbound");
103                                        break;
104                                case 2:
105                                        fprintf(out, "\t%10s", "Unknown");
106                                        break;
107                        }
108                        fprintf(out, "\t%16" PRIu64 " %16" PRIu64 "\n",
109                                tcpseg_stat[j][i].bytes,
110                                tcpseg_stat[j][i].count);       
111                        indent_needed=true;
112                }
113        }
114        fclose(out);
115}
Note: See TracBrowser for help on using the repository browser.