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/wifi-default-ack-manager.h"
31#include "ns3/wifi-default-protection-manager.h"
32#include "ns3/wifi-helper.h"
33#include "ns3/wifi-net-device.h"
34
35namespace ns3
36{
38 : m_nInterfaces(1),
39 m_spreadChannelPolicy(ZERO_CHANNEL),
40 m_stack(nullptr),
41 m_standard(WIFI_STANDARD_80211a)
42{
43}
44
46{
47 m_stack = nullptr;
48}
49
50void
52{
53 m_spreadChannelPolicy = policy;
54}
55
56void
58{
59 m_nInterfaces = nInterfaces;
60}
61
64{
65 NetDeviceContainer devices;
67 for (auto i = c.Begin(); i != c.End(); ++i)
68 {
69 Ptr<Node> node = *i;
70 // Create a mesh point device
71 Ptr<MeshPointDevice> mp = CreateObject<MeshPointDevice>();
72 node->AddDevice(mp);
73 // Create wifi interfaces (single interface by default)
74 for (uint32_t i = 0; i < m_nInterfaces; ++i)
75 {
76 uint32_t channel = 0;
78 {
79 channel = 100;
80 }
82 {
83 channel = 100 + i * 5;
84 }
85 Ptr<WifiNetDevice> iface = CreateInterface(phyHelper, node, channel);
86 mp->AddInterface(iface);
87 }
88 if (!m_stack->InstallStack(mp))
89 {
90 NS_FATAL_ERROR("Stack is not installed!");
91 }
92 devices.Add(mp);
93 }
94 return devices;
95}
96
99{
100 MeshHelper helper;
101 helper.SetMacType();
102 helper.SetRemoteStationManager("ns3::ArfWifiManager");
104 return helper;
105}
106
107void
109{
110 m_standard = standard;
111}
112
115 Ptr<Node> node,
116 uint16_t channelId) const
117{
118 Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice>();
119
120 // this is a const method, but we need to force the correct QoS setting
121 ObjectFactory macObjectFactory = m_mac;
122 macObjectFactory.Set("QosSupported", BooleanValue(true)); // a mesh station is a QoS station
123 std::vector<Ptr<WifiPhy>> phys = phyHelper.Create(node, device);
124 NS_ABORT_IF(phys.size() != 1);
125 node->AddDevice(device);
126 phys[0]->ConfigureStandard(m_standard);
127 device->SetPhy(phys[0]);
128 Ptr<MeshWifiInterfaceMac> mac = macObjectFactory.Create<MeshWifiInterfaceMac>();
129 NS_ASSERT(mac);
130 mac->SetSsid(Ssid());
131 mac->SetDevice(device);
133 NS_ASSERT(manager);
134 device->SetRemoteStationManager(manager);
135 mac->SetAddress(Mac48Address::Allocate());
136 device->SetMac(mac);
137 mac->SetMacQueueScheduler(CreateObject<FcfsWifiQueueScheduler>());
138 mac->ConfigureStandard(m_standard);
139 Ptr<FrameExchangeManager> fem = mac->GetFrameExchangeManager();
140 if (fem)
141 {
142 Ptr<WifiProtectionManager> protectionManager = CreateObject<WifiDefaultProtectionManager>();
143 protectionManager->SetWifiMac(mac);
144 fem->SetProtectionManager(protectionManager);
145
146 Ptr<WifiAckManager> ackManager = CreateObject<WifiDefaultAckManager>();
147 ackManager->SetWifiMac(mac);
148 fem->SetAckManager(ackManager);
149 }
150 mac->SwitchFrequencyChannel(channelId);
151
152 return device;
153}
154
155void
156MeshHelper::Report(const ns3::Ptr<ns3::NetDevice>& device, std::ostream& os)
157{
159 Ptr<MeshPointDevice> mp = device->GetObject<MeshPointDevice>();
160 NS_ASSERT(mp);
161 std::vector<Ptr<NetDevice>> ifaces = mp->GetInterfaces();
162 os << "<MeshPointDevice time=\"" << Simulator::Now().GetSeconds() << "\" address=\""
163 << Mac48Address::ConvertFrom(mp->GetAddress()) << "\">\n";
164 m_stack->Report(mp, os);
165 os << "</MeshPointDevice>\n";
166}
167
168void
170{
172 Ptr<MeshPointDevice> mp = device->GetObject<MeshPointDevice>();
173 NS_ASSERT(mp);
174 m_stack->ResetStats(mp);
175}
176
177int64_t
179{
180 int64_t currentStream = stream;
181 Ptr<NetDevice> netDevice;
182 for (auto i = c.Begin(); i != c.End(); ++i)
183 {
184 netDevice = (*i);
185 Ptr<MeshPointDevice> mpd = DynamicCast<MeshPointDevice>(netDevice);
188 if (mpd)
189 {
190 currentStream += mpd->AssignStreams(currentStream);
191 // To access, we need the underlying WifiNetDevices
192 std::vector<Ptr<NetDevice>> ifaces = mpd->GetInterfaces();
193 for (auto i = ifaces.begin(); i != ifaces.end(); i++)
194 {
195 wifi = DynamicCast<WifiNetDevice>(*i);
196
197 // Handle any random numbers in the PHY objects.
198 currentStream += wifi->GetPhy()->AssignStreams(currentStream);
199
200 // Handle any random numbers in the station managers.
201 Ptr<WifiRemoteStationManager> manager = wifi->GetRemoteStationManager();
202 Ptr<MinstrelWifiManager> minstrel = DynamicCast<MinstrelWifiManager>(manager);
203 if (minstrel)
204 {
205 currentStream += minstrel->AssignStreams(currentStream);
206 }
207 // Handle any random numbers in the mesh mac and plugins
208 mac = DynamicCast<MeshWifiInterfaceMac>(wifi->GetMac());
209 currentStream += mac->AssignStreams(currentStream);
210
211 PointerValue ptr;
212 mac->GetAttribute("Txop", ptr);
213 Ptr<Txop> txop = ptr.Get<Txop>();
214 currentStream += txop->AssignStreams(currentStream);
215
216 mac->GetAttribute("VO_Txop", ptr);
217 Ptr<QosTxop> vo_txop = ptr.Get<QosTxop>();
218 currentStream += vo_txop->AssignStreams(currentStream);
219
220 mac->GetAttribute("VI_Txop", ptr);
221 Ptr<QosTxop> vi_txop = ptr.Get<QosTxop>();
222 currentStream += vi_txop->AssignStreams(currentStream);
223
224 mac->GetAttribute("BE_Txop", ptr);
225 Ptr<QosTxop> be_txop = ptr.Get<QosTxop>();
226 currentStream += be_txop->AssignStreams(currentStream);
227
228 mac->GetAttribute("BK_Txop", ptr);
229 Ptr<QosTxop> bk_txop = ptr.Get<QosTxop>();
230 currentStream += bk_txop->AssignStreams(currentStream);
231 }
232 }
233 }
234 return (currentStream - stream);
235}
236
237void
239{
241
242 LogComponentEnable("MeshL2RoutingProtocol", LOG_LEVEL_ALL);
243 LogComponentEnable("MeshPointDevice", LOG_LEVEL_ALL);
244 LogComponentEnable("MeshWifiInterfaceMac", LOG_LEVEL_ALL);
245
246 LogComponentEnable("Dot11sPeerManagementProtocol", LOG_LEVEL_ALL);
247 LogComponentEnable("HwmpProtocol", LOG_LEVEL_ALL);
248 LogComponentEnable("HwmpProtocolMac", LOG_LEVEL_ALL);
249 LogComponentEnable("HwmpRtable", LOG_LEVEL_ALL);
250 LogComponentEnable("PeerManagementProtocol", LOG_LEVEL_ALL);
251 LogComponentEnable("PeerManagementProtocolMac", LOG_LEVEL_ALL);
252
253 LogComponentEnable("FlameProtocol", LOG_LEVEL_ALL);
254 LogComponentEnable("FlameProtocolMac", LOG_LEVEL_ALL);
255 LogComponentEnable("FlameRtable", LOG_LEVEL_ALL);
256}
257
258} // namespace ns3
AttributeValue implementation for Boolean.
Definition: boolean.h:37
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:108
Ptr< WifiNetDevice > CreateInterface(const WifiPhyHelper &phyHelper, Ptr< Node > node, uint16_t channelId) const
Definition: mesh-helper.cc:114
Ptr< MeshStack > m_stack
stack
Definition: mesh-helper.h:179
~MeshHelper()
Destroy a MeshHelper.
Definition: mesh-helper.cc:45
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:51
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:238
MeshHelper()
Construct a MeshHelper used to make life easier when creating 802.11s networks.
Definition: mesh-helper.cc:37
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:178
static MeshHelper Default()
Set the helper to the default values for the MAC type, remote station manager and channel policy.
Definition: mesh-helper.cc:98
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:63
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:169
void Report(const ns3::Ptr< ns3::NetDevice > &device, std::ostream &os)
Print statistics.
Definition: mesh-helper.cc:156
void SetNumberOfInterfaces(uint32_t nInterfaces)
Set a number of interfaces in a mesh network.
Definition: mesh-helper.cc:57
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.
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
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:80
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
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116