A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
uan-phy-gen.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Leonard Tracy <lentracy@gmail.com>
7 * Andrea Sacco <andrea.sacco85@gmail.com>
8 */
9
10#ifndef UAN_PHY_GEN_H
11#define UAN_PHY_GEN_H
12
13#include "uan-phy.h"
14
15#include "ns3/device-energy-model.h"
16#include "ns3/event-id.h"
17#include "ns3/nstime.h"
18#include "ns3/random-variable-stream.h"
19#include "ns3/traced-callback.h"
20
21#include <list>
22
23namespace ns3
24{
25
26/**
27 * \ingroup uan
28 *
29 * Default Packet Error Rate calculator for UanPhyGen
30 *
31 * Considers no error if SINR is > user defined threshold
32 * (configured by an attribute).
33 */
35{
36 public:
37 /** Constructor */
39 /** Destructor */
40 ~UanPhyPerGenDefault() override;
41
42 /**
43 * Register this type.
44 * \return The TypeId.
45 */
46 static TypeId GetTypeId();
47
48 double CalcPer(Ptr<Packet> pkt, double sinrDb, UanTxMode mode) override;
49
50 private:
51 double m_thresh; //!< SINR threshold.
52
53}; // class UanPhyPerGenDefault
54
55/**
56 * \ingroup uan
57 *
58 * Packet error rate calculation assuming WHOI Micromodem-like PHY (FH-FSK)
59 *
60 * Calculates PER assuming rate 1/2 convolutional code with
61 * constraint length 9 with soft decision viterbi decoding and
62 * a CRC capable of correcting 1 bit error.
63 */
65{
66 public:
67 /** Constructor */
69 /** Destructor */
70 ~UanPhyPerUmodem() override;
71
72 /**
73 * Register this type.
74 * \return The TypeId.
75 */
76 static TypeId GetTypeId();
77
78 /**
79 * Calculate the packet error probability based on
80 * SINR at the receiver and a tx mode.
81 *
82 * This implementation uses calculations
83 * for binary FSK modulation coded by a rate 1/2 convolutional code
84 * with constraint length = 9 and a viterbi decoder and finally a CRC capable
85 * of correcting one bit error. These equations can be found in
86 * the book, Digital Communications, by Proakis (any version I think).
87 *
88 * \param pkt Packet which is under consideration.
89 * \param sinrDb SINR at receiver.
90 * \param mode TX mode used to transmit packet.
91 * \return Probability of packet error.
92 */
93 double CalcPer(Ptr<Packet> pkt, double sinrDb, UanTxMode mode) override;
94
95 private:
96 /**
97 * Binomial coefficient
98 *
99 * \param n Pool size.
100 * \param k Number of draws.
101 * \return Binomial coefficient n choose k.
102 */
103 double NChooseK(uint32_t n, uint32_t k);
104
105}; // class UanPhyPerUmodem
106
107/**
108 * \ingroup uan
109 *
110 * Packet error rate calculation for common tx modes based on UanPhyPerUmodem
111 *
112 * Calculates PER for common UanTxMode modulations, by deriving
113 * PER from the BER taken from well known literature's formulas.
114 */
116{
117 public:
118 /** Constructor */
120 /** Destructor */
121 ~UanPhyPerCommonModes() override;
122
123 /**
124 * Register this type.
125 * \return The TypeId.
126 */
127 static TypeId GetTypeId();
128
129 /**
130 * Calculate the Packet ERror probability based on
131 * SINR at the receiver and a tx mode.
132 *
133 * This implementation calculates PER for common UanTxMode modulations,
134 * by deriving PER from the BER taken from literature's formulas.
135 *
136 * \param pkt Packet which is under consideration.
137 * \param sinrDb SINR at receiver.
138 * \param mode TX mode used to transmit packet.
139 * \return Probability of packet error.
140 */
141 double CalcPer(Ptr<Packet> pkt, double sinrDb, UanTxMode mode) override;
142
143}; // class UanPhyPerCommonModes
144
145/**
146 * \ingroup uan
147 *
148 * Default SINR calculator for UanPhyGen.
149 *
150 * The default ignores mode data and assumes that all rxpower transmitted is
151 * captured by the receiver, and that all signal power associated with
152 * interfering packets affects SINR identically to additional ambient noise.
153 */
155{
156 public:
157 /** Constructor */
159 /** Destructor */
160 ~UanPhyCalcSinrDefault() override;
161
162 /**
163 * Register this type.
164 * \return The TypeId.
165 */
166 static TypeId GetTypeId();
167
168 /**
169 * Calculate the SINR value for a packet.
170 *
171 * This implementation simply adds all arriving signal power
172 * and assumes it acts identically to additional noise.
173 *
174 * \param pkt Packet to calculate SINR for.
175 * \param arrTime Arrival time of pkt.
176 * \param rxPowerDb The received signal strength of the packet in dB re 1 uPa.
177 * \param ambNoiseDb Ambient channel noise in dB re 1 uPa.
178 * \param mode TX Mode of pkt.
179 * \param pdp Power delay profile of pkt.
180 * \param arrivalList List of interfering arrivals given from Transducer.
181 * \return The SINR in dB re 1 uPa.
182 */
183 double CalcSinrDb(Ptr<Packet> pkt,
184 Time arrTime,
185 double rxPowerDb,
186 double ambNoiseDb,
187 UanTxMode mode,
188 UanPdp pdp,
189 const UanTransducer::ArrivalList& arrivalList) const override;
190
191}; // class UanPhyCalcSinrDefault
192
193/**
194 * \ingroup uan
195 *
196 * WHOI Micromodem like FH-FSK model.
197 *
198 * Model of interference calculation for FH-FSK wherein all nodes
199 * use an identical hopping pattern. In this case, there is an (M-1)*SymbolTime
200 * clearing time between symbols transmitted on the same frequency.
201 * This clearing time combats ISI from channel delay spread and also has
202 * a byproduct of possibly reducing interference from other transmitted packets.
203 *
204 * Thanks to Randall Plate for the latest model revision based on the following
205 * papers:
206 * <ul>
207 * <li>Parrish, "System Design Considerations for Undersea Networks: Link and Multiple Access
208 * Protocols" <li>Siderius, "Effects of Ocean Thermocline Variability on Noncoherent Underwater
209 * Acoustic Communications" <li>Rao, "Channel Coding Techniques for Wireless Communications", ch 2
210 * </ul>
211 */
213{
214 public:
215 /** Constructor */
217 /** Destructor */
218 ~UanPhyCalcSinrFhFsk() override;
219
220 /**
221 * Register this type.
222 * \return The TypeId.
223 */
224 static TypeId GetTypeId();
225
226 double CalcSinrDb(Ptr<Packet> pkt,
227 Time arrTime,
228 double rxPowerDb,
229 double ambNoiseDb,
230 UanTxMode mode,
231 UanPdp pdp,
232 const UanTransducer::ArrivalList& arrivalList) const override;
233
234 private:
235 uint32_t m_hops; //!< Number of hops.
236
237}; // class UanPhyCalcSinrFhFsk
238
239/**
240 * \ingroup uan
241 *
242 * Generic PHY model.
243 *
244 * This is a generic PHY class. SINR and PER information
245 * are controlled via attributes. By adapting the SINR
246 * and PER models to a specific situation, this PHY should
247 * be able to model a wide variety of networks.
248 */
249class UanPhyGen : public UanPhy
250{
251 public:
252 /** Constructor */
253 UanPhyGen();
254 /** Dummy destructor, see DoDispose */
255 ~UanPhyGen() override;
256 /**
257 * Get the default transmission modes.
258 *
259 * \return The default mode list.
260 */
262
263 /**
264 * Register this type.
265 * \return The TypeId.
266 */
267 static TypeId GetTypeId();
268
269 // Inherited methods
271 void EnergyDepletionHandler() override;
272 void EnergyRechargeHandler() override;
273 void SendPacket(Ptr<Packet> pkt, uint32_t modeNum) override;
274 void RegisterListener(UanPhyListener* listener) override;
275 void StartRxPacket(Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp) override;
276 void SetReceiveOkCallback(RxOkCallback cb) override;
277 void SetReceiveErrorCallback(RxErrCallback cb) override;
278 bool IsStateSleep() override;
279 bool IsStateIdle() override;
280 bool IsStateBusy() override;
281 bool IsStateRx() override;
282 bool IsStateTx() override;
283 bool IsStateCcaBusy() override;
284 void SetTxPowerDb(double txpwr) override;
285 void SetRxThresholdDb(double thresh) override;
286 void SetCcaThresholdDb(double thresh) override;
287 double GetTxPowerDb() override;
288 double GetRxThresholdDb() override;
289 double GetCcaThresholdDb() override;
290 Ptr<UanChannel> GetChannel() const override;
291 Ptr<UanNetDevice> GetDevice() const override;
293 void SetChannel(Ptr<UanChannel> channel) override;
294 void SetDevice(Ptr<UanNetDevice> device) override;
295 void SetMac(Ptr<UanMac> mac) override;
296 void SetTransducer(Ptr<UanTransducer> trans) override;
297 void NotifyTransStartTx(Ptr<Packet> packet, double txPowerDb, UanTxMode txMode) override;
298 void NotifyIntChange() override;
299 uint32_t GetNModes() override;
300 UanTxMode GetMode(uint32_t n) override;
301 Ptr<Packet> GetPacketRx() const override;
302 void Clear() override;
303 void SetSleepMode(bool sleep) override;
304 int64_t AssignStreams(int64_t stream) override;
305
306 private:
307 /** List of Phy Listeners. */
308 typedef std::list<UanPhyListener*> ListenerList;
309
310 UanModesList m_modes; //!< List of modes supported by this PHY.
311
312 State m_state; //!< Phy state.
313 ListenerList m_listeners; //!< List of listeners.
314 RxOkCallback m_recOkCb; //!< Callback for packets received without error.
315 RxErrCallback m_recErrCb; //!< Callback for packets received with errors.
316 Ptr<UanChannel> m_channel; //!< Attached channel.
317 Ptr<UanTransducer> m_transducer; //!< Associated transducer.
318 Ptr<UanNetDevice> m_device; //!< Device hosting this Phy.
319 Ptr<UanMac> m_mac; //!< MAC layer.
320 Ptr<UanPhyPer> m_per; //!< Error model.
321 Ptr<UanPhyCalcSinr> m_sinr; //!< SINR calculator.
322
323 double m_txPwrDb; //!< Transmit power.
324 double m_rxThreshDb; //!< Receive SINR threshold.
325 double m_ccaThreshDb; //!< CCA busy threshold.
326
327 Ptr<Packet> m_pktRx; //!< Received packet.
328 Ptr<Packet> m_pktTx; //!< Sent packet.
329 double m_minRxSinrDb; //!< Minimum receive SINR during packet reception.
330 double m_rxRecvPwrDb; //!< Receiver power.
331 Time m_pktRxArrTime; //!< Packet arrival time.
332 UanPdp m_pktRxPdp; //!< Power delay profile of packet.
333 UanTxMode m_pktRxMode; //!< Packet transmission mode at receiver.
334
335 bool m_cleared; //!< Flag when we've been cleared.
336
337 EventId m_txEndEvent; //!< Tx event
338 EventId m_rxEndEvent; //!< Rx event
339
340 /** Provides uniform random variables. */
342
343 /** Energy model callback. */
345 /** A packet destined for this Phy was received without error. */
347 /** A packet destined for this Phy was received with error. */
349 /** A packet was sent from this Phy. */
351
352 /**
353 * Calculate the SINR value for a packet.
354 *
355 * \param pkt Packet to calculate SINR for.
356 * \param arrTime Arrival time of pkt.
357 * \param rxPowerDb The received signal strength of the packet in dB re 1 uPa.
358 * \param mode TX Mode of pkt.
359 * \param pdp Power delay profile of pkt.
360 * \return The SINR in dB re 1 uPa.
361 */
362 double CalculateSinrDb(Ptr<Packet> pkt,
363 Time arrTime,
364 double rxPowerDb,
365 UanTxMode mode,
366 UanPdp pdp);
367
368 /**
369 * Calculate interference power from overlapping packet arrivals, in dB.
370 *
371 * The "signal" packet power is excluded. Use
372 * GetInterferenceDb ( (Ptr<Packet>) 0) to treat all signals as
373 * interference, for instance in calculating the CCA busy.
374 *
375 * \param pkt The arriving (signal) packet.
376 * \return The total interference power, in dB.
377 */
378 double GetInterferenceDb(Ptr<Packet> pkt);
379 /**
380 * Convert dB to kilopascals.
381 *
382 * \f[{\rm{kPa}} = {10^{\frac{{{\rm{dB}}}}{{10}}}}\f]
383 *
384 * \param db Signal level in dB.
385 * \return Sound pressure in kPa.
386 */
387 double DbToKp(double db);
388 /**
389 * Convert kilopascals to dB.
390 *
391 * \f[{\rm{dB}} = 10{\log _{10}}{\rm{kPa}}\f]
392 *
393 * \param kp Sound pressure in kPa.
394 * \return Signal level in dB.
395 */
396 double KpToDb(double kp);
397 /**
398 * Event to process end of packet reception.
399 *
400 * \param pkt The packet.
401 * \param rxPowerDb Received signal power.
402 * \param txMode Transmission mode.
403 */
404 void RxEndEvent(Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode);
405 /** Event to process end of packet transmission. */
406 void TxEndEvent();
407 /**
408 * Update energy source with new state.
409 *
410 * \param state The new Phy state.
411 */
412 void UpdatePowerConsumption(const State state);
413
414 /** Call UanListener::NotifyRxStart on all listeners. */
416 /** Call UanListener::NotifyRxEndOk on all listeners. */
418 /** Call UanListener::NotifyRxEndError on all listeners. */
420 /** Call UanListener::NotifyCcaStart on all listeners. */
422 /** Call UanListener::NotifyCcaEnd on all listeners. */
424 /**
425 * Call UanListener::NotifyTxStart on all listeners.
426 *
427 * \param duration Duration of transmission.
428 */
429 void NotifyListenersTxStart(Time duration);
430 /**
431 * Call UanListener::NotifyTxEnd on all listeners.
432 */
434
435 protected:
436 void DoDispose() override;
437
438}; // class UanPhyGen
439
440} // namespace ns3
441
442#endif /* UAN_PHY_GEN_H */
An identifier for simulation events.
Definition event-id.h:45
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:48
Container for UanTxModes.
The power delay profile returned by propagation models.
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.
Definition uan-phy.h:33
Generic PHY model.
std::list< UanPhyListener * > ListenerList
List of Phy Listeners.
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.
UanPhyGen()
Constructor.
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.
State m_state
Phy state.
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.
Definition uan-phy.h:167
State
Enum defining possible Phy states.
Definition uan-phy.h:171
Interface for PHY event listener.
Definition uan-phy.h:134
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.
Definition uan-phy-gen.h:35
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.
Definition uan-phy-gen.h:51
Calculate packet error probability, based on received SINR and modulation (mode).
Definition uan-phy.h:99
Packet error rate calculation assuming WHOI Micromodem-like PHY (FH-FSK)
Definition uan-phy-gen.h:65
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.
std::list< UanPacketArrival > ArrivalList
List of arriving packets overlapping in time.
Abstraction of packet modulation information.
Definition uan-tx-mode.h:32
Every class exported by the ns3 library is enclosed in the ns3 namespace.