A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
wifi-helper.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 INRIA
4  * Copyright (c) 2009 MIRKO BANCHI
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Author: Mirko Banchi <mk.banchi@gmail.com>
21  */
22 #include "wifi-helper.h"
23 #include "ns3/wifi-net-device.h"
24 #include "ns3/wifi-mac.h"
25 #include "ns3/regular-wifi-mac.h"
26 #include "ns3/dca-txop.h"
27 #include "ns3/edca-txop-n.h"
28 #include "ns3/minstrel-wifi-manager.h"
29 #include "ns3/wifi-phy.h"
30 #include "ns3/wifi-remote-station-manager.h"
31 #include "ns3/wifi-channel.h"
32 #include "ns3/yans-wifi-channel.h"
33 #include "ns3/propagation-delay-model.h"
34 #include "ns3/propagation-loss-model.h"
35 #include "ns3/mobility-model.h"
36 #include "ns3/log.h"
37 #include "ns3/config.h"
38 #include "ns3/pointer.h"
39 #include "ns3/simulator.h"
40 #include "ns3/names.h"
41 
42 NS_LOG_COMPONENT_DEFINE ("WifiHelper");
43 
44 namespace ns3 {
45 
46 WifiPhyHelper::~WifiPhyHelper ()
47 {
48 }
49 
50 WifiMacHelper::~WifiMacHelper ()
51 {
52 }
53 
55  : m_standard (WIFI_PHY_STANDARD_80211a)
56 {
57 }
58 
61 {
62  WifiHelper helper;
63  helper.SetRemoteStationManager ("ns3::ArfWifiManager");
64  return helper;
65 }
66 
67 void
69  std::string n0, const AttributeValue &v0,
70  std::string n1, const AttributeValue &v1,
71  std::string n2, const AttributeValue &v2,
72  std::string n3, const AttributeValue &v3,
73  std::string n4, const AttributeValue &v4,
74  std::string n5, const AttributeValue &v5,
75  std::string n6, const AttributeValue &v6,
76  std::string n7, const AttributeValue &v7)
77 {
78  m_stationManager = ObjectFactory ();
79  m_stationManager.SetTypeId (type);
80  m_stationManager.Set (n0, v0);
81  m_stationManager.Set (n1, v1);
82  m_stationManager.Set (n2, v2);
83  m_stationManager.Set (n3, v3);
84  m_stationManager.Set (n4, v4);
85  m_stationManager.Set (n5, v5);
86  m_stationManager.Set (n6, v6);
87  m_stationManager.Set (n7, v7);
88 }
89 
90 void
92 {
93  m_standard = standard;
94 }
95 
98  const WifiMacHelper &macHelper, NodeContainer c) const
99 {
100  NetDeviceContainer devices;
101  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
102  {
103  Ptr<Node> node = *i;
104  Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
105  Ptr<WifiRemoteStationManager> manager = m_stationManager.Create<WifiRemoteStationManager> ();
106  Ptr<WifiMac> mac = macHelper.Create ();
107  Ptr<WifiPhy> phy = phyHelper.Create (node, device);
108  mac->SetAddress (Mac48Address::Allocate ());
109  mac->ConfigureStandard (m_standard);
110  phy->ConfigureStandard (m_standard);
111  device->SetMac (mac);
112  device->SetPhy (phy);
113  device->SetRemoteStationManager (manager);
114  node->AddDevice (device);
115  devices.Add (device);
116  NS_LOG_DEBUG ("node=" << node << ", mob=" << node->GetObject<MobilityModel> ());
117  }
118  return devices;
119 }
120 
123  const WifiMacHelper &mac, Ptr<Node> node) const
124 {
125  return Install (phy, mac, NodeContainer (node));
126 }
127 
130  const WifiMacHelper &mac, std::string nodeName) const
131 {
132  Ptr<Node> node = Names::Find<Node> (nodeName);
133  return Install (phy, mac, NodeContainer (node));
134 }
135 
138  const MobilityHelper &mobiHelper,
139  const WifiPhyHelper &phyHelper,
140  const WifiMacHelper &macHelper,
141  NodeContainer c) const
142 {
143  mobiHelper.Install(c);
144  NetDeviceContainer devices;
145  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
146  {
147  Ptr<Node> node = *i;
148  node->SetCognitiveRadio(true);
149  for (int x=0; x<MAX_RADIO; x++)
150  {
151  Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
152  Ptr<WifiRemoteStationManager> manager = m_stationManager.Create<WifiRemoteStationManager> ();
153  Ptr<WifiMac> mac = macHelper.Create ();
154  Ptr<WifiPhy> phy = phyHelper.Create (node, device);
155  mac->SetAddress (Mac48Address::Allocate ());
156  mac->ConfigureStandard (m_standard);
157  if (x == TRANSMITTER_RADIO)
158  mac->SetTxRadio (true);
159  if (x == RECEIVER_RADIO)
160  {
161  mac->SetRxRadio(true, node, repo, puModel, phy);
162  }
163  phy->ConfigureStandard (m_standard);
164  device->SetMac (mac);
165  device->SetPhy (phy);
166  device->SetRemoteStationManager (manager);
167  node->AddDevice (device);
168  devices.Add (device);
169  NS_LOG_DEBUG ("node=" << node << ", mob=" << node->GetObject<MobilityModel> ());
170  }
171  }
172  return devices;
173 }
174 
175 void
177 {
178  LogComponentEnable ("Aarfcd", LOG_LEVEL_ALL);
179  LogComponentEnable ("AdhocWifiMac", LOG_LEVEL_ALL);
180  LogComponentEnable ("AmrrWifiRemoteStation", LOG_LEVEL_ALL);
181  LogComponentEnable ("ApWifiMac", LOG_LEVEL_ALL);
182  LogComponentEnable ("ns3::ArfWifiManager", LOG_LEVEL_ALL);
183  LogComponentEnable ("Cara", LOG_LEVEL_ALL);
184  LogComponentEnable ("DcaTxop", LOG_LEVEL_ALL);
185  LogComponentEnable ("DcfManager", LOG_LEVEL_ALL);
186  LogComponentEnable ("DsssErrorRateModel", LOG_LEVEL_ALL);
187  LogComponentEnable ("EdcaTxopN", LOG_LEVEL_ALL);
188  LogComponentEnable ("InterferenceHelper", LOG_LEVEL_ALL);
189  LogComponentEnable ("Jakes", LOG_LEVEL_ALL);
190  LogComponentEnable ("MacLow", LOG_LEVEL_ALL);
191  LogComponentEnable ("MacRxMiddle", LOG_LEVEL_ALL);
192  LogComponentEnable ("MsduAggregator", LOG_LEVEL_ALL);
193  LogComponentEnable ("MsduStandardAggregator", LOG_LEVEL_ALL);
194  LogComponentEnable ("NistErrorRateModel", LOG_LEVEL_ALL);
195  LogComponentEnable ("OnoeWifiRemoteStation", LOG_LEVEL_ALL);
196  LogComponentEnable ("PropagationLossModel", LOG_LEVEL_ALL);
197  LogComponentEnable ("RegularWifiMac", LOG_LEVEL_ALL);
198  LogComponentEnable ("RraaWifiManager", LOG_LEVEL_ALL);
199  LogComponentEnable ("StaWifiMac", LOG_LEVEL_ALL);
200  LogComponentEnable ("SupportedRates", LOG_LEVEL_ALL);
201  LogComponentEnable ("WifiChannel", LOG_LEVEL_ALL);
202  LogComponentEnable ("WifiPhyStateHelper", LOG_LEVEL_ALL);
203  LogComponentEnable ("WifiPhy", LOG_LEVEL_ALL);
204  LogComponentEnable ("WifiRemoteStationManager", LOG_LEVEL_ALL);
205  LogComponentEnable ("YansErrorRateModel", LOG_LEVEL_ALL);
206  LogComponentEnable ("YansWifiChannel", LOG_LEVEL_ALL);
207  LogComponentEnable ("YansWifiPhy", LOG_LEVEL_ALL);
208 }
209 
210 int64_t
212 {
213  int64_t currentStream = stream;
214  Ptr<NetDevice> netDevice;
215  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
216  {
217  netDevice = (*i);
218  Ptr<WifiNetDevice> wifi = DynamicCast<WifiNetDevice> (netDevice);
219  if (wifi)
220  {
221  // Handle any random numbers in the PHY objects.
222  currentStream += wifi->GetPhy ()->AssignStreams (currentStream);
223 
224  // Handle any random numbers in the station managers.
225  Ptr<WifiRemoteStationManager> manager = wifi->GetRemoteStationManager ();
226  Ptr<MinstrelWifiManager> minstrel = DynamicCast<MinstrelWifiManager> (manager);
227  if (minstrel)
228  {
229  currentStream += minstrel->AssignStreams (currentStream);
230  }
231 
232  // Handle any random numbers in the MAC objects.
233  Ptr<WifiMac> mac = wifi->GetMac ();
234  Ptr<RegularWifiMac> rmac = DynamicCast<RegularWifiMac> (mac);
235  if (rmac)
236  {
237  PointerValue ptr;
238  rmac->GetAttribute ("DcaTxop", ptr);
239  Ptr<DcaTxop> dcaTxop = ptr.Get<DcaTxop> ();
240  currentStream += dcaTxop->AssignStreams (currentStream);
241 
242  rmac->GetAttribute ("VO_EdcaTxopN", ptr);
243  Ptr<EdcaTxopN> vo_edcaTxopN = ptr.Get<EdcaTxopN> ();
244  currentStream += vo_edcaTxopN->AssignStreams (currentStream);
245 
246  rmac->GetAttribute ("VI_EdcaTxopN", ptr);
247  Ptr<EdcaTxopN> vi_edcaTxopN = ptr.Get<EdcaTxopN> ();
248  currentStream += vi_edcaTxopN->AssignStreams (currentStream);
249 
250  rmac->GetAttribute ("BE_EdcaTxopN", ptr);
251  Ptr<EdcaTxopN> be_edcaTxopN = ptr.Get<EdcaTxopN> ();
252  currentStream += be_edcaTxopN->AssignStreams (currentStream);
253 
254  rmac->GetAttribute ("BK_EdcaTxopN", ptr);
255  Ptr<EdcaTxopN> bk_edcaTxopN = ptr.Get<EdcaTxopN> ();
256  currentStream += bk_edcaTxopN->AssignStreams (currentStream);
257  }
258  }
259  }
260  return (currentStream - stream);
261 }
262 
263 } // namespace ns3
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
NetDeviceContainer InstallCR(Ptr< Repository > repo, Ptr< PUModel > puModel, const MobilityHelper &mobiHelper, const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wifi-helper.cc:137
void SetRemoteStationManager(std::string type, 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())
Definition: wifi-helper.cc:68
Hold a value for an Attribute.
Definition: attribute.h:51
create PHY objects
Definition: wifi-helper.h:50
virtual Ptr< WifiMac > Create(void) const =0
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
void SetTypeId(TypeId tid)
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:92
NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wifi-helper.cc:97
Keep track of the current position and velocity of an object.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
static Mac48Address Allocate(void)
Ptr< Object > Create(void) const
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
holds a vector of ns3::NetDevice pointers
void SetStandard(enum WifiPhyStandard standard)
Definition: wifi-helper.cc:91
int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Definition: wifi-helper.cc:211
int64_t AssignStreams(int64_t stream)
hold a list of per-remote-station state.
keep track of a set of node pointers.
hold objects of type Ptr<T>
Definition: pointer.h:33
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
void Set(std::string name, const AttributeValue &value)
virtual Ptr< WifiPhy > Create(Ptr< Node > node, Ptr< WifiNetDevice > device) const =0
create MAC objects
Definition: wifi-helper.h:72
Helper class used to assign positions and mobility models to nodes.
instantiate subclasses of ns3::Object.
static void EnableLogComponents(void)
Definition: wifi-helper.cc:176
uint32_t AddDevice(Ptr< NetDevice > device)
Definition: node.cc:119
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
handle packet fragmentation and retransmissions.This class implements the packet fragmentation and re...
Definition: dca-txop.h:70
Ptr< T > GetObject(void) const
Definition: object.h:332
void LogComponentEnable(char const *name, enum LogLevel level)
Definition: log.cc:311
static WifiHelper Default(void)
Definition: wifi-helper.cc:60