source: test/test-convert.c @ cd7eec7

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since cd7eec7 was cd7eec7, checked in by Shane Alcock <salcock@…>, 15 years ago

Added a new format for reading and writing DUCK packets
Added corresponding test cases for DUCK
Removed references to RT_DUCK_* from format_rt
Added a configuration option for meta-data frequency (used solely for DUCK frequency at the moment) and updated other formats to ignore the option

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * This file is part of libtrace
3 *
4 * Copyright (c) 2004 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-pcap-to-erf.c,v 1.3 2006/02/27 03:41:12 perry Exp $
28 *
29 */
30#ifndef WIN32
31#  include <sys/time.h>
32#  include <netinet/in.h>
33#  include <netinet/in_systm.h>
34#  include <netinet/tcp.h>
35#  include <netinet/ip.h>
36#  include <netinet/ip_icmp.h>
37#  include <arpa/inet.h>
38#  include <sys/socket.h>
39#endif
40
41#include <stdio.h>
42#include <stdlib.h>
43#include <assert.h>
44#include <string.h>
45#include <sys/types.h>
46#include <time.h>
47#include <string.h>
48
49#include "dagformat.h"
50#include "libtrace.h"
51
52void iferr(libtrace_t *trace)
53{
54        libtrace_err_t err = trace_get_err(trace);
55        if (err.err_num==0)
56                return;
57        printf("Error: %s\n",err.problem);
58        exit(1);
59}
60
61void iferrout(libtrace_out_t *trace)
62{
63        libtrace_err_t err = trace_get_err_output(trace);
64        if (err.err_num==0)
65                return;
66        printf("Error: %s\n",err.problem);
67        exit(1);
68}
69
70char *lookup_uri(const char *type) 
71{
72        if (!strcmp(type,"erf"))
73                return "erf:traces/100_packets.erf";
74        if (!strcmp(type,"pcap"))
75                return "pcap:traces/100_packets.pcap";
76        if (!strcmp(type,"wtf"))
77                return "wtf:traces/wed.wtf";
78        if (!strcmp(type,"rtclient"))
79                return "rtclient:chasm";
80        if (!strcmp(type,"pcapfile"))
81                return "pcapfile:traces/100_packets.pcap";
82        if (!strcmp(type, "duck"))
83                return "duck:traces/100_packets.duck";
84        return "unknown";
85}
86
87char *lookup_out_uri(const char *type) {
88        if (!strcmp(type,"erf"))
89                return "erf:traces/100_packets.out.erf";
90        if (!strcmp(type,"pcap"))
91                return "pcap:traces/100_packets.out.pcap";
92        if (!strcmp(type,"wtf"))
93                return "wtf:traces/wed.out.wtf";
94        if (!strcmp(type,"duck"))
95                return "duck:traces/100_packets.out.duck";
96        return "unknown";
97}
98
99int main(int argc, char *argv[]) {
100        int psize = 0;
101        int error = 0;
102        int count = 0;
103        int level = 0;
104        int expected = 100;
105        libtrace_t *trace;
106        libtrace_out_t *outtrace;
107        libtrace_packet_t *packet;
108
109        trace = trace_create(lookup_uri(argv[1]));
110        iferr(trace);
111
112        if (strcmp(argv[1],"rtclient")==0)
113                expected=101;
114
115        outtrace = trace_create_output(lookup_out_uri(argv[2]));
116        iferrout(outtrace);
117
118        level=0;
119        trace_config_output(outtrace,TRACE_OPTION_OUTPUT_COMPRESS,&level);
120        iferrout(outtrace);
121
122        trace_start(trace);
123        iferr(trace);
124        trace_start_output(outtrace);
125        iferrout(outtrace);
126       
127        packet=trace_create_packet();
128        for (;;) {
129                if ((psize = trace_read_packet(trace, packet)) <0) {
130                        error = 1;
131                        break;
132                }
133                if (psize == 0) {
134                        error = 0;
135                        break;
136                }
137                count ++;
138                trace_write_packet(outtrace,packet);
139                iferrout(outtrace);
140                if (count>100)
141                        break;
142        }
143        trace_destroy_packet(&packet);
144        if (error == 0) {
145                if (count == expected) {
146                        printf("success: %d packets read\n",expected);
147                } else {
148                        printf("failure: %d packets expected, %d seen\n",expected,count);
149                        error = 1;
150                }
151        } else {
152                iferr(trace);
153        }
154        trace_destroy(trace);
155        trace_destroy_output(outtrace);
156        return error;
157}
Note: See TracBrowser for help on using the repository browser.