A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-test-interference-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
7 */
8
9//
10// This script is used to verify the behavior of InterferenceHelper.
11//
12// The scenario consists of two IEEE 802.11 hidden stations and an access point.
13// The two stations have both a packet to transmit to the access point.
14//
15//
16// (xA,0,0) (0,0,0) (xB,0,0)
17//
18// * -----> * <----- *
19// | | |
20// STA A AP STA B
21//
22//
23// The program can be configured at run-time by passing command-line arguments.
24// It enables to configure the delay between the transmission from station A
25// and the transmission from station B (--delay option). It is also possible to
26// select the tx power level (--txPowerA and --txPowerB options), the packet size
27// (--packetSizeA and --packetSizeB options) and the modulation (--txModeA and
28// --txModeB options) used for the respective transmissions.
29//
30// By default, IEEE 802.11a with long preamble type is considered, but those
31// parameters can be also picked among other IEEE 802.11 flavors and preamble
32// types available in the simulator (--standard and --preamble options).
33// Note that the program checks the consistency between the selected standard
34// the selected preamble type.
35//
36// The output of the program displays InterferenceHelper and SpectrumWifiPhy trace
37// logs associated to the chosen scenario.
38//
39
40#include "ns3/command-line.h"
41#include "ns3/config.h"
42#include "ns3/constant-position-mobility-model.h"
43#include "ns3/double.h"
44#include "ns3/interference-helper.h"
45#include "ns3/log.h"
46#include "ns3/nist-error-rate-model.h"
47#include "ns3/node.h"
48#include "ns3/packet.h"
49#include "ns3/propagation-delay-model.h"
50#include "ns3/propagation-loss-model.h"
51#include "ns3/simple-frame-capture-model.h"
52#include "ns3/simulator.h"
53#include "ns3/single-model-spectrum-channel.h"
54#include "ns3/spectrum-wifi-phy.h"
55#include "ns3/wifi-mac-trailer.h"
56#include "ns3/wifi-net-device.h"
57#include "ns3/wifi-psdu.h"
58
59using namespace ns3;
60
61NS_LOG_COMPONENT_DEFINE("test-interference-helper");
62
63bool checkResults = false; //!< True if results have to be checked.
64bool expectRxASuccessful = false; //!< True if Rx from A is expected to be successful.
65bool expectRxBSuccessful = false; //!< True if Rx from B is expected to be successful.
66
67/// InterferenceExperiment
69{
70 public:
71 /// Input structure
72 struct Input
73 {
74 Input();
75 Time interval; ///< interval
76 meter_u xA; ///< x A
77 meter_u xB; ///< x B
78 std::string txModeA; ///< transmit mode A
79 std::string txModeB; ///< transmit mode B
80 double txPowerLevelA; ///< transmit power level A
81 double txPowerLevelB; ///< transmit power level B
82 uint32_t packetSizeA; ///< packet size A
83 uint32_t packetSizeB; ///< packet size B
84 uint16_t channelA; ///< channel number A
85 uint16_t channelB; ///< channel number B
86 MHz_u widthA; ///< channel width A
87 MHz_u widthB; ///< channel width B
88 WifiStandard standard; ///< standard
89 WifiPhyBand band; ///< band
90 WifiPreamble preamble; ///< preamble
91 bool captureEnabled; ///< whether physical layer capture is enabled
92 double captureMargin; ///< margin used for physical layer capture
93 };
94
96 /**
97 * Run function
98 * \param input the interference experiment data
99 */
101
102 private:
103 /**
104 * Function triggered when a packet is dropped
105 * \param packet the packet that was dropped
106 * \param reason the reason why it was dropped
107 */
109 /// Send A function
110 void SendA() const;
111 /// Send B function
112 void SendB() const;
113 Ptr<SpectrumWifiPhy> m_txA; ///< transmit A function
114 Ptr<SpectrumWifiPhy> m_txB; ///< transmit B function
115 Input m_input; ///< input
116 bool m_droppedA; ///< flag to indicate whether packet A has been dropped
117 bool m_droppedB; ///< flag to indicate whether packet B has been dropped
118 mutable uint64_t m_uidA; ///< UID to use for packet A
119 mutable uint64_t m_uidB; ///< UID to use for packet B
120};
121
122void
124{
125 WifiMacHeader hdr;
126 hdr.SetType(WIFI_MAC_CTL_ACK); // so that size may not be empty while being as short as possible
127 Ptr<Packet> p =
129 m_uidA = p->GetUid();
130 Ptr<WifiPsdu> psdu = Create<WifiPsdu>(p, hdr);
131 WifiTxVector txVector;
132 txVector.SetTxPowerLevel(0); // only one TX power level
133 txVector.SetMode(WifiMode(m_input.txModeA));
136 m_txA->Send(psdu, txVector);
137}
138
139void
141{
142 WifiMacHeader hdr;
143 hdr.SetType(WIFI_MAC_CTL_ACK); // so that size may not be empty while being as short as possible
144 Ptr<Packet> p =
146 m_uidB = p->GetUid();
147 Ptr<WifiPsdu> psdu = Create<WifiPsdu>(p, hdr);
148 WifiTxVector txVector;
149 txVector.SetTxPowerLevel(0); // only one TX power level
150 txVector.SetMode(WifiMode(m_input.txModeB));
153 m_txB->Send(psdu, txVector);
154}
155
156void
158{
159 if (packet->GetUid() == m_uidA)
160 {
161 m_droppedA = true;
162 }
163 else if (packet->GetUid() == m_uidB)
164 {
165 m_droppedB = true;
166 }
167 else
168 {
169 NS_LOG_ERROR("Unknown packet!");
170 exit(1);
171 }
172}
173
175 : m_droppedA(false),
176 m_droppedB(false),
177 m_uidA(0),
178 m_uidB(0)
179{
180}
181
183 : interval(MicroSeconds(0)),
184 xA(-5),
185 xB(5),
186 txModeA("OfdmRate54Mbps"),
187 txModeB("OfdmRate54Mbps"),
188 txPowerLevelA(16.0206),
189 txPowerLevelB(16.0206),
190 packetSizeA(1500),
191 packetSizeB(1500),
192 channelA(36),
193 channelB(36),
194 widthA(20),
195 widthB(20),
196 standard(WIFI_STANDARD_80211a),
197 band(WIFI_PHY_BAND_5GHZ),
198 preamble(WIFI_PREAMBLE_LONG),
199 captureEnabled(false),
200 captureMargin(0)
201{
202}
203
204void
206{
207 m_input = input;
208
209 double maxRange = std::max(std::abs(input.xA), input.xB);
210 Config::SetDefault("ns3::RangePropagationLossModel::MaxRange", DoubleValue(maxRange));
211
213 channel->SetPropagationDelayModel(CreateObject<ConstantSpeedPropagationDelayModel>());
215 channel->AddPropagationLossModel(loss);
216
218 posTxA->SetPosition(Vector(input.xA, 0.0, 0.0));
220 posTxB->SetPosition(Vector(input.xB, 0.0, 0.0));
222 posRx->SetPosition(Vector(0.0, 0.0, 0.0));
223
227 m_txA->SetDevice(devA);
228 m_txA->SetTxPowerStart(input.txPowerLevelA);
229 m_txA->SetTxPowerEnd(input.txPowerLevelA);
230
234 m_txB->SetDevice(devB);
235 m_txB->SetTxPowerStart(input.txPowerLevelB);
236 m_txB->SetTxPowerEnd(input.txPowerLevelB);
237
238 Ptr<Node> nodeRx = CreateObject<Node>();
241 rx->SetDevice(devRx);
242
244 m_txA->SetInterferenceHelper(interferenceTxA);
246 m_txA->SetErrorRateModel(errorTxA);
248 m_txB->SetInterferenceHelper(interferenceTxB);
250 m_txB->SetErrorRateModel(errorTxB);
252 rx->SetInterferenceHelper(interferenceRx);
254 rx->SetErrorRateModel(errorRx);
255 m_txA->AddChannel(channel);
256 m_txB->AddChannel(channel);
257 rx->AddChannel(channel);
258 m_txA->SetMobility(posTxA);
259 m_txB->SetMobility(posTxB);
260 rx->SetMobility(posRx);
261 if (input.captureEnabled)
262 {
264 frameCaptureModel->SetMargin(input.captureMargin);
265 rx->SetFrameCaptureModel(frameCaptureModel);
266 }
267
268 m_txA->ConfigureStandard(input.standard);
269 m_txB->ConfigureStandard(input.standard);
270 rx->ConfigureStandard(input.standard);
271
272 devA->SetPhy(m_txA);
273 nodeA->AddDevice(devA);
274 devB->SetPhy(m_txB);
275 nodeB->AddDevice(devB);
276 devRx->SetPhy(rx);
277 nodeRx->AddDevice(devRx);
278
279 m_txA->SetOperatingChannel(WifiPhy::ChannelTuple{input.channelA, 0, input.band, 0});
280 m_txB->SetOperatingChannel(WifiPhy::ChannelTuple{input.channelB, 0, input.band, 0});
281 rx->SetOperatingChannel(
282 WifiPhy::ChannelTuple{std::max(input.channelA, input.channelB), 0, input.band, 0});
283
284 rx->TraceConnectWithoutContext("PhyRxDrop",
286
289
292 m_txB->Dispose();
293 m_txA->Dispose();
294 rx->Dispose();
295
297 {
298 NS_LOG_ERROR("Results are not expected!");
299 exit(1);
300 }
301}
302
303int
304main(int argc, char* argv[])
305{
307 std::string str_standard = "WIFI_PHY_STANDARD_80211a";
308 std::string str_preamble = "WIFI_PREAMBLE_LONG";
309 Time delay{"0us"};
310
311 CommandLine cmd(__FILE__);
312 cmd.AddValue(
313 "delay",
314 "Delay between frame transmission from sender A and frame transmission from sender B",
315 delay);
316 cmd.AddValue("xA", "The position of transmitter A (< 0)", input.xA);
317 cmd.AddValue("xB", "The position of transmitter B (> 0)", input.xB);
318 cmd.AddValue("packetSizeA", "Packet size in bytes of transmitter A", input.packetSizeA);
319 cmd.AddValue("packetSizeB", "Packet size in bytes of transmitter B", input.packetSizeB);
320 cmd.AddValue("txPowerA", "TX power level of transmitter A", input.txPowerLevelA);
321 cmd.AddValue("txPowerB", "TX power level of transmitter B", input.txPowerLevelB);
322 cmd.AddValue("txModeA", "Wifi mode used for payload transmission of sender A", input.txModeA);
323 cmd.AddValue("txModeB", "Wifi mode used for payload transmission of sender B", input.txModeB);
324 cmd.AddValue("channelA", "The selected channel number of sender A", input.channelA);
325 cmd.AddValue("channelB", "The selected channel number of sender B", input.channelB);
326 cmd.AddValue("widthA", "The selected channel width (MHz) of sender A", input.widthA);
327 cmd.AddValue("widthB", "The selected channel width (MHz) of sender B", input.widthB);
328 cmd.AddValue("standard", "IEEE 802.11 flavor", str_standard);
329 cmd.AddValue("preamble", "Type of preamble", str_preamble);
330 cmd.AddValue("enableCapture", "Enable/disable physical layer capture", input.captureEnabled);
331 cmd.AddValue("captureMargin", "Margin used for physical layer capture", input.captureMargin);
332 cmd.AddValue("checkResults", "Used to check results at the end of the test", checkResults);
333 cmd.AddValue("expectRxASuccessful",
334 "Indicate whether packet A is expected to be successfully received",
336 cmd.AddValue("expectRxBSuccessful",
337 "Indicate whether packet B is expected to be successfully received",
339 cmd.Parse(argc, argv);
340
341 input.interval = delay;
342
343 if (input.xA >= 0 || input.xB <= 0)
344 {
345 std::cout << "Value of xA must be smaller than 0 and value of xB must be bigger than 0!"
346 << std::endl;
347 return 0;
348 }
349
350 if (str_standard == "WIFI_PHY_STANDARD_80211a")
351 {
353 input.band = WIFI_PHY_BAND_5GHZ;
354 }
355 else if (str_standard == "WIFI_PHY_STANDARD_80211b")
356 {
359 }
360 else if (str_standard == "WIFI_PHY_STANDARD_80211g")
361 {
364 }
365 else if (str_standard == "WIFI_PHY_STANDARD_80211n_2_4GHZ")
366 {
369 }
370 else if (str_standard == "WIFI_PHY_STANDARD_80211n_5GHZ")
371 {
373 input.band = WIFI_PHY_BAND_5GHZ;
374 }
375 else if (str_standard == "WIFI_PHY_STANDARD_80211ac")
376 {
378 input.band = WIFI_PHY_BAND_5GHZ;
379 }
380 else if (str_standard == "WIFI_PHY_STANDARD_80211ax_2_4GHZ")
381 {
384 }
385 else if (str_standard == "WIFI_PHY_STANDARD_80211ax_5GHZ")
386 {
388 input.band = WIFI_PHY_BAND_5GHZ;
389 }
390
391 if (str_preamble == "WIFI_PREAMBLE_LONG" &&
394 {
396 }
397 else if (str_preamble == "WIFI_PREAMBLE_SHORT" &&
399 {
401 }
402 else if (str_preamble == "WIFI_PREAMBLE_HT_MF" && input.standard == WIFI_STANDARD_80211n)
403 {
405 }
406 else if (str_preamble == "WIFI_PREAMBLE_VHT_SU" && input.standard == WIFI_STANDARD_80211ac)
407 {
409 }
410 else if (str_preamble == "WIFI_PREAMBLE_HE_SU" && input.standard == WIFI_STANDARD_80211ax)
411 {
413 }
414 else
415 {
416 std::cout << "Preamble does not exist or is not compatible with the selected standard!"
417 << std::endl;
418 return 0;
419 }
420
422 experiment.Run(input);
423
424 return 0;
425}
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(InterferenceExperiment::Input input)
Run function.
Parse command-line arguments.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Implements the IEEE 802.11 MAC header.
uint32_t GetSerializedSize() const override
virtual 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:40
std::tuple< uint8_t, MHz_u, WifiPhyBand, uint8_t > ChannelTuple
Tuple identifying a segment of an operating channel.
Definition wifi-phy.h:919
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(MHz_u channelWidth)
Sets the selected channelWidth.
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:883
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition log.h:243
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1332
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
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.
@ 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.
@ WIFI_PHY_BAND_5GHZ
The 5 GHz band.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const uint16_t WIFI_MAC_FCS_LENGTH
The length in octets 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:684
@ WIFI_MAC_CTL_ACK
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 expectRxASuccessful
True if Rx from A is expected to be successful.
bool expectRxBSuccessful
True if Rx from B is expected to be successful.
bool checkResults
True if results have to be checked.