|
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
|
2 /* |
|
3 * Copyright (c) 2005,2006 INRIA |
|
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
|
19 */ |
|
20 |
|
21 #ifndef YANS_WIFI_PHY_H |
|
22 #define YANS_WIFI_PHY_H |
|
23 |
|
24 #include <vector> |
|
25 #include <list> |
|
26 #include <stdint.h> |
|
27 #include "ns3/callback.h" |
|
28 #include "ns3/event-id.h" |
|
29 #include "ns3/packet.h" |
|
30 #include "ns3/object.h" |
|
31 #include "ns3/traced-callback.h" |
|
32 #include "ns3/nstime.h" |
|
33 #include "ns3/ptr.h" |
|
34 #include "ns3/random-variable.h" |
|
35 #include "wifi-phy.h" |
|
36 #include "wifi-mode.h" |
|
37 #include "wifi-preamble.h" |
|
38 #include "wifi-phy-standard.h" |
|
39 |
|
40 |
|
41 namespace ns3 { |
|
42 |
|
43 class RandomUniform; |
|
44 class RxEvent; |
|
45 class WifiChannel; |
|
46 |
|
47 |
|
48 /** |
|
49 * \brief 802.11 PHY layer model |
|
50 * |
|
51 * This PHY implements a model of 802.11a. The model |
|
52 * implemented here is based on the model described |
|
53 * in "Yet Another Network Simulator", |
|
54 * (http://cutebugs.net/files/wns2-yans.pdf). |
|
55 * |
|
56 * |
|
57 * This PHY model depends on a channel loss and delay |
|
58 * model as provided by the ns3::PropagationLossModel |
|
59 * and ns3::PropagationDelayModel classes, both of which are |
|
60 * members of the ns3::WifiChannel class. |
|
61 */ |
|
62 class YansWifiPhy : public WifiPhy |
|
63 { |
|
64 public: |
|
65 |
|
66 static TypeId GetTypeId (void); |
|
67 |
|
68 YansWifiPhy (); |
|
69 virtual ~YansWifiPhy (); |
|
70 |
|
71 void SetStandard (enum WifiPhyStandard standard); |
|
72 void SetRxNoise (double ratio); |
|
73 void SetTxPowerStart (double start); |
|
74 void SetTxPowerEnd (double end); |
|
75 void SetNTxPower (uint32_t n); |
|
76 void SetTxGain (double gain); |
|
77 void SetRxGain (double gain); |
|
78 void SetEdThreshold (double threshold); |
|
79 double GetRxNoise (void) const; |
|
80 double GetTxGain (void) const; |
|
81 double GetRxGain (void) const; |
|
82 double GetEdThreshold (void) const; |
|
83 |
|
84 |
|
85 virtual double GetTxPowerStart (void) const; |
|
86 virtual double GetTxPowerEnd (void) const; |
|
87 virtual uint32_t GetNTxPower (void) const; |
|
88 virtual void SetChannel (Ptr<WifiChannel> channel); |
|
89 virtual void SetReceiveOkCallback (WifiPhy::SyncOkCallback callback); |
|
90 virtual void SetReceiveErrorCallback (WifiPhy::SyncErrorCallback callback); |
|
91 virtual void SendPacket (Ptr<const Packet> packet, WifiMode mode, enum WifiPreamble preamble, uint8_t txPowerLevel); |
|
92 virtual void RegisterListener (WifiPhyListener *listener); |
|
93 virtual bool IsStateCcaBusy (void); |
|
94 virtual bool IsStateIdle (void); |
|
95 virtual bool IsStateBusy (void); |
|
96 virtual bool IsStateSync (void); |
|
97 virtual bool IsStateTx (void); |
|
98 virtual Time GetStateDuration (void); |
|
99 virtual Time GetDelayUntilIdle (void); |
|
100 virtual Time GetLastRxStartTime (void) const; |
|
101 virtual Time CalculateTxDuration (uint32_t size, WifiMode payloadMode, enum WifiPreamble preamble) const; |
|
102 virtual uint32_t GetNModes (void) const; |
|
103 virtual WifiMode GetMode (uint32_t mode) const; |
|
104 virtual double CalculateSnr (WifiMode txMode, double ber) const; |
|
105 virtual void StartReceivePacket (Ptr<Packet> packet, |
|
106 double rxPowerDbm, |
|
107 WifiMode mode, |
|
108 WifiPreamble preamble); |
|
109 virtual Ptr<WifiChannel> GetChannel (void) const; |
|
110 |
|
111 private: |
|
112 class NiChange { |
|
113 public: |
|
114 NiChange (Time time, double delta); |
|
115 Time GetTime (void) const; |
|
116 double GetDelta (void) const; |
|
117 bool operator < (NiChange const &o) const; |
|
118 private: |
|
119 Time m_time; |
|
120 double m_delta; |
|
121 }; |
|
122 typedef std::vector<WifiMode> Modes; |
|
123 typedef std::list<WifiPhyListener *> Listeners; |
|
124 typedef std::list<Ptr<RxEvent> > Events; |
|
125 typedef std::vector <NiChange> NiChanges; |
|
126 |
|
127 private: |
|
128 virtual void DoDispose (void); |
|
129 void Configure80211aParameters (void); |
|
130 void PrintModes (void) const; |
|
131 void Configure80211a (void); |
|
132 void ConfigureHolland (void); |
|
133 char const *StateToString (enum State state); |
|
134 enum YansWifiPhy::State GetState (void); |
|
135 double GetEdThresholdW (void) const; |
|
136 double DbmToW (double dbm) const; |
|
137 double DbToRatio (double db) const; |
|
138 double WToDbm (double w) const; |
|
139 double RatioToDb (double ratio) const; |
|
140 Time GetMaxPacketDuration (void) const; |
|
141 void CancelRx (void); |
|
142 double GetPowerDbm (uint8_t power) const; |
|
143 void NotifyTxStart (Time duration); |
|
144 void NotifyWakeup (void); |
|
145 void NotifySyncStart (Time duration); |
|
146 void NotifySyncEndOk (void); |
|
147 void NotifySyncEndError (void); |
|
148 void NotifyCcaBusyStart (Time duration); |
|
149 void LogPreviousIdleAndCcaBusyStates (void); |
|
150 void SwitchToTx (Time txDuration); |
|
151 void SwitchToSync (Time syncDuration); |
|
152 void SwitchFromSync (void); |
|
153 void SwitchMaybeToCcaBusy (Time duration); |
|
154 void AppendEvent (Ptr<RxEvent> event); |
|
155 double CalculateNoiseInterferenceW (Ptr<RxEvent> event, NiChanges *ni) const; |
|
156 double CalculateSnr (double signal, double noiseInterference, WifiMode mode) const; |
|
157 double CalculateChunkSuccessRate (double snir, Time delay, WifiMode mode) const; |
|
158 double CalculatePer (Ptr<const RxEvent> event, NiChanges *ni) const; |
|
159 void EndSync (Ptr<Packet> packet, Ptr<RxEvent> event); |
|
160 double Log2 (double val) const; |
|
161 double GetBpskBer (double snr, uint32_t signalSpread, uint32_t phyRate) const; |
|
162 double GetQamBer (double snr, unsigned int m, uint32_t signalSpread, uint32_t phyRate) const; |
|
163 uint32_t Factorial (uint32_t k) const; |
|
164 double Binomial (uint32_t k, double p, uint32_t n) const; |
|
165 double CalculatePdOdd (double ber, unsigned int d) const; |
|
166 double CalculatePdEven (double ber, unsigned int d) const; |
|
167 double CalculatePd (double ber, unsigned int d) const; |
|
168 double GetFecBpskBer (double snr, double nbits, |
|
169 uint32_t signalSpread, uint32_t phyRate, |
|
170 uint32_t dFree, uint32_t adFree) const; |
|
171 double GetFecQamBer (double snr, uint32_t nbits, |
|
172 uint32_t signalSpread, |
|
173 uint32_t phyRate, |
|
174 uint32_t m, uint32_t dfree, |
|
175 uint32_t adFree, uint32_t adFreePlusOne) const; |
|
176 double GetChunkSuccessRate (WifiMode mode, double snr, uint32_t nbits) const; |
|
177 private: |
|
178 uint64_t m_txPrepareDelayUs; |
|
179 uint64_t m_plcpLongPreambleDelayUs; |
|
180 uint64_t m_plcpShortPreambleDelayUs; |
|
181 WifiMode m_longPlcpHeaderMode; |
|
182 WifiMode m_shortPlcpHeaderMode; |
|
183 uint32_t m_plcpHeaderLength; |
|
184 Time m_maxPacketDuration; |
|
185 |
|
186 double m_edThresholdW; /* unit: W */ |
|
187 double m_txGainDb; |
|
188 double m_rxGainDb; |
|
189 double m_rxNoiseRatio; |
|
190 double m_txPowerBaseDbm; |
|
191 double m_txPowerEndDbm; |
|
192 uint32_t m_nTxPower; |
|
193 |
|
194 |
|
195 bool m_syncing; |
|
196 Time m_endTx; |
|
197 Time m_endSync; |
|
198 Time m_endCcaBusy; |
|
199 Time m_startTx; |
|
200 Time m_startSync; |
|
201 Time m_startCcaBusy; |
|
202 Time m_previousStateChangeTime; |
|
203 |
|
204 Ptr<WifiChannel> m_channel; |
|
205 SyncOkCallback m_syncOkCallback; |
|
206 SyncErrorCallback m_syncErrorCallback; |
|
207 TracedCallback<Ptr<const Packet>, double, WifiMode, enum WifiPreamble> m_rxOkTrace; |
|
208 TracedCallback<Ptr<const Packet>, double> m_rxErrorTrace; |
|
209 TracedCallback<Ptr<const Packet>,WifiMode,WifiPreamble,uint8_t> m_txTrace; |
|
210 Modes m_modes; |
|
211 Listeners m_listeners; |
|
212 EventId m_endSyncEvent; |
|
213 Events m_events; |
|
214 UniformVariable m_random; |
|
215 TracedCallback<Time,Time,enum YansWifiPhy::State> m_stateLogger; |
|
216 WifiPhyStandard m_standard; |
|
217 }; |
|
218 |
|
219 } // namespace ns3 |
|
220 |
|
221 |
|
222 #endif /* YANS_WIFI_PHY_H */ |