From dc3fb38cbb7718c969bc3165507cde705c689e59 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 18 Oct 2007 13:37:22 +0200 Subject: [PATCH] support BRAND_NEW station in adhoc code. initialize the supported rates. --- src/devices/wifi/mac-high-adhoc.cc | 24 ++++++++++++++++++++++++ src/devices/wifi/mac-high-adhoc.h | 6 ++++++ src/devices/wifi/mac-stations.cc | 12 ++++++++++-- src/devices/wifi/mac-stations.h | 2 ++ src/devices/wifi/wifi-net-device.cc | 6 ++++-- 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/devices/wifi/mac-high-adhoc.cc b/src/devices/wifi/mac-high-adhoc.cc index 44e6e3ad6..7f5d983d2 100644 --- a/src/devices/wifi/mac-high-adhoc.cc +++ b/src/devices/wifi/mac-high-adhoc.cc @@ -21,6 +21,8 @@ #include "mac-high-adhoc.h" #include "dca-txop.h" #include "wifi-net-device.h" +#include "mac-stations.h" +#include "wifi-phy.h" #include "ns3/packet.h" #include "ns3/log.h" @@ -49,6 +51,16 @@ MacHighAdhoc::SetDcaTxop (DcaTxop *dca) { m_dca = dca; } +void +MacHighAdhoc::SetStations (MacStations *stations) +{ + m_stations = stations; +} +void +MacHighAdhoc::SetPhy (WifiPhy *phy) +{ + m_phy = phy; +} Mac48Address MacHighAdhoc::GetBssid (void) const @@ -69,6 +81,18 @@ MacHighAdhoc::Enqueue (Packet packet, Mac48Address to) hdr.SetAddr3 (m_device->GetBssid ()); hdr.SetDsNotFrom (); hdr.SetDsNotTo (); + + MacStation *destination = m_stations->Lookup (to); + if (destination->IsBrandNew ()) + { + // in adhoc mode, we assume that every destination + // supports all the rates we support. + for (uint32_t i = 0; i < m_phy->GetNModes (); i++) + { + destination->AddSupportedMode (m_phy->GetMode (0)); + } + } + m_dca->Queue (packet, hdr); } diff --git a/src/devices/wifi/mac-high-adhoc.h b/src/devices/wifi/mac-high-adhoc.h index b6a412198..7c84368e3 100644 --- a/src/devices/wifi/mac-high-adhoc.h +++ b/src/devices/wifi/mac-high-adhoc.h @@ -30,6 +30,8 @@ class DcaTxop; class Packet; class WifiNetDevice; class WifiMacHeader; +class MacStations; +class WifiPhy; class MacHighAdhoc { public: @@ -41,6 +43,8 @@ public: void SetDevice (WifiNetDevice *device); void SetForwardCallback (ForwardCallback callback); void SetDcaTxop (DcaTxop *dca); + void SetStations (MacStations *stations); + void SetPhy (WifiPhy *phy); Mac48Address GetBssid (void) const; @@ -52,6 +56,8 @@ private: DcaTxop *m_dca; WifiNetDevice *m_device; ForwardCallback m_callback; + MacStations *m_stations; + WifiPhy *m_phy; }; } // namespace ns3 diff --git a/src/devices/wifi/mac-stations.cc b/src/devices/wifi/mac-stations.cc index a56230e50..b690d09eb 100644 --- a/src/devices/wifi/mac-stations.cc +++ b/src/devices/wifi/mac-stations.cc @@ -51,7 +51,9 @@ private: NonUnicastMacStation::NonUnicastMacStation (MacStations *stations) : m_stations (stations) -{} +{ + RecordDisassociated (); +} void NonUnicastMacStation::ReportRxOk (double rxSnr, WifiMode txMode) { @@ -184,11 +186,17 @@ MacStations::EndBasicModes (void) const namespace ns3 { MacStation::MacStation () - : m_state (DISASSOC) + : m_state (BRAND_NEW) {} MacStation::~MacStation () {} +bool +MacStation::IsBrandNew (void) const +{ + return m_state == BRAND_NEW; +} + bool MacStation::IsAssociated (void) const { diff --git a/src/devices/wifi/mac-stations.h b/src/devices/wifi/mac-stations.h index 793507121..f7eaed43a 100644 --- a/src/devices/wifi/mac-stations.h +++ b/src/devices/wifi/mac-stations.h @@ -86,6 +86,7 @@ public: // the BSSBasicRateSet. void AddSupportedMode (WifiMode mode); + bool IsBrandNew (void) const; bool IsAssociated (void) const; bool IsWaitAssocTxOk (void) const; void RecordWaitAssocTxOk (void); @@ -117,6 +118,7 @@ private: bool IsIn (WifiMode mode) const; WifiMode GetControlAnswerMode (WifiMode reqMode); enum { + BRAND_NEW, DISASSOC, WAIT_ASSOC_TX_OK, GOT_ASSOC_TX_OK diff --git a/src/devices/wifi/wifi-net-device.cc b/src/devices/wifi/wifi-net-device.cc index 5cce59ab1..83134ce9d 100644 --- a/src/devices/wifi/wifi-net-device.cc +++ b/src/devices/wifi/wifi-net-device.cc @@ -158,7 +158,6 @@ WifiNetDevice::CreateDca (uint32_t minCw, uint32_t maxCw) const return dca; } - void WifiNetDevice::ConnectTo (Ptr channel) { @@ -246,6 +245,8 @@ AdhocWifiNetDevice::AdhocWifiNetDevice (Ptr node) high->SetDcaTxop (m_dca); high->SetForwardCallback (MakeCallback (&AdhocWifiNetDevice::DoForwardUp, static_cast (this))); + high->SetPhy (m_phy); + high->SetStations (m_stations); m_rxMiddle->SetForwardCallback (MakeCallback (&MacHighAdhoc::Receive, high)); m_high = high; } @@ -390,7 +391,8 @@ NqapWifiNetDevice::NqapWifiNetDevice (Ptr node) SupportedRates rates; for (uint32_t i = 0; i < m_phy->GetNModes (); i++) { - rates.AddSupportedRate (m_phy->GetMode (i).GetPhyRate ()); + WifiMode mode = m_phy->GetMode (i); + rates.AddSupportedRate (mode.GetPhyRate ()); } MacHighNqap *high = new MacHighNqap ();