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"
61 void Receive (Ptr<Packet> p, double snr, WifiMode mode, enum WifiPreamble preamble);
68 PsrExperiment::Send (void)
70 Ptr<Packet> p = Create<Packet> (m_input.packetSize);
72 m_tx->SendPacket (p, mode, WIFI_PREAMBLE_SHORT, m_input.txPowerLevel);
81 PsrExperiment::PsrExperiment ()
84 PsrExperiment::Input::Input ()
86 txMode (
"OfdmRate6Mbps"),
96 m_output.received = 0;
105 channel->SetPropagationDelayModel (CreateObject<ConstantSpeedPropagationDelayModel> ());
107 channel->SetPropagationLossModel (log);
112 tx->SetErrorRateModel (error);
113 rx->SetErrorRateModel (error);
114 tx->SetChannel (channel);
115 rx->SetChannel (channel);
116 tx->SetMobility (posTx);
117 rx->SetMobility (posRx);
119 rx->SetReceiveOkCallback (
MakeCallback (&PsrExperiment::Receive,
this));
121 for (uint32_t i = 0; i < m_input.nPackets; ++i)
123 Simulator::Schedule (Seconds (i), &PsrExperiment::Send,
this);
127 Simulator::Destroy();
143 uint8_t txPowerLevelA;
144 uint8_t txPowerLevelB;
145 uint32_t packetSizeA;
146 uint32_t packetSizeB;
158 void SendA (void) const;
159 void SendB (void) const;
160 void Receive (Ptr<Packet> p, double snr, WifiMode mode, enum WifiPreamble preamble);
165 struct
Input m_input;
170 CollisionExperiment::SendA (void) const
172 Ptr<Packet> p = Create<Packet> (m_input.packetSizeA);
174 m_txA->SendPacket (p,
WifiMode (m_input.txModeA),
175 WIFI_PREAMBLE_SHORT, m_input.txPowerLevelA);
179 CollisionExperiment::SendB (
void)
const
181 Ptr<Packet> p = Create<Packet> (m_input.packetSizeB);
183 m_txB->SendPacket (p,
WifiMode (m_input.txModeB),
184 WIFI_PREAMBLE_SHORT, m_input.txPowerLevelB);
192 if (tag.GetFlowId () == m_flowIdA)
194 m_output.receivedA++;
196 else if (tag.GetFlowId () == m_flowIdB)
198 m_output.receivedB++;
202 CollisionExperiment::CollisionExperiment ()
205 CollisionExperiment::Input::Input ()
209 txModeA (
"OfdmRate6Mbps"),
210 txModeB (
"OfdmRate6Mbps"),
222 m_output.receivedA = 0;
223 m_output.receivedB = 0;
226 m_flowIdA = FlowIdTag::AllocateFlowId ();
227 m_flowIdB = FlowIdTag::AllocateFlowId ();
230 channel->SetPropagationDelayModel (CreateObject<ConstantSpeedPropagationDelayModel> ());
232 channel->SetPropagationLossModel (log);
246 txA->SetErrorRateModel (error);
247 txB->SetErrorRateModel (error);
248 rx->SetErrorRateModel (error);
249 txA->SetChannel (channel);
250 txB->SetChannel (channel);
251 rx->SetChannel (channel);
252 txA->SetMobility (posTxA);
253 txB->SetMobility (posTxB);
254 rx->SetMobility (posRx);
257 rx->SetReceiveOkCallback (
MakeCallback (&CollisionExperiment::Receive,
this));
259 for (uint32_t i = 0; i < m_input.nPackets; ++i)
261 Simulator::Schedule (Seconds (i), &CollisionExperiment::SendA,
this);
263 for (uint32_t i = 0; i < m_input.nPackets; ++i)
265 Simulator::Schedule (Seconds (i) + m_input.interval, &CollisionExperiment::SendB,
this);
270 Simulator::Destroy();
275 static void PrintPsr (
int argc,
char *argv[])
281 cmd.
AddValue (
"Distance",
"The distance between two phys", input.distance);
282 cmd.AddValue (
"PacketSize",
"The size of each packet sent", input.packetSize);
283 cmd.AddValue (
"TxMode",
"The mode to use to send each packet", input.txMode);
284 cmd.AddValue (
"NPackets",
"The number of packets to send", input.nPackets);
285 cmd.AddValue (
"TxPowerLevel",
"The power level index to use to send each packet", input.txPowerLevel);
286 cmd.Parse (argc, argv);
289 output = experiment.Run (input);
291 double psr = output.received;
292 psr /= input.nPackets;
294 std::cout << psr << std::endl;
299 double psr = output.received;
300 psr /= input.nPackets;
304 static void PrintPsrVsDistance (
int argc,
char *argv[])
308 cmd.
AddValue (
"TxPowerLevel",
"The power level index to use to send each packet", input.txPowerLevel);
309 cmd.AddValue (
"TxMode",
"The mode to use to send each packet", input.txMode);
310 cmd.AddValue (
"NPackets",
"The number of packets to send", input.nPackets);
311 cmd.AddValue (
"PacketSize",
"The size of each packet sent", input.packetSize);
312 cmd.Parse (argc, argv);
313 for (input.distance = 1.0; input.distance < 165; input.distance += 2.0)
315 std::cout << input.distance;
319 input.txMode =
"OfdmRate6Mbps";
320 output = experiment.Run (input);
321 std::cout <<
" " << CalcPsr (output, input);
323 input.txMode =
"OfdmRate9Mbps";
324 output = experiment.Run (input);
325 std::cout <<
" " << CalcPsr (output, input);
327 input.txMode =
"OfdmRate12Mbps";
328 output = experiment.Run (input);
329 std::cout <<
" " << CalcPsr (output, input);
331 input.txMode =
"OfdmRate18Mbps";
332 output = experiment.Run (input);
333 std::cout <<
" " << CalcPsr (output, input);
335 input.txMode =
"OfdmRate24Mbps";
336 output = experiment.Run (input);
337 std::cout <<
" " << CalcPsr (output, input);
339 input.txMode =
"OfdmRate36Mbps";
340 output = experiment.Run (input);
341 std::cout <<
" " << CalcPsr (output, input);
343 input.txMode =
"OfdmRate48Mbps";
344 output = experiment.Run (input);
345 std::cout <<
" " << CalcPsr (output, input);
347 input.txMode =
"OfdmRate54Mbps";
348 output = experiment.Run (input);
349 std::cout <<
" " << CalcPsr (output, input);
351 std::cout << std::endl;
355 static void PrintSizeVsRange (
int argc,
char *argv[])
357 double targetPsr = 0.05;
360 cmd.
AddValue (
"TxPowerLevel",
"The power level index to use to send each packet", input.txPowerLevel);
361 cmd.AddValue (
"TxMode",
"The mode to use to send each packet", input.txMode);
362 cmd.AddValue (
"NPackets",
"The number of packets to send", input.nPackets);
363 cmd.AddValue (
"TargetPsr",
"The psr needed to assume that we are within range", targetPsr);
364 cmd.Parse (argc, argv);
365 for (input.packetSize = 10; input.packetSize < 3000; input.packetSize += 40)
367 double precision = 0.1;
370 while (high - low > precision)
372 double middle = low + (high - low) / 2;
375 input.distance = middle;
376 output = experiment.Run (input);
377 double psr = CalcPsr (output, input);
378 if (psr >= targetPsr)
387 std::cout << input.packetSize <<
" " << input.distance << std::endl;
391 static void PrintPsrVsCollisionInterval (
int argc,
char *argv[])
394 input.nPackets = 100;
396 cmd.
AddValue (
"NPackets",
"The number of packets to send for each transmitter", input.nPackets);
397 cmd.
AddValue (
"xA",
"the position of transmitter A", input.xA);
398 cmd.
AddValue (
"xB",
"the position of transmitter B", input.xB);
399 for (uint32_t i = 0; i < 100; i += 1)
404 output = experiment.Run (input);
405 double perA = (output.receivedA + 0.0) / (input.nPackets + 0.0);
406 double perB = (output.receivedB + 0.0) / (input.nPackets + 0.0);
407 std::cout << i <<
" " << perA <<
" " << perB << std::endl;
409 for (uint32_t i = 100; i < 4000; i += 50)
414 output = experiment.Run (input);
415 double perA = (output.receivedA + 0.0) / (input.nPackets + 0.0);
416 double perB = (output.receivedB + 0.0) / (input.nPackets + 0.0);
417 std::cout << i <<
" " << perA <<
" " << perB << std::endl;
423 int main (
int argc,
char *argv[])
427 std::cout <<
"Available experiments: "
431 <<
"PsrVsCollisionInterval "
435 std::string type = argv[1];
441 PrintPsr (argc, argv);
443 else if (type ==
"SizeVsRange")
445 PrintSizeVsRange (argc, argv);
447 else if (type ==
"PsrVsDistance")
449 PrintPsrVsDistance (argc, argv);
451 else if (type ==
"PsrVsCollisionInterval")
453 PrintPsrVsCollisionInterval (argc, argv);
bool FindFirstMatchingByteTag(Tag &tag) const
smart pointer class similar to boost::intrusive_ptr
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
parse command-line argumentsInstances of this class can be used to parse command-line arguments: user...
void SetPosition(const Vector &position)
void AddValue(const std::string &name, const std::string &help, T &value)
Time MicroSeconds(uint64_t us)
create ns3::Time instances in units of microseconds.
void AddByteTag(const Tag &tag) const