17#include "ns3/double.h"
19#include "ns3/packet-burst.h"
20#include "ns3/packet.h"
21#include "ns3/simulator.h"
22#include "ns3/string.h"
23#include "ns3/trace-source-accessor.h"
24#include "ns3/uinteger.h"
41 TypeId(
"ns3::SimpleOfdmWimaxPhy")
43 .SetGroupName(
"Wimax")
49 "Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver.",
55 .AddAttribute(
"TxPower",
56 "Transmission power (dB).",
63 "This is the ratio of CP time to useful time.",
71 "Transmission gain (dB).",
78 "Reception gain (dB).",
90 .AddAttribute(
"TraceFilePath",
91 "Path to the directory containing SNR to block error rate files",
100 "ns3::PacketBurst::TracedCallback")
101 .AddTraceSource(
"Tx",
104 "ns3::PacketBurst::TracedCallback")
108 "Trace source indicating a packet has begun transmitting over the channel medium",
110 "ns3::PacketBurst::TracedCallback")
114 "Trace source indicating a packet has been completely transmitted over the channel",
116 "ns3::PacketBurst::TracedCallback")
118 .AddTraceSource(
"PhyTxDrop",
119 "Trace source indicating a packet has been dropped by the device "
120 "during transmission",
122 "ns3::PacketBurst::TracedCallback")
124 .AddTraceSource(
"PhyRxBegin",
125 "Trace source indicating a packet has begun being received from the "
126 "channel medium by the device",
128 "ns3::PacketBurst::TracedCallback")
130 .AddTraceSource(
"PhyRxEnd",
131 "Trace source indicating a packet has been completely received from "
132 "the channel medium by the device",
134 "ns3::PacketBurst::TracedCallback")
138 "Trace source indicating a packet has been dropped by the device during reception",
140 "ns3::PacketBurst::TracedCallback");
268 Send(o_params->GetBurst(),
270 o_params->GetDirection());
302 bool isLastFecBlock =
false;
367 double SNR = rxPower - Nwb;
371 double I1 = record->
GetI1();
372 double I2 = record->
GetI2();
374 double blockErrorRate =
m_URNG->GetValue(I1, I2);
376 double rand =
m_URNG->GetValue(0.0, 1.0);
378 if (rand < blockErrorRate)
382 if (rand > blockErrorRate)
387 if (blockErrorRate == 1.0)
391 if (blockErrorRate == 0.0)
397 NS_LOG_INFO(
"PHY: Receive rxPower=" << rxPower <<
", Nwb=" << Nwb <<
", SNR=" << SNR
398 <<
", Modulation=" << modulationType <<
", BlockErrorRate="
399 << blockErrorRate <<
", drop=" << std::boolalpha << drop);
489 Bvec buffer(burst->GetSize() * 8,
false);
491 std::list<Ptr<Packet>> packets = burst->GetPackets();
494 for (
auto iter = packets.begin(); iter != packets.end(); ++iter)
497 auto pstart = (uint8_t*)std::malloc(packet->GetSize());
498 std::memset(pstart, 0, packet->GetSize());
499 packet->CopyData(pstart, packet->GetSize());
501 temp.resize(0,
false);
502 temp.resize(8,
false);
503 for (
uint32_t i = 0; i < packet->GetSize(); i++)
505 for (uint8_t l = 0; l < 8; l++)
507 temp[l] = (bool)((((uint8_t)pstart[i]) >> (7 - l)) & 0x01);
508 buffer.at(j * 8 + l) = temp[l];
529 const auto bufferSize = buffer.size() / 8;
530 std::vector<uint8_t> bytes(bufferSize, 0);
533 for (std::size_t i = 0; i < buffer.size(); i += 8)
536 for (std::size_t l = 0; l < 8; l++)
538 bool bin = buffer.at(i + l);
539 temp |= (bin << (7 - l));
547 while (pos < bufferSize)
551 uint8_t ht = (bytes[pos] >> 7) & 0x01;
560 uint8_t Len_MSB = bytes[pos + 1] & 0x07;
561 packetSize = (uint16_t)((uint16_t)(Len_MSB << 8) | (uint16_t)(bytes[pos + 2]));
569 RecvBurst->AddPacket(p);
583 fecBlock =
Bvec(buffer.begin() + i, buffer.end());
604 buffer.insert(buffer.begin() + i, tmpRecFecBlock.begin(), tmpRecFecBlock.end());
625 uint8_t& bitsPerSymbol,
626 double& fecCode)
const
628 switch (modulationType)
664 uint8_t bitsPerSymbol = 0;
668 auto bitsTransmittedPerSymbol = (uint16_t)(bitsPerSymbol *
GetNrCarriers() * fecCode);
671 return (
uint32_t)symbolsPerSecond * bitsTransmittedPerSymbol;
677 switch (modulationType)
718 Time transmissionTime =
736 switch (modulationType)
763 return blockSize * 8;
771 switch (modulationType)
792 return blockSize * 8;
803 "Size of padding bytes < 0");
823 uint16_t duration = 0;
867 switch (frameDurationCode)
897 uint16_t nrBlocks = (burstSize * 8) / blockSize;
899 if ((burstSize * 8) % blockSize > 0)
923 Time psDuration =
Seconds(4.0 / samplingFrequency);
928 double subcarrierSpacing = samplingFrequency /
DoGetNfft();
929 double tb = 1.0 / subcarrierSpacing;
958 if (channelBandwidth % 1750000 == 0)
962 else if (channelBandwidth % 1500000 == 0)
966 else if (channelBandwidth % 1250000 == 0)
970 else if (channelBandwidth % 2750000 == 0)
974 else if (channelBandwidth % 2000000 == 0)
980 NS_LOG_DEBUG(
"Oops may be wrong channel bandwidth for OFDM PHY!");
1084 m_URNG->SetStream(stream);
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Smart pointer class similar to boost::intrusive_ptr.
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...
#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.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
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)
Ptr< const AttributeChecker > MakeUintegerChecker()
std::vector< bool > Bvec
boolean vector typedef
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Ptr< const AttributeChecker > MakeDoubleChecker()
Ptr< const AttributeChecker > MakeStringChecker()
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
static const uint32_t packetSize
Packet size generated at the AP.