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 
32 namespace ns3
33 {
35  m_nInterfaces (1),
36  m_spreadChannelPolicy (ZERO_CHANNEL),
37  m_stack (0),
38  m_standard (WIFI_STANDARD_80211a)
39 {
40 }
42 {
43  m_stack = 0;
44 }
45 void
47 {
48  m_spreadChannelPolicy = policy;
49 }
50 void
52  std::string n0, const AttributeValue &v0,
53  std::string n1, const AttributeValue &v1,
54  std::string n2, const AttributeValue &v2,
55  std::string n3, const AttributeValue &v3,
56  std::string n4, const AttributeValue &v4,
57  std::string n5, const AttributeValue &v5,
58  std::string n6, const AttributeValue &v6,
59  std::string n7, const AttributeValue &v7)
60 {
62  m_stackFactory.Set (n0, v0);
63  m_stackFactory.Set (n1, v1);
64  m_stackFactory.Set (n2, v2);
65  m_stackFactory.Set (n3, v3);
66  m_stackFactory.Set (n4, v4);
67  m_stackFactory.Set (n5, v5);
68  m_stackFactory.Set (n6, v6);
69  m_stackFactory.Set (n7, v7);
70 
72  if (m_stack == 0)
73  {
74  NS_FATAL_ERROR ("Stack has not been created: " << type);
75  }
76 }
77 
78 void
79 MeshHelper::SetNumberOfInterfaces (uint32_t nInterfaces)
80 {
81  m_nInterfaces = nInterfaces;
82 }
84 MeshHelper::Install (const WifiPhyHelper &phyHelper, NodeContainer c) const
85 {
87  NS_ASSERT (m_stack != 0);
88  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
89  {
90  Ptr<Node> node = *i;
91  // Create a mesh point device
92  Ptr<MeshPointDevice> mp = CreateObject<MeshPointDevice> ();
93  node->AddDevice (mp);
94  // Create wifi interfaces (single interface by default)
95  for (uint32_t i = 0; i < m_nInterfaces; ++i)
96  {
97  uint32_t channel = 0;
99  {
100  channel = 0;
101  }
103  {
104  channel = i * 5;
105  }
106  Ptr<WifiNetDevice> iface = CreateInterface (phyHelper, node, channel);
107  mp->AddInterface (iface);
108  }
109  if (!m_stack->InstallStack (mp))
110  {
111  NS_FATAL_ERROR ("Stack is not installed!");
112  }
113  devices.Add (mp);
114  }
115  return devices;
116 }
119 {
120  MeshHelper helper;
121  helper.SetMacType ();
122  helper.SetRemoteStationManager ("ns3::ArfWifiManager");
123  helper.SetAckPolicySelectorForAc (AC_BE, "ns3::ConstantWifiAckPolicySelector");
124  helper.SetAckPolicySelectorForAc (AC_BK, "ns3::ConstantWifiAckPolicySelector");
125  helper.SetAckPolicySelectorForAc (AC_VI, "ns3::ConstantWifiAckPolicySelector");
126  helper.SetAckPolicySelectorForAc (AC_VO, "ns3::ConstantWifiAckPolicySelector");
128  return helper;
129 }
130 
131 void
132 MeshHelper::SetMacType (std::string n0, const AttributeValue &v0,
133  std::string n1, const AttributeValue &v1,
134  std::string n2, const AttributeValue &v2,
135  std::string n3, const AttributeValue &v3,
136  std::string n4, const AttributeValue &v4,
137  std::string n5, const AttributeValue &v5,
138  std::string n6, const AttributeValue &v6,
139  std::string n7, const AttributeValue &v7)
140 {
141  m_mac.SetTypeId ("ns3::MeshWifiInterfaceMac");
142  m_mac.Set (n0, v0);
143  m_mac.Set (n1, v1);
144  m_mac.Set (n2, v2);
145  m_mac.Set (n3, v3);
146  m_mac.Set (n4, v4);
147  m_mac.Set (n5, v5);
148  m_mac.Set (n6, v6);
149  m_mac.Set (n7, v7);
150 }
151 void
153  std::string n0, const AttributeValue &v0,
154  std::string n1, const AttributeValue &v1,
155  std::string n2, const AttributeValue &v2,
156  std::string n3, const AttributeValue &v3,
157  std::string n4, const AttributeValue &v4,
158  std::string n5, const AttributeValue &v5,
159  std::string n6, const AttributeValue &v6,
160  std::string n7, const AttributeValue &v7)
161 {
164  m_stationManager.Set (n0, v0);
165  m_stationManager.Set (n1, v1);
166  m_stationManager.Set (n2, v2);
167  m_stationManager.Set (n3, v3);
168  m_stationManager.Set (n4, v4);
169  m_stationManager.Set (n5, v5);
170  m_stationManager.Set (n6, v6);
171  m_stationManager.Set (n7, v7);
172 }
173 void
175  std::string n0, const AttributeValue &v0,
176  std::string n1, const AttributeValue &v1,
177  std::string n2, const AttributeValue &v2,
178  std::string n3, const AttributeValue &v3,
179  std::string n4, const AttributeValue &v4,
180  std::string n5, const AttributeValue &v5,
181  std::string n6, const AttributeValue &v6,
182  std::string n7, const AttributeValue &v7)
183 {
185  m_ackPolicySelector[ac].SetTypeId (type);
186  m_ackPolicySelector[ac].Set (n0, v0);
187  m_ackPolicySelector[ac].Set (n1, v1);
188  m_ackPolicySelector[ac].Set (n2, v2);
189  m_ackPolicySelector[ac].Set (n3, v3);
190  m_ackPolicySelector[ac].Set (n4, v4);
191  m_ackPolicySelector[ac].Set (n5, v5);
192  m_ackPolicySelector[ac].Set (n6, v6);
193  m_ackPolicySelector[ac].Set (n7, v7);
194 }
195 void
197 {
198  m_standard = standard;
199 }
200 
202 MeshHelper::CreateInterface (const WifiPhyHelper &phyHelper, Ptr<Node> node, uint16_t channelId) const
203 {
204  Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
205 
206  auto it = wifiStandards.find (m_standard);
207  if (it == wifiStandards.end ())
208  {
209  NS_FATAL_ERROR ("Selected standard is not defined!");
210  return device;
211  }
212 
214  NS_ASSERT (mac != 0);
215  mac->SetSsid (Ssid ());
216  mac->SetDevice (device);
218  NS_ASSERT (manager != 0);
219  Ptr<WifiPhy> phy = phyHelper.Create (node, device);
220  mac->SetAddress (Mac48Address::Allocate ());
221  mac->ConfigureStandard (m_standard);
222  phy->ConfigureStandardAndBand (it->second.phyStandard, it->second.phyBand);
223  device->SetMac (mac);
224  device->SetPhy (phy);
225  device->SetRemoteStationManager (manager);
226  node->AddDevice (device);
227  mac->SwitchFrequencyChannel (channelId);
228  // Install ack policy selector
229  PointerValue ptr;
230  Ptr<WifiAckPolicySelector> ackSelector;
231 
232  mac->GetAttributeFailSafe ("BE_Txop", ptr);
234  ackSelector->SetQosTxop (ptr.Get<QosTxop> ());
235  ptr.Get<QosTxop> ()->SetAckPolicySelector (ackSelector);
236 
237  mac->GetAttributeFailSafe ("BK_Txop", ptr);
239  ackSelector->SetQosTxop (ptr.Get<QosTxop> ());
240  ptr.Get<QosTxop> ()->SetAckPolicySelector (ackSelector);
241 
242  mac->GetAttributeFailSafe ("VI_Txop", ptr);
244  ackSelector->SetQosTxop (ptr.Get<QosTxop> ());
245  ptr.Get<QosTxop> ()->SetAckPolicySelector (ackSelector);
246 
247  mac->GetAttributeFailSafe ("VO_Txop", ptr);
249  ackSelector->SetQosTxop (ptr.Get<QosTxop> ());
250  ptr.Get<QosTxop> ()->SetAckPolicySelector (ackSelector);
251 
252  return device;
253 }
254 void
255 MeshHelper::Report (const ns3::Ptr<ns3::NetDevice>& device, std::ostream& os)
256 {
257  NS_ASSERT (m_stack != 0);
259  NS_ASSERT (mp != 0);
260  std::vector<Ptr<NetDevice> > ifaces = mp->GetInterfaces ();
261  os << "<MeshPointDevice time=\"" << Simulator::Now ().GetSeconds () << "\" address=\""
262  << Mac48Address::ConvertFrom (mp->GetAddress ()) << "\">\n";
263  m_stack->Report (mp, os);
264  os << "</MeshPointDevice>\n";
265 }
266 void
268 {
269  NS_ASSERT (m_stack != 0);
271  NS_ASSERT (mp != 0);
272  m_stack->ResetStats (mp);
273 }
274 int64_t
276 {
277  int64_t currentStream = stream;
278  Ptr<NetDevice> netDevice;
279  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
280  {
281  netDevice = (*i);
282  Ptr<MeshPointDevice> mpd = DynamicCast<MeshPointDevice> (netDevice);
285  if (mpd)
286  {
287  // To access, we need the underlying WifiNetDevices
288  std::vector<Ptr<NetDevice> > ifaces = mpd->GetInterfaces ();
289  for (std::vector<Ptr<NetDevice> >::iterator i = ifaces.begin (); i != ifaces.end (); i++)
290  {
291  wifi = DynamicCast<WifiNetDevice> (*i);
292 
293  // Handle any random numbers in the PHY objects.
294  currentStream += wifi->GetPhy ()->AssignStreams (currentStream);
295 
296  // Handle any random numbers in the station managers.
297  Ptr<WifiRemoteStationManager> manager = wifi->GetRemoteStationManager ();
298  Ptr<MinstrelWifiManager> minstrel = DynamicCast<MinstrelWifiManager> (manager);
299  if (minstrel)
300  {
301  currentStream += minstrel->AssignStreams (currentStream);
302  }
303  // Handle any random numbers in the mesh mac and plugins
304  mac = DynamicCast<MeshWifiInterfaceMac> (wifi->GetMac ());
305  if (mac)
306  {
307  currentStream += mac->AssignStreams (currentStream);
308  }
309  Ptr<RegularWifiMac> rmac = DynamicCast<RegularWifiMac> (mac);
310  if (rmac)
311  {
312  PointerValue ptr;
313  rmac->GetAttribute ("Txop", ptr);
314  Ptr<Txop> txop = ptr.Get<Txop> ();
315  currentStream += txop->AssignStreams (currentStream);
316 
317  rmac->GetAttribute ("VO_Txop", ptr);
318  Ptr<QosTxop> vo_txop = ptr.Get<QosTxop> ();
319  currentStream += vo_txop->AssignStreams (currentStream);
320 
321  rmac->GetAttribute ("VI_Txop", ptr);
322  Ptr<QosTxop> vi_txop = ptr.Get<QosTxop> ();
323  currentStream += vi_txop->AssignStreams (currentStream);
324 
325  rmac->GetAttribute ("BE_Txop", ptr);
326  Ptr<QosTxop> be_txop = ptr.Get<QosTxop> ();
327  currentStream += be_txop->AssignStreams (currentStream);
328 
329  rmac->GetAttribute ("BK_Txop", ptr);
330  Ptr<QosTxop> bk_txop = ptr.Get<QosTxop> ();
331  currentStream += bk_txop->AssignStreams (currentStream);
332  }
333  }
334  }
335  }
336  return (currentStream - stream);
337 }
338 
339 } // namespace ns3
340 
Ptr< WifiNetDevice > CreateInterface(const WifiPhyHelper &phyHelper, Ptr< Node > node, uint16_t channelId) const
Definition: mesh-helper.cc:202
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:255
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:152
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:92
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
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:174
#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:45
Voice.
Definition: qos-utils.h:47
Best Effort.
Definition: qos-utils.h:41
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:79
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:34
phy
Definition: third.py:93
void SetStandard(enum WifiStandard standard)
Set standard.
Definition: mesh-helper.cc:196
Background.
Definition: qos-utils.h:43
void SetSpreadInterfaceChannels(ChannelPolicy policy)
set the channel policy
Definition: mesh-helper.cc:46
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:132
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:267
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:275
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:51
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:84
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:118
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:41
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:38
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