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 () { }
152  virtual void NotifyRxStart (void) = 0;
154  virtual void NotifyRxEndOk (void) = 0;
156  virtual void NotifyRxEndError (void) = 0;
158  virtual void NotifyCcaStart (void) = 0;
160  virtual void NotifyCcaEnd (void) = 0;
166  virtual void NotifyTxStart (Time duration) = 0;
167 
168 }; // class UanPhyListener
169 
175 class UanPhy : public Object
176 {
177 public:
179  enum State
180  {
183  RX,
184  TX,
187  };
188 
197 
204  typedef Callback<void, Ptr<Packet>, double > RxErrCallback;
205 
213  typedef void (* TracedCallback)
214  (Ptr<const Packet> pkt, double sinr, UanTxMode mode);
215 
216 
226  virtual void EnergyDepletionHandler (void) = 0;
230  virtual void EnergyRechargeHandler (void) = 0;
237  virtual void SendPacket (Ptr<Packet> pkt, uint32_t modeNum) = 0;
238 
244  virtual void RegisterListener (UanPhyListener *listener) = 0;
245 
254  virtual void StartRxPacket (Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp) = 0;
255 
261  virtual void SetReceiveOkCallback (RxOkCallback cb) = 0;
262 
268  virtual void SetReceiveErrorCallback (RxErrCallback cb) = 0;
269 
270 
276  virtual void SetTxPowerDb (double txpwr) = 0;
277 
285  virtual void SetRxThresholdDb (double thresh) = 0;
286 
292  virtual void SetCcaThresholdDb (double thresh) = 0;
293 
294 
300  virtual double GetTxPowerDb (void) = 0;
301 
308  virtual double GetRxThresholdDb (void) = 0;
309 
315  virtual double GetCcaThresholdDb (void) = 0;
317  virtual bool IsStateSleep (void) = 0;
319  virtual bool IsStateIdle (void) = 0;
321  virtual bool IsStateBusy (void) = 0;
323  virtual bool IsStateRx (void) = 0;
325  virtual bool IsStateTx (void) = 0;
327  virtual bool IsStateCcaBusy (void) = 0;
328 
334  virtual Ptr<UanChannel> GetChannel (void) const = 0;
335 
341  virtual Ptr<UanNetDevice> GetDevice (void) const = 0;
342 
348  virtual void SetChannel (Ptr<UanChannel> channel) = 0;
349 
355  virtual void SetDevice (Ptr<UanNetDevice> device) = 0;
356 
362  virtual void SetMac (Ptr<UanMac> mac) = 0;
363 
372  virtual void NotifyTransStartTx (Ptr<Packet> packet, double txPowerDb, UanTxMode txMode) = 0;
373 
379  virtual void NotifyIntChange (void) = 0;
380 
386  virtual void SetTransducer (Ptr<UanTransducer> trans) = 0;
387 
393  virtual Ptr<UanTransducer> GetTransducer (void) = 0;
394 
400  virtual uint32_t GetNModes (void) = 0;
401 
408  virtual UanTxMode GetMode (uint32_t n) = 0;
409 
416  virtual Ptr<Packet> GetPacketRx (void) const = 0;
417 
419  virtual void Clear (void) = 0;
420 
426  virtual void SetSleepMode (bool sleep) = 0;
427 
428 
437  void NotifyTxBegin (Ptr<const Packet> packet);
438 
447  void NotifyTxEnd (Ptr<const Packet> packet);
448 
458  void NotifyTxDrop (Ptr<const Packet> packet);
459 
468  void NotifyRxBegin (Ptr<const Packet> packet);
469 
478  void NotifyRxEnd (Ptr<const Packet> packet);
479 
488  void NotifyRxDrop (Ptr<const Packet> packet);
489 
498  virtual int64_t AssignStreams (int64_t stream) = 0;
499 
504  static TypeId GetTypeId (void);
505 
506 private:
514 
522 
530 
538 
546 
554 
555 }; // class UanPhy
556 
557 } // namespace ns3
558 
559 #endif /* UAN_PHY_H */
virtual ~UanPhyListener()
Default destructor.
Definition: uan-phy.h:150
tuple channel
Definition: third.py:85
ns3::TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
Trace source indicating a packet has been dropped by the device during transmission.
Definition: uan-phy.h:529
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
virtual bool IsStateBusy(void)=0
Idle state.
Definition: uan-phy.h:181
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:553
virtual void NotifyTransStartTx(Ptr< Packet > packet, double txPowerDb, UanTxMode txMode)=0
Called when a transmission is beginning on the attched transducer.
Callback template class.
Definition: callback.h:1176
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.
Sleeping.
Definition: uan-phy.h:185
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.
Receiving.
Definition: uan-phy.h:183
virtual void NotifyIntChange(void)=0
Called when there has been a change in the ammount of interference this node is experiencing from oth...
virtual void EnergyRechargeHandler(void)=0
Handle the energy recharge event.
virtual void DoDispose(void)
Destructor implementation.
Definition: uan-phy.cc:42
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.
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
Channel busy.
Definition: uan-phy.h:182
double KpToDb(double kp) const
Convert kilopascals to dB re 1 uPa.
Definition: uan-phy.h:92
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.
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:513
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.
State
Enum defining possible Phy states.
Definition: uan-phy.h:179
tuple mac
Definition: third.py:92
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:545
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.
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:537
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.
double DbToKp(double db) const
Convert dB re 1 uPa to kilopascals.
Definition: uan-phy.h:82
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:175
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.
Callback< void, Ptr< Packet >, double, UanTxMode > RxOkCallback
Packet received successfully callback function type.
Definition: uan-phy.h:196
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 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:521
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:204
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
Transmitting.
Definition: uan-phy.h:184
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.