A Discrete-Event Network Simulator
API
test-interference-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: S├ębastien Deronne <sebastien.deronne@gmail.com>
19  */
20 
21 //
22 // This script is used to verify the behavior of InterferenceHelper.
23 //
24 // The scenario consists of two IEEE 802.11 hidden stations and an access point.
25 // The two stations have both a packet to transmit to the access point.
26 //
27 //
28 // (xA,0,0) (0,0,0) (xB,0,0)
29 //
30 // * -----> * <----- *
31 // | | |
32 // STA A AP STA B
33 //
34 //
35 // The program can be configured at run-time by passing command-line arguments.
36 // It enables to configure the delay between the transmission from station A
37 // and the transmission from station B (--delay option). It is also possible to
38 // select the tx power level (--txPowerA and --txPowerB options), the packet size
39 // (--packetSizeA and --packetSizeB options) and the modulation (--txModeA and
40 // --txModeB options) used for the respective transmissions.
41 //
42 // By default, IEEE 802.11a with long preamble type is considered, but those
43 // parameters can be also picked among other IEEE 802.11 flavors and preamble
44 // types available in the simulator (--standard and --preamble options).
45 // Note that the program checks the consistency between the selected standard
46 // the selected preamble type.
47 //
48 // The output of the program displays InterfenceHelper and YansWifiPhy trace
49 // logs associated to the chosen scenario.
50 //
51 
52 #include "ns3/log.h"
53 #include "ns3/packet.h"
54 #include "ns3/config.h"
55 #include "ns3/double.h"
56 #include "ns3/simulator.h"
57 #include "ns3/command-line.h"
58 #include "ns3/yans-wifi-channel.h"
59 #include "ns3/yans-wifi-phy.h"
60 #include "ns3/propagation-loss-model.h"
61 #include "ns3/propagation-delay-model.h"
62 #include "ns3/nist-error-rate-model.h"
63 #include "ns3/constant-position-mobility-model.h"
64 #include "ns3/simple-frame-capture-model.h"
65 
66 using namespace ns3;
67 
68 NS_LOG_COMPONENT_DEFINE ("test-interference-helper");
69 
70 bool checkResults = false;
71 bool expectRxASuccessfull = false;
72 bool expectRxBSuccessfull = false;
73 
76 {
77 public:
79  struct Input
80  {
81  Input ();
83  double xA;
84  double xB;
85  std::string txModeA;
86  std::string txModeB;
87  double txPowerLevelA;
88  double txPowerLevelB;
89  uint32_t packetSizeA;
90  uint32_t packetSizeB;
94  double captureMargin;
95  };
96 
102  void Run (struct InterferenceExperiment::Input input);
103 
104 private:
110  void PacketDropped (Ptr<const Packet> packet, WifiPhyRxfailureReason reason);
112  void SendA (void) const;
114  void SendB (void) const;
117  struct Input m_input;
118  bool m_droppedA;
119  bool m_droppedB;
120 };
121 
122 void
124 {
125  Ptr<Packet> p = Create<Packet> (m_input.packetSizeA);
126  WifiTxVector txVector;
127  txVector.SetTxPowerLevel (0); //only one TX power level
128  txVector.SetMode (WifiMode (m_input.txModeA));
129  txVector.SetPreambleType (m_input.preamble);
130  m_txA->SendPacket (p, txVector);
131 }
132 
133 void
135 {
136  Ptr<Packet> p = Create<Packet> (m_input.packetSizeB);
137  WifiTxVector txVector;
138  txVector.SetTxPowerLevel (0); //only one TX power level
139  txVector.SetMode (WifiMode (m_input.txModeB));
140  txVector.SetPreambleType (m_input.preamble);
141  m_txB->SendPacket (p, txVector);
142 }
143 
144 void
146 {
147  if (packet->GetUid () == 0)
148  {
149  m_droppedA = true;
150  }
151  else if (packet->GetUid () == 1)
152  {
153  m_droppedB = true;
154  }
155  else
156  {
157  NS_LOG_ERROR ("Unknown packet!");
158  exit (1);
159  }
160 }
161 
163  : m_droppedA (false),
164  m_droppedB (false)
165 {
166 }
167 
169  : interval (MicroSeconds (0)),
170  xA (-5),
171  xB (5),
172  txModeA ("OfdmRate54Mbps"),
173  txModeB ("OfdmRate54Mbps"),
174  txPowerLevelA (16.0206),
175  txPowerLevelB (16.0206),
176  packetSizeA (1500),
177  packetSizeB (1500),
178  standard (WIFI_PHY_STANDARD_80211a),
179  preamble (WIFI_PREAMBLE_LONG),
180  captureEnabled (false),
181  captureMargin (0)
182 {
183 }
184 
185 void
187 {
188  m_input = input;
189 
190  double range = std::max (std::abs (input.xA), input.xB);
191  Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (range));
192 
193  Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
194  channel->SetPropagationDelayModel (CreateObject<ConstantSpeedPropagationDelayModel> ());
195  Ptr<RangePropagationLossModel> loss = CreateObject<RangePropagationLossModel> ();
196  channel->SetPropagationLossModel (loss);
197 
198  Ptr<MobilityModel> posTxA = CreateObject<ConstantPositionMobilityModel> ();
199  posTxA->SetPosition (Vector (input.xA, 0.0, 0.0));
200  Ptr<MobilityModel> posTxB = CreateObject<ConstantPositionMobilityModel> ();
201  posTxB->SetPosition (Vector (input.xB, 0.0, 0.0));
202  Ptr<MobilityModel> posRx = CreateObject<ConstantPositionMobilityModel> ();
203  posRx->SetPosition (Vector (0.0, 0.0, 0.0));
204 
205  m_txA = CreateObject<YansWifiPhy> ();
208  m_txB = CreateObject<YansWifiPhy> ();
211  Ptr<YansWifiPhy> rx = CreateObject<YansWifiPhy> ();
212 
213  Ptr<ErrorRateModel> error = CreateObject<NistErrorRateModel> ();
214  m_txA->SetErrorRateModel (error);
215  m_txB->SetErrorRateModel (error);
216  rx->SetErrorRateModel (error);
219  rx->SetChannel (channel);
220  m_txA->SetMobility (posTxA);
221  m_txB->SetMobility (posTxB);
222  rx->SetMobility (posRx);
223  if (input.captureEnabled)
224  {
225  Ptr<SimpleFrameCaptureModel> frameCaptureModel = CreateObject<SimpleFrameCaptureModel> ();
226  frameCaptureModel->SetMargin (input.captureMargin);
227  rx->SetFrameCaptureModel (frameCaptureModel);
228  }
229 
232  rx->ConfigureStandard (input.standard);
233 
235 
236  Simulator::Schedule (Seconds (0), &InterferenceExperiment::SendA, this);
237  Simulator::Schedule (Seconds (0) + input.interval, &InterferenceExperiment::SendB, this);
238 
239  Simulator::Run ();
240  Simulator::Destroy ();
241  m_txB->Dispose ();
242  m_txA->Dispose ();
243  rx->Dispose ();
244 
246  {
247  NS_LOG_ERROR ("Results are not expected!");
248  exit (1);
249  }
250 }
251 
252 int main (int argc, char *argv[])
253 {
255  std::string str_standard = "WIFI_PHY_STANDARD_80211a";
256  std::string str_preamble = "WIFI_PREAMBLE_LONG";
257  uint64_t delay = 0; //microseconds
258 
260  cmd.AddValue ("delay", "Delay in microseconds between frame transmission from sender A and frame transmission from sender B", delay);
261  cmd.AddValue ("xA", "The position of transmitter A (< 0)", input.xA);
262  cmd.AddValue ("xB", "The position of transmitter B (> 0)", input.xB);
263  cmd.AddValue ("packetSizeA", "Packet size in bytes of transmitter A", input.packetSizeA);
264  cmd.AddValue ("packetSizeB", "Packet size in bytes of transmitter B", input.packetSizeB);
265  cmd.AddValue ("txPowerA", "TX power level of transmitter A", input.txPowerLevelA);
266  cmd.AddValue ("txPowerB", "TX power level of transmitter B", input.txPowerLevelB);
267  cmd.AddValue ("txModeA", "Wifi mode used for payload transmission of sender A", input.txModeA);
268  cmd.AddValue ("txModeB", "Wifi mode used for payload transmission of sender B", input.txModeB);
269  cmd.AddValue ("standard", "IEEE 802.11 flavor", str_standard);
270  cmd.AddValue ("preamble", "Type of preamble", str_preamble);
271  cmd.AddValue ("enableCapture", "Enable/disable physical layer capture", input.captureEnabled);
272  cmd.AddValue ("captureMargin", "Margin used for physical layer capture", input.captureMargin);
273  cmd.AddValue ("checkResults", "Used to check results at the end of the test", checkResults);
274  cmd.AddValue ("expectRxASuccessfull", "Indicate whether packet A is expected to be successfully received", expectRxASuccessfull);
275  cmd.AddValue ("expectRxBSuccessfull", "Indicate whether packet B is expected to be successfully received", expectRxBSuccessfull);
276  cmd.Parse (argc, argv);
277 
278  input.interval = MicroSeconds (delay);
279 
280  if (input.xA >= 0 || input.xB <= 0)
281  {
282  std::cout << "Value of xA must be smaller than 0 and value of xB must be bigger than 0!" << std::endl;
283  return 0;
284  }
285 
286  if (str_standard == "WIFI_PHY_STANDARD_80211a")
287  {
289  }
290  else if (str_standard == "WIFI_PHY_STANDARD_80211b")
291  {
293  }
294  else if (str_standard == "WIFI_PHY_STANDARD_80211g")
295  {
297  }
298  else if (str_standard == "WIFI_PHY_STANDARD_80211n_2_4GHZ")
299  {
301  }
302  else if (str_standard == "WIFI_PHY_STANDARD_80211n_5GHZ")
303  {
305  }
306  else if (str_standard == "WIFI_PHY_STANDARD_80211ac")
307  {
309  }
310 
311  if (str_preamble == "WIFI_PREAMBLE_LONG" && (input.standard == WIFI_PHY_STANDARD_80211a || input.standard == WIFI_PHY_STANDARD_80211b || input.standard == WIFI_PHY_STANDARD_80211g))
312  {
314  }
315  else if (str_preamble == "WIFI_PREAMBLE_SHORT" && (input.standard == WIFI_PHY_STANDARD_80211b || input.standard == WIFI_PHY_STANDARD_80211g))
316  {
318  }
319  else if (str_preamble == "WIFI_PREAMBLE_HT_MF" && (input.standard == WIFI_PHY_STANDARD_80211n_2_4GHZ || input.standard == WIFI_PHY_STANDARD_80211n_5GHZ))
320  {
322  }
323  else if (str_preamble == "WIFI_PREAMBLE_HT_GF" && (input.standard == WIFI_PHY_STANDARD_80211n_2_4GHZ || input.standard == WIFI_PHY_STANDARD_80211n_5GHZ))
324  {
326  }
327  else if (str_preamble == "WIFI_PREAMBLE_VHT_SU" && input.standard == WIFI_PHY_STANDARD_80211ac)
328  {
330  }
331  else
332  {
333  std::cout << "Preamble does not exist or is not compatible with the selected standard!" << std::endl;
334  return 0;
335  }
336 
338  experiment.Run (input);
339 
340  return 0;
341 }
ERP-OFDM PHY (Clause 19, Section 19.5)
void Dispose(void)
Dispose of this Object.
Definition: object.cc:214
double txPowerLevelB
transmit power level B
uint64_t GetUid(void) const
Returns the packet&#39;s Uid.
Definition: packet.cc:390
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
void SendB(void) const
Send B function.
HT PHY for the 5 GHz band (clause 20)
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetChannel(const Ptr< YansWifiChannel > channel)
Set the YansWifiChannel this YansWifiPhy is to be connected to.
bool captureEnabled
whether physical layer capture is enabled
std::string txModeA
transmit mode A
bool m_droppedB
flag to indicate whether packet B has been dropped
Ptr< YansWifiPhy > m_txA
transmit A function
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
std::string txModeB
transmit mode B
void SetMobility(const Ptr< MobilityModel > mobility)
assign a mobility model to this device
Definition: wifi-phy.cc:743
cmd
Definition: second.py:35
HT PHY for the 2.4 GHz band (clause 20)
bool expectRxBSuccessfull
void SetFrameCaptureModel(const Ptr< FrameCaptureModel > frameCaptureModel)
Sets the frame capture model.
Definition: wifi-phy.cc:776
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
Ptr< YansWifiPhy > m_txB
transmit B function
channel
Definition: third.py:85
bool m_droppedA
flag to indicate whether packet A has been dropped
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
Definition: wifi-preamble.h:30
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
double captureMargin
margin used for physical layer capture
#define max(a, b)
Definition: 80211b.c:43
void PacketDropped(Ptr< const Packet > packet, WifiPhyRxfailureReason reason)
Function triggered when a packet is dropped.
void SetTxPowerEnd(double end)
Sets the maximum available transmission power level (dBm).
Definition: wifi-phy.cc:560
double txPowerLevelA
transmit power level A
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
Parse command-line arguments.
Definition: command-line.h:213
void SetErrorRateModel(const Ptr< ErrorRateModel > rate)
Sets the error rate model.
Definition: wifi-phy.cc:762
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:293
OFDM PHY for the 5 GHz band (Clause 17)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
InterferenceExperiment.
void Run(struct InterferenceExperiment::Input input)
Run function.
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
bool expectRxASuccessfull
void SetPosition(const Vector &position)
bool checkResults
void experiment(std::string queue_disc_type)
void SetTxPowerStart(double start)
Sets the minimum available transmission power level (dBm).
Definition: wifi-phy.cc:547
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
WifiPhyRxfailureReason
Definition: wifi-phy.h:48
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:810
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1078
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:256
void SetMargin(double margin)
Sets the frame capture margin (dB).
virtual void ConfigureStandard(WifiPhyStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:1217
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
void SendA(void) const
Send A function.