redo pcap tracing

This commit is contained in:
Craig Dowell
2010-01-04 10:35:32 -08:00
parent 6065f2f563
commit 8ae5f99f61
74 changed files with 2200 additions and 1241 deletions

404
src/node/radiotap-header.cc Normal file
View File

@@ -0,0 +1,404 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 CTTC
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Include., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Nicola Baldo <nbaldo@cttc.es>
*/
#include <iomanip>
#include <math.h>
#include "ns3/log.h"
#include "radiotap-header.h"
NS_LOG_COMPONENT_DEFINE ("RadiotapHeader");
namespace ns3 {
RadiotapHeader::RadiotapHeader()
: m_length(8),
m_present(0),
m_tsft(0),
m_flags(FRAME_FLAG_NONE),
m_rate(0),
m_channelFreq(0),
m_channelFlags(CHANNEL_FLAG_NONE),
m_antennaSignal(0),
m_antennaNoise(0)
{
NS_LOG_FUNCTION (this);
}
TypeId RadiotapHeader::GetTypeId (void)
{
static TypeId tid = TypeId ("RadiotapHeader")
.SetParent<Header> ()
.AddConstructor<RadiotapHeader> ()
;
return tid;
}
TypeId
RadiotapHeader::GetInstanceTypeId (void) const
{
NS_LOG_FUNCTION (this);
return GetTypeId ();
}
uint32_t
RadiotapHeader::GetSerializedSize (void) const
{
NS_LOG_FUNCTION (this);
return m_length;
}
void
RadiotapHeader::Serialize (Buffer::Iterator start) const
{
NS_LOG_FUNCTION (this);
start.WriteU8 (0); // major version of radiotap header
start.WriteU8 (0); // pad field
start.WriteU16 (m_length); // entire length of radiotap data + header
start.WriteU32 (m_present); // bits describing which fields follow header
//
// Time Synchronization Function Timer (when the first bit of the MPDU
// arrived at the MAC)
//
if (m_present & RADIOTAP_TSFT) // bit 0
{
start.WriteU64 (m_tsft);
}
//
// Properties of transmitted and received frames.
//
if (m_present & RADIOTAP_FLAGS) // bit 1
{
start.WriteU8 (m_flags);
}
//
// TX/RX data rate in units of 500 kbps
//
if (m_present & RADIOTAP_RATE) // bit 2
{
start.WriteU8 (m_rate);
}
//
// Tx/Rx frequency in MHz, followed by flags.
//
if (m_present & RADIOTAP_CHANNEL) // bit 3
{
start.WriteU16 (m_channelFreq);
start.WriteU16 (m_channelFlags);
}
//
// RF signal power at the antenna, decibel difference from an arbitrary, fixed
// reference.
//
if (m_present & RADIOTAP_DBM_ANTSIGNAL) // bit 5
{
start.WriteU8 (m_antennaSignal);
}
//
// RF noise power at the antenna, decibel difference from an arbitrary, fixed
// reference.
//
if (m_present & RADIOTAP_DBM_ANTNOISE) // bit 6
{
start.WriteU8 (m_antennaNoise);
}
}
uint32_t
RadiotapHeader::Deserialize (Buffer::Iterator start)
{
NS_LOG_FUNCTION (this);
uint8_t tmp = start.ReadU8 (); // major version of radiotap header
NS_ASSERT_MSG (tmp == 0x00, "RadiotapHeader::Deserialize(): Unexpected major version");
start.ReadU8 (); // pad field
m_length = start.ReadU16 (); // entire length of radiotap data + header
m_present = start.ReadU32 (); // bits describing which fields follow header
uint32_t bytesRead = 8;
//
// Time Synchronization Function Timer (when the first bit of the MPDU arrived at the MAC)
//
if (m_present & RADIOTAP_TSFT) // bit 0
{
m_tsft = start.ReadU64();
bytesRead += 8;
}
//
// Properties of transmitted and received frames.
//
if (m_present & RADIOTAP_FLAGS) // bit 1
{
m_flags = start.ReadU8();
++bytesRead;
}
//
// TX/RX data rate in units of 500 kbps
//
if (m_present & RADIOTAP_RATE) // bit 2
{
m_rate = start.ReadU8();
++bytesRead;
}
//
// Tx/Rx frequency in MHz, followed by flags.
//
if (m_present & RADIOTAP_CHANNEL) // bit 3
{
m_channelFreq = start.ReadU16();
m_channelFlags = start.ReadU16();
bytesRead += 4;
}
//
// The hop set and pattern for frequency-hopping radios. We don't need it but
// still need to account for it.
//
if (m_present & RADIOTAP_FHSS) // bit 4
{
start.ReadU8();
++bytesRead;
}
//
// RF signal power at the antenna, decibel difference from an arbitrary, fixed
// reference.
//
if (m_present & RADIOTAP_DBM_ANTSIGNAL) // bit 5
{
m_antennaSignal = start.ReadU8();
++bytesRead;
}
//
// RF noise power at the antenna, decibel difference from an arbitrary, fixed
// reference.
//
if (m_present & RADIOTAP_DBM_ANTNOISE) // bit 6
{
m_antennaNoise = start.ReadU8();
++bytesRead;
}
NS_ASSERT_MSG(m_length == bytesRead, "RadiotapHeader::Deserialize(): expected and actual lengths inconsistent");
return bytesRead;
}
void
RadiotapHeader::Print (std::ostream &os) const
{
NS_LOG_FUNCTION (this);
os << " tsft=" << m_tsft
<< " flags=" << std::hex << m_flags << std::dec
<< " rate=" << (uint16_t) m_rate
<< " freq=" << m_channelFreq
<< " chflags=" << std::hex << (uint32_t)m_channelFlags << std::dec
<< " signal=" << (int16_t) m_antennaSignal
<< " noise=" << (int16_t) m_antennaNoise;
}
void
RadiotapHeader::SetTsft (uint64_t value)
{
NS_LOG_FUNCTION (this << value);
m_tsft = value;
if (!(m_present & RADIOTAP_TSFT))
{
m_present |= RADIOTAP_TSFT;
m_length += 8;
}
NS_LOG_LOGIC (this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec);
}
uint64_t
RadiotapHeader::GetTsft () const
{
NS_LOG_FUNCTION (this);
return m_tsft;
}
void
RadiotapHeader::SetFrameFlags (uint8_t flags)
{
NS_LOG_FUNCTION (this << flags);
m_flags = flags;
if (!(m_present & RADIOTAP_FLAGS))
{
m_present |= RADIOTAP_FLAGS;
m_length += 1;
}
NS_LOG_LOGIC (this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec);
}
uint8_t
RadiotapHeader::GetFrameFlags (void) const
{
NS_LOG_FUNCTION (this);
return m_flags;
}
void
RadiotapHeader::SetRate (uint8_t rate)
{
NS_LOG_FUNCTION (this << rate);
m_rate = rate;
if (!(m_present & RADIOTAP_RATE))
{
m_present |= RADIOTAP_RATE;
m_length += 1;
}
NS_LOG_LOGIC (this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec);
}
uint8_t
RadiotapHeader::GetRate (void) const
{
NS_LOG_FUNCTION (this);
return m_rate;
}
void
RadiotapHeader::SetChannelFrequencyAndFlags (uint16_t frequency, uint16_t flags)
{
NS_LOG_FUNCTION (this << frequency << flags);
m_channelFreq = frequency;
m_channelFlags = flags;
if (!(m_present & RADIOTAP_CHANNEL))
{
m_present |= RADIOTAP_CHANNEL;
m_length += 4;
}
NS_LOG_LOGIC (this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec);
}
uint16_t
RadiotapHeader::GetChannelFrequency (void) const
{
NS_LOG_FUNCTION (this);
return m_channelFreq;
}
uint16_t
RadiotapHeader::GetChannelFlags (void) const
{
NS_LOG_FUNCTION (this);
return m_channelFlags;
}
void
RadiotapHeader::SetAntennaSignalPower (int8_t signal)
{
NS_LOG_FUNCTION (this << signal);
m_antennaSignal = signal;
if (!(m_present & RADIOTAP_DBM_ANTSIGNAL))
{
m_present |= RADIOTAP_DBM_ANTSIGNAL;
m_length += 1;
}
NS_LOG_LOGIC (this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec);
}
void
RadiotapHeader::SetAntennaSignalPower (double signal)
{
NS_LOG_FUNCTION (this << signal);
if (signal < -128)
{
return SetAntennaSignalPower (static_cast<int8_t> (-128));
}
if (signal > 127)
{
return SetAntennaSignalPower (static_cast<int8_t> (127));
}
SetAntennaSignalPower (static_cast<int8_t> (floor(signal + 0.5)));
}
uint8_t
RadiotapHeader::GetAntennaSignalPower (void) const
{
NS_LOG_FUNCTION (this);
return m_antennaSignal;
}
void
RadiotapHeader::SetAntennaNoisePower (int8_t noise)
{
NS_LOG_FUNCTION (this << noise);
m_antennaNoise = noise;
if (!(m_present & RADIOTAP_DBM_ANTNOISE))
{
m_present |= RADIOTAP_DBM_ANTNOISE;
m_length += 1;
}
NS_LOG_LOGIC (this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec);
}
void
RadiotapHeader::SetAntennaNoisePower (double noise)
{
NS_LOG_FUNCTION (this << noise);
if (noise < -128)
{
return SetAntennaNoisePower (static_cast<int8_t> (-128));
}
if (noise > 127)
{
return SetAntennaNoisePower (static_cast<int8_t> (127));
}
SetAntennaNoisePower (static_cast<int8_t> (floor(noise + 0.5)));
}
uint8_t
RadiotapHeader::GetAntennaNoisePower (void) const
{
NS_LOG_FUNCTION (this);
return m_antennaNoise;
}
} // namespace ns3

