22 #include "ns3/simulator.h"
23 #include "ns3/packet.h"
25 #include "ns3/uinteger.h"
26 #include "ns3/double.h"
27 #include "ns3/string.h"
31 #include "ns3/packet-burst.h"
34 #include "ns3/trace-source-accessor.h"
48 .AddAttribute (
"NoiseFigure",
49 "Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver.",
52 MakeDoubleChecker<double> ())
54 .AddAttribute (
"TxPower",
55 "Transmission power (dB).",
58 MakeDoubleChecker<double> ())
61 "This is the ratio of CP time to useful time.",
64 MakeDoubleChecker<double> ())
66 .AddAttribute (
"TxGain",
67 "Transmission gain (dB).",
70 MakeDoubleChecker<double> ())
72 .AddAttribute (
"RxGain",
73 "Reception gain (dB).",
76 MakeDoubleChecker<double> ())
78 .AddAttribute (
"Nfft",
82 MakeUintegerChecker<uint16_t> (256, 1024))
84 .AddAttribute (
"TraceFilePath",
85 "Path to the directory containing SNR to block error rate files",
95 .AddTraceSource (
"PhyTxBegin",
96 "Trace source indicating a packet has begun transmitting over the channel medium",
99 .AddTraceSource (
"PhyTxEnd",
100 "Trace source indicating a packet has been completely transmitted over the channel",
103 .AddTraceSource (
"PhyTxDrop",
104 "Trace source indicating a packet has been dropped by the device during transmission",
107 .AddTraceSource (
"PhyRxBegin",
108 "Trace source indicating a packet has begun being received from the channel medium by the device",
111 .AddTraceSource (
"PhyRxEnd",
112 "Trace source indicating a packet has been completely received from the channel medium by the device",
115 .AddTraceSource (
"PhyRxDrop",
116 "Trace source indicating a packet has been dropped by the device during reception",
141 m_g = (double) 1 / 4;
156 m_URNG = CreateObject<UniformRandomVariable> ();
279 bool isLastFecBlock = 0;
289 isLastFecBlock =
true;
293 isLastFecBlock =
false;
348 double SNR = rxPower - Nwb;
351 double I1 = record->
GetI1 ();
352 double I2 = record->
GetI2 ();
358 if (rand < blockErrorRate)
362 if (rand > blockErrorRate)
367 if (blockErrorRate == 1.0)
371 if (blockErrorRate == 0.0)
377 NS_LOG_INFO (
"PHY: Receive rxPower=" << rxPower <<
", Nwb=" << Nwb <<
", SNR=" << SNR <<
", Modulation="
378 << modulationType <<
", BlocErrorRate=" << blockErrorRate <<
", drop=" << (
int) drop);
472 bvec buffer (burst->GetSize () * 8, 0);
474 std::list<Ptr<Packet> > packets = burst->GetPackets ();
480 uint8_t *pstart = (uint8_t*) malloc (packet->
GetSize ());
481 memset (pstart, 0, packet->
GetSize ());
486 for (uint32_t i = 0; i < packet->
GetSize (); i++)
488 for (uint8_t l = 0; l < 8; l++)
490 temp[l] = (bool)((((uint8_t) pstart[i]) >> (7 - l)) & 0x01);
491 buffer.at (j * 8 + l) = temp[l];
512 uint8_t init[buffer.size () / 8];
513 uint8_t *pstart = init;
517 for (uint32_t i = 0; i < buffer.size (); i += 8)
521 for (
int l = 0; l < 8; l++)
523 bool bin = buffer.at (i + l);
524 temp += (uint8_t)(bin * pow (2, (7 - l)));
527 *(pstart + j) = temp;
530 uint16_t bufferSize = buffer.size () / 8;
533 while (pos < bufferSize)
535 uint16_t packetSize = 0;
537 uint8_t ht = (pstart[pos] >> 7) & 0x01;
546 uint8_t Len_MSB = pstart[pos + 1] & 0x07;
547 packetSize = (uint16_t)((uint16_t)(Len_MSB << 8) | (uint16_t)(pstart[pos + 2]));
554 Ptr<Packet> p = Create<Packet> (&(pstart[pos]), packetSize);
571 fecBlock =
bvec (buffer.begin () + i, buffer.end ());
576 fecBlock =
bvec (buffer.begin () + i, buffer.begin () + i +
m_blockSize);
593 buffer.insert (buffer.begin () + i, tmpRecFecBloc.begin (), tmpRecFecBloc.end ());
614 uint8_t &bitsPerSymbol,
615 double &fecCode)
const
617 switch (modulationType)
621 fecCode = (double) 1 / 2;
625 fecCode = (double) 1 / 2;
629 fecCode = (double) 3 / 4;
633 fecCode = (double) 1 / 2;
637 fecCode = (double) 3 / 4;
641 fecCode = (double) 2 / 3;
653 uint8_t bitsPerSymbol = 0;
657 uint16_t bitsTransmittedPerSymbol = (uint16_t)(bitsPerSymbol *
GetNrCarriers () * fecCode);
660 return (uint32_t) symbolsPerSecond * bitsTransmittedPerSymbol;
666 switch (modulationType)
727 uint32_t blockSize = 0;
728 switch (modulationType)
755 return blockSize * 8;
762 uint32_t blockSize = 0;
763 switch (modulationType)
790 return blockSize * 8;
820 uint16_t duration = 0;
872 switch (frameDurationCode)
909 uint16_t nrBlocks = (burstSize * 8) / blockSize;
911 if ((burstSize * 8) % blockSize > 0)
932 Time psDuration =
Seconds ((
double) 4 / samplingFrequency);
937 double subcarrierSpacing = samplingFrequency /
DoGetNfft ();
938 double tb = (double) 1 / subcarrierSpacing;
969 if (channelBandwidth % 1750000 == 0)
971 return (
double) 8 / 7;
973 else if (channelBandwidth % 1500000 == 0)
975 return (
double) 86 / 75;
977 else if (channelBandwidth % 1250000 == 0)
979 return (
double) 144 / 125;
981 else if (channelBandwidth % 2750000 == 0)
983 return (
double) 316 / 275;
985 else if (channelBandwidth % 2000000 == 0)
987 return (
double) 57 / 50;
991 NS_LOG_DEBUG (
"Oops may be wrong channel bandwidth for OFDM PHY!");
995 return (
double) 8 / 7;