source: test/test-drops.c @ e111394

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

Add a pretty dumb test for checking the drop code.

  • Property mode set to 100644
File size: 3.3 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        return type;
75}
76
77int main(int argc, char *argv[]) {
78        int psize = 0;
79        libtrace_t *trace;
80        libtrace_packet_t *packet;
81        int error;
82
83        if (argc<2) {
84                fprintf(stderr,"usage: %s type\n",argv[0]);
85                return 1;
86        }
87
88        trace = trace_create(lookup_uri(argv[1]));
89        iferr(trace);
90
91        trace_start(trace);
92        iferr(trace);
93       
94        packet=trace_create_packet();
95        for (;;) {
96                if ((psize = trace_read_packet(trace, packet)) <0) {
97                        error = 1;
98                        iferr(trace);
99                        break;
100                }
101                if (psize == 0) {
102                        error = 0;
103                        break;
104                }
105
106        }
107        trace_destroy_packet(packet);
108       
109        if (error == 0) {
110                uint64_t f;
111                f=trace_get_received_packets(trace);
112                if (f!=UINT64_MAX)
113                        fprintf(stderr,"%" PRIu64 " packets on input\n",f);
114                f=trace_get_filtered_packets(trace);
115                if (f!=UINT64_MAX)
116                        fprintf(stderr,"%" PRIu64 " packets filtered\n",f);
117                f=trace_get_dropped_packets(trace);
118                if (f!=UINT64_MAX)
119                        fprintf(stderr,"%" PRIu64 " packets dropped\n",f);
120                f=trace_get_accepted_packets(trace);
121                if (f!=UINT64_MAX)
122                        fprintf(stderr,"%" PRIu64 " packets accepted\n",f);
123        } else {
124                iferr(trace);
125        }
126        trace_destroy(trace);
127        return error;
128}
Note: See TracBrowser for help on using the repository browser.