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 #include "mesh-helper.h"
22 #include "ns3/simulator.h"
23 #include "ns3/pointer.h"
24 #include "ns3/mesh-point-device.h"
25 #include "ns3/dca-txop.h"
26 #include "ns3/edca-txop-n.h"
27 #include "ns3/wifi-net-device.h"
28 #include "ns3/minstrel-wifi-manager.h"
29 #include "ns3/mesh-wifi-interface-mac.h"
30 namespace ns3
31 {
33  m_nInterfaces (1),
34  m_spreadChannelPolicy (ZERO_CHANNEL),
35  m_stack (0),
36  m_standard (WIFI_PHY_STANDARD_80211a)
37 {
38 }
40 {
41  m_stack = 0;
42 }
43 void
45 {
46  m_spreadChannelPolicy = policy;
47 }
48 void
50  std::string n0, const AttributeValue &v0,
51  std::string n1, const AttributeValue &v1,
52  std::string n2, const AttributeValue &v2,
53  std::string n3, const AttributeValue &v3,
54  std::string n4, const AttributeValue &v4,
55  std::string n5, const AttributeValue &v5,
56  std::string n6, const AttributeValue &v6,
57  std::string n7, const AttributeValue &v7)
58 {
60  m_stackFactory.Set (n0, v0);
61  m_stackFactory.Set (n1, v1);
62  m_stackFactory.Set (n2, v2);
63  m_stackFactory.Set (n3, v3);
64  m_stackFactory.Set (n4, v4);
65  m_stackFactory.Set (n5, v5);
66  m_stackFactory.Set (n6, v6);
67  m_stackFactory.Set (n7, v7);
68 
70  if (m_stack == 0)
71  {
72  NS_FATAL_ERROR ("Stack has not been created: " << type);
73  }
74 }
75 
76 void
77 MeshHelper::SetNumberOfInterfaces (uint32_t nInterfaces)
78 {
79  m_nInterfaces = nInterfaces;
80 }
82 MeshHelper::Install (const WifiPhyHelper &phyHelper, NodeContainer c) const
83 {
85  NS_ASSERT (m_stack != 0);
86  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
87  {
88  Ptr<Node> node = *i;
89  // Create a mesh point device
90  Ptr<MeshPointDevice> mp = CreateObject<MeshPointDevice> ();
91  node->AddDevice (mp);
92  // Create wifi interfaces (single interface by default)
93  for (uint32_t i = 0; i < m_nInterfaces; ++i)
94  {
95  uint32_t channel = 0;
97  {
98  channel = 0;
99  }
101  {
102  channel = i * 5;
103  }
104  Ptr<WifiNetDevice> iface = CreateInterface (phyHelper, node, channel);
105  mp->AddInterface (iface);
106  }
107  if (!m_stack->InstallStack (mp))
108  {
109  NS_FATAL_ERROR ("Stack is not installed!");
110  }
111  devices.Add (mp);
112  }
113  return devices;
114 }
117 {
118  MeshHelper helper;
119  helper.SetMacType ();
120  helper.SetRemoteStationManager ("ns3::ArfWifiManager");
122  return helper;
123 }
124 
125 void
126 MeshHelper::SetMacType (std::string n0, const AttributeValue &v0,
127  std::string n1, const AttributeValue &v1,
128  std::string n2, const AttributeValue &v2,
129  std::string n3, const AttributeValue &v3,
130  std::string n4, const AttributeValue &v4,
131  std::string n5, const AttributeValue &v5,
132  std::string n6, const AttributeValue &v6,
133  std::string n7, const AttributeValue &v7)
134 {
135  m_mac.SetTypeId ("ns3::MeshWifiInterfaceMac");
136  m_mac.Set (n0, v0);
137  m_mac.Set (n1, v1);
138  m_mac.Set (n2, v2);
139  m_mac.Set (n3, v3);
140  m_mac.Set (n4, v4);
141  m_mac.Set (n5, v5);
142  m_mac.Set (n6, v6);
143  m_mac.Set (n7, v7);
144 }
145 void
147  std::string n0, const AttributeValue &v0,
148  std::string n1, const AttributeValue &v1,
149  std::string n2, const AttributeValue &v2,
150  std::string n3, const AttributeValue &v3,
151  std::string n4, const AttributeValue &v4,
152  std::string n5, const AttributeValue &v5,
153  std::string n6, const AttributeValue &v6,
154  std::string n7, const AttributeValue &v7)
155 {
158  m_stationManager.Set (n0, v0);
159  m_stationManager.Set (n1, v1);
160  m_stationManager.Set (n2, v2);
161  m_stationManager.Set (n3, v3);
162  m_stationManager.Set (n4, v4);
163  m_stationManager.Set (n5, v5);
164  m_stationManager.Set (n6, v6);
165  m_stationManager.Set (n7, v7);
166 }
167 void
169 {
170  m_standard = standard;
171 }
172 
174 MeshHelper::CreateInterface (const WifiPhyHelper &phyHelper, Ptr<Node> node, uint16_t channelId) const
175 {
176  Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
177 
179  NS_ASSERT (mac != 0);
180  mac->SetSsid (Ssid ());
182  NS_ASSERT (manager != 0);
183  Ptr<WifiPhy> phy = phyHelper.Create (node, device);
184  mac->SetAddress (Mac48Address::Allocate ());
187  device->SetMac (mac);
188  device->SetPhy (phy);
189  device->SetRemoteStationManager (manager);
190  node->AddDevice (device);
191  mac->SwitchFrequencyChannel (channelId);
192  return device;
193 }
194 void
195 MeshHelper::Report (const ns3::Ptr<ns3::NetDevice>& device, std::ostream& os)
196 {
197  NS_ASSERT (m_stack != 0);
199  NS_ASSERT (mp != 0);
200  std::vector<Ptr<NetDevice> > ifaces = mp->GetInterfaces ();
201  os << "<MeshPointDevice time=\"" << Simulator::Now ().GetSeconds () << "\" address=\""
202  << Mac48Address::ConvertFrom (mp->GetAddress ()) << "\">\n";
203  m_stack->Report (mp, os);
204  os << "</MeshPointDevice>\n";
205 }
206 void
208 {
209  NS_ASSERT (m_stack != 0);
211  NS_ASSERT (mp != 0);
212  m_stack->ResetStats (mp);
213 }
214 int64_t
216 {
217  int64_t currentStream = stream;
218  Ptr<NetDevice> netDevice;
219  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
220  {
221  netDevice = (*i);
222  Ptr<MeshPointDevice> mpd = DynamicCast<MeshPointDevice> (netDevice);
225  if (mpd)
226  {
227  // To access, we need the underlying WifiNetDevices
228  std::vector<Ptr<NetDevice> > ifaces = mpd->GetInterfaces ();
229  for (std::vector<Ptr<NetDevice> >::iterator i = ifaces.begin (); i != ifaces.end (); i++)
230  {
231  wifi = DynamicCast<WifiNetDevice> (*i);
232 
233  // Handle any random numbers in the PHY objects.
234  currentStream += wifi->GetPhy ()->AssignStreams (currentStream);
235 
236  // Handle any random numbers in the station managers.
237  Ptr<WifiRemoteStationManager> manager = wifi->GetRemoteStationManager ();
238  Ptr<MinstrelWifiManager> minstrel = DynamicCast<MinstrelWifiManager> (manager);
239  if (minstrel)
240  {
241  currentStream += minstrel->AssignStreams (currentStream);
242  }
243  // Handle any random numbers in the mesh mac and plugins
244  mac = DynamicCast<MeshWifiInterfaceMac> (wifi->GetMac ());
245  if (mac)
246  {
247  currentStream += mac->AssignStreams (currentStream);
248  }
249  Ptr<RegularWifiMac> rmac = DynamicCast<RegularWifiMac> (mac);
250  if (rmac)
251  {
252  PointerValue ptr;
253  rmac->GetAttribute ("DcaTxop", ptr);
254  Ptr<DcaTxop> dcaTxop = ptr.Get<DcaTxop> ();
255  currentStream += dcaTxop->AssignStreams (currentStream);
256 
257  rmac->GetAttribute ("VO_EdcaTxopN", ptr);
258  Ptr<EdcaTxopN> vo_edcaTxopN = ptr.Get<EdcaTxopN> ();
259  currentStream += vo_edcaTxopN->AssignStreams (currentStream);
260 
261  rmac->GetAttribute ("VI_EdcaTxopN", ptr);
262  Ptr<EdcaTxopN> vi_edcaTxopN = ptr.Get<EdcaTxopN> ();
263  currentStream += vi_edcaTxopN->AssignStreams (currentStream);
264 
265  rmac->GetAttribute ("BE_EdcaTxopN", ptr);
266  Ptr<EdcaTxopN> be_edcaTxopN = ptr.Get<EdcaTxopN> ();
267  currentStream += be_edcaTxopN->AssignStreams (currentStream);
268 
269  rmac->GetAttribute ("BK_EdcaTxopN", ptr);
270  Ptr<EdcaTxopN> bk_edcaTxopN = ptr.Get<EdcaTxopN> ();
271  currentStream += bk_edcaTxopN->AssignStreams (currentStream);
272  }
273  }
274  }
275  }
276  return (currentStream - stream);
277 }
278 
279 } // namespace ns3
280 
tuple channel
Definition: third.py:85
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
Ptr< T > Get(void) const
Definition: pointer.h:194
tuple devices
Definition: first.py:32
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:462
Hold a value for an Attribute.
Definition: attribute.h:68
create PHY objects
Definition: wifi-helper.h:48
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:146
ChannelPolicy m_spreadChannelPolicy
Definition: mesh-helper.h:213
#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.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
Ptr< WifiNetDevice > CreateInterface(const WifiPhyHelper &phyHelper, Ptr< Node > node, uint16_t channelId) const
Definition: mesh-helper.cc:174
void Report(const ns3::Ptr< ns3::NetDevice > &, std::ostream &)
Print statistics.
Definition: mesh-helper.cc:195
void SetNumberOfInterfaces(uint32_t nInterfaces)
Set a number of interfaces in a mesh network.
Definition: mesh-helper.cc:77
Prototype for class, which helps to install MAC-layer routing stack to ns3::MeshPointDevice.
MeshHelper()
Construct a MeshHelper used to make life easier when creating 802.11s networks.
Definition: mesh-helper.cc:32
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
This queue contains packets for a particular access class.
Definition: edca-txop-n.h:86
ChannelPolicy
Spread/not spread frequency channels of MP interfaces.
Definition: mesh-helper.h:130
uint32_t m_nInterfaces
Definition: mesh-helper.h:212
tuple phy
Definition: third.py:86
static Mac48Address Allocate(void)
Allocate a new Mac48Address.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
ObjectFactory m_mac
Definition: mesh-helper.h:218
holds a vector of ns3::NetDevice pointers
ObjectFactory m_stackFactory
Definition: mesh-helper.h:215
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
tuple mac
Definition: third.py:92
Ptr< MeshStack > m_stack
Definition: mesh-helper.h:214
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:126
static Mac48Address ConvertFrom(const Address &address)
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.
Definition: pointer.h:36
ObjectFactory m_stationManager
Definition: mesh-helper.h:219
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
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:224
void SetSpreadInterfaceChannels(ChannelPolicy)
set the channel policy
Definition: mesh-helper.cc:44
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:215
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:49
void ResetStats(const ns3::Ptr< ns3::NetDevice > &)
Reset statistics.
Definition: mesh-helper.cc:207
Virtual net device modeling mesh point.
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:38
void SetStandard(enum WifiPhyStandard standard)
Set PHY standard.
Definition: mesh-helper.cc:168
virtual void ConfigureStandard(enum WifiPhyStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:1026
Instantiate subclasses of ns3::Object.
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
NetDeviceContainer Install(const WifiPhyHelper &phyHelper, NodeContainer c) const
Install 802.11s mesh device & protocols on given node list.
Definition: mesh-helper.cc:82
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:116
tuple wifi
Definition: third.py:89
Helper to create IEEE 802.11s mesh networks.
Definition: mesh-helper.h:38
enum WifiPhyStandard m_standard
Definition: mesh-helper.h:220
~MeshHelper()
Destroy a MeshHelper.
Definition: mesh-helper.cc:39
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
handle packet fragmentation and retransmissions.
Definition: dca-txop.h:67
std::string m_stack
Basic MAC of mesh point Wi-Fi interface.