00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2005,2006,2007 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 * Contributions: Timo Bingmann <timo.bingmann@student.kit.edu> 00020 */ 00021 00022 #ifndef PROPAGATION_LOSS_MODEL_H 00023 #define PROPAGATION_LOSS_MODEL_H 00024 00025 #include "ns3/object.h" 00026 #include "ns3/random-variable.h" 00027 00028 namespace ns3 { 00029 00030 class MobilityModel; 00031 00032 /** 00033 * \brief Modelize the propagation loss through a transmission medium 00034 * 00035 * Calculate the receive power (dbm) from a transmit power (dbm) 00036 * and a mobility model for the source and destination positions. 00037 */ 00038 class PropagationLossModel : public Object 00039 { 00040 public: 00041 static TypeId GetTypeId (void); 00042 00043 PropagationLossModel (); 00044 virtual ~PropagationLossModel (); 00045 00046 void SetNext (Ptr<PropagationLossModel> next); 00047 00048 /** 00049 * \param txPowerDbm current transmission power (in dBm) 00050 * \param a the mobility model of the source 00051 * \param b the mobility model of the destination 00052 * \returns the reception power after adding/multiplying propagation loss (in dBm) 00053 */ 00054 double CalcRxPower (double txPowerDbm, 00055 Ptr<MobilityModel> a, 00056 Ptr<MobilityModel> b) const; 00057 private: 00058 PropagationLossModel (const PropagationLossModel &o); 00059 PropagationLossModel &operator = (const PropagationLossModel &o); 00060 virtual double DoCalcRxPower (double txPowerDbm, 00061 Ptr<MobilityModel> a, 00062 Ptr<MobilityModel> b) const = 0; 00063 00064 Ptr<PropagationLossModel> m_next; 00065 }; 00066 00067 /** 00068 * \brief The propagation loss follows a random distribution. 00069 */ 00070 class RandomPropagationLossModel : public PropagationLossModel 00071 { 00072 public: 00073 static TypeId GetTypeId (void); 00074 00075 RandomPropagationLossModel (); 00076 virtual ~RandomPropagationLossModel (); 00077 00078 private: 00079 RandomPropagationLossModel (const RandomPropagationLossModel &o); 00080 RandomPropagationLossModel & operator = (const RandomPropagationLossModel &o); 00081 virtual double DoCalcRxPower (double txPowerDbm, 00082 Ptr<MobilityModel> a, 00083 Ptr<MobilityModel> b) const; 00084 RandomVariable m_variable; 00085 }; 00086 00087 /** 00088 * \brief a Friis propagation loss model 00089 * 00090 * The Friis propagation loss model was first described in 00091 * "A Note on a Simple Transmission Formula", by 00092 * "Harald T. Friis". 00093 * 00094 * The original equation was described as: 00095 * \f$ \frac{P_r}{P_t} = \frac{A_r A_t}{d^2\lambda^2} \f$ 00096 * with the following equation for the case of an 00097 * isotropic antenna with no heat loss: 00098 * \f$ A_{isotr.} = \frac{\lambda^2}{4\pi} \f$ 00099 * 00100 * The final equation becomes: 00101 * \f$ \frac{P_r}{P_t} = \frac{\lambda^2}{(4 \pi d)^2} \f$ 00102 * 00103 * Modern extensions to this original equation are: 00104 * \f$ P_r = \frac{P_t G_t G_r \lambda^2}{(4 \pi d)^2 L}\f$ 00105 * 00106 * With: 00107 * - \f$ P_r \f$ : reception power (W) 00108 * - \f$ P_t \f$ : transmission power (W) 00109 * - \f$ G_t \f$ : transmission gain (unit-less) 00110 * - \f$ G_r \f$ : reception gain (unit-less) 00111 * - \f$ \lambda \f$ : wavelength (m) 00112 * - \f$ d \f$ : distance (m) 00113 * - \f$ L \f$ : system loss (unit-less) 00114 * 00115 * 00116 * This model is invalid for small distance values. 00117 * The current implementation returns the txpower as the rxpower 00118 * for any distance smaller than MinDistance. 00119 */ 00120 class FriisPropagationLossModel : public PropagationLossModel 00121 { 00122 public: 00123 static TypeId GetTypeId (void); 00124 FriisPropagationLossModel (); 00125 /** 00126 * \param frequency (Hz) 00127 * \param speed (m/s) 00128 * 00129 * Set the main wavelength used in the Friis model 00130 * calculation. 00131 */ 00132 void SetLambda (double frequency, double speed); 00133 /** 00134 * \param lambda (m) the wavelength 00135 * 00136 * Set the main wavelength used in the Friis model 00137 * calculation. 00138 */ 00139 void SetLambda (double lambda); 00140 /** 00141 * \param systemLoss (dimension-less) 00142 * 00143 * Set the system loss used by the Friis propagation model. 00144 */ 00145 void SetSystemLoss (double systemLoss); 00146 00147 /** 00148 * \param minDistance the minimum distance 00149 * 00150 * Below this distance, the txpower is returned 00151 * unmodified as the rxpower. 00152 */ 00153 void SetMinDistance (double minDistance); 00154 00155 /** 00156 * \returns the minimum distance. 00157 */ 00158 double GetMinDistance (void) const; 00159 00160 /** 00161 * \returns the current wavelength (m) 00162 */ 00163 double GetLambda (void) const; 00164 /** 00165 * \returns the current system loss (dimention-less) 00166 */ 00167 double GetSystemLoss (void) const; 00168 00169 private: 00170 FriisPropagationLossModel (const FriisPropagationLossModel &o); 00171 FriisPropagationLossModel & operator = (const FriisPropagationLossModel &o); 00172 virtual double DoCalcRxPower (double txPowerDbm, 00173 Ptr<MobilityModel> a, 00174 Ptr<MobilityModel> b) const; 00175 double DbmToW (double dbm) const; 00176 double DbmFromW (double w) const; 00177 00178 static const double PI; 00179 double m_lambda; 00180 double m_systemLoss; 00181 double m_minDistance; 00182 }; 00183 00184 /** 00185 * \brief a log distance propagation model. 00186 * 00187 * This model calculates the reception power with a so-called 00188 * log-distance propagation model: 00189 * \f$ L = L_0 + 10 n log_{10}(\frac{d}{d_0})\f$ 00190 * 00191 * where: 00192 * - \f$ n \f$ : the path loss distance exponent 00193 * - \f$ d_0 \f$ : reference distance (m) 00194 * - \f$ L_0 \f$ : path loss at reference distance (dB) 00195 * - \f$ d \f$ : distance (m) 00196 * - \f$ L \f$ : path loss (dB) 00197 * 00198 * When the path loss is requested at a distance smaller than 00199 * the reference distance, the tx power is returned. 00200 * 00201 */ 00202 class LogDistancePropagationLossModel : public PropagationLossModel 00203 { 00204 public: 00205 static TypeId GetTypeId (void); 00206 LogDistancePropagationLossModel (); 00207 00208 /** 00209 * \param n the path loss exponent. 00210 * Set the path loss exponent. 00211 */ 00212 void SetPathLossExponent (double n); 00213 /** 00214 * \returns the current path loss exponent. 00215 */ 00216 double GetPathLossExponent (void) const; 00217 00218 void SetReference (double referenceDistance, double referenceLoss); 00219 00220 private: 00221 LogDistancePropagationLossModel (const LogDistancePropagationLossModel &o); 00222 LogDistancePropagationLossModel & operator = (const LogDistancePropagationLossModel &o); 00223 virtual double DoCalcRxPower (double txPowerDbm, 00224 Ptr<MobilityModel> a, 00225 Ptr<MobilityModel> b) const; 00226 static Ptr<PropagationLossModel> CreateDefaultReference (void); 00227 00228 double m_exponent; 00229 double m_referenceDistance; 00230 double m_referenceLoss; 00231 }; 00232 00233 /** 00234 * \brief A log distance path loss propagation model with three distance 00235 * fields. This model is the same as ns3::LogDistancePropagationLossModel 00236 * except that it has three distance fields: near, middle and far with 00237 * different exponents. 00238 * 00239 * Within each field the reception power is calculated using the log-distance 00240 * propagation equation: 00241 * \f[ L = L_0 + 10 \cdot n_0 log_{10}(\frac{d}{d_0})\f] 00242 * Each field begins where the previous ends and all together form a continuous function. 00243 * 00244 * There are three valid distance fields: near, middle, far. Actually four: the 00245 * first from 0 to the reference distance is invalid and returns txPowerDbm. 00246 * 00247 * \f[ \underbrace{0 \cdots\cdots}_{=0} \underbrace{d_0 \cdots\cdots}_{n_0} \underbrace{d_1 \cdots\cdots}_{n_1} \underbrace{d_2 \cdots\cdots}_{n_2} \infty \f] 00248 * 00249 * Complete formula for the path loss in dB: 00250 * 00251 * \f[\displaystyle L = 00252 \begin{cases} 00253 0 & d < d_0 \\ 00254 L_0 + 10 \cdot n_0 \log_{10}(\frac{d}{d_0}) & d_0 \leq d < d_1 \\ 00255 L_0 + 10 \cdot n_0 \log_{10}(\frac{d_1}{d_0}) + 10 \cdot n_1 \log_{10}(\frac{d}{d_1}) & d_1 \leq d < d_2 \\ 00256 L_0 + 10 \cdot n_0 \log_{10}(\frac{d_1}{d_0}) + 10 \cdot n_1 \log_{10}(\frac{d_2}{d_1}) + 10 \cdot n_2 \log_{10}(\frac{d}{d_2})& d_2 \leq d 00257 \end{cases}\f] 00258 * 00259 * where: 00260 * - \f$ L \f$ : resulting path loss (dB) 00261 * - \f$ d \f$ : distance (m) 00262 * - \f$ d_0, d_1, d_2 \f$ : three distance fields (m) 00263 * - \f$ n_0, n_1, n_2 \f$ : path loss distance exponent for each field (unitless) 00264 * - \f$ L_0 \f$ : path loss at reference distance (dB) 00265 * 00266 * When the path loss is requested at a distance smaller than the reference 00267 * distance \f$ d_0 \f$, the tx power (with no path loss) is returned. The 00268 * reference distance defaults to 1m and reference loss defaults to 00269 * ns3::FriisPropagationLossModel with 5.15 GHz and is thus \f$ L_0 \f$ = 46.67 dB. 00270 */ 00271 00272 class ThreeLogDistancePropagationLossModel : public PropagationLossModel 00273 { 00274 public: 00275 static TypeId GetTypeId (void); 00276 ThreeLogDistancePropagationLossModel (); 00277 00278 // Parameters are all accessible via attributes. 00279 00280 private: 00281 ThreeLogDistancePropagationLossModel (const ThreeLogDistancePropagationLossModel& o); 00282 ThreeLogDistancePropagationLossModel& operator= (const ThreeLogDistancePropagationLossModel& o); 00283 00284 virtual double DoCalcRxPower (double txPowerDbm, 00285 Ptr<MobilityModel> a, 00286 Ptr<MobilityModel> b) const; 00287 00288 double m_distance0; 00289 double m_distance1; 00290 double m_distance2; 00291 00292 double m_exponent0; 00293 double m_exponent1; 00294 double m_exponent2; 00295 00296 double m_referenceLoss; 00297 }; 00298 00299 /** 00300 * \brief Nakagami-m fast fading propagation loss model. 00301 * 00302 * The Nakagami-m distribution is applied to the power level. The probability 00303 * density function is defined as 00304 * \f[ p(x; m, \omega) = \frac{2 m^m}{\Gamma(m) \omega^m} x^{2m - 1} e^{-\frac{m}{\omega} x^2} = 2 x \cdot p_{\text{Gamma}}(x^2, m, \frac{m}{\omega}) \f] 00305 * with \f$ m \f$ the fading depth parameter and \f$ \omega \f$ the average received power. 00306 * 00307 * It is implemented by either a ns3::GammaVariable or a ns3::ErlangVariable 00308 * random variable. 00309 * 00310 * Like in ns3::ThreeLogDistancePropagationLossModel, the m parameter is varied 00311 * over three distance fields: 00312 * \f[ \underbrace{0 \cdots\cdots}_{m_0} \underbrace{d_1 \cdots\cdots}_{m_1} \underbrace{d_2 \cdots\cdots}_{m_2} \infty \f] 00313 * 00314 * For m = 1 the Nakagami-m distribution equals the Rayleigh distribution. Thus 00315 * this model also implements Rayleigh distribution based fast fading. 00316 */ 00317 00318 class NakagamiPropagationLossModel : public PropagationLossModel 00319 { 00320 public: 00321 static TypeId GetTypeId (void); 00322 00323 NakagamiPropagationLossModel (); 00324 00325 // Parameters are all accessible via attributes. 00326 00327 private: 00328 NakagamiPropagationLossModel (const NakagamiPropagationLossModel& o); 00329 NakagamiPropagationLossModel& operator= (const NakagamiPropagationLossModel& o); 00330 00331 virtual double DoCalcRxPower (double txPowerDbm, 00332 Ptr<MobilityModel> a, 00333 Ptr<MobilityModel> b) const; 00334 00335 double m_distance1; 00336 double m_distance2; 00337 00338 double m_m0; 00339 double m_m1; 00340 double m_m2; 00341 }; 00342 00343 } // namespace ns3 00344 00345 #endif /* PROPAGATION_LOSS_MODEL_H */