28#include "ns3/double.h"
30#include "ns3/packet-burst.h"
31#include "ns3/packet.h"
32#include "ns3/simulator.h"
33#include "ns3/string.h"
34#include "ns3/trace-source-accessor.h"
35#include "ns3/uinteger.h"
51 TypeId(
"ns3::SimpleOfdmWimaxPhy")
53 .SetGroupName(
"Wimax")
59 "Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver.",
63 MakeDoubleChecker<double>())
65 .AddAttribute(
"TxPower",
66 "Transmission power (dB).",
70 MakeDoubleChecker<double>())
73 "This is the ratio of CP time to useful time.",
77 MakeDoubleChecker<double>())
81 "Transmission gain (dB).",
84 MakeDoubleChecker<double>())
88 "Reception gain (dB).",
91 MakeDoubleChecker<double>())
98 MakeUintegerChecker<uint16_t>(256, 1024))
100 .AddAttribute(
"TraceFilePath",
101 "Path to the directory containing SNR to block error rate files",
107 .AddTraceSource(
"Rx",
110 "ns3::PacketBurst::TracedCallback")
111 .AddTraceSource(
"Tx",
114 "ns3::PacketBurst::TracedCallback")
118 "Trace source indicating a packet has begun transmitting over the channel medium",
120 "ns3::PacketBurst::TracedCallback")
124 "Trace source indicating a packet has been completely transmitted over the channel",
126 "ns3::PacketBurst::TracedCallback")
128 .AddTraceSource(
"PhyTxDrop",
129 "Trace source indicating a packet has been dropped by the device "
130 "during transmission",
132 "ns3::PacketBurst::TracedCallback")
134 .AddTraceSource(
"PhyRxBegin",
135 "Trace source indicating a packet has begun being received from the "
136 "channel medium by the device",
138 "ns3::PacketBurst::TracedCallback")
140 .AddTraceSource(
"PhyRxEnd",
141 "Trace source indicating a packet has been completely received from "
142 "the channel medium by the device",
144 "ns3::PacketBurst::TracedCallback")
148 "Trace source indicating a packet has been dropped by the device during reception",
150 "ns3::PacketBurst::TracedCallback");
189 m_URNG = CreateObject<UniformRandomVariable>();
312 bool isLastFecBlock = 0;
377 double SNR = rxPower - Nwb;
381 double I1 = record->
GetI1();
382 double I2 = record->
GetI2();
388 if (rand < blockErrorRate)
392 if (rand > blockErrorRate)
397 if (blockErrorRate == 1.0)
401 if (blockErrorRate == 0.0)
407 NS_LOG_INFO(
"PHY: Receive rxPower=" << rxPower <<
", Nwb=" << Nwb <<
", SNR=" << SNR
408 <<
", Modulation=" << modulationType <<
", BlockErrorRate="
409 << blockErrorRate <<
", drop=" << std::boolalpha << drop);
499 Bvec buffer(burst->GetSize() * 8, 0);
501 std::list<Ptr<Packet>> packets = burst->GetPackets();
504 for (std::list<
Ptr<Packet>>::iterator iter = packets.begin(); iter != packets.end(); ++iter)
507 uint8_t* pstart = (uint8_t*)std::malloc(packet->GetSize());
508 std::memset(pstart, 0, packet->GetSize());
509 packet->CopyData(pstart, packet->GetSize());
513 for (
uint32_t i = 0; i < packet->GetSize(); i++)
515 for (uint8_t l = 0; l < 8; l++)
517 temp[l] = (bool)((((uint8_t)pstart[i]) >> (7 - l)) & 0x01);
518 buffer.at(j * 8 + l) = temp[l];
539 uint8_t init[buffer.size() / 8];
540 uint8_t* pstart = init;
544 for (
uint32_t i = 0; i < buffer.size(); i += 8)
547 for (
int l = 0; l < 8; l++)
549 bool bin = buffer.at(i + l);
550 temp |= (bin << (7 - l));
553 *(pstart + j) = temp;
556 uint16_t bufferSize = buffer.size() / 8;
559 while (pos < bufferSize)
563 uint8_t ht = (pstart[pos] >> 7) & 0x01;
572 uint8_t Len_MSB = pstart[pos + 1] & 0x07;
573 packetSize = (uint16_t)((uint16_t)(Len_MSB << 8) | (uint16_t)(pstart[pos + 2]));
581 RecvBurst->AddPacket(p);
595 fecBlock =
Bvec(buffer.begin() + i, buffer.end());
616 buffer.insert(buffer.begin() + i, tmpRecFecBlock.begin(), tmpRecFecBlock.end());
637 uint8_t& bitsPerSymbol,
638 double& fecCode)
const
640 switch (modulationType)
676 uint8_t bitsPerSymbol = 0;
680 uint16_t bitsTransmittedPerSymbol = (uint16_t)(bitsPerSymbol *
GetNrCarriers() * fecCode);
683 return (
uint32_t)symbolsPerSecond * bitsTransmittedPerSymbol;
689 switch (modulationType)
730 Time transmissionTime =
748 switch (modulationType)
775 return blockSize * 8;
783 switch (modulationType)
810 return blockSize * 8;
821 "Size of padding bytes < 0");
841 uint16_t duration = 0;
885 switch (frameDurationCode)
915 uint16_t nrBlocks = (burstSize * 8) / blockSize;
917 if ((burstSize * 8) % blockSize > 0)
941 Time psDuration =
Seconds(4.0 / samplingFrequency);
946 double subcarrierSpacing = samplingFrequency /
DoGetNfft();
947 double tb = 1.0 / subcarrierSpacing;
976 if (channelBandwidth % 1750000 == 0)
980 else if (channelBandwidth % 1500000 == 0)
984 else if (channelBandwidth % 1250000 == 0)
988 else if (channelBandwidth % 2750000 == 0)
992 else if (channelBandwidth % 2000000 == 0)
998 NS_LOG_DEBUG(
"Oops may be wrong channel bandwidth for OFDM PHY!");
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Ptr< PacketBurst > GetBurst() const
uint8_t GetModulationType() const
uint8_t GetDirection() const
Smart pointer class similar to boost::intrusive_ptr.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
This class handles the SNR to BlcER traces.
void ActivateLoss(bool loss)
If activate loss is called with false, all the returned BlcER will be 0 (no losses)
void ReLoadTraces()
Reloads the trace.
void LoadTraces()
Loads the traces form the repository specified in the constructor or set by SetTraceFilePath function...
SNRToBlockErrorRateRecord * GetSNRToBlockErrorRateRecord(double SNR, uint8_t modulation)
returns a record of type SNRToBlockErrorRateRecord corresponding to a given modulation and SNR value
std::string GetTraceFilePath()
void SetTraceFilePath(char *traceFilePath)
Set the path of the repository containing the traces.
This class represents a record (handled by SnrToBlockErrorRate manager) that keeps a mapping between ...
The SendParams class defines the parameters with which Send() function of a particular PHY is called.
SimpleOfdmWimaxChannel class.
SimpleOfdmWimaxPhy class.
std::string GetTraceFilePath() const
Get trace file path.
void GetModulationFecParams(WimaxPhy::ModulationType modulationType, uint8_t &bitsPerSymbol, double &fecCode) const
Get moduleation FEC parameters.
void NotifyRxBegin(Ptr< PacketBurst > burst)
Public method used to fire a PhyRxBegin trace.
double GetTxGain() const
Get transmit gain.
double DoGetSamplingFrequency() const override
Get sampling frequency.
void CreateFecBlocks(const Bvec &buffer, WimaxPhy::ModulationType modulationType)
Create FEC blocks.
static TypeId GetTypeId()
Get the type ID.
void NotifyRxEnd(Ptr< PacketBurst > burst)
Public method used to fire a PhyRxEnd trace.
TracedCallback< Ptr< PacketBurst > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium.
uint32_t m_dataRateQpsk12
data rate
double m_txPower
transmit power
void EndReceiveFecBlock(uint32_t burstSize, WimaxPhy::ModulationType modulationType, uint8_t direction, bool drop, Ptr< PacketBurst > burst)
End receive FEC block.
void EndReceive(Ptr< const PacketBurst > burst)
End receive.
double DoGetGValue() const override
Get G value.
void DoSetGValue(double g)
Set G value.
uint32_t CalculateDataRate(WimaxPhy::ModulationType modulationType) const
Calculate data rate.
void StartSendDummyFecBlock(bool isFirstBlock, WimaxPhy::ModulationType modulationType, uint8_t direction)
Start end dummy FEC block.
void DoAttach(Ptr< WimaxChannel > channel) override
Attach the physical layer to a channel.
uint16_t DoGetTtg() const override
Get TTG.
uint8_t DoGetFrameDurationCode() const override
Get frame duration code.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
double m_txGain
transmit gain
void ActivateLoss(bool loss)
if called with true it will enable the loss model
uint32_t m_dataRateQam16_34
data rate
uint16_t m_nbErroneousBlock
erroneous blocks
uint16_t m_nrBlocks
number of blocks
WimaxPhy::PhyType GetPhyType() const override
returns the type this physical layer
uint16_t m_blockSize
block size
void SetTraceFilePath(std::string path)
Set trace file path.
double m_rxGain
receive gain
void SetNoiseFigure(double nf)
set the noise figure of the device
uint16_t m_nrReceivedFecBlocks
number received FEC blocks
void SetRxGain(double rxgain)
Set receive gsain.
Ptr< PacketBurst > ConvertBitsToBurst(Bvec buffer)
Convert bits to burst.
void EndSendFecBlock(WimaxPhy::ModulationType modulationType, uint8_t direction)
End send FEC block.
uint32_t m_dataRateQpsk34
data rate
Ptr< PacketBurst > m_currentBurst
current burst
Ptr< UniformRandomVariable > m_URNG
Provides uniform random variables.
void DoSetNfft(uint16_t nfft)
Set NFFT.
void NotifyRxDrop(Ptr< PacketBurst > burst)
Public method used to fire a PhyRxDrop trace.
uint16_t GetNrBlocks(uint32_t burstSize, WimaxPhy::ModulationType modulationType) const
Get number of blocks.
Bvec RecreateBuffer()
Recreate buffer.
TracedCallback< Ptr< PacketBurst > > m_phyRxEndTrace
The trace source fired when a packet ends the reception process from the medium.
TracedCallback< Ptr< PacketBurst > > m_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
void NotifyTxEnd(Ptr< PacketBurst > burst)
Public method used to fire a PhyTxEnd trace.
double m_noiseFigure
noise figure
void SetBlockParameters(uint32_t burstSize, WimaxPhy::ModulationType modulationType)
Set block parameters.
uint32_t m_dataRateQam64_34
data rate
uint32_t m_dataRateBpsk12
data rate
double DoGetSamplingFactor() const override
Get sampling factor.
void SetTxPower(double txPower)
set the transmission power
uint32_t GetBandwidth() const
@ FRAME_DURATION_12_POINT_5_MS
@ FRAME_DURATION_2_POINT_5_MS
uint64_t DoGetNrBytes(uint32_t symbols, WimaxPhy::ModulationType modulationType) const override
Get number of bytes.
SNRToBlockErrorRateManager * m_snrToBlockErrorRateManager
SNR to block error rate manager.
TracedCallback< Ptr< const PacketBurst > > m_traceTx
trace transmit callback
void DoSetDataRates() override
Set data rates.
uint16_t DoGetNfft() const override
Get NFFT.
void DoSetPhyParameters() override
Set Phy parameters.
uint32_t m_dataRateQam16_12
data rate
uint16_t DoGetRtg() const override
Get RTG.
uint32_t GetCodedFecBlockSize(WimaxPhy::ModulationType modulationType) const
Get coded FEC block size.
std::list< Bvec > * m_receivedFecBlocks
a list of received FEC blocks until they are combined to recreate the full burst buffer
uint32_t GetFecBlockSize(WimaxPhy::ModulationType type) const
Get FEC block size.
void SetTxGain(double txgain)
Set transmit gain.
uint16_t m_nrRemainingBlocksToSend
number of remaining blocks to send
void SetBandwidth(uint32_t BW)
Set the bandwidth.
double GetNoiseFigure() const
TracedCallback< Ptr< PacketBurst > > m_phyTxEndTrace
The trace source fired when a packet ends the transmission process on the medium.
Time GetBlockTransmissionTime(WimaxPhy::ModulationType modulationType) const
Get block transmission time.
void Send(Ptr< PacketBurst > burst, WimaxPhy::ModulationType modulationType, uint8_t direction)
Sends a burst on the channel.
Time DoGetTransmissionTime(uint32_t size, WimaxPhy::ModulationType modulationType) const override
Get transmission time.
TracedCallback< Ptr< PacketBurst > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
double GetTxPower() const
Time DoGetFrameDuration(uint8_t frameDurationCode) const override
Get frame duration.
~SimpleOfdmWimaxPhy() override
void SetSNRToBlockErrorRateTracesPath(char *tracesPath)
Set the path of the repository containing the traces.
uint32_t m_currentBurstSize
current burst size
uint32_t DoGetDataRate(WimaxPhy::ModulationType modulationType) const override
Get data rate.
void NotifyTxDrop(Ptr< PacketBurst > burst)
Public method used to fire a PhyTxDrop trace.
uint64_t DoGetNrSymbols(uint32_t size, WimaxPhy::ModulationType modulationType) const override
Get number of symbols.
void InitSimpleOfdmWimaxPhy()
Initialize simple OFDM WIMAX Phy.
void NotifyTxBegin(Ptr< PacketBurst > burst)
Public method used to fire a PhyTxBegin trace.
TracedCallback< Ptr< PacketBurst > > m_phyTxDropTrace
The trace source fired when the phy layer drops a packet as it tries to transmit it.
uint32_t m_paddingBits
padding bits
std::list< Bvec > * m_fecBlocks
the FEC blocks
Time m_blockTime
block time
double GetRxGain() const
Get receive gain.
uint16_t m_fecBlockSize
in bits, size of FEC block transmitted after PHY operations
TracedCallback< Ptr< const PacketBurst > > m_traceRx
trace receive callback
Bvec ConvertBurstToBits(Ptr< const PacketBurst > burst)
Convert burst to bits.
uint32_t m_dataRateQam64_23
data rate
void DoDispose() override
Destructor implementation.
void StartReceive(uint32_t burstSize, bool isFirstBlock, uint64_t frequency, WimaxPhy::ModulationType modulationType, uint8_t direction, double rxPower, Ptr< PacketBurst > burst)
start the reception of a fec block
uint32_t m_nrFecBlocksSent
counting the number of FEC blocks sent (within a burst)
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
Time GetFrameDuration() const
Get the frame duration.
ModulationType
ModulationType enumeration.
@ MODULATION_TYPE_QPSK_12
@ MODULATION_TYPE_QAM16_12
@ MODULATION_TYPE_QAM64_34
@ MODULATION_TYPE_QAM16_34
@ MODULATION_TYPE_QAM64_23
@ MODULATION_TYPE_QPSK_34
@ MODULATION_TYPE_BPSK_12
void SetSymbolDuration(Time symbolDuration)
set the OFDM symbol duration
Ptr< WimaxChannel > GetChannel() const
void SetChannelBandwidth(uint32_t channelBandwidth)
Set the channel bandwidth.
uint64_t GetRxFrequency() const
Get the reception frequency.
PhyType
PhyType enumeration.
Time GetSymbolDuration() const
Get the OFDM symbol duration.
uint8_t GetNrCarriers() const
Get the number of carriers in the physical frame.
PhyState GetState() const
Get the state of the device.
void SetSymbolsPerFrame(uint32_t symbolsPerFrame)
set the number of symbols per frame
void SetScanningCallback() const
calls the scanning call back function
void SetNrCarriers(uint8_t nrCarriers)
Set the number of carriers in the physical frame.
void DoDispose() override
Destructor implementation.
void SetPsPerFrame(uint16_t psPerFrame)
set the number of physical slots per frame
void SetSimplex(uint64_t frequency)
configure the physical layer in simplex mode
uint64_t GetScanningFrequency() const
Get the scanning frequency.
void SetPsDuration(Time psDuration)
set the physical slot duration
uint16_t GetPsPerSymbol() const
Get the number of physical slots per symbol.
void SetState(PhyState state)
set the state of the device
uint32_t GetChannelBandwidth() const
Get the channel bandwidth.
EventId GetChnlSrchTimeoutEvent() const
Get channel search timeout event.
bool IsDuplex() const
Check if configured in duplex mode.
Callback< void, Ptr< const PacketBurst > > GetReceiveCallback() const
void SetPsPerSymbol(uint16_t psPerSymbol)
set the number of physical slots per symbol
uint64_t GetTxFrequency() const
Get the transmission frequency.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Ptr< const AttributeChecker > MakeStringChecker()
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
U * PeekPointer(const Ptr< U > &p)
std::vector< bool > Bvec
boolean vector typedef
static const uint32_t packetSize
Packet size generated at the AP.