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> ();
280 bool isLastFecBlock = 0;
290 isLastFecBlock =
true;
294 isLastFecBlock =
false;
349 double SNR = rxPower - Nwb;
352 double I1 = record->
GetI1 ();
353 double I2 = record->
GetI2 ();
359 if (rand < blockErrorRate)
363 if (rand > blockErrorRate)
368 if (blockErrorRate == 1.0)
372 if (blockErrorRate == 0.0)
378 NS_LOG_INFO (
"PHY: Receive rxPower=" << rxPower <<
", Nwb=" << Nwb <<
", SNR=" << SNR <<
", Modulation="
379 << modulationType <<
", BlocErrorRate=" << blockErrorRate <<
", drop=" << (
int) drop);
473 bvec buffer (burst->GetSize () * 8, 0);
475 std::list<Ptr<Packet> > packets = burst->GetPackets ();
481 uint8_t *pstart = (uint8_t*) std::malloc (packet->
GetSize ());
482 std::memset (pstart, 0, packet->
GetSize ());
487 for (uint32_t i = 0; i < packet->
GetSize (); i++)
489 for (uint8_t l = 0; l < 8; l++)
491 temp[l] = (bool)((((uint8_t) pstart[i]) >> (7 - l)) & 0x01);
492 buffer.at (j * 8 + l) = temp[l];
513 uint8_t init[buffer.size () / 8];
514 uint8_t *pstart = init;
518 for (uint32_t i = 0; i < buffer.size (); i += 8)
522 for (
int l = 0; l < 8; l++)
524 bool bin = buffer.at (i + l);
525 temp += (uint8_t)(bin * std::pow (2.0, (7 - l)));
528 *(pstart + j) = temp;
531 uint16_t bufferSize = buffer.size () / 8;
534 while (pos < bufferSize)
536 uint16_t packetSize = 0;
538 uint8_t ht = (pstart[pos] >> 7) & 0x01;
547 uint8_t Len_MSB = pstart[pos + 1] & 0x07;
548 packetSize = (uint16_t)((uint16_t)(Len_MSB << 8) | (uint16_t)(pstart[pos + 2]));
555 Ptr<Packet> p = Create<Packet> (&(pstart[pos]), packetSize);
572 fecBlock =
bvec (buffer.begin () + i, buffer.end ());
577 fecBlock =
bvec (buffer.begin () + i, buffer.begin () + i +
m_blockSize);
594 buffer.insert (buffer.begin () + i, tmpRecFecBloc.begin (), tmpRecFecBloc.end ());
615 uint8_t &bitsPerSymbol,
616 double &fecCode)
const
618 switch (modulationType)
622 fecCode = (double) 1 / 2;
626 fecCode = (double) 1 / 2;
630 fecCode = (double) 3 / 4;
634 fecCode = (double) 1 / 2;
638 fecCode = (double) 3 / 4;
642 fecCode = (double) 2 / 3;
654 uint8_t bitsPerSymbol = 0;
658 uint16_t bitsTransmittedPerSymbol = (uint16_t)(bitsPerSymbol *
GetNrCarriers () * fecCode);
661 return (uint32_t) symbolsPerSecond * bitsTransmittedPerSymbol;
667 switch (modulationType)
728 uint32_t blockSize = 0;
729 switch (modulationType)
756 return blockSize * 8;
763 uint32_t blockSize = 0;
764 switch (modulationType)
791 return blockSize * 8;
821 uint16_t duration = 0;
873 switch (frameDurationCode)
910 uint16_t nrBlocks = (burstSize * 8) / blockSize;
912 if ((burstSize * 8) % blockSize > 0)
933 Time psDuration =
Seconds ((
double) 4 / samplingFrequency);
938 double subcarrierSpacing = samplingFrequency /
DoGetNfft ();
939 double tb = (double) 1 / subcarrierSpacing;
970 if (channelBandwidth % 1750000 == 0)
972 return (
double) 8 / 7;
974 else if (channelBandwidth % 1500000 == 0)
976 return (
double) 86 / 75;
978 else if (channelBandwidth % 1250000 == 0)
980 return (
double) 144 / 125;
982 else if (channelBandwidth % 2750000 == 0)
984 return (
double) 316 / 275;
986 else if (channelBandwidth % 2000000 == 0)
988 return (
double) 57 / 50;
992 NS_LOG_DEBUG (
"Oops may be wrong channel bandwidth for OFDM PHY!");
996 return (
double) 8 / 7;