A Discrete-Event Network Simulator
API
mesh-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008,2009 IITP RAS
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Kirill Andreev <andreev@iitp.ru>
19  * Pavel Boyko <boyko@iitp.ru>
20  */
21 
22 #include "mesh-helper.h"
23 #include "ns3/simulator.h"
24 #include "ns3/pointer.h"
25 #include "ns3/mesh-point-device.h"
26 #include "ns3/wifi-net-device.h"
27 #include "ns3/minstrel-wifi-manager.h"
28 #include "ns3/mesh-wifi-interface-mac.h"
29 #include "ns3/wifi-helper.h"
30 #include "ns3/wifi-ack-policy-selector.h"
31 #include "ns3/frame-exchange-manager.h"
32 #include "ns3/wifi-default-protection-manager.h"
33 #include "ns3/wifi-default-ack-manager.h"
34 
35 namespace ns3
36 {
38  m_nInterfaces (1),
39  m_spreadChannelPolicy (ZERO_CHANNEL),
40  m_stack (0),
41  m_standard (WIFI_STANDARD_80211a)
42 {
43 }
45 {
46  m_stack = 0;
47 }
48 void
50 {
51  m_spreadChannelPolicy = policy;
52 }
53 void
55  std::string n0, const AttributeValue &v0,
56  std::string n1, const AttributeValue &v1,
57  std::string n2, const AttributeValue &v2,
58  std::string n3, const AttributeValue &v3,
59  std::string n4, const AttributeValue &v4,
60  std::string n5, const AttributeValue &v5,
61  std::string n6, const AttributeValue &v6,
62  std::string n7, const AttributeValue &v7)
63 {
65  m_stackFactory.Set (n0, v0);
66  m_stackFactory.Set (n1, v1);
67  m_stackFactory.Set (n2, v2);
68  m_stackFactory.Set (n3, v3);
69  m_stackFactory.Set (n4, v4);
70  m_stackFactory.Set (n5, v5);
71  m_stackFactory.Set (n6, v6);
72  m_stackFactory.Set (n7, v7);
73 
75  if (m_stack == 0)
76  {
77  NS_FATAL_ERROR ("Stack has not been created: " << type);
78  }
79 }
80 
81 void
82 MeshHelper::SetNumberOfInterfaces (uint32_t nInterfaces)
83 {
84  m_nInterfaces = nInterfaces;
85 }
87 MeshHelper::Install (const WifiPhyHelper &phyHelper, NodeContainer c) const
88 {
90  NS_ASSERT (m_stack != 0);
91  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
92  {
93  Ptr<Node> node = *i;
94  // Create a mesh point device
95  Ptr<MeshPointDevice> mp = CreateObject<MeshPointDevice> ();
96  node->AddDevice (mp);
97  // Create wifi interfaces (single interface by default)
98  for (uint32_t i = 0; i < m_nInterfaces; ++i)
99  {
100  uint32_t channel = 0;
102  {
103  channel = 0;
104  }
106  {
107  channel = i * 5;
108  }
109  Ptr<WifiNetDevice> iface = CreateInterface (phyHelper, node, channel);
110  mp->AddInterface (iface);
111  }
112  if (!m_stack->InstallStack (mp))
113  {
114  NS_FATAL_ERROR ("Stack is not installed!");
115  }
116  devices.Add (mp);
117  }
118  return devices;
119 }
122 {
123  MeshHelper helper;
124  helper.SetMacType ();
125  helper.SetRemoteStationManager ("ns3::ArfWifiManager");
126  helper.SetAckPolicySelectorForAc (AC_BE, "ns3::ConstantWifiAckPolicySelector");
127  helper.SetAckPolicySelectorForAc (AC_BK, "ns3::ConstantWifiAckPolicySelector");
128  helper.SetAckPolicySelectorForAc (AC_VI, "ns3::ConstantWifiAckPolicySelector");
129  helper.SetAckPolicySelectorForAc (AC_VO, "ns3::ConstantWifiAckPolicySelector");
131  return helper;
132 }
133 
134 void
135 MeshHelper::SetMacType (std::string n0, const AttributeValue &v0,
136  std::string n1, const AttributeValue &v1,
137  std::string n2, const AttributeValue &v2,
138  std::string n3, const AttributeValue &v3,
139  std::string n4, const AttributeValue &v4,
140  std::string n5, const AttributeValue &v5,
141  std::string n6, const AttributeValue &v6,
142  std::string n7, const AttributeValue &v7)
143 {
144  m_mac.SetTypeId ("ns3::MeshWifiInterfaceMac");
145  m_mac.Set (n0, v0);
146  m_mac.Set (n1, v1);
147  m_mac.Set (n2, v2);
148  m_mac.Set (n3, v3);
149  m_mac.Set (n4, v4);
150  m_mac.Set (n5, v5);
151  m_mac.Set (n6, v6);
152  m_mac.Set (n7, v7);
153 }
154 void
156  std::string n0, const AttributeValue &v0,
157  std::string n1, const AttributeValue &v1,
158  std::string n2, const AttributeValue &v2,
159  std::string n3, const AttributeValue &v3,
160  std::string n4, const AttributeValue &v4,
161  std::string n5, const AttributeValue &v5,
162  std::string n6, const AttributeValue &v6,
163  std::string n7, const AttributeValue &v7)
164 {
167  m_stationManager.Set (n0, v0);
168  m_stationManager.Set (n1, v1);
169  m_stationManager.Set (n2, v2);
170  m_stationManager.Set (n3, v3);
171  m_stationManager.Set (n4, v4);
172  m_stationManager.Set (n5, v5);
173  m_stationManager.Set (n6, v6);
174  m_stationManager.Set (n7, v7);
175 }
176 void
178  std::string n0, const AttributeValue &v0,
179  std::string n1, const AttributeValue &v1,
180  std::string n2, const AttributeValue &v2,
181  std::string n3, const AttributeValue &v3,
182  std::string n4, const AttributeValue &v4,
183  std::string n5, const AttributeValue &v5,
184  std::string n6, const AttributeValue &v6,
185  std::string n7, const AttributeValue &v7)
186 {
188  m_ackPolicySelector[ac].SetTypeId (type);
189  m_ackPolicySelector[ac].Set (n0, v0);
190  m_ackPolicySelector[ac].Set (n1, v1);
191  m_ackPolicySelector[ac].Set (n2, v2);
192  m_ackPolicySelector[ac].Set (n3, v3);
193  m_ackPolicySelector[ac].Set (n4, v4);
194  m_ackPolicySelector[ac].Set (n5, v5);
195  m_ackPolicySelector[ac].Set (n6, v6);
196  m_ackPolicySelector[ac].Set (n7, v7);
197 }
198 void
200 {
201  m_standard = standard;
202 }
203 
205 MeshHelper::CreateInterface (const WifiPhyHelper &phyHelper, Ptr<Node> node, uint16_t channelId) const
206 {
207  Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
208 
209  auto it = wifiStandards.find (m_standard);
210  if (it == wifiStandards.end ())
211  {
212  NS_FATAL_ERROR ("Selected standard is not defined!");
213  return device;
214  }
215 
217  NS_ASSERT (mac != 0);
218  mac->SetSsid (Ssid ());
219  mac->SetDevice (device);
221  NS_ASSERT (manager != 0);
222  Ptr<WifiPhy> phy = phyHelper.Create (node, device);
223  mac->SetAddress (Mac48Address::Allocate ());
224  mac->ConfigureStandard (m_standard);
225  Ptr<RegularWifiMac> wifiMac = DynamicCast<RegularWifiMac> (mac);
227  if (wifiMac != 0 && (fem = wifiMac->GetFrameExchangeManager ()) != 0)
228  {
229  Ptr<WifiProtectionManager> protectionManager = CreateObject<WifiDefaultProtectionManager> ();
230  protectionManager->SetWifiMac (wifiMac);
231  fem->SetProtectionManager (protectionManager);
232 
233  Ptr<WifiAckManager> ackManager = CreateObject<WifiDefaultAckManager> ();
234  ackManager->SetWifiMac (wifiMac);
235  fem->SetAckManager (ackManager);
236  }
237  phy->ConfigureStandardAndBand (it->second.phyStandard, it->second.phyBand);
238  device->SetMac (mac);
239  device->SetPhy (phy);
240  device->SetRemoteStationManager (manager);
241  node->AddDevice (device);
242  mac->SwitchFrequencyChannel (channelId);
243  // Install ack policy selector
244  PointerValue ptr;
245  Ptr<WifiAckPolicySelector> ackSelector;
246 
247  mac->GetAttributeFailSafe ("BE_Txop", ptr);
249  ackSelector->SetQosTxop (ptr.Get<QosTxop> ());
250  ptr.Get<QosTxop> ()->SetAckPolicySelector (ackSelector);
251 
252  mac->GetAttributeFailSafe ("BK_Txop", ptr);
254  ackSelector->SetQosTxop (ptr.Get<QosTxop> ());
255  ptr.Get<QosTxop> ()->SetAckPolicySelector (ackSelector);
256 
257  mac->GetAttributeFailSafe ("VI_Txop", ptr);
259  ackSelector->SetQosTxop (ptr.Get<QosTxop> ());
260  ptr.Get<QosTxop> ()->SetAckPolicySelector (ackSelector);
261 
262  mac->GetAttributeFailSafe ("VO_Txop", ptr);
264  ackSelector->SetQosTxop (ptr.Get<QosTxop> ());
265  ptr.Get<QosTxop> ()->SetAckPolicySelector (ackSelector);
266 
267  return device;
268 }
269 void
270 MeshHelper::Report (const ns3::Ptr<ns3::NetDevice>& device, std::ostream& os)
271 {
272  NS_ASSERT (m_stack != 0);
274  NS_ASSERT (mp != 0);
275  std::vector<Ptr<NetDevice> > ifaces = mp->GetInterfaces ();
276  os << "<MeshPointDevice time=\"" << Simulator::Now ().GetSeconds () << "\" address=\""
277  << Mac48Address::ConvertFrom (mp->GetAddress ()) << "\">\n";
278  m_stack->Report (mp, os);
279  os << "</MeshPointDevice>\n";
280 }
281 void
283 {
284  NS_ASSERT (m_stack != 0);
286  NS_ASSERT (mp != 0);
287  m_stack->ResetStats (mp);
288 }
289 int64_t
291 {
292  int64_t currentStream = stream;
293  Ptr<NetDevice> netDevice;
294  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
295  {
296  netDevice = (*i);
297  Ptr<MeshPointDevice> mpd = DynamicCast<MeshPointDevice> (netDevice);
300  if (mpd)
301  {
302  // To access, we need the underlying WifiNetDevices
303  std::vector<Ptr<NetDevice> > ifaces = mpd->GetInterfaces ();
304  for (std::vector<Ptr<NetDevice> >::iterator i = ifaces.begin (); i != ifaces.end (); i++)
305  {
306  wifi = DynamicCast<WifiNetDevice> (*i);
307 
308  // Handle any random numbers in the PHY objects.
309  currentStream += wifi->GetPhy ()->AssignStreams (currentStream);
310 
311  // Handle any random numbers in the station managers.
312  Ptr<WifiRemoteStationManager> manager = wifi->GetRemoteStationManager ();
313  Ptr<MinstrelWifiManager> minstrel = DynamicCast<MinstrelWifiManager> (manager);
314  if (minstrel)
315  {
316  currentStream += minstrel->AssignStreams (currentStream);
317  }
318  // Handle any random numbers in the mesh mac and plugins
319  mac = DynamicCast<MeshWifiInterfaceMac> (wifi->GetMac ());
320  if (mac)
321  {
322  currentStream += mac->AssignStreams (currentStream);
323  }
324  Ptr<RegularWifiMac> rmac = DynamicCast<RegularWifiMac> (mac);
325  if (rmac)
326  {
327  PointerValue ptr;
328  rmac->GetAttribute ("Txop", ptr);
329  Ptr<Txop> txop = ptr.Get<Txop> ();
330  currentStream += txop->AssignStreams (currentStream);
331 
332  rmac->GetAttribute ("VO_Txop", ptr);
333  Ptr<QosTxop> vo_txop = ptr.Get<QosTxop> ();
334  currentStream += vo_txop->AssignStreams (currentStream);
335 
336  rmac->GetAttribute ("VI_Txop", ptr);
337  Ptr<QosTxop> vi_txop = ptr.Get<QosTxop> ();
338  currentStream += vi_txop->AssignStreams (currentStream);
339 
340  rmac->GetAttribute ("BE_Txop", ptr);
341  Ptr<QosTxop> be_txop = ptr.Get<QosTxop> ();
342  currentStream += be_txop->AssignStreams (currentStream);
343 
344  rmac->GetAttribute ("BK_Txop", ptr);
345  Ptr<QosTxop> bk_txop = ptr.Get<QosTxop> ();
346  currentStream += bk_txop->AssignStreams (currentStream);
347  }
348  }
349  }
350  }
351  return (currentStream - stream);
352 }
353 
354 } // namespace ns3
355 
Ptr< WifiNetDevice > CreateInterface(const WifiPhyHelper &phyHelper, Ptr< Node > node, uint16_t channelId) const
Definition: mesh-helper.cc:205
Ptr< T > Get(void) const
Definition: pointer.h:201
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
ObjectFactory m_ackPolicySelector[4]
ack policy selector for all ACs
Definition: mesh-helper.h:267
Hold a value for an Attribute.
Definition: attribute.h:68
create PHY objects
Definition: wifi-helper.h:46
void Report(const ns3::Ptr< ns3::NetDevice > &device, std::ostream &os)
Print statistics.
Definition: mesh-helper.cc:270
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: mesh-helper.cc:155
ChannelPolicy m_spreadChannelPolicy
spread channel policy
Definition: mesh-helper.h:260
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
Definition: qos-txop.h:94
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:380
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
void SetAckPolicySelectorForAc(AcIndex ac, 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: mesh-helper.cc:177
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
Video.
Definition: qos-utils.h:64
Voice.
Definition: qos-utils.h:66
Best Effort.
Definition: qos-utils.h:60
const std::map< WifiStandard, WifiStandardInfo > wifiStandards
map a given standard configured by the user to the corresponding WifiStandardInfo ...
void SetNumberOfInterfaces(uint32_t nInterfaces)
Set a number of interfaces in a mesh network.
Definition: mesh-helper.cc:82
Prototype for class, which helps to install MAC-layer routing stack to ns3::MeshPointDevice.
channel
Definition: third.py:92
MeshHelper()
Construct a MeshHelper used to make life easier when creating 802.11s networks.
Definition: mesh-helper.cc:37
phy
Definition: third.py:93
void SetStandard(enum WifiStandard standard)
Set standard.
Definition: mesh-helper.cc:199
Background.
Definition: qos-utils.h:62
void SetSpreadInterfaceChannels(ChannelPolicy policy)
set the channel policy
Definition: mesh-helper.cc:49
uint32_t m_nInterfaces
number of interfaces
Definition: mesh-helper.h:259
static Mac48Address Allocate(void)
Allocate a new Mac48Address.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
void SetMac(const Ptr< WifiMac > mac)
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: txop.cc:332
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
ObjectFactory m_mac
the MAC
Definition: mesh-helper.h:265
holds a vector of ns3::NetDevice pointers
mac
Definition: third.py:99
ObjectFactory m_stackFactory
stack factory
Definition: mesh-helper.h:262
Ptr< MeshStack > m_stack
stack
Definition: mesh-helper.h:261
hold a list of per-remote-station state.
void SetMacType(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: mesh-helper.cc:135
static Mac48Address ConvertFrom(const Address &address)
ChannelPolicy
Spread/not spread frequency channels of MP interfaces.
Definition: mesh-helper.h:169
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiStandard
Identifies the allowed configurations that a Wifi device is configured to use.
keep track of a set of node pointers.
Hold objects of type Ptr<T>.
Definition: pointer.h:36
ObjectFactory m_stationManager
the station manager
Definition: mesh-helper.h:266
void ResetStats(const ns3::Ptr< ns3::NetDevice > &device)
Reset statistics.
Definition: mesh-helper.cc:282
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: mesh-helper.cc:290
void SetStackInstaller(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: mesh-helper.cc:54
Virtual net device modeling mesh point.
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:35
enum WifiStandard m_standard
standard
Definition: mesh-helper.h:268
wifi
Definition: third.py:96
Instantiate subclasses of ns3::Object.
void SetPhy(const Ptr< WifiPhy > phy)
NetDeviceContainer Install(const WifiPhyHelper &phyHelper, NodeContainer c) const
Install 802.11s mesh device & protocols on given node list.
Definition: mesh-helper.cc:87
virtual Ptr< WifiPhy > Create(Ptr< Node > node, Ptr< NetDevice > device) const =0
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:130
std::vector< Ptr< NetDevice > >::const_iterator Iterator
NetDevice container iterator.
static MeshHelper Default()
Set the helper to the default values for the MAC type, remote station manager and channel policy...
Definition: mesh-helper.cc:121
Helper to create IEEE 802.11s mesh networks.
Definition: mesh-helper.h:43
devices
Definition: first.py:39
~MeshHelper()
Destroy a MeshHelper.
Definition: mesh-helper.cc:44
WifiAckPolicySelector is in charge of selecting the acknowledgment policy for PSDUs containing QoS Da...
std::string m_stack
Basic MAC of mesh point Wi-Fi interface.
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:57
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
void SetRemoteStationManager(const Ptr< WifiRemoteStationManager > manager)
Handle packet fragmentation and retransmissions for data and management frames.
Definition: txop.h:66