source: test/test-sll.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 d5a27e8, checked in by Perry Lorier <perry@…>, 14 years ago

Update the copyright information
Fix libpcap issue
Remove all swig/python builds

  • Property mode set to 100644
File size: 3.7 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-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/* This test is a bit more complicated.  It takes a pcap file (which doesn't
42 * have any direction tagging), then tags it (causing a promotion), then
43 * writes it to an erf file (which should demote it again).
44 */
45
46#include <stdio.h>
47#include <stdlib.h>
48#include <assert.h>
49#include <string.h>
50#include <sys/types.h>
51#include <time.h>
52#include <string.h>
53
54#include "libtrace.h"
55
56void iferr(libtrace_t *trace)
57{
58        libtrace_err_t err = trace_get_err(trace);
59        if (err.err_num==0)
60                return;
61        printf("Error: %s\n",err.problem);
62        exit(1);
63}
64
65void iferrout(libtrace_out_t *trace)
66{
67        libtrace_err_t err = trace_get_err_output(trace);
68        if (err.err_num==0)
69                return;
70        printf("Error: %s\n",err.problem);
71        exit(1);
72}
73
74char *lookup_uri(const char *type) 
75{
76                return "pcap:traces/100_packets.pcap";
77}
78
79char *lookup_out_uri(const char *type) {
80        if (!strcmp(type,"pcap"))
81                return "pcap:traces/100_packets.out.pcap";
82        return "unknown";
83}
84
85int main(int argc, char *argv[]) {
86        int psize = 0;
87        int error = 0;
88        int count = 0;
89        int level = 0;
90        int expected = 100;
91        libtrace_t *trace;
92        libtrace_out_t *outtrace;
93        libtrace_packet_t *packet;
94
95        trace = trace_create(lookup_uri("pcap"));
96        iferr(trace);
97
98        outtrace = trace_create_output(lookup_out_uri("pcap"));
99        iferrout(outtrace);
100
101        level=0;
102        trace_config_output(outtrace,TRACE_OPTION_OUTPUT_COMPRESS,&level);
103        iferrout(outtrace);
104
105        trace_start(trace);
106        iferr(trace);
107        trace_start_output(outtrace);
108        iferrout(outtrace);
109       
110        packet=trace_create_packet();
111        for (;;) {
112                if ((psize = trace_read_packet(trace, packet)) <0) {
113                        error = 1;
114                        break;
115                }
116                if (psize == 0) {
117                        error = 0;
118                        break;
119                }
120                count ++;
121                /* Force promotion */
122                if (trace_get_source_port(packet)==80) {
123                        trace_set_direction(packet,TRACE_DIR_OUTGOING);
124                        assert(trace_get_direction(packet)==TRACE_DIR_OUTGOING);
125                        assert(trace_get_source_port(packet)==80);
126                }
127                else {
128                        trace_set_direction(packet,TRACE_DIR_INCOMING);
129                        assert(trace_get_direction(packet)==TRACE_DIR_INCOMING);
130                }
131                /* And then force demotion */
132                trace_write_packet(outtrace,packet);
133                iferrout(outtrace);
134                if (count>100)
135                        break;
136        }
137        trace_destroy_packet(packet);
138        if (error == 0) {
139                if (count != expected) {
140                        printf("failure: %d packets expected, %d seen\n",expected,count);
141                        error = 1;
142                }
143        } else {
144                iferr(trace);
145        }
146        trace_destroy(trace);
147        trace_destroy_output(outtrace);
148
149        return error;
150}
Note: See TracBrowser for help on using the repository browser.