A Discrete-Event Network Simulator
API
uan-phy-gen.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 #ifndef UAN_PHY_GEN_H
23 #define UAN_PHY_GEN_H
24 
25 
26 #include "uan-phy.h"
27 #include "ns3/traced-callback.h"
28 #include "ns3/nstime.h"
29 #include "ns3/device-energy-model.h"
30 #include "ns3/random-variable-stream.h"
31 #include "ns3/event-id.h"
32 #include <list>
33 
34 namespace ns3 {
35 
45 {
46 public:
50  virtual ~UanPhyPerGenDefault ();
51 
56  static TypeId GetTypeId (void);
57 
58  virtual double CalcPer (Ptr<Packet> pkt, double sinrDb, UanTxMode mode);
59 private:
60 
61  double m_thresh;
62 
63 }; // class UanPhyPerGenDefault
64 
65 
75 class UanPhyPerUmodem : public UanPhyPer
76 {
77 public:
79  UanPhyPerUmodem ();
81  virtual ~UanPhyPerUmodem ();
82 
87  static TypeId GetTypeId (void);
88 
104  virtual double CalcPer (Ptr<Packet> pkt, double sinrDb, UanTxMode mode);
105 
106 private:
114  double NChooseK (uint32_t n, uint32_t k);
115 
116 }; // class UanPhyPerUmodem
117 
118 
129 {
130 
131 public:
135  virtual ~UanPhyCalcSinrDefault ();
136 
141  static TypeId GetTypeId (void);
142 
158  virtual double CalcSinrDb (Ptr<Packet> pkt,
159  Time arrTime,
160  double rxPowerDb,
161  double ambNoiseDb,
162  UanTxMode mode,
163  UanPdp pdp,
164  const UanTransducer::ArrivalList &arrivalList
165  ) const;
166 
167 }; // class UanPhyCalcSinrDefault
168 
169 
182 {
183 
184 public:
188  virtual ~UanPhyCalcSinrFhFsk ();
189 
194  static TypeId GetTypeId (void);
195 
196  virtual double CalcSinrDb (Ptr<Packet> pkt,
197  Time arrTime,
198  double rxPowerDb,
199  double ambNoiseDb,
200  UanTxMode mode,
201  UanPdp pdp,
202  const UanTransducer::ArrivalList &arrivalList
203  ) const;
204 private:
205  uint32_t m_hops;
206 
207 }; // class UanPhyCalcSinrFhFsk
208 
209 
220 class UanPhyGen : public UanPhy
221 {
222 public:
224  UanPhyGen ();
226  virtual ~UanPhyGen ();
232  static UanModesList GetDefaultModes (void);
233 
234 
239  static TypeId GetTypeId (void);
240 
241  // Inherited methods
243  virtual void EnergyDepletionHandler (void);
244  virtual void EnergyRechargeHandler (void);
245  virtual void SendPacket (Ptr<Packet> pkt, uint32_t modeNum);
246  virtual void RegisterListener (UanPhyListener *listener);
247  virtual void StartRxPacket (Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp);
248  virtual void SetReceiveOkCallback (RxOkCallback cb);
249  virtual void SetReceiveErrorCallback (RxErrCallback cb);
250  virtual bool IsStateSleep (void);
251  virtual bool IsStateIdle (void);
252  virtual bool IsStateBusy (void);
253  virtual bool IsStateRx (void);
254  virtual bool IsStateTx (void);
255  virtual bool IsStateCcaBusy (void);
256  virtual void SetRxGainDb (double gain);
257  virtual void SetTxPowerDb (double txpwr);
258  virtual void SetRxThresholdDb (double thresh);
259  virtual void SetCcaThresholdDb (double thresh);
260  virtual double GetRxGainDb (void);
261  virtual double GetTxPowerDb (void);
262  virtual double GetRxThresholdDb (void);
263  virtual double GetCcaThresholdDb (void);
264  virtual Ptr<UanChannel> GetChannel (void) const;
265  virtual Ptr<UanNetDevice> GetDevice (void) const;
266  virtual Ptr<UanTransducer> GetTransducer (void);
267  virtual void SetChannel (Ptr<UanChannel> channel);
268  virtual void SetDevice (Ptr<UanNetDevice> device);
269  virtual void SetMac (Ptr<UanMac> mac);
270  virtual void SetTransducer (Ptr<UanTransducer> trans);
271  virtual void NotifyTransStartTx (Ptr<Packet> packet, double txPowerDb, UanTxMode txMode);
272  virtual void NotifyIntChange (void);
273  virtual uint32_t GetNModes (void);
274  virtual UanTxMode GetMode (uint32_t n);
275  virtual Ptr<Packet> GetPacketRx (void) const;
276  virtual void Clear (void);
277  virtual void SetSleepMode (bool sleep);
278  int64_t AssignStreams (int64_t stream);
279 
280 private:
282  typedef std::list<UanPhyListener *> ListenerList;
283 
285 
287  ListenerList m_listeners;
296 
297  double m_rxGainDb;
298  double m_txPwrDb;
299  double m_rxThreshDb;
300  double m_ccaThreshDb;
301 
304  double m_minRxSinrDb;
305  double m_rxRecvPwrDb;
309 
310  bool m_cleared;
311 
314 
317 
326 
337  double CalculateSinrDb (Ptr<Packet> pkt, Time arrTime, double rxPowerDb,
338  UanTxMode mode, UanPdp pdp);
339 
350  double GetInterferenceDb (Ptr<Packet> pkt);
359  double DbToKp (double db);
368  double KpToDb (double kp);
376  void RxEndEvent (Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode);
378  void TxEndEvent ();
384  void UpdatePowerConsumption (const State state);
385 
386 
388  void NotifyListenersRxStart (void);
390  void NotifyListenersRxGood (void);
392  void NotifyListenersRxBad (void);
394  void NotifyListenersCcaStart (void);
396  void NotifyListenersCcaEnd (void);
402  void NotifyListenersTxStart (Time duration);
403 
404 protected:
405  virtual void DoDispose ();
406 
407 }; // class UanPhyGen
408 
409 } // namespace ns3
410 
411 #endif /* UAN_PHY_GEN_H */
virtual void NotifyTransStartTx(Ptr< Packet > packet, double txPowerDb, UanTxMode txMode)
Called when a transmission is beginning on the attched transducer.
Definition: uan-phy-gen.cc:906
tuple channel
Definition: third.py:85
virtual bool IsStateBusy(void)
Definition: uan-phy-gen.cc:760
virtual Ptr< UanTransducer > GetTransducer(void)
Get the attached transducer.
Definition: uan-phy-gen.cc:838
virtual double GetRxThresholdDb(void)
Get the minimum received signal strength required to receive a packet without errors.
Definition: uan-phy-gen.cc:815
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
virtual bool IsStateRx(void)
Definition: uan-phy-gen.cc:765
double KpToDb(double kp)
Convert kilopascals to dB.
Definition: uan-phy-gen.cc:959
virtual void SetEnergyModelCallback(DeviceEnergyModel::ChangeStateCallback cb)
Set the DeviceEnergyModel callback for UanPhy device.
Definition: uan-phy-gen.cc:493
uint32_t m_hops
Number of hops.
Definition: uan-phy-gen.h:205
Ptr< Packet > m_pktTx
Sent packet.
Definition: uan-phy-gen.h:303
virtual void SetReceiveErrorCallback(RxErrCallback cb)
Set the callback to be used when a packet is received with errors.
Definition: uan-phy-gen.cc:745
double CalculateSinrDb(Ptr< Packet > pkt, Time arrTime, double rxPowerDb, UanTxMode mode, UanPdp pdp)
Calculate the SINR value for a packet.
Definition: uan-phy-gen.cc:925
virtual void EnergyDepletionHandler(void)
Handle the energy depletion event.
Definition: uan-phy-gen.cc:511
virtual void SetTransducer(Ptr< UanTransducer > trans)
Attach a transducer to this Phy.
Definition: uan-phy-gen.cc:861
Forward calls to a chain of Callback.
virtual ~UanPhyGen()
Dummy destructor, see DoDispose.
Definition: uan-phy-gen.cc:369
Ptr< UniformRandomVariable > m_pg
Provides uniform random variables.
Definition: uan-phy-gen.h:316
double m_rxRecvPwrDb
Receiver power.
Definition: uan-phy-gen.h:305
Packet error rate calculation assuming WHOI Micromodem-like PHY.
Definition: uan-phy-gen.h:75
virtual void SetSleepMode(bool sleep)
Set the Phy SLEEP mode.
Definition: uan-phy-gen.cc:868
virtual void StartRxPacket(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
Packet arriving from channel: i.e.
Definition: uan-phy-gen.cc:612
virtual uint32_t GetNModes(void)
Get the number of transmission modes supported by this Phy.
Container for UanTxModes.
Definition: uan-tx-mode.h:257
virtual double GetTxPowerDb(void)
Get the current transmit power, in dB.
Definition: uan-phy-gen.cc:809
virtual double GetCcaThresholdDb(void)
Get the CCA threshold signal strength required to detect channel busy.
Definition: uan-phy-gen.cc:820
EventId m_rxEndEvent
Rx event.
Definition: uan-phy-gen.h:313
double m_rxThreshDb
Receive SINR threshold.
Definition: uan-phy-gen.h:299
EventId m_txEndEvent
Tx event.
Definition: uan-phy-gen.h:312
Ptr< UanPhyPer > m_per
Error model.
Definition: uan-phy-gen.h:294
virtual void DoDispose()
Destructor implementation.
Definition: uan-phy-gen.cc:417
Time m_pktRxArrTime
Packet arrival time.
Definition: uan-phy-gen.h:306
bool m_cleared
Flag when we've been cleared.
Definition: uan-phy-gen.h:310
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:256
double NChooseK(uint32_t n, uint32_t k)
Binomial coefficient.
Definition: uan-phy-gen.cc:267
WHOI Micromodem like FH-FSK model.
Definition: uan-phy-gen.h:181
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:433
virtual double CalcSinrDb(Ptr< Packet > pkt, Time arrTime, double rxPowerDb, double ambNoiseDb, UanTxMode mode, UanPdp pdp, const UanTransducer::ArrivalList &arrivalList) const
Calculate the SINR value for a packet.
Definition: uan-phy-gen.cc:73
virtual bool IsStateTx(void)
Definition: uan-phy-gen.cc:770
virtual void SetDevice(Ptr< UanNetDevice > device)
Set the device hosting this Phy.
Definition: uan-phy-gen.cc:849
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: uan-phy-gen.cc:898
double m_rxGainDb
Receive gain.
Definition: uan-phy-gen.h:297
virtual void EnergyRechargeHandler(void)
Handle the energy recharge event.
Definition: uan-phy-gen.cc:533
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_rxErrLogger
A packet destined for this Phy was received with error.
Definition: uan-phy-gen.h:323
virtual ~UanPhyPerUmodem()
Destructor.
Definition: uan-phy-gen.cc:251
Ptr< UanNetDevice > m_device
Device hosting this Phy.
Definition: uan-phy-gen.h:292
virtual Ptr< Packet > GetPacketRx(void) const
Get the packet currently being received.
double m_txPwrDb
Transmit power.
Definition: uan-phy-gen.h:298
The power delay profile returned by propagation models.
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:41
double m_thresh
SINR threshold.
Definition: uan-phy-gen.h:61
Calculate packet error probability, based on received SINR and modulation (mode). ...
Definition: uan-phy.h:110
DeviceEnergyModel::ChangeStateCallback m_energyCallback
Energy model callback.
Definition: uan-phy-gen.h:319
double m_ccaThreshDb
CCA busy threshold.
Definition: uan-phy-gen.h:300
void NotifyListenersRxGood(void)
Call UanListener::NotifyRxEndOk on all listeners.
Definition: uan-phy-gen.cc:975
void NotifyListenersCcaEnd(void)
Call UanListener::NotifyCcaEnd on all listeners.
Generic PHY model.
Definition: uan-phy-gen.h:220
std::list< UanPacketArrival > ArrivalList
List of arriving packets overlapping in time.
State
Enum defining possible Phy states.
Definition: uan-phy.h:179
Ptr< Packet > m_pktRx
Received packet.
Definition: uan-phy-gen.h:302
tuple mac
Definition: third.py:92
virtual void SetCcaThresholdDb(double thresh)
Set the threshold for detecting channel busy.
Definition: uan-phy-gen.cc:799
virtual void NotifyIntChange(void)
Called when there has been a change in the ammount of interference this node is experiencing from oth...
Definition: uan-phy-gen.cc:915
UanPdp m_pktRxPdp
Power delay profile of pakket.
Definition: uan-phy-gen.h:307
virtual double CalcSinrDb(Ptr< Packet > pkt, Time arrTime, double rxPowerDb, double ambNoiseDb, UanTxMode mode, UanPdp pdp, const UanTransducer::ArrivalList &arrivalList) const
Calculate the SINR value for a packet.
Definition: uan-phy-gen.cc:125
virtual Ptr< UanChannel > GetChannel(void) const
Get the attached channel.
Definition: uan-phy-gen.cc:826
Ptr< UanPhyCalcSinr > m_sinr
SINR calculator.
Definition: uan-phy-gen.h:295
virtual UanTxMode GetMode(uint32_t n)
Get a specific transmission mode.
virtual void SetRxThresholdDb(double thresh)
Set the minimum SINR threshold to receive a packet without errors.
Definition: uan-phy-gen.cc:794
void TxEndEvent()
Event to process end of packet transmission.
Definition: uan-phy-gen.cc:583
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double DbToKp(double db)
Convert dB to kilopascals.
Definition: uan-phy-gen.cc:954
virtual void SetRxGainDb(double gain)
Set the receiver gain.
Definition: uan-phy-gen.cc:783
RxOkCallback m_recOkCb
Callback for packets received without error.
Definition: uan-phy-gen.h:288
UanModesList m_modes
List of modes supported by this PHY.
Definition: uan-phy-gen.h:284
Interface for PHY event listener.
Definition: uan-phy.h:146
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:217
void UpdatePowerConsumption(const State state)
Update energy source with new state.
Definition: uan-phy-gen.cc:500
void NotifyListenersRxStart(void)
Call UanListener::NotifyRxStart on all listeners.
Definition: uan-phy-gen.cc:965
virtual double CalcPer(Ptr< Packet > pkt, double sinrDb, UanTxMode mode)
Calculate the packet error probability based on SINR at the receiver and a tx mode.
Definition: uan-phy-gen.cc:287
State m_state
Phy state.
Definition: uan-phy-gen.h:286
virtual ~UanPhyCalcSinrFhFsk()
Destructor.
Definition: uan-phy-gen.cc:104
void RxEndEvent(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode)
Event to process end of packet reception.
Definition: uan-phy-gen.cc:688
virtual Ptr< UanNetDevice > GetDevice(void) const
Get the device hosting this Phy.
Definition: uan-phy-gen.cc:832
virtual void SetChannel(Ptr< UanChannel > channel)
Attach to a channel.
Definition: uan-phy-gen.cc:843
Default SINR calculator for UanPhyGen.
Definition: uan-phy-gen.h:128
Class used for calculating SINR of packet in UanPhy.
Definition: uan-phy.h:44
Ptr< UanMac > m_mac
MAC layer.
Definition: uan-phy-gen.h:293
Base class for UAN Phy models.
Definition: uan-phy.h:175
std::list< UanPhyListener * > ListenerList
List of Phy Listeners.
Definition: uan-phy-gen.h:282
virtual ~UanPhyPerGenDefault()
Destructor.
Definition: uan-phy-gen.cc:212
UanPhyCalcSinrFhFsk()
Constructor.
Definition: uan-phy-gen.cc:100
An identifier for simulation events.
Definition: event-id.h:53
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_txLogger
A packet was sent from this Phy.
Definition: uan-phy-gen.h:325
virtual bool IsStateIdle(void)
Definition: uan-phy-gen.cc:755
RxErrCallback m_recErrCb
Callback for packets received with errors.
Definition: uan-phy-gen.h:289
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:62
Ptr< UanChannel > m_channel
Attached channel.
Definition: uan-phy-gen.h:290
void NotifyListenersCcaStart(void)
Call UanListener::NotifyCcaStart on all listeners.
Definition: uan-phy-gen.cc:993
double GetInterferenceDb(Ptr< Packet > pkt)
Calculate interference power from overlapping packet arrivals, in dB.
Definition: uan-phy-gen.cc:932
void NotifyListenersRxBad(void)
Call UanListener::NotifyRxEndError on all listeners.
Definition: uan-phy-gen.cc:984
Ptr< UanTransducer > m_transducer
Associated transducer.
Definition: uan-phy-gen.h:291
UanPhyPerUmodem()
Constructor.
Definition: uan-phy-gen.cc:247
UanPhyPerGenDefault()
Constructor.
Definition: uan-phy-gen.cc:207
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:110
UanPhyGen()
Constructor.
Definition: uan-phy-gen.cc:349
virtual ~UanPhyCalcSinrDefault()
Destructor.
Definition: uan-phy-gen.cc:56
virtual void SendPacket(Ptr< Packet > pkt, uint32_t modeNum)
Send a packet using a specific transmission mode.
Definition: uan-phy-gen.cc:543
Default Packet Error Rate calculator for UanPhyGen.
Definition: uan-phy-gen.h:44
UanTxMode m_pktRxMode
Packet transmission mode at receiver.
Definition: uan-phy-gen.h:308
ListenerList m_listeners
List of listeners.
Definition: uan-phy-gen.h:287
virtual bool IsStateCcaBusy(void)
Definition: uan-phy-gen.cc:776
virtual void RegisterListener(UanPhyListener *listener)
Register a UanPhyListener to be notified of common UanPhy events.
Definition: uan-phy-gen.cc:605
virtual double GetRxGainDb(void)
Get the receiver gain added to signal at receiver in dB.
Definition: uan-phy-gen.cc:804
double m_minRxSinrDb
Minimum receive SINR during packet reception.
Definition: uan-phy-gen.h:304
virtual bool IsStateSleep(void)
Definition: uan-phy-gen.cc:750
virtual void SetMac(Ptr< UanMac > mac)
Set the MAC forwarding messages to this Phy.
Definition: uan-phy-gen.cc:855
virtual void SetReceiveOkCallback(RxOkCallback cb)
Set the callback to be used when a packet is received without error.
Definition: uan-phy-gen.cc:739
static UanModesList GetDefaultModes(void)
Get the default transmission modes.
Definition: uan-phy-gen.cc:425
a unique identifier for an interface.
Definition: type-id.h:58
virtual double CalcPer(Ptr< Packet > pkt, double sinrDb, UanTxMode mode)
Calculate the packet error probability based on SINR at the receiver and a tx mode.
Definition: uan-phy-gen.cc:234
virtual void Clear(void)
Clear all pointer references.
Definition: uan-phy-gen.cc:375
UanPhyCalcSinrDefault()
Constructor.
Definition: uan-phy-gen.cc:52
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_rxOkLogger
A packet destined for this Phy was received without error.
Definition: uan-phy-gen.h:321
void NotifyListenersTxStart(Time duration)
Call UanListener::NotifyTxStart on all listeners.
virtual void SetTxPowerDb(double txpwr)
Set the transmit power.
Definition: uan-phy-gen.cc:789