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_PHY_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 
207  NS_ASSERT (mac != 0);
208  mac->SetSsid (Ssid ());
209  mac->SetDevice (device);
211  NS_ASSERT (manager != 0);
212  Ptr<WifiPhy> phy = phyHelper.Create (node, device);
213  mac->SetAddress (Mac48Address::Allocate ());
214  mac->ConfigureStandard (m_standard);
215  phy->ConfigureStandard (m_standard);
216  device->SetMac (mac);
217  device->SetPhy (phy);
218  device->SetRemoteStationManager (manager);
219  node->AddDevice (device);
220  mac->SwitchFrequencyChannel (channelId);
221  // Install ack policy selector
222  PointerValue ptr;
223  Ptr<WifiAckPolicySelector> ackSelector;
224 
225  mac->GetAttributeFailSafe ("BE_Txop", ptr);
227  ackSelector->SetQosTxop (ptr.Get<QosTxop> ());
228  ptr.Get<QosTxop> ()->SetAckPolicySelector (ackSelector);
229 
230  mac->GetAttributeFailSafe ("BK_Txop", ptr);
232  ackSelector->SetQosTxop (ptr.Get<QosTxop> ());
233  ptr.Get<QosTxop> ()->SetAckPolicySelector (ackSelector);
234 
235  mac->GetAttributeFailSafe ("VI_Txop", ptr);
237  ackSelector->SetQosTxop (ptr.Get<QosTxop> ());
238  ptr.Get<QosTxop> ()->SetAckPolicySelector (ackSelector);
239 
240  mac->GetAttributeFailSafe ("VO_Txop", ptr);
242  ackSelector->SetQosTxop (ptr.Get<QosTxop> ());
243  ptr.Get<QosTxop> ()->SetAckPolicySelector (ackSelector);
244 
245  return device;
246 }
247 void
248 MeshHelper::Report (const ns3::Ptr<ns3::NetDevice>& device, std::ostream& os)
249 {
250  NS_ASSERT (m_stack != 0);
252  NS_ASSERT (mp != 0);
253  std::vector<Ptr<NetDevice> > ifaces = mp->GetInterfaces ();
254  os << "<MeshPointDevice time=\"" << Simulator::Now ().GetSeconds () << "\" address=\""
255  << Mac48Address::ConvertFrom (mp->GetAddress ()) << "\">\n";
256  m_stack->Report (mp, os);
257  os << "</MeshPointDevice>\n";
258 }
259 void
261 {
262  NS_ASSERT (m_stack != 0);
264  NS_ASSERT (mp != 0);
265  m_stack->ResetStats (mp);
266 }
267 int64_t
269 {
270  int64_t currentStream = stream;
271  Ptr<NetDevice> netDevice;
272  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
273  {
274  netDevice = (*i);
275  Ptr<MeshPointDevice> mpd = DynamicCast<MeshPointDevice> (netDevice);
278  if (mpd)
279  {
280  // To access, we need the underlying WifiNetDevices
281  std::vector<Ptr<NetDevice> > ifaces = mpd->GetInterfaces ();
282  for (std::vector<Ptr<NetDevice> >::iterator i = ifaces.begin (); i != ifaces.end (); i++)
283  {
284  wifi = DynamicCast<WifiNetDevice> (*i);
285 
286  // Handle any random numbers in the PHY objects.
287  currentStream += wifi->GetPhy ()->AssignStreams (currentStream);
288 
289  // Handle any random numbers in the station managers.
290  Ptr<WifiRemoteStationManager> manager = wifi->GetRemoteStationManager ();
291  Ptr<MinstrelWifiManager> minstrel = DynamicCast<MinstrelWifiManager> (manager);
292  if (minstrel)
293  {
294  currentStream += minstrel->AssignStreams (currentStream);
295  }
296  // Handle any random numbers in the mesh mac and plugins
297  mac = DynamicCast<MeshWifiInterfaceMac> (wifi->GetMac ());
298  if (mac)
299  {
300  currentStream += mac->AssignStreams (currentStream);
301  }
302  Ptr<RegularWifiMac> rmac = DynamicCast<RegularWifiMac> (mac);
303  if (rmac)
304  {
305  PointerValue ptr;
306  rmac->GetAttribute ("Txop", ptr);
307  Ptr<Txop> txop = ptr.Get<Txop> ();
308  currentStream += txop->AssignStreams (currentStream);
309 
310  rmac->GetAttribute ("VO_Txop", ptr);
311  Ptr<QosTxop> vo_txop = ptr.Get<QosTxop> ();
312  currentStream += vo_txop->AssignStreams (currentStream);
313 
314  rmac->GetAttribute ("VI_Txop", ptr);
315  Ptr<QosTxop> vi_txop = ptr.Get<QosTxop> ();
316  currentStream += vi_txop->AssignStreams (currentStream);
317 
318  rmac->GetAttribute ("BE_Txop", ptr);
319  Ptr<QosTxop> be_txop = ptr.Get<QosTxop> ();
320  currentStream += be_txop->AssignStreams (currentStream);
321 
322  rmac->GetAttribute ("BK_Txop", ptr);
323  Ptr<QosTxop> bk_txop = ptr.Get<QosTxop> ();
324  currentStream += bk_txop->AssignStreams (currentStream);
325  }
326  }
327  }
328  }
329  return (currentStream - stream);
330 }
331 
332 } // namespace ns3
333 
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:45
void Report(const ns3::Ptr< ns3::NetDevice > &device, std::ostream &os)
Print statistics.
Definition: mesh-helper.cc:248
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:361
#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:162
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
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
Background.
Definition: qos-utils.h:43
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
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
OFDM PHY for the 5 GHz band (Clause 17)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:260
void Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
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:268
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
void SetStandard(enum WifiPhyStandard standard)
Set PHY standard.
Definition: mesh-helper.cc:196
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
enum WifiPhyStandard m_standard
phy standard
Definition: mesh-helper.h:268
~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