A Discrete-Event Network Simulator
API
uan-phy.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 University of Washington
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Leonard Tracy <lentracy@gmail.com>
19  * Andrea Sacco <andrea.sacco85@gmail.com>
20  */
21 
22 
23 #ifndef UAN_PHY_H
24 #define UAN_PHY_H
25 
26 #include "ns3/object.h"
27 #include "ns3/uan-mac.h"
28 #include "ns3/uan-tx-mode.h"
29 #include "ns3/uan-prop-model.h"
30 #include "ns3/uan-transducer.h"
31 #include "ns3/device-energy-model.h"
32 
33 namespace ns3 {
34 
35 
44 class UanPhyCalcSinr : public Object
45 {
46 public:
59  virtual double CalcSinrDb (Ptr<Packet> pkt,
60  Time arrTime,
61  double rxPowerDb,
62  double ambNoiseDb,
63  UanTxMode mode,
64  UanPdp pdp,
65  const UanTransducer::ArrivalList &arrivalList
66  ) const = 0;
71  static TypeId GetTypeId (void);
72 
74  virtual void Clear (void);
75 
82  inline double DbToKp (double db) const
83  {
84  return std::pow (10, db / 10.0);
85  }
92  inline double KpToDb (double kp) const
93  {
94  return 10 * std::log10 (kp);
95  }
96 
97 protected:
98  virtual void DoDispose (void);
99 
100 }; // class UanPhyCalcSinr
101 
110 class UanPhyPer : public Object
111 {
112 public:
122  virtual double CalcPer (Ptr<Packet> pkt, double sinrDb, UanTxMode mode) = 0;
123 
128  static TypeId GetTypeId (void);
130  virtual void Clear (void);
131 
132 protected:
133  virtual void DoDispose (void);
134 
135 }; // class UanPhyPer
136 
137 
147 {
148 public:
150  virtual ~UanPhyListener ()
151  {
152  }
154  virtual void NotifyRxStart (void) = 0;
156  virtual void NotifyRxEndOk (void) = 0;
158  virtual void NotifyRxEndError (void) = 0;
160  virtual void NotifyCcaStart (void) = 0;
162  virtual void NotifyCcaEnd (void) = 0;
168  virtual void NotifyTxStart (Time duration) = 0;
170  virtual void NotifyTxEnd (void) = 0;
171 }; // class UanPhyListener
172 
178 class UanPhy : public Object
179 {
180 public:
182  enum State
183  {
186  RX,
187  TX,
190  };
191 
200 
208 
216  typedef void (* TracedCallback)(Ptr<const Packet> pkt, double sinr, UanTxMode mode);
217 
218 
228  virtual void EnergyDepletionHandler (void) = 0;
232  virtual void EnergyRechargeHandler (void) = 0;
239  virtual void SendPacket (Ptr<Packet> pkt, uint32_t modeNum) = 0;
240 
246  virtual void RegisterListener (UanPhyListener *listener) = 0;
247 
256  virtual void StartRxPacket (Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp) = 0;
257 
263  virtual void SetReceiveOkCallback (RxOkCallback cb) = 0;
264 
270  virtual void SetReceiveErrorCallback (RxErrCallback cb) = 0;
271 
272 
278  virtual void SetTxPowerDb (double txpwr) = 0;
279 
287  virtual void SetRxThresholdDb (double thresh) = 0;
288 
294  virtual void SetCcaThresholdDb (double thresh) = 0;
295 
296 
302  virtual double GetTxPowerDb (void) = 0;
303 
310  virtual double GetRxThresholdDb (void) = 0;
311 
317  virtual double GetCcaThresholdDb (void) = 0;
319  virtual bool IsStateSleep (void) = 0;
321  virtual bool IsStateIdle (void) = 0;
323  virtual bool IsStateBusy (void) = 0;
325  virtual bool IsStateRx (void) = 0;
327  virtual bool IsStateTx (void) = 0;
329  virtual bool IsStateCcaBusy (void) = 0;
330 
336  virtual Ptr<UanChannel> GetChannel (void) const = 0;
337 
343  virtual Ptr<UanNetDevice> GetDevice (void) const = 0;
344 
350  virtual void SetChannel (Ptr<UanChannel> channel) = 0;
351 
357  virtual void SetDevice (Ptr<UanNetDevice> device) = 0;
358 
364  virtual void SetMac (Ptr<UanMac> mac) = 0;
365 
374  virtual void NotifyTransStartTx (Ptr<Packet> packet, double txPowerDb, UanTxMode txMode) = 0;
375 
381  virtual void NotifyIntChange (void) = 0;
382 
388  virtual void SetTransducer (Ptr<UanTransducer> trans) = 0;
389 
395  virtual Ptr<UanTransducer> GetTransducer (void) = 0;
396 
402  virtual uint32_t GetNModes (void) = 0;
403 
410  virtual UanTxMode GetMode (uint32_t n) = 0;
411 
418  virtual Ptr<Packet> GetPacketRx (void) const = 0;
419 
421  virtual void Clear (void) = 0;
422 
428  virtual void SetSleepMode (bool sleep) = 0;
429 
430 
439  void NotifyTxBegin (Ptr<const Packet> packet);
440 
449  void NotifyTxEnd (Ptr<const Packet> packet);
450 
460  void NotifyTxDrop (Ptr<const Packet> packet);
461 
470  void NotifyRxBegin (Ptr<const Packet> packet);
471 
480  void NotifyRxEnd (Ptr<const Packet> packet);
481 
490  void NotifyRxDrop (Ptr<const Packet> packet);
491 
500  virtual int64_t AssignStreams (int64_t stream) = 0;
501 
506  static TypeId GetTypeId (void);
507 
508 private:
516 
524 
532 
540 
548 
556 
557 }; // class UanPhy
558 
559 } // namespace ns3
560 
561 #endif /* UAN_PHY_H */
virtual ~UanPhyListener()
Default destructor.
Definition: uan-phy.h:150
ns3::TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
Trace source indicating a packet has been dropped by the device during transmission.
Definition: uan-phy.h:531
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
virtual bool IsStateBusy(void)=0
virtual bool IsStateSleep(void)=0
ns3::TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
Trace source indicating a packet has been dropped by the device during reception. ...
Definition: uan-phy.h:555
virtual void NotifyTransStartTx(Ptr< Packet > packet, double txPowerDb, UanTxMode txMode)=0
Called when a transmission is beginning on the attached transducer.
Callback template class.
Definition: callback.h:1278
Transmitting.
Definition: uan-phy.h:187
void NotifyRxDrop(Ptr< const Packet > packet)
Called when the Phy drops a packet.
Definition: uan-phy.cc:144
virtual void SetCcaThresholdDb(double thresh)=0
Set the threshold for detecting channel busy.
virtual double GetRxThresholdDb(void)=0
Get the minimum received signal strength required to receive a packet without errors.
virtual Ptr< UanChannel > GetChannel(void) const =0
Get the attached channel.
Forward calls to a chain of Callback.
virtual void SetRxThresholdDb(double thresh)=0
Set the minimum SINR threshold to receive a packet without errors.
virtual void SetDevice(Ptr< UanNetDevice > device)=0
Set the device hosting this Phy.
virtual void Clear(void)=0
Clear all pointer references.
virtual void SetReceiveErrorCallback(RxErrCallback cb)=0
Set the callback to be used when a packet is received with errors.
virtual void NotifyIntChange(void)=0
Called when there has been a change in the amount of interference this node is experiencing from othe...
virtual void EnergyRechargeHandler(void)=0
Handle the energy recharge event.
virtual void DoDispose(void)
Destructor implementation.
Definition: uan-phy.cc:42
Channel busy.
Definition: uan-phy.h:185
virtual uint32_t GetNModes(void)=0
Get the number of transmission modes supported by this Phy.
virtual bool IsStateTx(void)=0
virtual double GetCcaThresholdDb(void)=0
Get the CCA threshold signal strength required to detect channel busy.
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:126
void NotifyRxEnd(Ptr< const Packet > packet)
Called when a packet is received without error.
Definition: uan-phy.cc:138
virtual void RegisterListener(UanPhyListener *listener)=0
Register a UanPhyListener to be notified of common UanPhy events.
channel
Definition: third.py:92
virtual void NotifyRxStart(void)=0
Called when UanPhy begins receiving packet.
virtual bool IsStateCcaBusy(void)=0
virtual void Clear(void)
Clear all pointer references.
Definition: uan-phy.cc:37
virtual void NotifyTxStart(Time duration)=0
Called when transmission starts from Phy object.
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy.cc:50
The power delay profile returned by propagation models.
Receiving.
Definition: uan-phy.h:186
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:41
ns3::TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
Trace source indicating a packet has begun transmitting over the channel medium.
Definition: uan-phy.h:515
mac
Definition: third.py:99
Idle state.
Definition: uan-phy.h:184
Calculate packet error probability, based on received SINR and modulation (mode). ...
Definition: uan-phy.h:110
std::list< UanPacketArrival > ArrivalList
List of arriving packets overlapping in time.
double DbToKp(double db) const
Convert dB re 1 uPa to kilopascals.
Definition: uan-phy.h:82
State
Enum defining possible Phy states.
Definition: uan-phy.h:182
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:547
void NotifyTxBegin(Ptr< const Packet > packet)
Called when the transducer begins transmitting a packet.
Definition: uan-phy.cc:114
virtual void NotifyRxEndError(void)=0
Called when UanPhy finishes receiving packet in error.
Sleeping.
Definition: uan-phy.h:188
void NotifyRxBegin(Ptr< const Packet > packet)
Called when the Phy begins to receive a packet.
Definition: uan-phy.cc:132
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void NotifyRxEndOk(void)=0
Called when UanPhy finishes receiving packet without error.
virtual void SetTxPowerDb(double txpwr)=0
Set the transmit power.
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy.cc:73
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:539
Interface for PHY event listener.
Definition: uan-phy.h:146
virtual void DoDispose(void)
Destructor implementation.
Definition: uan-phy.cc:65
virtual void SetSleepMode(bool sleep)=0
Set the Phy SLEEP mode.
virtual int64_t AssignStreams(int64_t stream)=0
Assign a fixed random variable stream number to the random variables used by this model...
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.
Class used for calculating SINR of packet in UanPhy.
Definition: uan-phy.h:44
Base class for UAN Phy models.
Definition: uan-phy.h:178
virtual void EnergyDepletionHandler(void)=0
Handle the energy depletion event.
virtual double GetTxPowerDb(void)=0
Get the current transmit power, in dB.
virtual void NotifyCcaStart(void)=0
Called when UanPhy begins sensing channel is busy.
virtual void SetEnergyModelCallback(DeviceEnergyModel::ChangeStateCallback callback)=0
Set the DeviceEnergyModel callback for UanPhy device.
double KpToDb(double kp) const
Convert kilopascals to dB re 1 uPa.
Definition: uan-phy.h:92
Callback< void, Ptr< Packet >, double, UanTxMode > RxOkCallback
Packet received successfully callback function type.
Definition: uan-phy.h:199
virtual void NotifyCcaEnd(void)=0
Called when UanPhy stops sensing channel is busy.
virtual UanTxMode GetMode(uint32_t n)=0
Get a specific transmission mode.
virtual void Clear(void)
Clear all pointer references.
Definition: uan-phy.cc:60
virtual void NotifyTxEnd(void)=0
Function called when Phy object finishes transmitting packet.
virtual void StartRxPacket(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp)=0
Packet arriving from channel: i.e.
ns3::TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
Trace source indicating a packet has been completely transmitted over the channel.
Definition: uan-phy.h:523
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy.cc:27
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.
virtual Ptr< UanTransducer > GetTransducer(void)=0
Get the attached transducer.
A base class which provides memory management and object aggregation.
Definition: object.h:87
virtual void SetMac(Ptr< UanMac > mac)=0
Set the MAC forwarding messages to this Phy.
virtual bool IsStateIdle(void)=0
virtual Ptr< Packet > GetPacketRx(void) const =0
Get the packet currently being received.
virtual void SetChannel(Ptr< UanChannel > channel)=0
Attach to a channel.
Callback< void, Ptr< Packet >, double > RxErrCallback
Packet receive error callback function type.
Definition: uan-phy.h:207
virtual void SendPacket(Ptr< Packet > pkt, uint32_t modeNum)=0
Send a packet using a specific transmission mode.
virtual void SetTransducer(Ptr< UanTransducer > trans)=0
Attach a transducer to this Phy.
a unique identifier for an interface.
Definition: type-id.h:58
void NotifyTxEnd(Ptr< const Packet > packet)
Called when the transducer finishes transmitting a packet.
Definition: uan-phy.cc:120
virtual bool IsStateRx(void)=0
virtual Ptr< UanNetDevice > GetDevice(void) const =0
Get the device hosting this Phy.
virtual void SetReceiveOkCallback(RxOkCallback cb)=0
Set the callback to be used when a packet is received without error.