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"
49 .AddAttribute (
"NoiseFigure",
50 "Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver.",
53 MakeDoubleChecker<double> ())
55 .AddAttribute (
"TxPower",
56 "Transmission power (dB).",
59 MakeDoubleChecker<double> ())
62 "This is the ratio of CP time to useful time.",
65 MakeDoubleChecker<double> ())
67 .AddAttribute (
"TxGain",
68 "Transmission gain (dB).",
71 MakeDoubleChecker<double> ())
73 .AddAttribute (
"RxGain",
74 "Reception gain (dB).",
77 MakeDoubleChecker<double> ())
79 .AddAttribute (
"Nfft",
83 MakeUintegerChecker<uint16_t> (256, 1024))
85 .AddAttribute (
"TraceFilePath",
86 "Path to the directory containing SNR to block error rate files",
96 .AddTraceSource (
"PhyTxBegin",
97 "Trace source indicating a packet has begun transmitting over the channel medium",
100 .AddTraceSource (
"PhyTxEnd",
101 "Trace source indicating a packet has been completely transmitted over the channel",
104 .AddTraceSource (
"PhyTxDrop",
105 "Trace source indicating a packet has been dropped by the device during transmission",
108 .AddTraceSource (
"PhyRxBegin",
109 "Trace source indicating a packet has begun being received from the channel medium by the device",
112 .AddTraceSource (
"PhyRxEnd",
113 "Trace source indicating a packet has been completely received from the channel medium by the device",
116 .AddTraceSource (
"PhyRxDrop",
117 "Trace source indicating a packet has been dropped by the device during reception",
142 m_g = (double) 1 / 4;
157 m_URNG = CreateObject<UniformRandomVariable> ();
281 bool isLastFecBlock = 0;
292 isLastFecBlock =
true;
296 isLastFecBlock =
false;
351 double SNR = rxPower - Nwb;
354 double I1 = record->
GetI1 ();
355 double I2 = record->
GetI2 ();
361 if (rand < blockErrorRate)
365 if (rand > blockErrorRate)
370 if (blockErrorRate == 1.0)
374 if (blockErrorRate == 0.0)
380 NS_LOG_INFO (
"PHY: Receive rxPower=" << rxPower <<
", Nwb=" << Nwb <<
", SNR=" << SNR <<
", Modulation="
381 << modulationType <<
", BlocErrorRate=" << blockErrorRate <<
", drop=" << (
int) drop);
475 bvec buffer (burst->GetSize () * 8, 0);
477 std::list<Ptr<Packet> > packets = burst->GetPackets ();
483 uint8_t *pstart = (uint8_t*) std::malloc (packet->
GetSize ());
484 std::memset (pstart, 0, packet->
GetSize ());
489 for (uint32_t i = 0; i < packet->
GetSize (); i++)
491 for (uint8_t l = 0; l < 8; l++)
493 temp[l] = (bool)((((uint8_t) pstart[i]) >> (7 - l)) & 0x01);
494 buffer.at (j * 8 + l) = temp[l];
515 uint8_t init[buffer.size () / 8];
516 uint8_t *pstart = init;
520 for (uint32_t i = 0; i < buffer.size (); i += 8)
524 for (
int l = 0; l < 8; l++)
526 bool bin = buffer.at (i + l);
527 temp += (uint8_t)(bin * std::pow (2.0, (7 - l)));
530 *(pstart + j) = temp;
533 uint16_t bufferSize = buffer.size () / 8;
536 while (pos < bufferSize)
538 uint16_t packetSize = 0;
540 uint8_t ht = (pstart[pos] >> 7) & 0x01;
549 uint8_t Len_MSB = pstart[pos + 1] & 0x07;
550 packetSize = (uint16_t)((uint16_t)(Len_MSB << 8) | (uint16_t)(pstart[pos + 2]));
557 Ptr<Packet> p = Create<Packet> (&(pstart[pos]), packetSize);
574 fecBlock =
bvec (buffer.begin () + i, buffer.end ());
579 fecBlock =
bvec (buffer.begin () + i, buffer.begin () + i +
m_blockSize);
596 buffer.insert (buffer.begin () + i, tmpRecFecBloc.begin (), tmpRecFecBloc.end ());
617 uint8_t &bitsPerSymbol,
618 double &fecCode)
const
620 switch (modulationType)
624 fecCode = (double) 1 / 2;
628 fecCode = (double) 1 / 2;
632 fecCode = (double) 3 / 4;
636 fecCode = (double) 1 / 2;
640 fecCode = (double) 3 / 4;
644 fecCode = (double) 2 / 3;
656 uint8_t bitsPerSymbol = 0;
660 uint16_t bitsTransmittedPerSymbol = (uint16_t)(bitsPerSymbol *
GetNrCarriers () * fecCode);
663 return (uint32_t) symbolsPerSecond * bitsTransmittedPerSymbol;
669 switch (modulationType)
730 uint32_t blockSize = 0;
731 switch (modulationType)
758 return blockSize * 8;
765 uint32_t blockSize = 0;
766 switch (modulationType)
793 return blockSize * 8;
823 uint16_t duration = 0;
875 switch (frameDurationCode)
878 return Seconds (2.5);
893 return Seconds (12.5);
912 uint16_t nrBlocks = (burstSize * 8) / blockSize;
914 if ((burstSize * 8) % blockSize > 0)
935 Time psDuration = Seconds ((
double) 4 / samplingFrequency);
940 double subcarrierSpacing = samplingFrequency /
DoGetNfft ();
941 double tb = (double) 1 / subcarrierSpacing;
943 Time symbolDuration = Seconds (tb + tg);
972 if (channelBandwidth % 1750000 == 0)
974 return (
double) 8 / 7;
976 else if (channelBandwidth % 1500000 == 0)
978 return (
double) 86 / 75;
980 else if (channelBandwidth % 1250000 == 0)
982 return (
double) 144 / 125;
984 else if (channelBandwidth % 2750000 == 0)
986 return (
double) 316 / 275;
988 else if (channelBandwidth % 2000000 == 0)
990 return (
double) 57 / 50;
994 NS_LOG_DEBUG (
"Oops may be wrong channel bandwidth for OFDM PHY!");
998 return (
double) 8 / 7;