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/frame-exchange-manager.h"
31 #include "ns3/wifi-default-protection-manager.h"
32 #include "ns3/wifi-default-ack-manager.h"
33 
34 namespace ns3
35 {
37  m_nInterfaces (1),
38  m_spreadChannelPolicy (ZERO_CHANNEL),
39  m_stack (0),
40  m_standard (WIFI_STANDARD_80211a)
41 {
42 }
44 {
45  m_stack = 0;
46 }
47 void
49 {
50  m_spreadChannelPolicy = policy;
51 }
52 void
54  std::string n0, const AttributeValue &v0,
55  std::string n1, const AttributeValue &v1,
56  std::string n2, const AttributeValue &v2,
57  std::string n3, const AttributeValue &v3,
58  std::string n4, const AttributeValue &v4,
59  std::string n5, const AttributeValue &v5,
60  std::string n6, const AttributeValue &v6,
61  std::string n7, const AttributeValue &v7)
62 {
64  m_stackFactory.Set (n0, v0);
65  m_stackFactory.Set (n1, v1);
66  m_stackFactory.Set (n2, v2);
67  m_stackFactory.Set (n3, v3);
68  m_stackFactory.Set (n4, v4);
69  m_stackFactory.Set (n5, v5);
70  m_stackFactory.Set (n6, v6);
71  m_stackFactory.Set (n7, v7);
72 
74  if (m_stack == 0)
75  {
76  NS_FATAL_ERROR ("Stack has not been created: " << type);
77  }
78 }
79 
80 void
81 MeshHelper::SetNumberOfInterfaces (uint32_t nInterfaces)
82 {
83  m_nInterfaces = nInterfaces;
84 }
86 MeshHelper::Install (const WifiPhyHelper &phyHelper, NodeContainer c) const
87 {
89  NS_ASSERT (m_stack != 0);
90  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
91  {
92  Ptr<Node> node = *i;
93  // Create a mesh point device
94  Ptr<MeshPointDevice> mp = CreateObject<MeshPointDevice> ();
95  node->AddDevice (mp);
96  // Create wifi interfaces (single interface by default)
97  for (uint32_t i = 0; i < m_nInterfaces; ++i)
98  {
99  uint32_t channel = 0;
101  {
102  channel = 100;
103  }
105  {
106  channel = 100 + i * 5;
107  }
108  Ptr<WifiNetDevice> iface = CreateInterface (phyHelper, node, channel);
109  mp->AddInterface (iface);
110  }
111  if (!m_stack->InstallStack (mp))
112  {
113  NS_FATAL_ERROR ("Stack is not installed!");
114  }
115  devices.Add (mp);
116  }
117  return devices;
118 }
121 {
122  MeshHelper helper;
123  helper.SetMacType ();
124  helper.SetRemoteStationManager ("ns3::ArfWifiManager");
126  return helper;
127 }
128 
129 void
130 MeshHelper::SetMacType (std::string n0, const AttributeValue &v0,
131  std::string n1, const AttributeValue &v1,
132  std::string n2, const AttributeValue &v2,
133  std::string n3, const AttributeValue &v3,
134  std::string n4, const AttributeValue &v4,
135  std::string n5, const AttributeValue &v5,
136  std::string n6, const AttributeValue &v6,
137  std::string n7, const AttributeValue &v7)
138 {
139  m_mac.SetTypeId ("ns3::MeshWifiInterfaceMac");
140  m_mac.Set (n0, v0);
141  m_mac.Set (n1, v1);
142  m_mac.Set (n2, v2);
143  m_mac.Set (n3, v3);
144  m_mac.Set (n4, v4);
145  m_mac.Set (n5, v5);
146  m_mac.Set (n6, v6);
147  m_mac.Set (n7, v7);
148 }
149 void
151  std::string n0, const AttributeValue &v0,
152  std::string n1, const AttributeValue &v1,
153  std::string n2, const AttributeValue &v2,
154  std::string n3, const AttributeValue &v3,
155  std::string n4, const AttributeValue &v4,
156  std::string n5, const AttributeValue &v5,
157  std::string n6, const AttributeValue &v6,
158  std::string n7, const AttributeValue &v7)
159 {
162  m_stationManager.Set (n0, v0);
163  m_stationManager.Set (n1, v1);
164  m_stationManager.Set (n2, v2);
165  m_stationManager.Set (n3, v3);
166  m_stationManager.Set (n4, v4);
167  m_stationManager.Set (n5, v5);
168  m_stationManager.Set (n6, v6);
169  m_stationManager.Set (n7, v7);
170 }
171 void
173 {
174  m_standard = standard;
175 }
176 
178 MeshHelper::CreateInterface (const WifiPhyHelper &phyHelper, Ptr<Node> node, uint16_t channelId) const
179 {
180  Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
181 
182  auto it = wifiStandards.find (m_standard);
183  if (it == wifiStandards.end ())
184  {
185  NS_FATAL_ERROR ("Selected standard is not defined!");
186  return device;
187  }
188 
190  NS_ASSERT (mac != 0);
191  mac->SetSsid (Ssid ());
192  mac->SetDevice (device);
194  NS_ASSERT (manager != 0);
195  Ptr<WifiPhy> phy = phyHelper.Create (node, device);
196  mac->SetAddress (Mac48Address::Allocate ());
197  mac->ConfigureStandard (m_standard);
198  Ptr<RegularWifiMac> wifiMac = DynamicCast<RegularWifiMac> (mac);
200  if (wifiMac != 0 && (fem = wifiMac->GetFrameExchangeManager ()) != 0)
201  {
202  Ptr<WifiProtectionManager> protectionManager = CreateObject<WifiDefaultProtectionManager> ();
203  protectionManager->SetWifiMac (wifiMac);
204  fem->SetProtectionManager (protectionManager);
205 
206  Ptr<WifiAckManager> ackManager = CreateObject<WifiDefaultAckManager> ();
207  ackManager->SetWifiMac (wifiMac);
208  fem->SetAckManager (ackManager);
209  }
210  phy->ConfigureStandardAndBand (it->second.phyStandard, it->second.phyBand);
211  device->SetMac (mac);
212  device->SetPhy (phy);
213  device->SetRemoteStationManager (manager);
214  node->AddDevice (device);
215  mac->SwitchFrequencyChannel (channelId);
216 
217  return device;
218 }
219 void
220 MeshHelper::Report (const ns3::Ptr<ns3::NetDevice>& device, std::ostream& os)
221 {
222  NS_ASSERT (m_stack != 0);
224  NS_ASSERT (mp != 0);
225  std::vector<Ptr<NetDevice> > ifaces = mp->GetInterfaces ();
226  os << "<MeshPointDevice time=\"" << Simulator::Now ().GetSeconds () << "\" address=\""
227  << Mac48Address::ConvertFrom (mp->GetAddress ()) << "\">\n";
228  m_stack->Report (mp, os);
229  os << "</MeshPointDevice>\n";
230 }
231 void
233 {
234  NS_ASSERT (m_stack != 0);
236  NS_ASSERT (mp != 0);
237  m_stack->ResetStats (mp);
238 }
239 int64_t
241 {
242  int64_t currentStream = stream;
243  Ptr<NetDevice> netDevice;
244  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
245  {
246  netDevice = (*i);
247  Ptr<MeshPointDevice> mpd = DynamicCast<MeshPointDevice> (netDevice);
250  if (mpd)
251  {
252  // To access, we need the underlying WifiNetDevices
253  std::vector<Ptr<NetDevice> > ifaces = mpd->GetInterfaces ();
254  for (std::vector<Ptr<NetDevice> >::iterator i = ifaces.begin (); i != ifaces.end (); i++)
255  {
256  wifi = DynamicCast<WifiNetDevice> (*i);
257 
258  // Handle any random numbers in the PHY objects.
259  currentStream += wifi->GetPhy ()->AssignStreams (currentStream);
260 
261  // Handle any random numbers in the station managers.
262  Ptr<WifiRemoteStationManager> manager = wifi->GetRemoteStationManager ();
263  Ptr<MinstrelWifiManager> minstrel = DynamicCast<MinstrelWifiManager> (manager);
264  if (minstrel)
265  {
266  currentStream += minstrel->AssignStreams (currentStream);
267  }
268  // Handle any random numbers in the mesh mac and plugins
269  mac = DynamicCast<MeshWifiInterfaceMac> (wifi->GetMac ());
270  if (mac)
271  {
272  currentStream += mac->AssignStreams (currentStream);
273  }
274  Ptr<RegularWifiMac> rmac = DynamicCast<RegularWifiMac> (mac);
275  if (rmac)
276  {
277  PointerValue ptr;
278  rmac->GetAttribute ("Txop", ptr);
279  Ptr<Txop> txop = ptr.Get<Txop> ();
280  currentStream += txop->AssignStreams (currentStream);
281 
282  rmac->GetAttribute ("VO_Txop", ptr);
283  Ptr<QosTxop> vo_txop = ptr.Get<QosTxop> ();
284  currentStream += vo_txop->AssignStreams (currentStream);
285 
286  rmac->GetAttribute ("VI_Txop", ptr);
287  Ptr<QosTxop> vi_txop = ptr.Get<QosTxop> ();
288  currentStream += vi_txop->AssignStreams (currentStream);
289 
290  rmac->GetAttribute ("BE_Txop", ptr);
291  Ptr<QosTxop> be_txop = ptr.Get<QosTxop> ();
292  currentStream += be_txop->AssignStreams (currentStream);
293 
294  rmac->GetAttribute ("BK_Txop", ptr);
295  Ptr<QosTxop> bk_txop = ptr.Get<QosTxop> ();
296  currentStream += bk_txop->AssignStreams (currentStream);
297  }
298  }
299  }
300  }
301  return (currentStream - stream);
302 }
303 
304 } // namespace ns3
305 
Ptr< WifiNetDevice > CreateInterface(const WifiPhyHelper &phyHelper, Ptr< Node > node, uint16_t channelId) const
Definition: mesh-helper.cc:178
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.
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:220
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:150
ChannelPolicy m_spreadChannelPolicy
spread channel policy
Definition: mesh-helper.h:228
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
Definition: qos-txop.h:74
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.
#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.
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:81
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:36
phy
Definition: third.py:93
void SetStandard(enum WifiStandard standard)
Set standard.
Definition: mesh-helper.cc:172
void SetSpreadInterfaceChannels(ChannelPolicy policy)
set the channel policy
Definition: mesh-helper.cc:48
uint32_t m_nInterfaces
number of interfaces
Definition: mesh-helper.h:227
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:303
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:233
holds a vector of ns3::NetDevice pointers
mac
Definition: third.py:99
ObjectFactory m_stackFactory
stack factory
Definition: mesh-helper.h:230
Ptr< MeshStack > m_stack
stack
Definition: mesh-helper.h:229
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:130
static Mac48Address ConvertFrom(const Address &address)
ChannelPolicy
Spread/not spread frequency channels of MP interfaces.
Definition: mesh-helper.h:137
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:234
void ResetStats(const ns3::Ptr< ns3::NetDevice > &device)
Reset statistics.
Definition: mesh-helper.cc:232
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:240
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:53
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:236
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:86
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:120
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:43
std::string m_stack
Basic MAC of mesh point Wi-Fi interface.
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:64