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