18#include "ns3/double.h" 
   19#include "ns3/energy-source-container.h" 
   23#include "ns3/simulator.h" 
   24#include "ns3/string.h" 
   25#include "ns3/trace-source-accessor.h" 
   26#include "ns3/traced-callback.h" 
   27#include "ns3/uinteger.h" 
   71        NS_LOG_WARN(
"Calculating SINR for unsupported modulation type");
 
   74    double intKp = -
DbToKp(rxPowerDb); 
 
   75    auto it = arrivalList.begin();
 
   76    for (; it != arrivalList.end(); it++)
 
   78        intKp += 
DbToKp(it->GetRxPowerDb());
 
   84                 << rxPowerDb << 
" dB.  Number of interferers = " << arrivalList.size()
 
   85                 << 
"  Interference + noise power = " << totalIntDb
 
   86                 << 
" dB.  SINR = " << rxPowerDb - totalIntDb << 
" dB.");
 
   87    return rxPowerDb - totalIntDb;
 
 
  106                            .AddAttribute(
"NumberOfHops",
 
  107                                          "Number of frequencies in hopping pattern.",
 
 
  136    for (; pit != pdp.
GetEnd(); pit++)
 
  138        if (std::abs(pit->GetAmp()) > maxAmp)
 
  140            maxAmp = std::abs(pit->GetAmp());
 
  147    double effRxPowerDb = rxPowerDb + 
KpToDb(csp);
 
  153    auto it = arrivalList.begin();
 
  154    double intKp = -
DbToKp(effRxPowerDb);
 
  155    for (; it != arrivalList.end(); it++)
 
  157        UanPdp intPdp = it->GetPdp();
 
  158        Time tDelta = 
Abs(arrTime + maxTapDelay - it->GetArrivalTime());
 
  163        tDelta = 
Rem(tDelta, ts + clearingTime);
 
  166        if (arrTime + maxTapDelay > it->GetArrivalTime())
 
  168            tDelta = ts + clearingTime - tDelta;
 
  171        double intPower = 0.0;
 
  178                intPdp.
SumTapsNc(ts - tDelta + clearingTime, 2 * ts - tDelta + clearingTime);
 
  184            Time start = ts + clearingTime - tDelta;
 
  187            intPower += intPdp.
SumTapsNc(start, end);
 
  189            start = start + ts + clearingTime;
 
  191            end = end + ts + clearingTime; 
 
  192            intPower += intPdp.
SumTapsNc(start, end);
 
  194        intKp += 
DbToKp(it->GetRxPowerDb()) * intPower;
 
  197    double totalIntDb = 
KpToDb(isiUpa + intKp + 
DbToKp(ambNoiseDb));
 
  200                 << rxPowerDb << 
" dB.  Effective Rx power " << effRxPowerDb
 
  201                 << 
" dB.  Number of interferers = " << arrivalList.size()
 
  202                 << 
"  Interference + noise power = " << totalIntDb
 
  203                 << 
" dB.  SINR = " << effRxPowerDb - totalIntDb << 
" dB.");
 
  204    return effRxPowerDb - totalIntDb;
 
 
  223                            .AddAttribute(
"Threshold",
 
  224                                          "SINR cutoff for good packet reception.",
 
 
  272    double EbNo = std::pow(10.0, sinrDb / 10.0);
 
  283            BER = 0.5 * erfc(sqrt(EbNo));
 
  288            BER = 0.5 * erfc(sqrt(0.5 * EbNo));
 
  307        int log2sqrtM = (int)::std::log2(sqrt(M));
 
  309        double log2M = ::std::log2(M);
 
  316        double sqrtM = ::std::sqrt(M);
 
  318        NS_LOG_DEBUG(
"M=" << M << 
"; log2sqrtM=" << log2sqrtM << 
"; log2M=" << log2M
 
  319                          << 
"; sqrtM=" << sqrtM);
 
  324        for (
int k = 0; k < log2sqrtM; k++)
 
  327                (int)((1.0 - ::std::pow(2.0, (-1.0) * (
double)k)) * ::std::sqrt(M) - 1.0);
 
  328            double pow2k = ::std::pow(2.0, (
double)k - 1.0);
 
  330            NS_LOG_DEBUG(
"k=" << k << 
"; sum_items=" << sum_items << 
"; pow2k=" << pow2k);
 
  335            for (
int j = 0; j < sum_items; ++j)
 
  337                PbK += ::std::pow(-1.0, ::std::floor((
double)j * pow2k / sqrtM)) *
 
  338                       (pow2k - ::std::floor((
double)(j * pow2k / sqrtM) + 0.5)) *
 
  339                       erfc((2.0 * (
double)j + 1.0) *
 
  340                            ::std::sqrt(3.0 * (log2M * EbNo) / (2.0 * (M - 1.0))));
 
  348            NS_LOG_DEBUG(
"k=" << k << 
"; PbK=" << PbK << 
"; BER=" << BER);
 
  351        BER *= 1.0 / (
double)log2sqrtM;
 
  360            BER = 0.5 * erfc(sqrt(0.5 * EbNo));
 
  374    PER = (1.0 - pow(1.0 - BER, (
double)pkt->GetSize() * 8.0));
 
 
  407    for (
uint32_t i = std::max(k, n - k) + 1; i <= n; ++i)
 
  412    for (
uint32_t i = 2; i <= std::min(k, n - k); ++i)
 
 
  423    uint32_t d[] = {12, 14, 16, 18, 20, 22, 24, 26, 28};
 
  425        {33, 281, 2179, 15035LLU, 105166LLU, 692330LLU, 4580007LLU, 29692894LLU, 190453145LLU};
 
  428    double ebno = std::pow(10.0, sinr / 10.0);
 
  429    double perror = 1.0 / (2.0 + ebno);
 
  450            sumd = sumd + 
NChooseK(d[r] - 1 + k, k) * std::pow(1 - perror, (
double)k);
 
  452        P[r] = std::pow(perror, (
double)d[r]) * sumd;
 
  458        Pb = Pb + Bd[r] * P[r];
 
  466    temp *= std::pow((1 - Pb), (
double)bits);
 
  468    temp = 
NChooseK(288, 1) * Pb * std::pow((1 - Pb), bits - 1.0);
 
 
  486      m_transducer(nullptr),
 
 
  577            .AddAttribute(
"CcaThreshold",
 
  578                          "Aggregate energy of incoming signals to move to CCA Busy state dB.",
 
  582            .AddAttribute(
"RxThreshold",
 
  583                          "Required SNR for signal acquisition in dB.",
 
  587            .AddAttribute(
"TxPower",
 
  588                          "Transmission output power in dB.",
 
  592            .AddAttribute(
"SupportedModes",
 
  593                          "List of modes supported by this PHY.",
 
  597            .AddAttribute(
"PerModel",
 
  598                          "Functor to calculate PER based on SINR and TxMode.",
 
  602            .AddAttribute(
"SinrModel",
 
  603                          "Functor to calculate SINR based on pkt arrivals and modes.",
 
  607            .AddTraceSource(
"RxOk",
 
  608                            "A packet was received successfully.",
 
  610                            "ns3::UanPhy::TracedCallback")
 
  611            .AddTraceSource(
"RxError",
 
  612                            "A packet was received unsuccessfuly.",
 
  614                            "ns3::UanPhy::TracedCallback")
 
  615            .AddTraceSource(
"Tx",
 
  616                            "Packet transmission beginning.",
 
  618                            "ns3::UanPhy::TracedCallback");
 
 
  645                                            << 
", stopping rx/tx activities");
 
 
  667                                             << 
", restoring rx/tx activities");
 
 
  678        NS_LOG_DEBUG(
"Energy depleted, node cannot transmit any packet. Dropping.");
 
  684        NS_LOG_DEBUG(
"PHY requested to TX while already Transmitting.  Dropping packet.");
 
  689        NS_LOG_DEBUG(
"PHY requested to TX while sleeping.  Dropping packet.");
 
 
  717        NS_LOG_DEBUG(
"Transmission ended but node sleeping or dead");
 
 
  745    NS_LOG_DEBUG(
"PHY " << 
m_mac->GetAddress() << 
": rx power after RX gain = " << rxPowerDb
 
  751        NS_LOG_DEBUG(
"Energy depleted, node cannot receive any packet. Dropping.");
 
  764                            << 
": Starting RX in RX mode.  SINR of pktRx = " << 
m_minRxSinrDb);
 
  772        bool hasmode = 
false;
 
  788                            << 
": Starting RX in IDLE mode.  SINR = " << newsinr);
 
 
 1036    m_pg->SetStream(stream);
 
 
 1079    auto it = arrivalList.begin();
 
 1081    double interfPower = 0;
 
 1083    for (; it != arrivalList.end(); it++)
 
 1085        if (pkt != it->GetPacket())
 
 1087            interfPower += 
DbToKp(it->GetRxPowerDb());
 
 1091    return KpToDb(interfPower);
 
 
 1097    return std::pow(10, db / 10.0);
 
 
 1103    return 10 * std::log10(kp);
 
 
 1112        (*it)->NotifyRxStart();
 
 
 1122        (*it)->NotifyRxEndOk();
 
 
 1132        (*it)->NotifyRxEndError();
 
 
 1142        (*it)->NotifyCcaStart();
 
 
 1152        (*it)->NotifyCcaEnd();
 
 
 1162        (*it)->NotifyTxStart(duration);
 
 
 1172        (*it)->NotifyTxEnd();
 
 
void Nullify()
Discard the implementation, set it to null.
bool IsNull() const
Check for null implementation.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
bool IsPending() const
This method is syntactic sugar for !IsExpired().
virtual void DoDispose()
Destructor implementation.
Smart pointer class similar to boost::intrusive_ptr.
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...
static Time Now()
Return the current simulation virtual time.
Hold variables of type string.
Time GetDelay() const
Get the delay time, usually from first arrival of signal.
Simulation virtual time values and global simulation resolution.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Container for UanTxModes.
uint32_t GetNModes() const
Get the number of modes in this list.
void AppendMode(UanTxMode mode)
Add mode to this list.
AttributeValue implementation for UanModesList.
void Clear()
Clear all pointer references.
Ptr< Node > GetNode() const override
The power delay profile returned by propagation models.
Iterator GetEnd() const
Get the end of the tap list (one beyond the last entry).
double SumTapsFromMaxNc(Time delay, Time duration) const
Compute the non-coherent sum of tap amplitudes starting after a delay from the maximum amplitude for ...
double SumTapsNc(Time begin, Time end) const
Compute the non-coherent sum of tap amplitudes between a start and end time.
const Tap & GetTap(uint32_t i) const
Get the Tap at the specified delay index.
Iterator GetBegin() const
Get the beginning of the tap vector.
Default SINR calculator for UanPhyGen.
double CalcSinrDb(Ptr< Packet > pkt, Time arrTime, double rxPowerDb, double ambNoiseDb, UanTxMode mode, UanPdp pdp, const UanTransducer::ArrivalList &arrivalList) const override
Calculate the SINR value for a packet.
UanPhyCalcSinrDefault()
Constructor.
static TypeId GetTypeId()
Register this type.
~UanPhyCalcSinrDefault() override
Destructor.
WHOI Micromodem like FH-FSK model.
UanPhyCalcSinrFhFsk()
Constructor.
double CalcSinrDb(Ptr< Packet > pkt, Time arrTime, double rxPowerDb, double ambNoiseDb, UanTxMode mode, UanPdp pdp, const UanTransducer::ArrivalList &arrivalList) const override
Calculate the SINR value for a packet.
static TypeId GetTypeId()
Register this type.
~UanPhyCalcSinrFhFsk() override
Destructor.
uint32_t m_hops
Number of hops.
Class used for calculating SINR of packet in UanPhy.
double DbToKp(double db) const
Convert dB re 1 uPa to kilopascals.
double KpToDb(double kp) const
Convert kilopascals to dB re 1 uPa.
Ptr< UanChannel > GetChannel() const override
Get the attached channel.
bool IsStateSleep() override
void SetTxPowerDb(double txpwr) override
Set the transmit power.
double KpToDb(double kp)
Convert kilopascals to dB.
void NotifyTransStartTx(Ptr< Packet > packet, double txPowerDb, UanTxMode txMode) override
Called when a transmission is beginning on the attached transducer.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< UanPhyPer > m_per
Error model.
void SetRxThresholdDb(double thresh) override
Set the minimum SINR threshold to receive a packet without errors.
void EnergyDepletionHandler() override
Handle the energy depletion event.
void NotifyListenersTxStart(Time duration)
Call UanListener::NotifyTxStart on all listeners.
Time m_pktRxArrTime
Packet arrival time.
UanTxMode GetMode(uint32_t n) override
Get a specific transmission mode.
void UpdatePowerConsumption(const State state)
Update energy source with new state.
void SetEnergyModelCallback(energy::DeviceEnergyModel::ChangeStateCallback cb) override
Set the DeviceEnergyModel callback for UanPhy device.
double GetRxThresholdDb() override
Get the minimum received signal strength required to receive a packet without errors.
ListenerList m_listeners
List of listeners.
void NotifyListenersCcaStart()
Call UanListener::NotifyCcaStart on all listeners.
void SetSleepMode(bool sleep) override
Set the Phy SLEEP mode.
~UanPhyGen() override
Dummy destructor, see DoDispose.
double m_rxRecvPwrDb
Receiver power.
bool IsStateBusy() override
void NotifyListenersRxGood()
Call UanListener::NotifyRxEndOk on all listeners.
uint32_t GetNModes() override
Get the number of transmission modes supported by this Phy.
Ptr< UanPhyCalcSinr > m_sinr
SINR calculator.
void NotifyListenersRxBad()
Call UanListener::NotifyRxEndError on all listeners.
double GetCcaThresholdDb() override
Get the CCA threshold signal strength required to detect channel busy.
Ptr< Packet > m_pktRx
Received packet.
void SetReceiveErrorCallback(RxErrCallback cb) override
Set the callback to be used when a packet is received with errors.
Ptr< UanTransducer > GetTransducer() override
Get the attached transducer.
Ptr< UanTransducer > m_transducer
Associated transducer.
double m_rxThreshDb
Receive SINR threshold.
EventId m_rxEndEvent
Rx event.
void DoDispose() override
Destructor implementation.
double m_ccaThreshDb
CCA busy threshold.
void SetTransducer(Ptr< UanTransducer > trans) override
Attach a transducer to this Phy.
RxOkCallback m_recOkCb
Callback for packets received without error.
void NotifyListenersTxEnd()
Call UanListener::NotifyTxEnd on all listeners.
Ptr< UanMac > m_mac
MAC layer.
Ptr< UanNetDevice > GetDevice() const override
Get the device hosting this Phy.
double GetInterferenceDb(Ptr< Packet > pkt)
Calculate interference power from overlapping packet arrivals, in dB.
double m_txPwrDb
Transmit power.
double CalculateSinrDb(Ptr< Packet > pkt, Time arrTime, double rxPowerDb, UanTxMode mode, UanPdp pdp)
Calculate the SINR value for a packet.
void SetReceiveOkCallback(RxOkCallback cb) override
Set the callback to be used when a packet is received without error.
static UanModesList GetDefaultModes()
Get the default transmission modes.
bool IsStateTx() override
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_rxOkLogger
A packet destined for this Phy was received without error.
Ptr< UniformRandomVariable > m_pg
Provides uniform random variables.
EventId m_txEndEvent
Tx event.
void SendPacket(Ptr< Packet > pkt, uint32_t modeNum) override
Send a packet using a specific transmission mode.
void RegisterListener(UanPhyListener *listener) override
Register a UanPhyListener to be notified of common UanPhy events.
bool m_cleared
Flag when we've been cleared.
bool IsStateRx() override
void SetMac(Ptr< UanMac > mac) override
Set the MAC forwarding messages to this Phy.
double m_minRxSinrDb
Minimum receive SINR during packet reception.
static TypeId GetTypeId()
Register this type.
energy::DeviceEnergyModel::ChangeStateCallback m_energyCallback
Energy model callback.
void SetCcaThresholdDb(double thresh) override
Set the threshold for detecting channel busy.
Ptr< UanChannel > m_channel
Attached channel.
bool IsStateCcaBusy() override
void SetDevice(Ptr< UanNetDevice > device) override
Set the device hosting this Phy.
double DbToKp(double db)
Convert dB to kilopascals.
UanTxMode m_pktRxMode
Packet transmission mode at receiver.
void TxEndEvent()
Event to process end of packet transmission.
void Clear() override
Clear all pointer references.
Ptr< Packet > GetPacketRx() const override
Get the packet currently being received.
RxErrCallback m_recErrCb
Callback for packets received with errors.
void RxEndEvent(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode)
Event to process end of packet reception.
Ptr< UanNetDevice > m_device
Device hosting this Phy.
void StartRxPacket(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp) override
Packet arriving from channel: i.e.
Ptr< Packet > m_pktTx
Sent packet.
void SetChannel(Ptr< UanChannel > channel) override
Attach to a channel.
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_txLogger
A packet was sent from this Phy.
void NotifyIntChange() override
Called when there has been a change in the amount of interference this node is experiencing from othe...
double GetTxPowerDb() override
Get the current transmit power, in dB.
bool IsStateIdle() override
UanPdp m_pktRxPdp
Power delay profile of packet.
void NotifyListenersCcaEnd()
Call UanListener::NotifyCcaEnd on all listeners.
void EnergyRechargeHandler() override
Handle the energy recharge event.
void NotifyListenersRxStart()
Call UanListener::NotifyRxStart on all listeners.
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_rxErrLogger
A packet destined for this Phy was received with error.
UanModesList m_modes
List of modes supported by this PHY.
Base class for UAN Phy models.
void NotifyTxDrop(Ptr< const Packet > packet)
Called when the transducer attempts to transmit a new packet while already transmitting a prior packe...
void NotifyRxDrop(Ptr< const Packet > packet)
Called when the Phy drops a packet.
void NotifyRxBegin(Ptr< const Packet > packet)
Called when the Phy begins to receive a packet.
void NotifyRxEnd(Ptr< const Packet > packet)
Called when a packet is received without error.
State
Enum defining possible Phy states.
Interface for PHY event listener.
Packet error rate calculation for common tx modes based on UanPhyPerUmodem.
~UanPhyPerCommonModes() override
Destructor.
double CalcPer(Ptr< Packet > pkt, double sinrDb, UanTxMode mode) override
Calculate the Packet ERror probability based on SINR at the receiver and a tx mode.
UanPhyPerCommonModes()
Constructor.
static TypeId GetTypeId()
Register this type.
Default Packet Error Rate calculator for UanPhyGen.
UanPhyPerGenDefault()
Constructor.
~UanPhyPerGenDefault() override
Destructor.
double CalcPer(Ptr< Packet > pkt, double sinrDb, UanTxMode mode) override
Calculate the packet error probability based on SINR at the receiver and a tx mode.
static TypeId GetTypeId()
Register this type.
double m_thresh
SINR threshold.
Calculate packet error probability, based on received SINR and modulation (mode).
Packet error rate calculation assuming WHOI Micromodem-like PHY (FH-FSK)
double CalcPer(Ptr< Packet > pkt, double sinrDb, UanTxMode mode) override
Calculate the packet error probability based on SINR at the receiver and a tx mode.
static TypeId GetTypeId()
Register this type.
double NChooseK(uint32_t n, uint32_t k)
Binomial coefficient.
UanPhyPerUmodem()
Constructor.
~UanPhyPerUmodem() override
Destructor.
virtual void AddPhy(Ptr< UanPhy > phy)=0
Attach a physical network layer above this transducer.
virtual const ArrivalList & GetArrivalList() const =0
Get the list of overlapped (in time) packets at this transducer.
std::list< UanPacketArrival > ArrivalList
List of arriving packets overlapping in time.
virtual void Transmit(Ptr< UanPhy > src, Ptr< Packet > packet, double txPowerDb, UanTxMode txMode)=0
Transmit a packet from this transducer.
virtual void Clear()=0
Clears all pointer references.
static UanTxMode CreateMode(UanTxMode::ModulationType type, uint32_t dataRateBps, uint32_t phyRateSps, uint32_t cfHz, uint32_t bwHz, uint32_t constSize, std::string name)
Abstraction of packet modulation information.
uint32_t GetUid() const
Get a unique id for the mode.
@ QAM
Quadrature amplitude modulation.
@ OTHER
Unspecified/undefined.
@ FSK
Frequency shift keying.
uint32_t GetConstellationSize() const
Get the number of constellation points in the modulation scheme.
uint32_t GetPhyRateSps() const
Get the physical signaling rate.
uint32_t GetDataRateBps() const
Get the data rate of the transmit mode.
uint32_t GetBandwidthHz() const
Get the transmission signal bandwidth.
ModulationType GetModType() const
Get the modulation type of the mode.
uint32_t GetCenterFreqHz() const
Get the transmission center frequency.
Hold an unsigned integer type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< const AttributeChecker > MakeDoubleChecker()
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Ptr< const AttributeChecker > MakeUanModesListChecker()
Ptr< const AttributeAccessor > MakeUanModesListAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
int64x64_t Abs(const int64x64_t &value)
Absolute value.
#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_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
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.
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.
Time Rem(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
@ IDLE
Channel is IDLE, no packet is being transmitted.