source: test/test-wireless.c @ faffcfc

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since faffcfc was faffcfc, checked in by Scott Raynel <smr26@…>, 15 years ago

Add tests for wireless functions in tests/test-wireless.c

  • Property mode set to 100644
File size: 5.5 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 "libtrace.h"
50
51void iferr(libtrace_t *trace)
52{
53        libtrace_err_t err = trace_get_err(trace);
54        if (err.err_num==0)
55                return;
56        printf("Error: %s\n",err.problem);
57        exit(1);
58}
59
60
61int main(int argc, char *argv[]) {
62        libtrace_t *trace;
63        libtrace_packet_t *packet;
64        int result;
65        uint64_t tsft;
66        uint16_t freq, cflags, tmp16;
67        uint32_t fcs;
68        uint8_t flags, rate, sdbm, ndbm, sdb, antenna, tmp8;
69       
70        uint32_t total_fcs, expected_fcs = 3012874435;
71        uint16_t total_freq, expected_freq = 24170;
72        uint16_t total_cflags, expected_cflags = 1600;
73       
74        void *l;
75        libtrace_linktype_t lt;
76        trace = trace_create("pcapfile:traces/10_packets_radiotap.pcap");
77        iferr(trace);
78
79        trace_start(trace);
80        iferr(trace);
81       
82        packet=trace_create_packet();
83
84        trace_read_packet(trace, packet);
85
86        l = trace_get_link(packet);
87        lt = trace_get_link_type(packet);
88
89        /* Check that the right linktype is being reported for this trace */
90        assert(lt == TRACE_TYPE_80211_RADIO);
91
92        /* Check that fields that exist in this trace are reported as
93         * existing */
94        assert(trace_get_wireless_tsft(l,lt,&tsft));
95        assert(trace_get_wireless_flags(l,lt,&flags));
96        assert(trace_get_wireless_rate(l,lt,&rate));
97        assert(trace_get_wireless_freq(l,lt,&freq));
98        assert(trace_get_wireless_channel_flags(l,lt,&cflags));
99        assert(trace_get_wireless_signal_strength_dbm(l,lt,(int8_t *)&sdbm));
100        assert(trace_get_wireless_noise_strength_dbm(l,lt,(int8_t *)&ndbm));
101        assert(trace_get_wireless_signal_strength_db(l,lt,&sdb));
102        assert(trace_get_wireless_antenna(l,lt,&antenna));
103        assert(trace_get_wireless_fcs(l,lt,&fcs));
104
105        /* Check that the fields that do not exist in this trace are
106         * reported as not existing */
107        assert(!trace_get_wireless_fhss_hopset(l,lt,&tmp8));
108        assert(!trace_get_wireless_fhss_hoppattern(l,lt,&tmp8));
109        assert(!trace_get_wireless_noise_strength_db(l,lt,&tmp8));
110        assert(!trace_get_wireless_lock_quality(l,lt,&tmp16));
111        assert(!trace_get_wireless_tx_attenuation(l,lt,&tmp16));
112        assert(!trace_get_wireless_tx_attenuation_db(l,lt,&tmp16));
113        assert(!trace_get_wireless_tx_power_dbm(l,lt,(int8_t *)&tmp8));
114
115        /* Check that the functions are returning the right values for
116         * this trace
117         * TODO: Check all fields :)
118         */
119        total_fcs = fcs;
120        total_freq = freq;
121        total_cflags = cflags;
122       
123        while((result = trace_read_packet(trace, packet)) > 0) {
124                if(trace_get_wireless_fcs(l,lt,&fcs)) 
125                        total_fcs += fcs;
126                if(trace_get_wireless_freq(l,lt,&freq)) 
127                        total_freq += freq;
128                if(trace_get_wireless_channel_flags(l,lt,&cflags))
129                        total_cflags += cflags;
130        }
131
132        assert(total_fcs == expected_fcs);
133        assert(total_freq == expected_freq);
134        assert(total_cflags == expected_cflags);
135
136        trace_destroy_packet(packet);
137        trace_destroy(trace);
138               
139        /* Now check that we don't process non-radiotap traces */
140       
141        trace = trace_create("pcapfile:traces/100_packets.pcap");
142        iferr(trace);
143        trace_start(trace);
144        iferr(trace);
145        packet = trace_create_packet();
146        trace_read_packet(trace,packet);
147        l = trace_get_link(packet);
148        lt = trace_get_link_type(packet);
149        assert(lt != TRACE_TYPE_80211_RADIO);
150
151        assert(!trace_get_wireless_tsft(l,lt,&tsft));
152        assert(!trace_get_wireless_flags(l,lt,&flags));
153        assert(!trace_get_wireless_rate(l,lt,&rate));
154        assert(!trace_get_wireless_freq(l,lt,&freq));
155        assert(!trace_get_wireless_channel_flags(l,lt,&cflags));
156        assert(!trace_get_wireless_signal_strength_dbm(l,lt,(int8_t *)&sdbm));
157        assert(!trace_get_wireless_noise_strength_dbm(l,lt,(int8_t *)&ndbm));
158        assert(!trace_get_wireless_signal_strength_db(l,lt,&sdb));
159        assert(!trace_get_wireless_antenna(l,lt,&antenna));
160        assert(!trace_get_wireless_fcs(l,lt,&fcs));
161        assert(!trace_get_wireless_fhss_hopset(l,lt,&tmp8));
162        assert(!trace_get_wireless_fhss_hoppattern(l,lt,&tmp8));
163        assert(!trace_get_wireless_noise_strength_db(l,lt,&tmp8));
164        assert(!trace_get_wireless_lock_quality(l,lt,&tmp16));
165        assert(!trace_get_wireless_tx_attenuation(l,lt,&tmp16));
166        assert(!trace_get_wireless_tx_attenuation_db(l,lt,&tmp16));
167        assert(!trace_get_wireless_tx_power_dbm(l,lt,(int8_t *)&tmp8));
168
169
170        trace_destroy_packet(packet);
171        trace_destroy(trace);
172        printf("%s: success\n", argv[0]);
173        return 0;
174}
Note: See TracBrowser for help on using the repository browser.