LEFT | RIGHT |
(no file at all) | |
| 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2005,2006 INRIA |
| 4 * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. |
| 5 * |
| 6 * This program is free software; you can redistribute it and/or modify |
| 7 * it under the terms of the GNU General Public License version 2 as |
| 8 * published by the Free Software Foundation; |
| 9 * |
| 10 * This program is distributed in the hope that it will be useful, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 * GNU General Public License for more details. |
| 14 * |
| 15 * You should have received a copy of the GNU General Public License |
| 16 * along with this program; if not, write to the Free Software |
| 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 * |
| 19 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
| 20 * Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu> |
| 21 */ |
| 22 |
| 23 #ifndef NSL_WIFI_PHY_H |
| 24 #define NSL_WIFI_PHY_H |
| 25 |
| 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 "ns3/wifi-radio-energy-model.h" |
| 36 #include "ns3/wifi-phy.h" |
| 37 #include "ns3/wifi-mode.h" |
| 38 #include "ns3/wifi-preamble.h" |
| 39 #include "ns3/wifi-phy-standard.h" |
| 40 #include "ns3/interference-helper.h" |
| 41 #include "wireless-module-utility.h" |
| 42 |
| 43 namespace ns3 { |
| 44 |
| 45 class RandomUniform; |
| 46 class RxEvent; |
| 47 class NslWifiChannel; |
| 48 class WifiPhyStateHelper; |
| 49 class Node; |
| 50 |
| 51 /** |
| 52 * \brief 802.11 PHY layer model |
| 53 * |
| 54 * This PHY extends the Yans wifi PHY implemented previously and described in |
| 55 * "Yet Another Network Simulator", (http://cutebugs.net/files/wns2-yans.pdf). |
| 56 * |
| 57 * This is a duplication of YansWifiPhy with driver interfaces (functions) to |
| 58 * interface with WirelessModuleUtility class. |
| 59 */ |
| 60 class NslWifiPhy : public WifiPhy |
| 61 { |
| 62 public: |
| 63 static TypeId GetTypeId (void); |
| 64 NslWifiPhy (); |
| 65 virtual ~NslWifiPhy (); |
| 66 |
| 67 void SetChannel (Ptr<NslWifiChannel> channel); |
| 68 |
| 69 /** |
| 70 * \brief Set channel number. |
| 71 * |
| 72 * Channel center frequency = Channel starting frequency + 5 MHz * (nch - 1) |
| 73 * |
| 74 * where Starting channel frequency is standard-dependent, see SetStandard() |
| 75 * as defined in IEEE 802.11-2007 17.3.8.3.2. |
| 76 * |
| 77 * NslWifiPhy can switch among different channels. Basically, NslWifiPhy has |
| 78 * a private attribute m_channelNumber that identifies the channel the PHY |
| 79 * operates on. Channel switching cannot interrupt an ongoing transmission. |
| 80 * When PHY is in TX state, the channel switching is postponed until the end |
| 81 * of the current transmission. When the PHY is in SYNC state, the channel |
| 82 * switching causes the drop of the sync packet. |
| 83 */ |
| 84 void SetChannelNumber (uint16_t id); |
| 85 /** |
| 86 * Return current channel number, see SetChannelNumber(). |
| 87 */ |
| 88 uint16_t GetChannelNumber () const; |
| 89 /** |
| 90 * Return current center channel frequency in MHz, see SetСhannelNumber() |
| 91 */ |
| 92 double GetChannelFrequencyMhz() const; |
| 93 |
| 94 /** |
| 95 * Overwrites the original function in YansWifiPhy to insert driver. |
| 96 */ |
| 97 void StartReceivePacket (Ptr<Packet> packet, |
| 98 double rxPowerDbm, |
| 99 WifiMode mode, |
| 100 WifiPreamble preamble); |
| 101 |
| 102 void SetRxNoiseFigure (double noiseFigureDb); |
| 103 void SetTxPowerStart (double start); |
| 104 void SetTxPowerEnd (double end); |
| 105 void SetNTxPower (uint32_t n); |
| 106 void SetTxGain (double gain); |
| 107 void SetRxGain (double gain); |
| 108 void SetEdThreshold (double threshold); |
| 109 void SetCcaMode1Threshold (double threshold); |
| 110 void SetErrorRateModel (Ptr<ErrorRateModel> rate); |
| 111 void SetDevice (Ptr<Object> device); |
| 112 void SetMobility (Ptr<Object> mobility); |
| 113 double GetRxNoiseFigure (void) const; |
| 114 double GetTxGain (void) const; |
| 115 double GetRxGain (void) const; |
| 116 double GetEdThreshold (void) const; |
| 117 double GetCcaMode1Threshold (void) const; |
| 118 Ptr<ErrorRateModel> GetErrorRateModel (void) const; |
| 119 Ptr<Object> GetDevice (void) const; |
| 120 Ptr<Object> GetMobility (void); |
| 121 |
| 122 double GetTxPowerStart (void) const; |
| 123 double GetTxPowerEnd (void) const; |
| 124 uint32_t GetNTxPower (void) const; |
| 125 void SetReceiveOkCallback (WifiPhy::RxOkCallback callback); |
| 126 void SetReceiveErrorCallback (WifiPhy::RxErrorCallback callback); |
| 127 void SendPacket (Ptr<const Packet> packet, WifiMode mode, enum WifiPreamble pr
eamble, uint8_t txPowerLevel); |
| 128 void RegisterListener (WifiPhyListener *listener); |
| 129 bool IsStateCcaBusy (void); |
| 130 bool IsStateIdle (void); |
| 131 bool IsStateBusy (void); |
| 132 bool IsStateRx (void); |
| 133 bool IsStateTx (void); |
| 134 bool IsStateSwitching (void); |
| 135 Time GetStateDuration (void); |
| 136 Time GetDelayUntilIdle (void); |
| 137 virtual Time GetLastRxStartTime (void) const; |
| 138 uint32_t GetNModes (void) const; |
| 139 WifiMode GetMode (uint32_t mode) const; |
| 140 double CalculateSnr (WifiMode txMode, double ber) const; |
| 141 Ptr<WifiChannel> GetChannel (void) const; |
| 142 void ConfigureStandard (enum WifiPhyStandard standard); |
| 143 |
| 144 // Driver related public functions. |
| 145 /** |
| 146 * \param node Pointer to the node where PHY is being installed. |
| 147 * |
| 148 * This function sets the pointer to the node where PHY is being installed. |
| 149 */ |
| 150 void SetNode (Ptr<Node> node); |
| 151 ·· |
| 152 /** |
| 153 * \returns Current RSS reading at node, in Watts. |
| 154 * |
| 155 * This function measures RSS (in Watts), used as callback in utility module. |
| 156 * It is made public such that other layers can query for current RSS reading |
| 157 * as well. |
| 158 */ |
| 159 double MeasureRss (void); |
| 160 |
| 161 |
| 162 private: |
| 163 typedef std::vector<WifiMode> Modes; |
| 164 |
| 165 private: |
| 166 NslWifiPhy (const NslWifiPhy &o); |
| 167 void DoDispose (void); |
| 168 void Configure80211a (void); |
| 169 void Configure80211b (void); |
| 170 void Configure80211_10Mhz (void); |
| 171 void Configure80211_5Mhz (); |
| 172 void ConfigureHolland (void); |
| 173 void Configure80211p_CCH (void); |
| 174 void Configure80211p_SCH (void); |
| 175 double GetEdThresholdW (void) const; |
| 176 double DbmToW (double dbm) const; |
| 177 double DbToRatio (double db) const; |
| 178 double WToDbm (double w) const; |
| 179 double RatioToDb (double ratio) const; |
| 180 double GetPowerDbm (uint8_t power) const; |
| 181 /** |
| 182 * Overwrites the original function in YansWifiPhy to insert driver |
| 183 */ |
| 184 void EndReceive (Ptr<Packet> packet, Ptr<InterferenceHelper::Event> event); |
| 185 |
| 186 /* |
| 187 * Driver functions. |
| 188 */ |
| 189 void DoStart (void); |
| 190 |
| 191 /** |
| 192 * Resets driver. Called at DoDispose. |
| 193 */ |
| 194 void ResetDriver (void); |
| 195 /** |
| 196 * Initializes driver. Setting pointers to utility and energy model. |
| 197 */ |
| 198 void InitDriver (void); |
| 199 |
| 200 /** |
| 201 * \brief Driver function invoked at start of TX. |
| 202 * |
| 203 * \param packet Pointer to packet being sent. |
| 204 * \param txPower TX power. |
| 205 * |
| 206 * This function is called at SendPacket, for interfacing with the energy and |
| 207 * utility modules. |
| 208 */ |
| 209 void DriverStartTx (Ptr<const Packet> packet, double txPower); |
| 210 |
| 211 /** |
| 212 * \brief Driver functions invoked at end of TX, scheduled by DriverStartTx. |
| 213 * |
| 214 * \param packet Pointer to packet being sent. |
| 215 * \param txPower TX power used for transmission. |
| 216 */ |
| 217 void DriverEndTx (Ptr<const Packet> packet, double txPower); |
| 218 |
| 219 /** |
| 220 * \brief Driver function invoked at start of RX. |
| 221 * |
| 222 * \param packet Pointer to packet being received. |
| 223 * \param startRssW RSS reading at start of the packet, in Watts. |
| 224 * \returns True if the packet is to be received, false if we are to skip the |
| 225 * packet (eg. reactive jammer). |
| 226 */ |
| 227 bool DriverStartRx (Ptr<Packet> packet, double startRssW); |
| 228 |
| 229 /** |
| 230 * \brief Driver function invoked at end of RX. |
| 231 * |
| 232 * \param packet Pointer to packet received. |
| 233 * \param averageRssW Average RSS for the received packet, in Watts. |
| 234 * \param isSuccessfullyReceived True if packet is successfully received. |
| 235 */ |
| 236 void DriverEndRx (Ptr<Packet> packet, double averageRssW, |
| 237 const bool isSuccessfullyReceived); |
| 238 |
| 239 /** |
| 240 * \param mode Current WifiMode being used in channel. |
| 241 * |
| 242 * This function sets the current wifi mode. Called at beginning of every |
| 243 * StartReceivePacket function. It is used to keep a latest copy of WifiMode |
| 244 * being used in by the channel. |
| 245 */ |
| 246 void SetCurrentWifiMode (WifiMode mode); |
| 247 ·· |
| 248 /** |
| 249 * \param packet Pointer to packet to be sent. |
| 250 * \param powerW Sending power, in watts. |
| 251 * \param utilitySendMode sending mode set by Utility - enum in Utility |
| 252 *· |
| 253 * This function sends packet at a given power (W). It converts the power to |
| 254 * corresponding power levels internally and calls SendPacket to send. Used |
| 255 * as callback in Utility module. |
| 256 */ |
| 257 void UtilitySendPacket (Ptr<Packet> packet, double &powerW, int utilitySendMod
e); |
| 258 |
| 259 /** |
| 260 * This function updates PHY layer information & informs utility. |
| 261 */ |
| 262 void UpdatePhyLayerInfo (void); |
| 263 |
| 264 /** |
| 265 * \param callback Callback to notify radio energy model of state change. |
| 266 * |
| 267 * This function sets the callback to notify radio energy model when radio |
| 268 * state changes. |
| 269 */ |
| 270 void SetChangeRadioStateCallback (DeviceEnergyModel::ChangeStateCallback callb
ack); |
| 271 |
| 272 private: |
| 273 double m_edThresholdW; |
| 274 double m_ccaMode1ThresholdW; |
| 275 double m_txGainDb; |
| 276 double m_rxGainDb; |
| 277 double m_txPowerBaseDbm; |
| 278 double m_txPowerEndDbm; |
| 279 uint32_t m_nTxPower; |
| 280 |
| 281 Ptr<NslWifiChannel> m_channel; |
| 282 uint16_t m_channelNumber; |
| 283 Ptr<Object> m_device; |
| 284 Ptr<Object> m_mobility; |
| 285 Modes m_modes; |
| 286 EventId m_endRxEvent; |
| 287 UniformVariable m_random; |
| 288 /// Standard-dependent center frequency of 0-th channel, MHz |
| 289 double m_channelStartingFrequency; |
| 290 Ptr<WifiPhyStateHelper> m_state; |
| 291 InterferenceHelper m_interference; |
| 292 Time m_channelSwitchDelay; |
| 293 |
| 294 /* |
| 295 * Driver variables |
| 296 */ |
| 297 bool m_isDriverInitialized; // flag indicating if driver is initialized |
| 298 Ptr<Node> m_node; // pointer to the node where the PHY is installed |
| 299 Ptr<WirelessModuleUtility> m_utility; // pointer to utility object |
| 300 WifiMode m_currentWifiMode; // current wifi mode |
| 301 WirelessModuleUtility::PhyLayerInfo m_phyLayerInfo; // PHY layer info |
| 302 }; |
| 303 |
| 304 } // namespace ns3 |
| 305 |
| 306 #endif /* NSL_WIFI_PHY_H */ |
LEFT | RIGHT |