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
34namespace 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}
47void
49{
50 m_spreadChannelPolicy = policy;
51}
52void
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
80void
82{
83 m_nInterfaces = nInterfaces;
84}
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
129void
130MeshHelper::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}
149void
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}
171void
173{
174 m_standard = standard;
175}
176
178MeshHelper::CreateInterface (const WifiPhyHelper &phyHelper, Ptr<Node> node, uint16_t channelId) const
179{
180 Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
181
182 // this is a const method, but we need to force the correct QoS setting
183 ObjectFactory macObjectFactory = m_mac;
184 macObjectFactory.Set ("QosSupported", BooleanValue (true)); // a mesh station is a QoS station
186 NS_ASSERT (mac != 0);
187 mac->SetSsid (Ssid ());
188 mac->SetDevice (device);
190 NS_ASSERT (manager != 0);
191 Ptr<WifiPhy> phy = phyHelper.Create (node, device);
192 mac->SetAddress (Mac48Address::Allocate ());
193 mac->ConfigureStandard (m_standard);
194 Ptr<FrameExchangeManager> fem = mac->GetFrameExchangeManager ();
195 if (fem != nullptr)
196 {
197 Ptr<WifiProtectionManager> protectionManager = CreateObject<WifiDefaultProtectionManager> ();
198 protectionManager->SetWifiMac (mac);
199 fem->SetProtectionManager (protectionManager);
200
201 Ptr<WifiAckManager> ackManager = CreateObject<WifiDefaultAckManager> ();
202 ackManager->SetWifiMac (mac);
203 fem->SetAckManager (ackManager);
204 }
205 phy->ConfigureStandard (m_standard);
206 device->SetMac (mac);
207 device->SetPhy (phy);
208 device->SetRemoteStationManager (manager);
209 node->AddDevice (device);
210 mac->SwitchFrequencyChannel (channelId);
211
212 return device;
213}
214void
215MeshHelper::Report (const ns3::Ptr<ns3::NetDevice>& device, std::ostream& os)
216{
217 NS_ASSERT (m_stack != 0);
219 NS_ASSERT (mp != 0);
220 std::vector<Ptr<NetDevice> > ifaces = mp->GetInterfaces ();
221 os << "<MeshPointDevice time=\"" << Simulator::Now ().GetSeconds () << "\" address=\""
222 << Mac48Address::ConvertFrom (mp->GetAddress ()) << "\">\n";
223 m_stack->Report (mp, os);
224 os << "</MeshPointDevice>\n";
225}
226void
228{
229 NS_ASSERT (m_stack != 0);
231 NS_ASSERT (mp != 0);
232 m_stack->ResetStats (mp);
233}
234int64_t
236{
237 int64_t currentStream = stream;
238 Ptr<NetDevice> netDevice;
239 for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
240 {
241 netDevice = (*i);
242 Ptr<MeshPointDevice> mpd = DynamicCast<MeshPointDevice> (netDevice);
245 if (mpd)
246 {
247 currentStream += mpd->AssignStreams (currentStream);
248 // To access, we need the underlying WifiNetDevices
249 std::vector<Ptr<NetDevice> > ifaces = mpd->GetInterfaces ();
250 for (std::vector<Ptr<NetDevice> >::iterator i = ifaces.begin (); i != ifaces.end (); i++)
251 {
252 wifi = DynamicCast<WifiNetDevice> (*i);
253
254 // Handle any random numbers in the PHY objects.
255 currentStream += wifi->GetPhy ()->AssignStreams (currentStream);
256
257 // Handle any random numbers in the station managers.
258 Ptr<WifiRemoteStationManager> manager = wifi->GetRemoteStationManager ();
259 Ptr<MinstrelWifiManager> minstrel = DynamicCast<MinstrelWifiManager> (manager);
260 if (minstrel)
261 {
262 currentStream += minstrel->AssignStreams (currentStream);
263 }
264 // Handle any random numbers in the mesh mac and plugins
265 mac = DynamicCast<MeshWifiInterfaceMac> (wifi->GetMac ());
266 currentStream += mac->AssignStreams (currentStream);
267
268 PointerValue ptr;
269 mac->GetAttribute ("Txop", ptr);
270 Ptr<Txop> txop = ptr.Get<Txop> ();
271 currentStream += txop->AssignStreams (currentStream);
272
273 mac->GetAttribute ("VO_Txop", ptr);
274 Ptr<QosTxop> vo_txop = ptr.Get<QosTxop> ();
275 currentStream += vo_txop->AssignStreams (currentStream);
276
277 mac->GetAttribute ("VI_Txop", ptr);
278 Ptr<QosTxop> vi_txop = ptr.Get<QosTxop> ();
279 currentStream += vi_txop->AssignStreams (currentStream);
280
281 mac->GetAttribute ("BE_Txop", ptr);
282 Ptr<QosTxop> be_txop = ptr.Get<QosTxop> ();
283 currentStream += be_txop->AssignStreams (currentStream);
284
285 mac->GetAttribute ("BK_Txop", ptr);
286 Ptr<QosTxop> bk_txop = ptr.Get<QosTxop> ();
287 currentStream += bk_txop->AssignStreams (currentStream);
288 }
289 }
290 }
291 return (currentStream - stream);
292}
293
294void
296{
298
299 LogComponentEnable ("MeshL2RoutingProtocol", LOG_LEVEL_ALL);
300 LogComponentEnable ("MeshPointDevice", LOG_LEVEL_ALL);
301 LogComponentEnable ("MeshWifiInterfaceMac", LOG_LEVEL_ALL);
302
303 LogComponentEnable ("Dot11sPeerManagementProtocol", LOG_LEVEL_ALL);
304 LogComponentEnable ("HwmpProtocol", LOG_LEVEL_ALL);
305 LogComponentEnable ("HwmpProtocolMac", LOG_LEVEL_ALL);
306 LogComponentEnable ("HwmpRtable", LOG_LEVEL_ALL);
307 LogComponentEnable ("PeerManagementProtocol", LOG_LEVEL_ALL);
308 LogComponentEnable ("PeerManagementProtocolMac", LOG_LEVEL_ALL);
309
310 LogComponentEnable ("FlameProtocol", LOG_LEVEL_ALL);
311 LogComponentEnable ("FlameProtocolMac", LOG_LEVEL_ALL);
312 LogComponentEnable ("FlameRtable", LOG_LEVEL_ALL);
313}
314
315} // namespace ns3
316
Hold a value for an Attribute.
Definition: attribute.h:69
AttributeValue implementation for Boolean.
Definition: boolean.h:37
static Mac48Address Allocate(void)
Allocate a new Mac48Address.
static Mac48Address ConvertFrom(const Address &address)
Helper to create IEEE 802.11s mesh networks.
Definition: mesh-helper.h:44
ObjectFactory m_stackFactory
stack factory
Definition: mesh-helper.h:235
enum WifiStandard m_standard
standard
Definition: mesh-helper.h:241
Ptr< WifiNetDevice > CreateInterface(const WifiPhyHelper &phyHelper, Ptr< Node > node, uint16_t channelId) const
Definition: mesh-helper.cc:178
Ptr< MeshStack > m_stack
stack
Definition: mesh-helper.h:234
~MeshHelper()
Destroy a MeshHelper.
Definition: mesh-helper.cc:43
uint32_t m_nInterfaces
number of interfaces
Definition: mesh-helper.h:232
ObjectFactory m_stationManager
the station manager
Definition: mesh-helper.h:239
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
void SetSpreadInterfaceChannels(ChannelPolicy policy)
set the channel policy
Definition: mesh-helper.cc:48
ObjectFactory m_mac
the MAC
Definition: mesh-helper.h:238
ChannelPolicy m_spreadChannelPolicy
spread channel policy
Definition: mesh-helper.h:233
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
void SetStandard(enum WifiStandard standard)
Set standard.
Definition: mesh-helper.cc:172
MeshHelper()
Construct a MeshHelper used to make life easier when creating 802.11s networks.
Definition: mesh-helper.cc:36
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:235
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
NetDeviceContainer Install(const WifiPhyHelper &phyHelper, NodeContainer c) const
Install 802.11s mesh device & protocols on given node list.
Definition: mesh-helper.cc:86
ChannelPolicy
Spread/not spread frequency channels of MP interfaces.
Definition: mesh-helper.h:138
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
void ResetStats(const ns3::Ptr< ns3::NetDevice > &device)
Reset statistics.
Definition: mesh-helper.cc:227
void Report(const ns3::Ptr< ns3::NetDevice > &device, std::ostream &os)
Print statistics.
Definition: mesh-helper.cc:215
void SetNumberOfInterfaces(uint32_t nInterfaces)
Set a number of interfaces in a mesh network.
Definition: mesh-helper.cc:81
static void EnableLogComponents(void)
Helper to enable all MeshPointDevice log components with one statement.
Definition: mesh-helper.cc:295
Virtual net device modeling mesh point.
Prototype for class, which helps to install MAC-layer routing stack to ns3::MeshPointDevice.
Basic MAC of mesh point Wi-Fi interface.
holds a vector of ns3::NetDevice pointers
std::vector< Ptr< NetDevice > >::const_iterator Iterator
NetDevice container iterator.
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
keep track of a set of node pointers.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:130
Instantiate subclasses of ns3::Object.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
Hold objects of type Ptr<T>.
Definition: pointer.h:37
Ptr< T > Get(void) const
Definition: pointer.h:201
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
Definition: qos-txop.h:72
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
Handle packet fragmentation and retransmissions for data and management frames.
Definition: txop.h:65
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: txop.cc:309
static void EnableLogComponents(void)
Helper to enable all WifiNetDevice log components with one statement.
Definition: wifi-helper.cc:894
void SetMac(const Ptr< WifiMac > mac)
void SetRemoteStationManager(const Ptr< WifiRemoteStationManager > manager)
void SetPhy(const Ptr< WifiPhy > phy)
create PHY objects
Definition: wifi-helper.h:48
virtual Ptr< WifiPhy > Create(Ptr< Node > node, Ptr< WifiNetDevice > device) const =0
hold a list of per-remote-station state.
#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
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
@ WIFI_STANDARD_80211a
devices
Definition: first.py:39
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:361
channel
Definition: third.py:92
mac
Definition: third.py:96
wifi
Definition: third.py:99
phy
Definition: third.py:93