Include signal strength in PCAP TX trace.
--- a/src/devices/wifi/wifi-phy.cc Tue Feb 15 14:53:05 2011 +0000
+++ b/src/devices/wifi/wifi-phy.cc Tue Feb 15 15:28:15 2011 +0000
@@ -129,16 +129,22 @@
m_phyRxDropTrace (packet);
}
-void
-WifiPhy::NotifyPromiscSniffRx (Ptr<const Packet> packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, bool isShortPreamble, double signalDbm, double noiseDbm)
+void
+WifiPhy::NotifyPromiscSniffRx (Ptr<const Packet> packet, uint16_t channelFreqMhz,
+ uint16_t channelNumber, uint32_t rate,
+ bool isShortPreamble, double signalDbm, double noiseDbm)
{
- m_phyPromiscSniffRxTrace (packet, channelFreqMhz, channelNumber, rate, isShortPreamble, signalDbm, noiseDbm);
+ m_phyPromiscSniffRxTrace (packet, channelFreqMhz, channelNumber, rate,
+ isShortPreamble, signalDbm, noiseDbm);
}
-void
-WifiPhy::NotifyPromiscSniffTx (Ptr<const Packet> packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, bool isShortPreamble)
+void
+WifiPhy::NotifyPromiscSniffTx (Ptr<const Packet> packet, uint16_t channelFreqMhz,
+ uint16_t channelNumber, uint32_t rate,
+ bool isShortPreamble, double signalDbm, double noiseDbm)
{
- m_phyPromiscSniffTxTrace (packet, channelFreqMhz, channelNumber, rate, isShortPreamble);
+ m_phyPromiscSniffTxTrace (packet, channelFreqMhz, channelNumber, rate,
+ isShortPreamble, signalDbm, noiseDbm);
}
double
--- a/src/devices/wifi/wifi-phy.h Tue Feb 15 14:53:05 2011 +0000
+++ b/src/devices/wifi/wifi-phy.h Tue Feb 15 15:28:15 2011 +0000
@@ -385,11 +385,10 @@
*/
void NotifyRxDrop (Ptr<const Packet> packet);
- /**
- *
- * Public method used to fire a PromiscSniffer trace for a wifi packet being received. Implemented for encapsulation
- * purposes.
- *
+ /**
+ * Public method used to fire a PromiscSniffer trace for a Wi-Fi
+ * packet being received. Implemented for encapsulation purposes.
+ *
* @param packet the packet being received
* @param channelFreqMhz the frequency in MHz at which the packet is
* received. Note that in real devices this is normally the
@@ -400,29 +399,35 @@
* on a nearby channel.
* @param channelNumber the channel on which the packet is received
* @param rate the PHY data rate in units of 500kbps (i.e., the same
- * units used both for the radiotap and for the prism header)
+ * units used both for the radiotap and for the prism header)
* @param isShortPreamble true if short preamble is used, false otherwise
* @param signalDbm signal power in dBm
* @param noiseDbm noise power in dBm
*/
- void NotifyPromiscSniffRx (Ptr<const Packet> packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, bool isShortPreamble,
+ void NotifyPromiscSniffRx (Ptr<const Packet> packet, uint16_t channelFreqMhz,
+ uint16_t channelNumber, uint32_t rate,
+ bool isShortPreamble,
double signalDbm, double noiseDbm);
- /**
- *
- * Public method used to fire a PromiscSniffer trace for a wifi packet being transmitted. Implemented for encapsulation
+ /**
+ * Public method used to fire a PromiscSniffer trace for a Wi-Fi
+ * packet being transmitted. Implemented for encapsulation
* purposes.
- *
+ *
* @param packet the packet being transmitted
* @param channelFreqMhz the frequency in MHz at which the packet is
- * transmitted.
+ * transmitted.
* @param channelNumber the channel on which the packet is transmitted
* @param rate the PHY data rate in units of 500kbps (i.e., the same
- * units used both for the radiotap and for the prism header)
+ * units used both for the radiotap and for the prism header)
* @param isShortPreamble true if short preamble is used, false otherwise
+ * @param signalDbm signal power in dBm
+ * @param noiseDbm noise power in dBm
*/
- void NotifyPromiscSniffTx (Ptr<const Packet> packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, bool isShortPreamble);
-
+ void NotifyPromiscSniffTx (Ptr<const Packet> packet, uint16_t channelFreqMhz,
+ uint16_t channelNumber, uint32_t rate,
+ bool isShortPreamble,
+ double signalDbm, double noiseDbm);
/** Functions that are useful in multiple derived PHYs */
static double DbmToW (double dbm);
@@ -479,29 +484,21 @@
TracedCallback<Ptr<const Packet> > m_phyRxDropTrace;
/**
- * A trace source that emulates a wifi device in monitor mode
- * sniffing a packet being received.
- *
+ * A trace source that emulates a Wi-Fi device in monitor mode
+ * sniffing a packet being received.
+ *
* As a reference with the real world, firing this trace
* corresponds in the madwifi driver to calling the function
* ieee80211_input_monitor()
*
* \see class CallBackTraceSource
*/
- TracedCallback<Ptr<const Packet>, uint16_t, uint16_t, uint32_t, bool, double, double> m_phyPromiscSniffRxTrace;
+ typedef TracedCallback<Ptr<const Packet>, uint16_t,
+ uint16_t, uint32_t, bool,
+ double, double> PromiscSniffCallback;
- /**
- * A trace source that emulates a wifi device in monitor mode
- * sniffing a packet being transmitted.
- *
- * As a reference with the real world, firing this trace
- * corresponds in the madwifi driver to calling the function
- * ieee80211_input_monitor()
- *
- * \see class CallBackTraceSource
- */
- TracedCallback<Ptr<const Packet>, uint16_t, uint16_t, uint32_t, bool> m_phyPromiscSniffTxTrace;
-
+ PromiscSniffCallback m_phyPromiscSniffRxTrace;
+ PromiscSniffCallback m_phyPromiscSniffTxTrace;
};
/**
--- a/src/devices/wifi/yans-wifi-phy.cc Tue Feb 15 14:53:05 2011 +0000
+++ b/src/devices/wifi/yans-wifi-phy.cc Tue Feb 15 15:28:15 2011 +0000
@@ -35,6 +35,7 @@
#include "ns3/pointer.h"
#include "ns3/net-device.h"
#include "ns3/trace-source-accessor.h"
+#include <float.h>
NS_LOG_COMPONENT_DEFINE ("YansWifiPhy");
@@ -514,9 +515,12 @@
NotifyTxBegin (packet);
uint32_t dataRate500KbpsUnits = txMode.GetDataRate () / 500000;
bool isShortPreamble = (WIFI_PREAMBLE_SHORT == preamble);
- NotifyPromiscSniffTx (packet, (uint16_t)GetChannelFrequencyMhz (), GetChannelNumber (), dataRate500KbpsUnits, isShortPreamble);
+ double txPowerDbm = GetPowerDbm (txPower);
+ NotifyPromiscSniffTx (packet, (uint16_t)GetChannelFrequencyMhz (),
+ GetChannelNumber (), dataRate500KbpsUnits, isShortPreamble,
+ txPowerDbm, DBL_MIN);
m_state->SwitchToTx (txDuration, packet, txMode, preamble, txPower);
- m_channel->Send (this, packet, GetPowerDbm (txPower) + m_txGainDb, txMode, preamble);
+ m_channel->Send (this, packet, txPowerDbm + m_txGainDb, txMode, preamble);
}
uint32_t
--- a/src/helper/yans-wifi-helper.cc Tue Feb 15 14:53:05 2011 +0000
+++ b/src/helper/yans-wifi-helper.cc Tue Feb 15 15:28:15 2011 +0000
@@ -239,14 +239,16 @@
return phy;
}
-static void
-PcapSniffTxEvent (
+static void
+PcapSniffEvent (
Ptr<PcapFileWrapper> file,
Ptr<const Packet> packet,
uint16_t channelFreqMhz,
uint16_t channelNumber,
uint32_t rate,
- bool isShortPreamble)
+ bool isShortPreamble,
+ double signalDbm,
+ double noiseDbm)
{
uint32_t dlt = file->GetDataLinkType ();
@@ -257,68 +259,7 @@
return;
case PcapHelper::DLT_PRISM_HEADER:
{
- NS_FATAL_ERROR ("PcapSniffTxEvent(): DLT_PRISM_HEADER not implemented");
- return;
- }
- case PcapHelper::DLT_IEEE802_11_RADIO:
- {
- Ptr<Packet> p = packet->Copy ();
- RadiotapHeader header;
- uint8_t frameFlags = RadiotapHeader::FRAME_FLAG_NONE;
- header.SetTsft (Simulator::Now ().GetMicroSeconds ());
-
- // Our capture includes the FCS, so we set the flag to say so.
- frameFlags |= RadiotapHeader::FRAME_FLAG_FCS_INCLUDED;
-
- if (isShortPreamble)
- {
- frameFlags |= RadiotapHeader::FRAME_FLAG_SHORT_PREAMBLE;
- }
-
- header.SetFrameFlags (frameFlags);
- header.SetRate (rate);
-
- if (channelFreqMhz < 2500)
- {
- header.SetChannelFrequencyAndFlags (channelFreqMhz,
- RadiotapHeader::CHANNEL_FLAG_SPECTRUM_2GHZ | RadiotapHeader::CHANNEL_FLAG_CCK);
- }
- else
- {
- header.SetChannelFrequencyAndFlags (channelFreqMhz,
- RadiotapHeader::CHANNEL_FLAG_SPECTRUM_5GHZ | RadiotapHeader::CHANNEL_FLAG_OFDM);
- }
-
- p->AddHeader (header);
- file->Write (Simulator::Now (), p);
- return;
- }
- default:
- NS_ABORT_MSG ("PcapSniffTxEvent(): Unexpected data link type " << dlt);
- }
-}
-
-static void
-PcapSniffRxEvent (
- Ptr<PcapFileWrapper> file,
- Ptr<const Packet> packet,
- uint16_t channelFreqMhz,
- uint16_t channelNumber,
- uint32_t rate,
- bool isShortPreamble,
- double signalDbm,
- double noiseDbm)
-{
- uint32_t dlt = file->GetDataLinkType ();
-
- switch (dlt)
- {
- case PcapHelper::DLT_IEEE802_11:
- file->Write (Simulator::Now (), packet);
- return;
- case PcapHelper::DLT_PRISM_HEADER:
- {
- NS_FATAL_ERROR ("PcapSniffRxEvent(): DLT_PRISM_HEADER not implemented");
+ NS_FATAL_ERROR ("PcapSniffEvent(): DLT_PRISM_HEADER not implemented");
return;
}
case PcapHelper::DLT_IEEE802_11_RADIO:
@@ -358,7 +299,7 @@
return;
}
default:
- NS_ABORT_MSG ("PcapSniffRxEvent(): Unexpected data link type " << dlt);
+ NS_ABORT_MSG ("PcapSniffEvent(): Unexpected data link type " << dlt);
}
}
@@ -413,8 +354,10 @@
Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out, m_pcapDlt);
- phy->TraceConnectWithoutContext ("PromiscSnifferTx", MakeBoundCallback (&PcapSniffTxEvent, file));
- phy->TraceConnectWithoutContext ("PromiscSnifferRx", MakeBoundCallback (&PcapSniffRxEvent, file));
+ phy->TraceConnectWithoutContext ("PromiscSnifferTx",
+ MakeBoundCallback (&PcapSniffEvent, file));
+ phy->TraceConnectWithoutContext ("PromiscSnifferRx",
+ MakeBoundCallback (&PcapSniffEvent, file));
}
void