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