A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mesh-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008,2009 IITP RAS
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Kirill Andreev <andreev@iitp.ru>
18 * Pavel Boyko <boyko@iitp.ru>
19 */
20
21#include "mesh-helper.h"
22
23#include "ns3/fcfs-wifi-queue-scheduler.h"
24#include "ns3/frame-exchange-manager.h"
25#include "ns3/mesh-point-device.h"
26#include "ns3/mesh-wifi-interface-mac.h"
27#include "ns3/minstrel-wifi-manager.h"
28#include "ns3/pointer.h"
29#include "ns3/simulator.h"
30#include "ns3/string.h"
31#include "ns3/wifi-default-ack-manager.h"
32#include "ns3/wifi-default-protection-manager.h"
33#include "ns3/wifi-helper.h"
34#include "ns3/wifi-net-device.h"
35
36namespace ns3
37{
39 : m_nInterfaces(1),
40 m_spreadChannelPolicy(ZERO_CHANNEL),
41 m_stack(nullptr),
42 m_standard(WIFI_STANDARD_80211a)
43{
44}
45
47{
48 m_stack = nullptr;
49}
50
51void
53{
54 m_spreadChannelPolicy = policy;
55}
56
57void
59{
60 m_nInterfaces = nInterfaces;
61}
62
65{
66 NetDeviceContainer devices;
68 for (auto i = c.Begin(); i != c.End(); ++i)
69 {
70 Ptr<Node> node = *i;
71 // Create a mesh point device
72 Ptr<MeshPointDevice> mp = CreateObject<MeshPointDevice>();
73 node->AddDevice(mp);
74 // Create wifi interfaces (single interface by default)
75 for (uint32_t i = 0; i < m_nInterfaces; ++i)
76 {
77 uint32_t channel = 0;
79 {
80 channel = 100;
81 }
83 {
84 channel = 100 + i * 5;
85 }
86 Ptr<WifiNetDevice> iface = CreateInterface(phyHelper, node, channel);
87 mp->AddInterface(iface);
88 }
89 if (!m_stack->InstallStack(mp))
90 {
91 NS_FATAL_ERROR("Stack is not installed!");
92 }
93 devices.Add(mp);
94 }
95 return devices;
96}
97
100{
101 MeshHelper helper;
102 helper.SetMacType();
103 helper.SetRemoteStationManager("ns3::ArfWifiManager");
105 return helper;
106}
107
108void
110{
111 m_standard = standard;
112}
113
116 Ptr<Node> node,
117 uint16_t channelId) const
118{
119 Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice>();
120
121 // this is a const method, but we need to force the correct QoS setting
122 ObjectFactory macObjectFactory = m_mac;
123 macObjectFactory.Set("QosSupported", BooleanValue(true)); // a mesh station is a QoS station
124 // create (Qos)Txop objects
125 for (const std::string ac : {"BE", "BK", "VI", "VO"})
126 {
127 auto qosTxop =
128 CreateObjectWithAttributes<QosTxop>("AcIndex", StringValue(std::string("AC_") + ac));
129 macObjectFactory.Set(ac + "_Txop", PointerValue(qosTxop));
130 }
131 std::vector<Ptr<WifiPhy>> phys = phyHelper.Create(node, device);
132 NS_ABORT_IF(phys.size() != 1);
133 node->AddDevice(device);
134 phys[0]->ConfigureStandard(m_standard);
135 device->SetPhy(phys[0]);
136 Ptr<MeshWifiInterfaceMac> mac = macObjectFactory.Create<MeshWifiInterfaceMac>();
137 NS_ASSERT(mac);
138 mac->SetSsid(Ssid());
139 mac->SetDevice(device);
141 NS_ASSERT(manager);
142 device->SetRemoteStationManager(manager);
143 mac->SetAddress(Mac48Address::Allocate());
144 device->SetMac(mac);
145 mac->SetMacQueueScheduler(CreateObject<FcfsWifiQueueScheduler>());
146 mac->SetChannelAccessManagers({CreateObject<ChannelAccessManager>()});
147 ObjectFactory femFactory;
149 auto fem = femFactory.Create<FrameExchangeManager>();
150 mac->SetFrameExchangeManagers({fem});
151 fem->SetAddress(mac->GetAddress());
152 Ptr<WifiProtectionManager> protectionManager = CreateObject<WifiDefaultProtectionManager>();
153 protectionManager->SetWifiMac(mac);
154 fem->SetProtectionManager(protectionManager);
155
156 Ptr<WifiAckManager> ackManager = CreateObject<WifiDefaultAckManager>();
157 ackManager->SetWifiMac(mac);
158 fem->SetAckManager(ackManager);
159 mac->SwitchFrequencyChannel(channelId);
160
161 return device;
162}
163
164void
165MeshHelper::Report(const ns3::Ptr<ns3::NetDevice>& device, std::ostream& os)
166{
168 Ptr<MeshPointDevice> mp = device->GetObject<MeshPointDevice>();
169 NS_ASSERT(mp);
170 std::vector<Ptr<NetDevice>> ifaces = mp->GetInterfaces();
171 os << "<MeshPointDevice time=\"" << Simulator::Now().GetSeconds() << "\" address=\""
172 << Mac48Address::ConvertFrom(mp->GetAddress()) << "\">\n";
173 m_stack->Report(mp, os);
174 os << "</MeshPointDevice>\n";
175}
176
177void
179{
181 Ptr<MeshPointDevice> mp = device->GetObject<MeshPointDevice>();
182 NS_ASSERT(mp);
183 m_stack->ResetStats(mp);
184}
185
186int64_t
188{
189 int64_t currentStream = stream;
190 Ptr<NetDevice> netDevice;
191 for (auto i = c.Begin(); i != c.End(); ++i)
192 {
193 netDevice = (*i);
194 Ptr<MeshPointDevice> mpd = DynamicCast<MeshPointDevice>(netDevice);
197 if (mpd)
198 {
199 currentStream += mpd->AssignStreams(currentStream);
200 // To access, we need the underlying WifiNetDevices
201 std::vector<Ptr<NetDevice>> ifaces = mpd->GetInterfaces();
202 for (auto i = ifaces.begin(); i != ifaces.end(); i++)
203 {
204 wifi = DynamicCast<WifiNetDevice>(*i);
205
206 // Handle any random numbers in the PHY objects.
207 currentStream += wifi->GetPhy()->AssignStreams(currentStream);
208
209 // Handle any random numbers in the station managers.
210 Ptr<WifiRemoteStationManager> manager = wifi->GetRemoteStationManager();
211 Ptr<MinstrelWifiManager> minstrel = DynamicCast<MinstrelWifiManager>(manager);
212 if (minstrel)
213 {
214 currentStream += minstrel->AssignStreams(currentStream);
215 }
216 // Handle any random numbers in the mesh mac and plugins
217 mac = DynamicCast<MeshWifiInterfaceMac>(wifi->GetMac());
218 currentStream += mac->AssignStreams(currentStream);
219
220 PointerValue ptr;
221 mac->GetAttribute("Txop", ptr);
222 Ptr<Txop> txop = ptr.Get<Txop>();
223 currentStream += txop->AssignStreams(currentStream);
224
225 mac->GetAttribute("VO_Txop", ptr);
226 Ptr<QosTxop> vo_txop = ptr.Get<QosTxop>();
227 currentStream += vo_txop->AssignStreams(currentStream);
228
229 mac->GetAttribute("VI_Txop", ptr);
230 Ptr<QosTxop> vi_txop = ptr.Get<QosTxop>();
231 currentStream += vi_txop->AssignStreams(currentStream);
232
233 mac->GetAttribute("BE_Txop", ptr);
234 Ptr<QosTxop> be_txop = ptr.Get<QosTxop>();
235 currentStream += be_txop->AssignStreams(currentStream);
236
237 mac->GetAttribute("BK_Txop", ptr);
238 Ptr<QosTxop> bk_txop = ptr.Get<QosTxop>();
239 currentStream += bk_txop->AssignStreams(currentStream);
240 }
241 }
242 }
243 return (currentStream - stream);
244}
245
246void
248{
250
251 LogComponentEnable("MeshL2RoutingProtocol", LOG_LEVEL_ALL);
252 LogComponentEnable("MeshPointDevice", LOG_LEVEL_ALL);
253 LogComponentEnable("MeshWifiInterfaceMac", LOG_LEVEL_ALL);
254
255 LogComponentEnable("Dot11sPeerManagementProtocol", LOG_LEVEL_ALL);
256 LogComponentEnable("HwmpProtocol", LOG_LEVEL_ALL);
257 LogComponentEnable("HwmpProtocolMac", LOG_LEVEL_ALL);
258 LogComponentEnable("HwmpRtable", LOG_LEVEL_ALL);
259 LogComponentEnable("PeerManagementProtocol", LOG_LEVEL_ALL);
260 LogComponentEnable("PeerManagementProtocolMac", LOG_LEVEL_ALL);
261
262 LogComponentEnable("FlameProtocol", LOG_LEVEL_ALL);
263 LogComponentEnable("FlameProtocolMac", LOG_LEVEL_ALL);
264 LogComponentEnable("FlameRtable", LOG_LEVEL_ALL);
265}
266
267} // namespace ns3
FrameExchangeManager is a base class handling the basic frame exchange sequences for non-QoS stations...
static Mac48Address ConvertFrom(const Address &address)
static Mac48Address Allocate()
Allocate a new Mac48Address.
Helper to create IEEE 802.11s mesh networks.
Definition: mesh-helper.h:44
void SetRemoteStationManager(std::string type, Ts &&... args)
Set the remote station manager type and Attributes.
Definition: mesh-helper.h:203
void SetStandard(WifiStandard standard)
Set standard.
Definition: mesh-helper.cc:109
Ptr< WifiNetDevice > CreateInterface(const WifiPhyHelper &phyHelper, Ptr< Node > node, uint16_t channelId) const
Definition: mesh-helper.cc:115
Ptr< MeshStack > m_stack
stack
Definition: mesh-helper.h:179
~MeshHelper()
Destroy a MeshHelper.
Definition: mesh-helper.cc:46
uint32_t m_nInterfaces
number of interfaces
Definition: mesh-helper.h:177
ObjectFactory m_stationManager
the station manager
Definition: mesh-helper.h:184
void SetSpreadInterfaceChannels(ChannelPolicy policy)
set the channel policy
Definition: mesh-helper.cc:52
ObjectFactory m_mac
the MAC
Definition: mesh-helper.h:183
ChannelPolicy m_spreadChannelPolicy
spread channel policy
Definition: mesh-helper.h:178
static void EnableLogComponents()
Helper to enable all MeshPointDevice log components with one statement.
Definition: mesh-helper.cc:247
MeshHelper()
Construct a MeshHelper used to make life easier when creating 802.11s networks.
Definition: mesh-helper.cc:38
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:187
static MeshHelper Default()
Set the helper to the default values for the MAC type, remote station manager and channel policy.
Definition: mesh-helper.cc:99
void SetMacType(Ts &&... args)
Set the Mac Attributes.
Definition: mesh-helper.h:195
NetDeviceContainer Install(const WifiPhyHelper &phyHelper, NodeContainer c) const
Install 802.11s mesh device & protocols on given node list.
Definition: mesh-helper.cc:64
ChannelPolicy
Spread/not spread frequency channels of MP interfaces.
Definition: mesh-helper.h:101
WifiStandard m_standard
standard
Definition: mesh-helper.h:186
void ResetStats(const ns3::Ptr< ns3::NetDevice > &device)
Reset statistics.
Definition: mesh-helper.cc:178
void Report(const ns3::Ptr< ns3::NetDevice > &device, std::ostream &os)
Print statistics.
Definition: mesh-helper.cc:165
void SetNumberOfInterfaces(uint32_t nInterfaces)
Set a number of interfaces in a mesh network.
Definition: mesh-helper.cc:58
Virtual net device modeling mesh point.
Basic MAC of mesh point Wi-Fi interface.
holds a vector of ns3::NetDevice pointers
Iterator Begin() const
Get an iterator which refers to the first NetDevice in the container.
Iterator End() const
Get an iterator which indicates past-the-last NetDevice in the container.
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
AttributeValue implementation for Pointer.
Definition: pointer.h:48
Ptr< T > Get() const
Definition: pointer.h:234
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
Definition: qos-txop.h:74
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
Hold variables of type string.
Definition: string.h:56
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:403
Handle packet fragmentation and retransmissions for data and management frames.
Definition: txop.h:82
static void EnableLogComponents(LogLevel logLevel=LOG_LEVEL_ALL)
Helper to enable all WifiNetDevice log components with one statement.
Definition: wifi-helper.cc:880
create PHY objects
Definition: wifi-helper.h:49
virtual std::vector< 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:66
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition: abort.h:76
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
@ WIFI_STANDARD_80211a
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:302
std::string GetFrameExchangeManagerTypeIdName(WifiStandard standard, bool qosSupported)
Get the TypeId name for the FrameExchangeManager corresponding to the given standard.
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116