source: test/test-wireless.c @ f0c639b

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since f0c639b was f0c639b, checked in by Scott Raynel <smr26@…>, 14 years ago
  • Remove trace_get_wireless_fcs as it is no longer part of the Radiotap standard.
  • Update trace_get_wire_length to account for the presence (or absence) of FCS bytes at the end of wireless frames. (only pcap and pcapfile for now)
  • Update radiotap libpacketdump decoder to no longer output non-standard FCS field.
  • Update test-wireless to ensure new length functions work correctly.
  • Property mode set to 100644
File size: 4.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#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, tmp16;
67        uint8_t flags, rate, sdbm, ndbm, sdb, antenna, tmp8;
68       
69        uint16_t total_freq, expected_freq = 24170;
70       
71        void *l;
72        libtrace_linktype_t lt;
73        trace = trace_create("pcapfile:traces/10_packets_radiotap.pcap");
74        iferr(trace);
75
76        trace_start(trace);
77        iferr(trace);
78       
79        packet=trace_create_packet();
80
81        trace_read_packet(trace, packet);
82
83        l = trace_get_link(packet);
84        lt = trace_get_link_type(packet);
85
86        /* Check that the right linktype is being reported for this trace */
87        assert(lt == TRACE_TYPE_80211_RADIO);
88
89        /* Check that fields that exist in this trace are reported as
90         * existing */
91        assert(trace_get_wireless_tsft(l,lt,&tsft));
92        assert(trace_get_wireless_rate(l,lt,&rate));
93        assert(trace_get_wireless_freq(l,lt,&freq));
94        assert(trace_get_wireless_signal_strength_dbm(l,lt,(int8_t *)&sdbm));
95        assert(trace_get_wireless_noise_strength_dbm(l,lt,(int8_t *)&ndbm));
96        assert(trace_get_wireless_signal_strength_db(l,lt,&sdb));
97        assert(trace_get_wireless_antenna(l,lt,&antenna));
98
99        /* Check that the fields that do not exist in this trace are
100         * reported as not existing */
101        assert(!trace_get_wireless_noise_strength_db(l,lt,&tmp8));
102        assert(!trace_get_wireless_tx_attenuation(l,lt,&tmp16));
103        assert(!trace_get_wireless_tx_attenuation_db(l,lt,&tmp16));
104        assert(!trace_get_wireless_tx_power_dbm(l,lt,(int8_t *)&tmp8));
105
106        /* Check that the functions are returning the right values for
107         * this trace
108         * TODO: Check all fields :)
109         */
110        total_freq = freq;
111       
112        while((result = trace_read_packet(trace, packet)) > 0) {
113                /* This trace has no FCS at the end of packets, so ensure
114                 * that wire-length is 4 bytes greater than capture length */
115                int caplen = trace_get_capture_length(packet);
116                int wirelen = trace_get_wire_length(packet);
117                assert(wirelen == caplen + 4);
118                if(trace_get_wireless_freq(l,lt,&freq)) 
119                        total_freq += freq;
120        }
121
122        assert(total_freq == expected_freq);
123
124        trace_destroy_packet(packet);
125        trace_destroy(trace);
126               
127        /* Now check that we don't process non-radiotap traces */
128       
129        trace = trace_create("pcapfile:traces/100_packets.pcap");
130        iferr(trace);
131        trace_start(trace);
132        iferr(trace);
133        packet = trace_create_packet();
134        trace_read_packet(trace,packet);
135        l = trace_get_link(packet);
136        lt = trace_get_link_type(packet);
137        assert(lt != TRACE_TYPE_80211_RADIO);
138
139        assert(!trace_get_wireless_tsft(l,lt,&tsft));
140        assert(!trace_get_wireless_rate(l,lt,&rate));
141        assert(!trace_get_wireless_freq(l,lt,&freq));
142        assert(!trace_get_wireless_signal_strength_dbm(l,lt,(int8_t *)&sdbm));
143        assert(!trace_get_wireless_noise_strength_dbm(l,lt,(int8_t *)&ndbm));
144        assert(!trace_get_wireless_signal_strength_db(l,lt,&sdb));
145        assert(!trace_get_wireless_antenna(l,lt,&antenna));
146        assert(!trace_get_wireless_noise_strength_db(l,lt,&tmp8));
147        assert(!trace_get_wireless_tx_attenuation(l,lt,&tmp16));
148        assert(!trace_get_wireless_tx_attenuation_db(l,lt,&tmp16));
149        assert(!trace_get_wireless_tx_power_dbm(l,lt,(int8_t *)&tmp8));
150
151
152        trace_destroy_packet(packet);
153        trace_destroy(trace);
154        printf("%s: success\n", argv[0]);
155        return 0;
156}
Note: See TracBrowser for help on using the repository browser.