26 #include "ns3/simulator.h"
27 #include "ns3/traced-callback.h"
29 #include "ns3/trace-source-accessor.h"
30 #include "ns3/double.h"
32 #include "ns3/uan-tx-mode.h"
34 #include "ns3/uinteger.h"
35 #include "ns3/energy-source-container.h"
36 #include "ns3/acoustic-modem-energy-model.h"
68 static TypeId tid =
TypeId (
"ns3::UanPhyCalcSinrDefault")
70 .AddConstructor<UanPhyCalcSinrDefault> ()
86 NS_LOG_WARN (
"Calculating SINR for unsupported modulation type");
89 double intKp = -
DbToKp (rxPowerDb);
90 UanTransducer::ArrivalList::const_iterator it = arrivalList.begin ();
91 for (; it != arrivalList.end (); it++)
93 intKp +=
DbToKp (it->GetRxPowerDb ());
96 double totalIntDb =
KpToDb (intKp +
DbToKp (ambNoiseDb));
98 NS_LOG_DEBUG (
"Calculating SINR: RxPower = " << rxPowerDb <<
" dB. Number of interferers = " << arrivalList.size () <<
" Interference + noise power = " << totalIntDb <<
" dB. SINR = " << rxPowerDb - totalIntDb <<
" dB.");
99 return rxPowerDb - totalIntDb;
117 .AddConstructor<UanPhyCalcSinrFhFsk> ()
118 .AddAttribute (
"NumberOfHops",
119 "Number of frequencies in hopping pattern.",
122 MakeUintegerChecker<uint32_t> ())
137 NS_LOG_WARN (
"Calculating SINR for unsupported mode type");
143 double clearingTime = (
m_hops - 1.0) * ts;
148 double maxTapDelay = 0.0;
150 for (; pit != pdp.
GetEnd (); pit++)
152 if (std::abs (pit->GetAmp ()) > maxAmp)
154 maxAmp = std::abs (pit->GetAmp ());
155 maxTapDelay = pit->GetDelay ().GetSeconds ();
160 double effRxPowerDb = rxPowerDb +
KpToDb (csp);
162 double isiUpa = rxPowerDb * pdp.
SumTapsFromMaxNc (Seconds (ts + clearingTime), Seconds (ts));
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;
185 intPower += intPdp.
SumTapsNc (Seconds (0), Seconds (ts - tDelta));
186 intPower += intPdp.
SumTapsNc (Seconds (ts - tDelta + clearingTime),
187 Seconds (2 * ts - tDelta + clearingTime));
191 Time start = Seconds (ts + clearingTime - tDelta);
192 Time end = start + Seconds (ts);
193 intPower += intPdp.
SumTapsNc (start, end);
195 start = start + Seconds (ts + clearingTime);
196 end = start + Seconds (ts);
197 intPower += intPdp.
SumTapsNc (start, end);
199 intKp +=
DbToKp (it->GetRxPowerDb ()) * intPower;
202 double totalIntDb =
KpToDb (isiUpa + intKp +
DbToKp (ambNoiseDb));
204 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.");
205 return effRxPowerDb - totalIntDb;
223 .AddConstructor<UanPhyPerGenDefault> ()
224 .AddAttribute (
"Threshold",
"SINR cutoff for good packet reception.",
227 MakeDoubleChecker<double> ());
261 .AddConstructor<UanPhyPerUmodem> ()
273 for (uint32_t i = std::max (k,n - k) + 1; i <= n; ++i)
278 for (uint32_t i = 2; i <= std::min (k,n - k); ++i)
290 { 12, 14, 16, 18, 20, 22, 24, 26, 28 };
293 33, 281, 2179, 15035LLU, 105166LLU, 692330LLU, 4580007LLU, 29692894LLU,
298 double ebno = std::pow (10.0, sinr / 10.0);
299 double perror = 1.0 / (2.0 + ebno);
311 for (uint32_t r = 0; r < 9; r++)
314 for (uint32_t k = 0; k < d[r]; k++)
316 sumd = sumd +
NChooseK (d[r] - 1 + k, k) * std::pow (1 - perror, (
double) k);
318 P[r] = std::pow (perror, (
double) d[r]) * sumd;
323 for (uint32_t r = 0; r < 8; r++)
325 Pb = Pb + Bd[r] * P[r];
329 uint32_t bits = pkt->
GetSize () * 8;
333 temp *= std::pow ( (1 - Pb), (
double) bits);
335 temp =
NChooseK (288, 1) * Pb * std::pow ( (1 - Pb), bits - 1.0);
364 m_pg = CreateObject<UniformRandomVariable> ();
438 .AddConstructor<UanPhyGen> ()
439 .AddAttribute (
"CcaThreshold",
440 "Aggregate energy of incoming signals to move to CCA Busy state dB.",
443 MakeDoubleChecker<double> ())
444 .AddAttribute (
"RxThreshold",
445 "Required SNR for signal acquisition in dB.",
448 MakeDoubleChecker<double> ())
449 .AddAttribute (
"TxPower",
450 "Transmission output power in dB.",
453 MakeDoubleChecker<double> ())
454 .AddAttribute (
"RxGain",
455 "Gain added to incoming signal at receiver.",
458 MakeDoubleChecker<double> ())
459 .AddAttribute (
"SupportedModes",
460 "List of modes supported by this PHY.",
463 MakeUanModesListChecker () )
464 .AddAttribute (
"PerModel",
465 "Functor to calculate PER based on SINR and TxMode.",
468 MakePointerChecker<UanPhyPer> ())
469 .AddAttribute (
"SinrModel",
470 "Functor to calculate SINR based on pkt arrivals and modes.",
473 MakePointerChecker<UanPhyCalcSinr> ())
474 .AddTraceSource (
"RxOk",
475 "A packet was received successfully.",
477 .AddTraceSource (
"RxError",
478 "A packet was received unsuccessfully.",
480 .AddTraceSource (
"Tx",
481 "Packet transmission beginning.",
511 ", stopping rx/tx activities");
522 NS_LOG_DEBUG (
"Energy depleted, node cannot transmit any packet. Dropping.");
528 NS_LOG_DEBUG (
"PHY requested to TX while already Transmitting. Dropping packet.");
533 NS_LOG_DEBUG (
"PHY requested to TX while sleeping. Dropping packet.");
560 NS_LOG_DEBUG (
"Transmission ended but node sleeping or dead");
589 NS_LOG_DEBUG (
"Energy depleted, node cannot receive any packet. Dropping.");
614 bool hasmode =
false;
615 for (uint32_t i = 0; i <
GetNModes (); i++)
630 NS_LOG_DEBUG (
"PHY " <<
m_mac->GetAddress () <<
": Starting RX in IDLE mode. SINR = " << newsinr);
904 return m_sinr->CalcSinrDb (pkt, arrTime, rxPowerDb, noiseDb, mode, pdp,
m_transducer->GetArrivalList ());
913 UanTransducer::ArrivalList::const_iterator it = arrivalList.begin ();
915 double interfPower = 0;
917 for (; it != arrivalList.end (); it++)
919 if (pkt != it->GetPacket ())
921 interfPower +=
DbToKp (it->GetRxPowerDb ());
925 return KpToDb (interfPower);
932 return std::pow (10, db / 10.0);
937 return 10 * std::log10 (kp);
943 ListenerList::const_iterator it =
m_listeners.begin ();
946 (*it)->NotifyRxStart ();
953 ListenerList::const_iterator it =
m_listeners.begin ();
956 (*it)->NotifyRxEndOk ();
962 ListenerList::const_iterator it =
m_listeners.begin ();
965 (*it)->NotifyRxEndError ();
971 ListenerList::const_iterator it =
m_listeners.begin ();
974 (*it)->NotifyCcaStart ();
980 ListenerList::const_iterator it =
m_listeners.begin ();
983 (*it)->NotifyCcaEnd ();
990 ListenerList::const_iterator it =
m_listeners.begin ();
993 (*it)->NotifyTxStart (duration);
virtual void NotifyTransStartTx(Ptr< Packet > packet, double txPowerDb, UanTxMode txMode)
Called when a transmission is beginning on the attched transducer.
virtual bool IsStateBusy(void)
virtual Ptr< UanTransducer > GetTransducer(void)
Get the attached transducer.
virtual double GetRxThresholdDb(void)
Get the minimum received signal strength required to receive a packet without errors.
keep track of time values and allow control of global simulation resolution
uint32_t GetNModes(void) const
Get the number of modes in this list.
std::vector< Tap >::const_iterator Iterator
Convenience iterator typedef.
virtual bool IsStateRx(void)
#define NS_LOG_FUNCTION(parameters)
double KpToDb(double kp)
Convert kilopascals to dB.
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
virtual void SetEnergyModelCallback(DeviceEnergyModel::ChangeStateCallback cb)
Set the DeviceEnergyModel callback for UanPhy device.
uint32_t m_hops
Number of hops.
void NotifyRxDrop(Ptr< const Packet > packet)
Called when the Phy drops a packet.
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.
bool IsNull(void) const
Check for null implementation.
#define NS_ASSERT(condition)
virtual ~UanPhyGen()
Dummy destructor, see DoDispose.
Ptr< UniformRandomVariable > m_pg
Provides uniform random variables.
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
Channel is IDLE, no packet is being transmitted.
double m_rxRecvPwrDb
Receiver power.
double SumTapsFromMaxNc(Time delay, Time duration) const
Compute the non-coherent sum of tap amplitudes starting after a delay from the maximum amplitude for ...
uint32_t GetSize(void) const
virtual void SetSleepMode(bool sleep)
Set the Phy SLEEP mode.
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.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Container for UanTxModes.
virtual double GetTxPowerDb(void)
Get the current transmit power, in dB.
virtual double GetCcaThresholdDb(void)
Get the CCA threshold signal strength required to detect channel busy.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
ModulationType GetModType(void) const
Get the modulation type of the mode.
double m_rxThreshDb
Receive SINR threshold.
void NotifyRxEnd(Ptr< const Packet > packet)
Called when a packet is received without error.
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()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Time m_pktRxArrTime
Packet arrival time.
NS_LOG_COMPONENT_DEFINE("UanPhyGen")
bool m_cleared
Flag when we've been cleared.
TracedCallback< Ptr< const Packet >, double, UanTxMode > m_txLogger
A packet was sent from this Phy.
double GetSeconds(void) const
static TypeId GetTypeId(void)
Register this type.
double NChooseK(uint32_t n, uint32_t k)
Binomial coefficient.
static TypeId GetTypeId(void)
Register this type.
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 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...
double m_rxGainDb
Receive gain.
uint32_t GetDataRateBps(void) const
Get the data rate of the transmit mode.
virtual ~UanPhyPerUmodem()
Destructor.
Hold an unsigned integer type.
double KpToDb(double kp) const
Convert kilopascals to dB re 1 uPa.
Ptr< UanNetDevice > m_device
Device hosting this Phy.
virtual Ptr< Packet > GetPacketRx(void) const
Get the packet currently being received.
double m_txPwrDb
Transmit power.
The power delay profile returned by propagation models.
Abstraction of packet modulation information.
double m_thresh
SINR threshold.
DeviceEnergyModel::ChangeStateCallback m_energyCallback
Energy model callback.
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.
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 ammount of interference this node is experiencing from oth...
UanPdp m_pktRxPdp
Power delay profile of pakket.
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 Ptr< UanChannel > GetChannel(void) const
Get the attached channel.
Ptr< UanPhyCalcSinr > m_sinr
SINR calculator.
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.
double DbToKp(double db)
Convert dB to kilopascals.
virtual void SetRxGainDb(double gain)
Set the receiver gain.
RxOkCallback m_recOkCb
Callback for packets received without error.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
UanModesList m_modes
List of modes supported by this PHY.
uint32_t GetCenterFreqHz(void) const
Get the transmission center frequency.
Interface for PHY event listener.
static TypeId GetTypeId(void)
Register this type.
void UpdatePowerConsumption(const State state)
Update energy source with new state.
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.
double DbToKp(double db) const
Convert dB re 1 uPa to kilopascals.
TracedCallback< Ptr< const Packet >, double, UanTxMode > m_rxOkLogger
A packet destined for this Phy was received without error.
static Time Now(void)
Return the "current simulation time".
virtual void SetChannel(Ptr< UanChannel > channel)
Attach to a channel.
Ptr< UanMac > m_mac
MAC layer.
Iterator GetEnd(void) const
Get the end of the tap list (one beyond the last entry).
Base class for UAN Phy models.
uint32_t GetPhyRateSps(void) const
Get the physical signaling rate.
TracedCallback< Ptr< const Packet >, double, UanTxMode > m_rxErrLogger
A packet destined for this Phy was received with error.
virtual ~UanPhyPerGenDefault()
Destructor.
UanPhyCalcSinrFhFsk()
Constructor.
bool m_disabled
Energy depleted.
virtual bool IsStateIdle(void)
RxErrCallback m_recErrCb
Callback for packets received with errors.
#define NS_LOG_DEBUG(msg)
static TypeId GetTypeId(void)
Register this type.
Ptr< UanChannel > m_channel
Attached channel.
void NotifyListenersCcaStart(void)
Call UanListener::NotifyCcaStart on all listeners.
void AppendMode(UanTxMode mode)
Add mode to this list.
double GetInterferenceDb(Ptr< Packet > pkt)
Calculate interference power from overlapping packet arrivals, in dB.
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.
static TypeId GetTypeId(void)
Register this type.
virtual ~UanPhyCalcSinrDefault()
Destructor.
a base class which provides memory management and object aggregation
uint32_t GetBandwidthHz(void) const
Get the transmission signal bandwidth.
virtual void SendPacket(Ptr< Packet > pkt, uint32_t modeNum)
Send a packet using a specific transmission mode.
Iterator GetBegin(void) const
Get the beginning of the tap vector.
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.
virtual double GetRxGainDb(void)
Get the receiver gain added to signal at receiver in dB.
double m_minRxSinrDb
Minimum receive SINR during packet reception.
Hold a floating point type.
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.
uint32_t GetUid(void) const
Get a unique id for the mode.
double SumTapsNc(Time begin, Time end) const
Compute the non-coherent sum of tap amplitudes between a start and end time.
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.
virtual Ptr< UanNetDevice > GetDevice(void)
Get the device hosting this Phy.
TypeId SetParent(TypeId tid)
virtual void Clear(void)
Clear all pointer references.
UanPhyCalcSinrDefault()
Constructor.
void NotifyListenersTxStart(Time duration)
Call UanListener::NotifyTxStart on all listeners.
Attribute Value class for UanTxModes.
virtual void SetTxPowerDb(double txpwr)
Set the transmit power.