Set radiotap modulation type flags correctly
authorDean Armstrong <deanarm@gmail.com>
Thu, 24 Feb 2011 11:06:37 +0000
changeset 6820 110ddcce20bb
parent 6819 69fa08fe3ecb
child 6821 9be74ee020fa
Set radiotap modulation type flags correctly
src/devices/wifi/spectrum-yans-wifi-phy.cc
src/devices/wifi/wifi-phy.cc
src/devices/wifi/wifi-phy.h
src/devices/wifi/yans-wifi-phy.cc
src/helper/spectrum-wifi-helper.cc
--- a/src/devices/wifi/spectrum-yans-wifi-phy.cc	Tue Feb 15 13:03:22 2011 +0000
+++ b/src/devices/wifi/spectrum-yans-wifi-phy.cc	Thu Feb 24 11:06:37 2011 +0000
@@ -519,12 +519,11 @@
       m_endRxEvent.Cancel ();
     }
   NotifyTxBegin (packet);
-  uint32_t dataRate500KbpsUnits = txMode.GetDataRate () / 500000;
   bool isShortPreamble = (WIFI_PREAMBLE_SHORT == preamble);
   double txPowerDbm = GetPowerDbm (txPower);
   NS_LOG_DEBUG ("Wifi Power in Dbm" << txPowerDbm);
   NotifyPromiscSniffTx (packet, m_channelFreqMhz, m_channelNumber,
-                        dataRate500KbpsUnits, isShortPreamble,
+                        isShortPreamble, txMode,
                         txPowerDbm, DBL_MIN);
   m_state->SwitchToTx (txDuration, packet, txMode, preamble, txPower);
 
@@ -709,12 +708,11 @@
       m_spectrumInterferenceTracker->EndRx ())
     {
       NotifyRxEnd (packet);
-      uint32_t dataRate500KbpsUnits = event->GetPayloadMode ().GetDataRate () / 500000;
       bool isShortPreamble = (WIFI_PREAMBLE_SHORT == event->GetPreambleType ());
       double signalDbm = RatioToDb (event->GetRxPowerW ()) + 30;
       double noiseDbm = RatioToDb(event->GetRxPowerW() / snrPer.snr) - GetRxNoiseFigure() + 30 ;
       NotifyPromiscSniffRx (packet, m_channelFreqMhz, m_channelNumber,
-                            dataRate500KbpsUnits, isShortPreamble,
+                            isShortPreamble, event->GetPayloadMode (),
                             signalDbm, noiseDbm);
       m_state->SwitchFromRxEndOk (packet, snrPer.snr, event->GetPayloadMode (), event->GetPreambleType ());
       rxSucceeded = true;
--- a/src/devices/wifi/wifi-phy.cc	Tue Feb 15 13:03:22 2011 +0000
+++ b/src/devices/wifi/wifi-phy.cc	Thu Feb 24 11:06:37 2011 +0000
@@ -131,20 +131,20 @@
 
 void
 WifiPhy::NotifyPromiscSniffRx (Ptr<const Packet> packet, uint16_t channelFreqMhz,
-                               uint16_t channelNumber, uint32_t rate,
-                               bool isShortPreamble, double signalDbm, double noiseDbm)
+                               uint16_t channelNumber, bool isShortPreamble,
+                               WifiMode payloadMode, double signalDbm, double noiseDbm)
 {
-  m_phyPromiscSniffRxTrace (packet, channelFreqMhz, channelNumber, rate,
-                            isShortPreamble, signalDbm, noiseDbm);
+  m_phyPromiscSniffRxTrace (packet, channelFreqMhz, channelNumber, isShortPreamble,
+                            payloadMode, signalDbm, noiseDbm);
 }
 
 void
 WifiPhy::NotifyPromiscSniffTx (Ptr<const Packet> packet, uint16_t channelFreqMhz,
-                               uint16_t channelNumber, uint32_t rate,
-                               bool isShortPreamble, double signalDbm, double noiseDbm)
+                               uint16_t channelNumber, bool isShortPreamble,
+                               WifiMode payloadMode, double signalDbm, double noiseDbm)
 {
-  m_phyPromiscSniffTxTrace (packet, channelFreqMhz, channelNumber, rate,
-                            isShortPreamble, signalDbm, noiseDbm);
+  m_phyPromiscSniffTxTrace (packet, channelFreqMhz, channelNumber, isShortPreamble,
+                            payloadMode, signalDbm, noiseDbm);
 }
 
 double
--- a/src/devices/wifi/wifi-phy.h	Tue Feb 15 13:03:22 2011 +0000
+++ b/src/devices/wifi/wifi-phy.h	Thu Feb 24 11:06:37 2011 +0000
@@ -406,8 +406,9 @@
    * @param noiseDbm  noise power in dBm
    */
   void NotifyPromiscSniffRx (Ptr<const Packet> packet, uint16_t channelFreqMhz,
-                             uint16_t channelNumber, uint32_t rate,
+                             uint16_t channelNumber,
                              bool isShortPreamble,
+                             WifiMode payloadMode,
                              double signalDbm, double noiseDbm);
 
   /**
@@ -426,8 +427,9 @@
    * @param noiseDbm  noise power in dBm
    */
   void NotifyPromiscSniffTx (Ptr<const Packet> packet, uint16_t channelFreqMhz,
-                             uint16_t channelNumber, uint32_t rate,
+                             uint16_t channelNumber,
                              bool isShortPreamble,
+                             WifiMode payloadMode,
                              double signalDbm, double noiseDbm);
 
   /** Functions that are useful in multiple derived PHYs */
