A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
propagation-loss-model.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006,2007 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  * Contributions: Timo Bingmann <timo.bingmann@student.kit.edu>
20  * Contributions: Tom Hewer <tomhewer@mac.com> for Two Ray Ground Model
21  * Pavel Boyko <boyko@iitp.ru> for matrix
22  */
23 
24 #include "propagation-loss-model.h"
25 #include "ns3/log.h"
26 #include "ns3/mobility-model.h"
27 #include "ns3/boolean.h"
28 #include "ns3/double.h"
29 #include "ns3/string.h"
30 #include "ns3/pointer.h"
31 #include <cmath>
32 
33 NS_LOG_COMPONENT_DEFINE ("PropagationLossModel");
34 
35 namespace ns3 {
36 
37 // ------------------------------------------------------------------------- //
38 
39 NS_OBJECT_ENSURE_REGISTERED (PropagationLossModel);
40 
41 TypeId
42 PropagationLossModel::GetTypeId (void)
43 {
44  static TypeId tid = TypeId ("ns3::PropagationLossModel")
45  .SetParent<Object> ()
46  ;
47  return tid;
48 }
49 
50 PropagationLossModel::PropagationLossModel ()
51  : m_next (0)
52 {
53 }
54 
55 PropagationLossModel::~PropagationLossModel ()
56 {
57 }
58 
59 void
60 PropagationLossModel::SetNext (Ptr<PropagationLossModel> next)
61 {
62  m_next = next;
63 }
64 
66 PropagationLossModel::GetNext ()
67 {
68  return m_next;
69 }
70 
71 double
72 PropagationLossModel::CalcRxPower (double txPowerDbm,
74  Ptr<MobilityModel> b) const
75 {
76  double self = DoCalcRxPower (txPowerDbm, a, b);
77  if (m_next != 0)
78  {
79  self = m_next->CalcRxPower (self, a, b);
80  }
81  return self;
82 }
83 
84 int64_t
85 PropagationLossModel::AssignStreams (int64_t stream)
86 {
87  int64_t currentStream = stream;
88  currentStream += DoAssignStreams (stream);
89  if (m_next != 0)
90  {
91  currentStream += m_next->AssignStreams (currentStream);
92  }
93  return (currentStream - stream);
94 }
95 
96 // ------------------------------------------------------------------------- //
97 
98 NS_OBJECT_ENSURE_REGISTERED (RandomPropagationLossModel);
99 
100 TypeId
101 RandomPropagationLossModel::GetTypeId (void)
102 {
103  static TypeId tid = TypeId ("ns3::RandomPropagationLossModel")
105  .AddConstructor<RandomPropagationLossModel> ()
106  .AddAttribute ("Variable", "The random variable used to pick a loss everytime CalcRxPower is invoked.",
107  StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"),
108  MakePointerAccessor (&RandomPropagationLossModel::m_variable),
109  MakePointerChecker<RandomVariableStream> ())
110  ;
111  return tid;
112 }
113 RandomPropagationLossModel::RandomPropagationLossModel ()
114  : PropagationLossModel ()
115 {
116 }
117 
118 RandomPropagationLossModel::~RandomPropagationLossModel ()
119 {
120 }
121 
122 double
123 RandomPropagationLossModel::DoCalcRxPower (double txPowerDbm,
124  Ptr<MobilityModel> a,
125  Ptr<MobilityModel> b) const
126 {
127  double rxc = -m_variable->GetValue ();
128  NS_LOG_DEBUG ("attenuation coefficent="<<rxc<<"Db");
129  return txPowerDbm + rxc;
130 }
131 
132 int64_t
134 {
135  m_variable->SetStream (stream);
136  return 1;
137 }
138 
139 // ------------------------------------------------------------------------- //
140 
141 NS_OBJECT_ENSURE_REGISTERED (FriisPropagationLossModel);
142 
143 const double FriisPropagationLossModel::PI = 3.14159265358979323846;
144 
145 TypeId
146 FriisPropagationLossModel::GetTypeId (void)
147 {
148  static TypeId tid = TypeId ("ns3::FriisPropagationLossModel")
150  .AddConstructor<FriisPropagationLossModel> ()
151  .AddAttribute ("Frequency",
152  "The carrier frequency (in Hz) at which propagation occurs (default is 5.15 GHz).",
153  DoubleValue (5.150e9),
154  MakeDoubleAccessor (&FriisPropagationLossModel::SetFrequency,
156  MakeDoubleChecker<double> ())
157  .AddAttribute ("SystemLoss", "The system loss",
158  DoubleValue (1.0),
159  MakeDoubleAccessor (&FriisPropagationLossModel::m_systemLoss),
160  MakeDoubleChecker<double> ())
161  .AddAttribute ("MinDistance",
162  "The distance under which the propagation model refuses to give results (m)",
163  DoubleValue (0.5),
164  MakeDoubleAccessor (&FriisPropagationLossModel::SetMinDistance,
166  MakeDoubleChecker<double> ())
167  ;
168  return tid;
169 }
170 
171 FriisPropagationLossModel::FriisPropagationLossModel ()
172 {
173 }
174 void
176 {
177  m_systemLoss = systemLoss;
178 }
179 double
181 {
182  return m_systemLoss;
183 }
184 void
186 {
187  m_minDistance = minDistance;
188 }
189 double
191 {
192  return m_minDistance;
193 }
194 
195 void
197 {
198  m_frequency = frequency;
199  static const double C = 299792458.0; // speed of light in vacuum
200  m_lambda = C / frequency;
201 }
202 
203 double
205 {
206  return m_frequency;
207 }
208 
209 double
210 FriisPropagationLossModel::DbmToW (double dbm) const
211 {
212  double mw = std::pow (10.0,dbm/10.0);
213  return mw / 1000.0;
214 }
215 
216 double
217 FriisPropagationLossModel::DbmFromW (double w) const
218 {
219  double dbm = std::log10 (w * 1000.0) * 10.0;
220  return dbm;
221 }
222 
223 double
224 FriisPropagationLossModel::DoCalcRxPower (double txPowerDbm,
225  Ptr<MobilityModel> a,
226  Ptr<MobilityModel> b) const
227 {
228  /*
229  * Friis free space equation:
230  * where Pt, Gr, Gr and P are in Watt units
231  * L is in meter units.
232  *
233  * P Gt * Gr * (lambda^2)
234  * --- = ---------------------
235  * Pt (4 * pi * d)^2 * L
236  *
237  * Gt: tx gain (unit-less)
238  * Gr: rx gain (unit-less)
239  * Pt: tx power (W)
240  * d: distance (m)
241  * L: system loss
242  * lambda: wavelength (m)
243  *
244  * Here, we ignore tx and rx gain and the input and output values
245  * are in dB or dBm:
246  *
247  * lambda^2
248  * rx = tx + 10 log10 (-------------------)
249  * (4 * pi * d)^2 * L
250  *
251  * rx: rx power (dB)
252  * tx: tx power (dB)
253  * d: distance (m)
254  * L: system loss (unit-less)
255  * lambda: wavelength (m)
256  */
257  double distance = a->GetDistanceFrom (b);
258  if (distance <= m_minDistance)
259  {
260  return txPowerDbm;
261  }
262  double numerator = m_lambda * m_lambda;
263  double denominator = 16 * PI * PI * distance * distance * m_systemLoss;
264  double pr = 10 * std::log10 (numerator / denominator);
265  NS_LOG_DEBUG ("distance="<<distance<<"m, attenuation coefficient="<<pr<<"dB");
266  return txPowerDbm + pr;
267 }
268 
269 int64_t
271 {
272  return 0;
273 }
274 
275 // ------------------------------------------------------------------------- //
276 // -- Two-Ray Ground Model ported from NS-2 -- tomhewer@mac.com -- Nov09 //
277 
278 NS_OBJECT_ENSURE_REGISTERED (TwoRayGroundPropagationLossModel);
279 
280 const double TwoRayGroundPropagationLossModel::PI = 3.14159265358979323846;
281 
282 TypeId
283 TwoRayGroundPropagationLossModel::GetTypeId (void)
284 {
285  static TypeId tid = TypeId ("ns3::TwoRayGroundPropagationLossModel")
287  .AddConstructor<TwoRayGroundPropagationLossModel> ()
288  .AddAttribute ("Frequency",
289  "The carrier frequency (in Hz) at which propagation occurs (default is 5.15 GHz).",
290  DoubleValue (5.150e9),
293  MakeDoubleChecker<double> ())
294  .AddAttribute ("SystemLoss", "The system loss",
295  DoubleValue (1.0),
296  MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::m_systemLoss),
297  MakeDoubleChecker<double> ())
298  .AddAttribute ("MinDistance",
299  "The distance under which the propagation model refuses to give results (m)",
300  DoubleValue (0.5),
303  MakeDoubleChecker<double> ())
304  .AddAttribute ("HeightAboveZ",
305  "The height of the antenna (m) above the node's Z coordinate",
306  DoubleValue (0),
307  MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::m_heightAboveZ),
308  MakeDoubleChecker<double> ())
309  ;
310  return tid;
311 }
312 
313 TwoRayGroundPropagationLossModel::TwoRayGroundPropagationLossModel ()
314 {
315 }
316 void
318 {
319  m_systemLoss = systemLoss;
320 }
321 double
323 {
324  return m_systemLoss;
325 }
326 void
328 {
329  m_minDistance = minDistance;
330 }
331 double
333 {
334  return m_minDistance;
335 }
336 void
338 {
339  m_heightAboveZ = heightAboveZ;
340 }
341 
342 void
344 {
345  m_frequency = frequency;
346  static const double C = 299792458.0; // speed of light in vacuum
347  m_lambda = C / frequency;
348 }
349 
350 double
352 {
353  return m_frequency;
354 }
355 
356 double
357 TwoRayGroundPropagationLossModel::DbmToW (double dbm) const
358 {
359  double mw = std::pow (10.0,dbm / 10.0);
360  return mw / 1000.0;
361 }
362 
363 double
364 TwoRayGroundPropagationLossModel::DbmFromW (double w) const
365 {
366  double dbm = std::log10 (w * 1000.0) * 10.0;
367  return dbm;
368 }
369 
370 double
371 TwoRayGroundPropagationLossModel::DoCalcRxPower (double txPowerDbm,
372  Ptr<MobilityModel> a,
373  Ptr<MobilityModel> b) const
374 {
375  /*
376  * Two-Ray Ground equation:
377  *
378  * where Pt, Gt and Gr are in dBm units
379  * L, Ht and Hr are in meter units.
380  *
381  * Pr Gt * Gr * (Ht^2 * Hr^2)
382  * -- = (-------------------------)
383  * Pt d^4 * L
384  *
385  * Gt: tx gain (unit-less)
386  * Gr: rx gain (unit-less)
387  * Pt: tx power (dBm)
388  * d: distance (m)
389  * L: system loss
390  * Ht: Tx antenna height (m)
391  * Hr: Rx antenna height (m)
392  * lambda: wavelength (m)
393  *
394  * As with the Friis model we ignore tx and rx gain and output values
395  * are in dB or dBm
396  *
397  * (Ht * Ht) * (Hr * Hr)
398  * rx = tx + 10 log10 (-----------------------)
399  * (d * d * d * d) * L
400  */
401  double distance = a->GetDistanceFrom (b);
402  if (distance <= m_minDistance)
403  {
404  return txPowerDbm;
405  }
406 
407  // Set the height of the Tx and Rx antennae
408  double txAntHeight = a->GetPosition ().z + m_heightAboveZ;
409  double rxAntHeight = b->GetPosition ().z + m_heightAboveZ;
410 
411  // Calculate a crossover distance, under which we use Friis
412  /*
413  *
414  * dCross = (4 * pi * Ht * Hr) / lambda
415  *
416  */
417 
418  double dCross = (4 * PI * txAntHeight * rxAntHeight) / m_lambda;
419  double tmp = 0;
420  if (distance <= dCross)
421  {
422  // We use Friis
423  double numerator = m_lambda * m_lambda;
424  tmp = PI * distance;
425  double denominator = 16 * tmp * tmp * m_systemLoss;
426  double pr = 10 * std::log10 (numerator / denominator);
427  NS_LOG_DEBUG ("Receiver within crossover (" << dCross << "m) for Two_ray path; using Friis");
428  NS_LOG_DEBUG ("distance=" << distance << "m, attenuation coefficient=" << pr << "dB");
429  return txPowerDbm + pr;
430  }
431  else // Use Two-Ray Pathloss
432  {
433  tmp = txAntHeight * rxAntHeight;
434  double rayNumerator = tmp * tmp;
435  tmp = distance * distance;
436  double rayDenominator = tmp * tmp * m_systemLoss;
437  double rayPr = 10 * std::log10 (rayNumerator / rayDenominator);
438  NS_LOG_DEBUG ("distance=" << distance << "m, attenuation coefficient=" << rayPr << "dB");
439  return txPowerDbm + rayPr;
440 
441  }
442 }
443 
444 int64_t
446 {
447  return 0;
448 }
449 
450 // ------------------------------------------------------------------------- //
451 
452 NS_OBJECT_ENSURE_REGISTERED (LogDistancePropagationLossModel);
453 
454 TypeId
455 LogDistancePropagationLossModel::GetTypeId (void)
456 {
457  static TypeId tid = TypeId ("ns3::LogDistancePropagationLossModel")
459  .AddConstructor<LogDistancePropagationLossModel> ()
460  .AddAttribute ("Exponent",
461  "The exponent of the Path Loss propagation model",
462  DoubleValue (3.0),
463  MakeDoubleAccessor (&LogDistancePropagationLossModel::m_exponent),
464  MakeDoubleChecker<double> ())
465  .AddAttribute ("ReferenceDistance",
466  "The distance at which the reference loss is calculated (m)",
467  DoubleValue (1.0),
468  MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceDistance),
469  MakeDoubleChecker<double> ())
470  .AddAttribute ("ReferenceLoss",
471  "The reference loss at reference distance (dB). (Default is Friis at 1m with 5.15 GHz)",
472  DoubleValue (46.6777),
473  MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceLoss),
474  MakeDoubleChecker<double> ())
475  ;
476  return tid;
477 
478 }
479 
480 LogDistancePropagationLossModel::LogDistancePropagationLossModel ()
481 {
482 }
483 
484 void
486 {
487  m_exponent = n;
488 }
489 void
490 LogDistancePropagationLossModel::SetReference (double referenceDistance, double referenceLoss)
491 {
492  m_referenceDistance = referenceDistance;
493  m_referenceLoss = referenceLoss;
494 }
495 double
497 {
498  return m_exponent;
499 }
500 
501 double
504  Ptr<MobilityModel> b) const
505 {
506  double distance = a->GetDistanceFrom (b);
507  if (distance <= m_referenceDistance)
508  {
509  return txPowerDbm;
510  }
525  double pathLossDb = 10 * m_exponent * std::log10 (distance / m_referenceDistance);
526  double rxc = -m_referenceLoss - pathLossDb;
527  NS_LOG_DEBUG ("distance="<<distance<<"m, reference-attenuation="<< -m_referenceLoss<<"dB, "<<
528  "attenuation coefficient="<<rxc<<"db");
529  return txPowerDbm + rxc;
530 }
531 
532 int64_t
534 {
535  return 0;
536 }
537 
538 // ------------------------------------------------------------------------- //
539 
540 NS_OBJECT_ENSURE_REGISTERED (ThreeLogDistancePropagationLossModel);
541 
542 TypeId
543 ThreeLogDistancePropagationLossModel::GetTypeId (void)
544 {
545  static TypeId tid = TypeId ("ns3::ThreeLogDistancePropagationLossModel")
547  .AddConstructor<ThreeLogDistancePropagationLossModel> ()
548  .AddAttribute ("Distance0",
549  "Beginning of the first (near) distance field",
550  DoubleValue (1.0),
551  MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance0),
552  MakeDoubleChecker<double> ())
553  .AddAttribute ("Distance1",
554  "Beginning of the second (middle) distance field.",
555  DoubleValue (200.0),
556  MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance1),
557  MakeDoubleChecker<double> ())
558  .AddAttribute ("Distance2",
559  "Beginning of the third (far) distance field.",
560  DoubleValue (500.0),
561  MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance2),
562  MakeDoubleChecker<double> ())
563  .AddAttribute ("Exponent0",
564  "The exponent for the first field.",
565  DoubleValue (1.9),
566  MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent0),
567  MakeDoubleChecker<double> ())
568  .AddAttribute ("Exponent1",
569  "The exponent for the second field.",
570  DoubleValue (3.8),
571  MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent1),
572  MakeDoubleChecker<double> ())
573  .AddAttribute ("Exponent2",
574  "The exponent for the third field.",
575  DoubleValue (3.8),
576  MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent2),
577  MakeDoubleChecker<double> ())
578  .AddAttribute ("ReferenceLoss",
579  "The reference loss at distance d0 (dB). (Default is Friis at 1m with 5.15 GHz)",
580  DoubleValue (46.6777),
581  MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_referenceLoss),
582  MakeDoubleChecker<double> ())
583  ;
584  return tid;
585 
586 }
587 
588 ThreeLogDistancePropagationLossModel::ThreeLogDistancePropagationLossModel ()
589 {
590 }
591 
592 double
593 ThreeLogDistancePropagationLossModel::DoCalcRxPower (double txPowerDbm,
594  Ptr<MobilityModel> a,
595  Ptr<MobilityModel> b) const
596 {
597  double distance = a->GetDistanceFrom (b);
598  NS_ASSERT (distance >= 0);
599 
600  // See doxygen comments for the formula and explanation
601 
602  double pathLossDb;
603 
604  if (distance < m_distance0)
605  {
606  pathLossDb = 0;
607  }
608  else if (distance < m_distance1)
609  {
610  pathLossDb = m_referenceLoss
611  + 10 * m_exponent0 * std::log10 (distance / m_distance0);
612  }
613  else if (distance < m_distance2)
614  {
615  pathLossDb = m_referenceLoss
616  + 10 * m_exponent0 * std::log10 (m_distance1 / m_distance0)
617  + 10 * m_exponent1 * std::log10 (distance / m_distance1);
618  }
619  else
620  {
621  pathLossDb = m_referenceLoss
622  + 10 * m_exponent0 * std::log10 (m_distance1 / m_distance0)
623  + 10 * m_exponent1 * std::log10 (m_distance2 / m_distance1)
624  + 10 * m_exponent2 * std::log10 (distance / m_distance2);
625  }
626 
627  NS_LOG_DEBUG ("ThreeLogDistance distance=" << distance << "m, " <<
628  "attenuation=" << pathLossDb << "dB");
629 
630  return txPowerDbm - pathLossDb;
631 }
632 
633 int64_t
635 {
636  return 0;
637 }
638 
639 // ------------------------------------------------------------------------- //
640 
641 NS_OBJECT_ENSURE_REGISTERED (NakagamiPropagationLossModel);
642 
643 TypeId
644 NakagamiPropagationLossModel::GetTypeId (void)
645 {
646  static TypeId tid = TypeId ("ns3::NakagamiPropagationLossModel")
648  .AddConstructor<NakagamiPropagationLossModel> ()
649  .AddAttribute ("Distance1",
650  "Beginning of the second distance field. Default is 80m.",
651  DoubleValue (80.0),
652  MakeDoubleAccessor (&NakagamiPropagationLossModel::m_distance1),
653  MakeDoubleChecker<double> ())
654  .AddAttribute ("Distance2",
655  "Beginning of the third distance field. Default is 200m.",
656  DoubleValue (200.0),
657  MakeDoubleAccessor (&NakagamiPropagationLossModel::m_distance2),
658  MakeDoubleChecker<double> ())
659  .AddAttribute ("m0",
660  "m0 for distances smaller than Distance1. Default is 1.5.",
661  DoubleValue (1.5),
662  MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m0),
663  MakeDoubleChecker<double> ())
664  .AddAttribute ("m1",
665  "m1 for distances smaller than Distance2. Default is 0.75.",
666  DoubleValue (0.75),
667  MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m1),
668  MakeDoubleChecker<double> ())
669  .AddAttribute ("m2",
670  "m2 for distances greater than Distance2. Default is 0.75.",
671  DoubleValue (0.75),
672  MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m2),
673  MakeDoubleChecker<double> ())
674  .AddAttribute ("ErlangRv",
675  "Access to the underlying ErlangRandomVariable",
676  StringValue ("ns3::ErlangRandomVariable"),
677  MakePointerAccessor (&NakagamiPropagationLossModel::m_erlangRandomVariable),
678  MakePointerChecker<ErlangRandomVariable> ())
679  .AddAttribute ("GammaRv",
680  "Access to the underlying GammaRandomVariable",
681  StringValue ("ns3::GammaRandomVariable"),
682  MakePointerAccessor (&NakagamiPropagationLossModel::m_gammaRandomVariable),
683  MakePointerChecker<GammaRandomVariable> ());
684  ;
685  return tid;
686 
687 }
688 
689 NakagamiPropagationLossModel::NakagamiPropagationLossModel ()
690 {
691 }
692 
693 double
694 NakagamiPropagationLossModel::DoCalcRxPower (double txPowerDbm,
695  Ptr<MobilityModel> a,
696  Ptr<MobilityModel> b) const
697 {
698  // select m parameter
699 
700  double distance = a->GetDistanceFrom (b);
701  NS_ASSERT (distance >= 0);
702 
703  double m;
704  if (distance < m_distance1)
705  {
706  m = m_m0;
707  }
708  else if (distance < m_distance2)
709  {
710  m = m_m1;
711  }
712  else
713  {
714  m = m_m2;
715  }
716 
717  // the current power unit is dBm, but Watt is put into the Nakagami /
718  // Rayleigh distribution.
719  double powerW = std::pow (10, (txPowerDbm - 30) / 10);
720 
721  double resultPowerW;
722 
723  // switch between Erlang- and Gamma distributions: this is only for
724  // speed. (Gamma is equal to Erlang for any positive integer m.)
725  unsigned int int_m = static_cast<unsigned int>(std::floor (m));
726 
727  if (int_m == m)
728  {
729  resultPowerW = m_erlangRandomVariable->GetValue (int_m, powerW / m);
730  }
731  else
732  {
733  resultPowerW = m_gammaRandomVariable->GetValue (m, powerW / m);
734  }
735 
736  double resultPowerDbm = 10 * std::log10 (resultPowerW) + 30;
737 
738  NS_LOG_DEBUG ("Nakagami distance=" << distance << "m, " <<
739  "power=" << powerW <<"W, " <<
740  "resultPower=" << resultPowerW << "W=" << resultPowerDbm << "dBm");
741 
742  return resultPowerDbm;
743 }
744 
745 int64_t
747 {
748  m_erlangRandomVariable->SetStream (stream);
749  m_gammaRandomVariable->SetStream (stream + 1);
750  return 2;
751 }
752 
753 // ------------------------------------------------------------------------- //
754 
755 NS_OBJECT_ENSURE_REGISTERED (FixedRssLossModel);
756 
757 TypeId
758 FixedRssLossModel::GetTypeId (void)
759 {
760  static TypeId tid = TypeId ("ns3::FixedRssLossModel")
762  .AddConstructor<FixedRssLossModel> ()
763  .AddAttribute ("Rss", "The fixed receiver Rss.",
764  DoubleValue (-150.0),
765  MakeDoubleAccessor (&FixedRssLossModel::m_rss),
766  MakeDoubleChecker<double> ())
767  ;
768  return tid;
769 }
770 FixedRssLossModel::FixedRssLossModel ()
771  : PropagationLossModel ()
772 {
773 }
774 
775 FixedRssLossModel::~FixedRssLossModel ()
776 {
777 }
778 
779 void
781 {
782  m_rss = rss;
783 }
784 
785 double
786 FixedRssLossModel::DoCalcRxPower (double txPowerDbm,
788  Ptr<MobilityModel> b) const
789 {
790  return m_rss;
791 }
792 
793 int64_t
795 {
796  return 0;
797 }
798 
799 // ------------------------------------------------------------------------- //
800 
801 NS_OBJECT_ENSURE_REGISTERED (MatrixPropagationLossModel);
802 
803 TypeId
804 MatrixPropagationLossModel::GetTypeId (void)
805 {
806  static TypeId tid = TypeId ("ns3::MatrixPropagationLossModel")
808  .AddConstructor<MatrixPropagationLossModel> ()
809  .AddAttribute ("DefaultLoss", "The default value for propagation loss, dB.",
810  DoubleValue (std::numeric_limits<double>::max ()),
811  MakeDoubleAccessor (&MatrixPropagationLossModel::m_default),
812  MakeDoubleChecker<double> ())
813  ;
814  return tid;
815 }
816 
817 MatrixPropagationLossModel::MatrixPropagationLossModel ()
818  : PropagationLossModel (), m_default (std::numeric_limits<double>::max ())
819 {
820 }
821 
822 MatrixPropagationLossModel::~MatrixPropagationLossModel ()
823 {
824 }
825 
826 void
828 {
829  m_default = loss;
830 }
831 
832 void
834 {
835  NS_ASSERT (ma != 0 && mb != 0);
836 
837  MobilityPair p = std::make_pair (ma, mb);
838  std::map<MobilityPair, double>::iterator i = m_loss.find (p);
839 
840  if (i == m_loss.end ())
841  {
842  m_loss.insert (std::make_pair (p, loss));
843  }
844  else
845  {
846  i->second = loss;
847  }
848 
849  if (symmetric)
850  {
851  SetLoss (mb, ma, loss, false);
852  }
853 }
854 
855 double
856 MatrixPropagationLossModel::DoCalcRxPower (double txPowerDbm,
858  Ptr<MobilityModel> b) const
859 {
860  std::map<MobilityPair, double>::const_iterator i = m_loss.find (std::make_pair (a, b));
861 
862  if (i != m_loss.end ())
863  {
864  return txPowerDbm - i->second;
865  }
866  else
867  {
868  return txPowerDbm - m_default;
869  }
870 }
871 
872 int64_t
874 {
875  return 0;
876 }
877 
878 // ------------------------------------------------------------------------- //
879 
880 NS_OBJECT_ENSURE_REGISTERED (RangePropagationLossModel);
881 
882 TypeId
883 RangePropagationLossModel::GetTypeId (void)
884 {
885  static TypeId tid = TypeId ("ns3::RangePropagationLossModel")
887  .AddConstructor<RangePropagationLossModel> ()
888  .AddAttribute ("MaxRange",
889  "Maximum Transmission Range (meters)",
890  DoubleValue (250),
891  MakeDoubleAccessor (&RangePropagationLossModel::m_range),
892  MakeDoubleChecker<double> ())
893  ;
894  return tid;
895 }
896 
897 RangePropagationLossModel::RangePropagationLossModel ()
898 {
899 }
900 
901 double
902 RangePropagationLossModel::DoCalcRxPower (double txPowerDbm,
903  Ptr<MobilityModel> a,
904  Ptr<MobilityModel> b) const
905 {
906  double distance = a->GetDistanceFrom (b);
907  if (distance <= m_range)
908  {
909  return txPowerDbm;
910  }
911  else
912  {
913  return -1000;
914  }
915 }
916 
917 int64_t
919 {
920  return 0;
921 }
922 
923 // ------------------------------------------------------------------------- //
924 
925 } // namespace ns3
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
void SetDefaultLoss(double)
Set default loss (in dB, positive) to be used, infinity if not set.
double GetDistanceFrom(Ptr< const MobilityModel > position) const
hold variables of type string
Definition: string.h:19
a Two-Ray Ground propagation loss model ported from NS2
#define NS_ASSERT(condition)
Definition: assert.h:64
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
The propagation loss depends only on the distance (range) between transmitter and receiver...
virtual double DoCalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
virtual int64_t DoAssignStreams(int64_t stream)
virtual double GetValue(void)=0
Returns a random double from the underlying distribution.
A log distance path loss propagation model with three distance fields. This model is the same as ns3:...
void SetMinDistance(double minDistance)
virtual int64_t DoAssignStreams(int64_t stream)
The propagation loss follows a random distribution.
Return a constant received power level independent of the transmit power.
virtual int64_t DoAssignStreams(int64_t stream)
virtual int64_t DoAssignStreams(int64_t stream)
a Friis propagation loss model
virtual int64_t DoAssignStreams(int64_t stream)
Nakagami-m fast fading propagation loss model.
Modelize the propagation loss through a transmission medium.
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
void SetLoss(Ptr< MobilityModel > a, Ptr< MobilityModel > b, double loss, bool symmetric=true)
Set loss (in dB, positive) between pair of ns-3 objects (typically, nodes).
virtual int64_t DoAssignStreams(int64_t stream)
virtual int64_t DoAssignStreams(int64_t stream)
virtual int64_t DoAssignStreams(int64_t stream)
a log distance propagation model.
Hold an floating point type.
Definition: double.h:41
a unique identifier for an interface.
Definition: type-id.h:44
TypeId SetParent(TypeId tid)
Definition: type-id.cc:471
The propagation loss is fixed for each pair of nodes and doesn't depend on their actual positions...
virtual int64_t DoAssignStreams(int64_t stream)
std::map< MobilityPair, double > m_loss
Fixed loss between pair of nodes.