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/core-module.h"
53 #include "ns3/yans-wifi-channel.h"
54 #include "ns3/propagation-loss-model.h"
55 #include "ns3/propagation-delay-model.h"
56 #include "ns3/nist-error-rate-model.h"
57 #include "ns3/constant-position-mobility-model.h"
58 #include "ns3/simple-frame-capture-model.h"
59 #include "ns3/log.h"
60 
61 using namespace ns3;
62 
63 NS_LOG_COMPONENT_DEFINE ("test-interference-helper");
64 
65 bool checkResults = false;
66 bool expectRxASuccessfull = false;
67 bool expectRxBSuccessfull = false;
68 
71 {
72 public:
74  struct Input
75  {
76  Input ();
78  double xA;
79  double xB;
80  std::string txModeA;
81  std::string txModeB;
82  double txPowerLevelA;
83  double txPowerLevelB;
84  uint32_t packetSizeA;
85  uint32_t packetSizeB;
89  double captureMargin;
90  };
91 
97  void Run (struct InterferenceExperiment::Input input);
98 
99 private:
104  void PacketDropped(Ptr<const Packet> packet);
106  void SendA (void) const;
108  void SendB (void) const;
111  struct Input m_input;
112  bool m_droppedA;
113  bool m_droppedB;
114 };
115 
116 void
118 {
119  Ptr<Packet> p = Create<Packet> (m_input.packetSizeA);
120  WifiTxVector txVector;
121  txVector.SetTxPowerLevel (m_input.txPowerLevelA);
122  txVector.SetMode (WifiMode (m_input.txModeA));
123  txVector.SetPreambleType (m_input.preamble);
124  m_txA->SendPacket (p, txVector);
125 }
126 
127 void
129 {
130  Ptr<Packet> p = Create<Packet> (m_input.packetSizeB);
131  WifiTxVector txVector;
132  txVector.SetTxPowerLevel (m_input.txPowerLevelB);
133  txVector.SetMode (WifiMode (m_input.txModeB));
134  txVector.SetPreambleType (m_input.preamble);
135  m_txB->SendPacket (p, txVector);
136 }
137 
138 void
140 {
141  if (packet->GetUid () == 0)
142  {
143  m_droppedA = true;
144  }
145  else if (packet->GetUid () == 1)
146  {
147  m_droppedB = true;
148  }
149  else
150  {
151  NS_LOG_ERROR ("Unknown packet!");
152  exit (1);
153  }
154 }
155 
157  : m_droppedA (false),
158  m_droppedB (false)
159 {
160 }
161 
163  : interval (MicroSeconds (0)),
164  xA (-5),
165  xB (5),
166  txModeA ("OfdmRate54Mbps"),
167  txModeB ("OfdmRate54Mbps"),
168  txPowerLevelA (16.0206),
169  txPowerLevelB (16.0206),
170  packetSizeA (1500),
171  packetSizeB (1500),
172  standard (WIFI_PHY_STANDARD_80211a),
173  preamble (WIFI_PREAMBLE_LONG),
174  captureEnabled (false),
175  captureMargin (0)
176 {
177 }
178 
179 void
181 {
182  m_input = input;
183 
184  double range = std::max (std::abs (input.xA), input.xB);
185  Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (range));
186 
187  Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
188  channel->SetPropagationDelayModel (CreateObject<ConstantSpeedPropagationDelayModel> ());
189  Ptr<RangePropagationLossModel> loss = CreateObject<RangePropagationLossModel> ();
190  channel->SetPropagationLossModel (loss);
191 
192  Ptr<MobilityModel> posTxA = CreateObject<ConstantPositionMobilityModel> ();
193  posTxA->SetPosition (Vector (input.xA, 0.0, 0.0));
194  Ptr<MobilityModel> posTxB = CreateObject<ConstantPositionMobilityModel> ();
195  posTxB->SetPosition (Vector (input.xB, 0.0, 0.0));
196  Ptr<MobilityModel> posRx = CreateObject<ConstantPositionMobilityModel> ();
197  posRx->SetPosition (Vector (0.0, 0.0, 0.0));
198 
199  m_txA = CreateObject<YansWifiPhy> ();
202  m_txB = CreateObject<YansWifiPhy> ();
205  Ptr<YansWifiPhy> rx = CreateObject<YansWifiPhy> ();
206 
207  Ptr<ErrorRateModel> error = CreateObject<NistErrorRateModel> ();
208  m_txA->SetErrorRateModel (error);
209  m_txB->SetErrorRateModel (error);
210  rx->SetErrorRateModel (error);
211  m_txA->SetChannel (channel);
212  m_txB->SetChannel (channel);
213  rx->SetChannel (channel);
214  m_txA->SetMobility (posTxA);
215  m_txB->SetMobility (posTxB);
216  rx->SetMobility (posRx);
217  if (input.captureEnabled)
218  {
219  Ptr<SimpleFrameCaptureModel> frameCaptureModel = CreateObject<SimpleFrameCaptureModel> ();
220  frameCaptureModel->SetMargin (input.captureMargin);
221  rx->SetFrameCaptureModel (frameCaptureModel);
222  }
223 
226  rx->ConfigureStandard (input.standard);
227 
229 
230  Simulator::Schedule (Seconds (0), &InterferenceExperiment::SendA, this);
231  Simulator::Schedule (Seconds (0) + input.interval, &InterferenceExperiment::SendB, this);
232 
233  Simulator::Run ();
234  Simulator::Destroy ();
235  m_txB->Dispose ();
236  m_txA->Dispose ();
237  rx->Dispose ();
238 
240  {
241  NS_LOG_ERROR ("Results are not expected!");
242  exit (1);
243  }
244 }
245 
246 int main (int argc, char *argv[])
247 {
249  std::string str_standard = "WIFI_PHY_STANDARD_80211a";
250  std::string str_preamble = "WIFI_PREAMBLE_LONG";
251  double delay = 0; //microseconds
252 
254  cmd.AddValue ("delay", "Delay in microseconds between frame transmission from sender A and frame transmission from sender B", delay);
255  cmd.AddValue ("xA", "The position of transmitter A (< 0)", input.xA);
256  cmd.AddValue ("xB", "The position of transmitter B (> 0)", input.xB);
257  cmd.AddValue ("packetSizeA", "Packet size in bytes of transmitter A", input.packetSizeA);
258  cmd.AddValue ("packetSizeB", "Packet size in bytes of transmitter B", input.packetSizeB);
259  cmd.AddValue ("txPowerA", "TX power level of transmitter A", input.txPowerLevelA);
260  cmd.AddValue ("txPowerB", "TX power level of transmitter B", input.txPowerLevelB);
261  cmd.AddValue ("txModeA", "Wifi mode used for payload transmission of sender A", input.txModeA);
262  cmd.AddValue ("txModeB", "Wifi mode used for payload transmission of sender B", input.txModeB);
263  cmd.AddValue ("standard", "IEEE 802.11 flavor", str_standard);
264  cmd.AddValue ("preamble", "Type of preamble", str_preamble);
265  cmd.AddValue ("enableCapture", "Enable/disable physical layer capture", input.captureEnabled);
266  cmd.AddValue ("captureMargin", "Margin used for physical layer capture", input.captureMargin);
267  cmd.AddValue ("checkResults", "Used to check results at the end of the test", checkResults);
268  cmd.AddValue ("expectRxASuccessfull", "Indicate whether packet A is expected to be successfully received", expectRxASuccessfull);
269  cmd.AddValue ("expectRxBSuccessfull", "Indicate whether packet B is expected to be successfully received", expectRxBSuccessfull);
270  cmd.Parse (argc, argv);
271 
272  LogComponentEnable ("WifiPhy", LOG_LEVEL_ALL);
273  LogComponentEnable ("YansWifiPhy", LOG_LEVEL_ALL);
274  LogComponentEnable ("InterferenceHelper", LOG_LEVEL_ALL);
275  LogComponentEnable ("SimpleFrameCaptureModel", LOG_LEVEL_ALL);
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
tuple channel
Definition: third.py:85
double txPowerLevelB
transmit power level B
void experiment(bool enableCtsRts)
Run single 10 seconds experiment with enabled or disabled RTS/CTS mechanism.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
void SetPropagationLossModel(const Ptr< PropagationLossModel > loss)
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
uint64_t GetUid(void) const
Returns the packet's Uid.
Definition: packet.cc:367
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:201
std::string txModeB
transmit mode B
void SetMobility(const Ptr< MobilityModel > mobility)
assign a mobility model to this device
Definition: wifi-phy.cc:682
HT PHY for the 2.4 GHz band (clause 20)
bool expectRxBSuccessfull
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
tuple cmd
Definition: second.py:35
Ptr< YansWifiPhy > m_txB
transmit B function
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
void SetPropagationDelayModel(const Ptr< PropagationDelayModel > delay)
void SetFrameCaptureModel(const Ptr< FrameCaptureModel > rate)
Sets the frame capture model.
Definition: wifi-phy.cc:714
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:369
#define max(a, b)
Definition: 80211b.c:45
void SetTxPowerEnd(double end)
Sets the maximum available transmission power level (dBm).
Definition: wifi-phy.cc:539
double txPowerLevelA
transmit power level A
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
void SendA(void) const
Send A function.
Parse command-line arguments.
Definition: command-line.h:205
void SetErrorRateModel(const Ptr< ErrorRateModel > rate)
Sets the error rate model.
Definition: wifi-phy.cc:701
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 SendB(void) const
Send B function.
void SetTxPowerStart(double start)
Sets the minimum available transmission power level (dBm).
Definition: wifi-phy.cc:526
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:498
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:993
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.
Print everything.
Definition: log.h:112
void Parse(int argc, char *argv[])
Parse the program arguments.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1009
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:253
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:1147
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41