--- a/src/wifi/helper/wifi-helper.h Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/helper/wifi-helper.h Mon Jan 26 15:17:35 2015 -0800
@@ -55,8 +55,12 @@
*
* Subclasses must implement this method to allow the ns3::WifiHelper class
* to create PHY objects from ns3::WifiHelper::Install.
+ *
+ * Typically the device type will be of class WifiNetDevice but the
+ * type of the pointer is generalized so that this method may be used
+ * by other Wifi device variants such as WaveNetDevice.
*/
- virtual Ptr<WifiPhy> Create (Ptr<Node> node, Ptr<WifiNetDevice> device) const = 0;
+ virtual Ptr<WifiPhy> Create (Ptr<Node> node, Ptr<NetDevice> device) const = 0;
};
/**
--- a/src/wifi/helper/yans-wifi-helper.cc Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/helper/yans-wifi-helper.cc Mon Jan 26 15:17:35 2015 -0800
@@ -234,7 +234,7 @@
}
Ptr<WifiPhy>
-YansWifiPhyHelper::Create (Ptr<Node> node, Ptr<WifiNetDevice> device) const
+YansWifiPhyHelper::Create (Ptr<Node> node, Ptr<NetDevice> device) const
{
Ptr<YansWifiPhy> phy = m_phy.Create<YansWifiPhy> ();
Ptr<ErrorRateModel> error = m_errorRateModel.Create<ErrorRateModel> ();
@@ -419,6 +419,12 @@
}
}
+uint32_t
+YansWifiPhyHelper::GetPcapDataLinkType (void) const
+{
+ return m_pcapDlt;
+}
+
void
YansWifiPhyHelper::EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous, bool explicitFilename)
{
--- a/src/wifi/helper/yans-wifi-helper.h Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/helper/yans-wifi-helper.h Mon Jan 26 15:17:35 2015 -0800
@@ -243,6 +243,15 @@
*/
void SetPcapDataLinkType (enum SupportedPcapDataLinkTypes dlt);
+ /**
+ * Get the data link type of PCAP traces to be used.
+ *
+ * @see SupportedPcapDataLinkTypes
+ *
+ * @returns The data link type of the pcap file (and packets) to be used
+ */
+ uint32_t GetPcapDataLinkType (void) const;
+
private:
/**
* \param node the node on which we wish to create a wifi PHY
@@ -251,7 +260,7 @@
*
* This method implements the pure virtual method defined in \ref ns3::WifiPhyHelper.
*/
- virtual Ptr<WifiPhy> Create (Ptr<Node> node, Ptr<WifiNetDevice> device) const;
+ virtual Ptr<WifiPhy> Create (Ptr<Node> node, Ptr<NetDevice> device) const;
/**
* @brief Enable pcap output the indicated net device.
--- a/src/wifi/model/adhoc-wifi-mac.cc Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/adhoc-wifi-mac.cc Mon Jan 26 15:17:35 2015 -0800
@@ -87,10 +87,7 @@
{
// In ad hoc mode, we assume that every destination supports all
// the rates we support.
- for (uint32_t i = 0; i < m_phy->GetNModes (); i++)
- {
- m_stationManager->AddSupportedMode (to, m_phy->GetMode (i));
- }
+ m_stationManager->AddAllSupportedModes (to);
m_stationManager->RecordDisassociated (to);
}
--- a/src/wifi/model/dca-txop.cc Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/dca-txop.cc Mon Jan 26 15:17:35 2015 -0800
@@ -66,6 +66,14 @@
{
m_txop->NotifyChannelSwitching ();
}
+ virtual void DoNotifySleep (void)
+ {
+ m_txop->NotifySleep ();
+ }
+ virtual void DoNotifyWakeUp (void)
+ {
+ m_txop->NotifyWakeUp ();
+ }
DcaTxop *m_txop;
};
@@ -512,6 +520,22 @@
m_queue->Flush ();
m_currentPacket = 0;
}
+void
+DcaTxop::NotifySleep (void)
+{
+ NS_LOG_FUNCTION (this);
+ if (m_currentPacket != 0)
+ {
+ m_queue->PushFront (m_currentPacket, m_currentHdr);
+ m_currentPacket = 0;
+ }
+}
+void
+DcaTxop::NotifyWakeUp (void)
+{
+ NS_LOG_FUNCTION (this);
+ RestartAccessIfNeeded ();
+}
void
DcaTxop::GotCts (double snr, WifiMode txMode)
--- a/src/wifi/model/dca-txop.h Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/dca-txop.h Mon Jan 26 15:17:35 2015 -0800
@@ -194,6 +194,15 @@
* When a channel switching occurs, enqueued packets are removed.
*/
void NotifyChannelSwitching (void);
+ /**
+ * When sleep operation occurs, if there is a pending packet transmission,
+ * it will be reinserted to the front of the queue.
+ */
+ void NotifySleep (void);
+ /**
+ * When wake up operation occurs, channel access will be restarted
+ */
+ void NotifyWakeUp (void);
/* Event handlers */
/**
--- a/src/wifi/model/dcf-manager.cc Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/dcf-manager.cc Mon Jan 26 15:17:35 2015 -0800
@@ -161,6 +161,16 @@
{
DoNotifyChannelSwitching ();
}
+void
+DcfState::NotifySleep (void)
+{
+ DoNotifySleep ();
+}
+void
+DcfState::NotifyWakeUp (void)
+{
+ DoNotifyWakeUp ();
+}
/**
@@ -311,6 +321,19 @@
m_phyListener = new PhyListener (this);
phy->RegisterListener (m_phyListener);
}
+
+void
+DcfManager::RemovePhyListener (Ptr<WifiPhy> phy)
+{
+ NS_LOG_FUNCTION (this << phy);
+ if (m_phyListener != 0)
+ {
+ phy->UnregisterListener (m_phyListener);
+ delete m_phyListener;
+ m_phyListener = 0;
+ }
+}
+
void
DcfManager::SetupLowListener (Ptr<MacLow> low)
{
@@ -765,6 +788,13 @@
{
m_accessTimeout.Cancel ();
}
+
+ // Reset backoffs
+ for (States::iterator i = m_states.begin (); i != m_states.end (); i++)
+ {
+ DcfState *state = *i;
+ state->NotifySleep ();
+ }
}
void
@@ -772,7 +802,6 @@
{
NS_LOG_FUNCTION (this);
m_sleeping = false;
- // Reset backoffs
for (States::iterator i = m_states.begin (); i != m_states.end (); i++)
{
DcfState *state = *i;
@@ -784,6 +813,7 @@
}
state->ResetCw ();
state->m_accessRequested = false;
+ state->NotifyWakeUp ();
}
}
--- a/src/wifi/model/dcf-manager.h Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/dcf-manager.h Mon Jan 26 15:17:35 2015 -0800
@@ -160,6 +160,14 @@
* Notify that the device is switching channel.
*/
void NotifyChannelSwitching (void);
+ /**
+ * Notify that the device has started to sleep.
+ */
+ void NotifySleep (void);
+ /**
+ * Notify that the device has started to wake up
+ */
+ void NotifyWakeUp (void);
/**
@@ -194,10 +202,25 @@
* Called by DcfManager to notify a DcfState subclass
* that a channel switching occured.
*
- * The subclass is expected to flush the queue of
- * packets.
+ * The subclass is expected to flush the queue of packets.
+ */
+ virtual void DoNotifyChannelSwitching (void) = 0;
+ /**
+ * Called by DcfManager to notify a DcfState subclass that the device has
+ * begun to sleep.
+ *
+ * The subclass is expected to re-insert the pending packet into the queue
*/
- virtual void DoNotifyChannelSwitching () = 0;
+ virtual void DoNotifySleep (void) = 0;
+ /**
+ * Called by DcfManager to notify a DcfState subclass that the device
+ * has begun to wake up.
+ *
+ * The subclass is expected to restart a new backoff by
+ * calling DcfState::StartBackoffNow and DcfManager::RequestAccess
+ * is access is still needed.
+ */
+ virtual void DoNotifyWakeUp (void) = 0;
uint32_t m_aifsn;
uint32_t m_backoffSlots;
@@ -239,6 +262,12 @@
*/
void SetupPhyListener (Ptr<WifiPhy> phy);
/**
+ * Remove current registered listener for Phy events.
+ *
+ * \param phy
+ */
+ void RemovePhyListener (Ptr<WifiPhy> phy);
+ /**
* Set up listener for MacLow events.
*
* \param low
--- a/src/wifi/model/edca-txop-n.cc Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/edca-txop-n.cc Mon Jan 26 15:17:35 2015 -0800
@@ -66,6 +66,14 @@
{
m_txop->NotifyChannelSwitching ();
}
+ virtual void DoNotifySleep (void)
+ {
+ m_txop->NotifySleep ();
+ }
+ virtual void DoNotifyWakeUp (void)
+ {
+ m_txop->NotifyWakeUp ();
+ }
EdcaTxopN *m_txop;
};
@@ -554,6 +562,22 @@
m_queue->Flush ();
m_currentPacket = 0;
}
+void
+EdcaTxopN::NotifySleep (void)
+{
+ NS_LOG_FUNCTION (this);
+ if (m_currentPacket != 0)
+ {
+ m_queue->PushFront (m_currentPacket, m_currentHdr);
+ m_currentPacket = 0;
+ }
+}
+void
+EdcaTxopN::NotifyWakeUp (void)
+{
+ NS_LOG_FUNCTION (this);
+ RestartAccessIfNeeded ();
+}
void
EdcaTxopN::Queue (Ptr<const Packet> packet, const WifiMacHeader &hdr)
--- a/src/wifi/model/edca-txop-n.h Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/edca-txop-n.h Mon Jan 26 15:17:35 2015 -0800
@@ -187,6 +187,14 @@
* When a channel switching occurs, enqueued packets are removed.
*/
void NotifyChannelSwitching (void);
+ /**
+ * When sleep operation occurs, re-insert pending packet into front of the queue
+ */
+ void NotifySleep (void);
+ /**
+ * When wake up operation occurs, restart channel access
+ */
+ void NotifyWakeUp (void);
/* Event handlers */
/**
--- a/src/wifi/model/mac-low.cc Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/mac-low.cc Mon Jan 26 15:17:35 2015 -0800
@@ -327,6 +327,16 @@
phy->RegisterListener (m_phyMacLowListener);
}
+void
+MacLow::RemovePhyMacLowListener (Ptr<WifiPhy> phy)
+{
+ if (m_phyMacLowListener != 0 )
+ {
+ phy->UnregisterListener (m_phyMacLowListener);
+ delete m_phyMacLowListener;
+ m_phyMacLowListener = 0;
+ }
+}
void
MacLow::DoDispose (void)
@@ -433,6 +443,19 @@
m_phy->SetReceiveErrorCallback (MakeCallback (&MacLow::ReceiveError, this));
SetupPhyMacLowListener (phy);
}
+Ptr<WifiPhy>
+MacLow::GetPhy (void) const
+{
+ return m_phy;
+}
+void
+MacLow::ResetPhy (void)
+{
+ m_phy->SetReceiveOkCallback (MakeNullCallback<void,Ptr<Packet>, double, WifiMode, enum WifiPreamble> ());
+ m_phy->SetReceiveErrorCallback (MakeNullCallback<void,Ptr<const Packet>, double> ());
+ RemovePhyMacLowListener (m_phy);
+ m_phy = 0;
+}
void
MacLow::SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> manager)
{
@@ -663,7 +686,6 @@
MacLow::NotifySleepNow (void)
{
NS_LOG_DEBUG ("Device in sleep mode. Cancelling MAC pending events");
- m_stationManager->Reset ();
CancelAllEvents ();
if (m_navCounterResetCtsMissed.IsRunning ())
{
--- a/src/wifi/model/mac-low.h Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/mac-low.h Mon Jan 26 15:17:35 2015 -0800
@@ -425,6 +425,16 @@
* \param phy WifiPhy associated with this MacLow
*/
void SetPhy (Ptr<WifiPhy> phy);
+ /*
+ * \return current attached PHY device
+ */
+ Ptr<WifiPhy> GetPhy (void) const;
+ /**
+ * Remove WifiPhy associated with this MacLow.
+ *
+ * \param phy WifiPhy associated with this MacLow
+ */
+ void ResetPhy (void);
/**
* Set up WifiRemoteStationManager associated with this MacLow.
*
@@ -611,7 +621,7 @@
* Start the transmission of the input packet and notify the listener
* of transmission events.
*/
- void StartTransmission (Ptr<const Packet> packet,
+ virtual void StartTransmission (Ptr<const Packet> packet,
const WifiMacHeader* hdr,
MacLowTransmissionParameters parameters,
MacLowTransmissionListener *listener);
@@ -1072,6 +1082,12 @@
* \param phy the WifiPhy this MacLow is connected to
*/
void SetupPhyMacLowListener (Ptr<WifiPhy> phy);
+ /**
+ * Remove current WifiPhy listener for this MacLow.
+ *
+ * \param phy the WifiPhy this MacLow is connected to
+ */
+ void RemovePhyMacLowListener (Ptr<WifiPhy> phy);
Ptr<WifiPhy> m_phy; //!< Pointer to WifiPhy (actually send/receives frames)
Ptr<WifiRemoteStationManager> m_stationManager; //!< Pointer to WifiRemoteStationManager (rate control)
--- a/src/wifi/model/regular-wifi-mac.cc Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/regular-wifi-mac.cc Mon Jan 26 15:17:35 2015 -0800
@@ -208,12 +208,22 @@
}
Ptr<WifiPhy>
-RegularWifiMac::GetWifiPhy () const
+RegularWifiMac::GetWifiPhy (void) const
{
+ NS_LOG_FUNCTION (this);
return m_phy;
}
void
+RegularWifiMac::ResetWifiPhy (void)
+{
+ NS_LOG_FUNCTION (this);
+ m_low->ResetPhy ();
+ m_dcfManager->RemovePhyListener (m_phy);
+ m_phy = 0;
+}
+
+void
RegularWifiMac::SetForwardUpCallback (ForwardUpCallback upCallback)
{
NS_LOG_FUNCTION (this);
--- a/src/wifi/model/regular-wifi-mac.h Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/regular-wifi-mac.h Mon Jan 26 15:17:35 2015 -0800
@@ -189,7 +189,11 @@
/**
* \return the physical layer attached to this MAC.
*/
- virtual Ptr<WifiPhy> GetWifiPhy () const;
+ virtual Ptr<WifiPhy> GetWifiPhy (void) const;
+ /**
+ * removes attached WifiPhy device from this MAC.
+ */
+ virtual void ResetWifiPhy (void);
/**
* \param stationManager the station manager attached to this MAC.
*/
@@ -197,7 +201,7 @@
/**
* \return the station manager attached to this MAC.
*/
- virtual Ptr<WifiRemoteStationManager> GetWifiRemoteStationManager () const;
+ virtual Ptr<WifiRemoteStationManager> GetWifiRemoteStationManager (void) const;
/**
* This type defines the callback of a higher layer that a
--- a/src/wifi/model/wifi-mac.h Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/wifi-mac.h Mon Jan 26 15:17:35 2015 -0800
@@ -190,10 +190,23 @@
*/
virtual void SetWifiPhy (Ptr<WifiPhy> phy) = 0;
/**
+ * return current attached WifiPhy device
+ */
+ virtual Ptr<WifiPhy> GetWifiPhy (void) const = 0;
+ /**
+ * remove current attached WifiPhy device from this MAC.
+ */
+ virtual void ResetWifiPhy (void) = 0;
+ /**
* \param stationManager the station manager attached to this MAC.
*/
virtual void SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> stationManager) = 0;
/**
+ * \return the station manager attached to this MAC.
+ */
+ virtual Ptr<WifiRemoteStationManager> GetWifiRemoteStationManager (void) const = 0;
+
+ /**
* \param upCallback the callback to invoke when a packet must be forwarded up the stack.
*/
virtual void SetForwardUpCallback (Callback<void,Ptr<Packet>, Mac48Address, Mac48Address> upCallback) = 0;
--- a/src/wifi/model/wifi-phy-state-helper.cc Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/wifi-phy-state-helper.cc Mon Jan 26 15:17:35 2015 -0800
@@ -21,6 +21,7 @@
#include "ns3/log.h"
#include "ns3/simulator.h"
#include "ns3/trace-source-accessor.h"
+#include <algorithm>
namespace ns3 {
@@ -85,6 +86,15 @@
{
m_listeners.push_back (listener);
}
+void
+WifiPhyStateHelper::UnregisterListener (WifiPhyListener *listener)
+{
+ ListenersI i = find (m_listeners.begin(), m_listeners.end(), listener);
+ if (i != m_listeners.end())
+ {
+ m_listeners.erase(i);
+ }
+}
bool
WifiPhyStateHelper::IsStateIdle (void)
--- a/src/wifi/model/wifi-phy-state-helper.h Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/wifi-phy-state-helper.h Mon Jan 26 15:17:35 2015 -0800
@@ -58,6 +58,12 @@
*/
void RegisterListener (WifiPhyListener *listener);
/**
+ * Remove WifiPhyListener from this WifiPhyStateHelper.
+ *
+ * \param listener
+ */
+ void UnregisterListener (WifiPhyListener *listener);
+ /**
* Return the current state of WifiPhy.
*
* \return the current state of WifiPhy
@@ -232,6 +238,7 @@
* typedef for a list of WifiPhyListeners
*/
typedef std::vector<WifiPhyListener *> Listeners;
+ typedef std::vector<WifiPhyListener *>::iterator ListenersI;
/**
* Log the ideal and CCA states.
--- a/src/wifi/model/wifi-phy.h Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/wifi-phy.h Mon Jan 26 15:17:35 2015 -0800
@@ -219,6 +219,13 @@
* PHY-level events.
*/
virtual void RegisterListener (WifiPhyListener *listener) = 0;
+ /**
+ * \param listener the listener to be unregistered
+ *
+ * Remove the input listener from the list of objects to be notified of
+ * PHY-level events.
+ */
+ virtual void UnregisterListener (WifiPhyListener *listener) = 0;
/**
* Put in sleep mode.
@@ -494,7 +501,11 @@
*
* \return the current channel number
*/
- virtual uint16_t GetChannelNumber () const = 0;
+ virtual uint16_t GetChannelNumber (void) const = 0;
+ /**
+ * \return the required time for channel switch operation of this WifiPhy
+ */
+ virtual Time GetChannelSwitchDelay (void) const = 0;
/**
* Configure the PHY-level parameters for different Wi-Fi standard.
--- a/src/wifi/model/wifi-remote-station-manager.cc Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/wifi-remote-station-manager.cc Mon Jan 26 15:17:35 2015 -0800
@@ -447,6 +447,18 @@
}
state->m_operationalRateSet.push_back (mode);
}
+void
+WifiRemoteStationManager::AddAllSupportedModes (Mac48Address address)
+{
+ NS_ASSERT (!address.IsGroup ());
+ WifiRemoteStationState *state = LookupState (address);
+ state->m_operationalRateSet.clear ();
+ for (uint32_t i = 0; i < m_wifiPhy->GetNModes (); i++)
+ {
+ state->m_operationalRateSet.push_back ( m_wifiPhy->GetMode (i));
+ }
+}
+
/*void
WifiRemoteStationManager::AddBssMembershipParameters(Mac48Address address, uint32_t selector)
{
--- a/src/wifi/model/wifi-remote-station-manager.h Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/wifi-remote-station-manager.h Mon Jan 26 15:17:35 2015 -0800
@@ -276,6 +276,14 @@
* \param mode the WifiMode supports by the station
*/
void AddSupportedMode (Mac48Address address, WifiMode mode);
+ /**
+ * Invoked in a STA or AP to store all of the modes supported
+ * by a destination which is also supported locally.
+ * The set of supported modes includes the BSSBasicRateSet.
+ *
+ * \param address the address of the station being recorded
+ */
+ void AddAllSupportedModes (Mac48Address address);
//void AddBssMembershipParameters(Mac48Address address, uint32_t selector);
/**
--- a/src/wifi/model/yans-wifi-phy.cc Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/yans-wifi-phy.cc Mon Jan 26 15:17:35 2015 -0800
@@ -423,11 +423,17 @@
}
uint16_t
-YansWifiPhy::GetChannelNumber () const
+YansWifiPhy::GetChannelNumber (void) const
{
return m_channelNumber;
}
+Time
+YansWifiPhy::GetChannelSwitchDelay (void) const
+{
+ return m_channelSwitchDelay;
+}
+
double
YansWifiPhy::GetChannelFrequencyMhz () const
{
@@ -792,6 +798,12 @@
m_state->RegisterListener (listener);
}
+void
+YansWifiPhy::UnregisterListener (WifiPhyListener *listener)
+{
+ m_state->UnregisterListener (listener);
+}
+
bool
YansWifiPhy::IsStateCcaBusy (void)
{
--- a/src/wifi/model/yans-wifi-phy.h Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/model/yans-wifi-phy.h Mon Jan 26 15:17:35 2015 -0800
@@ -87,7 +87,11 @@
*
* \return the current channel number
*/
- uint16_t GetChannelNumber () const;
+ uint16_t GetChannelNumber (void) const;
+ /**
+ * \return the required time for channel switch operation of this WifiPhy
+ */
+ Time GetChannelSwitchDelay (void) const;
/**
* Return current center channel frequency in MHz.
*
@@ -249,6 +253,7 @@
virtual void SetReceiveErrorCallback (WifiPhy::RxErrorCallback callback);
virtual void SendPacket (Ptr<const Packet> packet, WifiTxVector txvector, enum WifiPreamble preamble);
virtual void RegisterListener (WifiPhyListener *listener);
+ virtual void UnregisterListener (WifiPhyListener *listener);
virtual void SetSleepMode (void);
virtual void ResumeFromSleep (void);
virtual bool IsStateCcaBusy (void);
--- a/src/wifi/test/dcf-manager-test.cc Mon Jan 26 23:21:27 2015 +0100
+++ b/src/wifi/test/dcf-manager-test.cc Mon Jan 26 15:17:35 2015 -0800
@@ -37,6 +37,8 @@
virtual void DoNotifyInternalCollision (void);
virtual void DoNotifyCollision (void);
virtual void DoNotifyChannelSwitching (void);
+ virtual void DoNotifySleep (void);
+ virtual void DoNotifyWakeUp (void);
typedef std::pair<uint64_t,uint64_t> ExpectedGrant;
typedef std::list<ExpectedGrant> ExpectedGrants;
@@ -136,7 +138,16 @@
{
m_test->NotifyChannelSwitching (m_i);
}
+void
+DcfStateTest::DoNotifySleep (void)
+{
+}
+void
+DcfStateTest::DoNotifyWakeUp (void)
+{
+
+}
DcfManagerTest::DcfManagerTest ()
: TestCase ("DcfManager")