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> ())
140 double clearingTime = (
m_hops - 1.0) * ts;
145 double maxTapDelay = 0.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 double tDelta = std::abs (arrTime.
GetSeconds () + maxTapDelay - it->GetArrivalTime ().GetSeconds ());
173 int32_t syms = (uint32_t)( (
double) tDelta / (ts + clearingTime));
174 tDelta = tDelta - syms * (ts + clearingTime);
177 if (arrTime +
Seconds (maxTapDelay) > it->GetArrivalTime ())
179 tDelta = ts + clearingTime - tDelta;
182 double intPower = 0.0;
188 Seconds (2 * ts - tDelta + clearingTime));
199 end = end +
Seconds (ts + clearingTime);
202 intKp +=
DbToKp (it->GetRxPowerDb ()) * intPower;
205 double totalIntDb =
KpToDb (isiUpa + intKp +
DbToKp (ambNoiseDb));
207 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.");
208 return effRxPowerDb - totalIntDb;
226 .SetGroupName (
"Uan")
228 .AddAttribute (
"Threshold",
"SINR cutoff for good packet reception.",
231 MakeDoubleChecker<double> ());
266 static TypeId tid =
TypeId (
"ns3::UanPhyPerCommonModes")
268 .SetGroupName (
"Uan")
279 double EbNo = std::pow (10.0, sinrDb / 10.0);
290 BER = 0.5 * erfc (sqrt (EbNo));
295 BER = 0.5 * erfc (sqrt (0.5 * EbNo));
315 int log2sqrtM = (int) ::std::log2 ( sqrt (M));
317 double log2M = ::std::log2 (M);
324 double sqrtM = ::std::sqrt (M);
326 NS_LOG_DEBUG (
"M=" << M <<
"; log2sqrtM=" << log2sqrtM <<
"; log2M=" << log2M <<
"; sqrtM=" << sqrtM);
331 for (
int k = 0; k < log2sqrtM; k++)
333 int sum_items = (int) ((1.0 - ::std::pow ( 2.0, (-1.0) * (
double) k)) * ::std::sqrt (M) - 1.0);
334 double pow2k = ::std::pow (2.0, (
double) k - 1.0);
336 NS_LOG_DEBUG (
"k=" << k <<
"; sum_items=" << sum_items <<
"; pow2k=" << pow2k);
341 for (
int j = 0; j < sum_items; ++j)
343 PbK += ::std::pow (-1.0, (
double) j * pow2k / sqrtM)
344 * (pow2k - ::std::floor ( (
double) (j * pow2k / sqrtM) - 0.5))
345 * erfc ((2.0 * (
double)j + 1.0) * ::std::sqrt (3.0 * (log2M * EbNo) / (2.0 * (M - 1.0))));
354 NS_LOG_DEBUG (
"k=" << k <<
"; PbK=" << PbK <<
"; BER=" << BER);
357 BER *= 1.0 / (double) log2sqrtM;
367 BER = 0.5 * erfc (sqrt (0.5 * EbNo));
381 PER = (1.0 - pow (1.0 - BER, (
double) pkt->
GetSize () * 8.0));
402 .SetGroupName (
"Uan")
415 for (uint32_t i =
std::max (k,
n - k) + 1; i <=
n; ++i)
420 for (uint32_t i = 2; i <=
std::min (k,
n - k); ++i)
432 { 12, 14, 16, 18, 20, 22, 24, 26, 28 };
435 33, 281, 2179, 15035LLU, 105166LLU, 692330LLU, 4580007LLU, 29692894LLU,
440 double ebno = std::pow (10.0, sinr / 10.0);
441 double perror = 1.0 / (2.0 + ebno);
457 for (uint32_t r = 0; r < 9; r++)
460 for (uint32_t k = 0; k < d[r]; k++)
462 sumd = sumd +
NChooseK (d[r] - 1 + k, k) * std::pow (1 - perror, (
double) k);
464 P[r] = std::pow (perror, (
double) d[r]) * sumd;
469 for (uint32_t r = 0; r < 8; r++)
471 Pb = Pb + Bd[r] * P[r];
475 uint32_t bits = pkt->
GetSize () * 8;
479 temp *= std::pow ( (1 - Pb), (
double) bits);
481 temp =
NChooseK (288, 1) * Pb * std::pow ( (1 - Pb), bits - 1.0);
509 m_pg = CreateObject<UniformRandomVariable> ();
586 .SetGroupName (
"Uan")
588 .AddAttribute (
"CcaThreshold",
589 "Aggregate energy of incoming signals to move to CCA Busy state dB.",
592 MakeDoubleChecker<double> ())
593 .AddAttribute (
"RxThreshold",
594 "Required SNR for signal acquisition in dB.",
597 MakeDoubleChecker<double> ())
598 .AddAttribute (
"TxPower",
599 "Transmission output power in dB.",
602 MakeDoubleChecker<double> ())
603 .AddAttribute (
"SupportedModes",
604 "List of modes supported by this PHY.",
608 .AddAttribute (
"PerModel",
609 "Functor to calculate PER based on SINR and TxMode.",
612 MakePointerChecker<UanPhyPer> ())
613 .AddAttribute (
"SinrModel",
614 "Functor to calculate SINR based on pkt arrivals and modes.",
617 MakePointerChecker<UanPhyCalcSinr> ())
618 .AddTraceSource (
"RxOk",
619 "A packet was received successfully.",
621 "ns3::UanPhy::TracedCallback")
622 .AddTraceSource (
"RxError",
623 "A packet was received unsuccessfully.",
625 "ns3::UanPhy::TracedCallback")
626 .AddTraceSource (
"Tx",
627 "Packet transmission beginning.",
629 "ns3::UanPhy::TracedCallback")
658 ", stopping rx/tx activities");
680 ", restoring rx/tx activities");
691 NS_LOG_DEBUG (
"Energy depleted, node cannot transmit any packet. Dropping.");
697 NS_LOG_DEBUG (
"PHY requested to TX while already Transmitting. Dropping packet.");
702 NS_LOG_DEBUG (
"PHY requested to TX while sleeping. Dropping packet.");
730 NS_LOG_DEBUG (
"Transmission ended but node sleeping or dead");
757 NS_LOG_DEBUG (
"PHY " <<
m_mac->GetAddress () <<
": rx power after RX gain = " << rxPowerDb <<
" dB re uPa");
762 NS_LOG_DEBUG (
"Energy depleted, node cannot receive any packet. Dropping.");
783 bool hasmode =
false;
784 for (uint32_t i = 0; i <
GetNModes (); i++)
799 NS_LOG_DEBUG (
"PHY " <<
m_mac->GetAddress () <<
": Starting RX in IDLE mode. SINR = " << newsinr);
1066 return m_sinr->CalcSinrDb (pkt, arrTime, rxPowerDb, noiseDb, mode, pdp,
m_transducer->GetArrivalList ());
1075 UanTransducer::ArrivalList::const_iterator it = arrivalList.begin ();
1077 double interfPower = 0;
1079 for (; it != arrivalList.end (); it++)
1081 if (pkt != it->GetPacket ())
1083 interfPower +=
DbToKp (it->GetRxPowerDb ());
1087 return KpToDb (interfPower);
1094 return std::pow (10, db / 10.0);
1099 return 10 * std::log10 (kp);
1105 ListenerList::const_iterator it =
m_listeners.begin ();
1108 (*it)->NotifyRxStart ();
1115 ListenerList::const_iterator it =
m_listeners.begin ();
1118 (*it)->NotifyRxEndOk ();
1124 ListenerList::const_iterator it =
m_listeners.begin ();
1127 (*it)->NotifyRxEndError ();
1133 ListenerList::const_iterator it =
m_listeners.begin ();
1136 (*it)->NotifyCcaStart ();
1142 ListenerList::const_iterator it =
m_listeners.begin ();
1145 (*it)->NotifyCcaEnd ();
1152 ListenerList::const_iterator it =
m_listeners.begin ();
1155 (*it)->NotifyTxStart (duration);
virtual void NotifyTransStartTx(Ptr< Packet > packet, double txPowerDb, UanTxMode txMode)
Called when a transmission is beginning on the attached transducer.
virtual bool IsStateBusy(void)
virtual Ptr< UanTransducer > GetTransducer(void)
Get the attached transducer.
double SumTapsNc(Time begin, Time end) const
Compute the non-coherent sum of tap amplitudes between a start and end time.
virtual double GetRxThresholdDb(void)
Get the minimum received signal strength required to receive a packet without errors.
Simulation virtual time values and global simulation resolution.
Ptr< const AttributeChecker > MakeUanModesListChecker(void)
std::vector< Tap >::const_iterator Iterator
Convenience iterator typedef.
virtual bool IsStateRx(void)
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
double KpToDb(double kp)
Convert kilopascals to dB.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Iterator GetBegin(void) const
Get the beginning of the tap vector.
virtual void SetEnergyModelCallback(DeviceEnergyModel::ChangeStateCallback cb)
Set the DeviceEnergyModel callback for UanPhy device.
uint32_t m_hops
Number of hops.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
void NotifyRxDrop(Ptr< const Packet > packet)
Called when the Phy drops a packet.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Ptr< Packet > m_pktTx
Sent packet.
Hold variables of type string.
virtual void SetReceiveErrorCallback(RxErrCallback cb)
Set the callback to be used when a packet is received with errors.
double CalculateSinrDb(Ptr< Packet > pkt, Time arrTime, double rxPowerDb, UanTxMode mode, UanPdp pdp)
Calculate the SINR value for a packet.
virtual void EnergyDepletionHandler(void)
Handle the energy depletion event.
virtual void SetTransducer(Ptr< UanTransducer > trans)
Attach a transducer to this Phy.
Packet error rate calculation for common tx modes based on UanPhyPerUmodem.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
uint32_t GetDataRateBps(void) const
Get the data rate of the transmit mode.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
virtual ~UanPhyGen()
Dummy destructor, see DoDispose.
Ptr< UniformRandomVariable > m_pg
Provides uniform random variables.
Channel is IDLE, no packet is being transmitted.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
double m_rxRecvPwrDb
Receiver power.
Packet error rate calculation assuming WHOI Micromodem-like PHY (FH-FSK)
virtual void SetSleepMode(bool sleep)
Set the Phy SLEEP mode.
#define NS_UNUSED(x)
Mark a local variable as unused.
virtual void StartRxPacket(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
Packet arriving from channel: i.e.
virtual uint32_t GetNModes(void)
Get the number of transmission modes supported by this Phy.
Container for UanTxModes.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
uint32_t GetBandwidthHz(void) const
Get the transmission signal bandwidth.
virtual double GetTxPowerDb(void)
Get the current transmit power, in dB.
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...
virtual double GetCcaThresholdDb(void)
Get the CCA threshold signal strength required to detect channel busy.
virtual void DoDispose(void)
Destructor implementation.
EventId m_rxEndEvent
Rx event.
double m_rxThreshDb
Receive SINR threshold.
uint32_t GetNModes(void) const
Get the number of modes in this list.
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.
void NotifyTxDrop(Ptr< const Packet > packet)
Called when the transducer attempts to transmit a new packet while already transmitting a prior packe...
void NotifyRxEnd(Ptr< const Packet > packet)
Called when a packet is received without error.
EventId m_txEndEvent
Tx event.
static UanTxMode CreateMode(UanTxMode::ModulationType type, uint32_t dataRateBps, uint32_t phyRateSps, uint32_t cfHz, uint32_t bwHz, uint32_t constSize, std::string name)
Ptr< UanPhyPer > m_per
Error model.
virtual void DoDispose()
Destructor implementation.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Time m_pktRxArrTime
Packet arrival time.
bool m_cleared
Flag when we've been cleared.
static TypeId GetTypeId(void)
Register this type.
double NChooseK(uint32_t n, uint32_t k)
Binomial coefficient.
Quadrature amplitude modulation.
WHOI Micromodem like FH-FSK model.
static TypeId GetTypeId(void)
Register this type.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
virtual bool IsStateTx(void)
virtual void SetDevice(Ptr< UanNetDevice > device)
Set the device hosting this Phy.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
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.
virtual ~UanPhyPerUmodem()
Destructor.
Hold an unsigned integer type.
Ptr< UanNetDevice > m_device
Device hosting this Phy.
double m_txPwrDb
Transmit power.
The power delay profile returned by propagation models.
Abstraction of packet modulation information.
double m_thresh
SINR threshold.
Calculate packet error probability, based on received SINR and modulation (mode). ...
DeviceEnergyModel::ChangeStateCallback m_energyCallback
Energy model callback.
uint32_t GetPhyRateSps(void) const
Get the physical signaling rate.
double m_ccaThreshDb
CCA busy threshold.
void NotifyListenersRxGood(void)
Call UanListener::NotifyRxEndOk on all listeners.
void NotifyListenersCcaEnd(void)
Call UanListener::NotifyCcaEnd on all listeners.
std::list< UanPacketArrival > ArrivalList
List of arriving packets overlapping in time.
Ptr< Packet > m_pktRx
Received packet.
double DbToKp(double db) const
Convert dB re 1 uPa to kilopascals.
virtual void SetCcaThresholdDb(double thresh)
Set the threshold for detecting channel busy.
virtual void NotifyIntChange(void)
Called when there has been a change in the amount of interference this node is experiencing from othe...
UanPdp m_pktRxPdp
Power delay profile of packet.
Ptr< UanPhyCalcSinr > m_sinr
SINR calculator.
virtual Ptr< UanChannel > GetChannel(void) const
Get the attached channel.
virtual UanTxMode GetMode(uint32_t n)
Get a specific transmission mode.
virtual void SetRxThresholdDb(double thresh)
Set the minimum SINR threshold to receive a packet without errors.
void NotifyRxBegin(Ptr< const Packet > packet)
Called when the Phy begins to receive a packet.
void TxEndEvent()
Event to process end of packet transmission.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double DbToKp(double db)
Convert dB to kilopascals.
RxOkCallback m_recOkCb
Callback for packets received without error.
UanModesList m_modes
List of modes supported by this PHY.
Interface for PHY event listener.
static TypeId GetTypeId(void)
Register this type.
void UpdatePowerConsumption(const State state)
Update energy source with new state.
const Tap & GetTap(uint32_t i) const
Get the Tap at the specified delay index.
void NotifyListenersRxStart(void)
Call UanListener::NotifyRxStart on all listeners.
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 ~UanPhyCalcSinrFhFsk()
Destructor.
void RxEndEvent(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode)
Event to process end of packet reception.
static Time Now(void)
Return the current simulation virtual time.
virtual void SetChannel(Ptr< UanChannel > channel)
Attach to a channel.
Default SINR calculator for UanPhyGen.
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.
Class used for calculating SINR of packet in UanPhy.
Ptr< UanMac > m_mac
MAC layer.
Base class for UAN Phy models.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
uint32_t GetCenterFreqHz(void) const
Get the transmission center frequency.
virtual ~UanPhyPerGenDefault()
Destructor.
double KpToDb(double kp) const
Convert kilopascals to dB re 1 uPa.
UanPhyCalcSinrFhFsk()
Constructor.
uint32_t GetUid(void) const
Get a unique id for the mode.
Time GetDelay(void) const
Get the delay time, usually from first arrival of signal.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_txLogger
A packet was sent from this Phy.
virtual bool IsStateIdle(void)
RxErrCallback m_recErrCb
Callback for packets received with errors.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
static TypeId GetTypeId(void)
Register this type.
Ptr< UanChannel > m_channel
Attached channel.
void NotifyListenersCcaStart(void)
Call UanListener::NotifyCcaStart on all listeners.
Time Seconds(double value)
Construct a Time in the indicated unit.
void AppendMode(UanTxMode mode)
Add mode to this list.
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
double GetInterferenceDb(Ptr< Packet > pkt)
Calculate interference power from overlapping packet arrivals, in dB.
virtual Ptr< UanNetDevice > GetDevice(void) const
Get the device hosting this Phy.
static TypeId GetTypeId(void)
Register this type.
void NotifyListenersRxBad(void)
Call UanListener::NotifyRxEndError on all listeners.
Ptr< UanTransducer > m_transducer
Associated transducer.
void Nullify(void)
Discard the implementation, set it to null.
UanPhyPerUmodem()
Constructor.
UanPhyPerGenDefault()
Constructor.
Ptr< const AttributeAccessor > MakeUanModesListAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
static TypeId GetTypeId(void)
Register this type.
virtual ~UanPhyPerCommonModes()
Destructor.
virtual Ptr< Packet > GetPacketRx(void) const
Get the packet currently being received.
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 ~UanPhyCalcSinrDefault()
Destructor.
Iterator GetEnd(void) const
Get the end of the tap list (one beyond the last entry).
virtual void SendPacket(Ptr< Packet > pkt, uint32_t modeNum)
Send a packet using a specific transmission mode.
Default Packet Error Rate calculator for UanPhyGen.
double SumTapsFromMaxNc(Time delay, Time duration) const
Compute the non-coherent sum of tap amplitudes starting after a delay from the maximum amplitude for ...
UanTxMode m_pktRxMode
Packet transmission mode at receiver.
ListenerList m_listeners
List of listeners.
virtual bool IsStateCcaBusy(void)
virtual void RegisterListener(UanPhyListener *listener)
Register a UanPhyListener to be notified of common UanPhy events.
bool IsNull(void) const
Check for null implementation.
double m_minRxSinrDb
Minimum receive SINR during packet reception.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
virtual bool IsStateSleep(void)
virtual void SetMac(Ptr< UanMac > mac)
Set the MAC forwarding messages to this Phy.
virtual void SetReceiveOkCallback(RxOkCallback cb)
Set the callback to be used when a packet is received without error.
UanPhyPerCommonModes()
Constructor.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
static UanModesList GetDefaultModes(void)
Get the default transmission modes.
a unique identifier for an interface.
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.
uint32_t GetConstellationSize(void) const
Get the number of constellation points in the modulation scheme.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
virtual void Clear(void)
Clear all pointer references.
UanPhyCalcSinrDefault()
Constructor.
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_rxOkLogger
A packet destined for this Phy was received without error.
void NotifyListenersTxStart(Time duration)
Call UanListener::NotifyTxStart on all listeners.
AttributeValue implementation for UanModesList.
virtual void SetTxPowerDb(double txpwr)
Set the transmit power.
ModulationType GetModType(void) const
Get the modulation type of the mode.