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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Kirill Andreev <andreev@iitp.ru>
7 * Pavel Boyko <boyko@iitp.ru>
8 */
9
10#include "mesh-helper.h"
11
12#include "ns3/fcfs-wifi-queue-scheduler.h"
13#include "ns3/frame-exchange-manager.h"
14#include "ns3/mesh-point-device.h"
15#include "ns3/mesh-wifi-interface-mac.h"
16#include "ns3/minstrel-wifi-manager.h"
17#include "ns3/pointer.h"
18#include "ns3/simulator.h"
19#include "ns3/string.h"
20#include "ns3/wifi-default-ack-manager.h"
21#include "ns3/wifi-default-protection-manager.h"
22#include "ns3/wifi-helper.h"
23#include "ns3/wifi-net-device.h"
24
25namespace ns3
26{
28 : m_nInterfaces(1),
29 m_spreadChannelPolicy(ZERO_CHANNEL),
30 m_stack(nullptr),
31 m_standard(WIFI_STANDARD_80211a)
32{
33}
34
36{
37 m_stack = nullptr;
38}
39
40void
45
46void
48{
49 m_nInterfaces = nInterfaces;
50}
51
54{
55 NetDeviceContainer devices;
57 for (auto i = c.Begin(); i != c.End(); ++i)
58 {
59 Ptr<Node> node = *i;
60 // Create a mesh point device
62 node->AddDevice(mp);
63 // Create wifi interfaces (single interface by default)
64 for (uint32_t i = 0; i < m_nInterfaces; ++i)
65 {
66 uint32_t channel = 0;
68 {
69 channel = 100;
70 }
72 {
73 channel = 100 + i * 5;
74 }
75 Ptr<WifiNetDevice> iface = CreateInterface(phyHelper, node, channel);
76 mp->AddInterface(iface);
77 }
78 if (!m_stack->InstallStack(mp))
79 {
80 NS_FATAL_ERROR("Stack is not installed!");
81 }
82 devices.Add(mp);
83 }
84 return devices;
85}
86
89{
90 MeshHelper helper;
91 helper.SetMacType();
92 helper.SetRemoteStationManager("ns3::ArfWifiManager");
94 return helper;
95}
96
97void
99{
100 m_standard = standard;
101}
102
105 Ptr<Node> node,
106 uint16_t channelId) const
107{
109
110 // this is a const method, but we need to force the correct QoS setting
111 ObjectFactory macObjectFactory = m_mac;
112 macObjectFactory.Set("QosSupported", BooleanValue(true)); // a mesh station is a QoS station
113 // create (Qos)Txop objects
114 for (const std::string ac : {"BE", "BK", "VI", "VO"})
115 {
116 auto qosTxop =
117 CreateObjectWithAttributes<QosTxop>("AcIndex", StringValue(std::string("AC_") + ac));
118 macObjectFactory.Set(ac + "_Txop", PointerValue(qosTxop));
119 }
120 std::vector<Ptr<WifiPhy>> phys = phyHelper.Create(node, device);
121 NS_ABORT_IF(phys.size() != 1);
122 node->AddDevice(device);
123 phys[0]->ConfigureStandard(m_standard);
124 device->SetPhy(phys[0]);
125 Ptr<MeshWifiInterfaceMac> mac = macObjectFactory.Create<MeshWifiInterfaceMac>();
126 NS_ASSERT(mac);
127 mac->SetSsid(Ssid());
128 mac->SetDevice(device);
130 NS_ASSERT(manager);
131 device->SetRemoteStationManager(manager);
132 mac->SetAddress(Mac48Address::Allocate());
133 device->SetMac(mac);
134 mac->SetMacQueueScheduler(CreateObject<FcfsWifiQueueScheduler>());
135 mac->SetChannelAccessManagers({CreateObject<ChannelAccessManager>()});
136 ObjectFactory femFactory;
138 auto fem = femFactory.Create<FrameExchangeManager>();
139 mac->SetFrameExchangeManagers({fem});
140 fem->SetAddress(mac->GetAddress());
142 protectionManager->SetWifiMac(mac);
143 fem->SetProtectionManager(protectionManager);
144
146 ackManager->SetWifiMac(mac);
147 fem->SetAckManager(ackManager);
148 mac->SwitchFrequencyChannel(channelId);
149
150 return device;
151}
152
153void
154MeshHelper::Report(const ns3::Ptr<ns3::NetDevice>& device, std::ostream& os)
155{
157 Ptr<MeshPointDevice> mp = device->GetObject<MeshPointDevice>();
158 NS_ASSERT(mp);
159 std::vector<Ptr<NetDevice>> ifaces = mp->GetInterfaces();
160 os << "<MeshPointDevice time=\"" << Simulator::Now().GetSeconds() << "\" address=\""
161 << Mac48Address::ConvertFrom(mp->GetAddress()) << "\">\n";
162 m_stack->Report(mp, os);
163 os << "</MeshPointDevice>\n";
164}
165
166void
168{
170 Ptr<MeshPointDevice> mp = device->GetObject<MeshPointDevice>();
171 NS_ASSERT(mp);
172 m_stack->ResetStats(mp);
173}
174
175int64_t
177{
178 int64_t currentStream = stream;
179 Ptr<NetDevice> netDevice;
180 for (auto i = c.Begin(); i != c.End(); ++i)
181 {
182 netDevice = (*i);
186 if (mpd)
187 {
188 currentStream += mpd->AssignStreams(currentStream);
189 // To access, we need the underlying WifiNetDevices
190 std::vector<Ptr<NetDevice>> ifaces = mpd->GetInterfaces();
191 for (auto i = ifaces.begin(); i != ifaces.end(); i++)
192 {
194
195 // Handle any random numbers in the PHY objects.
196 currentStream += wifi->GetPhy()->AssignStreams(currentStream);
197
198 // Handle any random numbers in the station managers.
199 Ptr<WifiRemoteStationManager> manager = wifi->GetRemoteStationManager();
201 if (minstrel)
202 {
203 currentStream += minstrel->AssignStreams(currentStream);
204 }
205 // Handle any random numbers in the mesh mac and plugins
206 mac = DynamicCast<MeshWifiInterfaceMac>(wifi->GetMac());
207 currentStream += mac->AssignStreams(currentStream);
208
209 PointerValue ptr;
210 mac->GetAttribute("Txop", ptr);
211 Ptr<Txop> txop = ptr.Get<Txop>();
212 currentStream += txop->AssignStreams(currentStream);
213
214 mac->GetAttribute("VO_Txop", ptr);
215 Ptr<QosTxop> vo_txop = ptr.Get<QosTxop>();
216 currentStream += vo_txop->AssignStreams(currentStream);
217
218 mac->GetAttribute("VI_Txop", ptr);
219 Ptr<QosTxop> vi_txop = ptr.Get<QosTxop>();
220 currentStream += vi_txop->AssignStreams(currentStream);
221
222 mac->GetAttribute("BE_Txop", ptr);
223 Ptr<QosTxop> be_txop = ptr.Get<QosTxop>();
224 currentStream += be_txop->AssignStreams(currentStream);
225
226 mac->GetAttribute("BK_Txop", ptr);
227 Ptr<QosTxop> bk_txop = ptr.Get<QosTxop>();
228 currentStream += bk_txop->AssignStreams(currentStream);
229 }
230 }
231 }
232 return (currentStream - stream);
233}
234
235void
237{
239
240 LogComponentEnable("MeshL2RoutingProtocol", LOG_LEVEL_ALL);
241 LogComponentEnable("MeshPointDevice", LOG_LEVEL_ALL);
242 LogComponentEnable("MeshWifiInterfaceMac", LOG_LEVEL_ALL);
243
244 LogComponentEnable("Dot11sPeerManagementProtocol", LOG_LEVEL_ALL);
245 LogComponentEnable("HwmpProtocol", LOG_LEVEL_ALL);
246 LogComponentEnable("HwmpProtocolMac", LOG_LEVEL_ALL);
247 LogComponentEnable("HwmpRtable", LOG_LEVEL_ALL);
248 LogComponentEnable("PeerManagementProtocol", LOG_LEVEL_ALL);
249 LogComponentEnable("PeerManagementProtocolMac", LOG_LEVEL_ALL);
250
251 LogComponentEnable("FlameProtocol", LOG_LEVEL_ALL);
252 LogComponentEnable("FlameProtocolMac", LOG_LEVEL_ALL);
253 LogComponentEnable("FlameRtable", LOG_LEVEL_ALL);
254}
255
256} // 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:33
void SetRemoteStationManager(std::string type, Ts &&... args)
Set the remote station manager type and Attributes.
void SetStandard(WifiStandard standard)
Set standard.
Ptr< WifiNetDevice > CreateInterface(const WifiPhyHelper &phyHelper, Ptr< Node > node, uint16_t channelId) const
Ptr< MeshStack > m_stack
stack
~MeshHelper()
Destroy a MeshHelper.
uint32_t m_nInterfaces
number of interfaces
ObjectFactory m_stationManager
the station manager
void SetSpreadInterfaceChannels(ChannelPolicy policy)
set the channel policy
ObjectFactory m_mac
the MAC
ChannelPolicy m_spreadChannelPolicy
spread channel policy
static void EnableLogComponents()
Helper to enable all MeshPointDevice log components with one statement.
MeshHelper()
Construct a MeshHelper used to make life easier when creating 802.11s networks.
int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
static MeshHelper Default()
Set the helper to the default values for the MAC type, remote station manager and channel policy.
void SetMacType(Ts &&... args)
Set the Mac Attributes.
NetDeviceContainer Install(const WifiPhyHelper &phyHelper, NodeContainer c) const
Install 802.11s mesh device & protocols on given node list.
ChannelPolicy
Spread/not spread frequency channels of MP interfaces.
Definition mesh-helper.h:90
WifiStandard m_standard
standard
void ResetStats(const ns3::Ptr< ns3::NetDevice > &device)
Reset statistics.
void Report(const ns3::Ptr< ns3::NetDevice > &device, std::ostream &os)
Print statistics.
void SetNumberOfInterfaces(uint32_t nInterfaces)
Set a number of interfaces in a mesh network.
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.
Ptr< T > Get() const
Definition pointer.h:223
Smart pointer class similar to boost::intrusive_ptr.
Handles the packet queue and stores DCF/EDCA access parameters (one Txop per AC).
Definition qos-txop.h:52
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
The IEEE 802.11 SSID Information Element.
Definition ssid.h:25
Hold variables of type string.
Definition string.h:45
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
Handles the packet queue and stores DCF/EDCA access parameters (one Txop per AC).
Definition txop.h:56
static void EnableLogComponents(LogLevel logLevel=LOG_LEVEL_ALL)
Helper to enable all WifiNetDevice log components with one statement.
create PHY objects
Definition wifi-helper.h:39
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:55
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition abort.h:65
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Ptr< T > CreateObjectWithAttributes(Args... args)
Allocate an Object on the heap and initialize with a set of attributes.
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:291
std::string GetFrameExchangeManagerTypeIdName(WifiStandard standard, bool qosSupported)
Get the TypeId name for the FrameExchangeManager corresponding to the given standard.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
@ LOG_LEVEL_ALL
Print everything.
Definition log.h:105