source: test/test-drops.c @ 7c95027

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 7c95027 was 09dd4f1, checked in by Shane Alcock <salcock@…>, 11 years ago
  • Disabled direct read for trace set testing (as direct read seems to cause issues)
  • Added test-case for threading bug fixed in r1685
  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * This file is part of libtrace
3 *
4 * Copyright (c) 2007 The University of Waikato, Hamilton, New Zealand.
5 * Authors: Daniel Lawson
6 *          Perry Lorier
7 *         
8 * All rights reserved.
9 *
10 * This code has been developed by the University of Waikato WAND
11 * research group. For further information please see http://www.wand.net.nz/
12 *
13 * libtrace is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * libtrace is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with libtrace; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 *
27 * $Id: test-rtclient.c,v 1.2 2006/02/27 03:41:12 perry Exp $
28 *
29 */
30#include <stdio.h>
31#include <stdlib.h>
32#include <assert.h>
33#include <string.h>
34#include <sys/types.h>
35#include <time.h>
36#include <string.h>
37#include <inttypes.h>
38
39#include "libtrace.h"
40#include "libpacketdump.h"
41
42void iferr(libtrace_t *trace)
43{
44        libtrace_err_t err = trace_get_err(trace);
45        if (err.err_num==0)
46                return;
47        printf("Error: %s\n",err.problem);
48        exit(1);
49}
50
51const char *lookup_uri(const char *type) {
52        if (strchr(type,':'))
53                return type;
54        if (!strcmp(type,"erf"))
55                return "erf:traces/100_packets.erf";
56        if (!strcmp(type,"pcap"))
57                return "pcap:traces/100_packets.pcap";
58        if (!strcmp(type,"wtf"))
59                return "wtf:traces/wed.wtf";
60        if (!strcmp(type,"rtclient"))
61                return "rtclient:chasm";
62        if (!strcmp(type,"pcapfile"))
63                return "pcapfile:traces/100_packets.pcap";
64        if (!strcmp(type, "duck"))
65                return "duck:traces/100_packets.duck";
66        if (!strcmp(type, "legacyatm"))
67                return "legacyatm:traces/legacyatm.gz";
68        if (!strcmp(type, "legacypos"))
69                return "legacypos:traces/legacypos.gz";
70        if (!strcmp(type, "legacyeth"))
71                return "legacyeth:traces/legacyeth.gz";
72        if (!strcmp(type, "tsh"))
73                return "tsh:traces/10_packets.tsh.gz";
74        if (!strcmp(type, "legacylarge"))
75                return "legacyatm:traces/large_legacy.gz";
76        return type;
77}
78
79int main(int argc, char *argv[]) {
80        int psize = 0;
81        libtrace_t *trace;
82        libtrace_packet_t *packet;
83        int error;
84
85        if (argc<2) {
86                fprintf(stderr,"usage: %s type\n",argv[0]);
87                return 1;
88        }
89
90        trace = trace_create(lookup_uri(argv[1]));
91        iferr(trace);
92
93        trace_start(trace);
94        iferr(trace);
95       
96        packet=trace_create_packet();
97        for (;;) {
98                if ((psize = trace_read_packet(trace, packet)) <0) {
99                        error = 1;
100                        iferr(trace);
101                        break;
102                }
103                if (psize == 0) {
104                        error = 0;
105                        break;
106                }
107
108        }
109        trace_destroy_packet(packet);
110       
111        if (error == 0) {
112                uint64_t f;
113                f=trace_get_received_packets(trace);
114                if (f!=UINT64_MAX)
115                        fprintf(stderr,"%" PRIu64 " packets on input\n",f);
116                f=trace_get_filtered_packets(trace);
117                if (f!=UINT64_MAX)
118                        fprintf(stderr,"%" PRIu64 " packets filtered\n",f);
119                f=trace_get_dropped_packets(trace);
120                if (f!=UINT64_MAX)
121                        fprintf(stderr,"%" PRIu64 " packets dropped\n",f);
122                f=trace_get_accepted_packets(trace);
123                if (f!=UINT64_MAX)
124                        fprintf(stderr,"%" PRIu64 " packets accepted\n",f);
125        } else {
126                iferr(trace);
127        }
128        trace_destroy(trace);
129        return error;
130}
Note: See TracBrowser for help on using the repository browser.