--- a/src/wifi/helper/wifi-helper.cc Sun Sep 08 09:57:13 2013 -0700 +++ a/src/wifi/helper/wifi-helper.cc Wed Sep 11 05:37:26 2013 -0700 @@ -26,6 +26,7 @@ #include "ns3/dca-txop.h" #include "ns3/edca-txop-n.h" #include "ns3/minstrel-wifi-manager.h" +#include "ns3/ap-wifi-mac.h" #include "ns3/wifi-phy.h" #include "ns3/wifi-remote-station-manager.h" #include "ns3/wifi-channel.h" @@ -215,6 +216,13 @@ rmac->GetAttribute ("BK_EdcaTxopN", ptr); Ptr bk_edcaTxopN = ptr.Get (); currentStream += bk_edcaTxopN->AssignStreams (currentStream); + + // if an AP, handle any beacon jitter + Ptr apmac = DynamicCast (rmac); + if (apmac) + { + currentStream += apmac->AssignStreams (currentStream); + } } } } --- a/src/wifi/model/ap-wifi-mac.cc Sun Sep 08 09:57:13 2013 -0700 +++ a/src/wifi/model/ap-wifi-mac.cc Wed Sep 11 05:37:26 2013 -0700 @@ -55,6 +55,14 @@ MakeTimeAccessor (&ApWifiMac::GetBeaconInterval, &ApWifiMac::SetBeaconInterval), MakeTimeChecker ()) + .AddAttribute ("BeaconJitter", "A uniform random variable to cause the initial beacon starting time (after simulation time 0) to be distributed between 0 and the BeaconInterval.", + StringValue ("ns3::UniformRandomVariable"), + MakePointerAccessor (&ApWifiMac::m_beaconJitter), + MakePointerChecker ()) + .AddAttribute ("EnableBeaconJitter", "If beacons are enabled, whether to jitter the initial send event.", + BooleanValue (false), + MakeBooleanAccessor (&ApWifiMac::m_enableBeaconJitter), + MakeBooleanChecker ()) .AddAttribute ("BeaconGeneration", "Whether or not beacons are generated.", BooleanValue (true), MakeBooleanAccessor (&ApWifiMac::SetBeaconGeneration, @@ -172,6 +180,14 @@ SendOneBeacon (); } +int64_t +ApWifiMac::AssignStreams (int64_t stream) +{ + NS_LOG_FUNCTION (this << stream); + m_beaconJitter->SetStream (stream); + return 1; +} + void ApWifiMac::ForwardDown (Ptr packet, Mac48Address from, Mac48Address to) @@ -648,7 +664,17 @@ m_beaconEvent.Cancel (); if (m_enableBeaconGeneration) { - m_beaconEvent = Simulator::ScheduleNow (&ApWifiMac::SendOneBeacon, this); + if (m_enableBeaconJitter) + { + int64_t jitter = m_beaconJitter->GetValue (0, m_beaconInterval.GetMicroSeconds ()); + NS_LOG_DEBUG ("Scheduling initial beacon for access point " << GetAddress() << " at time " << jitter << " microseconds"); + m_beaconEvent = Simulator::Schedule (MicroSeconds (jitter), &ApWifiMac::SendOneBeacon, this); + } + else + { + NS_LOG_DEBUG ("Scheduling initial beacon for access point " << GetAddress() << " at time 0"); + m_beaconEvent = Simulator::ScheduleNow (&ApWifiMac::SendOneBeacon, this); + } } RegularWifiMac::DoInitialize (); } --- a/src/wifi/model/ap-wifi-mac.h Sun Sep 08 09:57:13 2013 -0700 +++ a/src/wifi/model/ap-wifi-mac.h Wed Sep 11 05:37:26 2013 -0700 @@ -26,6 +26,7 @@ #include "ht-capabilities.h" #include "amsdu-subframe-header.h" #include "supported-rates.h" +#include "ns3/random-variable-stream.h" namespace ns3 { @@ -95,6 +96,16 @@ */ void StartBeaconing (void); + /** + * Assign a fixed random variable stream number to the random variables + * used by this model. Return the number of streams (possibly zero) that + * have been assigned. + * + * \param stream first stream index to use + * \return the number of stream indices assigned by this model + */ + int64_t AssignStreams (int64_t stream); + private: virtual void Receive (Ptr packet, const WifiMacHeader *hdr); virtual void TxOk (const WifiMacHeader &hdr); @@ -128,6 +139,8 @@ Time m_beaconInterval; bool m_enableBeaconGeneration; EventId m_beaconEvent; + Ptr m_beaconJitter; + bool m_enableBeaconJitter; }; } // namespace ns3 --- a/src/wifi/test/wifi-test.cc Sun Sep 08 09:57:13 2013 -0700 +++ a/src/wifi/test/wifi-test.cc Wed Sep 11 05:37:26 2013 -0700 @@ -39,6 +39,8 @@ #include "ns3/pointer.h" #include "ns3/rng-seed-manager.h" #include "ns3/edca-txop-n.h" +#include "ns3/config.h" +#include "ns3/boolean.h" namespace ns3 { @@ -416,6 +418,10 @@ RngSeedManager::SetSeed (1); RngSeedManager::SetRun (17); + // Disable the initial jitter of AP beacons (test case was written before + // beacon jitter was added) + Config::SetDefault ("ns3::ApWifiMac::EnableBeaconJitter", BooleanValue (false)); + Ptr channel = CreateObject (); Ptr propDelay = m_propDelay.Create (); Ptr propLoss = CreateObject ();