26 #include "ns3/simulator.h"
27 #include "ns3/traced-callback.h"
29 #include "ns3/trace-source-accessor.h"
30 #include "ns3/double.h"
31 #include "ns3/string.h"
33 #include "ns3/uan-tx-mode.h"
35 #include "ns3/uinteger.h"
36 #include "ns3/energy-source-container.h"
37 #include "ns3/acoustic-modem-energy-model.h"
65 static TypeId tid =
TypeId (
"ns3::UanPhyCalcSinrDefault")
84 NS_LOG_WARN (
"Calculating SINR for unsupported modulation type");
87 double intKp = -
DbToKp (rxPowerDb);
88 UanTransducer::ArrivalList::const_iterator it = arrivalList.begin ();
89 for (; it != arrivalList.end (); it++)
91 intKp +=
DbToKp (it->GetRxPowerDb ());
94 double totalIntDb =
KpToDb (intKp +
DbToKp (ambNoiseDb));
96 NS_LOG_DEBUG (
"Calculating SINR: RxPower = " << rxPowerDb <<
" dB. Number of interferers = " << arrivalList.size () <<
" Interference + noise power = " << totalIntDb <<
" dB. SINR = " << rxPowerDb - totalIntDb <<
" dB.");
97 return rxPowerDb - totalIntDb;
115 .SetGroupName (
"Uan")
117 .AddAttribute (
"NumberOfHops",
118 "Number of frequencies in hopping pattern.",
121 MakeUintegerChecker<uint32_t> ())
145 Time maxTapDelay (0);
147 for (; pit != pdp.
GetEnd (); pit++)
149 if (std::abs (pit->GetAmp ()) > maxAmp)
151 maxAmp = std::abs (pit->GetAmp ());
159 double effRxPowerDb = rxPowerDb +
KpToDb (csp);
163 UanTransducer::ArrivalList::const_iterator it = arrivalList.begin ();
164 double intKp = -
DbToKp (effRxPowerDb);
165 for (; it != arrivalList.end (); it++)
167 UanPdp intPdp = it->GetPdp ();
168 Time tDelta =
Abs (arrTime + maxTapDelay - it->GetArrivalTime ());
173 tDelta =
Rem (tDelta, ts + clearingTime);
176 if (arrTime + maxTapDelay > it->GetArrivalTime ())
178 tDelta = ts + clearingTime - tDelta;
181 double intPower = 0.0;
186 intPower += intPdp.
SumTapsNc (ts - tDelta + clearingTime,
187 2 * ts - tDelta + clearingTime);
198 end = end + ts + clearingTime;
201 intKp +=
DbToKp (it->GetRxPowerDb ()) * intPower;
204 double totalIntDb =
KpToDb (isiUpa + intKp +
DbToKp (ambNoiseDb));
206 NS_LOG_DEBUG (
"Calculating SINR: RxPower = " << rxPowerDb <<
" dB. Effective Rx power " << effRxPowerDb <<
" dB. Number of interferers = " << arrivalList.size () <<
" Interference + noise power = " << totalIntDb <<
" dB. SINR = " << effRxPowerDb - totalIntDb <<
" dB.");
207 return effRxPowerDb - totalIntDb;
225 .SetGroupName (
"Uan")
227 .AddAttribute (
"Threshold",
"SINR cutoff for good packet reception.",
230 MakeDoubleChecker<double> ());
265 static TypeId tid =
TypeId (
"ns3::UanPhyPerCommonModes")
267 .SetGroupName (
"Uan")
278 double EbNo = std::pow (10.0, sinrDb / 10.0);
289 BER = 0.5 * erfc (sqrt (EbNo));
294 BER = 0.5 * erfc (sqrt (0.5 * EbNo));
314 int log2sqrtM = (int) ::std::log2 ( sqrt (M));
316 double log2M = ::std::log2 (M);
323 double sqrtM = ::std::sqrt (M);
325 NS_LOG_DEBUG (
"M=" << M <<
"; log2sqrtM=" << log2sqrtM <<
"; log2M=" << log2M <<
"; sqrtM=" << sqrtM);
330 for (
int k = 0;
k < log2sqrtM;
k++)
332 int sum_items = (int) ((1.0 - ::std::pow ( 2.0, (-1.0) * (
double)
k)) * ::std::sqrt (M) - 1.0);
333 double pow2k = ::std::pow (2.0, (
double)
k - 1.0);
335 NS_LOG_DEBUG (
"k=" <<
k <<
"; sum_items=" << sum_items <<
"; pow2k=" << pow2k);
340 for (
int j = 0; j < sum_items; ++j)
342 PbK += ::std::pow (-1.0, (
double) j * pow2k / sqrtM)
343 * (pow2k - ::std::floor ( (
double) (j * pow2k / sqrtM) - 0.5))
344 * erfc ((2.0 * (
double)j + 1.0) * ::std::sqrt (3.0 * (log2M * EbNo) / (2.0 * (M - 1.0))));
353 NS_LOG_DEBUG (
"k=" <<
k <<
"; PbK=" << PbK <<
"; BER=" << BER);
356 BER *= 1.0 / (double) log2sqrtM;
366 BER = 0.5 * erfc (sqrt (0.5 * EbNo));
380 PER = (1.0 - pow (1.0 - BER, (
double) pkt->
GetSize () * 8.0));
401 .SetGroupName (
"Uan")
414 for (uint32_t i =
std::max (
k,n -
k) + 1; i <= n; ++i)
419 for (uint32_t i = 2; i <=
std::min (
k,n -
k); ++i)
431 { 12, 14, 16, 18, 20, 22, 24, 26, 28 };
434 33, 281, 2179, 15035LLU, 105166LLU, 692330LLU, 4580007LLU, 29692894LLU,
439 double ebno = std::pow (10.0, sinr / 10.0);
440 double perror = 1.0 / (2.0 + ebno);
456 for (uint32_t r = 0; r < 9; r++)
459 for (uint32_t
k = 0;
k < d[r];
k++)
461 sumd = sumd +
NChooseK (d[r] - 1 +
k,
k) * std::pow (1 - perror, (
double)
k);
463 P[r] = std::pow (perror, (
double) d[r]) * sumd;
468 for (uint32_t r = 0; r < 8; r++)
470 Pb = Pb + Bd[r] * P[r];
474 uint32_t bits = pkt->
GetSize () * 8;
478 temp *= std::pow ( (1 - Pb), (
double) bits);
480 temp =
NChooseK (288, 1) * Pb * std::pow ( (1 - Pb), bits - 1.0);
508 m_pg = CreateObject<UniformRandomVariable> ();
585 .SetGroupName (
"Uan")
587 .AddAttribute (
"CcaThreshold",
588 "Aggregate energy of incoming signals to move to CCA Busy state dB.",
591 MakeDoubleChecker<double> ())
592 .AddAttribute (
"RxThreshold",
593 "Required SNR for signal acquisition in dB.",
596 MakeDoubleChecker<double> ())
597 .AddAttribute (
"TxPower",
598 "Transmission output power in dB.",
601 MakeDoubleChecker<double> ())
602 .AddAttribute (
"SupportedModes",
603 "List of modes supported by this PHY.",
607 .AddAttribute (
"PerModel",
608 "Functor to calculate PER based on SINR and TxMode.",
611 MakePointerChecker<UanPhyPer> ())
612 .AddAttribute (
"SinrModel",
613 "Functor to calculate SINR based on pkt arrivals and modes.",
616 MakePointerChecker<UanPhyCalcSinr> ())
617 .AddTraceSource (
"RxOk",
618 "A packet was received successfully.",
620 "ns3::UanPhy::TracedCallback")
621 .AddTraceSource (
"RxError",
622 "A packet was received unsuccessfully.",
624 "ns3::UanPhy::TracedCallback")
625 .AddTraceSource (
"Tx",
626 "Packet transmission beginning.",
628 "ns3::UanPhy::TracedCallback")
657 ", stopping rx/tx activities");
679 ", restoring rx/tx activities");
690 NS_LOG_DEBUG (
"Energy depleted, node cannot transmit any packet. Dropping.");
696 NS_LOG_DEBUG (
"PHY requested to TX while already Transmitting. Dropping packet.");
701 NS_LOG_DEBUG (
"PHY requested to TX while sleeping. Dropping packet.");
729 NS_LOG_DEBUG (
"Transmission ended but node sleeping or dead");
758 NS_LOG_DEBUG (
"PHY " <<
m_mac->GetAddress () <<
": rx power after RX gain = " << rxPowerDb <<
" dB re uPa");
763 NS_LOG_DEBUG (
"Energy depleted, node cannot receive any packet. Dropping.");
784 bool hasmode =
false;
785 for (uint32_t i = 0; i <
GetNModes (); i++)
800 NS_LOG_DEBUG (
"PHY " <<
m_mac->GetAddress () <<
": Starting RX in IDLE mode. SINR = " << newsinr);
1065 return m_sinr->CalcSinrDb (pkt, arrTime, rxPowerDb, noiseDb, mode, pdp,
m_transducer->GetArrivalList ());
1074 UanTransducer::ArrivalList::const_iterator it = arrivalList.begin ();
1076 double interfPower = 0;
1078 for (; it != arrivalList.end (); it++)
1080 if (pkt != it->GetPacket ())
1082 interfPower +=
DbToKp (it->GetRxPowerDb ());
1086 return KpToDb (interfPower);
1093 return std::pow (10, db / 10.0);
1098 return 10 * std::log10 (kp);
1104 ListenerList::const_iterator it =
m_listeners.begin ();
1107 (*it)->NotifyRxStart ();
1114 ListenerList::const_iterator it =
m_listeners.begin ();
1117 (*it)->NotifyRxEndOk ();
1123 ListenerList::const_iterator it =
m_listeners.begin ();
1126 (*it)->NotifyRxEndError ();
1132 ListenerList::const_iterator it =
m_listeners.begin ();
1135 (*it)->NotifyCcaStart ();
1141 ListenerList::const_iterator it =
m_listeners.begin ();
1144 (*it)->NotifyCcaEnd ();
1151 ListenerList::const_iterator it =
m_listeners.begin ();
1154 (*it)->NotifyTxStart (duration);
1161 ListenerList::const_iterator it =
m_listeners.begin ();
1164 (*it)->NotifyTxEnd ();
bool IsNull(void) const
Check for null implementation.
void Nullify(void)
Discard the implementation, set it to null.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
virtual void DoDispose(void)
Destructor implementation.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
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 EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now(void)
Return the current simulation virtual time.
Hold variables of type string.
Time GetDelay(void) 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(void) const
Get the number of modes in this list.
void AppendMode(UanTxMode mode)
Add mode to this list.
AttributeValue implementation for UanModesList.
The power delay profile returned by propagation models.
double SumTapsFromMaxNc(Time delay, Time duration) const
Compute the non-coherent sum of tap amplitudes starting after a delay from the maximum amplitude for ...
std::vector< Tap >::const_iterator Iterator
Convenience iterator typedef.
double SumTapsNc(Time begin, Time end) const
Compute the non-coherent sum of tap amplitudes between a start and end time.
Iterator GetBegin(void) const
Get the beginning of the tap vector.
Iterator GetEnd(void) const
Get the end of the tap list (one beyond the last entry).
const Tap & GetTap(uint32_t i) const
Get the Tap at the specified delay index.
Default SINR calculator for UanPhyGen.
UanPhyCalcSinrDefault()
Constructor.
virtual double CalcSinrDb(Ptr< Packet > pkt, Time arrTime, double rxPowerDb, double ambNoiseDb, UanTxMode mode, UanPdp pdp, const UanTransducer::ArrivalList &arrivalList) const
Calculate the SINR value for a packet.
static TypeId GetTypeId(void)
Register this type.
virtual ~UanPhyCalcSinrDefault()
Destructor.
WHOI Micromodem like FH-FSK model.
UanPhyCalcSinrFhFsk()
Constructor.
virtual double CalcSinrDb(Ptr< Packet > pkt, Time arrTime, double rxPowerDb, double ambNoiseDb, UanTxMode mode, UanPdp pdp, const UanTransducer::ArrivalList &arrivalList) const
Calculate the SINR value for a packet.
virtual ~UanPhyCalcSinrFhFsk()
Destructor.
static TypeId GetTypeId(void)
Register this type.
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.
virtual Ptr< UanNetDevice > GetDevice(void) const
Get the device hosting this Phy.
void NotifyListenersRxStart(void)
Call UanListener::NotifyRxStart on all listeners.
double KpToDb(double kp)
Convert kilopascals to dB.
virtual Ptr< UanTransducer > GetTransducer(void)
Get the attached transducer.
Ptr< UanPhyPer > m_per
Error model.
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_rxOkLogger
A packet destined for this Phy was received without error.
virtual uint32_t GetNModes(void)
Get the number of transmission modes supported by this Phy.
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_txLogger
A packet was sent from this Phy.
virtual void SetRxThresholdDb(double thresh)
Set the minimum SINR threshold to receive a packet without errors.
virtual void EnergyRechargeHandler(void)
Handle the energy recharge event.
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_rxErrLogger
A packet destined for this Phy was received with error.
void NotifyListenersTxStart(Time duration)
Call UanListener::NotifyTxStart on all listeners.
virtual bool IsStateRx(void)
Time m_pktRxArrTime
Packet arrival time.
virtual void StartRxPacket(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
Packet arriving from channel: i.e.
virtual void SetSleepMode(bool sleep)
Set the Phy SLEEP mode.
void UpdatePowerConsumption(const State state)
Update energy source with new state.
void NotifyListenersTxEnd(void)
Call UanListener::NotifyTxEnd on all listeners.
ListenerList m_listeners
List of listeners.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
double m_rxRecvPwrDb
Receiver power.
virtual void SetChannel(Ptr< UanChannel > channel)
Attach to a channel.
virtual Ptr< UanChannel > GetChannel(void) const
Get the attached channel.
Ptr< UanPhyCalcSinr > m_sinr
SINR calculator.
Ptr< Packet > m_pktRx
Received packet.
static UanModesList GetDefaultModes(void)
Get the default transmission modes.
virtual ~UanPhyGen()
Dummy destructor, see DoDispose.
DeviceEnergyModel::ChangeStateCallback m_energyCallback
Energy model callback.
Ptr< UanTransducer > m_transducer
Associated transducer.
double m_rxThreshDb
Receive SINR threshold.
EventId m_rxEndEvent
Rx event.
double m_ccaThreshDb
CCA busy threshold.
virtual bool IsStateSleep(void)
virtual void RegisterListener(UanPhyListener *listener)
Register a UanPhyListener to be notified of common UanPhy events.
RxOkCallback m_recOkCb
Callback for packets received without error.
virtual void SendPacket(Ptr< Packet > pkt, uint32_t modeNum)
Send a packet using a specific transmission mode.
virtual void SetDevice(Ptr< UanNetDevice > device)
Set the device hosting this Phy.
Ptr< UanMac > m_mac
MAC layer.
virtual void SetTransducer(Ptr< UanTransducer > trans)
Attach a transducer to 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 NotifyListenersCcaStart(void)
Call UanListener::NotifyCcaStart on all listeners.
static TypeId GetTypeId(void)
Register this type.
Ptr< UniformRandomVariable > m_pg
Provides uniform random variables.
virtual void DoDispose()
Destructor implementation.
virtual void SetTxPowerDb(double txpwr)
Set the transmit power.
EventId m_txEndEvent
Tx event.
virtual void NotifyTransStartTx(Ptr< Packet > packet, double txPowerDb, UanTxMode txMode)
Called when a transmission is beginning on the attached transducer.
virtual void SetReceiveOkCallback(RxOkCallback cb)
Set the callback to be used when a packet is received without error.
bool m_cleared
Flag when we've been cleared.
virtual bool IsStateCcaBusy(void)
virtual void EnergyDepletionHandler(void)
Handle the energy depletion event.
virtual void SetMac(Ptr< UanMac > mac)
Set the MAC forwarding messages to this Phy.
virtual double GetTxPowerDb(void)
Get the current transmit power, in dB.
double m_minRxSinrDb
Minimum receive SINR during packet reception.
void NotifyListenersRxBad(void)
Call UanListener::NotifyRxEndError on all listeners.
Ptr< UanChannel > m_channel
Attached channel.
virtual Ptr< Packet > GetPacketRx(void) const
Get the packet currently being received.
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.
virtual bool IsStateTx(void)
virtual UanTxMode GetMode(uint32_t n)
Get a specific transmission mode.
virtual void SetCcaThresholdDb(double thresh)
Set the threshold for detecting channel busy.
RxErrCallback m_recErrCb
Callback for packets received with errors.
virtual bool IsStateIdle(void)
void RxEndEvent(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode)
Event to process end of packet reception.
virtual double GetCcaThresholdDb(void)
Get the CCA threshold signal strength required to detect channel busy.
Ptr< UanNetDevice > m_device
Device hosting this Phy.
virtual void Clear(void)
Clear all pointer references.
virtual void SetReceiveErrorCallback(RxErrCallback cb)
Set the callback to be used when a packet is received with errors.
Ptr< Packet > m_pktTx
Sent packet.
virtual void SetEnergyModelCallback(DeviceEnergyModel::ChangeStateCallback cb)
Set the DeviceEnergyModel callback for UanPhy device.
void NotifyListenersRxGood(void)
Call UanListener::NotifyRxEndOk on all listeners.
UanPdp m_pktRxPdp
Power delay profile of packet.
virtual double GetRxThresholdDb(void)
Get the minimum received signal strength required to receive a packet without errors.
UanModesList m_modes
List of modes supported by this PHY.
virtual bool IsStateBusy(void)
virtual void NotifyIntChange(void)
Called when there has been a change in the amount of interference this node is experiencing from othe...
void NotifyListenersCcaEnd(void)
Call UanListener::NotifyCcaEnd on all listeners.
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.
virtual ~UanPhyPerCommonModes()
Destructor.
virtual double CalcPer(Ptr< Packet > pkt, double sinrDb, UanTxMode mode)
Calculate the Packet ERror probability based on SINR at the receiver and a tx mode.
static TypeId GetTypeId(void)
Register this type.
UanPhyPerCommonModes()
Constructor.
Default Packet Error Rate calculator for UanPhyGen.
UanPhyPerGenDefault()
Constructor.
static TypeId GetTypeId(void)
Register this type.
virtual double CalcPer(Ptr< Packet > pkt, double sinrDb, UanTxMode mode)
Calculate the packet error probability based on SINR at the receiver and a tx mode.
virtual ~UanPhyPerGenDefault()
Destructor.
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)
static TypeId GetTypeId(void)
Register this type.
virtual double CalcPer(Ptr< Packet > pkt, double sinrDb, UanTxMode mode)
Calculate the packet error probability based on SINR at the receiver and a tx mode.
double NChooseK(uint32_t n, uint32_t k)
Binomial coefficient.
UanPhyPerUmodem()
Constructor.
virtual ~UanPhyPerUmodem()
Destructor.
std::list< UanPacketArrival > ArrivalList
List of arriving packets overlapping in time.
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.
@ QAM
Quadrature amplitude modulation.
@ OTHER
Unspecified/undefined.
@ FSK
Frequency shift keying.
uint32_t GetDataRateBps(void) const
Get the data rate of the transmit mode.
uint32_t GetCenterFreqHz(void) const
Get the transmission center frequency.
uint32_t GetBandwidthHz(void) const
Get the transmission signal bandwidth.
uint32_t GetConstellationSize(void) const
Get the number of constellation points in the modulation scheme.
uint32_t GetPhyRateSps(void) const
Get the physical signaling rate.
uint32_t GetUid(void) const
Get a unique id for the mode.
ModulationType GetModType(void) const
Get the modulation type of the mode.
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 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< const AttributeChecker > MakeUanModesListChecker(void)
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 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.
#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.