implement AP beaconing
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 08 Nov 2007 15:23:06 +0100
changeset 2089 f6d8dea92b39
parent 2088 a651a0131bfe
child 2090 3622fda1717b
implement AP beaconing
samples/main-ap-wifi.cc
src/devices/wifi/mac-high-nqap.cc
src/devices/wifi/mac-high-nqap.h
src/devices/wifi/wifi-net-device.cc
src/devices/wifi/wifi-net-device.h
--- 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<WifiChannel> channel,
               Position position, 
               const char *ipAddress,
-              Ssid ssid)
+              Ssid ssid, 
+              Time at)
 {
   Ptr<Node> node = Create<InternetNode> ();  
   Ptr<NqapWifiNetDevice> device = Create<NqapWifiNetDevice> (node);
   device->SetSsid (ssid);
+  Simulator::Schedule (at, &NqapWifiNetDevice::StartBeaconing, device);
   device->ConnectTo (channel);
   Ptr<MobilityModel> mobility = Create<StaticMobilityModel> ();
   mobility->Set (position);
@@ -164,7 +166,8 @@
   Ptr<Node> 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<Node> 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 ();
 
--- 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="<<Mac48Address::GetBroadcast ());
+  WifiMacHeader hdr;
+  hdr.SetBeacon ();
+  hdr.SetAddr1 (Mac48Address::GetBroadcast ());
+  hdr.SetAddr2 (m_device->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)
 {
--- 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<WifiPhy> 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<WifiPhy> m_phy;
--- 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;
 }
 
 
--- 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;
 };