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
33using namespace ns3;
34
37{
38public:
40 struct Input
41 {
42 Input ();
43 double distance;
44 std::string txMode;
45 uint8_t txPowerLevel;
48 };
50 struct Output
51 {
53 };
55
61 struct PsrExperiment::Output Run (struct PsrExperiment::Input input);
62
63private:
65 void Send (void);
73 void Receive (Ptr<const WifiPsdu> psdu, RxSignalInfo rxSignalInfo,
74 WifiTxVector txVector, std::vector<bool> statusPerMpdu);
75 Ptr<WifiPhy> m_tx;
76 struct Input m_input;
78};
79
80void
82{
83 Ptr<WifiPsdu> psdu = Create<WifiPsdu> (Create<Packet> (m_input.packetSize), WifiMacHeader ());
85 WifiTxVector txVector;
87 txVector.SetMode (mode);
89 m_tx->Send (psdu, txVector);
90}
91
92void
94 WifiTxVector txVector, std::vector<bool> statusPerMpdu)
95{
97}
98
100{
101}
103 : distance (5.0),
104 txMode ("OfdmRate6Mbps"),
105 txPowerLevel (0),
106 packetSize (2304),
107 nPackets (400)
108{
109}
110
112PsrExperiment::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
139
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;
148 Simulator::Destroy ();
149 return m_output;
150}
151
154{
155public:
157 struct Input
158 {
159 Input ();
161 double xA;
162 double xB;
163 std::string txModeA;
164 std::string txModeB;
170 };
172 struct Output
173 {
176 };
178
185private:
187 void SendA (void) const;
189 void SendB (void) const;
197 void Receive (Ptr<const WifiPsdu> psdu, RxSignalInfo rxSignalInfo,
198 WifiTxVector txVector, std::vector<bool> statusPerMpdu);
199 Ptr<WifiPhy> m_txA;
200 Ptr<WifiPhy> m_txB;
203 struct Input m_input;
205};
206
207void
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
219void
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
231void
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
267CollisionExperiment::Run (struct CollisionExperiment::Input input)
268{
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
306
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;
320 Simulator::Destroy ();
321 return m_output;
322}
323
324
325static 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
347double CalcPsr (struct PsrExperiment::Output output, struct PsrExperiment::Input input)
348{
349 double psr = output.received;
350 psr /= input.nPackets;
351 return psr;
352}
353
354static 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
406static 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
443static 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
476int 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}
void Run(ObjectFactory &factory, uint32_t pop, uint32_t total, uint32_t runs, Ptr< RandomVariableStream > eventStream, bool calRev)
Perform the runs for a single scheduler type.
CollisionExperiment.
uint32_t m_flowIdB
flow ID B
void SendA(void) const
Send A function.
struct Output m_output
output
void SendB(void) const
Send B function.
struct Input m_input
input
Ptr< WifiPhy > m_txB
transmit B
struct CollisionExperiment::Output Run(struct CollisionExperiment::Input input)
Run function.
Ptr< WifiPhy > m_txA
transmit A
uint32_t m_flowIdA
flow ID A
void Receive(Ptr< const WifiPsdu > psdu, RxSignalInfo rxSignalInfo, WifiTxVector txVector, std::vector< bool > statusPerMpdu)
Receive function.
PsrExperiment.
Ptr< WifiPhy > m_tx
transmit
void Receive(Ptr< const WifiPsdu > psdu, RxSignalInfo rxSignalInfo, WifiTxVector txVector, std::vector< bool > statusPerMpdu)
Send receive function.
void Send(void)
Send function.
struct Input m_input
input
struct PsrExperiment::Output Run(struct PsrExperiment::Input input)
Run function.
struct Output m_output
output
Parse command-line arguments.
Definition: command-line.h:229
Introspection did not find any typical Config paths.
Definition: flow-id-tag.h:28
uint32_t GetFlowId(void) const
Gets the flow id for the tag.
Definition: flow-id-tag.cc:88
void SetPosition(const Vector &position)
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
Implements the IEEE 802.11 MAC header.
represent a single transmission mode
Definition: wifi-mode.h:48
void Send(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector)
This function is a wrapper for the Send variant that accepts a WifiConstPsduMap as first argument.
Definition: wifi-phy.cc:1568
void SetErrorRateModel(const Ptr< ErrorRateModel > model)
Sets the error rate model.
Definition: wifi-phy.cc:608
virtual void ConfigureStandard(WifiStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:883
void SetMobility(const Ptr< MobilityModel > mobility)
assign a mobility model to this device
Definition: wifi-phy.cc:581
void SetReceiveOkCallback(RxOkCallback callback)
Definition: wifi-phy.cc:411
std::vector< Ptr< WifiMpdu > >::const_iterator begin(void) const
Return a const iterator to the first MPDU.
Definition: wifi-psdu.cc:319
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
void SetChannel(const Ptr< YansWifiChannel > channel)
Set the YansWifiChannel this YansWifiPhy is to be connected to.
void experiment(std::string queue_disc_type)
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1261
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1245
@ WIFI_STANDARD_80211a
@ WIFI_PREAMBLE_LONG
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:661
cmd
Definition: second.py:43
channel
Definition: third.py:83
uint32_t nPackets
number of packets
uint8_t txPowerLevelB
transmit power level B
uint32_t packetSizeA
packet size A
std::string txModeA
transmit mode A
uint8_t txPowerLevelA
transmit power level A
uint32_t packetSizeB
packet size B
std::string txModeB
transmit mode B
uint32_t receivedA
received A
uint32_t receivedB
received B
Input structure.
uint32_t nPackets
number of packets
std::string txMode
transmit mode
double distance
distance
uint8_t txPowerLevel
transmit power level
uint32_t packetSize
packet size
Output structure.
uint32_t received
received
RxSignalInfo structure containing info on the received signal.
Definition: phy-entity.h:69
static void PrintPsr(int argc, char *argv[])
double CalcPsr(struct PsrExperiment::Output output, struct PsrExperiment::Input input)
static void PrintPsrVsCollisionInterval(int argc, char *argv[])
static void PrintPsrVsDistance(int argc, char *argv[])
static void PrintSizeVsRange(int argc, char *argv[])
static const uint32_t packetSize
Packet size generated at the AP.