@@ -495,7 +497,7 @@
    * \see class CallBackTraceSource
    */
   typedef TracedCallback<Ptr<const Packet>, uint16_t,
-                         uint16_t, uint32_t, bool,
+                         uint16_t, bool, WifiMode,
                          double, double> PromiscSniffCallback;
 
   PromiscSniffCallback m_phyPromiscSniffRxTrace;
--- a/src/devices/wifi/yans-wifi-phy.cc	Tue Feb 15 13:03:22 2011 +0000
+++ b/src/devices/wifi/yans-wifi-phy.cc	Thu Feb 24 11:06:37 2011 +0000
@@ -514,11 +514,11 @@
       m_interference.NotifyRxEnd ();
     }
   NotifyTxBegin (packet);
-  uint32_t dataRate500KbpsUnits = txMode.GetDataRate () / 500000;   
   bool isShortPreamble = (WIFI_PREAMBLE_SHORT == preamble);
   double txPowerDbm = GetPowerDbm (txPower);
   NotifyPromiscSniffTx (packet, (uint16_t)GetChannelFrequencyMhz (),
-                        GetChannelNumber (), dataRate500KbpsUnits, isShortPreamble,
+                        GetChannelNumber (),
+                        isShortPreamble, txMode,
                         txPowerDbm, DBL_MIN);
   m_state->SwitchToTx (txDuration, packet, txMode, preamble, txPower);
   m_channel->Send (this, packet, txPowerDbm + m_txGainDb, txMode, preamble);
@@ -760,11 +760,12 @@
   if (m_random.GetValue () > snrPer.per) 
     {
       NotifyRxEnd (packet); 
-      uint32_t dataRate500KbpsUnits = event->GetPayloadMode ().GetDataRate () / 500000;   
       bool isShortPreamble = (WIFI_PREAMBLE_SHORT == event->GetPreambleType ());  
       double signalDbm = RatioToDb (event->GetRxPowerW ()) + 30;
       double noiseDbm = RatioToDb(event->GetRxPowerW() / snrPer.snr) - GetRxNoiseFigure() + 30 ;
-      NotifyPromiscSniffRx (packet, (uint16_t)GetChannelFrequencyMhz (), GetChannelNumber (), dataRate500KbpsUnits, isShortPreamble, signalDbm, noiseDbm);
+      NotifyPromiscSniffRx (packet, (uint16_t)GetChannelFrequencyMhz (), GetChannelNumber (),
+                            isShortPreamble, event->GetPayloadMode (),
+                            signalDbm, noiseDbm);
       m_state->SwitchFromRxEndOk (packet, snrPer.snr, event->GetPayloadMode (), event->GetPreambleType ());
     } 
   else 
--- a/src/helper/spectrum-wifi-helper.cc	Tue Feb 15 13:03:22 2011 +0000
+++ b/src/helper/spectrum-wifi-helper.cc	Thu Feb 24 11:06:37 2011 +0000
@@ -158,8 +158,8 @@
   Ptr<const Packet> packet,
   uint16_t channelFreqMhz,
   uint16_t channelNumber,
-  uint32_t rate,
   bool isShortPreamble,
+  WifiMode payloadMode,
   double signalDbm,
   double noiseDbm)
 {
@@ -191,18 +191,27 @@
           }
 
         header.SetFrameFlags (frameFlags);
-        header.SetRate (rate);
+        header.SetRate (payloadMode.GetDataRate () / 5e5);
+
+        uint16_t channelFlags = 0;
 
-        if (channelFreqMhz < 2500)
+        channelFlags |= ((channelFreqMhz < 2500) ? RadiotapHeader::CHANNEL_FLAG_SPECTRUM_2GHZ :
+                         RadiotapHeader::CHANNEL_FLAG_SPECTRUM_5GHZ);
+
+        switch (payloadMode.GetModulationClass ())
           {
-            header.SetChannelFrequencyAndFlags (channelFreqMhz,
-              RadiotapHeader::CHANNEL_FLAG_SPECTRUM_2GHZ | RadiotapHeader::CHANNEL_FLAG_CCK);
+          case WIFI_MOD_CLASS_DSSS:
+            channelFlags |= RadiotapHeader::CHANNEL_FLAG_CCK;
+            break;
+          case WIFI_MOD_CLASS_ERP_OFDM:
+          case WIFI_MOD_CLASS_OFDM:
+            channelFlags |= RadiotapHeader::CHANNEL_FLAG_OFDM;
+            break;
+          default:
+            NS_ABORT_MSG ("Attempt to construct radiotap header for unsupported modulation class");
+            break;
           }
-        else
-          {
-            header.SetChannelFrequencyAndFlags (channelFreqMhz,
-              RadiotapHeader::CHANNEL_FLAG_SPECTRUM_5GHZ | RadiotapHeader::CHANNEL_FLAG_OFDM);
-          }
+        header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags);
 
         header.SetAntennaSignalPower (signalDbm);
         header.SetAntennaNoisePower (noiseDbm);