diff --git a/samples/main-ap-wifi.cc b/samples/main-ap-wifi.cc index c341c71cd..26266b94f 100644 --- a/samples/main-ap-wifi.cc +++ b/samples/main-ap-wifi.cc @@ -41,12 +41,12 @@ using namespace ns3; -static void +void WifiNetDeviceTrace (const TraceContext &context, Packet p, Mac48Address address) { std::cout << context << " ad=" << address << " p: " << p << std::endl; } -static void +void WifiPhyStateTrace (const TraceContext &context, Time start, Time duration, enum WifiPhy::State state) { std::cout << context << " state="; @@ -71,11 +71,13 @@ static Ptr CreateApNode (Ptr channel, Position position, const char *ipAddress, - Ssid ssid) + Ssid ssid, + Time at) { Ptr node = Create (); Ptr device = Create (node); device->SetSsid (ssid); + Simulator::Schedule (at, &NqapWifiNetDevice::StartBeaconing, device); device->ConnectTo (channel); Ptr mobility = Create (); mobility->Set (position); @@ -164,7 +166,8 @@ int main (int argc, char *argv[]) Ptr a = CreateApNode (channel, Position (5.0,0.0,0.0), "192.168.0.1", - ssid); + ssid, + Seconds (0.1)); Simulator::Schedule (Seconds (1.0), &AdvancePosition, a); Ptr b = CreateStaNode (channel, @@ -186,8 +189,8 @@ int main (int argc, char *argv[]) GlobalRouteManager::PopulateRoutingTables (); - NodeList::Connect ("/nodes/*/devices/*/*", MakeCallback (&WifiNetDeviceTrace)); - NodeList::Connect ("/nodes/*/devices/*/phy/state", MakeCallback (&WifiPhyStateTrace)); + //NodeList::Connect ("/nodes/*/devices/*/*", MakeCallback (&WifiNetDeviceTrace)); + //NodeList::Connect ("/nodes/*/devices/*/phy/state", MakeCallback (&WifiPhyStateTrace)); Simulator::Run (); diff --git a/src/devices/wifi/mac-high-nqap.cc b/src/devices/wifi/mac-high-nqap.cc index a791ae22b..34cc19b83 100644 --- a/src/devices/wifi/mac-high-nqap.cc +++ b/src/devices/wifi/mac-high-nqap.cc @@ -52,6 +52,13 @@ MacHighNqap::SetDcaTxop (DcaTxop *dca) m_dca->SetTxFailedCallback (MakeCallback (&MacHighNqap::TxFailed, this)); } void +MacHighNqap::SetBeaconDcaTxop (DcaTxop *dca) +{ + // we do not need to be notified when a beacon has been transmitted + // successfully or not. + m_beaconDca = dca; +} +void MacHighNqap::SetDevice (WifiNetDevice *device) { m_device = device; @@ -76,6 +83,11 @@ MacHighNqap::SetBeaconInterval (Time interval) { m_beaconInterval = interval; } +void +MacHighNqap::StartBeaconing (void) +{ + SendOneBeacon (); +} void MacHighNqap::ForwardDown (Packet packet, Mac48Address from, Mac48Address to) { @@ -160,6 +172,27 @@ MacHighNqap::SendAssocResp (Mac48Address to, bool success) m_dca->Queue (packet, hdr); } +void +MacHighNqap::SendOneBeacon (void) +{ + TRACE ("send probe response to="<GetSelfAddress ()); + hdr.SetAddr3 (m_device->GetSelfAddress ()); + hdr.SetDsNotFrom (); + hdr.SetDsNotTo (); + Packet packet; + MgtBeaconHeader beacon; + beacon.SetSsid (m_device->GetSsid ()); + beacon.SetSupportedRates (GetSupportedRates ()); + beacon.SetBeaconIntervalUs (m_beaconInterval.GetMicroSeconds ()); + packet.AddHeader (beacon); + + m_beaconDca->Queue (packet, hdr); + Simulator::Schedule (m_beaconInterval, &MacHighNqap::SendOneBeacon, this); +} void MacHighNqap::TxOk (WifiMacHeader const &hdr) { diff --git a/src/devices/wifi/mac-high-nqap.h b/src/devices/wifi/mac-high-nqap.h index 570617906..3c9ea96a1 100644 --- a/src/devices/wifi/mac-high-nqap.h +++ b/src/devices/wifi/mac-high-nqap.h @@ -43,6 +43,7 @@ public: ~MacHighNqap (); void SetDcaTxop (DcaTxop *dca); + void SetBeaconDcaTxop (DcaTxop *dca); void SetDevice (WifiNetDevice *device); void SetStations (MacStations *stations); void SetPhy (Ptr phy); @@ -51,6 +52,8 @@ public: void Queue (Packet packet, Mac48Address to); + void StartBeaconing (void); + void Receive (Packet packet, WifiMacHeader const *hdr); private: void ForwardDown (Packet packet, Mac48Address from, Mac48Address to); @@ -58,9 +61,11 @@ private: void TxFailed (WifiMacHeader const &hdr); void SendProbeResp (Mac48Address to); void SendAssocResp (Mac48Address to, bool success); + void SendOneBeacon (void); SupportedRates GetSupportedRates (void) const; DcaTxop *m_dca; + DcaTxop *m_beaconDca; WifiNetDevice *m_device; MacStations *m_stations; Ptr m_phy; diff --git a/src/devices/wifi/wifi-net-device.cc b/src/devices/wifi/wifi-net-device.cc index e66cdcb40..90105687a 100644 --- a/src/devices/wifi/wifi-net-device.cc +++ b/src/devices/wifi/wifi-net-device.cc @@ -448,6 +448,16 @@ NqapWifiNetDevice::NqapWifiNetDevice (Ptr node) m_ssid = WifiDefaultParameters::GetSsid (); m_dca = CreateDca (15, 1023); + m_beaconDca = CreateDca (15, 1023); + /** + * We use a DIFS value for the beacons smaller than the 802.11 default + * value to ensure that the beacon queue will get access to the medium + * even when a lot of data has been queued. This is an 'extension' of + * 802.11 which is a first step towards 802.11e but it is a nice way + * to get timely beacons without a lot of other hacks. + */ + Time beaconDifs = m_parameters->GetSifs () + m_parameters->GetSlotTime (); + m_beaconDca->SetDifs (beaconDifs); // By default, we configure the Basic Rate Set to be the set // of rates we support which are mandatory. @@ -464,6 +474,7 @@ NqapWifiNetDevice::NqapWifiNetDevice (Ptr node) MacHighNqap *high = new MacHighNqap (); high->SetDevice (this); high->SetDcaTxop (m_dca); + high->SetBeaconDcaTxop (m_beaconDca); high->SetStations (m_stations); high->SetPhy (m_phy); high->SetForwardCallback (MakeCallback (&NqapWifiNetDevice::DoForwardUp, @@ -488,6 +499,11 @@ NqapWifiNetDevice::SetSsid (Ssid ssid) { m_ssid = ssid; } +void +NqapWifiNetDevice::StartBeaconing (void) +{ + m_high->StartBeaconing (); +} bool NqapWifiNetDevice::DoSendTo (const Packet &packet, Mac48Address const & to) { @@ -506,9 +522,11 @@ NqapWifiNetDevice::DoDispose (void) WifiNetDevice::DoDispose (); // local cleanup delete m_dca; + delete m_beaconDca; delete m_high; m_dca = 0; m_high = 0; + m_beaconDca = 0; } diff --git a/src/devices/wifi/wifi-net-device.h b/src/devices/wifi/wifi-net-device.h index 53ee3a38c..283c40fb9 100644 --- a/src/devices/wifi/wifi-net-device.h +++ b/src/devices/wifi/wifi-net-device.h @@ -217,6 +217,7 @@ public: virtual Mac48Address GetBssid (void) const; virtual Ssid GetSsid (void) const; void SetSsid (Ssid ssid); + void StartBeaconing (void); protected: virtual void DoDispose (void); private: @@ -225,6 +226,7 @@ private: friend class WifiNetDeviceFactory; Ssid m_ssid; DcaTxop *m_dca; + DcaTxop *m_beaconDca; MacHighNqap *m_high; };