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