From 9080f150a6a67d5884fda5704972f24dee403b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deronne?= Date: Sun, 14 Jun 2015 20:15:37 +0200 Subject: [PATCH] cleanup yans-wifi-phy --- src/wifi/model/yans-wifi-channel.cc | 2 +- src/wifi/model/yans-wifi-phy.cc | 819 +++++++++++++++------------- src/wifi/model/yans-wifi-phy.h | 41 +- 3 files changed, 449 insertions(+), 413 deletions(-) diff --git a/src/wifi/model/yans-wifi-channel.cc b/src/wifi/model/yans-wifi-channel.cc index 075e5c99a..e40986db2 100644 --- a/src/wifi/model/yans-wifi-channel.cc +++ b/src/wifi/model/yans-wifi-channel.cc @@ -125,7 +125,7 @@ void YansWifiChannel::Receive (uint32_t i, Ptr packet, double *atts, WifiTxVector txVector, WifiPreamble preamble) const { - m_phyList[i]->StartReceivePlcp (packet, *atts, txVector, preamble,*(atts+1), NanoSeconds(*(atts+2))); + m_phyList[i]->StartReceivePreambleAndHeader (packet, *atts, txVector, preamble, *(atts+1), NanoSeconds(*(atts+2))); delete[] atts; } diff --git a/src/wifi/model/yans-wifi-phy.cc b/src/wifi/model/yans-wifi-phy.cc index 5b4065448..1098ef75d 100644 --- a/src/wifi/model/yans-wifi-phy.cc +++ b/src/wifi/model/yans-wifi-phy.cc @@ -15,8 +15,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Author: Mathieu Lacage - * Author: Ghada Badawy + * Authors: Mathieu Lacage + * Ghada Badawy */ #include "yans-wifi-phy.h" @@ -61,7 +61,7 @@ YansWifiPhy::GetTypeId (void) MakeDoubleChecker ()) .AddAttribute ("CcaMode1Threshold", "The energy of a received signal should be higher than " - "this threshold (dbm) to allow the PHY layer to declare CCA BUSY state", + "this threshold (dbm) to allow the PHY layer to declare CCA BUSY state.", DoubleValue (-99.0), MakeDoubleAccessor (&YansWifiPhy::SetCcaMode1Threshold, &YansWifiPhy::GetCcaMode1Threshold), @@ -102,13 +102,13 @@ YansWifiPhy::GetTypeId (void) "\"the difference in decibels (dB) between" " the noise output of the actual receiver to the noise output of an " " ideal receiver with the same overall gain and bandwidth when the receivers " - " are connected to sources at the standard noise temperature T0 (usually 290 K)\"." - " For", + " are connected to sources at the standard noise temperature T0 (usually 290 K)\".", DoubleValue (7), MakeDoubleAccessor (&YansWifiPhy::SetRxNoiseFigure, &YansWifiPhy::GetRxNoiseFigure), MakeDoubleChecker ()) - .AddAttribute ("State", "The state of the PHY layer", + .AddAttribute ("State", + "The state of the PHY layer.", PointerValue (), MakePointerAccessor (&YansWifiPhy::m_state), MakePointerChecker ()) @@ -118,64 +118,70 @@ YansWifiPhy::GetTypeId (void) MakeTimeAccessor (&YansWifiPhy::m_channelSwitchDelay), MakeTimeChecker ()) .AddAttribute ("ChannelNumber", - "Channel center frequency = Channel starting frequency + 5 MHz * nch", + "Channel center frequency = Channel starting frequency + 5 MHz * nch.", UintegerValue (1), MakeUintegerAccessor (&YansWifiPhy::SetChannelNumber, &YansWifiPhy::GetChannelNumber), MakeUintegerChecker ()) - .AddAttribute ("Frequency", "The operating frequency.", + .AddAttribute ("Frequency", + "The operating frequency.", UintegerValue (2407), MakeUintegerAccessor (&YansWifiPhy::GetFrequency, &YansWifiPhy::SetFrequency), MakeUintegerChecker ()) - .AddAttribute ("Transmitters", "The number of transmitters.", + .AddAttribute ("Transmitters", + "The number of transmitters.", UintegerValue (1), MakeUintegerAccessor (&YansWifiPhy::GetNumberOfTransmitAntennas, &YansWifiPhy::SetNumberOfTransmitAntennas), MakeUintegerChecker ()) - .AddAttribute ("Receivers", "The number of receivers.", + .AddAttribute ("Receivers", + "The number of receivers.", UintegerValue (1), MakeUintegerAccessor (&YansWifiPhy::GetNumberOfReceiveAntennas, &YansWifiPhy::SetNumberOfReceiveAntennas), MakeUintegerChecker ()) - .AddAttribute ("ShortGuardEnabled", "Whether or not short guard interval is enabled.", + .AddAttribute ("ShortGuardEnabled", + "Whether or not short guard interval is enabled.", BooleanValue (false), MakeBooleanAccessor (&YansWifiPhy::GetGuardInterval, &YansWifiPhy::SetGuardInterval), MakeBooleanChecker ()) - .AddAttribute ("LdpcEnabled", "Whether or not LDPC is enabled.", + .AddAttribute ("LdpcEnabled", + "Whether or not LDPC is enabled.", BooleanValue (false), MakeBooleanAccessor (&YansWifiPhy::GetLdpc, &YansWifiPhy::SetLdpc), MakeBooleanChecker ()) - .AddAttribute ("STBCEnabled", "Whether or not STBC is enabled.", + .AddAttribute ("STBCEnabled", + "Whether or not STBC is enabled.", BooleanValue (false), MakeBooleanAccessor (&YansWifiPhy::GetStbc, &YansWifiPhy::SetStbc), MakeBooleanChecker ()) - .AddAttribute ("GreenfieldEnabled", "Whether or not STBC is enabled.", + .AddAttribute ("GreenfieldEnabled", + "Whether or not STBC is enabled.", BooleanValue (false), MakeBooleanAccessor (&YansWifiPhy::GetGreenfield, &YansWifiPhy::SetGreenfield), MakeBooleanChecker ()) - .AddAttribute ("ChannelBonding", "Whether 20MHz or 40MHz.", + .AddAttribute ("ChannelBonding", + "Whether 20MHz or 40MHz.", BooleanValue (false), MakeBooleanAccessor (&YansWifiPhy::GetChannelBonding, &YansWifiPhy::SetChannelBonding), MakeBooleanChecker ()) - - ; return tid; } YansWifiPhy::YansWifiPhy () - : m_initialized (false), + : m_initialized (false), m_channelNumber (1), m_endRxEvent (), - m_endPlcpRxEvent(), + m_endPlcpRxEvent (), m_channelStartingFrequency (0), - m_mpdusNum(0), + m_mpdusNum (0), m_plcpSuccess (false) { NS_LOG_FUNCTION (this); @@ -194,7 +200,7 @@ YansWifiPhy::DoDispose (void) NS_LOG_FUNCTION (this); m_channel = 0; m_deviceRateSet.clear (); - m_deviceMcsSet.clear(); + m_deviceMcsSet.clear (); m_device = 0; m_mobility = 0; m_state = 0; @@ -232,79 +238,87 @@ YansWifiPhy::ConfigureStandard (enum WifiPhyStandard standard) ConfigureHolland (); break; case WIFI_PHY_STANDARD_80211n_2_4GHZ: - m_channelStartingFrequency=2407; + m_channelStartingFrequency = 2407; Configure80211n (); break; case WIFI_PHY_STANDARD_80211n_5GHZ: - m_channelStartingFrequency=5e3; + m_channelStartingFrequency = 5e3; Configure80211n (); break; - default: NS_ASSERT (false); break; } } - void YansWifiPhy::SetRxNoiseFigure (double noiseFigureDb) { NS_LOG_FUNCTION (this << noiseFigureDb); m_interference.SetNoiseFigure (DbToRatio (noiseFigureDb)); } + void YansWifiPhy::SetTxPowerStart (double start) { NS_LOG_FUNCTION (this << start); m_txPowerBaseDbm = start; } + void YansWifiPhy::SetTxPowerEnd (double end) { NS_LOG_FUNCTION (this << end); m_txPowerEndDbm = end; } + void YansWifiPhy::SetNTxPower (uint32_t n) { NS_LOG_FUNCTION (this << n); m_nTxPower = n; } + void YansWifiPhy::SetTxGain (double gain) { NS_LOG_FUNCTION (this << gain); m_txGainDb = gain; } + void YansWifiPhy::SetRxGain (double gain) { NS_LOG_FUNCTION (this << gain); m_rxGainDb = gain; } + void YansWifiPhy::SetEdThreshold (double threshold) { NS_LOG_FUNCTION (this << threshold); m_edThresholdW = DbmToW (threshold); } + void YansWifiPhy::SetCcaMode1Threshold (double threshold) { NS_LOG_FUNCTION (this << threshold); m_ccaMode1ThresholdW = DbmToW (threshold); } + void YansWifiPhy::SetErrorRateModel (Ptr rate) { m_interference.SetErrorRateModel (rate); } + void YansWifiPhy::SetDevice (Ptr device) { m_device = device; } + void YansWifiPhy::SetMobility (Ptr mobility) { @@ -316,21 +330,25 @@ YansWifiPhy::GetRxNoiseFigure (void) const { return RatioToDb (m_interference.GetNoiseFigure ()); } + double YansWifiPhy::GetTxPowerStart (void) const { return m_txPowerBaseDbm; } + double YansWifiPhy::GetTxPowerEnd (void) const { return m_txPowerEndDbm; } + double YansWifiPhy::GetTxGain (void) const { return m_txGainDb; } + double YansWifiPhy::GetRxGain (void) const { @@ -354,11 +372,13 @@ YansWifiPhy::GetErrorRateModel (void) const { return m_interference.GetErrorRateModel (); } + Ptr YansWifiPhy::GetDevice (void) const { return m_device; } + Ptr YansWifiPhy::GetMobility (void) { @@ -376,6 +396,7 @@ YansWifiPhy::GetChannel (void) const { return m_channel; } + void YansWifiPhy::SetChannel (Ptr channel) { @@ -388,7 +409,7 @@ YansWifiPhy::SetChannelNumber (uint16_t nch) { if (!m_initialized) { - // this is not channel switch, this is initialization + //this is not channel switch, this is initialization NS_LOG_DEBUG ("start at channel " << nch); m_channelNumber = nch; return; @@ -399,7 +420,7 @@ YansWifiPhy::SetChannelNumber (uint16_t nch) { case YansWifiPhy::RX: NS_LOG_DEBUG ("drop packet because of channel switching while reception"); - m_endPlcpRxEvent.Cancel(); + m_endPlcpRxEvent.Cancel (); m_endRxEvent.Cancel (); goto switchChannel; break; @@ -460,29 +481,29 @@ YansWifiPhy::SetSleepMode (void) NS_LOG_FUNCTION (this); switch (m_state->GetState ()) { - case YansWifiPhy::TX: - NS_LOG_DEBUG ("setting sleep mode postponed until end of current transmission"); - Simulator::Schedule (GetDelayUntilIdle (), &YansWifiPhy::SetSleepMode, this); - break; - case YansWifiPhy::RX: - NS_LOG_DEBUG ("setting sleep mode postponed until end of current reception"); - Simulator::Schedule (GetDelayUntilIdle (), &YansWifiPhy::SetSleepMode, this); - break; - case YansWifiPhy::SWITCHING: - NS_LOG_DEBUG ("setting sleep mode postponed until end of channel switching"); - Simulator::Schedule (GetDelayUntilIdle (), &YansWifiPhy::SetSleepMode, this); - break; - case YansWifiPhy::CCA_BUSY: - case YansWifiPhy::IDLE: - NS_LOG_DEBUG ("setting sleep mode"); - m_state->SwitchToSleep (); - break; - case YansWifiPhy::SLEEP: - NS_LOG_DEBUG ("already in sleep mode"); - break; - default: - NS_ASSERT (false); - break; + case YansWifiPhy::TX: + NS_LOG_DEBUG ("setting sleep mode postponed until end of current transmission"); + Simulator::Schedule (GetDelayUntilIdle (), &YansWifiPhy::SetSleepMode, this); + break; + case YansWifiPhy::RX: + NS_LOG_DEBUG ("setting sleep mode postponed until end of current reception"); + Simulator::Schedule (GetDelayUntilIdle (), &YansWifiPhy::SetSleepMode, this); + break; + case YansWifiPhy::SWITCHING: + NS_LOG_DEBUG ("setting sleep mode postponed until end of channel switching"); + Simulator::Schedule (GetDelayUntilIdle (), &YansWifiPhy::SetSleepMode, this); + break; + case YansWifiPhy::CCA_BUSY: + case YansWifiPhy::IDLE: + NS_LOG_DEBUG ("setting sleep mode"); + m_state->SwitchToSleep (); + break; + case YansWifiPhy::SLEEP: + NS_LOG_DEBUG ("already in sleep mode"); + break; + default: + NS_ASSERT (false); + break; } } @@ -492,18 +513,27 @@ YansWifiPhy::ResumeFromSleep (void) NS_LOG_FUNCTION (this); switch (m_state->GetState ()) { - case YansWifiPhy::TX: - case YansWifiPhy::RX: - case YansWifiPhy::IDLE: - case YansWifiPhy::CCA_BUSY: - case YansWifiPhy::SWITCHING: - NS_LOG_DEBUG ("not in sleep mode, there is nothing to resume"); - break; - case YansWifiPhy::SLEEP: - NS_LOG_DEBUG ("resuming from sleep mode"); - Time delayUntilCcaEnd = m_interference.GetEnergyDuration (m_ccaMode1ThresholdW); - m_state->SwitchFromSleep (delayUntilCcaEnd); - break; + case YansWifiPhy::TX: + case YansWifiPhy::RX: + case YansWifiPhy::IDLE: + case YansWifiPhy::CCA_BUSY: + case YansWifiPhy::SWITCHING: + { + NS_LOG_DEBUG ("not in sleep mode, there is nothing to resume"); + break; + } + case YansWifiPhy::SLEEP: + { + NS_LOG_DEBUG ("resuming from sleep mode"); + Time delayUntilCcaEnd = m_interference.GetEnergyDuration (m_ccaMode1ThresholdW); + m_state->SwitchFromSleep (delayUntilCcaEnd); + break; + } + default: + { + NS_ASSERT (false); + break; + } } } @@ -512,6 +542,7 @@ YansWifiPhy::SetReceiveOkCallback (RxOkCallback callback) { m_state->SetReceiveOkCallback (callback); } + void YansWifiPhy::SetReceiveErrorCallback (RxErrorCallback callback) { @@ -519,21 +550,20 @@ YansWifiPhy::SetReceiveErrorCallback (RxErrorCallback callback) } void -YansWifiPhy::StartReceivePlcp (Ptr packet, - double rxPowerDbm, - WifiTxVector txVector, - enum WifiPreamble preamble, - uint8_t packetType, Time rxDuration) +YansWifiPhy::StartReceivePreambleAndHeader (Ptr packet, + double rxPowerDbm, + WifiTxVector txVector, + enum WifiPreamble preamble, + uint8_t packetType, Time rxDuration) { - // This function should be later split to check separately wether plcp preamble and plcp header can be successfully received. - // Note: plcp preamble reception is not yet modeled. - NS_LOG_FUNCTION (this << packet << rxPowerDbm << txVector.GetMode()<< preamble << (uint32_t)packetType); + //This function should be later split to check separately wether plcp preamble and plcp header can be successfully received. + //Note: plcp preamble reception is not yet modeled. + NS_LOG_FUNCTION (this << packet << rxPowerDbm << txVector.GetMode() << preamble << (uint32_t)packetType); AmpduTag ampduTag; - rxPowerDbm += m_rxGainDb; double rxPowerW = DbmToW (rxPowerDbm); Time endRx = Simulator::Now () + rxDuration; - Time plcpDuration = CalculatePlcpPreambleAndHeaderDuration (txVector, preamble); + Time preambleAndHeaderDuration = CalculatePlcpPreambleAndHeaderDuration (txVector, preamble); Ptr event; event = m_interference.Add (packet->GetSize (), @@ -558,8 +588,8 @@ YansWifiPhy::StartReceivePlcp (Ptr packet, */ if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ()) { - // that packet will be noise _after_ the completion of the - // channel switching. + //that packet will be noise _after_ the completion of the + //channel switching. goto maybeCcaBusy; } break; @@ -569,8 +599,8 @@ YansWifiPhy::StartReceivePlcp (Ptr packet, NotifyRxDrop (packet); if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ()) { - // that packet will be noise _after_ the reception of the - // currently-received packet. + //that packet will be noise _after_ the reception of the + //currently-received packet. goto maybeCcaBusy; } break; @@ -580,8 +610,8 @@ YansWifiPhy::StartReceivePlcp (Ptr packet, NotifyRxDrop (packet); if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ()) { - // that packet will be noise _after_ the transmission of the - // currently-transmitted packet. + //that packet will be noise _after_ the transmission of the + //currently-transmitted packet. goto maybeCcaBusy; } break; @@ -595,7 +625,7 @@ YansWifiPhy::StartReceivePlcp (Ptr packet, NotifyRxDrop (packet); goto maybeCcaBusy; } - else if (preamble == WIFI_PREAMBLE_NONE && m_plcpSuccess == false) // A-MPDU reception fails + else if (preamble == WIFI_PREAMBLE_NONE && m_plcpSuccess == false) //A-MPDU reception fails { NS_LOG_DEBUG ("Drop MPDU because no plcp has been received"); NotifyRxDrop (packet); @@ -604,15 +634,15 @@ YansWifiPhy::StartReceivePlcp (Ptr packet, else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum == 0) { //received the first MPDU in an MPDU - m_mpdusNum = ampduTag.GetNoOfMpdus()-1; + m_mpdusNum = ampduTag.GetNoOfMpdus () - 1; } else if (preamble == WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum > 0) { //received the other MPDUs that are part of the A-MPDU - if (ampduTag.GetNoOfMpdus() < m_mpdusNum) + if (ampduTag.GetNoOfMpdus () < m_mpdusNum) { - NS_LOG_DEBUG ("Missing MPDU from the A-MPDU " << m_mpdusNum - ampduTag.GetNoOfMpdus()); - m_mpdusNum = ampduTag.GetNoOfMpdus(); + NS_LOG_DEBUG ("Missing MPDU from the A-MPDU " << m_mpdusNum - ampduTag.GetNoOfMpdus ()); + m_mpdusNum = ampduTag.GetNoOfMpdus (); } else m_mpdusNum--; @@ -624,7 +654,7 @@ YansWifiPhy::StartReceivePlcp (Ptr packet, } NS_LOG_DEBUG ("sync to signal (power=" << rxPowerW << "W)"); - // sync to signal + //sync to signal m_state->SwitchToRx (rxDuration); NS_ASSERT (m_endPlcpRxEvent.IsExpired ()); NotifyRxBegin (packet); @@ -633,7 +663,7 @@ YansWifiPhy::StartReceivePlcp (Ptr packet, if (preamble != WIFI_PREAMBLE_NONE) { NS_ASSERT (m_endPlcpRxEvent.IsExpired ()); - m_endPlcpRxEvent = Simulator::Schedule (plcpDuration, &YansWifiPhy::StartReceivePacket, this, + m_endPlcpRxEvent = Simulator::Schedule (preambleAndHeaderDuration, &YansWifiPhy::StartReceivePacket, this, packet, txVector, preamble, packetType, event); } @@ -660,10 +690,10 @@ YansWifiPhy::StartReceivePlcp (Ptr packet, return; maybeCcaBusy: - // We are here because we have received the first bit of a packet and we are - // not going to be able to synchronize on it - // In this model, CCA becomes busy when the aggregation of all signals as - // tracked by the InterferenceHelper class is higher than the CcaBusyThreshold + //We are here because we have received the first bit of a packet and we are + //not going to be able to synchronize on it + //In this model, CCA becomes busy when the aggregation of all signals as + //tracked by the InterferenceHelper class is higher than the CcaBusyThreshold Time delayUntilCcaEnd = m_interference.GetEnergyDuration (m_ccaMode1ThresholdW); if (!delayUntilCcaEnd.IsZero ()) @@ -671,6 +701,7 @@ YansWifiPhy::StartReceivePlcp (Ptr packet, m_state->SwitchMaybeToCcaBusy (delayUntilCcaEnd); } } + void YansWifiPhy::StartReceivePacket (Ptr packet, WifiTxVector txVector, @@ -678,11 +709,11 @@ YansWifiPhy::StartReceivePacket (Ptr packet, uint8_t packetType, Ptr event) { - NS_LOG_FUNCTION (this << packet << txVector.GetMode()<< preamble << (uint32_t)packetType); + NS_LOG_FUNCTION (this << packet << txVector.GetMode () << preamble << (uint32_t)packetType); NS_ASSERT (IsStateRx ()); NS_ASSERT (m_endPlcpRxEvent.IsExpired ()); AmpduTag ampduTag; - WifiMode txMode = txVector.GetMode(); + WifiMode txMode = txVector.GetMode (); struct InterferenceHelper::SnrPer snrPer; snrPer = m_interference.CalculatePlcpHeaderSnrPer (event); @@ -691,7 +722,7 @@ YansWifiPhy::StartReceivePacket (Ptr packet, if (m_random->GetValue () > snrPer.per) //plcp reception succeeded { - if (IsModeSupported (txMode) || IsMcsSupported(txMode)) + if (IsModeSupported (txMode) || IsMcsSupported (txMode)) { NS_LOG_DEBUG ("receiving plcp payload"); //endReceive is already scheduled m_plcpSuccess = true; @@ -705,7 +736,7 @@ YansWifiPhy::StartReceivePacket (Ptr packet, } else //plcp reception failed { - NS_LOG_DEBUG ("drop packet because plcp reception failed"); + NS_LOG_DEBUG ("drop packet because plcp preamble/header reception failed"); NotifyRxDrop (packet); m_plcpSuccess = false; } @@ -714,7 +745,7 @@ YansWifiPhy::StartReceivePacket (Ptr packet, void YansWifiPhy::SendPacket (Ptr packet, WifiTxVector txVector, WifiPreamble preamble, uint8_t packetType) { - NS_LOG_FUNCTION (this << packet << txVector.GetMode() << preamble << (uint32_t)txVector.GetTxPowerLevel() << (uint32_t)packetType); + NS_LOG_FUNCTION (this << packet << txVector.GetMode () << preamble << (uint32_t)txVector.GetTxPowerLevel () << (uint32_t)packetType); /* Transmission can happen if: * - we are syncing on a packet. It is the responsability of the * MAC layer to avoid doing this but the PHY does nothing to @@ -729,8 +760,8 @@ YansWifiPhy::SendPacket (Ptr packet, WifiTxVector txVector, WifiPr NotifyTxDrop (packet); return; } - - Time txDuration = CalculateTxDuration (packet->GetSize (), txVector, preamble, GetFrequency(), packetType, 1); + + Time txDuration = CalculateTxDuration (packet->GetSize (), txVector, preamble, GetFrequency (), packetType, 1); if (m_state->IsStateRx ()) { m_endPlcpRxEvent.Cancel (); @@ -741,16 +772,16 @@ YansWifiPhy::SendPacket (Ptr packet, WifiTxVector txVector, WifiPr uint32_t dataRate500KbpsUnits; if (txVector.GetMode().GetModulationClass () == WIFI_MOD_CLASS_HT) { - dataRate500KbpsUnits = 128 + WifiModeToMcs (txVector.GetMode()); + dataRate500KbpsUnits = 128 + WifiModeToMcs (txVector.GetMode ()); } else { - dataRate500KbpsUnits = txVector.GetMode().GetDataRate () * txVector.GetNss() / 500000; + dataRate500KbpsUnits = txVector.GetMode ().GetDataRate () * txVector.GetNss () / 500000; } bool isShortPreamble = (WIFI_PREAMBLE_SHORT == preamble); NotifyMonitorSniffTx (packet, (uint16_t)GetChannelFrequencyMhz (), GetChannelNumber (), dataRate500KbpsUnits, isShortPreamble, txVector); - m_state->SwitchToTx (txDuration, packet, GetPowerDbm (txVector.GetTxPowerLevel()), txVector, preamble); - m_channel->Send (this, packet, GetPowerDbm (txVector.GetTxPowerLevel()) + m_txGainDb, txVector, preamble, packetType, txDuration); + m_state->SwitchToTx (txDuration, packet, GetPowerDbm (txVector.GetTxPowerLevel ()), txVector, preamble); + m_channel->Send (this, packet, GetPowerDbm (txVector.GetTxPowerLevel ()) + m_txGainDb, txVector, preamble, packetType, txDuration); } uint32_t @@ -758,11 +789,13 @@ YansWifiPhy::GetNModes (void) const { return m_deviceRateSet.size (); } + WifiMode YansWifiPhy::GetMode (uint32_t mode) const { return m_deviceRateSet[mode]; } + bool YansWifiPhy::IsModeSupported (WifiMode mode) const { @@ -780,13 +813,14 @@ YansWifiPhy::IsMcsSupported (WifiMode mode) { for (uint32_t i = 0; i < GetNMcs (); i++) { - if (mode == McsToWifiMode(GetMcs (i))) + if (mode == McsToWifiMode (GetMcs (i))) { return true; } } return false; } + uint32_t YansWifiPhy::GetNTxPower (void) const { @@ -797,7 +831,7 @@ void YansWifiPhy::Configure80211a (void) { NS_LOG_FUNCTION (this); - m_channelStartingFrequency = 5e3; // 5.000 GHz + m_channelStartingFrequency = 5e3; //5.000 GHz m_deviceRateSet.push_back (WifiPhy::GetOfdmRate6Mbps ()); m_deviceRateSet.push_back (WifiPhy::GetOfdmRate9Mbps ()); @@ -809,12 +843,11 @@ YansWifiPhy::Configure80211a (void) m_deviceRateSet.push_back (WifiPhy::GetOfdmRate54Mbps ()); } - void YansWifiPhy::Configure80211b (void) { NS_LOG_FUNCTION (this); - m_channelStartingFrequency = 2407; // 2.407 GHz + m_channelStartingFrequency = 2407; //2.407 GHz m_deviceRateSet.push_back (WifiPhy::GetDsssRate1Mbps ()); m_deviceRateSet.push_back (WifiPhy::GetDsssRate2Mbps ()); @@ -826,7 +859,7 @@ void YansWifiPhy::Configure80211g (void) { NS_LOG_FUNCTION (this); - m_channelStartingFrequency = 2407; // 2.407 GHz + m_channelStartingFrequency = 2407; //2.407 GHz m_deviceRateSet.push_back (WifiPhy::GetDsssRate1Mbps ()); m_deviceRateSet.push_back (WifiPhy::GetDsssRate2Mbps ()); @@ -846,7 +879,7 @@ void YansWifiPhy::Configure80211_10Mhz (void) { NS_LOG_FUNCTION (this); - m_channelStartingFrequency = 5e3; // 5.000 GHz, suppose 802.11a + m_channelStartingFrequency = 5e3; //5.000 GHz, suppose 802.11a m_deviceRateSet.push_back (WifiPhy::GetOfdmRate3MbpsBW10MHz ()); m_deviceRateSet.push_back (WifiPhy::GetOfdmRate4_5MbpsBW10MHz ()); @@ -862,7 +895,7 @@ void YansWifiPhy::Configure80211_5Mhz (void) { NS_LOG_FUNCTION (this); - m_channelStartingFrequency = 5e3; // 5.000 GHz, suppose 802.11a + m_channelStartingFrequency = 5e3; //5.000 GHz, suppose 802.11a m_deviceRateSet.push_back (WifiPhy::GetOfdmRate1_5MbpsBW5MHz ()); m_deviceRateSet.push_back (WifiPhy::GetOfdmRate2_25MbpsBW5MHz ()); @@ -878,7 +911,7 @@ void YansWifiPhy::ConfigureHolland (void) { NS_LOG_FUNCTION (this); - m_channelStartingFrequency = 5e3; // 5.000 GHz + m_channelStartingFrequency = 5e3; //5.000 GHz m_deviceRateSet.push_back (WifiPhy::GetOfdmRate6Mbps ()); m_deviceRateSet.push_back (WifiPhy::GetOfdmRate12Mbps ()); m_deviceRateSet.push_back (WifiPhy::GetOfdmRate18Mbps ()); @@ -886,6 +919,33 @@ YansWifiPhy::ConfigureHolland (void) m_deviceRateSet.push_back (WifiPhy::GetOfdmRate54Mbps ()); } +void +YansWifiPhy::Configure80211n (void) +{ + NS_LOG_FUNCTION (this); + if (m_channelStartingFrequency >= 2400 && m_channelStartingFrequency <= 2500) //at 2.4 GHz + { + m_deviceRateSet.push_back (WifiPhy::GetDsssRate1Mbps ()); + m_deviceRateSet.push_back (WifiPhy::GetDsssRate2Mbps ()); + m_deviceRateSet.push_back (WifiPhy::GetDsssRate5_5Mbps ()); + m_deviceRateSet.push_back (WifiPhy::GetErpOfdmRate6Mbps ()); + m_deviceRateSet.push_back (WifiPhy::GetDsssRate11Mbps ()); + m_deviceRateSet.push_back (WifiPhy::GetErpOfdmRate12Mbps ()); + m_deviceRateSet.push_back (WifiPhy::GetErpOfdmRate24Mbps ()); + } + if (m_channelStartingFrequency >= 5000 && m_channelStartingFrequency <= 6000) //at 5 GHz + { + m_deviceRateSet.push_back (WifiPhy::GetOfdmRate6Mbps ()); + m_deviceRateSet.push_back (WifiPhy::GetOfdmRate12Mbps ()); + m_deviceRateSet.push_back (WifiPhy::GetOfdmRate24Mbps ()); + } + m_bssMembershipSelectorSet.push_back(HT_PHY); + for (uint8_t i = 0; i < 8; i++) + { + m_deviceMcsSet.push_back(i); + } +} + void YansWifiPhy::RegisterListener (WifiPhyListener *listener) { @@ -909,26 +969,31 @@ YansWifiPhy::IsStateIdle (void) { return m_state->IsStateIdle (); } + bool YansWifiPhy::IsStateBusy (void) { return m_state->IsStateBusy (); } + bool YansWifiPhy::IsStateRx (void) { return m_state->IsStateRx (); } + bool YansWifiPhy::IsStateTx (void) { return m_state->IsStateTx (); } + bool YansWifiPhy::IsStateSwitching (void) { return m_state->IsStateSwitching (); } + bool YansWifiPhy::IsStateSleep (void) { @@ -940,6 +1005,7 @@ YansWifiPhy::GetStateDuration (void) { return m_state->GetStateDuration (); } + Time YansWifiPhy::GetDelayUntilIdle (void) { @@ -1014,45 +1080,45 @@ YansWifiPhy::EndReceive (Ptr packet, enum WifiPreamble preamble, uint8_t m_interference.NotifyRxEnd (); if (m_plcpSuccess == true) - { - NS_LOG_DEBUG ("mode=" << (event->GetPayloadMode ().GetDataRate ()) << - ", snr=" << snrPer.snr << ", per=" << snrPer.per << ", size=" << packet->GetSize ()); - - if (m_random->GetValue () > snrPer.per) { - NotifyRxEnd (packet); - uint32_t dataRate500KbpsUnits; - if ((event->GetPayloadMode ().GetModulationClass () == WIFI_MOD_CLASS_HT)) + NS_LOG_DEBUG ("mode=" << (event->GetPayloadMode ().GetDataRate ()) << + ", snr=" << snrPer.snr << ", per=" << snrPer.per << ", size=" << packet->GetSize ()); + + if (m_random->GetValue () > snrPer.per) { - dataRate500KbpsUnits = 128 + WifiModeToMcs (event->GetPayloadMode ()); + NotifyRxEnd (packet); + uint32_t dataRate500KbpsUnits; + if ((event->GetPayloadMode ().GetModulationClass () == WIFI_MOD_CLASS_HT)) + { + dataRate500KbpsUnits = 128 + WifiModeToMcs (event->GetPayloadMode ()); + } + else + { + dataRate500KbpsUnits = event->GetPayloadMode ().GetDataRate () * event->GetTxVector ().GetNss () / 500000; + } + bool isShortPreamble = (WIFI_PREAMBLE_SHORT == event->GetPreambleType ()); + double signalDbm = RatioToDb (event->GetRxPowerW ()) + 30; + double noiseDbm = RatioToDb (event->GetRxPowerW () / snrPer.snr) - GetRxNoiseFigure () + 30; + NotifyMonitorSniffRx (packet, (uint16_t)GetChannelFrequencyMhz (), GetChannelNumber (), dataRate500KbpsUnits, isShortPreamble, event->GetTxVector (), signalDbm, noiseDbm); + m_state->SwitchFromRxEndOk (packet, snrPer.snr, event->GetTxVector (), event->GetPreambleType ()); } else { - dataRate500KbpsUnits = event->GetPayloadMode ().GetDataRate () * event->GetTxVector().GetNss()/ 500000; + /* failure. */ + NotifyRxDrop (packet); + m_state->SwitchFromRxEndError (packet, snrPer.snr); } - bool isShortPreamble = (WIFI_PREAMBLE_SHORT == event->GetPreambleType ()); - double signalDbm = RatioToDb (event->GetRxPowerW ()) + 30; - double noiseDbm = RatioToDb (event->GetRxPowerW () / snrPer.snr) - GetRxNoiseFigure () + 30; - NotifyMonitorSniffRx (packet, (uint16_t)GetChannelFrequencyMhz (), GetChannelNumber (), dataRate500KbpsUnits, isShortPreamble, event->GetTxVector (), signalDbm, noiseDbm); - m_state->SwitchFromRxEndOk (packet, snrPer.snr, event->GetTxVector (), event->GetPreambleType ()); } - else + else { - /* failure. */ - NotifyRxDrop (packet); + //notify rx end m_state->SwitchFromRxEndError (packet, snrPer.snr); } - } - else - { - m_state->SwitchFromRxEndError (packet, snrPer.snr); //notify rx end - } if (preamble == WIFI_PREAMBLE_NONE && packetType == 2) { m_plcpSuccess = false; } - } int64_t @@ -1074,6 +1140,7 @@ YansWifiPhy::SetNumberOfTransmitAntennas (uint32_t tx) { m_numberOfTransmitters = tx; } + void YansWifiPhy::SetNumberOfReceiveAntennas (uint32_t rx) { @@ -1097,11 +1164,13 @@ YansWifiPhy::SetGreenfield (bool greenfield) { m_greenfield = greenfield; } + bool YansWifiPhy::GetGuardInterval (void) const { return m_guardInterval; } + void YansWifiPhy::SetGuardInterval (bool guardInterval) { @@ -1119,6 +1188,7 @@ YansWifiPhy::GetNumberOfTransmitAntennas (void) const { return m_numberOfTransmitters; } + uint32_t YansWifiPhy::GetNumberOfReceiveAntennas (void) const { @@ -1130,6 +1200,7 @@ YansWifiPhy::GetLdpc (void) const { return m_ldpc; } + bool YansWifiPhy::GetStbc (void) const { @@ -1154,306 +1225,266 @@ YansWifiPhy::SetChannelBonding(bool channelbonding) m_channelBonding= channelbonding; } -void -YansWifiPhy::Configure80211n (void) -{ - NS_LOG_FUNCTION (this); - if (m_channelStartingFrequency>=2400 && m_channelStartingFrequency<=2500) //@ 2.4 GHz - { - m_deviceRateSet.push_back (WifiPhy::GetDsssRate1Mbps ()); - m_deviceRateSet.push_back (WifiPhy::GetDsssRate2Mbps ()); - m_deviceRateSet.push_back (WifiPhy::GetDsssRate5_5Mbps ()); - m_deviceRateSet.push_back (WifiPhy::GetErpOfdmRate6Mbps ()); - m_deviceRateSet.push_back (WifiPhy::GetDsssRate11Mbps ()); - m_deviceRateSet.push_back (WifiPhy::GetErpOfdmRate12Mbps ()); - m_deviceRateSet.push_back (WifiPhy::GetErpOfdmRate24Mbps ()); - } - if (m_channelStartingFrequency>=5000 && m_channelStartingFrequency<=6000) //@ 5 GHz - { - m_deviceRateSet.push_back (WifiPhy::GetOfdmRate6Mbps ()); - m_deviceRateSet.push_back (WifiPhy::GetOfdmRate12Mbps ()); - m_deviceRateSet.push_back (WifiPhy::GetOfdmRate24Mbps ()); - } - m_bssMembershipSelectorSet.push_back(HT_PHY); - for (uint8_t i=0; i <8; i++) - { - m_deviceMcsSet.push_back(i); - } - -} uint32_t YansWifiPhy::GetNBssMembershipSelectors (void) const { return m_bssMembershipSelectorSet.size (); } + uint32_t YansWifiPhy::GetBssMembershipSelector (uint32_t selector) const { return m_bssMembershipSelectorSet[selector]; } + WifiModeList YansWifiPhy::GetMembershipSelectorModes(uint32_t selector) { - uint32_t id=GetBssMembershipSelector(selector); + uint32_t id = GetBssMembershipSelector (selector); WifiModeList supportedmodes; if (id == HT_PHY) - { - //mandatory MCS 0 to 7 - supportedmodes.push_back (WifiPhy::GetOfdmRate6_5MbpsBW20MHz ()); - supportedmodes.push_back (WifiPhy::GetOfdmRate13MbpsBW20MHz ()); - supportedmodes.push_back (WifiPhy::GetOfdmRate19_5MbpsBW20MHz ()); - supportedmodes.push_back (WifiPhy::GetOfdmRate26MbpsBW20MHz ()); - supportedmodes.push_back (WifiPhy::GetOfdmRate39MbpsBW20MHz ()); - supportedmodes.push_back (WifiPhy::GetOfdmRate52MbpsBW20MHz ()); - supportedmodes.push_back (WifiPhy::GetOfdmRate58_5MbpsBW20MHz ()); - supportedmodes.push_back (WifiPhy::GetOfdmRate65MbpsBW20MHz ()); - } + { + //mandatory MCS 0 to 7 + supportedmodes.push_back (WifiPhy::GetOfdmRate6_5MbpsBW20MHz ()); + supportedmodes.push_back (WifiPhy::GetOfdmRate13MbpsBW20MHz ()); + supportedmodes.push_back (WifiPhy::GetOfdmRate19_5MbpsBW20MHz ()); + supportedmodes.push_back (WifiPhy::GetOfdmRate26MbpsBW20MHz ()); + supportedmodes.push_back (WifiPhy::GetOfdmRate39MbpsBW20MHz ()); + supportedmodes.push_back (WifiPhy::GetOfdmRate52MbpsBW20MHz ()); + supportedmodes.push_back (WifiPhy::GetOfdmRate58_5MbpsBW20MHz ()); + supportedmodes.push_back (WifiPhy::GetOfdmRate65MbpsBW20MHz ()); + } return supportedmodes; } + uint8_t YansWifiPhy::GetNMcs (void) const { return m_deviceMcsSet.size (); } + uint8_t YansWifiPhy::GetMcs (uint8_t mcs) const { return m_deviceMcsSet[mcs]; } + uint32_t YansWifiPhy::WifiModeToMcs (WifiMode mode) { - uint32_t mcs = 0; - if (mode.GetUniqueName() == "OfdmRate135MbpsBW40MHzShGi" || mode.GetUniqueName() == "OfdmRate65MbpsBW20MHzShGi" ) - { - mcs=6; - } + uint32_t mcs = 0; + if (mode.GetUniqueName () == "OfdmRate135MbpsBW40MHzShGi" || mode.GetUniqueName () == "OfdmRate65MbpsBW20MHzShGi") + { + mcs = 6; + } else { - switch (mode.GetDataRate()) - { - case 6500000: - case 7200000: - case 13500000: - case 15000000: - mcs=0; - break; - case 13000000: - case 14400000: - case 27000000: - case 30000000: - mcs=1; - break; - case 19500000: - case 21700000: - case 40500000: - case 45000000: - mcs=2; - break; - case 26000000: - case 28900000: - case 54000000: - case 60000000: - mcs=3; - break; - case 39000000: - case 43300000: - case 81000000: - case 90000000: - mcs=4; - break; - case 52000000: - case 57800000: - case 108000000: - case 120000000: - mcs=5; - break; - case 58500000: - case 121500000: - mcs=6; - break; - case 65000000: - case 72200000: - case 135000000: - case 150000000: - mcs=7; - break; - } + switch (mode.GetDataRate ()) + { + case 6500000: + case 7200000: + case 13500000: + case 15000000: + mcs = 0; + break; + case 13000000: + case 14400000: + case 27000000: + case 30000000: + mcs = 1; + break; + case 19500000: + case 21700000: + case 40500000: + case 45000000: + mcs = 2; + break; + case 26000000: + case 28900000: + case 54000000: + case 60000000: + mcs = 3; + break; + case 39000000: + case 43300000: + case 81000000: + case 90000000: + mcs = 4; + break; + case 52000000: + case 57800000: + case 108000000: + case 120000000: + mcs = 5; + break; + case 58500000: + case 121500000: + mcs = 6; + break; + case 65000000: + case 72200000: + case 135000000: + case 150000000: + mcs = 7; + break; + } } return mcs; } + WifiMode YansWifiPhy::McsToWifiMode (uint8_t mcs) { - WifiMode mode; - switch (mcs) - { - case 7: - if (!GetGuardInterval() && !GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate65MbpsBW20MHz (); - } - else if(GetGuardInterval() && !GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate72_2MbpsBW20MHz (); - } - else if (!GetGuardInterval() && GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate135MbpsBW40MHz (); - } - else - { - mode = WifiPhy::GetOfdmRate150MbpsBW40MHz (); - } - break; - case 6: - if (!GetGuardInterval() && !GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate58_5MbpsBW20MHz (); - - } - else if(GetGuardInterval() && !GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate65MbpsBW20MHzShGi (); - - } - else if (!GetGuardInterval() && GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate121_5MbpsBW40MHz (); - - } - else - { - mode= WifiPhy::GetOfdmRate135MbpsBW40MHzShGi (); - - } - break; - case 5: - if (!GetGuardInterval() && !GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate52MbpsBW20MHz (); - - } - else if(GetGuardInterval() && !GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate57_8MbpsBW20MHz (); - } - else if (!GetGuardInterval() && GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate108MbpsBW40MHz (); - - } - else - { - mode = WifiPhy::GetOfdmRate120MbpsBW40MHz (); - - } - break; - case 4: - if (!GetGuardInterval() && !GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate39MbpsBW20MHz (); - } - else if(GetGuardInterval() && !GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate43_3MbpsBW20MHz (); - } - else if (!GetGuardInterval() && GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate81MbpsBW40MHz (); - - } - else - { - mode = WifiPhy::GetOfdmRate90MbpsBW40MHz (); - - } - break; - case 3: - if (!GetGuardInterval() && !GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate26MbpsBW20MHz (); - - } - else if(GetGuardInterval() && !GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate28_9MbpsBW20MHz (); - - } - else if (!GetGuardInterval() && GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate54MbpsBW40MHz (); - - } - else - { - mode = WifiPhy::GetOfdmRate60MbpsBW40MHz (); - } - break; - case 2: - if (!GetGuardInterval() && !GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate19_5MbpsBW20MHz (); - - } - else if(GetGuardInterval() && !GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate21_7MbpsBW20MHz (); - - } - else if (!GetGuardInterval() && GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate40_5MbpsBW40MHz (); - - } - else - { - mode = WifiPhy::GetOfdmRate45MbpsBW40MHz (); - - } - break; - case 1: - if (!GetGuardInterval() && !GetChannelBonding()) - { + WifiMode mode; + switch (mcs) + { + case 7: + if (!GetGuardInterval () && !GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate65MbpsBW20MHz (); + } + else if (GetGuardInterval () && !GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate72_2MbpsBW20MHz (); + } + else if (!GetGuardInterval () && GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate135MbpsBW40MHz (); + } + else + { + mode = WifiPhy::GetOfdmRate150MbpsBW40MHz (); + } + break; + case 6: + if (!GetGuardInterval () && !GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate58_5MbpsBW20MHz (); + } + else if (GetGuardInterval () && !GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate65MbpsBW20MHzShGi (); + } + else if (!GetGuardInterval () && GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate121_5MbpsBW40MHz (); + } + else + { + mode= WifiPhy::GetOfdmRate135MbpsBW40MHzShGi (); + } + break; + case 5: + if (!GetGuardInterval () && !GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate52MbpsBW20MHz (); + } + else if (GetGuardInterval() && !GetChannelBonding()) + { + mode = WifiPhy::GetOfdmRate57_8MbpsBW20MHz (); + } + else if (!GetGuardInterval () && GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate108MbpsBW40MHz (); + } + else + { + mode = WifiPhy::GetOfdmRate120MbpsBW40MHz (); + } + break; + case 4: + if (!GetGuardInterval () && !GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate39MbpsBW20MHz (); + } + else if (GetGuardInterval () && !GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate43_3MbpsBW20MHz (); + } + else if (!GetGuardInterval () && GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate81MbpsBW40MHz (); + } + else + { + mode = WifiPhy::GetOfdmRate90MbpsBW40MHz (); + } + break; + case 3: + if (!GetGuardInterval () && !GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate26MbpsBW20MHz (); + } + else if (GetGuardInterval () && !GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate28_9MbpsBW20MHz (); + } + else if (!GetGuardInterval () && GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate54MbpsBW40MHz (); + } + else + { + mode = WifiPhy::GetOfdmRate60MbpsBW40MHz (); + } + break; + case 2: + if (!GetGuardInterval () && !GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate19_5MbpsBW20MHz (); + } + else if (GetGuardInterval () && !GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate21_7MbpsBW20MHz (); + } + else if (!GetGuardInterval () && GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate40_5MbpsBW40MHz (); + } + else + { + mode = WifiPhy::GetOfdmRate45MbpsBW40MHz (); + } + break; + case 1: + if (!GetGuardInterval () && !GetChannelBonding ()) + { mode = WifiPhy::GetOfdmRate13MbpsBW20MHz (); - - } - else if(GetGuardInterval() && !GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate14_4MbpsBW20MHz (); - } - else if (!GetGuardInterval() && GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate27MbpsBW40MHz (); - - } - else - { - mode = WifiPhy::GetOfdmRate30MbpsBW40MHz (); - } - break; - case 0: - default: - if (!GetGuardInterval() && !GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate6_5MbpsBW20MHz (); - - } - else if(GetGuardInterval() && !GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate7_2MbpsBW20MHz (); - } - else if (!GetGuardInterval() && GetChannelBonding()) - { - mode = WifiPhy::GetOfdmRate13_5MbpsBW40MHz (); - - } - else - { - mode = WifiPhy::GetOfdmRate15MbpsBW40MHz (); - } - break; - } - return mode; + } + else if (GetGuardInterval () && !GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate14_4MbpsBW20MHz (); + } + else if (!GetGuardInterval () && GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate27MbpsBW40MHz (); + } + else + { + mode = WifiPhy::GetOfdmRate30MbpsBW40MHz (); + } + break; + case 0: + default: + if (!GetGuardInterval () && !GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate6_5MbpsBW20MHz (); + } + else if (GetGuardInterval () && !GetChannelBonding ()) + { + mode = WifiPhy::GetOfdmRate7_2MbpsBW20MHz (); + } + else if (!GetGuardInterval() && GetChannelBonding()) + { + mode = WifiPhy::GetOfdmRate13_5MbpsBW40MHz (); + } + else + { + mode = WifiPhy::GetOfdmRate15MbpsBW40MHz (); + } + break; + } + return mode; } + } // namespace ns3 diff --git a/src/wifi/model/yans-wifi-phy.h b/src/wifi/model/yans-wifi-phy.h index 82c6de264..ab5d2ce3a 100644 --- a/src/wifi/model/yans-wifi-phy.h +++ b/src/wifi/model/yans-wifi-phy.h @@ -15,8 +15,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Author: Mathieu Lacage - * Author: ghada Badawy + * Authors: Mathieu Lacage + * Ghada Badawy */ #ifndef YANS_WIFI_PHY_H @@ -37,7 +37,6 @@ #include "wifi-phy-standard.h" #include "interference-helper.h" - namespace ns3 { #define HT_PHY 127 @@ -75,7 +74,6 @@ public: * \param channel the YansWifiChannel this YansWifiPhy is to be connected to */ void SetChannel (Ptr channel); - /** * Set the current channel number. * @@ -109,12 +107,12 @@ public: * \param packetType The type of the received packet (values: 0 not an A-MPDU, 1 corresponds to any packets in an A-MPDU except the last one, 2 is the last packet in an A-MPDU) * \param rxDuration the duration needed for the reception of the packet */ - void StartReceivePlcp (Ptr packet, - double rxPowerDbm, - WifiTxVector txVector, - WifiPreamble preamble, - uint8_t packetType, - Time rxDuration); + void StartReceivePreambleAndHeader (Ptr packet, + double rxPowerDbm, + WifiTxVector txVector, + WifiPreamble preamble, + uint8_t packetType, + Time rxDuration); /** * Starting receiving the payload of a packet (i.e. the first bit of the packet has arrived). * @@ -150,7 +148,7 @@ public: void SetTxPowerEnd (double end); /** * Sets the number of transmission power levels available between the - * minimum level and the maximum level. Transmission power levels are + * minimum level and the maximum level. Transmission power levels are * equally separated (in dBm) with the minimum and the maximum included. * * \param n the number of available levels @@ -177,7 +175,7 @@ public: */ void SetEdThreshold (double threshold); /** - * Sets the CCA threshold (dBm). The energy of a received signal + * Sets the CCA threshold (dBm). The energy of a received signal * should be higher than this threshold to allow the PHY * layer to declare CCA BUSY state. * @@ -250,7 +248,6 @@ public: * \return the mobility model this PHY is associated with */ Ptr GetMobility (void); - /** * Return the minimum available transmission power level (dBm). * \return the minimum available transmission power level (dBm) @@ -267,6 +264,7 @@ public: * \return the number of available transmission power levels */ virtual uint32_t GetNTxPower (void) const; + virtual void SetReceiveOkCallback (WifiPhy::RxOkCallback callback); virtual void SetReceiveErrorCallback (WifiPhy::RxErrorCallback callback); virtual void SendPacket (Ptr packet, WifiTxVector txvector, enum WifiPreamble preamble, uint8_t packetType); @@ -315,6 +313,9 @@ public: * \param tx the number of transmitters on this node. */ virtual void SetNumberOfTransmitAntennas (uint32_t tx); + /** + * \return the number of transmitters on this node. + */ virtual uint32_t GetNumberOfTransmitAntennas (void) const; /** * \param rx the number of receivers on this node. @@ -387,6 +388,7 @@ public: virtual uint32_t GetNBssMembershipSelectors (void) const; virtual uint32_t GetBssMembershipSelector (uint32_t selector) const; virtual WifiModeList GetMembershipSelectorModes(uint32_t selector); + /** * \return the number of MCS supported by this phy */ @@ -396,9 +398,11 @@ public: virtual uint32_t WifiModeToMcs (WifiMode mode); virtual WifiMode McsToWifiMode (uint8_t mcs); + private: - //YansWifiPhy (const YansWifiPhy &o); + virtual void DoInitialize (void); virtual void DoDispose (void); + /** * Configure YansWifiPhy with appropriate channel frequency and * supported rates for 802.11a standard. @@ -440,6 +444,7 @@ private: * Convert from dBm to Watts. * * \param dbm the power in dBm + * * \return the equivalent Watts for the given dBm */ double DbmToW (double dbm) const; @@ -447,6 +452,7 @@ private: * Convert from dB to ratio. * * \param db + * * \return ratio */ double DbToRatio (double db) const; @@ -454,6 +460,7 @@ private: * Convert from Watts to dBm. * * \param w the power in Watts + * * \return the equivalent dBm for the given Watts */ double WToDbm (double w) const; @@ -461,6 +468,7 @@ private: * Convert from ratio to dB. * * \param ratio + * * \return dB */ double RatioToDb (double ratio) const; @@ -469,6 +477,7 @@ private: * In YansWifiPhy implementation, the power levels are equally spaced (in dBm). * * \param power the power level + * * \return the transmission power in dBm at the given power level */ double GetPowerDbm (uint8_t power) const; @@ -481,9 +490,6 @@ private: * \param event the corresponding event of the first time the packet arrives */ void EndReceive (Ptr packet, enum WifiPreamble preamble, uint8_t packetType, Ptr event); - -private: - virtual void DoInitialize (void); bool m_initialized; //!< Flag for runtime initialization double m_edThresholdW; //!< Energy detection threshold in watts @@ -562,5 +568,4 @@ private: } // namespace ns3 - #endif /* YANS_WIFI_PHY_H */