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:
109  void PacketDropped (Ptr<const Packet> packet);
111  void SendA (void) const;
113  void SendB (void) const;
116  struct Input m_input;
117  bool m_droppedA;
118  bool m_droppedB;
119 };
120 
121 void
123 {
124  Ptr<Packet> p = Create<Packet> (m_input.packetSizeA);
125  WifiTxVector txVector;
126  txVector.SetTxPowerLevel (0); //only one TX power level
127  txVector.SetMode (WifiMode (m_input.txModeA));
128  txVector.SetPreambleType (m_input.preamble);
129  m_txA->SendPacket (p, txVector);
130 }
131 
132 void
134 {
135  Ptr<Packet> p = Create<Packet> (m_input.packetSizeB);
136  WifiTxVector txVector;
137  txVector.SetTxPowerLevel (0); //only one TX power level
138  txVector.SetMode (WifiMode (m_input.txModeB));
139  txVector.SetPreambleType (m_input.preamble);
140  m_txB->SendPacket (p, txVector);
141 }
142 
143 void
145 {
146  if (packet->GetUid () == 0)
147  {
148  m_droppedA = true;
149  }
150  else if (packet->GetUid () == 1)
151  {
152  m_droppedB = true;
153  }
154  else
155  {
156  NS_LOG_ERROR ("Unknown packet!");
157  exit (1);
158  }
159 }
160 
162  : m_droppedA (false),
163  m_droppedB (false)
164 {
165 }
166 
168  : interval (MicroSeconds (0)),
169  xA (-5),
170  xB (5),
171  txModeA ("OfdmRate54Mbps"),
172  txModeB ("OfdmRate54Mbps"),
173  txPowerLevelA (16.0206),
174  txPowerLevelB (16.0206),
175  packetSizeA (1500),
176  packetSizeB (1500),
177  standard (WIFI_PHY_STANDARD_80211a),
178  preamble (WIFI_PREAMBLE_LONG),
179  captureEnabled (false),
180  captureMargin (0)
181 {
182 }
183 
184 void
186 {
187  m_input = input;
188 
189  double range = std::max (std::abs (input.xA), input.xB);
190  Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (range));
191 
192  Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
193  channel->SetPropagationDelayModel (CreateObject<ConstantSpeedPropagationDelayModel> ());
194  Ptr<RangePropagationLossModel> loss = CreateObject<RangePropagationLossModel> ();
195  channel->SetPropagationLossModel (loss);
196 
197  Ptr<MobilityModel> posTxA = CreateObject<ConstantPositionMobilityModel> ();
198  posTxA->SetPosition (Vector (input.xA, 0.0, 0.0));
199  Ptr<MobilityModel> posTxB = CreateObject<ConstantPositionMobilityModel> ();
200  posTxB->SetPosition (Vector (input.xB, 0.0, 0.0));
201  Ptr<MobilityModel> posRx = CreateObject<ConstantPositionMobilityModel> ();
202  posRx->SetPosition (Vector (0.0, 0.0, 0.0));
203 
204  m_txA = CreateObject<YansWifiPhy> ();
207  m_txB = CreateObject<YansWifiPhy> ();
210  Ptr<YansWifiPhy> rx = CreateObject<YansWifiPhy> ();
211 
212  Ptr<ErrorRateModel> error = CreateObject<NistErrorRateModel> ();
213  m_txA->SetErrorRateModel (error);
214  m_txB->SetErrorRateModel (error);
215  rx->SetErrorRateModel (error);
218  rx->SetChannel (channel);
219  m_txA->SetMobility (posTxA);
220  m_txB->SetMobility (posTxB);
221  rx->SetMobility (posRx);
222  if (input.captureEnabled)
223  {
224  Ptr<SimpleFrameCaptureModel> frameCaptureModel = CreateObject<SimpleFrameCaptureModel> ();
225  frameCaptureModel->SetMargin (input.captureMargin);
226  rx->SetFrameCaptureModel (frameCaptureModel);
227  }
228 
231  rx->ConfigureStandard (input.standard);
232 
234 
235  Simulator::Schedule (Seconds (0), &InterferenceExperiment::SendA, this);
236  Simulator::Schedule (Seconds (0) + input.interval, &InterferenceExperiment::SendB, this);
237 
238  Simulator::Run ();
239  Simulator::Destroy ();
240  m_txB->Dispose ();
241  m_txA->Dispose ();
242  rx->Dispose ();
243 
245  {
246  NS_LOG_ERROR ("Results are not expected!");
247  exit (1);
248  }
249 }
250 
251 int main (int argc, char *argv[])
252 {
254  std::string str_standard = "WIFI_PHY_STANDARD_80211a";
255  std::string str_preamble = "WIFI_PREAMBLE_LONG";
256  uint64_t delay = 0; //microseconds
257 
259  cmd.AddValue ("delay", "Delay in microseconds between frame transmission from sender A and frame transmission from sender B", delay);
260  cmd.AddValue ("xA", "The position of transmitter A (< 0)", input.xA);
261  cmd.AddValue ("xB", "The position of transmitter B (> 0)", input.xB);
262  cmd.AddValue ("packetSizeA", "Packet size in bytes of transmitter A", input.packetSizeA);
263  cmd.AddValue ("packetSizeB", "Packet size in bytes of transmitter B", input.packetSizeB);
264  cmd.AddValue ("txPowerA", "TX power level of transmitter A", input.txPowerLevelA);
265  cmd.AddValue ("txPowerB", "TX power level of transmitter B", input.txPowerLevelB);
266  cmd.AddValue ("txModeA", "Wifi mode used for payload transmission of sender A", input.txModeA);
267  cmd.AddValue ("txModeB", "Wifi mode used for payload transmission of sender B", input.txModeB);
268  cmd.AddValue ("standard", "IEEE 802.11 flavor", str_standard);
269  cmd.AddValue ("preamble", "Type of preamble", str_preamble);
270  cmd.AddValue ("enableCapture", "Enable/disable physical layer capture", input.captureEnabled);
271  cmd.AddValue ("captureMargin", "Margin used for physical layer capture", input.captureMargin);
272  cmd.AddValue ("checkResults", "Used to check results at the end of the test", checkResults);
273  cmd.AddValue ("expectRxASuccessfull", "Indicate whether packet A is expected to be successfully received", expectRxASuccessfull);
274  cmd.AddValue ("expectRxBSuccessfull", "Indicate whether packet B is expected to be successfully received", expectRxBSuccessfull);
275  cmd.Parse (argc, argv);
276 
277  input.interval = MicroSeconds (delay);
278 
279  if (input.xA >= 0 || input.xB <= 0)
280  {
281  std::cout << "Value of xA must be smaller than 0 and value of xB must be bigger than 0!" << std::endl;
282  return 0;
283  }
284 
285  if (str_standard == "WIFI_PHY_STANDARD_80211a")
286  {
288  }
289  else if (str_standard == "WIFI_PHY_STANDARD_80211b")
290  {
292  }
293  else if (str_standard == "WIFI_PHY_STANDARD_80211g")
294  {
296  }
297  else if (str_standard == "WIFI_PHY_STANDARD_80211n_2_4GHZ")
298  {
300  }
301  else if (str_standard == "WIFI_PHY_STANDARD_80211n_5GHZ")
302  {
304  }
305  else if (str_standard == "WIFI_PHY_STANDARD_80211ac")
306  {
308  }
309 
310  if (str_preamble == "WIFI_PREAMBLE_LONG" && (input.standard == WIFI_PHY_STANDARD_80211a || input.standard == WIFI_PHY_STANDARD_80211b || input.standard == WIFI_PHY_STANDARD_80211g))
311  {
313  }
314  else if (str_preamble == "WIFI_PREAMBLE_SHORT" && (input.standard == WIFI_PHY_STANDARD_80211b || input.standard == WIFI_PHY_STANDARD_80211g))
315  {
317  }
318  else if (str_preamble == "WIFI_PREAMBLE_HT_MF" && (input.standard == WIFI_PHY_STANDARD_80211n_2_4GHZ || input.standard == WIFI_PHY_STANDARD_80211n_5GHZ))
319  {
321  }
322  else if (str_preamble == "WIFI_PREAMBLE_HT_GF" && (input.standard == WIFI_PHY_STANDARD_80211n_2_4GHZ || input.standard == WIFI_PHY_STANDARD_80211n_5GHZ))
323  {
325  }
326  else if (str_preamble == "WIFI_PREAMBLE_VHT" && input.standard == WIFI_PHY_STANDARD_80211ac)
327  {
328  input.preamble = WIFI_PREAMBLE_VHT;
329  }
330  else
331  {
332  std::cout << "Preamble does not exist or is not compatible with the selected standard!" << std::endl;
333  return 0;
334  }
335 
337  experiment.Run (input);
338 
339  return 0;
340 }
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:202
std::string txModeB
transmit mode B
void SetMobility(const Ptr< MobilityModel > mobility)
assign a mobility model to this device
Definition: wifi-phy.cc:662
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:688
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 SetTxPowerEnd(double end)
Sets the maximum available transmission power level (dBm).
Definition: wifi-phy.cc:519
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:681
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 SetTxPowerStart(double start)
Sets the minimum available transmission power level (dBm).
Definition: wifi-phy.cc:506
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:782
void PacketDropped(Ptr< const Packet > packet)
Function triggered when a packet is dropped.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1030
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
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:1119
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.
void experiment(bool enableCtsRts, std::string wifiManager)
Run single 10 seconds experiment.