A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
uan-phy.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_H
11#define UAN_PHY_H
12
13#include "uan-mac.h"
14#include "uan-prop-model.h"
15#include "uan-transducer.h"
16#include "uan-tx-mode.h"
17
18#include "ns3/device-energy-model.h"
19#include "ns3/object.h"
20
21namespace ns3
22{
23
24/**
25 * @ingroup uan
26 *
27 * Class used for calculating SINR of packet in UanPhy.
28 *
29 * Can be set to any derived class using attributes of UanPhy
30 * to implement different models.
31 */
32class UanPhyCalcSinr : public Object
33{
34 public:
35 /**
36 * Calculate the SINR value for a packet.
37 *
38 * @param pkt Packet to calculate SINR for.
39 * @param arrTime Arrival time of pkt.
40 * @param rxPowerDb The received signal strength of the packet in dB re 1 uPa.
41 * @param ambNoiseDb Ambient channel noise in dB re 1 uPa.
42 * @param mode TX Mode of pkt.
43 * @param pdp Power delay profile of pkt.
44 * @param arrivalList List of interfering arrivals given from Transducer.
45 * @return The SINR in dB re 1 uPa.
46 */
47 virtual double CalcSinrDb(Ptr<Packet> pkt,
48 Time arrTime,
49 double rxPowerDb,
50 double ambNoiseDb,
51 UanTxMode mode,
52 UanPdp pdp,
53 const UanTransducer::ArrivalList& arrivalList) const = 0;
54 /**
55 * Register this type.
56 * @return The object TypeId.
57 */
58 static TypeId GetTypeId();
59
60 /** Clear all pointer references. */
61 virtual void Clear();
62
63 /**
64 * Convert dB re 1 uPa to kilopascals.
65 *
66 * @param db dB value.
67 * @return Value in kilopascals.
68 */
69 inline double DbToKp(double db) const
70 {
71 return std::pow(10, db / 10.0);
72 }
73
74 /**
75 * Convert kilopascals to dB re 1 uPa.
76 *
77 * @param kp Value in kilopascals.
78 * @return Value in dB re 1 uPa
79 */
80 inline double KpToDb(double kp) const
81 {
82 return 10 * std::log10(kp);
83 }
84
85 protected:
86 void DoDispose() override;
87
88}; // class UanPhyCalcSinr
89
90/**
91 * @ingroup uan
92 *
93 * Calculate packet error probability, based on received SINR
94 * and modulation (mode).
95 *
96 * Can be set in UanPhy via attributes.
97 */
98class UanPhyPer : public Object
99{
100 public:
101 /**
102 * Calculate the packet error probability based on
103 * SINR at the receiver and a tx mode.
104 *
105 * @param pkt Packet which is under consideration.
106 * @param sinrDb SINR at receiver.
107 * @param mode TX mode used to transmit packet.
108 * @return Probability of packet error.
109 */
110 virtual double CalcPer(Ptr<Packet> pkt, double sinrDb, UanTxMode mode) = 0;
111
112 /**
113 * Register this type.
114 * @return The TypeId.
115 */
116 static TypeId GetTypeId();
117 /** Clear all pointer references. */
118 virtual void Clear();
119
120 protected:
121 void DoDispose() override;
122
123}; // class UanPhyPer
124
125/**
126 * @ingroup uan
127 *
128 * Interface for PHY event listener.
129 *
130 * A class which implements this interface may register with Phy object
131 * to receive notification of TX/RX/CCA events
132 */
134{
135 public:
136 /** Default destructor */
138 {
139 }
140
141 /** Called when UanPhy begins receiving packet. */
142 virtual void NotifyRxStart() = 0;
143 /** Called when UanPhy finishes receiving packet without error. */
144 virtual void NotifyRxEndOk() = 0;
145 /** Called when UanPhy finishes receiving packet in error. */
146 virtual void NotifyRxEndError() = 0;
147 /** Called when UanPhy begins sensing channel is busy. */
148 virtual void NotifyCcaStart() = 0;
149 /** Called when UanPhy stops sensing channel is busy. */
150 virtual void NotifyCcaEnd() = 0;
151 /**
152 * Called when transmission starts from Phy object.
153 *
154 * @param duration Duration of transmission.
155 */
156 virtual void NotifyTxStart(Time duration) = 0;
157 /** Function called when Phy object finishes transmitting packet */
158 virtual void NotifyTxEnd() = 0;
159}; // class UanPhyListener
160
161/**
162 * @ingroup uan
163 *
164 * Base class for UAN Phy models.
165 */
166class UanPhy : public Object
167{
168 public:
169 /// Enum defining possible Phy states.
170 enum State
171 {
172 IDLE, //!< Idle state.
173 CCABUSY, //!< Channel busy.
174 RX, //!< Receiving.
175 TX, //!< Transmitting.
176 SLEEP, //!< Sleeping.
177 DISABLED //!< Disabled.
178 };
179
180 /**
181 * Packet received successfully callback function type.
182 *
183 * \pname{arg1} Packet received successfully.
184 * \pname{arg2} SNIR of packet.
185 * \pname{arg3} Mode of packet.
186 */
188
189 /**
190 * Packet receive error callback function type.
191 *
192 * \pname{arg1} Packet received successfully.
193 * \pname{arg2} SNIR of packet.
194 */
196
197 /**
198 * TracedCallback signature for UanPhy packet send/receive events.
199 *
200 * @param [in] pkt The packet.
201 * @param [in] sinr The SINR.
202 * @param [in] mode The channel mode.
203 */
204 typedef void (*TracedCallback)(Ptr<const Packet> pkt, double sinr, UanTxMode mode);
205
206 /**
207 * Set the DeviceEnergyModel callback for UanPhy device.
208 *
209 * @param callback The DeviceEnergyModel change state callback.
210 */
213 /**
214 * Handle the energy depletion event.
215 */
216 virtual void EnergyDepletionHandler() = 0;
217 /**
218 * Handle the energy recharge event.
219 */
220 virtual void EnergyRechargeHandler() = 0;
221 /**
222 * Send a packet using a specific transmission mode.
223 *
224 * @param pkt Packet to transmit.
225 * @param modeNum Index of mode in SupportedModes list to use for transmission.
226 */
227 virtual void SendPacket(Ptr<Packet> pkt, uint32_t modeNum) = 0;
228
229 /**
230 * Register a UanPhyListener to be notified of common UanPhy events.
231 *
232 * @param listener New listener to register.
233 */
234 virtual void RegisterListener(UanPhyListener* listener) = 0;
235
236 /**
237 * Packet arriving from channel: i.e. leading bit of packet has arrived.
238 *
239 * @param pkt Packet which is arriving.
240 * @param rxPowerDb Signal power of incoming packet in dB re 1 uPa.
241 * @param txMode Transmission mode defining modulation of incoming packet.
242 * @param pdp Power delay profile of incoming packet.
243 */
244 virtual void StartRxPacket(Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp) = 0;
245
246 /**
247 * Set the callback to be used when a packet is received without error.
248 *
249 * @param cb The callback.
250 */
251 virtual void SetReceiveOkCallback(RxOkCallback cb) = 0;
252
253 /**
254 * Set the callback to be used when a packet is received with errors.
255 *
256 * @param cb The callback.
257 */
259
260 /**
261 * Set the transmit power.
262 *
263 * @param txpwr Final output transmission power, in dB.
264 */
265 virtual void SetTxPowerDb(double txpwr) = 0;
266
267 /**
268 * Set the minimum SINR threshold to receive a packet without errors.
269 *
270 * @deprecated See UanPhyPer.
271 *
272 * @param thresh Threshold SINR for proper reception in dB re 1 uPa.
273 */
274 // NS_DEPRECATED() - tag for future removal
275 virtual void SetRxThresholdDb(double thresh) = 0;
276
277 /**
278 * Set the threshold for detecting channel busy.
279 *
280 * @param thresh Signal power threshold at receiver.
281 */
282 virtual void SetCcaThresholdDb(double thresh) = 0;
283
284 /**
285 * Get the current transmit power, in dB.
286 *
287 * @return The transmit power.
288 */
289 virtual double GetTxPowerDb() = 0;
290
291 /**
292 * Get the minimum received signal strength required
293 * to receive a packet without errors.
294 *
295 * @return The minimum required signal strength, in dB.
296 */
297 virtual double GetRxThresholdDb() = 0;
298
299 /**
300 * Get the CCA threshold signal strength required to detect channel busy.
301 *
302 * @return The CCA threshold signal strength in dB.
303 */
304 virtual double GetCcaThresholdDb() = 0;
305 /** @return True if Phy is in SLEEP state. */
306 virtual bool IsStateSleep() = 0;
307 /** @return True if Phy is in IDLE state. */
308 virtual bool IsStateIdle() = 0;
309 /** @return True if Phy is neither IDLE nor SLEEP. */
310 virtual bool IsStateBusy() = 0;
311 /** @return True if Phy is currently in receive mode. */
312 virtual bool IsStateRx() = 0;
313 /** @return True if Phy is busy transmitting. */
314 virtual bool IsStateTx() = 0;
315 /** @return True if Phy is in CCABUSY state. */
316 virtual bool IsStateCcaBusy() = 0;
317
318 /**
319 * Get the attached channel.
320 *
321 * @return The channel.
322 */
323 virtual Ptr<UanChannel> GetChannel() const = 0;
324
325 /**
326 * Get the device hosting this Phy.
327 *
328 * @return The net device.
329 */
330 virtual Ptr<UanNetDevice> GetDevice() const = 0;
331
332 /**
333 * Attach to a channel.
334 *
335 * @param channel The channel to attach to.
336 */
337 virtual void SetChannel(Ptr<UanChannel> channel) = 0;
338
339 /**
340 * Set the device hosting this Phy.
341 *
342 * @param device The device.
343 */
344 virtual void SetDevice(Ptr<UanNetDevice> device) = 0;
345
346 /**
347 * Set the MAC forwarding messages to this Phy.
348 *
349 * @param mac The MAC.
350 */
351 virtual void SetMac(Ptr<UanMac> mac) = 0;
352
353 /**
354 * Called when a transmission is beginning
355 * on the attached transducer.
356 *
357 * @param packet Packet that is beginning transmission.
358 * @param txPowerDb Transmit power of packet.
359 * @param txMode Transmission mode of packet.
360 */
361 virtual void NotifyTransStartTx(Ptr<Packet> packet, double txPowerDb, UanTxMode txMode) = 0;
362
363 /**
364 * Called when there has been a change in the
365 * amount of interference this node is experiencing
366 * from other transmissions.
367 */
368 virtual void NotifyIntChange() = 0;
369
370 /**
371 * Attach a transducer to this Phy.
372 *
373 * @param trans The transducer.
374 */
375 virtual void SetTransducer(Ptr<UanTransducer> trans) = 0;
376
377 /**
378 * Get the attached transducer.
379 *
380 * @return The transducer.
381 */
383
384 /**
385 * Get the number of transmission modes supported by this Phy.
386 *
387 * @return The number modes.
388 */
389 virtual uint32_t GetNModes() = 0;
390
391 /**
392 * Get a specific transmission mode.
393 *
394 * @param n The mode number.
395 * @return The mode.
396 */
397 virtual UanTxMode GetMode(uint32_t n) = 0;
398
399 /**
400 * Get the packet currently being received.
401 *
402 * @warning Returns non-valid pointer if IsStateRx == false.
403 * @return The packet.
404 */
405 virtual Ptr<Packet> GetPacketRx() const = 0;
406
407 /** Clear all pointer references. */
408 virtual void Clear() = 0;
409
410 /**
411 * Set the Phy SLEEP mode.
412 *
413 * @param sleep SLEEP on or off.
414 */
415 virtual void SetSleepMode(bool sleep) = 0;
416
417 /**
418 * Called when the transducer begins transmitting a packet.
419 *
420 * This fires a PhyTxBegin trace. Implemented for encapsulation
421 * purposes.
422 *
423 * @param packet The packet.
424 */
425 void NotifyTxBegin(Ptr<const Packet> packet);
426
427 /**
428 * Called when the transducer finishes transmitting a packet.
429 *
430 * This fires a PhyTxEnd trace. Implemented for encapsulation
431 * purposes.
432 *
433 * @param packet The packet.
434 */
435 void NotifyTxEnd(Ptr<const Packet> packet);
436
437 /**
438 * Called when the transducer attempts to transmit a new packet while
439 * already transmitting a prior packet.
440 *
441 * This fires a PhyTxDrop trace. Implemented for encapsulation
442 * purposes.
443 *
444 * @param packet The packet.
445 */
446 void NotifyTxDrop(Ptr<const Packet> packet);
447
448 /**
449 * Called when the Phy begins to receive a packet.
450 *
451 * This fires a PhyRxBegin trace. Implemented for encapsulation
452 * purposes.
453 *
454 * @param packet The packet.
455 */
456 void NotifyRxBegin(Ptr<const Packet> packet);
457
458 /**
459 * Called when a packet is received without error.
460 *
461 * This fires a PhyRxEnd trace. Implemented for encapsulation
462 * purposes.
463 *
464 * @param packet The packet.
465 */
466 void NotifyRxEnd(Ptr<const Packet> packet);
467
468 /**
469 * Called when the Phy drops a packet.
470 *
471 * This fires a PhyRxDrop trace. Implemented for encapsulation
472 * purposes.
473 *
474 * @param packet The packet.
475 */
476 void NotifyRxDrop(Ptr<const Packet> packet);
477
478 /**
479 * Assign a fixed random variable stream number to the random variables
480 * used by this model. Return the number of streams (possibly zero) that
481 * have been assigned.
482 *
483 * @param stream First stream index to use.
484 * @return The number of stream indices assigned by this model.
485 */
486 virtual int64_t AssignStreams(int64_t stream) = 0;
487
488 /**
489 * Register this type.
490 * @return The TypeId.
491 */
492 static TypeId GetTypeId();
493
494 private:
495 /**
496 * Trace source indicating a packet has begun transmitting
497 * over the channel medium.
498 *
499 * @see class CallBackTraceSource
500 */
502
503 /**
504 * Trace source indicating a packet has been completely transmitted
505 * over the channel.
506 *
507 * @see class CallBackTraceSource
508 */
510
511 /**
512 * Trace source indicating a packet has been dropped by the device
513 * during transmission.
514 *
515 * @see class CallBackTraceSource
516 */
518
519 /**
520 * Trace source indicating a packet has begun being received
521 * from the channel medium by the device.
522 *
523 * @see class CallBackTraceSource
524 */
526
527 /**
528 * Trace source indicating a packet has been completely received
529 * from the channel medium by the device.
530 *
531 * @see class CallBackTraceSource
532 */
534
535 /**
536 * Trace source indicating a packet has been dropped by the device
537 * during reception.
538 *
539 * @see class CallBackTraceSource
540 */
542
543}; // class UanPhy
544
545} // namespace ns3
546
547#endif /* UAN_PHY_H */
Callback template class.
Definition callback.h:422
A base class which provides memory management and object aggregation.
Definition object.h:78
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
The power delay profile returned by propagation models.
Class used for calculating SINR of packet in UanPhy.
Definition uan-phy.h:33
static TypeId GetTypeId()
Register this type.
Definition uan-phy.cc:17
double DbToKp(double db) const
Convert dB re 1 uPa to kilopascals.
Definition uan-phy.h:69
virtual void Clear()
Clear all pointer references.
Definition uan-phy.cc:24
void DoDispose() override
Destructor implementation.
Definition uan-phy.cc:29
virtual double CalcSinrDb(Ptr< Packet > pkt, Time arrTime, double rxPowerDb, double ambNoiseDb, UanTxMode mode, UanPdp pdp, const UanTransducer::ArrivalList &arrivalList) const =0
Calculate the SINR value for a packet.
double KpToDb(double kp) const
Convert kilopascals to dB re 1 uPa.
Definition uan-phy.h:80
Base class for UAN Phy models.
Definition uan-phy.h:167
virtual bool IsStateRx()=0
Callback< void, Ptr< Packet >, double, UanTxMode > RxOkCallback
Packet received successfully callback function type.
Definition uan-phy.h:187
virtual void SetTxPowerDb(double txpwr)=0
Set the transmit power.
virtual double GetTxPowerDb()=0
Get the current transmit power, in dB.
static TypeId GetTypeId()
Register this type.
Definition uan-phy.cc:59
virtual Ptr< Packet > GetPacketRx() const =0
Get the packet currently being received.
virtual uint32_t GetNModes()=0
Get the number of transmission modes supported by this Phy.
virtual void SetChannel(Ptr< UanChannel > channel)=0
Attach to a channel.
virtual bool IsStateTx()=0
void NotifyTxDrop(Ptr< const Packet > packet)
Called when the transducer attempts to transmit a new packet while already transmitting a prior packe...
Definition uan-phy.cc:111
ns3::TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
Trace source indicating a packet has begun being received from the channel medium by the device.
Definition uan-phy.h:525
virtual void SetTransducer(Ptr< UanTransducer > trans)=0
Attach a transducer to this Phy.
virtual void SetEnergyModelCallback(energy::DeviceEnergyModel::ChangeStateCallback callback)=0
Set the DeviceEnergyModel callback for UanPhy device.
virtual void SetCcaThresholdDb(double thresh)=0
Set the threshold for detecting channel busy.
void NotifyTxEnd(Ptr< const Packet > packet)
Called when the transducer finishes transmitting a packet.
Definition uan-phy.cc:105
void NotifyRxDrop(Ptr< const Packet > packet)
Called when the Phy drops a packet.
Definition uan-phy.cc:129
virtual void StartRxPacket(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp)=0
Packet arriving from channel: i.e.
virtual void SetDevice(Ptr< UanNetDevice > device)=0
Set the device hosting this Phy.
ns3::TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
Trace source indicating a packet has been dropped by the device during transmission.
Definition uan-phy.h:517
virtual double GetRxThresholdDb()=0
Get the minimum received signal strength required to receive a packet without errors.
ns3::TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
Trace source indicating a packet has been dropped by the device during reception.
Definition uan-phy.h:541
ns3::TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
Trace source indicating a packet has been completely received from the channel medium by the device.
Definition uan-phy.h:533
virtual void NotifyIntChange()=0
Called when there has been a change in the amount of interference this node is experiencing from othe...
virtual void NotifyTransStartTx(Ptr< Packet > packet, double txPowerDb, UanTxMode txMode)=0
Called when a transmission is beginning on the attached transducer.
virtual UanTxMode GetMode(uint32_t n)=0
Get a specific transmission mode.
virtual bool IsStateSleep()=0
virtual void EnergyRechargeHandler()=0
Handle the energy recharge event.
virtual void RegisterListener(UanPhyListener *listener)=0
Register a UanPhyListener to be notified of common UanPhy events.
virtual void EnergyDepletionHandler()=0
Handle the energy depletion event.
ns3::TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
Trace source indicating a packet has been completely transmitted over the channel.
Definition uan-phy.h:509
virtual bool IsStateIdle()=0
virtual Ptr< UanChannel > GetChannel() const =0
Get the attached channel.
virtual Ptr< UanNetDevice > GetDevice() const =0
Get the device hosting this Phy.
virtual void SetReceiveErrorCallback(RxErrCallback cb)=0
Set the callback to be used when a packet is received with errors.
virtual bool IsStateBusy()=0
virtual bool IsStateCcaBusy()=0
virtual void SetRxThresholdDb(double thresh)=0
Set the minimum SINR threshold to receive a packet without errors.
ns3::TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
Trace source indicating a packet has begun transmitting over the channel medium.
Definition uan-phy.h:501
virtual void SetMac(Ptr< UanMac > mac)=0
Set the MAC forwarding messages to this Phy.
virtual void SendPacket(Ptr< Packet > pkt, uint32_t modeNum)=0
Send a packet using a specific transmission mode.
virtual void SetReceiveOkCallback(RxOkCallback cb)=0
Set the callback to be used when a packet is received without error.
void NotifyRxBegin(Ptr< const Packet > packet)
Called when the Phy begins to receive a packet.
Definition uan-phy.cc:117
virtual int64_t AssignStreams(int64_t stream)=0
Assign a fixed random variable stream number to the random variables used by this model.
void NotifyRxEnd(Ptr< const Packet > packet)
Called when a packet is received without error.
Definition uan-phy.cc:123
virtual Ptr< UanTransducer > GetTransducer()=0
Get the attached transducer.
Callback< void, Ptr< Packet >, double > RxErrCallback
Packet receive error callback function type.
Definition uan-phy.h:195
virtual double GetCcaThresholdDb()=0
Get the CCA threshold signal strength required to detect channel busy.
void NotifyTxBegin(Ptr< const Packet > packet)
Called when the transducer begins transmitting a packet.
Definition uan-phy.cc:99
virtual void Clear()=0
Clear all pointer references.
State
Enum defining possible Phy states.
Definition uan-phy.h:171
@ RX
Receiving.
Definition uan-phy.h:174
@ SLEEP
Sleeping.
Definition uan-phy.h:176
@ IDLE
Idle state.
Definition uan-phy.h:172
@ DISABLED
Disabled.
Definition uan-phy.h:177
@ TX
Transmitting.
Definition uan-phy.h:175
@ CCABUSY
Channel busy.
Definition uan-phy.h:173
virtual void SetSleepMode(bool sleep)=0
Set the Phy SLEEP mode.
Interface for PHY event listener.
Definition uan-phy.h:134
virtual ~UanPhyListener()
Default destructor.
Definition uan-phy.h:137
virtual void NotifyRxStart()=0
Called when UanPhy begins receiving packet.
virtual void NotifyTxStart(Time duration)=0
Called when transmission starts from Phy object.
virtual void NotifyRxEndError()=0
Called when UanPhy finishes receiving packet in error.
virtual void NotifyTxEnd()=0
Function called when Phy object finishes transmitting packet.
virtual void NotifyCcaStart()=0
Called when UanPhy begins sensing channel is busy.
virtual void NotifyCcaEnd()=0
Called when UanPhy stops sensing channel is busy.
virtual void NotifyRxEndOk()=0
Called when UanPhy finishes receiving packet without error.
Calculate packet error probability, based on received SINR and modulation (mode).
Definition uan-phy.h:99
virtual void Clear()
Clear all pointer references.
Definition uan-phy.cc:45
static TypeId GetTypeId()
Register this type.
Definition uan-phy.cc:38
virtual double CalcPer(Ptr< Packet > pkt, double sinrDb, UanTxMode mode)=0
Calculate the packet error probability based on SINR at the receiver and a tx mode.
void DoDispose() override
Destructor implementation.
Definition uan-phy.cc:50
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.