diff --git a/examples/mixed-wireless.cc b/examples/mixed-wireless.cc index 5e38ee577..923def716 100644 --- a/examples/mixed-wireless.cc +++ b/examples/mixed-wireless.cc @@ -137,7 +137,6 @@ main (int argc, char *argv[]) // WifiHelper wifi; wifi.SetMac ("ns3::AdhocWifiMac"); - wifi.SetPhy ("ns3::YansWifiPhy"); NetDeviceContainer backboneDevices = wifi.Install (backbone); // // Add the IPv4 protocol stack to the nodes in our container @@ -246,7 +245,6 @@ main (int argc, char *argv[]) // WifiHelper wifiInfra; wifiInfra.SetMac ("ns3::AdhocWifiMac"); - wifiInfra.SetPhy ("ns3::YansWifiPhy"); NetDeviceContainer infraDevices = wifiInfra.Install (infra); // Add the IPv4 protocol stack to the nodes in our container diff --git a/examples/wifi-adhoc.cc b/examples/wifi-adhoc.cc index a506571c8..aedeacf1c 100644 --- a/examples/wifi-adhoc.cc +++ b/examples/wifi-adhoc.cc @@ -172,7 +172,6 @@ int main (int argc, char *argv[]) GnuplotDataset dataset; wifi.SetMac ("ns3::AdhocWifiMac"); - wifi.SetPhy ("ns3::YansWifiPhy"); NS_LOG_DEBUG ("54"); experiment = Experiment ("54mb"); diff --git a/examples/wifi-ap.cc b/examples/wifi-ap.cc index b4a30d6fd..df5de111c 100644 --- a/examples/wifi-ap.cc +++ b/examples/wifi-ap.cc @@ -131,14 +131,13 @@ int main (int argc, char *argv[]) packetSocket.Install (stas); packetSocket.Install (ap); - Ptr channel = CreateObject (); + Ptr channel = CreateObject (); channel->SetPropagationDelayModel (CreateObject ()); Ptr log = CreateObject (); log->SetReferenceModel (CreateObject ()); channel->SetPropagationLossModel (log); Ssid ssid = Ssid ("wifi-default"); - wifi.SetPhy ("ns3::YansWifiPhy"); wifi.SetRemoteStationManager ("ns3::ArfWifiManager"); // setup stas. wifi.SetMac ("ns3::NqstaWifiMac", diff --git a/src/devices/wifi/wifi-channel.cc b/src/devices/wifi/wifi-channel.cc index 400b2714f..a13149a79 100644 --- a/src/devices/wifi/wifi-channel.cc +++ b/src/devices/wifi/wifi-channel.cc @@ -24,8 +24,10 @@ #include "ns3/node.h" #include "ns3/log.h" #include "ns3/pointer.h" +#include "ns3/object-factory.h" #include "wifi-channel.h" -#include "wifi-phy.h" +#include "wifi-net-device.h" +#include "yans-wifi-phy.h" #include "propagation-loss-model.h" #include "propagation-delay-model.h" @@ -38,94 +40,8 @@ WifiChannel::GetTypeId (void) { static TypeId tid = TypeId ("ns3::WifiChannel") .SetParent () - .AddConstructor () - .AddAttribute ("PropagationLossModel", "A pointer to the propagation loss model attached to this channel.", - PointerValue (), - MakePointerAccessor (&WifiChannel::m_loss), - MakePointerChecker ()) - .AddAttribute ("PropagationDelayModel", "A pointer to the propagation delay model attached to this channel.", - PointerValue (), - MakePointerAccessor (&WifiChannel::m_delay), - MakePointerChecker ()) ; return tid; } -WifiChannel::WifiChannel () -{} -WifiChannel::~WifiChannel () -{ - m_deviceList.clear (); -} - -void -WifiChannel::SetPropagationLossModel (Ptr loss) -{ - m_loss = loss; -} -void -WifiChannel::SetPropagationDelayModel (Ptr delay) -{ - m_delay = delay; -} - -void -WifiChannel::Add (Ptr device, Ptr phy, Ptr mobility) -{ - struct Item item; - item.device = device; - item.phy = phy; - item.mobility = mobility; - m_deviceList.push_back (item); -} -void -WifiChannel::Send (Ptr sender, Ptr packet, double txPowerDbm, - WifiMode wifiMode, WifiPreamble preamble) const -{ - Ptr senderMobility = 0; - for (DeviceList::const_iterator i = m_deviceList.begin (); i != m_deviceList.end (); i++) - { - if (sender == i->phy) - { - senderMobility = i->mobility->GetObject (); - break; - } - } - NS_ASSERT (senderMobility != 0); - uint32_t j = 0; - for (DeviceList::const_iterator i = m_deviceList.begin (); i != m_deviceList.end (); i++) - { - if (sender != i->phy) - { - Ptr receiverMobility = i->mobility->GetObject (); - Time delay = m_delay->GetDelay (senderMobility, receiverMobility); - double rxPowerDbm = txPowerDbm + m_loss->GetLoss (senderMobility, receiverMobility); - NS_LOG_DEBUG ("propagation: txPower="< GetDevice (uint32_t i) const; - - /** - * \param loss the new propagation loss model. - */ - void SetPropagationLossModel (Ptr loss); - /** - * \param delay the new propagation delay model. - */ - void SetPropagationDelayModel (Ptr delay); - - /** - * \param device the device to add to the list of connected - * devices. - * \param phy the physical layer which will receive packets - * on behalf of the device. - * \param mobility the mobility model associated to the device. - * - * This method should not be invoked by normal users. It is - * currently invoked only from WifiPhy::SetChannel. - */ - void Add (Ptr device, Ptr phy, Ptr mobility); - /** - * \param sender the device from which the packet is originating. - * \param packet the packet to send - * \param txPowerDbm the tx power associated to the packet - * \param wifiMode the tx mode associated to the packet - * \param preamble the preamble associated to the packet - * - * This method should not be invoked by normal users. It is - * currently invoked only from WifiPhy::Send. - */ - void Send (Ptr sender, Ptr packet, double txPowerDbm, - WifiMode wifiMode, WifiPreamble preamble) const; - -private: - struct Item { - Ptr device; - Ptr phy; - Ptr mobility; - }; - typedef std::vector DeviceList; - void Receive (uint32_t i, Ptr packet, double rxPowerDbm, - WifiMode txMode, WifiPreamble preamble) const; - - - DeviceList m_deviceList; - Ptr m_loss; - Ptr m_delay; + virtual Ptr CreatePhy (Ptr device, + Ptr mobility, + UnsafeAttributeList list) = 0; }; } // namespace ns3 diff --git a/src/devices/wifi/wifi-net-device.cc b/src/devices/wifi/wifi-net-device.cc index edc7111a7..48e751262 100644 --- a/src/devices/wifi/wifi-net-device.cc +++ b/src/devices/wifi/wifi-net-device.cc @@ -112,11 +112,6 @@ WifiNetDevice::SetPhy (Ptr phy) m_phy = phy; if (m_phy != 0) { - if (m_channel != 0 && m_node != 0) - { - m_channel->Add (this, m_phy, m_node); - m_phy->SetChannel (m_channel); - } if (m_stationManager != 0) { m_stationManager->SetupPhy (m_phy); @@ -147,11 +142,6 @@ void WifiNetDevice::SetChannel (Ptr channel) { m_channel = channel; - if (m_channel != 0 && m_phy != 0 && m_node != 0) - { - m_channel->Add (this, m_phy, m_node); - m_phy->SetChannel (m_channel); - } } Ptr WifiNetDevice::GetMac (void) const @@ -292,11 +282,6 @@ void WifiNetDevice::SetNode (Ptr node) { m_node = node; - if (m_channel != 0 && m_phy != 0 && m_node != 0) - { - m_channel->Add (this, m_phy, m_node); - m_phy->SetChannel (m_channel); - } } bool WifiNetDevice::NeedsArp (void) const diff --git a/src/devices/wifi/wifi-phy-test.cc b/src/devices/wifi/wifi-phy-test.cc index c618f6b29..7f770feed 100644 --- a/src/devices/wifi/wifi-phy-test.cc +++ b/src/devices/wifi/wifi-phy-test.cc @@ -1,5 +1,5 @@ -#include "wifi-phy.h" -#include "wifi-channel.h" +#include "wifi-net-device.h" +#include "yans-wifi-channel.h" #include "yans-wifi-phy.h" #include "propagation-loss-model.h" #include "propagation-delay-model.h" @@ -78,20 +78,15 @@ PsrExperiment::Run (struct PsrExperiment::Input input) Ptr posRx = CreateObject (); posRx->SetPosition (Vector (m_input.distance, 0.0, 0.0)); - Ptr tx = CreateObject (); - Ptr rx = CreateObject (); - rx->SetReceiveOkCallback (MakeCallback (&PsrExperiment::Receive, this)); - - Ptr channel = CreateObject (); + Ptr channel = CreateObject (); channel->SetPropagationDelayModel (CreateObject ()); Ptr log = CreateObject (); log->SetReferenceModel (CreateObject ()); channel->SetPropagationLossModel (log); - channel->Add (0, tx, posTx); - channel->Add (0, rx, posRx); - tx->SetChannel (channel); - rx->SetChannel (channel); + Ptr tx = channel->CreatePhy (0, posTx, UnsafeAttributeList ()); + Ptr rx = channel->CreatePhy (0, posRx, UnsafeAttributeList ()); + rx->SetReceiveOkCallback (MakeCallback (&PsrExperiment::Receive, this)); for (uint32_t i = 0; i < m_input.nPackets; ++i) { @@ -198,6 +193,12 @@ CollisionExperiment::Run (struct CollisionExperiment::Input input) m_flowIdA = FlowIdTag::AllocateFlowId (); m_flowIdB = FlowIdTag::AllocateFlowId (); + Ptr channel = CreateObject (); + channel->SetPropagationDelayModel (CreateObject ()); + Ptr log = CreateObject (); + log->SetReferenceModel (CreateObject ()); + channel->SetPropagationLossModel (log); + Ptr posTxA = CreateObject (); posTxA->SetPosition (Vector (input.xA, 0.0, 0.0)); Ptr posTxB = CreateObject (); @@ -205,24 +206,11 @@ CollisionExperiment::Run (struct CollisionExperiment::Input input) Ptr posRx = CreateObject (); posRx->SetPosition (Vector (0, 0.0, 0.0)); - Ptr txA = CreateObject (); - Ptr txB = CreateObject (); - Ptr rx = CreateObject (); + Ptr txA = channel->CreatePhy (0, posTxA, UnsafeAttributeList ()); + Ptr txB = channel->CreatePhy (0, posTxB, UnsafeAttributeList ()); + Ptr rx = channel->CreatePhy (0, posRx, UnsafeAttributeList ()); rx->SetReceiveOkCallback (MakeCallback (&CollisionExperiment::Receive, this)); - Ptr channel = CreateObject (); - channel->SetPropagationDelayModel (CreateObject ()); - Ptr log = CreateObject (); - log->SetReferenceModel (CreateObject ()); - channel->SetPropagationLossModel (log); - - channel->Add (0, txA, posTxA); - channel->Add (0, txB, posTxB); - channel->Add (0, rx, posRx); - txA->SetChannel (channel); - txB->SetChannel (channel); - rx->SetChannel (channel); - for (uint32_t i = 0; i < m_input.nPackets; ++i) { Simulator::Schedule (Seconds (i), &CollisionExperiment::SendA, this); diff --git a/src/devices/wifi/wifi-phy.h b/src/devices/wifi/wifi-phy.h index 8a9cf3d8b..a158f615c 100644 --- a/src/devices/wifi/wifi-phy.h +++ b/src/devices/wifi/wifi-phy.h @@ -140,11 +140,6 @@ public: */ virtual uint32_t GetNTxPower (void) const = 0; - /** - * \param channel the channel to connect to. - */ - virtual void SetChannel (Ptr channel) = 0; - /** * \param callback the callback to invoke * upon successful packet reception. @@ -234,11 +229,6 @@ public: */ virtual double CalculateSnr (WifiMode txMode, double ber) const = 0; - /* rxPower unit is Watt */ - virtual void StartReceivePacket (Ptr packet, - double rxPowerDbm, - WifiMode mode, - WifiPreamble preamble) = 0; virtual Ptr GetChannel (void) const = 0; diff --git a/src/devices/wifi/wifi-test.cc b/src/devices/wifi/wifi-test.cc index 37cb35989..be74753b9 100644 --- a/src/devices/wifi/wifi-test.cc +++ b/src/devices/wifi/wifi-test.cc @@ -1,7 +1,7 @@ #ifdef RUN_SELF_TESTS #include "wifi-net-device.h" -#include "wifi-channel.h" +#include "yans-wifi-channel.h" #include "adhoc-wifi-mac.h" #include "yans-wifi-phy.h" #include "arf-wifi-manager.h" @@ -50,7 +50,7 @@ WifiTest::CreateOne (Vector pos, Ptr channel) Ptr mac = m_mac.Create (); Ptr mobility = CreateObject (); - Ptr phy = CreateObject (); + Ptr phy = channel->CreatePhy (dev, mobility, UnsafeAttributeList ()); Ptr manager = m_manager.Create (); mobility->SetPosition (pos); @@ -68,7 +68,7 @@ WifiTest::CreateOne (Vector pos, Ptr channel) void WifiTest::RunOne (void) { - Ptr channel = CreateObject (); + Ptr channel = CreateObject (); Ptr propDelay = m_propDelay.Create (); Ptr propLoss = CreateObject (); channel->SetPropagationDelayModel (propDelay); diff --git a/src/devices/wifi/wscript b/src/devices/wifi/wscript index eb0a863bc..a176ac200 100644 --- a/src/devices/wifi/wscript +++ b/src/devices/wifi/wscript @@ -12,6 +12,7 @@ def build(bld): 'ssid.cc', 'wifi-phy.cc', 'yans-wifi-phy.cc', + 'yans-wifi-channel.cc', 'wifi-mac-header.cc', 'wifi-mac-trailer.cc', 'mac-low.cc', @@ -55,6 +56,7 @@ def build(bld): 'wifi-preamble.h', 'wifi-phy-standard.h', 'yans-wifi-phy.h', + 'yans-wifi-channel.h', 'wifi-phy.h', 'wifi-remote-station-manager.h', 'arf-wifi-manager.h', diff --git a/src/devices/wifi/yans-wifi-channel.cc b/src/devices/wifi/yans-wifi-channel.cc new file mode 100644 index 000000000..086b5807f --- /dev/null +++ b/src/devices/wifi/yans-wifi-channel.cc @@ -0,0 +1,142 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2006,2007 INRIA + * + * 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, + */ +#include "ns3/packet.h" +#include "ns3/simulator.h" +#include "ns3/mobility-model.h" +#include "ns3/net-device.h" +#include "ns3/node.h" +#include "ns3/log.h" +#include "ns3/pointer.h" +#include "ns3/object-factory.h" +#include "yans-wifi-channel.h" +#include "yans-wifi-phy.h" +#include "wifi-net-device.h" +#include "propagation-loss-model.h" +#include "propagation-delay-model.h" + +NS_LOG_COMPONENT_DEFINE ("YansWifiChannel"); + +namespace ns3 { + +TypeId +YansWifiChannel::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::YansWifiChannel") + .SetParent () + .AddConstructor () + .AddAttribute ("PropagationLossModel", "A pointer to the propagation loss model attached to this channel.", + PointerValue (), + MakePointerAccessor (&YansWifiChannel::m_loss), + MakePointerChecker ()) + .AddAttribute ("PropagationDelayModel", "A pointer to the propagation delay model attached to this channel.", + PointerValue (), + MakePointerAccessor (&YansWifiChannel::m_delay), + MakePointerChecker ()) + ; + return tid; +} + +YansWifiChannel::YansWifiChannel () +{} +YansWifiChannel::~YansWifiChannel () +{ + m_deviceList.clear (); +} + +void +YansWifiChannel::SetPropagationLossModel (Ptr loss) +{ + m_loss = loss; +} +void +YansWifiChannel::SetPropagationDelayModel (Ptr delay) +{ + m_delay = delay; +} + +void +YansWifiChannel::Send (Ptr sender, Ptr packet, double txPowerDbm, + WifiMode wifiMode, WifiPreamble preamble) const +{ + Ptr senderMobility = 0; + for (DeviceList::const_iterator i = m_deviceList.begin (); i != m_deviceList.end (); i++) + { + if (sender == i->phy) + { + senderMobility = i->mobility->GetObject (); + break; + } + } + NS_ASSERT (senderMobility != 0); + uint32_t j = 0; + for (DeviceList::const_iterator i = m_deviceList.begin (); i != m_deviceList.end (); i++) + { + if (sender != i->phy) + { + Ptr receiverMobility = i->mobility->GetObject (); + Time delay = m_delay->GetDelay (senderMobility, receiverMobility); + double rxPowerDbm = txPowerDbm + m_loss->GetLoss (senderMobility, receiverMobility); + NS_LOG_DEBUG ("propagation: txPower="< phy = factory.Create (); + phy->SetChannel (this); + struct Item item; + item.device = device; + item.phy = phy; + item.mobility = mobility; + m_deviceList.push_back (item); + return phy; +} + +} // namespace ns3 diff --git a/src/devices/wifi/yans-wifi-channel.h b/src/devices/wifi/yans-wifi-channel.h new file mode 100644 index 000000000..4e3f0d390 --- /dev/null +++ b/src/devices/wifi/yans-wifi-channel.h @@ -0,0 +1,120 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2006,2007 INRIA + * + * 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 YANS_WIFI_CHANNEL_H +#define YANS_WIFI_CHANNEL_H + +#include +#include +#include "ns3/packet.h" +#include "wifi-channel.h" +#include "wifi-mode.h" +#include "wifi-preamble.h" + +namespace ns3 { + +class NetDevice; +class WifiNetDevice; +class PropagationLossModel; +class PropagationDelayModel; +class YansWifiPhy; + +/** + * \brief A Yans wifi channel + * + * This wifi channel implements the propagation model described in + * "Yet Another Network Simulator", (http://cutebugs.net/files/wns2-yans.pdf). + * + * This class is expected to be used in tandem with the ns3::YansWifiPhy + * class and contains a ns3::PropagationLossModel and a ns3::PropagationDelayModel. + * By default, no propagation models are set so, it is the caller's responsability + * to set them before using the channel. + */ +class YansWifiChannel : public WifiChannel +{ +public: + static TypeId GetTypeId (void); + + YansWifiChannel (); + virtual ~YansWifiChannel (); + + /** + * \returns the number of network interfaces connected to + * this channel. + * + * Overriden from the NetDevice base class. + */ + virtual uint32_t GetNDevices (void) const; + + /** + * \param i index of the requested network interface. + * \returns the requested network interfaces connected to + * this channel. + * + * Overriden from the NetDevice base class. + * Indexes start at 0 and end at n-1. + */ + virtual Ptr GetDevice (uint32_t i) const; + + virtual Ptr CreatePhy (Ptr device, + Ptr mobility, + UnsafeAttributeList list); + + /** + * \param loss the new propagation loss model. + */ + void SetPropagationLossModel (Ptr loss); + /** + * \param delay the new propagation delay model. + */ + void SetPropagationDelayModel (Ptr delay); + + /** + * \param sender the device from which the packet is originating. + * \param packet the packet to send + * \param txPowerDbm the tx power associated to the packet + * \param wifiMode the tx mode associated to the packet + * \param preamble the preamble associated to the packet + * + * This method should not be invoked by normal users. It is + * currently invoked only from WifiPhy::Send. + */ + void Send (Ptr sender, Ptr packet, double txPowerDbm, + WifiMode wifiMode, WifiPreamble preamble) const; + +private: + struct Item { + Ptr device; + Ptr phy; + Ptr mobility; + }; + typedef std::vector DeviceList; + void Receive (uint32_t i, Ptr packet, double rxPowerDbm, + WifiMode txMode, WifiPreamble preamble) const; + + + DeviceList m_deviceList; + Ptr m_loss; + Ptr m_delay; +}; + +} // namespace ns3 + + +#endif /* YANS_WIFI_CHANNEL_H */ diff --git a/src/devices/wifi/yans-wifi-phy.cc b/src/devices/wifi/yans-wifi-phy.cc index a1fd6206f..8dc9445fe 100644 --- a/src/devices/wifi/yans-wifi-phy.cc +++ b/src/devices/wifi/yans-wifi-phy.cc @@ -20,7 +20,7 @@ #include "yans-wifi-phy.h" #include "wifi-mode.h" -#include "wifi-channel.h" +#include "yans-wifi-channel.h" #include "wifi-preamble.h" #include "ns3/simulator.h" #include "ns3/packet.h" @@ -341,7 +341,7 @@ YansWifiPhy::GetChannel (void) const } void -YansWifiPhy::SetChannel (Ptr channel) +YansWifiPhy::SetChannel (Ptr channel) { m_channel = channel; } diff --git a/src/devices/wifi/yans-wifi-phy.h b/src/devices/wifi/yans-wifi-phy.h index 54e9edfe4..92a42af67 100644 --- a/src/devices/wifi/yans-wifi-phy.h +++ b/src/devices/wifi/yans-wifi-phy.h @@ -42,7 +42,7 @@ namespace ns3 { class RandomUniform; class RxEvent; -class WifiChannel; +class YansWifiChannel; /** @@ -57,7 +57,7 @@ class WifiChannel; * This PHY model depends on a channel loss and delay * model as provided by the ns3::PropagationLossModel * and ns3::PropagationDelayModel classes, both of which are - * members of the ns3::WifiChannel class. + * members of the ns3::YansWifiChannel class. */ class YansWifiPhy : public WifiPhy { @@ -68,6 +68,12 @@ public: YansWifiPhy (); virtual ~YansWifiPhy (); + void SetChannel (Ptr channel); + void StartReceivePacket (Ptr packet, + double rxPowerDbm, + WifiMode mode, + WifiPreamble preamble); + void SetStandard (enum WifiPhyStandard standard); void SetRxNoise (double ratio); void SetTxPowerStart (double start); @@ -85,7 +91,6 @@ public: virtual double GetTxPowerStart (void) const; virtual double GetTxPowerEnd (void) const; virtual uint32_t GetNTxPower (void) const; - virtual void SetChannel (Ptr channel); virtual void SetReceiveOkCallback (WifiPhy::SyncOkCallback callback); virtual void SetReceiveErrorCallback (WifiPhy::SyncErrorCallback callback); virtual void SendPacket (Ptr packet, WifiMode mode, enum WifiPreamble preamble, uint8_t txPowerLevel); @@ -102,10 +107,6 @@ public: virtual uint32_t GetNModes (void) const; virtual WifiMode GetMode (uint32_t mode) const; virtual double CalculateSnr (WifiMode txMode, double ber) const; - virtual void StartReceivePacket (Ptr packet, - double rxPowerDbm, - WifiMode mode, - WifiPreamble preamble); virtual Ptr GetChannel (void) const; private: @@ -201,7 +202,7 @@ private: Time m_startCcaBusy; Time m_previousStateChangeTime; - Ptr m_channel; + Ptr m_channel; SyncOkCallback m_syncOkCallback; SyncErrorCallback m_syncErrorCallback; TracedCallback, double, WifiMode, enum WifiPreamble> m_rxOkTrace; diff --git a/src/helper/wifi-helper.cc b/src/helper/wifi-helper.cc index 75ecbdf62..94ddd59de 100644 --- a/src/helper/wifi-helper.cc +++ b/src/helper/wifi-helper.cc @@ -23,6 +23,7 @@ #include "ns3/wifi-phy.h" #include "ns3/wifi-remote-station-manager.h" #include "ns3/wifi-channel.h" +#include "ns3/yans-wifi-channel.h" #include "ns3/propagation-delay-model.h" #include "ns3/propagation-loss-model.h" #include "ns3/mobility-model.h" @@ -72,7 +73,6 @@ static void AsciiPhyRxOkEvent (std::ostream *os, std::string context, WifiHelper::WifiHelper () { m_stationManager.SetTypeId ("ns3::ArfWifiManager"); - m_phy.SetTypeId ("ns3::WifiPhy"); m_mac.SetTypeId ("ns3::AdhocWifiMac"); } @@ -123,26 +123,9 @@ WifiHelper::SetMac (std::string type, } void -WifiHelper::SetPhy (std::string type, - std::string n0, const AttributeValue &v0, - std::string n1, const AttributeValue &v1, - std::string n2, const AttributeValue &v2, - std::string n3, const AttributeValue &v3, - std::string n4, const AttributeValue &v4, - std::string n5, const AttributeValue &v5, - std::string n6, const AttributeValue &v6, - std::string n7, const AttributeValue &v7) +WifiHelper::SetPhyAttribute (std::string name, const AttributeValue &value) { - m_phy = ObjectFactory (); - m_phy.SetTypeId (type); - m_phy.Set (n0, v0); - m_phy.Set (n1, v1); - m_phy.Set (n2, v2); - m_phy.Set (n3, v3); - m_phy.Set (n4, v4); - m_phy.Set (n5, v5); - m_phy.Set (n6, v6); - m_phy.Set (n7, v7); + m_phyAttributes.Set (name, value); } void @@ -234,7 +217,7 @@ WifiHelper::EnableAsciiAll (std::ostream &os) NetDeviceContainer WifiHelper::Install (NodeContainer c) const { - Ptr channel = CreateObject (); + Ptr channel = CreateObject (); channel->SetPropagationDelayModel (CreateObject ()); Ptr log = CreateObject (); log->SetReferenceModel (CreateObject ()); @@ -251,7 +234,7 @@ WifiHelper::Install (NodeContainer c, Ptr channel) const Ptr device = CreateObject (); Ptr manager = m_stationManager.Create (); Ptr mac = m_mac.Create (); - Ptr phy = m_phy.Create (); + Ptr phy = channel->CreatePhy (device, node, m_phyAttributes); mac->SetAddress (Mac48Address::Allocate ()); device->SetMac (mac); device->SetPhy (phy); diff --git a/src/helper/wifi-helper.h b/src/helper/wifi-helper.h index 35ec3141b..9b8cae398 100644 --- a/src/helper/wifi-helper.h +++ b/src/helper/wifi-helper.h @@ -107,36 +107,11 @@ public: std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); /** - * \param phyType the type of ns3::WifiPhy to create. - * \param n0 the name of the attribute to set - * \param v0 the value of the attribute to set - * \param n1 the name of the attribute to set - * \param v1 the value of the attribute to set - * \param n2 the name of the attribute to set - * \param v2 the value of the attribute to set - * \param n3 the name of the attribute to set - * \param v3 the value of the attribute to set - * \param n4 the name of the attribute to set - * \param v4 the value of the attribute to set - * \param n5 the name of the attribute to set - * \param v5 the value of the attribute to set - * \param n6 the name of the attribute to set - * \param v6 the value of the attribute to set - * \param n7 the name of the attribute to set - * \param v7 the value of the attribute to set + * \param name the name of the attribute to set + * \param value the value of the attribute to set * - * All the attributes specified in this method should exist - * in the requested phy. */ - void SetPhy (std::string phyType, - std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), - std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), - std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), - std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), - std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), - std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), - std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), - std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); + void SetPhyAttribute (std::string n0, const AttributeValue &v0); @@ -249,7 +224,7 @@ public: private: ObjectFactory m_stationManager; ObjectFactory m_mac; - ObjectFactory m_phy; + UnsafeAttributeList m_phyAttributes; }; } // namespace ns3