A Discrete-Event Network Simulator
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
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  */
22 #ifndef UAN_PHY_GEN_H
23 #define UAN_PHY_GEN_H
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>
34 namespace ns3 {
45 {
46 public:
50  virtual ~UanPhyPerGenDefault ();
56  static TypeId GetTypeId (void);
58  virtual double CalcPer (Ptr<Packet> pkt, double sinrDb, UanTxMode mode);
59 private:
60  double m_thresh;
62 }; // class UanPhyPerGenDefault
74 class UanPhyPerUmodem : public UanPhyPer
75 {
76 public:
78  UanPhyPerUmodem ();
80  virtual ~UanPhyPerUmodem ();
86  static TypeId GetTypeId (void);
103  virtual double CalcPer (Ptr<Packet> pkt, double sinrDb, UanTxMode mode);
105 private:
113  double NChooseK (uint32_t n, uint32_t k);
115 }; // class UanPhyPerUmodem
127 {
128 public:
132  virtual ~UanPhyPerCommonModes ();
138  static TypeId GetTypeId (void);
152  virtual double CalcPer (Ptr<Packet> pkt, double sinrDb, UanTxMode mode);
154 }; // class UanPhyPerCommonModes
167 {
169 public:
173  virtual ~UanPhyCalcSinrDefault ();
179  static TypeId GetTypeId (void);
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;
205 }; // class UanPhyCalcSinrDefault
228 {
230 public:
234  virtual ~UanPhyCalcSinrFhFsk ();
240  static TypeId GetTypeId (void);
242  virtual double CalcSinrDb (Ptr<Packet> pkt,
243  Time arrTime,
244  double rxPowerDb,
245  double ambNoiseDb,
246  UanTxMode mode,
247  UanPdp pdp,
248  const UanTransducer::ArrivalList &arrivalList
249  ) const;
250 private:
251  uint32_t m_hops;
253 }; // class UanPhyCalcSinrFhFsk
266 class UanPhyGen : public UanPhy
267 {
268 public:
270  UanPhyGen ();
272  virtual ~UanPhyGen ();
278  static UanModesList GetDefaultModes (void);
284  static TypeId GetTypeId (void);
286  // Inherited methods
288  virtual void EnergyDepletionHandler (void);
289  virtual void EnergyRechargeHandler (void);
290  virtual void SendPacket (Ptr<Packet> pkt, uint32_t modeNum);
291  virtual void RegisterListener (UanPhyListener *listener);
292  virtual void StartRxPacket (Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp);
293  virtual void SetReceiveOkCallback (RxOkCallback cb);
294  virtual void SetReceiveErrorCallback (RxErrCallback cb);
295  virtual bool IsStateSleep (void);
296  virtual bool IsStateIdle (void);
297  virtual bool IsStateBusy (void);
298  virtual bool IsStateRx (void);
299  virtual bool IsStateTx (void);
300  virtual bool IsStateCcaBusy (void);
301  virtual void SetTxPowerDb (double txpwr);
302  virtual void SetRxThresholdDb (double thresh);
303  virtual void SetCcaThresholdDb (double thresh);
304  virtual double GetTxPowerDb (void);
305  virtual double GetRxThresholdDb (void);
306  virtual double GetCcaThresholdDb (void);
307  virtual Ptr<UanChannel> GetChannel (void) const;
308  virtual Ptr<UanNetDevice> GetDevice (void) const;
309  virtual Ptr<UanTransducer> GetTransducer (void);
310  virtual void SetChannel (Ptr<UanChannel> channel);
311  virtual void SetDevice (Ptr<UanNetDevice> device);
312  virtual void SetMac (Ptr<UanMac> mac);
313  virtual void SetTransducer (Ptr<UanTransducer> trans);
314  virtual void NotifyTransStartTx (Ptr<Packet> packet, double txPowerDb, UanTxMode txMode);
315  virtual void NotifyIntChange (void);
316  virtual uint32_t GetNModes (void);
317  virtual UanTxMode GetMode (uint32_t n);
318  virtual Ptr<Packet> GetPacketRx (void) const;
319  virtual void Clear (void);
320  virtual void SetSleepMode (bool sleep);
321  int64_t AssignStreams (int64_t stream);
323 private:
325  typedef std::list<UanPhyListener *> ListenerList;
340  double m_txPwrDb;
341  double m_rxThreshDb;
342  double m_ccaThreshDb;
346  double m_minRxSinrDb;
347  double m_rxRecvPwrDb;
352  bool m_cleared;
379  double CalculateSinrDb (Ptr<Packet> pkt, Time arrTime, double rxPowerDb,
380  UanTxMode mode, UanPdp pdp);
392  double GetInterferenceDb (Ptr<Packet> pkt);
401  double DbToKp (double db);
410  double KpToDb (double kp);
418  void RxEndEvent (Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode);
420  void TxEndEvent ();
426  void UpdatePowerConsumption (const State state);
430  void NotifyListenersRxStart (void);
432  void NotifyListenersRxGood (void);
434  void NotifyListenersRxBad (void);
436  void NotifyListenersCcaStart (void);
438  void NotifyListenersCcaEnd (void);
444  void NotifyListenersTxStart (Time duration);
446 protected:
447  virtual void DoDispose ();
449 }; // class UanPhyGen
451 } // namespace ns3
453 #endif /* UAN_PHY_GEN_H */
virtual void NotifyTransStartTx(Ptr< Packet > packet, double txPowerDb, UanTxMode txMode)
Called when a transmission is beginning on the attached transducer.
virtual bool IsStateBusy(void)
Definition: uan-phy-gen.cc:906
virtual Ptr< UanTransducer > GetTransducer(void)
Get the attached transducer.
Definition: uan-phy-gen.cc:975
virtual double GetRxThresholdDb(void)
Get the minimum received signal strength required to receive a packet without errors.
Definition: uan-phy-gen.cc:952
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
virtual bool IsStateRx(void)
Definition: uan-phy-gen.cc:911
double KpToDb(double kp)
Convert kilopascals to dB.
virtual void SetEnergyModelCallback(DeviceEnergyModel::ChangeStateCallback cb)
Set the DeviceEnergyModel callback for UanPhy device.
Definition: uan-phy-gen.cc:636
uint32_t m_hops
Number of hops.
Definition: uan-phy-gen.h:251
Ptr< Packet > m_pktTx
Sent packet.
Definition: uan-phy-gen.h:345
virtual void SetReceiveErrorCallback(RxErrCallback cb)
Set the callback to be used when a packet is received with errors.
Definition: uan-phy-gen.cc:891
double CalculateSinrDb(Ptr< Packet > pkt, Time arrTime, double rxPowerDb, UanTxMode mode, UanPdp pdp)
Calculate the SINR value for a packet.
virtual void EnergyDepletionHandler(void)
Handle the energy depletion event.
Definition: uan-phy-gen.cc:654
virtual void SetTransducer(Ptr< UanTransducer > trans)
Attach a transducer to this Phy.
Definition: uan-phy-gen.cc:998
Forward calls to a chain of Callback.
Packet error rate calculation for common tx modes based on UanPhyPerUmodem.
Definition: uan-phy-gen.h:126
virtual ~UanPhyGen()
Dummy destructor, see DoDispose.
Definition: uan-phy-gen.cc:514
Ptr< UniformRandomVariable > m_pg
Provides uniform random variables.
Definition: uan-phy-gen.h:358
double m_rxRecvPwrDb
Receiver power.
Definition: uan-phy-gen.h:347
Packet error rate calculation assuming WHOI Micromodem-like PHY (FH-FSK)
Definition: uan-phy-gen.h:74
virtual void SetSleepMode(bool sleep)
Set the Phy SLEEP mode.
virtual void StartRxPacket(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
Packet arriving from channel: i.e.
Definition: uan-phy-gen.cc:755
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:945
virtual double GetCcaThresholdDb(void)
Get the CCA threshold signal strength required to detect channel busy.
Definition: uan-phy-gen.cc:957
EventId m_rxEndEvent
Rx event.
Definition: uan-phy-gen.h:355
double m_rxThreshDb
Receive SINR threshold.
Definition: uan-phy-gen.h:341
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:74
EventId m_txEndEvent
Tx event.
Definition: uan-phy-gen.h:354
Ptr< UanPhyPer > m_per
Error model.
Definition: uan-phy-gen.h:337
virtual void DoDispose()
Destructor implementation.
Definition: uan-phy-gen.cc:562
Definition: third.py:85
Time m_pktRxArrTime
Packet arrival time.
Definition: uan-phy-gen.h:348
bool m_cleared
Flag when we&#39;ve been cleared.
Definition: uan-phy-gen.h:352
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:398
double NChooseK(uint32_t n, uint32_t k)
Binomial coefficient.
Definition: uan-phy-gen.cc:409
WHOI Micromodem like FH-FSK model.
Definition: uan-phy-gen.h:227
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:581
virtual bool IsStateTx(void)
Definition: uan-phy-gen.cc:916
virtual void SetDevice(Ptr< UanNetDevice > device)
Set the device hosting this Phy.
Definition: uan-phy-gen.cc:986
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
virtual void EnergyRechargeHandler(void)
Handle the energy recharge event.
Definition: uan-phy-gen.cc:676
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_rxErrLogger
A packet destined for this Phy was received with error.
Definition: uan-phy-gen.h:365
virtual ~UanPhyPerUmodem()
Definition: uan-phy-gen.cc:393
Ptr< UanNetDevice > m_device
Device hosting this Phy.
Definition: uan-phy-gen.h:335
double m_txPwrDb
Transmit power.
Definition: uan-phy-gen.h:340
The power delay profile returned by propagation models.
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:41
Definition: third.py:92
double m_thresh
SINR threshold.
Definition: uan-phy-gen.h:60
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:361
double m_ccaThreshDb
CCA busy threshold.
Definition: uan-phy-gen.h:342
void NotifyListenersRxGood(void)
Call UanListener::NotifyRxEndOk on all listeners.
void NotifyListenersCcaEnd(void)
Call UanListener::NotifyCcaEnd on all listeners.
Generic PHY model.
Definition: uan-phy-gen.h:266
std::list< UanPacketArrival > ArrivalList
List of arriving packets overlapping in time.
Ptr< Packet > m_pktRx
Received packet.
Definition: uan-phy-gen.h:344
Enum defining possible Phy states.
Definition: uan-phy.h:179
virtual void SetCcaThresholdDb(double thresh)
Set the threshold for detecting channel busy.
Definition: uan-phy-gen.cc:939
virtual void NotifyIntChange(void)
Called when there has been a change in the amount of interference this node is experiencing from othe...
UanPdp m_pktRxPdp
Power delay profile of packet.
Definition: uan-phy-gen.h:349
Ptr< UanPhyCalcSinr > m_sinr
SINR calculator.
Definition: uan-phy-gen.h:338
virtual Ptr< UanChannel > GetChannel(void) const
Get the attached channel.
Definition: uan-phy-gen.cc:963
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:934
void TxEndEvent()
Event to process end of packet transmission.
Definition: uan-phy-gen.cc:726
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double DbToKp(double db)
Convert dB to kilopascals.
RxOkCallback m_recOkCb
Callback for packets received without error.
Definition: uan-phy-gen.h:331
UanModesList m_modes
List of modes supported by this PHY.
Definition: uan-phy-gen.h:327
Interface for PHY event listener.
Definition: uan-phy.h:146
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:222
void UpdatePowerConsumption(const State state)
Update energy source with new state.
Definition: uan-phy-gen.cc:643
void NotifyListenersRxStart(void)
Call UanListener::NotifyRxStart on all listeners.
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:429
State m_state
Phy state.
Definition: uan-phy-gen.h:329
virtual ~UanPhyCalcSinrFhFsk()
Definition: uan-phy-gen.cc:105
void RxEndEvent(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode)
Event to process end of packet reception.
Definition: uan-phy-gen.cc:833
virtual void SetChannel(Ptr< UanChannel > channel)
Attach to a channel.
Definition: uan-phy-gen.cc:980
Default SINR calculator for UanPhyGen.
Definition: uan-phy-gen.h:166
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:275
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:336
Base class for UAN Phy models.
Definition: uan-phy.h:175
std::list< UanPhyListener * > ListenerList
List of Phy Listeners.
Definition: uan-phy-gen.h:325
virtual ~UanPhyPerGenDefault()
Definition: uan-phy-gen.cc:217
Definition: uan-phy-gen.cc:101
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:367
virtual bool IsStateIdle(void)
Definition: uan-phy-gen.cc:901
RxErrCallback m_recErrCb
Callback for packets received with errors.
Definition: uan-phy-gen.h:332
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:63
Ptr< UanChannel > m_channel
Attached channel.
Definition: uan-phy-gen.h:333
void NotifyListenersCcaStart(void)
Call UanListener::NotifyCcaStart on all listeners.
double GetInterferenceDb(Ptr< Packet > pkt)
Calculate interference power from overlapping packet arrivals, in dB.
virtual Ptr< UanNetDevice > GetDevice(void) const
Get the device hosting this Phy.
Definition: uan-phy-gen.cc:969
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:264
void NotifyListenersRxBad(void)
Call UanListener::NotifyRxEndError on all listeners.
Ptr< UanTransducer > m_transducer
Associated transducer.
Definition: uan-phy-gen.h:334
Definition: uan-phy-gen.cc:389
Definition: uan-phy-gen.cc:212
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:111
Definition: uan-phy-gen.cc:495
virtual ~UanPhyPerCommonModes()
Definition: uan-phy-gen.cc:258
virtual Ptr< Packet > GetPacketRx(void) const
Get the packet currently being received.
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:126
virtual ~UanPhyCalcSinrDefault()
Definition: uan-phy-gen.cc:57
virtual void SendPacket(Ptr< Packet > pkt, uint32_t modeNum)
Send a packet using a specific transmission mode.
Definition: uan-phy-gen.cc:686
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:350
ListenerList m_listeners
List of listeners.
Definition: uan-phy-gen.h:330
virtual bool IsStateCcaBusy(void)
Definition: uan-phy-gen.cc:922
virtual void RegisterListener(UanPhyListener *listener)
Register a UanPhyListener to be notified of common UanPhy events.
Definition: uan-phy-gen.cc:748
double m_minRxSinrDb
Minimum receive SINR during packet reception.
Definition: uan-phy-gen.h:346
virtual bool IsStateSleep(void)
Definition: uan-phy-gen.cc:896
virtual void SetMac(Ptr< UanMac > mac)
Set the MAC forwarding messages to this Phy.
Definition: uan-phy-gen.cc:992
virtual void SetReceiveOkCallback(RxOkCallback cb)
Set the callback to be used when a packet is received without error.
Definition: uan-phy-gen.cc:885
Definition: uan-phy-gen.cc:252
static UanModesList GetDefaultModes(void)
Get the default transmission modes.
Definition: uan-phy-gen.cc:570
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:239
virtual void Clear(void)
Clear all pointer references.
Definition: uan-phy-gen.cc:520
Definition: uan-phy-gen.cc:53
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_rxOkLogger
A packet destined for this Phy was received without error.
Definition: uan-phy-gen.h:363
void NotifyListenersTxStart(Time duration)
Call UanListener::NotifyTxStart on all listeners.
virtual void SetTxPowerDb(double txpwr)
Set the transmit power.
Definition: uan-phy-gen.cc:929