# HG changeset patch # User Mathieu Lacage # Date 1194531786 -3600 # Node ID f6d8dea92b39c693fb24d38167fe04adfab5c95c # Parent a651a0131bfed2d0ed87edcbd407e785d596270f implement AP beaconing diff -r a651a0131bfe -r f6d8dea92b39 samples/main-ap-wifi.cc --- a/samples/main-ap-wifi.cc Thu Nov 08 15:22:22 2007 +0100 +++ b/samples/main-ap-wifi.cc Thu Nov 08 15:23:06 2007 +0100 @@ -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 @@ 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 @@ 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 @@ 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 -r a651a0131bfe -r f6d8dea92b39 src/devices/wifi/mac-high-nqap.cc --- a/src/devices/wifi/mac-high-nqap.cc Thu Nov 08 15:22:22 2007 +0100 +++ b/src/devices/wifi/mac-high-nqap.cc Thu Nov 08 15:23:06 2007 +0100 @@ -52,6 +52,13 @@ 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 @@ { m_beaconInterval = interval; } +void +MacHighNqap::StartBeaconing (void) +{ + SendOneBeacon (); +} void MacHighNqap::ForwardDown (Packet packet, Mac48Address from, Mac48Address to) { @@ -160,6 +172,27 @@ 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 -r a651a0131bfe -r f6d8dea92b39 src/devices/wifi/mac-high-nqap.h --- a/src/devices/wifi/mac-high-nqap.h Thu Nov 08 15:22:22 2007 +0100 +++ b/src/devices/wifi/mac-high-nqap.h Thu Nov 08 15:23:06 2007 +0100 @@ -43,6 +43,7 @@ ~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 @@ 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 @@ 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 -r a651a0131bfe -r f6d8dea92b39 src/devices/wifi/wifi-net-device.cc --- a/src/devices/wifi/wifi-net-device.cc Thu Nov 08 15:22:22 2007 +0100 +++ b/src/devices/wifi/wifi-net-device.cc Thu Nov 08 15:23:06 2007 +0100 @@ -448,6 +448,16 @@ 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 @@ 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 @@ { m_ssid = ssid; } +void +NqapWifiNetDevice::StartBeaconing (void) +{ + m_high->StartBeaconing (); +} bool NqapWifiNetDevice::DoSendTo (const Packet &packet, Mac48Address const & to) { @@ -506,9 +522,11 @@ WifiNetDevice::DoDispose (); // local cleanup delete m_dca; + delete m_beaconDca; delete m_high; m_dca = 0; m_high = 0; + m_beaconDca = 0; } diff -r a651a0131bfe -r f6d8dea92b39 src/devices/wifi/wifi-net-device.h --- a/src/devices/wifi/wifi-net-device.h Thu Nov 08 15:22:22 2007 +0100 +++ b/src/devices/wifi/wifi-net-device.h Thu Nov 08 15:23:06 2007 +0100 @@ -217,6 +217,7 @@ 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 @@ friend class WifiNetDeviceFactory; Ssid m_ssid; DcaTxop *m_dca; + DcaTxop *m_beaconDca; MacHighNqap *m_high; };