A Discrete-Event Network Simulator
API
wifi-test-interference-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015
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: Sébastien Deronne <sebastien.deronne@gmail.com>
18 */
19
20//
21// This script is used to verify the behavior of InterferenceHelper.
22//
23// The scenario consists of two IEEE 802.11 hidden stations and an access point.
24// The two stations have both a packet to transmit to the access point.
25//
26//
27// (xA,0,0) (0,0,0) (xB,0,0)
28//
29// * -----> * <----- *
30// | | |
31// STA A AP STA B
32//
33//
34// The program can be configured at run-time by passing command-line arguments.
35// It enables to configure the delay between the transmission from station A
36// and the transmission from station B (--delay option). It is also possible to
37// select the tx power level (--txPowerA and --txPowerB options), the packet size
38// (--packetSizeA and --packetSizeB options) and the modulation (--txModeA and
39// --txModeB options) used for the respective transmissions.
40//
41// By default, IEEE 802.11a with long preamble type is considered, but those
42// parameters can be also picked among other IEEE 802.11 flavors and preamble
43// types available in the simulator (--standard and --preamble options).
44// Note that the program checks the consistency between the selected standard
45// the selected preamble type.
46//
47// The output of the program displays InterfenceHelper and SpectrumWifiPhy trace
48// logs associated to the chosen scenario.
49//
50
51#include "ns3/command-line.h"
52#include "ns3/config.h"
53#include "ns3/constant-position-mobility-model.h"
54#include "ns3/double.h"
55#include "ns3/interference-helper.h"
56#include "ns3/log.h"
57#include "ns3/nist-error-rate-model.h"
58#include "ns3/node.h"
59#include "ns3/packet.h"
60#include "ns3/propagation-delay-model.h"
61#include "ns3/propagation-loss-model.h"
62#include "ns3/simple-frame-capture-model.h"
63#include "ns3/simulator.h"
64#include "ns3/single-model-spectrum-channel.h"
65#include "ns3/spectrum-wifi-phy.h"
66#include "ns3/wifi-mac-trailer.h"
67#include "ns3/wifi-net-device.h"
68#include "ns3/wifi-psdu.h"
69
70using namespace ns3;
71
72NS_LOG_COMPONENT_DEFINE("test-interference-helper");
73
74bool checkResults = false;
77
80{
81 public:
83 struct Input
84 {
85 Input();
87 double xA;
88 double xB;
89 std::string txModeA;
90 std::string txModeB;
95 uint16_t channelA;
96 uint16_t channelB;
97 uint16_t widthA;
98 uint16_t widthB;
104 };
105
111 void Run(struct InterferenceExperiment::Input input);
112
113 private:
121 void SendA() const;
123 void SendB() const;
126 struct Input m_input;
129 mutable uint64_t m_uidA;
130 mutable uint64_t m_uidB;
131};
132
133void
135{
136 WifiMacHeader hdr;
137 hdr.SetType(WIFI_MAC_CTL_ACK); // so that size may not be empty while being as short as possible
138 Ptr<Packet> p =
140 m_uidA = p->GetUid();
141 Ptr<WifiPsdu> psdu = Create<WifiPsdu>(p, hdr);
142 WifiTxVector txVector;
143 txVector.SetTxPowerLevel(0); // only one TX power level
144 txVector.SetMode(WifiMode(m_input.txModeA));
147 m_txA->Send(psdu, txVector);
148}
149
150void
152{
153 WifiMacHeader hdr;
154 hdr.SetType(WIFI_MAC_CTL_ACK); // so that size may not be empty while being as short as possible
155 Ptr<Packet> p =
157 m_uidB = p->GetUid();
158 Ptr<WifiPsdu> psdu = Create<WifiPsdu>(p, hdr);
159 WifiTxVector txVector;
160 txVector.SetTxPowerLevel(0); // only one TX power level
161 txVector.SetMode(WifiMode(m_input.txModeB));
164 m_txB->Send(psdu, txVector);
165}
166
167void
169{
170 if (packet->GetUid() == m_uidA)
171 {
172 m_droppedA = true;
173 }
174 else if (packet->GetUid() == m_uidB)
175 {
176 m_droppedB = true;
177 }
178 else
179 {
180 NS_LOG_ERROR("Unknown packet!");
181 exit(1);
182 }
183}
184
186 : m_droppedA(false),
187 m_droppedB(false),
188 m_uidA(0),
189 m_uidB(0)
190{
191}
192
194 : interval(MicroSeconds(0)),
195 xA(-5),
196 xB(5),
197 txModeA("OfdmRate54Mbps"),
198 txModeB("OfdmRate54Mbps"),
199 txPowerLevelA(16.0206),
200 txPowerLevelB(16.0206),
201 packetSizeA(1500),
202 packetSizeB(1500),
203 channelA(36),
204 channelB(36),
205 widthA(20),
206 widthB(20),
207 standard(WIFI_STANDARD_80211a),
208 band(WIFI_PHY_BAND_5GHZ),
209 preamble(WIFI_PREAMBLE_LONG),
210 captureEnabled(false),
211 captureMargin(0)
212{
213}
214
215void
217{
218 m_input = input;
219
220 double range = std::max(std::abs(input.xA), input.xB);
221 Config::SetDefault("ns3::RangePropagationLossModel::MaxRange", DoubleValue(range));
222
223 Ptr<SingleModelSpectrumChannel> channel = CreateObject<SingleModelSpectrumChannel>();
224 channel->SetPropagationDelayModel(CreateObject<ConstantSpeedPropagationDelayModel>());
225 Ptr<RangePropagationLossModel> loss = CreateObject<RangePropagationLossModel>();
226 channel->AddPropagationLossModel(loss);
227
228 Ptr<MobilityModel> posTxA = CreateObject<ConstantPositionMobilityModel>();
229 posTxA->SetPosition(Vector(input.xA, 0.0, 0.0));
230 Ptr<MobilityModel> posTxB = CreateObject<ConstantPositionMobilityModel>();
231 posTxB->SetPosition(Vector(input.xB, 0.0, 0.0));
232 Ptr<MobilityModel> posRx = CreateObject<ConstantPositionMobilityModel>();
233 posRx->SetPosition(Vector(0.0, 0.0, 0.0));
234
235 Ptr<Node> nodeA = CreateObject<Node>();
236 Ptr<WifiNetDevice> devA = CreateObject<WifiNetDevice>();
237 m_txA = CreateObject<SpectrumWifiPhy>();
239 m_txA->SetDevice(devA);
242
243 Ptr<Node> nodeB = CreateObject<Node>();
244 Ptr<WifiNetDevice> devB = CreateObject<WifiNetDevice>();
245 m_txB = CreateObject<SpectrumWifiPhy>();
247 m_txB->SetDevice(devB);
250
251 Ptr<Node> nodeRx = CreateObject<Node>();
252 Ptr<WifiNetDevice> devRx = CreateObject<WifiNetDevice>();
253 Ptr<SpectrumWifiPhy> rx = CreateObject<SpectrumWifiPhy>();
255 rx->SetDevice(devRx);
256
257 Ptr<InterferenceHelper> interferenceTxA = CreateObject<InterferenceHelper>();
258 m_txA->SetInterferenceHelper(interferenceTxA);
259 Ptr<ErrorRateModel> errorTxA = CreateObject<NistErrorRateModel>();
260 m_txA->SetErrorRateModel(errorTxA);
261 Ptr<InterferenceHelper> interferenceTxB = CreateObject<InterferenceHelper>();
262 m_txB->SetInterferenceHelper(interferenceTxB);
263 Ptr<ErrorRateModel> errorTxB = CreateObject<NistErrorRateModel>();
264 m_txB->SetErrorRateModel(errorTxB);
265 Ptr<InterferenceHelper> interferenceRx = CreateObject<InterferenceHelper>();
266 rx->SetInterferenceHelper(interferenceRx);
267 Ptr<ErrorRateModel> errorRx = CreateObject<NistErrorRateModel>();
268 rx->SetErrorRateModel(errorRx);
271 rx->SetChannel(channel);
272 m_txA->SetMobility(posTxA);
273 m_txB->SetMobility(posTxB);
274 rx->SetMobility(posRx);
275 if (input.captureEnabled)
276 {
277 Ptr<SimpleFrameCaptureModel> frameCaptureModel = CreateObject<SimpleFrameCaptureModel>();
278 frameCaptureModel->SetMargin(input.captureMargin);
279 rx->SetFrameCaptureModel(frameCaptureModel);
280 }
281
284 rx->ConfigureStandard(input.standard);
285
286 devA->SetPhy(m_txA);
287 nodeA->AddDevice(devA);
288 devB->SetPhy(m_txB);
289 nodeB->AddDevice(devB);
290 devRx->SetPhy(rx);
291 nodeRx->AddDevice(devRx);
292
296 WifiPhy::ChannelTuple{std::max(input.channelA, input.channelB), 0, (int)(input.band), 0});
297
298 rx->TraceConnectWithoutContext("PhyRxDrop",
300
301 Simulator::Schedule(Seconds(0), &InterferenceExperiment::SendA, this);
302 Simulator::Schedule(Seconds(0) + input.interval, &InterferenceExperiment::SendB, this);
303
304 Simulator::Run();
305 Simulator::Destroy();
306 m_txB->Dispose();
307 m_txA->Dispose();
308 rx->Dispose();
309
311 {
312 NS_LOG_ERROR("Results are not expected!");
313 exit(1);
314 }
315}
316
317int
318main(int argc, char* argv[])
319{
321 std::string str_standard = "WIFI_PHY_STANDARD_80211a";
322 std::string str_preamble = "WIFI_PREAMBLE_LONG";
323 uint64_t delay = 0; // microseconds
324
325 CommandLine cmd(__FILE__);
326 cmd.AddValue("delay",
327 "Delay in microseconds between frame transmission from sender A and frame "
328 "transmission from sender B",
329 delay);
330 cmd.AddValue("xA", "The position of transmitter A (< 0)", input.xA);
331 cmd.AddValue("xB", "The position of transmitter B (> 0)", input.xB);
332 cmd.AddValue("packetSizeA", "Packet size in bytes of transmitter A", input.packetSizeA);
333 cmd.AddValue("packetSizeB", "Packet size in bytes of transmitter B", input.packetSizeB);
334 cmd.AddValue("txPowerA", "TX power level of transmitter A", input.txPowerLevelA);
335 cmd.AddValue("txPowerB", "TX power level of transmitter B", input.txPowerLevelB);
336 cmd.AddValue("txModeA", "Wifi mode used for payload transmission of sender A", input.txModeA);
337 cmd.AddValue("txModeB", "Wifi mode used for payload transmission of sender B", input.txModeB);
338 cmd.AddValue("channelA", "The selected channel number of sender A", input.channelA);
339 cmd.AddValue("channelB", "The selected channel number of sender B", input.channelB);
340 cmd.AddValue("widthA", "The selected channel width (MHz) of sender A", input.widthA);
341 cmd.AddValue("widthB", "The selected channel width (MHz) of sender B", input.widthB);
342 cmd.AddValue("standard", "IEEE 802.11 flavor", str_standard);
343 cmd.AddValue("preamble", "Type of preamble", str_preamble);
344 cmd.AddValue("enableCapture", "Enable/disable physical layer capture", input.captureEnabled);
345 cmd.AddValue("captureMargin", "Margin used for physical layer capture", input.captureMargin);
346 cmd.AddValue("checkResults", "Used to check results at the end of the test", checkResults);
347 cmd.AddValue("expectRxASuccessfull",
348 "Indicate whether packet A is expected to be successfully received",
350 cmd.AddValue("expectRxBSuccessfull",
351 "Indicate whether packet B is expected to be successfully received",
353 cmd.Parse(argc, argv);
354
355 input.interval = MicroSeconds(delay);
356
357 if (input.xA >= 0 || input.xB <= 0)
358 {
359 std::cout << "Value of xA must be smaller than 0 and value of xB must be bigger than 0!"
360 << std::endl;
361 return 0;
362 }
363
364 if (str_standard == "WIFI_PHY_STANDARD_80211a")
365 {
367 input.band = WIFI_PHY_BAND_5GHZ;
368 }
369 else if (str_standard == "WIFI_PHY_STANDARD_80211b")
370 {
373 }
374 else if (str_standard == "WIFI_PHY_STANDARD_80211g")
375 {
378 }
379 else if (str_standard == "WIFI_PHY_STANDARD_80211n_2_4GHZ")
380 {
383 }
384 else if (str_standard == "WIFI_PHY_STANDARD_80211n_5GHZ")
385 {
387 input.band = WIFI_PHY_BAND_5GHZ;
388 }
389 else if (str_standard == "WIFI_PHY_STANDARD_80211ac")
390 {
392 input.band = WIFI_PHY_BAND_5GHZ;
393 }
394 else if (str_standard == "WIFI_PHY_STANDARD_80211ax_2_4GHZ")
395 {
398 }
399 else if (str_standard == "WIFI_PHY_STANDARD_80211ax_5GHZ")
400 {
402 input.band = WIFI_PHY_BAND_5GHZ;
403 }
404
405 if (str_preamble == "WIFI_PREAMBLE_LONG" &&
408 {
410 }
411 else if (str_preamble == "WIFI_PREAMBLE_SHORT" &&
413 {
415 }
416 else if (str_preamble == "WIFI_PREAMBLE_HT_MF" && input.standard == WIFI_STANDARD_80211n)
417 {
419 }
420 else if (str_preamble == "WIFI_PREAMBLE_VHT_SU" && input.standard == WIFI_STANDARD_80211ac)
421 {
423 }
424 else if (str_preamble == "WIFI_PREAMBLE_HE_SU" && input.standard == WIFI_STANDARD_80211ax)
425 {
427 }
428 else
429 {
430 std::cout << "Preamble does not exist or is not compatible with the selected standard!"
431 << std::endl;
432 return 0;
433 }
434
436 experiment.Run(input);
437
438 return 0;
439}
#define max(a, b)
Definition: 80211b.c:43
Ptr< SpectrumWifiPhy > m_txA
transmit A function
bool m_droppedB
flag to indicate whether packet B has been dropped
uint64_t m_uidB
UID to use for packet B.
bool m_droppedA
flag to indicate whether packet A has been dropped
void SendB() const
Send B function.
void PacketDropped(Ptr< const Packet > packet, WifiPhyRxfailureReason reason)
Function triggered when a packet is dropped.
Ptr< SpectrumWifiPhy > m_txB
transmit B function
uint64_t m_uidA
UID to use for packet A.
void SendA() const
Send A function.
void Run(struct InterferenceExperiment::Input input)
Run function.
Parse command-line arguments.
Definition: command-line.h:232
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
void SetPosition(const Vector &position)
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:138
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:369
void Dispose()
Dispose of this Object.
Definition: object.cc:219
uint64_t GetUid() const
Returns the packet's Uid.
Definition: packet.cc:412
void SetChannel(const Ptr< SpectrumChannel > channel)
Set the SpectrumChannel this SpectrumWifiPhy is to be connected to.
void CreateWifiSpectrumPhyInterface(Ptr< NetDevice > device)
Method to encapsulate the creation of the WifiSpectrumPhyInterface object (used to bind the WifiSpect...
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Implements the IEEE 802.11 MAC header.
uint32_t GetSerializedSize() const override
void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
represent a single transmission mode
Definition: wifi-mode.h:50
void SetPhy(const Ptr< WifiPhy > phy)
virtual void SetInterferenceHelper(const Ptr< InterferenceHelper > helper)
Sets the interference helper.
Definition: wifi-phy.cc:606
void Send(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector)
This function is a wrapper for the Send variant that accepts a WifiConstPsduMap as first argument.
Definition: wifi-phy.cc:1635
void SetErrorRateModel(const Ptr< ErrorRateModel > model)
Sets the error rate model.
Definition: wifi-phy.cc:614
virtual void ConfigureStandard(WifiStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:895
void SetOperatingChannel(const ChannelTuple &channelTuple)
If the standard for this object has not been set yet, store the given channel settings.
Definition: wifi-phy.cc:1004
void SetDevice(const Ptr< WifiNetDevice > device)
Sets the device this PHY is associated with.
Definition: wifi-phy.cc:575
void SetTxPowerEnd(double end)
Sets the maximum available transmission power level (dBm).
Definition: wifi-phy.cc:510
void SetMobility(const Ptr< MobilityModel > mobility)
assign a mobility model to this device
Definition: wifi-phy.cc:587
void SetFrameCaptureModel(const Ptr< FrameCaptureModel > frameCaptureModel)
Sets the frame capture model.
Definition: wifi-phy.cc:628
std::tuple< uint8_t, uint16_t, int, uint8_t > ChannelTuple
Tuple identifying an operating channel.
Definition: wifi-phy.h:869
void SetTxPowerStart(double start)
Sets the minimum available transmission power level (dBm).
Definition: wifi-phy.cc:497
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
void experiment(std::string queue_disc_type)
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:891
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1362
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
WifiPhyRxfailureReason
Enumeration of the possible reception failure reasons.
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
WifiPhyBand
Identifies the PHY band.
Definition: wifi-phy-band.h:33
@ WIFI_STANDARD_80211a
@ WIFI_STANDARD_80211n
@ WIFI_STANDARD_80211g
@ WIFI_STANDARD_80211ax
@ WIFI_STANDARD_80211ac
@ WIFI_STANDARD_80211b
@ WIFI_PREAMBLE_LONG
@ WIFI_PREAMBLE_HE_SU
@ WIFI_PREAMBLE_VHT_SU
@ WIFI_PREAMBLE_SHORT
@ WIFI_PREAMBLE_HT_MF
@ WIFI_PHY_BAND_2_4GHZ
The 2.4 GHz band.
Definition: wifi-phy-band.h:35
@ WIFI_PHY_BAND_5GHZ
The 5 GHz band.
Definition: wifi-phy-band.h:37
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const uint16_t WIFI_MAC_FCS_LENGTH
The length in octects of the IEEE 802.11 MAC FCS field.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:691
@ WIFI_MAC_CTL_ACK
cmd
Definition: second.py:33
channel
Definition: third.py:81
double txPowerLevelA
transmit power level A
double txPowerLevelB
transmit power level B
bool captureEnabled
whether physical layer capture is enabled
double captureMargin
margin used for physical layer capture
bool expectRxBSuccessfull
True if Rx from B is expected to be successful.
bool checkResults
True if results have to be checked.
bool expectRxASuccessfull
True if Rx from A is expected to be successful.