diff --git a/examples/wireless/power-adaptation-interference.cc b/examples/wireless/power-adaptation-interference.cc index 8ec2ff466..62989bc9b 100644 --- a/examples/wireless/power-adaptation-interference.cc +++ b/examples/wireless/power-adaptation-interference.cc @@ -82,7 +82,7 @@ public: void RxCallback (std::string path, Ptr packet, const Address &from); void PowerCallback (std::string path, double oldPower, double newPower, Mac48Address dest); void RateCallback (std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest); - void StateCallback (std::string path, Time init, Time duration, enum WifiPhy::State state); + void StateCallback (std::string path, Time init, Time duration, WifiPhyState state); Gnuplot2dDataset GetDatafile (); Gnuplot2dDataset GetPowerDatafile (); @@ -216,24 +216,24 @@ NodeStatistics::RateCallback (std::string path, DataRate oldRate, DataRate newRa } void -NodeStatistics::StateCallback (std::string path, Time init, Time duration, enum WifiPhy::State state) +NodeStatistics::StateCallback (std::string path, Time init, Time duration, WifiPhyState state) { - if (state == WifiPhy::CCA_BUSY) + if (state == WifiPhyState::CCA_BUSY) { busyTime += duration.GetSeconds (); totalBusyTime += duration.GetSeconds (); } - else if (state == WifiPhy::IDLE) + else if (state == WifiPhyState::IDLE) { idleTime += duration.GetSeconds (); totalIdleTime += duration.GetSeconds (); } - else if (state == WifiPhy::TX) + else if (state == WifiPhyState::TX) { txTime += duration.GetSeconds (); totalTxTime += duration.GetSeconds (); } - else if (state == WifiPhy::RX) + else if (state == WifiPhyState::RX) { rxTime += duration.GetSeconds (); totalRxTime += duration.GetSeconds (); diff --git a/examples/wireless/wifi-ap.cc b/examples/wireless/wifi-ap.cc index a40550466..74e7a47d4 100644 --- a/examples/wireless/wifi-ap.cc +++ b/examples/wireless/wifi-ap.cc @@ -46,7 +46,7 @@ DevRxTrace (std::string context, Ptr p) } } void -PhyRxOkTrace (std::string context, Ptr packet, double snr, WifiMode mode, enum WifiPreamble preamble) +PhyRxOkTrace (std::string context, Ptr packet, double snr, WifiMode mode, WifiPreamble preamble) { if (g_verbose) { @@ -70,7 +70,7 @@ PhyTxTrace (std::string context, Ptr packet, WifiMode mode, WifiPr } } void -PhyStateTrace (std::string context, Time start, Time duration, enum WifiPhy::State state) +PhyStateTrace (std::string context, Time start, Time duration, WifiPhyState state) { if (g_verbose) { diff --git a/examples/wireless/wifi-sleep.cc b/examples/wireless/wifi-sleep.cc index a011bbef1..62ffb67fd 100644 --- a/examples/wireless/wifi-sleep.cc +++ b/examples/wireless/wifi-sleep.cc @@ -68,7 +68,7 @@ void RemainingEnergyTrace (double oldValue, double newValue) } template -void PhyStateTrace (std::string context, Time start, Time duration, enum WifiPhy::State state) +void PhyStateTrace (std::string context, Time start, Time duration, WifiPhyState state) { std::stringstream ss; ss << "state_" << node << ".log"; diff --git a/src/energy/examples/basic-energy-model-test.cc b/src/energy/examples/basic-energy-model-test.cc index 3e974ff92..c64c71f45 100644 --- a/src/energy/examples/basic-energy-model-test.cc +++ b/src/energy/examples/basic-energy-model-test.cc @@ -61,7 +61,7 @@ private: * Runs simulation for a while, check if final state & remaining energy is * correctly updated. */ - bool StateSwitchTest (WifiPhy::State state); + bool StateSwitchTest (WifiPhyState state); private: double m_timeS; // in seconds @@ -89,32 +89,32 @@ BasicEnergyUpdateTest::DoRun (void) m_deviceEnergyModel.SetTypeId ("ns3::WifiRadioEnergyModel"); // run state switch tests - if (StateSwitchTest (WifiPhy::IDLE)) + if (StateSwitchTest (WifiPhyState::IDLE)) { return 1; std::cerr << "Problem with state switch test (WifiPhy idle)." << std::endl; } - if (StateSwitchTest (WifiPhy::CCA_BUSY)) + if (StateSwitchTest (WifiPhyState::CCA_BUSY)) { return 1; std::cerr << "Problem with state switch test (WifiPhy cca busy)." << std::endl; } - if (StateSwitchTest (WifiPhy::TX)) + if (StateSwitchTest (WifiPhyState::TX)) { return 1; std::cerr << "Problem with state switch test (WifiPhy tx)." << std::endl; } - if (StateSwitchTest (WifiPhy::RX)) + if (StateSwitchTest (WifiPhyState::RX)) { return 1; std::cerr << "Problem with state switch test (WifiPhy rx)." << std::endl; } - if (StateSwitchTest (WifiPhy::SWITCHING)) + if (StateSwitchTest (WifiPhyState::SWITCHING)) { return 1; std::cerr << "Problem with state switch test (WifiPhy switching)." << std::endl; } - if (StateSwitchTest (WifiPhy::SLEEP)) + if (StateSwitchTest (WifiPhyState::SLEEP)) { return 1; std::cerr << "Problem with state switch test (WifiPhy sleep)." << std::endl; @@ -123,7 +123,7 @@ BasicEnergyUpdateTest::DoRun (void) } bool -BasicEnergyUpdateTest::StateSwitchTest (WifiPhy::State state) +BasicEnergyUpdateTest::StateSwitchTest (WifiPhyState state) { // create node Ptr node = CreateObject (); @@ -172,7 +172,7 @@ BasicEnergyUpdateTest::StateSwitchTest (WifiPhy::State state) &WifiRadioEnergyModel::ChangeState, devModel, state); // Calculate remaining energy at simulation stop time - Simulator::Schedule (Seconds (m_timeS * 2), + Simulator::Schedule (Seconds (m_timeS * 2), &BasicEnergySource::UpdateEnergySource, source); double timeDelta = 0.000000001; // 1 nanosecond @@ -191,25 +191,25 @@ BasicEnergyUpdateTest::StateSwitchTest (WifiPhy::State state) double current = 0.0; switch (state) { - case WifiPhy::IDLE: + case WifiPhyState::IDLE: current = devModel->GetIdleCurrentA (); break; - case WifiPhy::CCA_BUSY: + case WifiPhyState::CCA_BUSY: current = devModel->GetCcaBusyCurrentA (); break; - case WifiPhy::TX: + case WifiPhyState::TX: current = devModel->GetTxCurrentA (); break; - case WifiPhy::RX: + case WifiPhyState::RX: current = devModel->GetRxCurrentA (); break; - case WifiPhy::SWITCHING: + case WifiPhyState::SWITCHING: current = devModel->GetSwitchingCurrentA (); break; - case WifiPhy::SLEEP: + case WifiPhyState::SLEEP: current = devModel->GetSleepCurrentA (); break; - case WifiPhy::OFF: + case WifiPhyState::OFF: current = 0; break; default: @@ -217,7 +217,7 @@ BasicEnergyUpdateTest::StateSwitchTest (WifiPhy::State state) break; } estRemainingEnergy -= current * voltage * m_timeS; - estRemainingEnergy = std::max(0.0, estRemainingEnergy); + estRemainingEnergy = std::max (0.0, estRemainingEnergy); // obtain remaining energy from source double remainingEnergy = source->GetRemainingEnergy (); @@ -226,15 +226,15 @@ BasicEnergyUpdateTest::StateSwitchTest (WifiPhy::State state) NS_LOG_DEBUG ("Difference is " << estRemainingEnergy - remainingEnergy); // check remaining energy - if ((remainingEnergy > (estRemainingEnergy + m_tolerance)) || - (remainingEnergy < (estRemainingEnergy - m_tolerance))) + if ((remainingEnergy > (estRemainingEnergy + m_tolerance)) + || (remainingEnergy < (estRemainingEnergy - m_tolerance))) { std::cerr << "Incorrect remaining energy!" << std::endl; return true; } // obtain radio state - WifiPhy::State endState = devModel->GetCurrentState (); + WifiPhyState endState = devModel->GetCurrentState (); NS_LOG_DEBUG ("Radio state is " << endState); // check end state if (endState != state) diff --git a/src/test/traced/traced-callback-typedef-test-suite.cc b/src/test/traced/traced-callback-typedef-test-suite.cc index 55829e419..1f2f6440d 100644 --- a/src/test/traced/traced-callback-typedef-test-suite.cc +++ b/src/test/traced/traced-callback-typedef-test-suite.cc @@ -658,7 +658,7 @@ TracedCallbackTypedefTestCase::DoRun (void) empty); CHECK (WifiPhyStateHelper::StateTracedCallback, - Time, Time, WifiPhy::State, + Time, Time, WifiPhyState, empty, empty); CHECK (WifiPhyStateHelper::TxTracedCallback, diff --git a/src/wifi/helper/athstats-helper.cc b/src/wifi/helper/athstats-helper.cc index 06cd6820f..705b497c2 100644 --- a/src/wifi/helper/athstats-helper.cc +++ b/src/wifi/helper/athstats-helper.cc @@ -227,7 +227,7 @@ AthstatsWifiTraceSink::PhyTxTrace (std::string context, Ptr packet } void -AthstatsWifiTraceSink::PhyStateTrace (std::string context, Time start, Time duration, WifiPhy::State state) +AthstatsWifiTraceSink::PhyStateTrace (std::string context, Time start, Time duration, WifiPhyState state) { NS_LOG_FUNCTION (this << context << start << duration << state); } diff --git a/src/wifi/helper/athstats-helper.h b/src/wifi/helper/athstats-helper.h index b5a949f1f..e84363bec 100644 --- a/src/wifi/helper/athstats-helper.h +++ b/src/wifi/helper/athstats-helper.h @@ -197,7 +197,7 @@ public: * @param duration * @param state */ - void PhyStateTrace (std::string context, Time start, Time duration, WifiPhy::State state); + void PhyStateTrace (std::string context, Time start, Time duration, WifiPhyState state); /** * Open a file for output diff --git a/src/wifi/helper/wifi-helper.cc b/src/wifi/helper/wifi-helper.cc index 68daea13c..45406ac8b 100644 --- a/src/wifi/helper/wifi-helper.cc +++ b/src/wifi/helper/wifi-helper.cc @@ -205,7 +205,7 @@ WifiPhyHelper::PcapSniffTxEvent ( if (txVector.GetMode ().GetModulationClass () != WIFI_MOD_CLASS_HT && txVector.GetMode ().GetModulationClass () != WIFI_MOD_CLASS_VHT && txVector.GetMode ().GetModulationClass () != WIFI_MOD_CLASS_HE) { rate = txVector.GetMode ().GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1) * txVector.GetNss () / 500000; - header.SetRate (static_cast(rate)); + header.SetRate (static_cast (rate)); } uint16_t channelFlags = 0; @@ -399,7 +399,7 @@ WifiPhyHelper::PcapSniffRxEvent ( if (txVector.GetMode ().GetModulationClass () != WIFI_MOD_CLASS_HT && txVector.GetMode ().GetModulationClass () != WIFI_MOD_CLASS_VHT && txVector.GetMode ().GetModulationClass () != WIFI_MOD_CLASS_HE) { rate = txVector.GetMode ().GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), 1) * txVector.GetNss () / 500000; - header.SetRate (static_cast(rate)); + header.SetRate (static_cast (rate)); } uint16_t channelFlags = 0; @@ -813,6 +813,7 @@ WifiHelper::EnableLogComponents (void) LogComponentEnable ("StaWifiMac", LOG_LEVEL_ALL); LogComponentEnable ("SupportedRates", LOG_LEVEL_ALL); LogComponentEnable ("WifiMac", LOG_LEVEL_ALL); + LogComponentEnable ("WifiMacQueueItem", LOG_LEVEL_ALL); LogComponentEnable ("WifiNetDevice", LOG_LEVEL_ALL); LogComponentEnable ("WifiPhyStateHelper", LOG_LEVEL_ALL); LogComponentEnable ("WifiPhy", LOG_LEVEL_ALL); diff --git a/src/wifi/model/wifi-mac-queue-item.cc b/src/wifi/model/wifi-mac-queue-item.cc new file mode 100644 index 000000000..1c9bf39b5 --- /dev/null +++ b/src/wifi/model/wifi-mac-queue-item.cc @@ -0,0 +1,86 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2005, 2009 INRIA + * Copyright (c) 2009 MIRKO BANCHI + * + * 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, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Mathieu Lacage + * Mirko Banchi + * Stefano Avallone + */ + +#include "wifi-mac-queue-item.h" +#include "ns3/simulator.h" + +namespace ns3 { + +NS_LOG_COMPONENT_DEFINE ("WifiMacQueueItem"); + +WifiMacQueueItem::WifiMacQueueItem (Ptr p, const WifiMacHeader & header) + : m_packet (p), + m_header (header), + m_tstamp (Simulator::Now ()) +{ +} + +WifiMacQueueItem::~WifiMacQueueItem () +{ +} + +Ptr +WifiMacQueueItem::GetPacket (void) const +{ + return m_packet; +} + +const WifiMacHeader& +WifiMacQueueItem::GetHeader (void) const +{ + return m_header; +} + +Mac48Address +WifiMacQueueItem::GetAddress (WifiMacHeader::AddressType type) const +{ + if (type == WifiMacHeader::ADDR1) + { + return m_header.GetAddr1 (); + } + if (type == WifiMacHeader::ADDR2) + { + return m_header.GetAddr2 (); + } + if (type == WifiMacHeader::ADDR3) + { + return m_header.GetAddr3 (); + } + return 0; +} + +Time +WifiMacQueueItem::GetTimeStamp (void) const +{ + return m_tstamp; +} + +uint32_t +WifiMacQueueItem::GetSize (void) const +{ + return m_packet->GetSize () + m_header.GetSerializedSize (); +} + +NS_OBJECT_TEMPLATE_CLASS_DEFINE (Queue, WifiMacQueueItem); + +} //namespace ns3 diff --git a/src/wifi/model/wifi-mac-queue-item.h b/src/wifi/model/wifi-mac-queue-item.h new file mode 100644 index 000000000..0087d06bd --- /dev/null +++ b/src/wifi/model/wifi-mac-queue-item.h @@ -0,0 +1,121 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2005, 2009 INRIA + * Copyright (c) 2009 MIRKO BANCHI + * + * 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, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Mathieu Lacage + * Mirko Banchi + * Stefano Avallone + */ + +#ifndef WIFI_MAC_QUEUE_ITEM_H +#define WIFI_MAC_QUEUE_ITEM_H + +#include "ns3/queue.h" +#include "wifi-mac-header.h" + +namespace ns3 { + +class QosBlockedDestinations; + +/** + * \ingroup wifi + * + * WifiMacQueueItem stores (const) packets along with their Wifi MAC headers + * and the time when they were enqueued. + */ +class WifiMacQueueItem : public SimpleRefCount +{ +public: + /** + * \brief Create a Wifi MAC queue item containing a packet and a Wifi MAC header. + * \param p the const packet included in the created item. + * \param header the Wifi Mac header included in the created item. + */ + WifiMacQueueItem (Ptr p, const WifiMacHeader & header); + + virtual ~WifiMacQueueItem (); + + /** + * \brief Get the packet stored in this item + * \return the packet stored in this item. + */ + Ptr GetPacket (void) const; + + /** + * \brief Get the header stored in this item + * \return the header stored in this item. + */ + const WifiMacHeader & GetHeader (void) const; + + /** + * \brief Return the requested address present in the header + * \param type the type of the address to return + * \return the address + */ + Mac48Address GetAddress (enum WifiMacHeader::AddressType type) const; + + /** + * \brief Get the timestamp included in this item + * \return the timestamp included in this item. + */ + Time GetTimeStamp (void) const; + + /** + * \brief Return the size of the packet included in this item + * + * \return the size of the packet included in this item. + */ + uint32_t GetSize (void) const; + +private: + /** + * \brief Default constructor + * + * Defined and unimplemented to avoid misuse + */ + WifiMacQueueItem (); + /** + * \brief Copy constructor + * + * Defined and unimplemented to avoid misuse + */ + WifiMacQueueItem (const WifiMacQueueItem &); + /** + * \brief Assignment operator + * + * Defined and unimplemented to avoid misuse + * \returns + */ + WifiMacQueueItem &operator = (const WifiMacQueueItem &); + + Ptr m_packet; //!< The packet contained in this queue item + WifiMacHeader m_header; //!< Wifi MAC header associated with the packet + Time m_tstamp; //!< timestamp when the packet arrived at the queue +}; + + +// The following explicit template instantiation declaration prevents modules +// including this header file from implicitly instantiating Queue. +// This would cause python examples using wifi to crash at runtime with the +// following error message: "Trying to allocate twice the same uid: +// ns3::Queue" +extern template class Queue; + + +} //namespace ns3 + +#endif /* WIFI_MAC_QUEUE_ITEM_H */ diff --git a/src/wifi/model/wifi-mac-queue.cc b/src/wifi/model/wifi-mac-queue.cc index a52856f58..8ea242d6f 100644 --- a/src/wifi/model/wifi-mac-queue.cc +++ b/src/wifi/model/wifi-mac-queue.cc @@ -32,61 +32,6 @@ namespace ns3 { NS_LOG_COMPONENT_DEFINE ("WifiMacQueue"); -WifiMacQueueItem::WifiMacQueueItem (Ptr p, const WifiMacHeader & header) - : m_packet (p), - m_header (header), - m_tstamp (Simulator::Now ()) -{ -} - -WifiMacQueueItem::~WifiMacQueueItem () -{ -} - -Ptr -WifiMacQueueItem::GetPacket (void) const -{ - return m_packet; -} - -const WifiMacHeader& -WifiMacQueueItem::GetHeader (void) const -{ - return m_header; -} - -Mac48Address -WifiMacQueueItem::GetAddress (WifiMacHeader::AddressType type) const -{ - if (type == WifiMacHeader::ADDR1) - { - return m_header.GetAddr1 (); - } - if (type == WifiMacHeader::ADDR2) - { - return m_header.GetAddr2 (); - } - if (type == WifiMacHeader::ADDR3) - { - return m_header.GetAddr3 (); - } - return 0; -} - -Time -WifiMacQueueItem::GetTimeStamp (void) const -{ - return m_tstamp; -} - -uint32_t -WifiMacQueueItem::GetSize (void) const -{ - return m_packet->GetSize () + m_header.GetSerializedSize (); -} - - -NS_OBJECT_TEMPLATE_CLASS_DEFINE (Queue,WifiMacQueueItem); NS_OBJECT_ENSURE_REGISTERED (WifiMacQueue); TypeId @@ -231,8 +176,8 @@ WifiMacQueue::DequeueByTidAndAddress (uint8_t tid, { if (!TtlExceeded (it)) { - if ((*it)->GetHeader ().IsQosData () && (*it)->GetAddress (type) == dest && - (*it)->GetHeader ().GetQosTid () == tid) + if ((*it)->GetHeader ().IsQosData () && (*it)->GetAddress (type) == dest + && (*it)->GetHeader ().GetQosTid () == tid) { return DoDequeue (it); } @@ -294,8 +239,8 @@ WifiMacQueue::PeekByTidAndAddress (uint8_t tid, { if (!TtlExceeded (it)) { - if ((*it)->GetHeader ().IsQosData () && (*it)->GetAddress (type) == dest && - (*it)->GetHeader ().GetQosTid () == tid) + if ((*it)->GetHeader ().IsQosData () && (*it)->GetAddress (type) == dest + && (*it)->GetHeader ().GetQosTid () == tid) { return DoPeek (it); } @@ -379,8 +324,8 @@ WifiMacQueue::GetNPacketsByTidAndAddress (uint8_t tid, WifiMacHeader::AddressTyp { if (!TtlExceeded (it)) { - if ((*it)->GetHeader ().IsQosData () && (*it)->GetAddress (type) == addr && - (*it)->GetHeader ().GetQosTid () == tid) + if ((*it)->GetHeader ().IsQosData () && (*it)->GetAddress (type) == addr + && (*it)->GetHeader ().GetQosTid () == tid) { nPackets++; } diff --git a/src/wifi/model/wifi-mac-queue.h b/src/wifi/model/wifi-mac-queue.h index f0262f6c2..a31770d9d 100644 --- a/src/wifi/model/wifi-mac-queue.h +++ b/src/wifi/model/wifi-mac-queue.h @@ -25,97 +25,13 @@ #define WIFI_MAC_QUEUE_H #include "ns3/queue.h" -#include "wifi-mac-header.h" +#include "wifi-mac-queue-item.h" + namespace ns3 { class QosBlockedDestinations; -/** - * \ingroup wifi - * - * WifiMacQueueItem stores (const) packets along with their Wifi MAC headers - * and the time when they were enqueued. - */ -class WifiMacQueueItem : public SimpleRefCount -{ -public: - /** - * \brief Create a Wifi MAC queue item containing a packet and a Wifi MAC header. - * \param p the const packet included in the created item. - * \param header the Wifi Mac header included in the created item. - */ - WifiMacQueueItem (Ptr p, const WifiMacHeader & header); - - virtual ~WifiMacQueueItem (); - - /** - * \brief Get the packet stored in this item - * \return the packet stored in this item. - */ - Ptr GetPacket (void) const; - - /** - * \brief Get the header stored in this item - * \return the header stored in this item. - */ - const WifiMacHeader & GetHeader (void) const; - - /** - * \brief Return the requested address present in the header - * \param type the type of the address to return - * \return the address - */ - Mac48Address GetAddress (WifiMacHeader::AddressType type) const; - - /** - * \brief Get the timestamp included in this item - * \return the timestamp included in this item. - */ - Time GetTimeStamp (void) const; - - /** - * \brief Return the size of the packet included in this item - * - * \return the size of the packet included in this item. - */ - uint32_t GetSize (void) const; - -private: - /** - * \brief Default constructor - * - * Defined and unimplemented to avoid misuse - */ - WifiMacQueueItem (); - /** - * \brief Copy constructor - * - * Defined and unimplemented to avoid misuse - */ - WifiMacQueueItem (const WifiMacQueueItem &); - /** - * \brief Assignment operator - * - * Defined and unimplemented to avoid misuse - * \returns - */ - WifiMacQueueItem &operator = (const WifiMacQueueItem &); - - Ptr m_packet; //!< The packet contained in this queue item - WifiMacHeader m_header; //!< Wifi MAC header associated with the packet - Time m_tstamp; //!< timestamp when the packet arrived at the queue -}; - - -// The following explicit template instantiation declaration prevents modules -// including this header file from implicitly instantiating Queue. -// This would cause python examples using wifi to crash at runtime with the -// following error message: "Trying to allocate twice the same uid: -// ns3::Queue" -extern template class Queue; - - /** * \ingroup wifi * diff --git a/src/wifi/model/wifi-phy-listener.h b/src/wifi/model/wifi-phy-listener.h new file mode 100644 index 000000000..6620f6929 --- /dev/null +++ b/src/wifi/model/wifi-phy-listener.h @@ -0,0 +1,123 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2005,2006 INRIA + * + * 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, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Mathieu Lacage + * Sébastien Deronne + */ + +#ifndef WIFI_PHY_LISTENER_H +#define WIFI_PHY_LISTENER_H + +#include "ns3/nstime.h" + +namespace ns3 { + +/** + * \brief receive notifications about phy events. + */ +class WifiPhyListener +{ +public: + /**************************************************************** + * This destructor is needed. + ****************************************************************/ + + virtual ~WifiPhyListener () + { + } + + /** + * \param duration the expected duration of the packet reception. + * + * We have received the first bit of a packet. We decided + * that we could synchronize on this packet. It does not mean + * we will be able to successfully receive completely the + * whole packet. It means that we will report a BUSY status until + * one of the following happens: + * - NotifyRxEndOk + * - NotifyRxEndError + * - NotifyTxStart + */ + virtual void NotifyRxStart (Time duration) = 0; + /** + * We have received the last bit of a packet for which + * NotifyRxStart was invoked first and, the packet has + * been successfully received. + */ + virtual void NotifyRxEndOk (void) = 0; + /** + * We have received the last bit of a packet for which + * NotifyRxStart was invoked first and, the packet has + * _not_ been successfully received. + */ + virtual void NotifyRxEndError (void) = 0; + /** + * \param duration the expected transmission duration. + * \param txPowerDbm the nominal tx power in dBm + * + * We are about to send the first bit of the packet. + * We do not send any event to notify the end of + * transmission. Listeners should assume that the + * channel implicitely reverts to the idle state + * unless they have received a cca busy report. + */ + virtual void NotifyTxStart (Time duration, double txPowerDbm) = 0; + /** + * \param duration the expected busy duration. + * + * This method does not really report a real state + * change as opposed to the other methods in this class. + * It merely reports that, unless the medium is reported + * busy through NotifyTxStart or NotifyRxStart/End, + * it will be busy as defined by the currently selected + * CCA mode. + * + * Typical client code which wants to have a clear picture + * of the CCA state will need to keep track of the time at + * which the last NotifyCcaBusyStart method is called and + * what duration it reported. + */ + virtual void NotifyMaybeCcaBusyStart (Time duration) = 0; + /** + * \param duration the expected channel switching duration. + * + * We do not send any event to notify the end of + * channel switching. Listeners should assume that the + * channel implicitely reverts to the idle or busy states. + */ + virtual void NotifySwitchingStart (Time duration) = 0; + /** + * Notify listeners that we went to sleep + */ + virtual void NotifySleep (void) = 0; + /** + * Notify listeners that we went to switch off + */ + virtual void NotifyOff (void) = 0; + /** + * Notify listeners that we woke up + */ + virtual void NotifyWakeup (void) = 0; + /** + * Notify listeners that we went to switch on + */ + virtual void NotifyOn (void) = 0; +}; + +} //namespace ns3 + +#endif /* WIFI_PHY_LISTENER_H */ diff --git a/src/wifi/model/wifi-phy-state-helper.cc b/src/wifi/model/wifi-phy-state-helper.cc index 1d2f35b2e..ece676294 100644 --- a/src/wifi/model/wifi-phy-state-helper.cc +++ b/src/wifi/model/wifi-phy-state-helper.cc @@ -19,8 +19,10 @@ */ #include "wifi-phy-state-helper.h" +#include "wifi-tx-vector.h" #include "ns3/log.h" #include "ns3/simulator.h" +#include "ns3/packet.h" #include namespace ns3 { @@ -74,13 +76,13 @@ WifiPhyStateHelper::WifiPhyStateHelper () } void -WifiPhyStateHelper::SetReceiveOkCallback (WifiPhy::RxOkCallback callback) +WifiPhyStateHelper::SetReceiveOkCallback (RxOkCallback callback) { m_rxOkCallback = callback; } void -WifiPhyStateHelper::SetReceiveErrorCallback (WifiPhy::RxErrorCallback callback) +WifiPhyStateHelper::SetReceiveErrorCallback (RxErrorCallback callback) { m_rxErrorCallback = callback; } @@ -104,49 +106,49 @@ WifiPhyStateHelper::UnregisterListener (WifiPhyListener *listener) bool WifiPhyStateHelper::IsStateIdle (void) const { - return (GetState () == WifiPhy::IDLE); + return (GetState () == WifiPhyState::IDLE); } bool WifiPhyStateHelper::IsStateBusy (void) const { - return (GetState () != WifiPhy::IDLE); + return (GetState () != WifiPhyState::IDLE); } bool WifiPhyStateHelper::IsStateCcaBusy (void) const { - return (GetState () == WifiPhy::CCA_BUSY); + return (GetState () == WifiPhyState::CCA_BUSY); } bool WifiPhyStateHelper::IsStateRx (void) const { - return (GetState () == WifiPhy::RX); + return (GetState () == WifiPhyState::RX); } bool WifiPhyStateHelper::IsStateTx (void) const { - return (GetState () == WifiPhy::TX); + return (GetState () == WifiPhyState::TX); } bool WifiPhyStateHelper::IsStateSwitching (void) const { - return (GetState () == WifiPhy::SWITCHING); + return (GetState () == WifiPhyState::SWITCHING); } bool WifiPhyStateHelper::IsStateSleep (void) const { - return (GetState () == WifiPhy::SLEEP); + return (GetState () == WifiPhyState::SLEEP); } bool WifiPhyStateHelper::IsStateOff (void) const { - return (GetState () == WifiPhy::OFF); + return (GetState () == WifiPhyState::OFF); } Time @@ -162,26 +164,26 @@ WifiPhyStateHelper::GetDelayUntilIdle (void) const switch (GetState ()) { - case WifiPhy::RX: + case WifiPhyState::RX: retval = m_endRx - Simulator::Now (); break; - case WifiPhy::TX: + case WifiPhyState::TX: retval = m_endTx - Simulator::Now (); break; - case WifiPhy::CCA_BUSY: + case WifiPhyState::CCA_BUSY: retval = m_endCcaBusy - Simulator::Now (); break; - case WifiPhy::SWITCHING: + case WifiPhyState::SWITCHING: retval = m_endSwitching - Simulator::Now (); break; - case WifiPhy::IDLE: + case WifiPhyState::IDLE: retval = Seconds (0); break; - case WifiPhy::SLEEP: + case WifiPhyState::SLEEP: NS_FATAL_ERROR ("Cannot determine when the device will wake up."); retval = Seconds (0); break; - case WifiPhy::OFF: + case WifiPhyState::OFF: NS_FATAL_ERROR ("Cannot determine when the device will be switched on."); retval = Seconds (0); break; @@ -200,36 +202,36 @@ WifiPhyStateHelper::GetLastRxStartTime (void) const return m_startRx; } -WifiPhy::State +WifiPhyState WifiPhyStateHelper::GetState (void) const { if (m_isOff) { - return WifiPhy::OFF; + return WifiPhyState::OFF; } if (m_sleeping) { - return WifiPhy::SLEEP; + return WifiPhyState::SLEEP; } else if (m_endTx > Simulator::Now ()) { - return WifiPhy::TX; + return WifiPhyState::TX; } else if (m_rxing) { - return WifiPhy::RX; + return WifiPhyState::RX; } else if (m_endSwitching > Simulator::Now ()) { - return WifiPhy::SWITCHING; + return WifiPhyState::SWITCHING; } else if (m_endCcaBusy > Simulator::Now ()) { - return WifiPhy::CCA_BUSY; + return WifiPhyState::CCA_BUSY; } else { - return WifiPhy::IDLE; + return WifiPhyState::IDLE; } } @@ -349,9 +351,9 @@ WifiPhyStateHelper::LogPreviousIdleAndCcaBusyStates (void) Time ccaBusyStart = Max (m_endTx, m_endRx); ccaBusyStart = Max (ccaBusyStart, m_startCcaBusy); ccaBusyStart = Max (ccaBusyStart, m_endSwitching); - m_stateLogger (ccaBusyStart, idleStart - ccaBusyStart, WifiPhy::CCA_BUSY); + m_stateLogger (ccaBusyStart, idleStart - ccaBusyStart, WifiPhyState::CCA_BUSY); } - m_stateLogger (idleStart, now - idleStart, WifiPhy::IDLE); + m_stateLogger (idleStart, now - idleStart, WifiPhyState::IDLE); } void @@ -363,29 +365,29 @@ WifiPhyStateHelper::SwitchToTx (Time txDuration, Ptr packet, doubl Time now = Simulator::Now (); switch (GetState ()) { - case WifiPhy::RX: + case WifiPhyState::RX: /* The packet which is being received as well * as its endRx event are cancelled by the caller. */ m_rxing = false; - m_stateLogger (m_startRx, now - m_startRx, WifiPhy::RX); + m_stateLogger (m_startRx, now - m_startRx, WifiPhyState::RX); m_endRx = now; break; - case WifiPhy::CCA_BUSY: + case WifiPhyState::CCA_BUSY: { Time ccaStart = Max (m_endRx, m_endTx); ccaStart = Max (ccaStart, m_startCcaBusy); ccaStart = Max (ccaStart, m_endSwitching); - m_stateLogger (ccaStart, now - ccaStart, WifiPhy::CCA_BUSY); + m_stateLogger (ccaStart, now - ccaStart, WifiPhyState::CCA_BUSY); } break; - case WifiPhy::IDLE: + case WifiPhyState::IDLE: LogPreviousIdleAndCcaBusyStates (); break; default: NS_FATAL_ERROR ("Invalid WifiPhy state."); break; } - m_stateLogger (now, txDuration, WifiPhy::TX); + m_stateLogger (now, txDuration, WifiPhyState::TX); m_previousStateChangeTime = now; m_endTx = now + txDuration; m_startTx = now; @@ -401,15 +403,15 @@ WifiPhyStateHelper::SwitchToRx (Time rxDuration) Time now = Simulator::Now (); switch (GetState ()) { - case WifiPhy::IDLE: + case WifiPhyState::IDLE: LogPreviousIdleAndCcaBusyStates (); break; - case WifiPhy::CCA_BUSY: + case WifiPhyState::CCA_BUSY: { Time ccaStart = Max (m_endRx, m_endTx); ccaStart = Max (ccaStart, m_startCcaBusy); ccaStart = Max (ccaStart, m_endSwitching); - m_stateLogger (ccaStart, now - ccaStart, WifiPhy::CCA_BUSY); + m_stateLogger (ccaStart, now - ccaStart, WifiPhyState::CCA_BUSY); } break; default: NS_FATAL_ERROR ("Invalid WifiPhy state."); @@ -430,22 +432,22 @@ WifiPhyStateHelper::SwitchToChannelSwitching (Time switchingDuration) Time now = Simulator::Now (); switch (GetState ()) { - case WifiPhy::RX: + case WifiPhyState::RX: /* The packet which is being received as well * as its endRx event are cancelled by the caller. */ m_rxing = false; - m_stateLogger (m_startRx, now - m_startRx, WifiPhy::RX); + m_stateLogger (m_startRx, now - m_startRx, WifiPhyState::RX); m_endRx = now; break; - case WifiPhy::CCA_BUSY: + case WifiPhyState::CCA_BUSY: { Time ccaStart = Max (m_endRx, m_endTx); ccaStart = Max (ccaStart, m_startCcaBusy); ccaStart = Max (ccaStart, m_endSwitching); - m_stateLogger (ccaStart, now - ccaStart, WifiPhy::CCA_BUSY); + m_stateLogger (ccaStart, now - ccaStart, WifiPhyState::CCA_BUSY); } break; - case WifiPhy::IDLE: + case WifiPhyState::IDLE: LogPreviousIdleAndCcaBusyStates (); break; default: @@ -458,7 +460,7 @@ WifiPhyStateHelper::SwitchToChannelSwitching (Time switchingDuration) m_endCcaBusy = now; } - m_stateLogger (now, switchingDuration, WifiPhy::SWITCHING); + m_stateLogger (now, switchingDuration, WifiPhyState::SWITCHING); m_previousStateChangeTime = now; m_startSwitching = now; m_endSwitching = now + switchingDuration; @@ -501,7 +503,7 @@ WifiPhyStateHelper::DoSwitchFromRx (void) NS_ASSERT (m_rxing); Time now = Simulator::Now (); - m_stateLogger (m_startRx, now - m_startRx, WifiPhy::RX); + m_stateLogger (m_startRx, now - m_startRx, WifiPhyState::RX); m_previousStateChangeTime = now; m_rxing = false; @@ -516,13 +518,13 @@ WifiPhyStateHelper::SwitchMaybeToCcaBusy (Time duration) Time now = Simulator::Now (); switch (GetState ()) { - case WifiPhy::IDLE: + case WifiPhyState::IDLE: LogPreviousIdleAndCcaBusyStates (); break; default: break; } - if (GetState () != WifiPhy::CCA_BUSY) + if (GetState () != WifiPhyState::CCA_BUSY) { m_startCcaBusy = now; } @@ -536,15 +538,15 @@ WifiPhyStateHelper::SwitchToSleep (void) Time now = Simulator::Now (); switch (GetState ()) { - case WifiPhy::IDLE: + case WifiPhyState::IDLE: LogPreviousIdleAndCcaBusyStates (); break; - case WifiPhy::CCA_BUSY: + case WifiPhyState::CCA_BUSY: { Time ccaStart = Max (m_endRx, m_endTx); ccaStart = Max (ccaStart, m_startCcaBusy); ccaStart = Max (ccaStart, m_endSwitching); - m_stateLogger (ccaStart, now - ccaStart, WifiPhy::CCA_BUSY); + m_stateLogger (ccaStart, now - ccaStart, WifiPhyState::CCA_BUSY); } break; default: NS_FATAL_ERROR ("Invalid WifiPhy state."); @@ -563,7 +565,7 @@ WifiPhyStateHelper::SwitchFromSleep (Time duration) NS_LOG_FUNCTION (this << duration); NS_ASSERT (IsStateSleep ()); Time now = Simulator::Now (); - m_stateLogger (m_startSleep, now - m_startSleep, WifiPhy::SLEEP); + m_stateLogger (m_startSleep, now - m_startSleep, WifiPhyState::SLEEP); m_previousStateChangeTime = now; m_sleeping = false; NotifyWakeup (); @@ -593,30 +595,30 @@ WifiPhyStateHelper::SwitchToOff (void) Time now = Simulator::Now (); switch (GetState ()) { - case WifiPhy::RX: + case WifiPhyState::RX: /* The packet which is being received as well * as its endRx event are cancelled by the caller. */ m_rxing = false; - m_stateLogger (m_startRx, now - m_startRx, WifiPhy::RX); + m_stateLogger (m_startRx, now - m_startRx, WifiPhyState::RX); m_endRx = now; break; - case WifiPhy::TX: + case WifiPhyState::TX: /* The packet which is being transmitted as well * as its endTx event are cancelled by the caller. */ - m_stateLogger (m_startTx, now - m_startTx, WifiPhy::TX); + m_stateLogger (m_startTx, now - m_startTx, WifiPhyState::TX); m_endTx = now; break; - case WifiPhy::IDLE: + case WifiPhyState::IDLE: LogPreviousIdleAndCcaBusyStates (); break; - case WifiPhy::CCA_BUSY: + case WifiPhyState::CCA_BUSY: { Time ccaStart = Max (m_endRx, m_endTx); ccaStart = Max (ccaStart, m_startCcaBusy); ccaStart = Max (ccaStart, m_endSwitching); - m_stateLogger (ccaStart, now - ccaStart, WifiPhy::CCA_BUSY); + m_stateLogger (ccaStart, now - ccaStart, WifiPhyState::CCA_BUSY); } break; default: NS_FATAL_ERROR ("Invalid WifiPhy state."); diff --git a/src/wifi/model/wifi-phy-state-helper.h b/src/wifi/model/wifi-phy-state-helper.h index 90051d27c..300c6919d 100644 --- a/src/wifi/model/wifi-phy-state-helper.h +++ b/src/wifi/model/wifi-phy-state-helper.h @@ -21,11 +21,32 @@ #ifndef WIFI_PHY_STATE_HELPER_H #define WIFI_PHY_STATE_HELPER_H -#include "wifi-phy.h" #include "ns3/object.h" +#include "wifi-phy-state.h" +#include "ns3/callback.h" +#include "ns3/traced-callback.h" +#include "wifi-preamble.h" +#include "wifi-phy-listener.h" namespace ns3 { +class WifiTxVector; +class WifiMode; +class Packet; + +/** + * arg1: packet received successfully + * arg2: snr of packet + * arg3: TXVECTOR of packet + * arg4: type of preamble used for packet. + */ +typedef Callback, double, WifiTxVector> RxOkCallback; +/** + * arg1: packet received unsuccessfully + * arg2: snr of packet + */ +typedef Callback, double> RxErrorCallback; + /** * \ingroup wifi * @@ -47,13 +68,13 @@ public: * * \param callback */ - void SetReceiveOkCallback (WifiPhy::RxOkCallback callback); + void SetReceiveOkCallback (RxOkCallback callback); /** * Set a callback for a failed reception. * * \param callback */ - void SetReceiveErrorCallback (WifiPhy::RxErrorCallback callback); + void SetReceiveErrorCallback (RxErrorCallback callback); /** * Register WifiPhyListener to this WifiPhyStateHelper. * @@ -71,7 +92,7 @@ public: * * \return the current state of WifiPhy */ - WifiPhy::State GetState (void) const; + WifiPhyState GetState (void) const; /** * Check whether the current state is CCA busy. * @@ -214,7 +235,7 @@ public: * the \p state. * \param [in] state The state. */ - typedef void (* StateTracedCallback)(Time start, Time duration, WifiPhy::State state); + typedef void (* StateTracedCallback)(Time start, Time duration, WifiPhyState state); /** * TracedCallback signature for receive end ok event. @@ -319,7 +340,7 @@ private: /** * The trace source fired when state is changed. */ - TracedCallback m_stateLogger; + TracedCallback m_stateLogger; bool m_rxing; ///< receiving bool m_sleeping; ///< sleeping @@ -339,8 +360,8 @@ private: TracedCallback, double, WifiMode, WifiPreamble> m_rxOkTrace; ///< receive OK trace callback TracedCallback, double> m_rxErrorTrace; ///< receive error trace callback TracedCallback, WifiMode, WifiPreamble, uint8_t> m_txTrace; ///< transmit trace callback - WifiPhy::RxOkCallback m_rxOkCallback; ///< receive OK callback - WifiPhy::RxErrorCallback m_rxErrorCallback; ///< receive error callback + RxOkCallback m_rxOkCallback; ///< receive OK callback + RxErrorCallback m_rxErrorCallback; ///< receive error callback }; } //namespace ns3 diff --git a/src/wifi/model/wifi-phy-state.h b/src/wifi/model/wifi-phy-state.h new file mode 100644 index 000000000..ae43af539 --- /dev/null +++ b/src/wifi/model/wifi-phy-state.h @@ -0,0 +1,61 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2005,2006 INRIA + * + * 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, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Mathieu Lacage + * Sébastien Deronne + */ + +#ifndef WIFI_PHY_STATE_H +#define WIFI_PHY_STATE_H + +/** + * The state of the PHY layer. + */ +/// State enumeration +enum WifiPhyState +{ + /** + * The PHY layer is IDLE. + */ + IDLE, + /** + * The PHY layer has sense the medium busy through the CCA mechanism + */ + CCA_BUSY, + /** + * The PHY layer is sending a packet. + */ + TX, + /** + * The PHY layer is receiving a packet. + */ + RX, + /** + * The PHY layer is switching to other channel. + */ + SWITCHING, + /** + * The PHY layer is sleeping. + */ + SLEEP, + /** + * The PHY layer is switched off. + */ + OFF +}; + +#endif /* WIFI_PHY_STATE_H */ diff --git a/src/wifi/model/wifi-phy.cc b/src/wifi/model/wifi-phy.cc index 559689dd7..4fc0a2cc2 100644 --- a/src/wifi/model/wifi-phy.cc +++ b/src/wifi/model/wifi-phy.cc @@ -20,7 +20,6 @@ */ #include "wifi-phy.h" -#include "wifi-phy-state-helper.h" #include "ns3/simulator.h" #include "ns3/log.h" #include "ns3/boolean.h" @@ -37,14 +36,6 @@ namespace ns3 { NS_LOG_COMPONENT_DEFINE ("WifiPhy"); -/**************************************************************** - * This destructor is needed. - ****************************************************************/ - -WifiPhyListener::~WifiPhyListener () -{ -} - /**************************************************************** * The actual WifiPhy class ****************************************************************/ @@ -1505,21 +1496,21 @@ WifiPhy::DoChannelSwitch (uint8_t nch) NS_ASSERT (!IsStateSwitching ()); switch (m_state->GetState ()) { - case WifiPhy::RX: + case WifiPhyState::RX: NS_LOG_DEBUG ("drop packet because of channel switching while reception"); m_endPlcpRxEvent.Cancel (); m_endRxEvent.Cancel (); goto switchChannel; break; - case WifiPhy::TX: + case WifiPhyState::TX: NS_LOG_DEBUG ("channel switching postponed until end of current transmission"); Simulator::Schedule (GetDelayUntilIdle (), &WifiPhy::SetChannelNumber, this, nch); break; - case WifiPhy::CCA_BUSY: - case WifiPhy::IDLE: + case WifiPhyState::CCA_BUSY: + case WifiPhyState::IDLE: goto switchChannel; break; - case WifiPhy::SLEEP: + case WifiPhyState::SLEEP: NS_LOG_DEBUG ("channel switching ignored in sleep mode"); break; default: @@ -1557,21 +1548,21 @@ WifiPhy::DoFrequencySwitch (uint16_t frequency) NS_ASSERT (!IsStateSwitching ()); switch (m_state->GetState ()) { - case WifiPhy::RX: + case WifiPhyState::RX: NS_LOG_DEBUG ("drop packet because of channel/frequency switching while reception"); m_endPlcpRxEvent.Cancel (); m_endRxEvent.Cancel (); goto switchFrequency; break; - case WifiPhy::TX: + case WifiPhyState::TX: NS_LOG_DEBUG ("channel/frequency switching postponed until end of current transmission"); Simulator::Schedule (GetDelayUntilIdle (), &WifiPhy::SetFrequency, this, frequency); break; - case WifiPhy::CCA_BUSY: - case WifiPhy::IDLE: + case WifiPhyState::CCA_BUSY: + case WifiPhyState::IDLE: goto switchFrequency; break; - case WifiPhy::SLEEP: + case WifiPhyState::SLEEP: NS_LOG_DEBUG ("frequency switching ignored in sleep mode"); break; default: @@ -1602,24 +1593,24 @@ WifiPhy::SetSleepMode (void) NS_LOG_FUNCTION (this); switch (m_state->GetState ()) { - case WifiPhy::TX: + case WifiPhyState::TX: NS_LOG_DEBUG ("setting sleep mode postponed until end of current transmission"); Simulator::Schedule (GetDelayUntilIdle (), &WifiPhy::SetSleepMode, this); break; - case WifiPhy::RX: + case WifiPhyState::RX: NS_LOG_DEBUG ("setting sleep mode postponed until end of current reception"); Simulator::Schedule (GetDelayUntilIdle (), &WifiPhy::SetSleepMode, this); break; - case WifiPhy::SWITCHING: + case WifiPhyState::SWITCHING: NS_LOG_DEBUG ("setting sleep mode postponed until end of channel switching"); Simulator::Schedule (GetDelayUntilIdle (), &WifiPhy::SetSleepMode, this); break; - case WifiPhy::CCA_BUSY: - case WifiPhy::IDLE: + case WifiPhyState::CCA_BUSY: + case WifiPhyState::IDLE: NS_LOG_DEBUG ("setting sleep mode"); m_state->SwitchToSleep (); break; - case WifiPhy::SLEEP: + case WifiPhyState::SLEEP: NS_LOG_DEBUG ("already in sleep mode"); break; default: @@ -1634,14 +1625,14 @@ WifiPhy::SetOffMode (void) NS_LOG_FUNCTION (this); switch (m_state->GetState ()) { - case WifiPhy::RX: + case WifiPhyState::RX: m_endPlcpRxEvent.Cancel (); m_endRxEvent.Cancel (); - case WifiPhy::TX: - case WifiPhy::SWITCHING: - case WifiPhy::CCA_BUSY: - case WifiPhy::IDLE: - case WifiPhy::SLEEP: + case WifiPhyState::TX: + case WifiPhyState::SWITCHING: + case WifiPhyState::CCA_BUSY: + case WifiPhyState::IDLE: + case WifiPhyState::SLEEP: m_state->SwitchToOff (); break; default: @@ -1656,16 +1647,16 @@ WifiPhy::ResumeFromSleep (void) NS_LOG_FUNCTION (this); switch (m_state->GetState ()) { - case WifiPhy::TX: - case WifiPhy::RX: - case WifiPhy::IDLE: - case WifiPhy::CCA_BUSY: - case WifiPhy::SWITCHING: + case WifiPhyState::TX: + case WifiPhyState::RX: + case WifiPhyState::IDLE: + case WifiPhyState::CCA_BUSY: + case WifiPhyState::SWITCHING: { NS_LOG_DEBUG ("not in sleep mode, there is nothing to resume"); break; } - case WifiPhy::SLEEP: + case WifiPhyState::SLEEP: { NS_LOG_DEBUG ("resuming from sleep mode"); Time delayUntilCcaEnd = m_interference.GetEnergyDuration (DbmToW (GetCcaMode1Threshold ())); @@ -1686,17 +1677,17 @@ WifiPhy::ResumeFromOff (void) NS_LOG_FUNCTION (this); switch (m_state->GetState ()) { - case WifiPhy::TX: - case WifiPhy::RX: - case WifiPhy::IDLE: - case WifiPhy::CCA_BUSY: - case WifiPhy::SWITCHING: - case WifiPhy::SLEEP: + case WifiPhyState::TX: + case WifiPhyState::RX: + case WifiPhyState::IDLE: + case WifiPhyState::CCA_BUSY: + case WifiPhyState::SWITCHING: + case WifiPhyState::SLEEP: { NS_LOG_DEBUG ("not in off mode, there is nothing to resume"); break; } - case WifiPhy::OFF: + case WifiPhyState::OFF: { NS_LOG_DEBUG ("resuming from off mode"); Time delayUntilCcaEnd = m_interference.GetEnergyDuration (DbmToW (GetCcaMode1Threshold ())); @@ -2411,13 +2402,13 @@ WifiPhy::SendPacket (Ptr packet, WifiTxVector txVector, MpduType m Ptr newPacket = packet->Copy (); // obtain non-const Packet WifiPhyTag oldtag; newPacket->RemovePacketTag (oldtag); - if (m_state->GetState () == WifiPhy::OFF) + if (m_state->GetState () == WifiPhyState::OFF) { NS_LOG_DEBUG ("Transmission canceled because device is OFF"); return; } uint8_t isFrameComplete = 1; - if (m_wifiRadioEnergyModel != 0 && m_wifiRadioEnergyModel->GetMaximumTimeInState (WifiPhy::TX) < txDuration) + if (m_wifiRadioEnergyModel != 0 && m_wifiRadioEnergyModel->GetMaximumTimeInState (WifiPhyState::TX) < txDuration) { isFrameComplete = 0; } @@ -2447,7 +2438,7 @@ WifiPhy::StartReceivePreambleAndHeader (Ptr packet, double rxPowerW, Tim //This function should be later split to check separately whether plcp preamble and plcp header can be successfully received. //Note: plcp preamble reception is not yet modeled. - if (m_state->GetState () == WifiPhy::OFF) + if (m_state->GetState () == WifiPhyState::OFF) { NS_LOG_DEBUG ("Cannot start RX because device is OFF"); return; @@ -2487,7 +2478,7 @@ WifiPhy::StartReceivePreambleAndHeader (Ptr packet, double rxPowerW, Tim MpduType mpdutype = tag.GetMpduType (); switch (m_state->GetState ()) { - case WifiPhy::SWITCHING: + case WifiPhyState::SWITCHING: NS_LOG_DEBUG ("drop packet because of channel switching"); NotifyRxDrop (packet); m_plcpSuccess = false; @@ -2507,7 +2498,7 @@ WifiPhy::StartReceivePreambleAndHeader (Ptr packet, double rxPowerW, Tim return; } break; - case WifiPhy::RX: + case WifiPhyState::RX: NS_ASSERT (m_currentEvent != 0); if (m_frameCaptureModel != 0 && m_frameCaptureModel->CaptureNewFrame (m_currentEvent, event)) @@ -2530,7 +2521,7 @@ WifiPhy::StartReceivePreambleAndHeader (Ptr packet, double rxPowerW, Tim } } break; - case WifiPhy::TX: + case WifiPhyState::TX: NS_LOG_DEBUG ("drop packet because already in Tx (power=" << rxPowerW << "W)"); NotifyRxDrop (packet); @@ -2542,11 +2533,11 @@ WifiPhy::StartReceivePreambleAndHeader (Ptr packet, double rxPowerW, Tim return; } break; - case WifiPhy::CCA_BUSY: - case WifiPhy::IDLE: + case WifiPhyState::CCA_BUSY: + case WifiPhyState::IDLE: StartRx (packet, txVector, mpdutype, rxPowerW, rxDuration, event); break; - case WifiPhy::SLEEP: + case WifiPhyState::SLEEP: NS_LOG_DEBUG ("drop packet because in sleep mode"); NotifyRxDrop (packet); m_plcpSuccess = false; @@ -3783,23 +3774,23 @@ WifiPhy::AssignStreams (int64_t stream) return 1; } -std::ostream& operator<< (std::ostream& os, WifiPhy::State state) +std::ostream& operator<< (std::ostream& os, WifiPhyState state) { switch (state) { - case WifiPhy::IDLE: + case WifiPhyState::IDLE: return (os << "IDLE"); - case WifiPhy::CCA_BUSY: + case WifiPhyState::CCA_BUSY: return (os << "CCA_BUSY"); - case WifiPhy::TX: + case WifiPhyState::TX: return (os << "TX"); - case WifiPhy::RX: + case WifiPhyState::RX: return (os << "RX"); - case WifiPhy::SWITCHING: + case WifiPhyState::SWITCHING: return (os << "SWITCHING"); - case WifiPhy::SLEEP: + case WifiPhyState::SLEEP: return (os << "SLEEP"); - case WifiPhy::OFF: + case WifiPhyState::OFF: return (os << "OFF"); default: NS_FATAL_ERROR ("Invalid WifiPhy state"); diff --git a/src/wifi/model/wifi-phy.h b/src/wifi/model/wifi-phy.h index 715066a78..b8aa611d6 100644 --- a/src/wifi/model/wifi-phy.h +++ b/src/wifi/model/wifi-phy.h @@ -23,7 +23,6 @@ #define WIFI_PHY_H #include -#include "ns3/callback.h" #include "ns3/event-id.h" #include "ns3/mobility-model.h" #include "ns3/random-variable-stream.h" @@ -32,6 +31,7 @@ #include "interference-helper.h" #include "ns3/node.h" #include "ns3/string.h" +#include "wifi-phy-state-helper.h" namespace ns3 { @@ -82,93 +82,6 @@ struct MpduInfo uint32_t mpduRefNumber; ///< MPDU ref number }; -/** - * \brief receive notifications about phy events. - */ -class WifiPhyListener -{ -public: - virtual ~WifiPhyListener (); - - /** - * \param duration the expected duration of the packet reception. - * - * We have received the first bit of a packet. We decided - * that we could synchronize on this packet. It does not mean - * we will be able to successfully receive completely the - * whole packet. It means that we will report a BUSY status until - * one of the following happens: - * - NotifyRxEndOk - * - NotifyRxEndError - * - NotifyTxStart - */ - virtual void NotifyRxStart (Time duration) = 0; - /** - * We have received the last bit of a packet for which - * NotifyRxStart was invoked first and, the packet has - * been successfully received. - */ - virtual void NotifyRxEndOk (void) = 0; - /** - * We have received the last bit of a packet for which - * NotifyRxStart was invoked first and, the packet has - * _not_ been successfully received. - */ - virtual void NotifyRxEndError (void) = 0; - /** - * \param duration the expected transmission duration. - * \param txPowerDbm the nominal tx power in dBm - * - * We are about to send the first bit of the packet. - * We do not send any event to notify the end of - * transmission. Listeners should assume that the - * channel implicitely reverts to the idle state - * unless they have received a cca busy report. - */ - virtual void NotifyTxStart (Time duration, double txPowerDbm) = 0; - /** - * \param duration the expected busy duration. - * - * This method does not really report a real state - * change as opposed to the other methods in this class. - * It merely reports that, unless the medium is reported - * busy through NotifyTxStart or NotifyRxStart/End, - * it will be busy as defined by the currently selected - * CCA mode. - * - * Typical client code which wants to have a clear picture - * of the CCA state will need to keep track of the time at - * which the last NotifyCcaBusyStart method is called and - * what duration it reported. - */ - virtual void NotifyMaybeCcaBusyStart (Time duration) = 0; - /** - * \param duration the expected channel switching duration. - * - * We do not send any event to notify the end of - * channel switching. Listeners should assume that the - * channel implicitely reverts to the idle or busy states. - */ - virtual void NotifySwitchingStart (Time duration) = 0; - /** - * Notify listeners that we went to sleep - */ - virtual void NotifySleep (void) = 0; - /** - * Notify listeners that we went to switch off - */ - virtual void NotifyOff (void) = 0; - /** - * Notify listeners that we woke up - */ - virtual void NotifyWakeup (void) = 0; - /** - * Notify listeners that we went to switch on - */ - virtual void NotifyOn (void) = 0; -}; - - /** * \brief 802.11 PHY layer model * \ingroup wifi @@ -177,55 +90,6 @@ public: class WifiPhy : public Object { public: - /** - * The state of the PHY layer. - */ - /// State enumeration - enum State - { - /** - * The PHY layer is IDLE. - */ - IDLE, - /** - * The PHY layer has sense the medium busy through the CCA mechanism - */ - CCA_BUSY, - /** - * The PHY layer is sending a packet. - */ - TX, - /** - * The PHY layer is receiving a packet. - */ - RX, - /** - * The PHY layer is switching to other channel. - */ - SWITCHING, - /** - * The PHY layer is sleeping. - */ - SLEEP, - /** - * The PHY layer is switched off. - */ - OFF - }; - - /** - * arg1: packet received successfully - * arg2: snr of packet - * arg3: TXVECTOR of packet - * arg4: type of preamble used for packet. - */ - typedef Callback, double, WifiTxVector> RxOkCallback; - /** - * arg1: packet received unsuccessfully - * arg2: snr of packet - */ - typedef Callback, double> RxErrorCallback; - /** * \brief Get the type ID. * \return the object TypeId @@ -2009,7 +1873,7 @@ private: * \param state wifi state to stringify * \return output stream */ -std::ostream& operator<< (std::ostream& os, WifiPhy::State state); +std::ostream& operator<< (std::ostream& os, WifiPhyState state); } //namespace ns3 diff --git a/src/wifi/model/wifi-radio-energy-model.cc b/src/wifi/model/wifi-radio-energy-model.cc index f572987a8..5855e994d 100644 --- a/src/wifi/model/wifi-radio-energy-model.cc +++ b/src/wifi/model/wifi-radio-energy-model.cc @@ -88,7 +88,7 @@ WifiRadioEnergyModel::GetTypeId (void) WifiRadioEnergyModel::WifiRadioEnergyModel () : m_source (0), - m_currentState (WifiPhy::IDLE), + m_currentState (WifiPhyState::IDLE), m_lastUpdateTime (Seconds (0.0)), m_nPendingChangeState (0) { @@ -115,7 +115,7 @@ WifiRadioEnergyModel::SetEnergySource (const Ptr source) m_source = source; m_switchToOffEvent.Cancel (); Time durationToOff = GetMaximumTimeInState (m_currentState); - m_switchToOffEvent = Simulator::Schedule (durationToOff, &WifiRadioEnergyModel::ChangeState, this, WifiPhy::OFF); + m_switchToOffEvent = Simulator::Schedule (durationToOff, &WifiRadioEnergyModel::ChangeState, this, WifiPhyState::OFF); } double @@ -131,25 +131,25 @@ WifiRadioEnergyModel::GetTotalEnergyConsumption (void) const double supplyVoltage = m_source->GetSupplyVoltage (); switch (m_currentState) { - case WifiPhy::IDLE: + case WifiPhyState::IDLE: energyToDecrease = duration.GetSeconds () * m_idleCurrentA * supplyVoltage; break; - case WifiPhy::CCA_BUSY: + case WifiPhyState::CCA_BUSY: energyToDecrease = duration.GetSeconds () * m_ccaBusyCurrentA * supplyVoltage; break; - case WifiPhy::TX: + case WifiPhyState::TX: energyToDecrease = duration.GetSeconds () * m_txCurrentA * supplyVoltage; break; - case WifiPhy::RX: + case WifiPhyState::RX: energyToDecrease = duration.GetSeconds () * m_rxCurrentA * supplyVoltage; break; - case WifiPhy::SWITCHING: + case WifiPhyState::SWITCHING: energyToDecrease = duration.GetSeconds () * m_switchingCurrentA * supplyVoltage; break; - case WifiPhy::SLEEP: + case WifiPhyState::SLEEP: energyToDecrease = duration.GetSeconds () * m_sleepCurrentA * supplyVoltage; break; - case WifiPhy::OFF: + case WifiPhyState::OFF: energyToDecrease = 0; break; default: @@ -246,7 +246,7 @@ WifiRadioEnergyModel::SetSleepCurrentA (double sleepCurrentA) m_sleepCurrentA = sleepCurrentA; } -WifiPhy::State +WifiPhyState WifiRadioEnergyModel::GetCurrentState (void) const { NS_LOG_FUNCTION (this); @@ -300,22 +300,22 @@ WifiRadioEnergyModel::GetMaximumTimeInState (int state) const double supplyVoltage = m_source->GetSupplyVoltage (); switch (state) { - case WifiPhy::IDLE: + case WifiPhyState::IDLE: remainingTime = NanoSeconds (1e9 * (remainingEnergy / (m_idleCurrentA * supplyVoltage))); break; - case WifiPhy::CCA_BUSY: + case WifiPhyState::CCA_BUSY: remainingTime = NanoSeconds (1e9 * (remainingEnergy / (m_ccaBusyCurrentA * supplyVoltage))); break; - case WifiPhy::TX: + case WifiPhyState::TX: remainingTime = NanoSeconds (1e9 * (remainingEnergy / (m_txCurrentA * supplyVoltage))); break; - case WifiPhy::RX: + case WifiPhyState::RX: remainingTime = NanoSeconds (1e9 * (remainingEnergy / (m_rxCurrentA * supplyVoltage))); break; - case WifiPhy::SWITCHING: + case WifiPhyState::SWITCHING: remainingTime = NanoSeconds (1e9 * (remainingEnergy / (m_switchingCurrentA * supplyVoltage))); break; - case WifiPhy::SLEEP: + case WifiPhyState::SLEEP: remainingTime = NanoSeconds (1e9 * (remainingEnergy / (m_sleepCurrentA * supplyVoltage))); break; default: @@ -331,18 +331,18 @@ WifiRadioEnergyModel::ChangeState (int newState) m_nPendingChangeState++; - if (m_nPendingChangeState > 1 && newState == WifiPhy::OFF) + if (m_nPendingChangeState > 1 && newState == WifiPhyState::OFF) { - SetWifiRadioState ((WifiPhy::State) newState); + SetWifiRadioState ((WifiPhyState) newState); m_nPendingChangeState--; return; } - if (newState != WifiPhy::OFF) + if (newState != WifiPhyState::OFF) { m_switchToOffEvent.Cancel (); Time durationToOff = GetMaximumTimeInState (newState); - m_switchToOffEvent = Simulator::Schedule (durationToOff, &WifiRadioEnergyModel::ChangeState, this, WifiPhy::OFF); + m_switchToOffEvent = Simulator::Schedule (durationToOff, &WifiRadioEnergyModel::ChangeState, this, WifiPhyState::OFF); } Time duration = Simulator::Now () - m_lastUpdateTime; @@ -353,25 +353,25 @@ WifiRadioEnergyModel::ChangeState (int newState) double supplyVoltage = m_source->GetSupplyVoltage (); switch (m_currentState) { - case WifiPhy::IDLE: + case WifiPhyState::IDLE: energyToDecrease = (duration.GetNanoSeconds () * m_idleCurrentA * supplyVoltage) / 1e9; break; - case WifiPhy::CCA_BUSY: + case WifiPhyState::CCA_BUSY: energyToDecrease = (duration.GetNanoSeconds () * m_ccaBusyCurrentA * supplyVoltage) / 1e9; break; - case WifiPhy::TX: + case WifiPhyState::TX: energyToDecrease = (duration.GetNanoSeconds () * m_txCurrentA * supplyVoltage) / 1e9; break; - case WifiPhy::RX: + case WifiPhyState::RX: energyToDecrease = (duration.GetNanoSeconds () * m_rxCurrentA * supplyVoltage) / 1e9; break; - case WifiPhy::SWITCHING: + case WifiPhyState::SWITCHING: energyToDecrease = (duration.GetNanoSeconds () * m_switchingCurrentA * supplyVoltage) / 1e9; break; - case WifiPhy::SLEEP: + case WifiPhyState::SLEEP: energyToDecrease = (duration.GetNanoSeconds () * m_sleepCurrentA * supplyVoltage) / 1e9; break; - case WifiPhy::OFF: + case WifiPhyState::OFF: energyToDecrease = 0.0; break; default: @@ -395,10 +395,10 @@ WifiRadioEnergyModel::ChangeState (int newState) // by the previous instance is erroneously the final state stored in m_currentState. The check below // ensures that previous instances do not change m_currentState. - if (m_nPendingChangeState <= 1 && m_currentState != WifiPhy::OFF) + if (m_nPendingChangeState <= 1 && m_currentState != WifiPhyState::OFF) { // update current state & last update time stamp - SetWifiRadioState ((WifiPhy::State) newState); + SetWifiRadioState ((WifiPhyState) newState); // some debug message NS_LOG_DEBUG ("WifiRadioEnergyModel:Total energy consumption is " << @@ -437,11 +437,11 @@ WifiRadioEnergyModel::HandleEnergyChanged (void) { NS_LOG_FUNCTION (this); NS_LOG_DEBUG ("WifiRadioEnergyModel:Energy is changed!"); - if (m_currentState != WifiPhy::OFF) + if (m_currentState != WifiPhyState::OFF) { m_switchToOffEvent.Cancel (); Time durationToOff = GetMaximumTimeInState (m_currentState); - m_switchToOffEvent = Simulator::Schedule (durationToOff, &WifiRadioEnergyModel::ChangeState, this, WifiPhy::OFF); + m_switchToOffEvent = Simulator::Schedule (durationToOff, &WifiRadioEnergyModel::ChangeState, this, WifiPhyState::OFF); } } @@ -469,19 +469,19 @@ WifiRadioEnergyModel::DoGetCurrentA (void) const { switch (m_currentState) { - case WifiPhy::IDLE: + case WifiPhyState::IDLE: return m_idleCurrentA; - case WifiPhy::CCA_BUSY: + case WifiPhyState::CCA_BUSY: return m_ccaBusyCurrentA; - case WifiPhy::TX: + case WifiPhyState::TX: return m_txCurrentA; - case WifiPhy::RX: + case WifiPhyState::RX: return m_rxCurrentA; - case WifiPhy::SWITCHING: + case WifiPhyState::SWITCHING: return m_switchingCurrentA; - case WifiPhy::SLEEP: + case WifiPhyState::SLEEP: return m_sleepCurrentA; - case WifiPhy::OFF: + case WifiPhyState::OFF: return 0.0; default: NS_FATAL_ERROR ("WifiRadioEnergyModel: undefined radio state " << m_currentState); @@ -489,32 +489,32 @@ WifiRadioEnergyModel::DoGetCurrentA (void) const } void -WifiRadioEnergyModel::SetWifiRadioState (const WifiPhy::State state) +WifiRadioEnergyModel::SetWifiRadioState (const WifiPhyState state) { NS_LOG_FUNCTION (this << state); m_currentState = state; std::string stateName; switch (state) { - case WifiPhy::IDLE: + case WifiPhyState::IDLE: stateName = "IDLE"; break; - case WifiPhy::CCA_BUSY: + case WifiPhyState::CCA_BUSY: stateName = "CCA_BUSY"; break; - case WifiPhy::TX: + case WifiPhyState::TX: stateName = "TX"; break; - case WifiPhy::RX: + case WifiPhyState::RX: stateName = "RX"; break; - case WifiPhy::SWITCHING: + case WifiPhyState::SWITCHING: stateName = "SWITCHING"; break; - case WifiPhy::SLEEP: + case WifiPhyState::SLEEP: stateName = "SLEEP"; break; - case WifiPhy::OFF: + case WifiPhyState::OFF: stateName = "OFF"; break; } @@ -560,7 +560,7 @@ WifiRadioEnergyModelPhyListener::NotifyRxStart (Time duration) { NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); } - m_changeStateCallback (WifiPhy::RX); + m_changeStateCallback (WifiPhyState::RX); m_switchToIdleEvent.Cancel (); } @@ -572,7 +572,7 @@ WifiRadioEnergyModelPhyListener::NotifyRxEndOk (void) { NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); } - m_changeStateCallback (WifiPhy::IDLE); + m_changeStateCallback (WifiPhyState::IDLE); } void @@ -583,7 +583,7 @@ WifiRadioEnergyModelPhyListener::NotifyRxEndError (void) { NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); } - m_changeStateCallback (WifiPhy::IDLE); + m_changeStateCallback (WifiPhyState::IDLE); } void @@ -599,7 +599,7 @@ WifiRadioEnergyModelPhyListener::NotifyTxStart (Time duration, double txPowerDbm { NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); } - m_changeStateCallback (WifiPhy::TX); + m_changeStateCallback (WifiPhyState::TX); // schedule changing state back to IDLE after TX duration m_switchToIdleEvent.Cancel (); m_switchToIdleEvent = Simulator::Schedule (duration, &WifiRadioEnergyModelPhyListener::SwitchToIdle, this); @@ -613,7 +613,7 @@ WifiRadioEnergyModelPhyListener::NotifyMaybeCcaBusyStart (Time duration) { NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); } - m_changeStateCallback (WifiPhy::CCA_BUSY); + m_changeStateCallback (WifiPhyState::CCA_BUSY); // schedule changing state back to IDLE after CCA_BUSY duration m_switchToIdleEvent.Cancel (); m_switchToIdleEvent = Simulator::Schedule (duration, &WifiRadioEnergyModelPhyListener::SwitchToIdle, this); @@ -627,7 +627,7 @@ WifiRadioEnergyModelPhyListener::NotifySwitchingStart (Time duration) { NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); } - m_changeStateCallback (WifiPhy::SWITCHING); + m_changeStateCallback (WifiPhyState::SWITCHING); // schedule changing state back to IDLE after CCA_BUSY duration m_switchToIdleEvent.Cancel (); m_switchToIdleEvent = Simulator::Schedule (duration, &WifiRadioEnergyModelPhyListener::SwitchToIdle, this); @@ -641,7 +641,7 @@ WifiRadioEnergyModelPhyListener::NotifySleep (void) { NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); } - m_changeStateCallback (WifiPhy::SLEEP); + m_changeStateCallback (WifiPhyState::SLEEP); m_switchToIdleEvent.Cancel (); } @@ -653,7 +653,7 @@ WifiRadioEnergyModelPhyListener::NotifyWakeup (void) { NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); } - m_changeStateCallback (WifiPhy::IDLE); + m_changeStateCallback (WifiPhyState::IDLE); } void @@ -664,7 +664,7 @@ WifiRadioEnergyModelPhyListener::NotifyOff (void) { NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); } - m_changeStateCallback (WifiPhy::OFF); + m_changeStateCallback (WifiPhyState::OFF); m_switchToIdleEvent.Cancel (); } @@ -676,7 +676,7 @@ WifiRadioEnergyModelPhyListener::NotifyOn (void) { NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); } - m_changeStateCallback (WifiPhy::IDLE); + m_changeStateCallback (WifiPhyState::IDLE); } void @@ -687,7 +687,7 @@ WifiRadioEnergyModelPhyListener::SwitchToIdle (void) { NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); } - m_changeStateCallback (WifiPhy::IDLE); + m_changeStateCallback (WifiPhyState::IDLE); } } // namespace ns3 diff --git a/src/wifi/model/wifi-radio-energy-model.h b/src/wifi/model/wifi-radio-energy-model.h index c49392afb..9e528fb10 100644 --- a/src/wifi/model/wifi-radio-energy-model.h +++ b/src/wifi/model/wifi-radio-energy-model.h @@ -321,7 +321,7 @@ public: /** * \returns Current state. */ - WifiPhy::State GetCurrentState (void) const; + WifiPhyState GetCurrentState (void) const; /** * \param callback Callback function. @@ -409,7 +409,7 @@ private: * Sets current state. This function is private so that only the energy model * can change its own state. */ - void SetWifiRadioState (const WifiPhy::State state); + void SetWifiRadioState (const WifiPhyState state); Ptr m_source; ///< energy source @@ -426,7 +426,7 @@ private: TracedValue m_totalEnergyConsumption; // State variables. - WifiPhy::State m_currentState; ///< current state the radio is in + WifiPhyState m_currentState; ///< current state the radio is in Time m_lastUpdateTime; ///< time stamp of previous energy update uint8_t m_nPendingChangeState; ///< pending state change diff --git a/src/wifi/wscript b/src/wifi/wscript index 0d7c032f1..d7746b59b 100644 --- a/src/wifi/wscript +++ b/src/wifi/wscript @@ -91,6 +91,7 @@ def build(bld): 'helper/yans-wifi-helper.cc', 'helper/spectrum-wifi-helper.cc', 'helper/wifi-mac-helper.cc', + 'model/wifi-mac-queue-item.cc', ] obj_test = bld.create_ns3_module_test_library('wifi') @@ -198,6 +199,9 @@ def build(bld): 'helper/yans-wifi-helper.h', 'helper/spectrum-wifi-helper.h', 'helper/wifi-mac-helper.h', + 'model/wifi-mac-queue-item.h', + 'model/wifi-phy-state.h', + 'model/wifi-phy-listener.h', ] if bld.env['ENABLE_GSL']: