20 #include "ns3/wifi-net-device.h"
21 #include "ns3/yans-wifi-channel.h"
22 #include "ns3/yans-wifi-phy.h"
23 #include "ns3/propagation-loss-model.h"
24 #include "ns3/propagation-delay-model.h"
25 #include "ns3/error-rate-model.h"
26 #include "ns3/yans-error-rate-model.h"
28 #include "ns3/mobility-model.h"
29 #include "ns3/constant-position-mobility-model.h"
30 #include "ns3/vector.h"
31 #include "ns3/packet.h"
32 #include "ns3/simulator.h"
33 #include "ns3/nstime.h"
34 #include "ns3/command-line.h"
35 #include "ns3/flow-id-tag.h"
36 #include "ns3/wifi-tx-vector.h"
62 void
Receive (Ptr<Packet> p, double snr, WifiMode mode, enum WifiPreamble preamble);
71 Ptr<Packet> p = Create<Packet> (m_input.packetSize);
90 txMode (
"OfdmRate6Mbps"),
117 rx->SetErrorRateModel (error);
119 rx->SetChannel (channel);
121 rx->SetMobility (posRx);
131 Simulator::Destroy();
162 void
SendA (void) const;
163 void
SendB (void) const;
164 void
Receive (Ptr<Packet> p, double snr, WifiMode mode, enum WifiPreamble preamble);
219 txModeA (
"OfdmRate6Mbps"),
220 txModeB (
"OfdmRate6Mbps"),
236 m_flowIdA = FlowIdTag::AllocateFlowId ();
237 m_flowIdB = FlowIdTag::AllocateFlowId ();
257 txB->SetErrorRateModel (error);
258 rx->SetErrorRateModel (error);
260 txB->SetChannel (channel);
261 rx->SetChannel (channel);
263 txB->SetMobility (posTxB);
264 rx->SetMobility (posRx);
280 Simulator::Destroy();
292 cmd.AddValue (
"PacketSize",
"The size of each packet sent", input.
packetSize);
293 cmd.AddValue (
"TxMode",
"The mode to use to send each packet", input.
txMode);
294 cmd.AddValue (
"NPackets",
"The number of packets to send", input.
nPackets);
295 cmd.AddValue (
"TxPowerLevel",
"The power level index to use to send each packet", input.
txPowerLevel);
296 cmd.Parse (argc, argv);
299 output = experiment.
Run (input);
304 std::cout << psr << std::endl;
318 cmd.
AddValue (
"TxPowerLevel",
"The power level index to use to send each packet", input.
txPowerLevel);
319 cmd.AddValue (
"TxMode",
"The mode to use to send each packet", input.
txMode);
320 cmd.AddValue (
"NPackets",
"The number of packets to send", input.
nPackets);
321 cmd.AddValue (
"PacketSize",
"The size of each packet sent", input.
packetSize);
322 cmd.Parse (argc, argv);
329 input.
txMode =
"OfdmRate6Mbps";
330 output = experiment.
Run (input);
331 std::cout <<
" " <<
CalcPsr (output, input);
333 input.
txMode =
"OfdmRate9Mbps";
334 output = experiment.
Run (input);
335 std::cout <<
" " <<
CalcPsr (output, input);
337 input.
txMode =
"OfdmRate12Mbps";
338 output = experiment.
Run (input);
339 std::cout <<
" " <<
CalcPsr (output, input);
341 input.
txMode =
"OfdmRate18Mbps";
342 output = experiment.
Run (input);
343 std::cout <<
" " <<
CalcPsr (output, input);
345 input.
txMode =
"OfdmRate24Mbps";
346 output = experiment.
Run (input);
347 std::cout <<
" " <<
CalcPsr (output, input);
349 input.
txMode =
"OfdmRate36Mbps";
350 output = experiment.
Run (input);
351 std::cout <<
" " <<
CalcPsr (output, input);
353 input.
txMode =
"OfdmRate48Mbps";
354 output = experiment.
Run (input);
355 std::cout <<
" " <<
CalcPsr (output, input);
357 input.
txMode =
"OfdmRate54Mbps";
358 output = experiment.
Run (input);
359 std::cout <<
" " <<
CalcPsr (output, input);
361 std::cout << std::endl;
367 double targetPsr = 0.05;
370 cmd.
AddValue (
"TxPowerLevel",
"The power level index to use to send each packet", input.
txPowerLevel);
371 cmd.AddValue (
"TxMode",
"The mode to use to send each packet", input.
txMode);
372 cmd.AddValue (
"NPackets",
"The number of packets to send", input.
nPackets);
373 cmd.AddValue (
"TargetPsr",
"The psr needed to assume that we are within range", targetPsr);
374 cmd.Parse (argc, argv);
377 double precision = 0.1;
380 while (high - low > precision)
382 double middle = low + (high - low) / 2;
386 output = experiment.Run (input);
387 double psr =
CalcPsr (output, input);
388 if (psr >= targetPsr)
406 cmd.
AddValue (
"NPackets",
"The number of packets to send for each transmitter", input.
nPackets);
407 cmd.
AddValue (
"xA",
"the position of transmitter A", input.
xA);
408 cmd.
AddValue (
"xB",
"the position of transmitter B", input.
xB);
409 for (uint32_t i = 0; i < 100; i += 1)
414 output = experiment.
Run (input);
417 std::cout << i <<
" " << perA <<
" " << perB << std::endl;
419 for (uint32_t i = 100; i < 4000; i += 50)
424 output = experiment.
Run (input);
427 std::cout << i <<
" " << perA <<
" " << perB << std::endl;
433 int main (
int argc,
char *argv[])
437 std::cout <<
"Available experiments: "
441 <<
"PsrVsCollisionInterval "
445 std::string type = argv[1];
453 else if (type ==
"SizeVsRange")
457 else if (type ==
"PsrVsDistance")
461 else if (type ==
"PsrVsCollisionInterval")
bool FindFirstMatchingByteTag(Tag &tag) const
Finds the first tag matching the parameter Tag type.
void experiment(bool enableCtsRts)
Run single 10 seconds experiment with enabled or disabled RTS/CTS mechanism.
Simulation virtual time values and global simulation resolution.
Smart pointer class similar to boost::intrusive_ptr.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetErrorRateModel(Ptr< ErrorRateModel > rate)
Sets the error rate model.
void SetPropagationLossModel(Ptr< PropagationLossModel > loss)
void SetPropagationDelayModel(Ptr< PropagationDelayModel > delay)
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
static void PrintPsrVsDistance(int argc, char *argv[])
static void PrintPsrVsCollisionInterval(int argc, char *argv[])
double CalcPsr(struct PsrExperiment::Output output, struct PsrExperiment::Input input)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
uint32_t GetFlowId(void) const
Gets the flow id for the tag.
static void PrintPsr(int argc, char *argv[])
Parse command-line arguments.
void SetChannel(Ptr< YansWifiChannel > channel)
Set the YansWifiChannel this YansWifiPhy is to be connected to.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
struct PsrExperiment::Output Run(struct PsrExperiment::Input input)
void SetPosition(const Vector &position)
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void Receive(Ptr< Packet > p, double snr, WifiMode mode, enum WifiPreamble preamble)
void SetMobility(Ptr< Object > mobility)
Sets the mobility model.
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Introspection did not find any typical Config paths.
Time Seconds(double value)
Construct a Time in the indicated unit.
struct CollisionExperiment::Output Run(struct CollisionExperiment::Input input)
static void PrintSizeVsRange(int argc, char *argv[])
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
static const uint32_t packetSize
void Receive(Ptr< Packet > p, double snr, WifiMode mode, enum WifiPreamble preamble)
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.