A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
uan-phy-gen.h
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 <list>
32 
33 namespace ns3 {
34 
42 {
43 public:
45  virtual ~UanPhyPerGenDefault ();
46 
47  static TypeId GetTypeId (void);
48  virtual double CalcPer (Ptr<Packet> pkt, double sinrDb, UanTxMode mode);
49 private:
50  double m_thresh;
51 
52 };
53 
60 class UanPhyPerUmodem : public UanPhyPer
61 {
62 public:
63  UanPhyPerUmodem ();
64  virtual ~UanPhyPerUmodem ();
65 
66  static TypeId GetTypeId (void);
67 
81  virtual double CalcPer (Ptr<Packet> pkt, double sinrDb, UanTxMode mode);
82 private:
83  double NChooseK (uint32_t n, uint32_t k);
84 
85 };
94 {
95 
96 public:
98  virtual ~UanPhyCalcSinrDefault ();
99  static TypeId GetTypeId (void);
113  virtual double CalcSinrDb (Ptr<Packet> pkt,
114  Time arrTime,
115  double rxPowerDb,
116  double ambNoiseDb,
117  UanTxMode mode,
118  UanPdp pdp,
119  const UanTransducer::ArrivalList &arrivalList
120  ) const;
121 };
122 
134 {
135 
136 public:
138  virtual ~UanPhyCalcSinrFhFsk ();
139  static TypeId GetTypeId (void);
140  virtual double CalcSinrDb (Ptr<Packet> pkt,
141  Time arrTime,
142  double rxPowerDb,
143  double ambNoiseDb,
144  UanTxMode mode,
145  UanPdp pdp,
146  const UanTransducer::ArrivalList &arrivalList
147  ) const;
148 private:
149  uint32_t m_hops;
150 };
151 
161 class UanPhyGen : public UanPhy
162 {
163 public:
164  UanPhyGen ();
165  virtual ~UanPhyGen ();
169  static UanModesList GetDefaultModes (void);
170 
171  static TypeId GetTypeId (void);
173  virtual void EnergyDepletionHandler (void);
174  virtual void SendPacket (Ptr<Packet> pkt, uint32_t modeNum);
175  virtual void RegisterListener (UanPhyListener *listener);
176  virtual void StartRxPacket (Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp);
177  virtual void SetReceiveOkCallback (RxOkCallback cb);
178  virtual void SetReceiveErrorCallback (RxErrCallback cb);
179  virtual bool IsStateSleep (void);
180  virtual bool IsStateIdle (void);
181  virtual bool IsStateBusy (void);
182  virtual bool IsStateRx (void);
183  virtual bool IsStateTx (void);
184  virtual bool IsStateCcaBusy (void);
185  virtual void SetRxGainDb (double gain);
186  virtual void SetTxPowerDb (double txpwr);
187  virtual void SetRxThresholdDb (double thresh);
188  virtual void SetCcaThresholdDb (double thresh);
189  virtual double GetRxGainDb (void);
190  virtual double GetTxPowerDb (void);
191  virtual double GetRxThresholdDb (void);
192  virtual double GetCcaThresholdDb (void);
193  virtual Ptr<UanChannel> GetChannel (void) const;
194  virtual Ptr<UanNetDevice> GetDevice (void);
195  virtual Ptr<UanTransducer> GetTransducer (void);
196  virtual void SetChannel (Ptr<UanChannel> channel);
197  virtual void SetDevice (Ptr<UanNetDevice> device);
198  virtual void SetMac (Ptr<UanMac> mac);
199  virtual void SetTransducer (Ptr<UanTransducer> trans);
200  virtual void NotifyTransStartTx (Ptr<Packet> packet, double txPowerDb, UanTxMode txMode);
201  virtual void NotifyIntChange (void);
202  virtual uint32_t GetNModes (void);
203  virtual UanTxMode GetMode (uint32_t n);
204  virtual Ptr<Packet> GetPacketRx (void) const;
205  virtual void Clear (void);
206 
207  virtual void SetSleepMode (bool sleep);
208 
217  int64_t AssignStreams (int64_t stream);
218 
219 private:
220  typedef std::list<UanPhyListener *> ListenerList;
221 
222  UanModesList m_modes;
223 
224  State m_state;
225  ListenerList m_listeners;
226  RxOkCallback m_recOkCb;
227  RxErrCallback m_recErrCb;
228  Ptr<UanChannel> m_channel;
229  Ptr<UanTransducer> m_transducer;
230  Ptr<UanNetDevice> m_device;
231  Ptr<UanMac> m_mac;
232  Ptr<UanPhyPer> m_per;
233  Ptr<UanPhyCalcSinr> m_sinr;
234 
235  double m_rxGainDb;
236  double m_txPwrDb;
237  double m_rxThreshDb;
238  double m_ccaThreshDb;
239 
240  Ptr<Packet> m_pktRx;
241  double m_minRxSinrDb;
242  double m_rxRecvPwrDb;
243  Time m_pktRxArrTime;
244  UanPdp m_pktRxPdp;
245  UanTxMode m_pktRxMode;
246 
247  bool m_cleared;
248  bool m_disabled;
249 
252 
254  TracedCallback<Ptr<const Packet>, double, UanTxMode > m_rxOkLogger;
255  TracedCallback<Ptr<const Packet>, double, UanTxMode > m_rxErrLogger;
256  TracedCallback<Ptr<const Packet>, double, UanTxMode > m_txLogger;
257 
258  double CalculateSinrDb (Ptr<Packet> pkt, Time arrTime, double rxPowerDb, UanTxMode mode, UanPdp pdp);
259  double GetInterferenceDb (Ptr<Packet> pkt);
260  double DbToKp (double db);
261  double KpToDb (double kp);
262  void RxEndEvent (Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode);
263  void TxEndEvent ();
264  void UpdatePowerConsumption (const State state);
265 
266  void NotifyListenersRxStart (void);
267  void NotifyListenersRxGood (void);
268  void NotifyListenersRxBad (void);
269  void NotifyListenersCcaStart (void);
270  void NotifyListenersCcaEnd (void);
271  void NotifyListenersTxStart (Time duration);
272 protected:
273  virtual void DoDispose ();
274 
275 };
276 
277 } // namespace ns3
278 
279 #endif /* UAN_PHY_GEN_H */
virtual void NotifyTransStartTx(Ptr< Packet > packet, double txPowerDb, UanTxMode txMode)
Definition: uan-phy-gen.cc:877
virtual bool IsStateBusy(void)
Definition: uan-phy-gen.cc:731
virtual Ptr< UanTransducer > GetTransducer(void)
Definition: uan-phy-gen.cc:809
virtual double GetRxThresholdDb(void)
Definition: uan-phy-gen.cc:786
keep track of time unit.
Definition: nstime.h:149
virtual bool IsStateRx(void)
Definition: uan-phy-gen.cc:736
virtual void SetEnergyModelCallback(DeviceEnergyModel::ChangeStateCallback cb)
Definition: uan-phy-gen.cc:484
virtual void SetReceiveErrorCallback(RxErrCallback cb)
Definition: uan-phy-gen.cc:716
virtual void EnergyDepletionHandler(void)
Definition: uan-phy-gen.cc:502
virtual void SetTransducer(Ptr< UanTransducer > trans)
Definition: uan-phy-gen.cc:832
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
Ptr< UniformRandomVariable > m_pg
Provides uniform random variables.
Definition: uan-phy-gen.h:251
Packet error rate calculation assuming WHOI Micromodem like PHY Calculates PER assuming rate 1/2 conv...
Definition: uan-phy-gen.h:60
virtual void StartRxPacket(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
Packet arriving from channel: i.e. leading bit of packet has arrived.
Definition: uan-phy-gen.cc:580
virtual uint32_t GetNModes(void)
Definition: uan-phy-gen.cc:993
Container for UanTxModes.
Definition: uan-tx-mode.h:162
virtual double GetTxPowerDb(void)
Definition: uan-phy-gen.cc:780
virtual double GetCcaThresholdDb(void)
Definition: uan-phy-gen.cc:791
virtual void DoDispose()
Definition: uan-phy-gen.cc:412
WHOI Micromodem like FH-FSK model.
Definition: uan-phy-gen.h:133
virtual double CalcSinrDb(Ptr< Packet > pkt, Time arrTime, double rxPowerDb, double ambNoiseDb, UanTxMode mode, UanPdp pdp, const UanTransducer::ArrivalList &arrivalList) const
Definition: uan-phy-gen.cc:71
virtual bool IsStateTx(void)
Definition: uan-phy-gen.cc:741
virtual void SetDevice(Ptr< UanNetDevice > device)
Definition: uan-phy-gen.cc:820
int64_t AssignStreams(int64_t stream)
Definition: uan-phy-gen.cc:869
virtual Ptr< Packet > GetPacketRx(void) const
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:36
Generic PHY model.
Definition: uan-phy-gen.h:161
std::list< UanPacketArrival > ArrivalList
Arrival list is a standard template library list of UanPacketArrivals objects.
State
Enum defining possible Phy states.
Definition: uan-phy.h:172
virtual void SetCcaThresholdDb(double thresh)
Definition: uan-phy-gen.cc:770
virtual void NotifyIntChange(void)
Definition: uan-phy-gen.cc:886
virtual double CalcSinrDb(Ptr< Packet > pkt, Time arrTime, double rxPowerDb, double ambNoiseDb, UanTxMode mode, UanPdp pdp, const UanTransducer::ArrivalList &arrivalList) const
Definition: uan-phy-gen.cc:122
virtual Ptr< UanChannel > GetChannel(void) const
Definition: uan-phy-gen.cc:797
virtual UanTxMode GetMode(uint32_t n)
Definition: uan-phy-gen.cc:999
virtual void SetRxThresholdDb(double thresh)
Definition: uan-phy-gen.cc:765
virtual void SetRxGainDb(double gain)
Definition: uan-phy-gen.cc:754
Interface for PHY event listener A class which implements this interface may register with Phy object...
Definition: uan-phy.h:128
virtual double CalcPer(Ptr< Packet > pkt, double sinrDb, UanTxMode mode)
Definition: uan-phy-gen.cc:282
virtual void SetChannel(Ptr< UanChannel > channel)
Definition: uan-phy-gen.cc:814
Default SINR calculator for UanPhyGen The default ignores mode data and assumes that all rxpower tran...
Definition: uan-phy-gen.h:93
Base class for UAN Phy models.
Definition: uan-phy.h:166
virtual bool IsStateIdle(void)
Definition: uan-phy-gen.cc:726
virtual void SendPacket(Ptr< Packet > pkt, uint32_t modeNum)
Definition: uan-phy-gen.cc:512
Default Packet Error Rate calculator for UanPhyGen Considers no error if SINR is > user defined thres...
Definition: uan-phy-gen.h:41
virtual bool IsStateCcaBusy(void)
Definition: uan-phy-gen.cc:747
virtual void RegisterListener(UanPhyListener *listener)
Definition: uan-phy-gen.cc:573
virtual double GetRxGainDb(void)
Definition: uan-phy-gen.cc:775
virtual bool IsStateSleep(void)
Definition: uan-phy-gen.cc:721
virtual void SetMac(Ptr< UanMac > mac)
Definition: uan-phy-gen.cc:826
virtual void SetReceiveOkCallback(RxOkCallback cb)
Definition: uan-phy-gen.cc:710
static UanModesList GetDefaultModes(void)
Definition: uan-phy-gen.cc:420
a unique identifier for an interface.
Definition: type-id.h:44
virtual double CalcPer(Ptr< Packet > pkt, double sinrDb, UanTxMode mode)
Definition: uan-phy-gen.cc:230
virtual Ptr< UanNetDevice > GetDevice(void)
Definition: uan-phy-gen.cc:803
virtual void Clear(void)
Definition: uan-phy-gen.cc:370
virtual void SetTxPowerDb(double txpwr)
Definition: uan-phy-gen.cc:760