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/wifi-net-device.h"
54 #include "ns3/yans-wifi-channel.h"
55 #include "ns3/yans-wifi-phy.h"
56 #include "ns3/propagation-loss-model.h"
57 #include "ns3/propagation-delay-model.h"
58 #include "ns3/error-rate-model.h"
59 #include "ns3/yans-error-rate-model.h"
60 #include "ns3/ptr.h"
61 #include "ns3/mobility-model.h"
62 #include "ns3/constant-position-mobility-model.h"
63 #include "ns3/vector.h"
64 #include "ns3/packet.h"
65 #include "ns3/simulator.h"
66 #include "ns3/nstime.h"
67 #include "ns3/command-line.h"
68 #include "ns3/wifi-tx-vector.h"
69 
70 using namespace ns3;
71 
73 {
74 public:
75  struct Input
76  {
77  Input ();
79  double xA;
80  double xB;
81  std::string txModeA;
82  std::string txModeB;
83  uint32_t txPowerLevelA;
84  uint32_t txPowerLevelB;
85  uint32_t packetSizeA;
86  uint32_t packetSizeB;
87  enum WifiPhyStandard standard;
88  enum WifiPreamble preamble;
89  };
90 
92  void Run (struct InterferenceExperiment::Input input);
93 
94 private:
95  void SendA (void) const;
96  void SendB (void) const;
99  struct Input m_input;
100 };
101 
102 void
104 {
105  Ptr<Packet> p = Create<Packet> (m_input.packetSizeA);
106  WifiTxVector txVector;
107  txVector.SetTxPowerLevel (m_input.txPowerLevelA);
108  txVector.SetMode (WifiMode (m_input.txModeA));
109  m_txA->SendPacket (p, txVector, m_input.preamble);
110 }
111 
112 void
114 {
115  Ptr<Packet> p = Create<Packet> (m_input.packetSizeB);
116  WifiTxVector txVector;
117  txVector.SetTxPowerLevel (m_input.txPowerLevelB);
118  txVector.SetMode (WifiMode (m_input.txModeB));
119  m_txB->SendPacket (p, txVector, m_input.preamble);
120 }
121 
123 {
124 }
126  : interval (MicroSeconds (0)),
127  xA (-5),
128  xB (5),
129  txModeA ("OfdmRate54Mbps"),
130  txModeB ("OfdmRate54Mbps"),
131  txPowerLevelA (0),
132  txPowerLevelB (0),
133  packetSizeA (1500),
134  packetSizeB (1500),
135  standard (WIFI_PHY_STANDARD_80211a),
136  preamble (WIFI_PREAMBLE_LONG)
137 {
138 }
139 
140 void
142 {
143  m_input = input;
144 
145  double range = std::max (std::abs (input.xA), input.xB);
146  Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (range));
147 
148  Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
149  channel->SetPropagationDelayModel (CreateObject<ConstantSpeedPropagationDelayModel> ());
150  Ptr<RangePropagationLossModel> loss = CreateObject<RangePropagationLossModel> ();
151  channel->SetPropagationLossModel (loss);
152 
153  Ptr<MobilityModel> posTxA = CreateObject<ConstantPositionMobilityModel> ();
154  posTxA->SetPosition (Vector (input.xA, 0.0, 0.0));
155  Ptr<MobilityModel> posTxB = CreateObject<ConstantPositionMobilityModel> ();
156  posTxB->SetPosition (Vector (input.xB, 0.0, 0.0));
157  Ptr<MobilityModel> posRx = CreateObject<ConstantPositionMobilityModel> ();
158  posRx->SetPosition (Vector (0.0, 0.0, 0.0));
159 
160  m_txA = CreateObject<YansWifiPhy> ();
161  m_txB = CreateObject<YansWifiPhy> ();
162  Ptr<YansWifiPhy> rx = CreateObject<YansWifiPhy> ();
163 
164  Ptr<ErrorRateModel> error = CreateObject<YansErrorRateModel> ();
165  m_txA->SetErrorRateModel (error);
166  m_txB->SetErrorRateModel (error);
167  rx->SetErrorRateModel (error);
168  m_txA->SetChannel (channel);
169  m_txB->SetChannel (channel);
170  rx->SetChannel (channel);
171  m_txA->SetMobility (posTxA);
172  m_txB->SetMobility (posTxB);
173  rx->SetMobility (posRx);
174 
176  m_txB->ConfigureStandard (input.standard);
177  rx->ConfigureStandard (input.standard);
178 
179  Simulator::Schedule (Seconds (0), &InterferenceExperiment::SendA, this);
180  Simulator::Schedule (Seconds (0) + input.interval, &InterferenceExperiment::SendB, this);
181 
182  Simulator::Run ();
183  Simulator::Destroy ();
184 }
185 
186 
187 int main (int argc, char *argv[])
188 {
190  std::string str_standard = "WIFI_PHY_STANDARD_80211a";
191  std::string str_preamble = "WIFI_PREAMBLE_LONG";
192  double delay = 0; //microseconds
193 
195  cmd.AddValue ("delay", "Delay in microseconds between frame transmission from sender A and frame transmission from sender B", delay);
196  cmd.AddValue ("xA", "The position of transmitter A (< 0)", input.xA);
197  cmd.AddValue ("xB", "The position of transmitter B (> 0)", input.xB);
198  cmd.AddValue ("packetSizeA", "Packet size in bytes of transmitter A", input.packetSizeA);
199  cmd.AddValue ("packetSizeB", "Packet size in bytes of transmitter B", input.packetSizeB);
200  cmd.AddValue ("txPowerA", "TX power level of transmitter A", input.txPowerLevelA);
201  cmd.AddValue ("txPowerB", "TX power level of transmitter B", input.txPowerLevelB);
202  cmd.AddValue ("txModeA", "Wifi mode used for payload transmission of sender A", input.txModeA);
203  cmd.AddValue ("txModeB", "Wifi mode used for payload transmission of sender B", input.txModeB);
204  cmd.AddValue ("standard", "IEEE 802.11 flavor", str_standard);
205  cmd.AddValue ("preamble", "Type of preamble", str_preamble);
206  cmd.Parse (argc, argv);
207 
208  LogComponentEnable ("YansWifiPhy", LOG_LEVEL_ALL);
209  LogComponentEnable ("InterferenceHelper", LOG_LEVEL_ALL);
210 
211  input.interval = MicroSeconds (delay);
212 
213  if (input.xA >= 0 || input.xB <= 0)
214  {
215  std::cout << "Value of xA must be smaller than 0 and value of xB must be bigger than 0!" << std::endl;
216  return 0;
217  }
218 
219  if (str_standard == "WIFI_PHY_STANDARD_80211a")
220  {
222  }
223  else if (str_standard == "WIFI_PHY_STANDARD_80211b")
224  {
226  }
227  else if (str_standard == "WIFI_PHY_STANDARD_80211g")
228  {
230  }
231  else if (str_standard == "WIFI_PHY_STANDARD_80211n_2_4GHZ")
232  {
234  }
235  else if (str_standard == "WIFI_PHY_STANDARD_80211n_5GHZ")
236  {
238  }
239  else if (str_standard == "WIFI_PHY_STANDARD_80211ac")
240  {
242  }
243 
244  if (str_preamble == "WIFI_PREAMBLE_LONG" && (input.standard == WIFI_PHY_STANDARD_80211a || input.standard == WIFI_PHY_STANDARD_80211b || input.standard == WIFI_PHY_STANDARD_80211g))
245  {
247  }
248  else if (str_preamble == "WIFI_PREAMBLE_SHORT" && (input.standard == WIFI_PHY_STANDARD_80211b || input.standard == WIFI_PHY_STANDARD_80211g))
249  {
251  }
252  else if (str_preamble == "WIFI_PREAMBLE_HT_MF" && (input.standard == WIFI_PHY_STANDARD_80211n_2_4GHZ || input.standard == WIFI_PHY_STANDARD_80211n_5GHZ))
253  {
255  }
256  else if (str_preamble == "WIFI_PREAMBLE_HT_GF" && (input.standard == WIFI_PHY_STANDARD_80211n_2_4GHZ || input.standard == WIFI_PHY_STANDARD_80211n_5GHZ))
257  {
259  }
260  else if (str_preamble == "WIFI_PREAMBLE_VHT" && input.standard == WIFI_PHY_STANDARD_80211ac)
261  {
262  input.preamble = WIFI_PREAMBLE_VHT;
263  }
264  else
265  {
266  std::cout << "Preamble does not exist or is not compatible with the selected standard!" << std::endl;
267  return 0;
268  }
269 
271  experiment.Run (input);
272 
273  return 0;
274 }
ERP-OFDM PHY (Clause 19, Section 19.5)
tuple channel
Definition: third.py:85
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
HT OFDM 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 SetPropagationLossModel(Ptr< PropagationLossModel > loss)
void SetPropagationDelayModel(Ptr< PropagationDelayModel > delay)
HT OFDM PHY for the 2.4 GHz band (clause 20)
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:99
tuple cmd
Definition: second.py:35
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.
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:351
#define max(a, b)
Definition: 80211b.c:45
Parse command-line arguments.
Definition: command-line.h:205
void SetChannel(Ptr< YansWifiChannel > channel)
Set the YansWifiChannel this YansWifiPhy is to be connected to.
OFDM PHY for the 5 GHz band (Clause 17)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
VHT OFDM PHY (clause 22)
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
void Run(struct InterferenceExperiment::Input input)
void SetMobility(Ptr< MobilityModel > mobility)
assign a mobility model to this device
Definition: wifi-phy.cc:610
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
void SetPosition(const Vector &position)
virtual void ConfigureStandard(enum WifiPhyStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:1026
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:495
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:774
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:911
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
void SetErrorRateModel(Ptr< ErrorRateModel > rate)
Sets the error rate model.
Definition: wifi-phy.cc:629