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 
31 namespace ns3
32 {
34  m_nInterfaces (1),
35  m_spreadChannelPolicy (ZERO_CHANNEL),
36  m_stack (0),
37  m_standard (WIFI_PHY_STANDARD_80211a)
38 {
39 }
41 {
42  m_stack = 0;
43 }
44 void
46 {
47  m_spreadChannelPolicy = policy;
48 }
49 void
51  std::string n0, const AttributeValue &v0,
52  std::string n1, const AttributeValue &v1,
53  std::string n2, const AttributeValue &v2,
54  std::string n3, const AttributeValue &v3,
55  std::string n4, const AttributeValue &v4,
56  std::string n5, const AttributeValue &v5,
57  std::string n6, const AttributeValue &v6,
58  std::string n7, const AttributeValue &v7)
59 {
61  m_stackFactory.Set (n0, v0);
62  m_stackFactory.Set (n1, v1);
63  m_stackFactory.Set (n2, v2);
64  m_stackFactory.Set (n3, v3);
65  m_stackFactory.Set (n4, v4);
66  m_stackFactory.Set (n5, v5);
67  m_stackFactory.Set (n6, v6);
68  m_stackFactory.Set (n7, v7);
69 
71  if (m_stack == 0)
72  {
73  NS_FATAL_ERROR ("Stack has not been created: " << type);
74  }
75 }
76 
77 void
78 MeshHelper::SetNumberOfInterfaces (uint32_t nInterfaces)
79 {
80  m_nInterfaces = nInterfaces;
81 }
83 MeshHelper::Install (const WifiPhyHelper &phyHelper, NodeContainer c) const
84 {
86  NS_ASSERT (m_stack != 0);
87  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
88  {
89  Ptr<Node> node = *i;
90  // Create a mesh point device
91  Ptr<MeshPointDevice> mp = CreateObject<MeshPointDevice> ();
92  node->AddDevice (mp);
93  // Create wifi interfaces (single interface by default)
94  for (uint32_t i = 0; i < m_nInterfaces; ++i)
95  {
96  uint32_t channel = 0;
98  {
99  channel = 0;
100  }
102  {
103  channel = i * 5;
104  }
105  Ptr<WifiNetDevice> iface = CreateInterface (phyHelper, node, channel);
106  mp->AddInterface (iface);
107  }
108  if (!m_stack->InstallStack (mp))
109  {
110  NS_FATAL_ERROR ("Stack is not installed!");
111  }
112  devices.Add (mp);
113  }
114  return devices;
115 }
118 {
119  MeshHelper helper;
120  helper.SetMacType ();
121  helper.SetRemoteStationManager ("ns3::ArfWifiManager");
123  return helper;
124 }
125 
126 void
127 MeshHelper::SetMacType (std::string n0, const AttributeValue &v0,
128  std::string n1, const AttributeValue &v1,
129  std::string n2, const AttributeValue &v2,
130  std::string n3, const AttributeValue &v3,
131  std::string n4, const AttributeValue &v4,
132  std::string n5, const AttributeValue &v5,
133  std::string n6, const AttributeValue &v6,
134  std::string n7, const AttributeValue &v7)
135 {
136  m_mac.SetTypeId ("ns3::MeshWifiInterfaceMac");
137  m_mac.Set (n0, v0);
138  m_mac.Set (n1, v1);
139  m_mac.Set (n2, v2);
140  m_mac.Set (n3, v3);
141  m_mac.Set (n4, v4);
142  m_mac.Set (n5, v5);
143  m_mac.Set (n6, v6);
144  m_mac.Set (n7, v7);
145 }
146 void
148  std::string n0, const AttributeValue &v0,
149  std::string n1, const AttributeValue &v1,
150  std::string n2, const AttributeValue &v2,
151  std::string n3, const AttributeValue &v3,
152  std::string n4, const AttributeValue &v4,
153  std::string n5, const AttributeValue &v5,
154  std::string n6, const AttributeValue &v6,
155  std::string n7, const AttributeValue &v7)
156 {
159  m_stationManager.Set (n0, v0);
160  m_stationManager.Set (n1, v1);
161  m_stationManager.Set (n2, v2);
162  m_stationManager.Set (n3, v3);
163  m_stationManager.Set (n4, v4);
164  m_stationManager.Set (n5, v5);
165  m_stationManager.Set (n6, v6);
166  m_stationManager.Set (n7, v7);
167 }
168 void
170 {
171  m_standard = standard;
172 }
173 
175 MeshHelper::CreateInterface (const WifiPhyHelper &phyHelper, Ptr<Node> node, uint16_t channelId) const
176 {
177  Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
178 
180  NS_ASSERT (mac != 0);
181  mac->SetSsid (Ssid ());
182  mac->SetDevice (device);
184  NS_ASSERT (manager != 0);
185  Ptr<WifiPhy> phy = phyHelper.Create (node, device);
186  mac->SetAddress (Mac48Address::Allocate ());
187  mac->ConfigureStandard (m_standard);
188  phy->ConfigureStandard (m_standard);
189  device->SetMac (mac);
190  device->SetPhy (phy);
191  device->SetRemoteStationManager (manager);
192  node->AddDevice (device);
193  mac->SwitchFrequencyChannel (channelId);
194  return device;
195 }
196 void
197 MeshHelper::Report (const ns3::Ptr<ns3::NetDevice>& device, std::ostream& os)
198 {
199  NS_ASSERT (m_stack != 0);
201  NS_ASSERT (mp != 0);
202  std::vector<Ptr<NetDevice> > ifaces = mp->GetInterfaces ();
203  os << "<MeshPointDevice time=\"" << Simulator::Now ().GetSeconds () << "\" address=\""
204  << Mac48Address::ConvertFrom (mp->GetAddress ()) << "\">\n";
205  m_stack->Report (mp, os);
206  os << "</MeshPointDevice>\n";
207 }
208 void
210 {
211  NS_ASSERT (m_stack != 0);
213  NS_ASSERT (mp != 0);
214  m_stack->ResetStats (mp);
215 }
216 int64_t
218 {
219  int64_t currentStream = stream;
220  Ptr<NetDevice> netDevice;
221  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
222  {
223  netDevice = (*i);
224  Ptr<MeshPointDevice> mpd = DynamicCast<MeshPointDevice> (netDevice);
227  if (mpd)
228  {
229  // To access, we need the underlying WifiNetDevices
230  std::vector<Ptr<NetDevice> > ifaces = mpd->GetInterfaces ();
231  for (std::vector<Ptr<NetDevice> >::iterator i = ifaces.begin (); i != ifaces.end (); i++)
232  {
233  wifi = DynamicCast<WifiNetDevice> (*i);
234 
235  // Handle any random numbers in the PHY objects.
236  currentStream += wifi->GetPhy ()->AssignStreams (currentStream);
237 
238  // Handle any random numbers in the station managers.
239  Ptr<WifiRemoteStationManager> manager = wifi->GetRemoteStationManager ();
240  Ptr<MinstrelWifiManager> minstrel = DynamicCast<MinstrelWifiManager> (manager);
241  if (minstrel)
242  {
243  currentStream += minstrel->AssignStreams (currentStream);
244  }
245  // Handle any random numbers in the mesh mac and plugins
246  mac = DynamicCast<MeshWifiInterfaceMac> (wifi->GetMac ());
247  if (mac)
248  {
249  currentStream += mac->AssignStreams (currentStream);
250  }
251  Ptr<RegularWifiMac> rmac = DynamicCast<RegularWifiMac> (mac);
252  if (rmac)
253  {
254  PointerValue ptr;
255  rmac->GetAttribute ("Txop", ptr);
256  Ptr<Txop> txop = ptr.Get<Txop> ();
257  currentStream += txop->AssignStreams (currentStream);
258 
259  rmac->GetAttribute ("VO_Txop", ptr);
260  Ptr<QosTxop> vo_txop = ptr.Get<QosTxop> ();
261  currentStream += vo_txop->AssignStreams (currentStream);
262 
263  rmac->GetAttribute ("VI_Txop", ptr);
264  Ptr<QosTxop> vi_txop = ptr.Get<QosTxop> ();
265  currentStream += vi_txop->AssignStreams (currentStream);
266 
267  rmac->GetAttribute ("BE_Txop", ptr);
268  Ptr<QosTxop> be_txop = ptr.Get<QosTxop> ();
269  currentStream += be_txop->AssignStreams (currentStream);
270 
271  rmac->GetAttribute ("BK_Txop", ptr);
272  Ptr<QosTxop> bk_txop = ptr.Get<QosTxop> ();
273  currentStream += bk_txop->AssignStreams (currentStream);
274  }
275  }
276  }
277  }
278  return (currentStream - stream);
279 }
280 
281 } // namespace ns3
282 
Ptr< WifiNetDevice > CreateInterface(const WifiPhyHelper &phyHelper, Ptr< Node > node, uint16_t channelId) const
Definition: mesh-helper.cc:175
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:44
void Report(const ns3::Ptr< ns3::NetDevice > &device, std::ostream &os)
Print statistics.
Definition: mesh-helper.cc:197
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:147
ChannelPolicy m_spreadChannelPolicy
spread channel policy
Definition: mesh-helper.h:227
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
Definition: qos-txop.h:91
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
#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:162
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
void SetNumberOfInterfaces(uint32_t nInterfaces)
Set a number of interfaces in a mesh network.
Definition: mesh-helper.cc:78
Prototype for class, which helps to install MAC-layer routing stack to ns3::MeshPointDevice.
channel
Definition: third.py:85
MeshHelper()
Construct a MeshHelper used to make life easier when creating 802.11s networks.
Definition: mesh-helper.cc:33
phy
Definition: third.py:86
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:45
uint32_t m_nInterfaces
number of interfaces
Definition: mesh-helper.h:226
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:321
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:232
holds a vector of ns3::NetDevice pointers
mac
Definition: third.py:92
ObjectFactory m_stackFactory
stack factory
Definition: mesh-helper.h:229
Ptr< MeshStack > m_stack
stack
Definition: mesh-helper.h:228
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:127
static Mac48Address ConvertFrom(const Address &address)
ChannelPolicy
Spread/not spread frequency channels of MP interfaces.
Definition: mesh-helper.h:136
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
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:233
void ResetStats(const ns3::Ptr< ns3::NetDevice > &device)
Reset statistics.
Definition: mesh-helper.cc:209
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:193
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:217
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:50
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:169
wifi
Definition: third.py:89
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:83
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:128
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:117
Ptr< T > Get(void) const
Definition: pointer.h:194
Helper to create IEEE 802.11s mesh networks.
Definition: mesh-helper.h:42
devices
Definition: first.py:32
enum WifiPhyStandard m_standard
phy standard
Definition: mesh-helper.h:234
~MeshHelper()
Destroy a MeshHelper.
Definition: mesh-helper.cc:40
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:65