# HG changeset patch # User Mathieu Lacage # Date 1192459673 -7200 # Node ID 041240a915f82a046d87c94bd4e65a646f0549aa # Parent 007214146da7f1ac1975a84d8d3b6b41af0915b9 build and link diff -r 007214146da7 -r 041240a915f8 samples/main-adhoc-wifi.cc --- a/samples/main-adhoc-wifi.cc Mon Oct 15 16:17:15 2007 +0200 +++ b/samples/main-adhoc-wifi.cc Mon Oct 15 16:47:53 2007 +0200 @@ -19,7 +19,6 @@ */ #include "ns3/wifi-net-device.h" -#include "ns3/wifi-net-device-factory.h" #include "ns3/wifi-channel.h" #include "ns3/simulator.h" #include "ns3/callback.h" @@ -38,11 +37,11 @@ using namespace ns3; static Ptr -CreateAdhocNode (Ptr factory, Ptr channel, +CreateAdhocNode (Ptr channel, Position position, const char *address) { Ptr node = Create (); - Ptr device = factory->CreateAdhoc (node); + Ptr device = Create (node); device->ConnectTo (channel); Ptr mobility = Create (); mobility->Set (position); @@ -91,22 +90,21 @@ //Simulator::EnableLogTo ("80211.log"); - Ptr factory = Create (); - // force rts/cts on all the time. - factory->SetMacRtsCtsThreshold (2200); - factory->SetMacFragmentationThreshold (2200); - //factory->SetCr (5, 5); - //factory->SetIdeal (1e-5); - factory->SetAarf (); - //factory->SetArf (); + // enable rts cts all the time. + DefaultValue::Bind ("WifiRtsCtsThreshold", "0"); + // disable fragmentation + DefaultValue::Bind ("WifiFragmentationThreshold", "2200"); + DefaultValue::Bind ("WifiRateControlAlgorithm", "Aarf"); + //DefaultValue::Bind ("WifiRateControlAlgorithm", "Arf"); + Ptr channel = Create (); - Ptr a = CreateAdhocNode (factory, channel, + Ptr a = CreateAdhocNode (channel, Position (5.0,0.0,0.0), "192.168.0.1"); Simulator::Schedule (Seconds (1.0), &AdvancePosition, a); - Ptr b = CreateAdhocNode (factory, channel, + Ptr b = CreateAdhocNode (channel, Position (0.0, 0.0, 0.0), "192.168.0.2"); @@ -117,13 +115,6 @@ app->Start (Seconds (0.5)); app->Stop (Seconds (43.0)); -#if 0 - TraceContainer container = TraceContainer (); - wifiServer->RegisterTraces (&container); - container.SetCallback ("80211-packet-rx", - MakeCallback (&ThroughputPrinter::Receive, printer)); -#endif - Simulator::Run (); Simulator::Destroy (); diff -r 007214146da7 -r 041240a915f8 src/devices/wifi/ideal-mac-stations.cc --- a/src/devices/wifi/ideal-mac-stations.cc Mon Oct 15 16:17:15 2007 +0200 +++ b/src/devices/wifi/ideal-mac-stations.cc Mon Oct 15 16:47:53 2007 +0200 @@ -18,7 +18,7 @@ * Author: Mathieu Lacage */ #include "ideal-mac-stations.h" -#include "wifi-phy.h" +#include "ns3/assert.h" #include #define noIDEAL_DEBUG 1 @@ -61,15 +61,9 @@ } void -IdealMacStations::InitializeThresholds (const WifiPhy *phy, double ber) +IdealMacStations::AddModeSnrThreshold (WifiMode mode, double snr) { - uint8_t nModes = phy->GetNModes (); - for (uint8_t i = 0; i < nModes; i++) - { - WifiMode mode = phy->GetMode (i); - double snr = phy->CalculateSnr (mode, ber); - m_thresholds.push_back (std::make_pair (snr,mode)); - } + m_thresholds.push_back (std::make_pair (snr,mode)); } IdealMacStation::IdealMacStation (IdealMacStations *stations) diff -r 007214146da7 -r 041240a915f8 src/devices/wifi/ideal-mac-stations.h --- a/src/devices/wifi/ideal-mac-stations.h Mon Oct 15 16:17:15 2007 +0200 +++ b/src/devices/wifi/ideal-mac-stations.h Mon Oct 15 16:47:53 2007 +0200 @@ -27,8 +27,6 @@ namespace ns3 { -class WifiPhy; - class IdealMacStations : public MacStations { public: IdealMacStations (WifiMode defaultTxMode); @@ -37,7 +35,7 @@ // return the min snr needed to successfully transmit // data with this mode at the specified ber. double GetSnrThreshold (WifiMode mode) const; - void InitializeThresholds (const WifiPhy *phy, double ber); + void AddModeSnrThreshold (WifiMode mode, double ber); private: virtual class MacStation *CreateStation (void); diff -r 007214146da7 -r 041240a915f8 src/devices/wifi/mac-high-adhoc.cc --- a/src/devices/wifi/mac-high-adhoc.cc Mon Oct 15 16:17:15 2007 +0200 +++ b/src/devices/wifi/mac-high-adhoc.cc Mon Oct 15 16:47:53 2007 +0200 @@ -41,9 +41,9 @@ {} void -MacHighAdhoc::SetInterface (WifiNetDevice *interface) +MacHighAdhoc::SetDevice (WifiNetDevice *device) { - m_interface = interface; + m_device = device; } void @@ -73,8 +73,8 @@ WifiMacHeader hdr; hdr.SetType (WIFI_MAC_DATA); hdr.SetAddr1 (to); - hdr.SetAddr2 (m_interface->GetSelfAddress ()); - hdr.SetAddr3 (m_interface->GetBssid ()); + hdr.SetAddr2 (m_device->GetSelfAddress ()); + hdr.SetAddr3 (m_device->GetBssid ()); hdr.SetDsNotFrom (); hdr.SetDsNotTo (); m_dca->Queue (packet, hdr); @@ -84,7 +84,7 @@ MacHighAdhoc::Receive (Packet packet, WifiMacHeader const *hdr) { TRACE ("received size="<GetSelfAddress () && + hdr.GetAddr1 () == m_device->GetSelfAddress () && m_ctsTimeoutEvent.IsRunning () && m_hasCurrent) { @@ -458,7 +457,7 @@ txMode); } else if (hdr.IsAck () && - hdr.GetAddr1 () == m_interface->GetSelfAddress () && + hdr.GetAddr1 () == m_device->GetSelfAddress () && (m_normalAckTimeoutEvent.IsRunning () || m_fastAckTimeoutEvent.IsRunning () || m_superFastAckTimeoutEvent.IsRunning ()) && @@ -497,7 +496,7 @@ { TRACE ("rx drop " << hdr.GetTypeString ()); } - else if (hdr.GetAddr1 () == m_interface->GetSelfAddress ()) + else if (hdr.GetAddr1 () == m_device->GetSelfAddress ()) { MacStation *station = GetStation (hdr.GetAddr2 ()); station->ReportRxOk (rxSnr, txMode); @@ -538,8 +537,8 @@ return; rxPacket: WifiMacTrailer fcs; - p.RemoveTrailer (fcs); - m_rxCallback (p, &hdr); + packet.RemoveTrailer (fcs); + m_rxCallback (packet, &hdr); return; } @@ -669,7 +668,7 @@ Time duration = MicroSeconds (hdr->GetDurationUs ()); if (hdr->IsCfpoll () && - hdr->GetAddr2 () == m_interface->GetBssid ()) + hdr->GetAddr2 () == m_device->GetBssid ()) { m_lastNavStart = newNavStart; m_lastNavDuration = duration; @@ -772,7 +771,7 @@ rts.SetDsNotFrom (); rts.SetDsNotTo (); rts.SetAddr1 (m_currentHdr.GetAddr1 ()); - rts.SetAddr2 (m_interface->GetSelfAddress ()); + rts.SetAddr2 (m_device->GetSelfAddress ()); WifiMode rtsTxMode = GetRtsTxMode (m_currentHdr.GetAddr1 ()); Time duration = Seconds (0); if (m_txParams.HasDurationId ()) diff -r 007214146da7 -r 041240a915f8 src/devices/wifi/mac-low.h --- a/src/devices/wifi/mac-low.h Mon Oct 15 16:17:15 2007 +0200 +++ b/src/devices/wifi/mac-low.h Mon Oct 15 16:47:53 2007 +0200 @@ -26,6 +26,7 @@ #include "wifi-mac-header.h" #include "wifi-mode.h" +#include "wifi-preamble.h" #include "ns3/mac48-address.h" #include "ns3/callback.h" #include "ns3/callback-trace-source.h" @@ -151,7 +152,7 @@ MacLow (); ~MacLow (); - void SetInterface (Ptr interface); + void SetDevice (Ptr device); void SetPhy (WifiPhy *phy); void SetStations (MacStations *stations); void SetParameters (MacParameters *parameters); @@ -171,8 +172,8 @@ MacLowTransmissionParameters parameters, MacLowTransmissionListener *listener); - void ReceiveOk (Packet const packet, double rxSnr, WifiMode txMode, WifiMode headerMode); - void ReceiveError (Packet const packet, double rxSnr); + void ReceiveOk (Packet packet, double rxSnr, WifiMode txMode, WifiPreamble preamble); + void ReceiveError (Packet packet, double rxSnr); private: void CancelAllEvents (void); uint32_t GetAckSize (void) const; @@ -213,7 +214,7 @@ void SendCurrentTxPacket (void); void StartDataTxTimers (void); - Ptr m_interface; + Ptr m_device; WifiPhy *m_phy; MacStations *m_stations; MacParameters *m_parameters; diff -r 007214146da7 -r 041240a915f8 src/devices/wifi/mac-parameters.cc --- a/src/devices/wifi/mac-parameters.cc Mon Oct 15 16:17:15 2007 +0200 +++ b/src/devices/wifi/mac-parameters.cc Mon Oct 15 16:47:53 2007 +0200 @@ -20,26 +20,36 @@ */ #include - #include "mac-parameters.h" -#include "wifi-phy.h" -#include "wifi-mac-header.h" -#include "wifi-preamble.h" +#include "wifi-default-parameters.h" namespace ns3 { MacParameters::MacParameters () { - m_rtsCtsThreshold = 1000; - m_fragmentationThreshold = 2000; - m_maxSsrc = 7; - m_maxSlrc = 7; + m_rtsCtsThreshold = WifiDefaultParameters::GetRtsCtsThreshold (); + m_fragmentationThreshold = WifiDefaultParameters::GetFragmentationThreshold (); + m_maxSsrc = WifiDefaultParameters::GetMaxSsrc (); + m_maxSlrc = WifiDefaultParameters::GetMaxSlrc (); + + // ensure something not too stupid is set by default. + NS_ASSERT (WifiDefaultParameters::GetPhyStandard () == WifiDefaultParameters::PHY_STANDARD_80211a); + uint32_t ctsAckSize = (2 + 2 + 6) * 8; // bits + double dataRate = (6e6 / 2); // mb/s + Time delay = Seconds (ctsAckSize / dataRate); + + Initialize (delay, delay); } void -MacParameters::Initialize80211a (WifiPhy const*phy) +MacParameters::Initialize (Time ctsDelay, Time ackDelay) { + NS_ASSERT (WifiDefaultParameters::GetPhyStandard () == WifiDefaultParameters::PHY_STANDARD_80211a); + + // these values are really 802.11a specific m_sifs = MicroSeconds (16); m_slot = MicroSeconds (9); + + /* see section 9.2.10 ieee 802.11-1999 */ m_pifs = m_sifs + m_slot; // 1000m @@ -48,16 +58,13 @@ (Formal description of MAC operation, see details on the Trsp timer setting at page 346) */ - WifiMacHeader hdr; - hdr.SetType (WIFI_MAC_CTL_CTS); m_ctsTimeout = m_sifs; - m_ctsTimeout += phy->CalculateTxDuration (hdr.GetSize (), phy->GetMode (0), WIFI_PREAMBLE_LONG); + m_ctsTimeout += ctsDelay; m_ctsTimeout += m_maxPropagationDelay * Scalar (2); m_ctsTimeout += m_slot; - hdr.SetType (WIFI_MAC_CTL_ACK); m_ackTimeout = m_sifs; - m_ackTimeout += phy->CalculateTxDuration (hdr.GetSize (), phy->GetMode (0), WIFI_PREAMBLE_LONG); + m_ackTimeout += ackDelay; m_ackTimeout += m_maxPropagationDelay * Scalar (2); m_ackTimeout += m_slot; } @@ -68,26 +75,6 @@ m_slot = slotTime; } -void -MacParameters::SetMaxSsrc (uint32_t ssrc) -{ - m_maxSsrc = ssrc; -} -void -MacParameters::SetMaxSlrc (uint32_t slrc) -{ - m_maxSlrc = slrc; -} -void -MacParameters::SetRtsCtsThreshold (uint32_t threshold) -{ - m_rtsCtsThreshold = threshold; -} -void -MacParameters::SetFragmentationThreshold (uint32_t threshold) -{ - m_fragmentationThreshold = threshold; -} Time MacParameters::GetPifs (void) const @@ -146,11 +133,6 @@ { return Seconds (10); } -uint32_t -MacParameters::GetMaxQueueSize (void) const -{ - return 400; -} Time MacParameters::GetMaxPropagationDelay (void) const { diff -r 007214146da7 -r 041240a915f8 src/devices/wifi/mac-parameters.h --- a/src/devices/wifi/mac-parameters.h Mon Oct 15 16:17:15 2007 +0200 +++ b/src/devices/wifi/mac-parameters.h Mon Oct 15 16:47:53 2007 +0200 @@ -26,18 +26,13 @@ namespace ns3 { -class WifiPhy; - -class MacParameters { +class MacParameters +{ public: MacParameters (); - - void Initialize80211a (WifiPhy const*phy); + + void Initialize (Time ctsDelay, Time ackDelay); void SetSlotTime (Time slotTime); - void SetMaxSsrc (uint32_t ssrc); - void SetMaxSlrc (uint32_t ssrc); - void SetRtsCtsThreshold (uint32_t threshold); - void SetFragmentationThreshold (uint32_t threshold); // XXX AP-specific Time GetBeaconInterval (void) const; @@ -53,13 +48,13 @@ Time GetCtsTimeout (void) const; Time GetAckTimeout (void) const; Time GetMsduLifetime (void) const; - uint32_t GetMaxQueueSize (void) const; Time GetMaxPropagationDelay (void) const; uint32_t GetMaxMsduSize (void) const; double GetCapLimit (void) const; double GetMinEdcaTrafficProportion (void) const; private: + void Initialize80211a (void); Time m_ctsTimeout; Time m_ackTimeout; Time m_sifs; diff -r 007214146da7 -r 041240a915f8 src/devices/wifi/wifi-default-parameters.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/devices/wifi/wifi-default-parameters.cc Mon Oct 15 16:47:53 2007 +0200 @@ -0,0 +1,204 @@ +#include "wifi-default-parameters.h" +#include "ns3/default-value.h" +#include "ns3/time-default-value.h" + +namespace ns3 { + +namespace WifiDefaultParameters { + +static NumericDefaultValue g_maxSsrc +("WifiMaxSsrc", + "The MAC maximum number of short retransmission retries (rts retransmissions).", + 7); + +static NumericDefaultValue g_maxSlrc +("WifiMaxSlrc", + "The MAC maximum number of long retransmission retries (data retransmissions).", + 7); + +static NumericDefaultValue g_rtsCtsThreshold +("WifiRtsCtsThreshold", + "The threshold (in bytes) over which rts/cts is used prior to data transmissions.", + 2000); + +static NumericDefaultValue g_fragmentationThreshold +("WifiFragmentationThreshold", + "The threshold (in bytes) over which data packets are fragmented", + 2000); + +static TimeDefaultValue g_apBeaconInterval +("WifiApBeaconInterval", + "The interval between two consecutive beacons", + Seconds (1.0)); + +static EnumDefaultValue g_rateControlAlgorithm +("WifiRateControlAlgorithm", + "The rate control algorithm to use", + ARF, "Arf", + CONSTANT_RATE, "ConstantRate", + AARF, "Aarf", + IDEAL, "Ideal", + 0, (void *)0); + +static NumericDefaultValue g_phyEdThreshold +("WifiPhyEnergyDetectionThreshold", + "The energy of a received signal should be higher than this threshold (dbm) to allow the PHY layer to detect the signal.", + -140.0); + +static NumericDefaultValue g_phyRxNoise +("WifiPhyRxNoise", + "Ratio of energy lost by receiver (dB).", + 7); + +static NumericDefaultValue g_phyTxPowerBase +("WifiPhyTxPowerBase", + "Minimum available transmission level (dbm).", + 16.0206); +static NumericDefaultValue g_phyTxPowerEnd +("WifiPhyTxPowerEnd", + "Maximum available transmission level (dbm).", + 16.0206); +static NumericDefaultValue g_phyNTxPower +("WifiPhyTxPowerLevels", + "Number of transmission power levels available between WifiPhyTxPowerBase and WifiPhyTxPowerEnd included.", + 1); +static NumericDefaultValue g_phyTxGain +("WifiPhyTxGain", + "Transmission gain (dbm).", + 1.0); +static NumericDefaultValue g_phyRxGain +("WifiPhyRxGain", + "Reception gain (dbm).", + 1.0); +static StringDefaultValue g_ssid +("WifiSsid", + "The ssid to use. \"\" is the broadcast ssid.", + ""); +static EnumDefaultValue g_dataMode +("WifiConstantDataRate", + "The rate to use for data transmissions if using the ConstantRate rate control algorithm.", + MODE_6MB, "6mb", + MODE_9MB, "9mb", + MODE_12MB, "12mb", + MODE_18MB, "18mb", + MODE_24MB, "24mb", + MODE_36MB, "36mb", + MODE_48MB, "48mb", + MODE_54MB, "54mb"); +static EnumDefaultValue g_ctlMode +("WifiConstantCtlRate", + "The rate to use for control transmissions if using the ConstantRate rate control algorithm.", + MODE_6MB, "6mb", + MODE_9MB, "9mb", + MODE_12MB, "12mb", + MODE_18MB, "18mb", + MODE_24MB, "24mb", + MODE_36MB, "36mb", + MODE_48MB, "48mb", + MODE_54MB, "54mb"); +static NumericDefaultValue g_idealBer +("WifiIdealRateControlBerThreshold", + "The maximum Bit Error Rate acceptable at any transmission mode", + 10e-6); + + + +uint32_t +GetMaxSsrc (void) +{ + return g_maxSsrc.GetValue (); +} +uint32_t +GetMaxSlrc (void) +{ + return g_maxSlrc.GetValue (); +} +uint32_t +GetRtsCtsThreshold (void) +{ + return g_rtsCtsThreshold.GetValue (); +} +uint32_t +GetFragmentationThreshold (void) +{ + return g_fragmentationThreshold.GetValue (); +} +Time +GetApBeaconInterval (void) +{ + return g_apBeaconInterval.GetValue (); +} +enum PhyStandard +GetPhyStandard (void) +{ + return PHY_STANDARD_80211a; +} +enum RateControlAlgorithm +GetRateControlAlgorithm (void) +{ + return g_rateControlAlgorithm.GetValue (); +} +enum PhyModeParameter +GetConstantDataRate (void) +{ + return g_dataMode.GetValue (); +} +enum PhyModeParameter +GetConstantCtlRate (void) +{ + return g_ctlMode.GetValue (); +} +double +GetIdealRateControlBer (void) +{ + return g_idealBer.GetValue (); +} +double +GetPhyEnergyDetectionThresholdDbm (void) +{ + return g_phyEdThreshold.GetValue (); +} +double +GetPhyRxNoiseDb (void) +{ + return g_phyRxNoise.GetValue (); +} + +double +GetPhyTxPowerBaseDbm (void) +{ + return g_phyTxPowerBase.GetValue (); +} + +double +GetPhyTxPowerEndDbm (void) +{ + return g_phyTxPowerEnd.GetValue (); +} + +uint32_t +GetPhyTxPowerLevels (void) +{ + return g_phyNTxPower.GetValue (); +} + +double +GetPhyTxGainDbm (void) +{ + return g_phyTxGain.GetValue (); +} +double +GetPhyRxGainDbm (void) +{ + return g_phyRxGain.GetValue (); +} +Ssid +GetSsid (void) +{ + return Ssid (g_ssid.GetValue ().c_str ()); +} + + +} // namespace WifiDefaultParameters + +} // namespace ns3 diff -r 007214146da7 -r 041240a915f8 src/devices/wifi/wifi-default-parameters.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/devices/wifi/wifi-default-parameters.h Mon Oct 15 16:47:53 2007 +0200 @@ -0,0 +1,57 @@ +#ifndef WIFI_DEFAULT_PARAMETERS_H +#define WIFI_DEFAULT_PARAMETERS_H + +#include +#include "ns3/nstime.h" +#include "ssid.h" + +namespace ns3 { + +namespace WifiDefaultParameters { + +enum PhyStandard { + PHY_STANDARD_80211a, +}; +enum RateControlAlgorithm { + CONSTANT_RATE, + ARF, + AARF, + IDEAL +}; +enum PhyModeParameter { + MODE_6MB = 6000000, + MODE_9MB = 9000000, + MODE_12MB = 12000000, + MODE_18MB = 18000000, + MODE_24MB = 24000000, + MODE_36MB = 36000000, + MODE_48MB = 48000000, + MODE_54MB = 54000000 +}; + +uint32_t GetMaxSsrc (void); +uint32_t GetMaxSlrc (void); +uint32_t GetRtsCtsThreshold (void); +uint32_t GetFragmentationThreshold (void); +Time GetApBeaconInterval (void); +enum PhyStandard GetPhyStandard (void); +enum RateControlAlgorithm GetRateControlAlgorithm (void); +enum PhyModeParameter GetConstantDataRate (void); +enum PhyModeParameter GetConstantCtlRate (void); +double GetIdealRateControlBer (void); + +double GetPhyEnergyDetectionThresholdDbm (void); +double GetPhyRxNoiseDb (void); +double GetPhyTxPowerBaseDbm (void); +double GetPhyTxPowerEndDbm (void); +uint32_t GetPhyTxPowerLevels (void); +double GetPhyTxGainDbm (void); +double GetPhyRxGainDbm (void); + +Ssid GetSsid (void); + +} // namespace WifiDefaultParameters + +} // namespace ns3 + +#endif /* WIFI_DEFAULT_PARAMETERS_H */ diff -r 007214146da7 -r 041240a915f8 src/devices/wifi/wifi-net-device-factory.h --- a/src/devices/wifi/wifi-net-device-factory.h Mon Oct 15 16:17:15 2007 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2005,2006 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ - -#ifndef NETWORK_INTERFACE_Wifi_FACTORY_H -#define NETWORK_INTERFACE_Wifi_FACTORY_H - -#include -#include "ssid.h" -#include "ns3/object.h" - -namespace ns3 { - -class WifiNetDevice; -class AdhocWifiNetDevice; -class NqstaWifiNetDevice; -class NqapWifiNetDevice; -class DcaTxop; -class Position; - -class WifiNetDeviceFactory : public Object -{ -public: - WifiNetDeviceFactory (); - virtual ~WifiNetDeviceFactory (); - - void SetArf (void); - void SetAarf (void); - void SetCr (uint8_t dataMode, uint8_t ctlMode); - void SetIdeal (double ber); - - /* absolute reception threshold. dBm. */ - void SetPhyEdThresholdDbm (double dbm); - /* Ratio of energy lost by receiver. dB. */ - void SetPhyRxNoiseDb (double rxNoise); - /* absolute transmission energy. dBm. */ - void SetPhyTxPowerDbm (double txPowerBase, - double txPowerEnd, - uint8_t nTxPower); - - /* no unit. */ - void SetPropSystemLoss (double systemLoss); - void SetPropTxGainDbm (double txGain); - void SetPropRxGainDbm (double rxGain); - void SetPropFrequencyHz (double frequency); - - void SetMacRtsCtsThreshold (uint32_t size); - void SetMacFragmentationThreshold (uint32_t size); - void SetMacMaxSsrc (uint32_t ssrc); - void SetMacMaxSlrc (uint32_t slrc); - - void SetSsid (Ssid ssid); - - Ptr CreateAdhoc (Ptr node); - Ptr CreateNqsta (Ptr node); - Ptr CreateNqap (Ptr node); -private: - void InitializeInterface (Ptr interface, Position *position) const; - DcaTxop *CreateDca (Ptr interface) const; - enum { - RATE_ARF, - RATE_AARF, - RATE_CR, - RATE_IDEAL - } m_rateControlMode; - - uint8_t m_crDataMode; - uint8_t m_crCtlMode; - - double m_idealBer; - - double m_phyEdThresholdDbm; - double m_phyRxNoiseDb; - double m_phyTxPowerBaseDbm; - double m_phyTxPowerEndDbm; - uint8_t m_phyNTxPower; - - double m_propSystemLoss; - double m_propTxGainDbm; - double m_propRxGainDbm; - double m_propFrequencyHz; - - uint32_t m_macRtsCtsThreshold; - uint32_t m_macFragmentationThreshold; - uint32_t m_macMaxSsrc; - uint32_t m_macMaxSlrc; - - Ssid m_ssid; -}; - -}; // namespace ns3 - -#endif /* NETWORK_INTERFACE_Wifi_FACTORY_H */ diff -r 007214146da7 -r 041240a915f8 src/devices/wifi/wifi-net-device.cc --- a/src/devices/wifi/wifi-net-device.cc Mon Oct 15 16:17:15 2007 +0200 +++ b/src/devices/wifi/wifi-net-device.cc Mon Oct 15 16:47:53 2007 +0200 @@ -33,14 +33,37 @@ #include "mac-high-nqsta.h" #include "mac-high-nqap.h" #include "dca-txop.h" +#include "wifi-default-parameters.h" +#include "arf-mac-stations.h" +#include "aarf-mac-stations.h" +#include "ideal-mac-stations.h" +#include "cr-mac-stations.h" namespace ns3 { +static WifiMode +GetWifiModeForPhyMode (WifiPhy *phy, enum WifiDefaultParameters::PhyModeParameter mode) +{ + uint32_t phyRate = (uint32_t)mode; + for (uint32_t i= 0; i < phy->GetNModes (); i++) + { + WifiMode mode = phy->GetMode (i); + if (mode.GetPhyRate () == phyRate) + { + return mode; + } + } + NS_ASSERT (false); + return WifiMode (); +} + + WifiNetDevice::WifiNetDevice (Ptr node) : NetDevice (node, Mac48Address::Allocate ()) { SetMtu (2300); EnableBroadcast (Mac48Address ("ff:ff:ff:ff:ff:ff")); + Construct (); } WifiNetDevice::~WifiNetDevice () @@ -53,9 +76,100 @@ delete m_rxMiddle; } +void +WifiNetDevice::Construct (void) +{ + // the physical layer. + m_phy = new WifiPhy (this); + + // the rate control algorithm + switch (WifiDefaultParameters::GetRateControlAlgorithm ()) { + case WifiDefaultParameters::ARF: + m_stations = new ArfMacStations (m_phy->GetMode (0)); + break; + case WifiDefaultParameters::AARF: + m_stations = new AarfMacStations (m_phy->GetMode (0)); + break; + case WifiDefaultParameters::CONSTANT_RATE: { + WifiMode dataRate = GetWifiModeForPhyMode (m_phy, WifiDefaultParameters::GetConstantDataRate ()); + WifiMode ctlRate = GetWifiModeForPhyMode (m_phy, WifiDefaultParameters::GetConstantCtlRate ()); + m_stations = new CrMacStations (dataRate, ctlRate); + } break; + case WifiDefaultParameters::IDEAL: { + double ber = WifiDefaultParameters::GetIdealRateControlBer (); + IdealMacStations *ideal = new IdealMacStations (m_phy->GetMode (0)); + uint32_t nModes = m_phy->GetNModes (); + for (uint32_t i = 0; i < nModes; i++) + { + WifiMode mode = m_phy->GetMode (i); + ideal->AddModeSnrThreshold (mode, m_phy->CalculateSnr (mode, ber)); + } + m_stations = ideal; + } break; + default: + // NOTREACHED + NS_ASSERT (false); + break; + } + + // MacParameters + MacParameters *parameters = new MacParameters (); + WifiMacHeader hdr; + hdr.SetType (WIFI_MAC_CTL_CTS); + Time ctsDelay = m_phy->CalculateTxDuration (hdr.GetSize (), m_phy->GetMode (0), WIFI_PREAMBLE_LONG); + hdr.SetType (WIFI_MAC_CTL_ACK); + Time ackDelay = m_phy->CalculateTxDuration (hdr.GetSize (), m_phy->GetMode (0), WIFI_PREAMBLE_LONG); + parameters->Initialize (ctsDelay, ackDelay); + m_parameters = parameters; + + // the MacLow + MacLow *low = new MacLow (); + low->SetDevice (this); + low->SetPhy (m_phy); + low->SetStations (m_stations); + low->SetParameters (m_parameters); + m_phy->SetReceiveOkCallback (MakeCallback (&MacLow::ReceiveOk, low)); + m_phy->SetReceiveErrorCallback (MakeCallback (&MacLow::ReceiveError, low)); + m_low = low; + + // the 'middle' rx + MacRxMiddle *rxMiddle = new MacRxMiddle (); + low->SetRxCallback (MakeCallback (&MacRxMiddle::Receive, rxMiddle)); + m_rxMiddle = rxMiddle; + + // the 'middle' tx + MacTxMiddle *txMiddle = new MacTxMiddle (); + m_txMiddle = txMiddle; + +} + +DcaTxop * +WifiNetDevice::CreateDca (void) const +{ + DcaTxop *dca = new DcaTxop (); + dca->SetParameters (m_parameters); + dca->SetTxMiddle (m_txMiddle); + dca->SetLow (m_low); + dca->SetPhy (m_phy); + // 802.11a + Time difs = m_parameters->GetSifs () + + m_parameters->GetSlotTime () + + m_parameters->GetSlotTime (); + Time eifs = difs + m_parameters->GetSifs () + + m_phy->CalculateTxDuration (2+2+6+4, m_phy->GetMode (0), WIFI_PREAMBLE_LONG); + dca->SetDifs (difs); + dca->SetEifs (eifs); + dca->SetCwBounds (15, 1023); + dca->SetMaxQueueSize (400); + dca->SetMaxQueueDelay (Seconds (10)); + return dca; +} + + void WifiNetDevice::ConnectTo (Ptr channel) { + m_channel = channel; m_phy->SetChannel (channel); NotifyConnected (); } @@ -92,6 +206,17 @@ Mac48Address self = Mac48Address::ConvertFrom (GetAddress ()); return self; } +bool +WifiNetDevice::DoNeedsArp (void) const +{ + return true; +} +Ptr +WifiNetDevice::DoGetChannel (void) const +{ + return m_channel; +} + /***************************************************** * Adhoc code @@ -99,7 +224,18 @@ AdhocWifiNetDevice::AdhocWifiNetDevice (Ptr node) : WifiNetDevice (node) -{} +{ + m_ssid = WifiDefaultParameters::GetSsid (); + m_dca = CreateDca (); + + MacHighAdhoc *high = new MacHighAdhoc (); + high->SetDevice (this); + high->SetDcaTxop (m_dca); + high->SetForwardCallback (MakeCallback (&AdhocWifiNetDevice::DoForwardUp, + static_cast (this))); + m_rxMiddle->SetForwardCallback (MakeCallback (&MacHighAdhoc::Receive, high)); + m_high = high; +} AdhocWifiNetDevice::~AdhocWifiNetDevice () { delete m_dca; @@ -139,7 +275,30 @@ NqstaWifiNetDevice::NqstaWifiNetDevice (Ptr node) : WifiNetDevice (node) -{} +{ + m_ssid = WifiDefaultParameters::GetSsid (); + m_dca = CreateDca (); + + SupportedRates rates; + for (uint32_t i = 0; i < m_phy->GetNModes (); i++) + { + WifiMode mode = m_phy->GetMode (i); + rates.AddSupportedRate (mode.GetPhyRate ()); + } + + MacHighNqsta *high = new MacHighNqsta (); + high->SetDevice (this); + high->SetDcaTxop (m_dca); + high->SetForwardCallback (MakeCallback (&NqstaWifiNetDevice::DoForwardUp, + this)); + high->SetAssociatedCallback (MakeCallback (&NqstaWifiNetDevice::Associated, + this)); + high->SetDisAssociatedCallback (MakeCallback (&NqstaWifiNetDevice::DisAssociated, + this)); + high->SetSupportedRates (rates); + m_rxMiddle->SetForwardCallback (MakeCallback (&MacHighNqsta::Receive, high)); + m_high = high; +} NqstaWifiNetDevice::~NqstaWifiNetDevice () { delete m_dca; @@ -193,7 +352,27 @@ NqapWifiNetDevice::NqapWifiNetDevice (Ptr node) : WifiNetDevice (node) -{} +{ + m_ssid = WifiDefaultParameters::GetSsid (); + + m_dca = CreateDca (); + + SupportedRates rates; + for (uint32_t i = 0; i < m_phy->GetNModes (); i++) + { + rates.AddSupportedRate (m_phy->GetMode (i).GetPhyRate ()); + } + + MacHighNqap *high = new MacHighNqap (); + high->SetDevice (this); + high->SetDcaTxop (m_dca); + high->SetStations (m_stations); + high->SetForwardCallback (MakeCallback (&NqapWifiNetDevice::DoForwardUp, + this)); + high->SetSupportedRates (rates); + m_rxMiddle->SetForwardCallback (MakeCallback (&MacHighNqap::Receive, high)); + m_high = high; +} NqapWifiNetDevice::~NqapWifiNetDevice () { delete m_dca; diff -r 007214146da7 -r 041240a915f8 src/devices/wifi/wifi-net-device.h --- a/src/devices/wifi/wifi-net-device.h Mon Oct 15 16:17:15 2007 +0200 +++ b/src/devices/wifi/wifi-net-device.h Mon Oct 15 16:47:53 2007 +0200 @@ -53,26 +53,33 @@ virtual Mac48Address GetBssid (void) const = 0; virtual Ssid GetSsid (void) const = 0; +private: + // inherited from parent. + virtual bool DoNeedsArp (void) const; + virtual Ptr DoGetChannel (void) const; + virtual bool SendTo (const Packet &packet, const Address &to, uint16_t protocolNumber); + // defined for children + virtual void NotifyConnected (void) = 0; + virtual bool DoSendTo (const Packet &packet, const Mac48Address &to) = 0; + // private helper + void Construct (void); + friend class WifiNetDeviceFactory; + + CallbackTraceSource m_rxLogger; + CallbackTraceSource m_txLogger; protected: WifiNetDevice (Ptr node); void DoForwardUp (Packet packet, const Mac48Address &from); -private: - virtual bool SendTo (const Packet &packet, const Address &to, uint16_t protocolNumber); - virtual void NotifyConnected (void) = 0; - virtual bool DoSendTo (const Packet &packet, const Mac48Address &to) = 0; - void Associated (void); + DcaTxop *CreateDca (void) const; - friend class WifiNetDeviceFactory; - + Ptr m_channel; WifiPhy *m_phy; MacStations *m_stations; MacLow *m_low; MacRxMiddle *m_rxMiddle; MacTxMiddle *m_txMiddle; MacParameters *m_parameters; - CallbackTraceSource m_rxLogger; - CallbackTraceSource m_txLogger; }; class AdhocWifiNetDevice : public WifiNetDevice { @@ -85,9 +92,10 @@ void SetSsid (Ssid ssid); private: + void ForwardUp (void); virtual bool DoSendTo (const Packet &packet, Mac48Address const & to); virtual void NotifyConnected (void); - friend class WifiNetDeviceFactory; + Ssid m_ssid; DcaTxop *m_dca; MacHighAdhoc *m_high; diff -r 007214146da7 -r 041240a915f8 src/devices/wifi/wifi-phy.cc --- a/src/devices/wifi/wifi-phy.cc Mon Oct 15 16:17:15 2007 +0200 +++ b/src/devices/wifi/wifi-phy.cc Mon Oct 15 16:47:53 2007 +0200 @@ -24,6 +24,7 @@ #include "wifi-channel.h" #include "wifi-net-device.h" #include "wifi-preamble.h" +#include "wifi-default-parameters.h" #include "ns3/simulator.h" #include "ns3/packet.h" #include "ns3/random-variable.h" @@ -198,13 +199,13 @@ ****************************************************************/ WifiPhy::WifiPhy (Ptr device) - : m_edThresholdW (DbmToW (-140)), - m_txGainDbm (1.0), - m_rxGainDbm (1.0), - m_rxNoiseRatio (DbToRatio (7)), - m_txPowerBaseDbm (16.0206), - m_txPowerEndDbm (16.0206), - m_nTxPower (1), + : m_edThresholdW (DbmToW (WifiDefaultParameters::GetPhyEnergyDetectionThresholdDbm ())), + m_txGainDbm (WifiDefaultParameters::GetPhyTxGainDbm ()), + m_rxGainDbm (WifiDefaultParameters::GetPhyRxGainDbm ()), + m_rxNoiseRatio (DbToRatio (WifiDefaultParameters::GetPhyRxNoiseDb ())), + m_txPowerBaseDbm (WifiDefaultParameters::GetPhyTxPowerBaseDbm ()), + m_txPowerEndDbm (WifiDefaultParameters::GetPhyTxPowerEndDbm ()), + m_nTxPower (WifiDefaultParameters::GetPhyTxPowerLevels ()), m_syncing (false), m_endTx (Seconds (0)), m_endSync (Seconds (0)), @@ -216,7 +217,10 @@ m_device (device), m_endSyncEvent (), m_random (0.0, 1.0) -{} +{ + NS_ASSERT (WifiDefaultParameters::GetPhyStandard () == WifiDefaultParameters::PHY_STANDARD_80211a); + Configure80211a (); +} WifiPhy::~WifiPhy () { @@ -357,31 +361,6 @@ m_channel->Send (m_device, packet, GetPowerDbm (txPower) + m_txGainDbm, txMode, preamble); } -void -WifiPhy::SetEdThresholdDbm (double edThreshold) -{ - m_edThresholdW = DbmToW (edThreshold); -} -void -WifiPhy::SetRxNoiseDb (double rxNoise) -{ - m_rxNoiseRatio = DbToRatio (rxNoise); -} -void -WifiPhy::SetTxPowerIncrementsDbm (double txPowerBase, - double txPowerEnd, - int nTxPower) -{ - m_txPowerBaseDbm = txPowerBase; - m_txPowerEndDbm = txPowerEnd; - m_nTxPower = nTxPower; -} -void -WifiPhy::SetRxTxGainDbm (double rxGainDbm, double txGainDbm) -{ - m_rxGainDbm = rxGainDbm; - m_txGainDbm = txGainDbm; -} uint32_t WifiPhy::GetNModes (void) const { diff -r 007214146da7 -r 041240a915f8 src/devices/wifi/wifi-phy.h --- a/src/devices/wifi/wifi-phy.h Mon Oct 15 16:17:15 2007 +0200 +++ b/src/devices/wifi/wifi-phy.h Mon Oct 15 16:47:53 2007 +0200 @@ -72,8 +72,8 @@ class WifiPhy { public: - typedef Callback SyncOkCallback; - typedef Callback SyncErrorCallback; + typedef Callback SyncOkCallback; + typedef Callback SyncErrorCallback; WifiPhy (Ptr device); virtual ~WifiPhy (); @@ -97,13 +97,6 @@ Time CalculateTxDuration (uint32_t size, WifiMode payloadMode, enum WifiPreamble preamble) const; - void Configure80211a (void); - void SetEdThresholdDbm (double rxThreshold); - void SetRxNoiseDb (double rxNoise); - void SetTxPowerIncrementsDbm (double txPowerBase, - double txPowerEnd, - int nTxPower); - void SetRxTxGainDbm (double rxGainDbm, double txGainDbm); uint32_t GetNModes (void) const; WifiMode GetMode (uint32_t mode) const; uint32_t GetModeBitRate (uint8_t mode) const; @@ -134,6 +127,7 @@ typedef std::vector NiChanges; private: + void Configure80211a (void); char const *StateToString (enum WifiPhyState state); enum WifiPhyState GetState (void); double GetEdThresholdW (void) const; diff -r 007214146da7 -r 041240a915f8 src/devices/wifi/wscript --- a/src/devices/wifi/wscript Mon Oct 15 16:17:15 2007 +0200 +++ b/src/devices/wifi/wscript Mon Oct 15 16:47:53 2007 +0200 @@ -31,11 +31,11 @@ 'mac-high-nqap.cc', 'mac-high-nqsta.cc', 'wifi-net-device.cc', + 'wifi-default-parameters.cc' ] headers = bld.create_obj('ns3header') headers.source = [ 'wifi-net-device.h', - 'wifi-net-device-factory.h', 'wifi-channel.h', 'wifi-mode.h', 'ssid.h',