A Discrete-Event Network Simulator
API
wifi-phy-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include "ns3/packet.h"
22 #include "ns3/constant-position-mobility-model.h"
23 #include "ns3/simulator.h"
24 #include "ns3/command-line.h"
25 #include "ns3/flow-id-tag.h"
26 #include "ns3/yans-wifi-channel.h"
27 #include "ns3/yans-wifi-phy.h"
28 #include "ns3/propagation-loss-model.h"
29 #include "ns3/propagation-delay-model.h"
30 #include "ns3/nist-error-rate-model.h"
31 #include "ns3/wifi-psdu.h"
32 
33 using namespace ns3;
34 
37 {
38 public:
40  struct Input
41  {
42  Input ();
43  double distance;
44  std::string txMode;
45  uint8_t txPowerLevel;
46  uint32_t packetSize;
47  uint32_t nPackets;
48  };
50  struct Output
51  {
52  uint32_t received;
53  };
54  PsrExperiment ();
55 
61  struct PsrExperiment::Output Run (struct PsrExperiment::Input input);
62 
63 private:
65  void Send (void);
73  void Receive (Ptr<WifiPsdu> psdu, RxSignalInfo rxSignalInfo,
74  WifiTxVector txVector, std::vector<bool> statusPerMpdu);
75  Ptr<WifiPhy> m_tx;
76  struct Input m_input;
77  struct Output m_output;
78 };
79 
80 void
82 {
83  Ptr<WifiPsdu> psdu = Create<WifiPsdu> (Create<Packet> (m_input.packetSize), WifiMacHeader ());
84  WifiMode mode = WifiMode (m_input.txMode);
85  WifiTxVector txVector;
86  txVector.SetTxPowerLevel (m_input.txPowerLevel);
87  txVector.SetMode (mode);
89  m_tx->Send (psdu, txVector);
90 }
91 
92 void
94  WifiTxVector txVector, std::vector<bool> statusPerMpdu)
95 {
96  m_output.received++;
97 }
98 
100 {
101 }
103  : distance (5.0),
104  txMode ("OfdmRate6Mbps"),
105  txPowerLevel (0),
106  packetSize (2304),
107  nPackets (400)
108 {
109 }
110 
112 PsrExperiment::Run (struct PsrExperiment::Input input)
113 {
114  m_output.received = 0;
115  m_input = input;
116 
117  Ptr<MobilityModel> posTx = CreateObject<ConstantPositionMobilityModel> ();
118  posTx->SetPosition (Vector (0.0, 0.0, 0.0));
119  Ptr<MobilityModel> posRx = CreateObject<ConstantPositionMobilityModel> ();
120  posRx->SetPosition (Vector (m_input.distance, 0.0, 0.0));
121 
122  Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
123  channel->SetPropagationDelayModel (CreateObject<ConstantSpeedPropagationDelayModel> ());
124  Ptr<LogDistancePropagationLossModel> log = CreateObject<LogDistancePropagationLossModel> ();
125  channel->SetPropagationLossModel (log);
126 
127  Ptr<YansWifiPhy> tx = CreateObject<YansWifiPhy> ();
128  Ptr<YansWifiPhy> rx = CreateObject<YansWifiPhy> ();
129  Ptr<ErrorRateModel> error = CreateObject<NistErrorRateModel> ();
130  tx->SetErrorRateModel (error);
131  rx->SetErrorRateModel (error);
132  tx->SetChannel (channel);
133  rx->SetChannel (channel);
134  tx->SetMobility (posTx);
135  rx->SetMobility (posRx);
136 
138  rx->ConfigureStandardAndBand (WIFI_PHY_STANDARD_80211a, WIFI_PHY_BAND_5GHZ);
139 
140  rx->SetReceiveOkCallback (MakeCallback (&PsrExperiment::Receive, this));
141 
142  for (uint32_t i = 0; i < m_input.nPackets; ++i)
143  {
144  Simulator::Schedule (Seconds (i), &PsrExperiment::Send, this);
145  }
146  m_tx = tx;
147  Simulator::Run ();
148  Simulator::Destroy ();
149  return m_output;
150 }
151 
154 {
155 public:
157  struct Input
158  {
159  Input ();
161  double xA;
162  double xB;
163  std::string txModeA;
164  std::string txModeB;
165  uint8_t txPowerLevelA;
166  uint8_t txPowerLevelB;
167  uint32_t packetSizeA;
168  uint32_t packetSizeB;
169  uint32_t nPackets;
170  };
172  struct Output
173  {
174  uint32_t receivedA;
175  uint32_t receivedB;
176  };
178 
185 private:
187  void SendA (void) const;
189  void SendB (void) const;
197  void Receive (Ptr<WifiPsdu> psdu, RxSignalInfo rxSignalInfo,
198  WifiTxVector txVector, std::vector<bool> statusPerMpdu);
199  Ptr<WifiPhy> m_txA;
200  Ptr<WifiPhy> m_txB;
201  uint32_t m_flowIdA;
202  uint32_t m_flowIdB;
203  struct Input m_input;
204  struct Output m_output;
205 };
206 
207 void
209 {
210  Ptr<WifiPsdu> psdu = Create<WifiPsdu> (Create<Packet> (m_input.packetSizeA), WifiMacHeader ());
211  (*psdu->begin ())->GetPacket ()->AddByteTag (FlowIdTag (m_flowIdA));
212  WifiTxVector txVector;
213  txVector.SetTxPowerLevel (m_input.txPowerLevelA);
214  txVector.SetMode (WifiMode (m_input.txModeA));
216  m_txA->Send (psdu, txVector);
217 }
218 
219 void
221 {
222  Ptr<WifiPsdu> psdu = Create<WifiPsdu> (Create<Packet> (m_input.packetSizeB), WifiMacHeader ());
223  (*psdu->begin ())->GetPacket ()->AddByteTag (FlowIdTag (m_flowIdB));
224  WifiTxVector txVector;
225  txVector.SetTxPowerLevel (m_input.txPowerLevelB);
226  txVector.SetMode (WifiMode (m_input.txModeB));
228  m_txB->Send (psdu, txVector);
229 }
230 
231 void
233  WifiTxVector txVector, std::vector<bool> statusPerMpdu)
234 {
235  FlowIdTag tag;
236  if ((*psdu->begin ())->GetPacket ()->FindFirstMatchingByteTag (tag))
237  {
238  if (tag.GetFlowId () == m_flowIdA)
239  {
240  m_output.receivedA++;
241  }
242  else if (tag.GetFlowId () == m_flowIdB)
243  {
244  m_output.receivedB++;
245  }
246  }
247 }
248 
250 {
251 }
253  : interval (MicroSeconds (0)),
254  xA (-5),
255  xB (5),
256  txModeA ("OfdmRate6Mbps"),
257  txModeB ("OfdmRate6Mbps"),
258  txPowerLevelA (0),
259  txPowerLevelB (0),
260  packetSizeA (2304),
261  packetSizeB (2304),
262  nPackets (400)
263 {
264 }
265 
267 CollisionExperiment::Run (struct CollisionExperiment::Input input)
268 {
269  m_output.receivedA = 0;
270  m_output.receivedB = 0;
271  m_input = input;
272 
273  m_flowIdA = FlowIdTag::AllocateFlowId ();
274  m_flowIdB = FlowIdTag::AllocateFlowId ();
275 
276  Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
277  channel->SetPropagationDelayModel (CreateObject<ConstantSpeedPropagationDelayModel> ());
278  Ptr<LogDistancePropagationLossModel> log = CreateObject<LogDistancePropagationLossModel> ();
279  channel->SetPropagationLossModel (log);
280 
281  Ptr<MobilityModel> posTxA = CreateObject<ConstantPositionMobilityModel> ();
282  posTxA->SetPosition (Vector (input.xA, 0.0, 0.0));
283  Ptr<MobilityModel> posTxB = CreateObject<ConstantPositionMobilityModel> ();
284  posTxB->SetPosition (Vector (input.xB, 0.0, 0.0));
285  Ptr<MobilityModel> posRx = CreateObject<ConstantPositionMobilityModel> ();
286  posRx->SetPosition (Vector (0, 0.0, 0.0));
287 
288  Ptr<YansWifiPhy> txA = CreateObject<YansWifiPhy> ();
289  Ptr<YansWifiPhy> txB = CreateObject<YansWifiPhy> ();
290  Ptr<YansWifiPhy> rx = CreateObject<YansWifiPhy> ();
291 
292  Ptr<ErrorRateModel> error = CreateObject<NistErrorRateModel> ();
293  txA->SetErrorRateModel (error);
294  txB->SetErrorRateModel (error);
295  rx->SetErrorRateModel (error);
296  txA->SetChannel (channel);
297  txB->SetChannel (channel);
298  rx->SetChannel (channel);
299  txA->SetMobility (posTxA);
300  txB->SetMobility (posTxB);
301  rx->SetMobility (posRx);
302 
304  txB->ConfigureStandardAndBand (WIFI_PHY_STANDARD_80211a, WIFI_PHY_BAND_5GHZ);
305  rx->ConfigureStandardAndBand (WIFI_PHY_STANDARD_80211a, WIFI_PHY_BAND_5GHZ);
306 
307  rx->SetReceiveOkCallback (MakeCallback (&CollisionExperiment::Receive, this));
308 
309  for (uint32_t i = 0; i < m_input.nPackets; ++i)
310  {
311  Simulator::Schedule (Seconds (i), &CollisionExperiment::SendA, this);
312  }
313  for (uint32_t i = 0; i < m_input.nPackets; ++i)
314  {
315  Simulator::Schedule (Seconds (i) + m_input.interval, &CollisionExperiment::SendB, this);
316  }
317  m_txA = txA;
318  m_txB = txB;
319  Simulator::Run ();
320  Simulator::Destroy ();
321  return m_output;
322 }
323 
324 
325 static void PrintPsr (int argc, char *argv[])
326 {
328  struct PsrExperiment::Input input;
329 
330  CommandLine cmd (__FILE__);
331  cmd.AddValue ("Distance", "The distance between two phys", input.distance);
332  cmd.AddValue ("PacketSize", "The size of each packet sent", input.packetSize);
333  cmd.AddValue ("TxMode", "The mode to use to send each packet", input.txMode);
334  cmd.AddValue ("NPackets", "The number of packets to send", input.nPackets);
335  cmd.AddValue ("TxPowerLevel", "The power level index to use to send each packet", input.txPowerLevel);
336  cmd.Parse (argc, argv);
337 
338  struct PsrExperiment::Output output;
339  output = experiment.Run (input);
340 
341  double psr = output.received;
342  psr /= input.nPackets;
343 
344  std::cout << psr << std::endl;
345 }
346 
347 double CalcPsr (struct PsrExperiment::Output output, struct PsrExperiment::Input input)
348 {
349  double psr = output.received;
350  psr /= input.nPackets;
351  return psr;
352 }
353 
354 static void PrintPsrVsDistance (int argc, char *argv[])
355 {
356  struct PsrExperiment::Input input;
357  CommandLine cmd (__FILE__);
358  cmd.AddValue ("TxPowerLevel", "The power level index to use to send each packet", input.txPowerLevel);
359  cmd.AddValue ("TxMode", "The mode to use to send each packet", input.txMode);
360  cmd.AddValue ("NPackets", "The number of packets to send", input.nPackets);
361  cmd.AddValue ("PacketSize", "The size of each packet sent", input.packetSize);
362  cmd.Parse (argc, argv);
363 
364  for (input.distance = 1.0; input.distance < 165; input.distance += 2.0)
365  {
366  std::cout << input.distance;
368  struct PsrExperiment::Output output;
369 
370  input.txMode = "OfdmRate6Mbps";
371  output = experiment.Run (input);
372  std::cout << " " << CalcPsr (output, input);
373 
374  input.txMode = "OfdmRate9Mbps";
375  output = experiment.Run (input);
376  std::cout << " " << CalcPsr (output, input);
377 
378  input.txMode = "OfdmRate12Mbps";
379  output = experiment.Run (input);
380  std::cout << " " << CalcPsr (output, input);
381 
382  input.txMode = "OfdmRate18Mbps";
383  output = experiment.Run (input);
384  std::cout << " " << CalcPsr (output, input);
385 
386  input.txMode = "OfdmRate24Mbps";
387  output = experiment.Run (input);
388  std::cout << " " << CalcPsr (output, input);
389 
390  input.txMode = "OfdmRate36Mbps";
391  output = experiment.Run (input);
392  std::cout << " " << CalcPsr (output, input);
393 
394  input.txMode = "OfdmRate48Mbps";
395  output = experiment.Run (input);
396  std::cout << " " << CalcPsr (output, input);
397 
398  input.txMode = "OfdmRate54Mbps";
399  output = experiment.Run (input);
400  std::cout << " " << CalcPsr (output, input);
401 
402  std::cout << std::endl;
403  }
404 }
405 
406 static void PrintSizeVsRange (int argc, char *argv[])
407 {
408  double targetPsr = 0.05;
409  struct PsrExperiment::Input input;
410  CommandLine cmd (__FILE__);
411  cmd.AddValue ("TxPowerLevel", "The power level index to use to send each packet", input.txPowerLevel);
412  cmd.AddValue ("TxMode", "The mode to use to send each packet", input.txMode);
413  cmd.AddValue ("NPackets", "The number of packets to send", input.nPackets);
414  cmd.AddValue ("TargetPsr", "The psr needed to assume that we are within range", targetPsr);
415  cmd.Parse (argc, argv);
416 
417  for (input.packetSize = 10; input.packetSize < 3000; input.packetSize += 40)
418  {
419  double precision = 0.1;
420  double low = 1.0;
421  double high = 200.0;
422  while (high - low > precision)
423  {
424  double middle = low + (high - low) / 2;
425  struct PsrExperiment::Output output;
427  input.distance = middle;
428  output = experiment.Run (input);
429  double psr = CalcPsr (output, input);
430  if (psr >= targetPsr)
431  {
432  low = middle;
433  }
434  else
435  {
436  high = middle;
437  }
438  }
439  std::cout << input.packetSize << " " << input.distance << std::endl;
440  }
441 }
442 
443 static void PrintPsrVsCollisionInterval (int argc, char *argv[])
444 {
446  input.nPackets = 100;
447  CommandLine cmd (__FILE__);
448  cmd.AddValue ("NPackets", "The number of packets to send for each transmitter", input.nPackets);
449  cmd.AddValue ("xA", "the position of transmitter A", input.xA);
450  cmd.AddValue ("xB", "the position of transmitter B", input.xB);
451  cmd.Parse (argc, argv);
452 
453  for (uint32_t i = 0; i < 100; i += 1)
454  {
457  input.interval = MicroSeconds (i);
458  output = experiment.Run (input);
459  double perA = (output.receivedA + 0.0) / (input.nPackets + 0.0);
460  double perB = (output.receivedB + 0.0) / (input.nPackets + 0.0);
461  std::cout << i << " " << perA << " " << perB << std::endl;
462  }
463  for (uint32_t i = 100; i < 4000; i += 50)
464  {
467  input.interval = MicroSeconds (i);
468  output = experiment.Run (input);
469  double perA = (output.receivedA + 0.0) / (input.nPackets + 0.0);
470  double perB = (output.receivedB + 0.0) / (input.nPackets + 0.0);
471  std::cout << i << " " << perA << " " << perB << std::endl;
472  }
473 }
474 
475 
476 int main (int argc, char *argv[])
477 {
478  if (argc <= 1)
479  {
480  std::cout << "Available experiments: "
481  << "Psr "
482  << "SizeVsRange "
483  << "PsrVsDistance "
484  << "PsrVsCollisionInterval "
485  << std::endl;
486  return 0;
487  }
488  std::string type = argv[1];
489  argc--;
490  argv[1] = argv[0];
491  argv++;
492  if (type == "Psr")
493  {
494  PrintPsr (argc, argv);
495  }
496  else if (type == "SizeVsRange")
497  {
498  PrintSizeVsRange (argc, argv);
499  }
500  else if (type == "PsrVsDistance")
501  {
502  PrintPsrVsDistance (argc, argv);
503  }
504  else if (type == "PsrVsCollisionInterval")
505  {
506  PrintPsrVsCollisionInterval (argc, argv);
507  }
508  else
509  {
510  std::cout << "Wrong arguments!" << std::endl;
511  }
512 
513  return 0;
514 }
Input structure.
static void Send(Ptr< NetDevice > dev, int level, std::string emuMode)
Definition: fd-emu-send.cc:55
Output structure.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
uint32_t packetSizeA
packet size A
uint32_t nPackets
number of packets
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
PsrExperiment.
uint8_t txPowerLevelA
transmit power level A
static const uint32_t packetSize
void SetChannel(const Ptr< YansWifiChannel > channel)
Set the YansWifiChannel this YansWifiPhy is to be connected to.
struct Output m_output
output
uint8_t txPowerLevelB
transmit power level B
virtual void ConfigureStandardAndBand(WifiPhyStandard standard, WifiPhyBand band)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:1255
uint32_t packetSizeB
packet size B
std::string txMode
transmit mode
void SendB(void) const
Send B function.
struct Output m_output
output
uint32_t nPackets
number of packets
void SetMobility(const Ptr< MobilityModel > mobility)
assign a mobility model to this device
Definition: wifi-phy.cc:788
cmd
Definition: second.py:35
The 5 GHz band.
Definition: wifi-phy-band.h:37
uint32_t m_flowIdA
flow ID A
uint32_t receivedA
received A
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:68
void SendA(void) const
Send A function.
channel
Definition: third.py:92
void Receive(Ptr< WifiPsdu > psdu, RxSignalInfo rxSignalInfo, WifiTxVector txVector, std::vector< bool > statusPerMpdu)
Receive function.
RxSignalInfo structure containing info on the received signal.
Definition: phy-entity.h:66
static void PrintPsrVsDistance(int argc, char *argv[])
static void PrintPsrVsCollisionInterval(int argc, char *argv[])
double CalcPsr(struct PsrExperiment::Output output, struct PsrExperiment::Input input)
uint32_t receivedB
received B
Ptr< WifiPhy > m_txA
transmit A
double distance
distance
uint32_t m_flowIdB
flow ID B
static void PrintPsr(int argc, char *argv[])
Parse command-line arguments.
Definition: command-line.h:227
uint32_t packetSize
packet size
void SetErrorRateModel(const Ptr< ErrorRateModel > rate)
Sets the error rate model.
Definition: wifi-phy.cc:807
OFDM PHY (Clause 17)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
void Send(void)
Send function.
struct PsrExperiment::Output Run(struct PsrExperiment::Input input)
Run function.
void SetPosition(const Vector &position)
Ptr< WifiPhy > m_txB
transmit B
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
CollisionExperiment.
uint32_t received
received
void experiment(std::string queue_disc_type)
std::string txModeB
transmit mode B
struct Input m_input
input
Introspection did not find any typical Config paths.
Definition: flow-id-tag.h:27
Ptr< WifiPhy > m_tx
transmit
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
std::vector< Ptr< WifiMacQueueItem > >::const_iterator begin(void) const
Return a const iterator to the first MPDU.
Definition: wifi-psdu.cc:325
std::string txModeA
transmit mode A
struct CollisionExperiment::Output Run(struct CollisionExperiment::Input input)
Run function.
static void PrintSizeVsRange(int argc, char *argv[])
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1305
uint32_t GetFlowId(void) const
Gets the flow id for the tag.
Definition: flow-id-tag.cc:88
uint8_t txPowerLevel
transmit power level
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1642
struct Input m_input
input
Implements the IEEE 802.11 MAC header.
void Receive(Ptr< WifiPsdu > psdu, RxSignalInfo rxSignalInfo, WifiTxVector txVector, std::vector< bool > statusPerMpdu)
Send receive function.