273
src/node/radiotap-header.h Normal file
View File

@@ -0,0 +1,273 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 CTTC
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Include., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Nicola Baldo <nbaldo@cttc.es>
*/
#ifndef RADIOTAP_HEADER_H
#define RADIOTAP_HEADER_H
#include <ns3/header.h>
namespace ns3 {
/**
* @brief Radiotap header implementation
*
* Radiotap is a de facto standard for 802.11 frame injection and reception.
* The radiotap header format is a mechanism to supply additional information
* about frames, from the driver to userspace applications such as libpcap, and
* from a userspace application to the driver for transmission.
*
* @warning the radiotap header specification says that the fields included in
* the header should be aligned to their natural ize (e.g., 16-bit fields
* aligned to 16-bit boundaries, 32-bit fields aligned to 32-bit boundaries,
* and so on. This implementation does not enforce this. However, the radiotap
* specification enforces an order in which fields have to appear (if they
* appear), and this ordering is such that, provided you don't leave gaps, all
* fields will end up aligned without the need of inserting padding space. By
* the term "gap" I mean not using a field which would appear between two used
* fields. Moral: don't leave gaps, or if you do be careful about how you
* do it.
*/
class RadiotapHeader : public Header
{
public:
RadiotapHeader();
static TypeId GetTypeId (void);
virtual TypeId GetInstanceTypeId (void) const;
/**
* This method is used by Packet::AddHeader to store the header into the byte
* buffer of a packet. This method returns the number of bytes which are
* needed to store the header data during a Serialize.
*
* @returns The expected size of the header.
*/
virtual uint32_t GetSerializedSize (void) const;
/**
* This method is used by Packet::AddHeader to store the header into the byte
* buffer of a packet. The data written is expected to match bit-for-bit the
* representation of this header in a real network.
*
* @param start An iterator which points to where the header should
* be written.
*/
virtual void Serialize (Buffer::Iterator start) const;
/**
* This method is used by Packet::RemoveHeader to re-create a header from the
* byte buffer of a packet. The data read is expected to match bit-for-bit
* the representation of this header in real networks.
*
* @param start An iterator which points to where the header should
* written.
* @returns The number of bytes read.
*/
virtual uint32_t Deserialize (Buffer::Iterator start);
/**
* This method is used by Packet::Print to print the content of the header as
* ascii data to a C++ output stream. Although the header is free to format
* its output as it wishes, it is recommended to follow a few rules to integrate
* with the packet pretty printer: start with flags, small field
* values located between a pair of parens. Values should be separated
* by whitespace. Follow the parens with the important fields,
* separated by whitespace.
*
* eg: (field1 val1 field2 val2 field3 val3) field4 val4 field5 val5
*
* @param os The output stream
*/
virtual void Print (std::ostream &os) const;
/**
* @brief Set the Time Synchronization Function Timer (TSFT) value. Valid for
* received frames only.
*
* @param tsft Value in microseconds of the MAC's 64-bit 802.11 Time
* Synchronization Function timer when the first bit of the MPDU
* arrived at the MAC.
*/
void SetTsft (uint64_t tsft);
/**
* @brief Get the Time Synchronization Function Timer (TSFT) value. Valid for
* received frames only.
*
* @returns The value in microseconds of the MAC's 64-bit 802.11 Time
* Synchronization Function timer when the first bit of the MPDU
* arrived at the MAC.
*/
uint64_t GetTsft (void) const;
enum {FRAME_FLAG_NONE = 0x00}; /**< No flags set */
enum {FRAME_FLAG_CFP = 0x01}; /**< Frame sent/received during CFP */
enum {FRAME_FLAG_SHORT_PREAMBLE = 0x02}; /**< Frame sent/received with short preamble */
enum {FRAME_FLAG_WEP = 0x04}; /**< Frame sent/received with WEP encryption */
enum {FRAME_FLAG_FRAGMENTED = 0x08}; /**< Frame sent/received with fragmentation */
enum {FRAME_FLAG_FCS_INCLUDED = 0x10}; /**< Frame includes FCS */
enum {FRAME_FLAG_DATA_PADDING = 0x20}; /**< Frame has padding between 802.11 header and payload (to 32-bit boundary) */
enum {FRAME_FLAG_BAD_FCS = 0x40}; /**< Frame failed FCS check */
enum {FRAME_FLAG_SHORT_GUARD = 0x80}; /**< Frame used short guard interval (HT) */
/**
* @brief Set the frame flags of the transmitted or received frame.
* @param flags flags to set.
*/
void SetFrameFlags (uint8_t flags);
/**
* @brief Get the frame flags of the transmitted or received frame.
* @returns The frame flags.
* @see FrameFlags.
*/
uint8_t GetFrameFlags (void) const;
/**
* @brief Set the transmit/receive channel frequency in units of megahertz
* @param rate the transmit/receive channel frequency in units of megahertz.
*/
void SetRate (uint8_t rate);
/**
* @brief Get the transmit/receive channel frequency in units of megahertz.
* @returns The transmit/receive channel frequency in units of megahertz.
*/
uint8_t GetRate (void) const;
enum {CHANNEL_FLAG_NONE = 0x0000}; /**< No flags set */
enum {CHANNEL_FLAG_TURBO = 0x0010}; /**< Turbo Channel */
enum {CHANNEL_FLAG_CCK = 0x0020}; /**< CCK channel */
enum {CHANNEL_FLAG_OFDM = 0x0040}; /**< OFDM channel */
enum {CHANNEL_FLAG_SPECTRUM_2GHZ = 0x0080}; /**< 2 GHz spectrum channel */
enum {CHANNEL_FLAG_SPECTRUM_5GHZ = 0x0100}; /**< 5 GHz spectrum channel */
enum {CHANNEL_FLAG_PASSIVE = 0x0200}; /**< Only passive scan allowed */
enum {CHANNEL_FLAG_DYNAMIC = 0x0400}; /**< Dynamic CCK-OFDM channel */
enum {CHANNEL_FLAG_GFSK = 0x0800}; /**< GFSK channel (FHSS PHY) */
/**
* @brief Set the transmit/receive channel frequency and flags
* @param frequency The transmit/receive data rate in units of 500 kbps.
* @param flags The flags to set.
* @see ChannelFlags
*/
void SetChannelFrequencyAndFlags (uint16_t frequency, uint16_t flags);
/**
* @brief Get the transmit/receive data rate in units of 500 kbps.
* @returns The transmit/receive data rate in units of 500 kbps.
*/
uint16_t GetChannelFrequency (void) const;
/**
* @brief Get the channel flags of the transmitted or received frame.
* @returns The frame flags.
* @see ChannelFlags.
*/
uint16_t GetChannelFlags (void) const;
/**
* @brief Set the RF signal power at the antenna as a decibel difference
* from an arbitrary, fixed reference.
*
* @param signal The RF signal power at the antenna as a decibel difference
* from an arbitrary, fixed reference.
*/
void SetAntennaSignalPower (int8_t signal);
/**
* @brief Set the RF signal power at the antenna as a decibel difference
* from an arbitrary, fixed reference.
*
* @param signal The RF signal power at the antenna as a decibel difference
* from an arbitrary, fixed reference;
*/
void SetAntennaSignalPower (double signal);
/**
* @brief Get the RF signal power at the antenna as a decibel difference
* from an arbitrary, fixed reference.
*
* @returns The RF signal power at the antenna as a decibel difference
* from an arbitrary, fixed reference.
*/
uint8_t GetAntennaSignalPower (void) const;
/**
* @brief Set the RF noise power at the antenna as a decibel difference
* from an arbitrary, fixed reference.
*
* @param noise The RF noise power at the antenna as a decibel difference
* from an arbitrary, fixed reference.
*/
void SetAntennaNoisePower (int8_t noise);
/**
* @brief Set the RF noise power at the antenna as a decibel difference
* from an arbitrary, fixed reference.
*
* @param noise The RF noise power at the antenna as a decibel difference
* from an arbitrary, fixed reference.
*/
void SetAntennaNoisePower (double noise);
/**
* @brief Get the RF noise power at the antenna as a decibel difference
* from an arbitrary, fixed reference.
*
* @returns The RF noise power at the antenna as a decibel difference
* from an arbitrary, fixed reference.
*/
uint8_t GetAntennaNoisePower (void) const;
private:
enum {RADIOTAP_TSFT = 0x00000001};
enum {RADIOTAP_FLAGS = 0x00000002};
enum {RADIOTAP_RATE = 0x00000004};
enum {RADIOTAP_CHANNEL = 0x00000008};
enum {RADIOTAP_FHSS = 0x00000010};
enum {RADIOTAP_DBM_ANTSIGNAL = 0x00000020};
enum {RADIOTAP_DBM_ANTNOISE = 0x00000040};
enum {RADIOTAP_LOCK_QUALITY = 0x00000080};
enum {RADIOTAP_TX_ATTENUATION = 0x00000100};
enum {RADIOTAP_DB_TX_ATTENUATION = 0x00000200};
enum {RADIOTAP_DBM_TX_POWER = 0x00000200};
enum {RADIOTAP_ANTENNA = 0x00000400};
enum {RADIOTAP_DB_ANTSIGNAL = 0x00000800};
enum {RADIOTAP_DB_ANTNOISE = 0x00001000};
enum {RADIOTAP_EXT = 0x10000000};
void CheckAddChannelField();
uint16_t m_length;
uint32_t m_present;
uint64_t m_tsft;
uint8_t m_flags;
uint8_t m_rate;
uint16_t m_channelFreq;
uint16_t m_channelFlags;
int8_t m_antennaSignal;
int8_t m_antennaNoise;
};
} // namespace ns3
#endif /* RADIOTAP_HEADER_H */

View File

@@ -48,6 +48,7 @@ def build(bld):
'ipv6-routing-protocol.cc',
'packetbb.cc',
'packetbb-test-suite.cc',
'radiotap-header.cc',
]
headers = bld.new_task_gen('ns3header')
@@ -96,4 +97,5 @@ def build(bld):
'ipv6-raw-socket-factory.h',
'ipv6-routing-protocol.h',
'packetbb.h',
'radiotap-header.h',
]