View | Details | Raw Unified | Return to bug 787
Collapse All | Expand All

(-)a/src/devices/wifi/propagation-loss-model-test-suite.cc (-6 / +142 lines)
 Lines 57-63    Link Here 
57
private:
57
private:
58
  virtual bool DoRun (void);
58
  virtual bool DoRun (void);
59
59
60
  typedef struct {
60
  typedef struct
61
  {
61
    Vector m_position;
62
    Vector m_position;
62
    double m_pt;  // dBm
63
    double m_pt;  // dBm
63
    double m_pr;  // W
64
    double m_pr;  // W
 Lines 68-74    Link Here 
68
};
69
};
69
70
70
FriisPropagationLossModelTestCase::FriisPropagationLossModelTestCase ()
71
FriisPropagationLossModelTestCase::FriisPropagationLossModelTestCase ()
71
  : TestCase ("Check to see that the ns-3 Friis propagation loss model provides correct received power"), m_testVectors ()
72
  : TestCase ("Check to see that the ns-3 Friis propagation loss model provides correct received power"),
73
    m_testVectors ()
72
{
74
{
73
}
75
}
74
76
 Lines 138-147    Link Here 
138
      testVector = m_testVectors.Get (i);
140
      testVector = m_testVectors.Get (i);
139
      b->SetPosition (testVector.m_position);
141
      b->SetPosition (testVector.m_position);
140
      double resultdBm = lossModel->CalcRxPower (testVector.m_pt, a, b);
142
      double resultdBm = lossModel->CalcRxPower (testVector.m_pt, a, b);
141
      double resultW =   pow (10.0, resultdBm/10.0)/1000;
143
      double resultW =   pow (10.0, resultdBm / 10.0) / 1000;
142
      NS_TEST_EXPECT_MSG_EQ_TOL (resultW, testVector.m_pr, testVector.m_tolerance, "Got unexpected rcv power");
144
      NS_TEST_EXPECT_MSG_EQ_TOL (resultW, testVector.m_pr, testVector.m_tolerance, "Got unexpected rcv power");
143
    }
145
    }
144
	
146
	
147
  return GetErrorStatus ();
148
}
149
150
// Added for Two-Ray Ground Model - tomhewer@mac.com
151
152
class TwoRayGroundPropagationLossModelTestCase : public TestCase
153
{
154
public:
155
  TwoRayGroundPropagationLossModelTestCase ();
156
  virtual ~TwoRayGroundPropagationLossModelTestCase ();
157
158
private:
159
  virtual bool DoRun (void);
160
161
  typedef struct
162
  {
163
    Vector m_position;
164
    double m_pt;  // dBm
165
    double m_pr;  // W
166
    double m_tolerance;
167
  } TestVector;
168
169
  TestVectors<TestVector> m_testVectors;
170
};
171
172
TwoRayGroundPropagationLossModelTestCase::TwoRayGroundPropagationLossModelTestCase ()
173
  : TestCase ("Check to see that the ns-3 TwoRayGround propagation loss model provides correct received power"),
174
    m_testVectors ()
175
{
176
}
177
178
TwoRayGroundPropagationLossModelTestCase::~TwoRayGroundPropagationLossModelTestCase ()
179
{
180
}
181
182
bool
183
TwoRayGroundPropagationLossModelTestCase::DoRun (void)
184
{
185
  // wavelength at 2.4 GHz is 0.125m
186
  Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::Lambda", DoubleValue (0.125));
187
  Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::SystemLoss", DoubleValue (1.0));
188
189
  // set antenna height to 1.5m above z coordinate
190
  Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::HeightAboveZ", DoubleValue (1.5));
191
192
  // Select a reference transmit power of 17.0206 dBm
193
  // Pt = 10^(17.0206/10)/10^3 = .05035702 W
194
  double txPowerW = 0.05035702;
195
  double txPowerdBm = 10 * log10 (txPowerW) + 30;
196
197
  //
198
  // As with the Friis tests above, we want to test the propagation loss 
199
  // model calculations at a few chosen distances and compare the results 
200
  // to those we can manually calculate. Let us test the ns-3 calculated 
201
  // value for agreement to be within 5e-16, as above.
202
  //
203
  TestVector testVector;
204
205
  // Below the Crossover distance use Friis so this test should be the same as that above
206
  // Crossover = (4 * PI * TxAntennaHeight * RxAntennaHeight) / Lamdba
207
  // Crossover = (4 * PI * 1.5 * 1.5) / 0.125 = 226.1946m
208
209
  testVector.m_position = Vector (100, 0, 0);
210
  testVector.m_pt = txPowerdBm;
211
  testVector.m_pr = 4.98265e-10;
212
  testVector.m_tolerance = 5e-16;
213
  m_testVectors.Add (testVector);
214
215
  // These values are above the crossover distance and therefore use the Two Ray calculation
216
217
  testVector.m_position = Vector (500, 0, 0);
218
  testVector.m_pt = txPowerdBm;
219
  testVector.m_pr = 4.07891862e-12;
220
  testVector.m_tolerance = 5e-16;
221
  m_testVectors.Add (testVector);
222
223
  testVector.m_position = Vector (1000, 0, 0);
224
  testVector.m_pt = txPowerdBm;
225
  testVector.m_pr = 2.5493241375e-13;
226
  testVector.m_tolerance = 5e-16;
227
  m_testVectors.Add (testVector);
228
229
  testVector.m_position = Vector (2000, 0, 0);
230
  testVector.m_pt = txPowerdBm;
231
  testVector.m_pr = 1.593327585938e-14;
232
  testVector.m_tolerance = 5e-16;
233
  m_testVectors.Add (testVector);
234
235
  // Repeat the tests for non-zero z coordinates
236
237
  // Pr = (0.05035702 * (1.5*1.5) * (2.5*2.5)) / (500*500*500*500) = 1.13303295e-11
238
  // dCross = (4 * pi * 1.5 * 2.5) / 0.125 = 376.99m
239
  testVector.m_position = Vector (500, 0, 1);
240
  testVector.m_pt = txPowerdBm;
241
  testVector.m_pr = 1.13303295e-11;
242
  testVector.m_tolerance = 5e-16;
243
  m_testVectors.Add (testVector);
244
245
  // Pr = (0.05035702 * (1.5*1.5) * (5.5*5.5)) / (1000*1000*1000*1000) = 3.42742467375e-12
246
  // dCross = (4 * pi * 1.5 * 5.5) / 0.125 = 829.38m
247
  testVector.m_position = Vector (1000, 0, 4);
248
  testVector.m_pt = txPowerdBm;
249
  testVector.m_pr = 3.42742467375e-12;
250
  testVector.m_tolerance = 5e-16;
251
  m_testVectors.Add (testVector);
252
253
  // Pr = (0.05035702 * (1.5*1.5) * (11.5*11.5)) / (2000*2000*2000*2000) = 9.36522547734e-13
254
  // dCross = (4 * pi * 1.5 * 11.5) / 0.125 = 1734.15m
255
  testVector.m_position = Vector (2000, 0, 10);
256
  testVector.m_pt = txPowerdBm;
257
  testVector.m_pr = 9.36522547734e-13;
258
  testVector.m_tolerance = 5e-16;
259
  m_testVectors.Add (testVector);
260
261
262
  // Now, check that the received power values are expected
263
264
  Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel> (); 
265
  a->SetPosition (Vector (0,0,0));
266
  Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel> (); 
267
268
  Ptr<TwoRayGroundPropagationLossModel> lossModel = CreateObject<TwoRayGroundPropagationLossModel> (); 
269
  for (uint32_t i = 0; i < m_testVectors.GetN (); ++i)
270
    {
271
      testVector = m_testVectors.Get (i);
272
      b->SetPosition (testVector.m_position);
273
      double resultdBm = lossModel->CalcRxPower (testVector.m_pt, a, b);
274
      double resultW =   pow (10.0, resultdBm / 10.0) / 1000;
275
      NS_TEST_EXPECT_MSG_EQ_TOL (resultW, testVector.m_pr, testVector.m_tolerance, "Got unexpected rcv power");
276
    }
277
145
  return GetErrorStatus ();
278
  return GetErrorStatus ();
146
}
279
}
147
280
 Lines 154-160    Link Here 
154
private:
287
private:
155
  virtual bool DoRun (void);
288
  virtual bool DoRun (void);
156
289
157
  typedef struct {
290
  typedef struct
291
  {
158
    Vector m_position;
292
    Vector m_position;
159
    double m_pt;  // dBm
293
    double m_pt;  // dBm
160
    double m_pr;  // W
294
    double m_pr;  // W
 Lines 165-171    Link Here 
165
};
299
};
166
300
167
LogDistancePropagationLossModelTestCase::LogDistancePropagationLossModelTestCase ()
301
LogDistancePropagationLossModelTestCase::LogDistancePropagationLossModelTestCase ()
168
  : TestCase ("Check to see that the ns-3 Log Distance propagation loss model provides correct received power"), m_testVectors ()
302
  : TestCase ("Check to see that the ns-3 Log Distance propagation loss model provides correct received power"),
303
    m_testVectors ()
169
{
304
{
170
}
305
}
171
306
 Lines 227-233    Link Here 
227
      testVector = m_testVectors.Get (i);
362
      testVector = m_testVectors.Get (i);
228
      b->SetPosition (testVector.m_position);
363
      b->SetPosition (testVector.m_position);
229
      double resultdBm = lossModel->CalcRxPower (testVector.m_pt, a, b);
364
      double resultdBm = lossModel->CalcRxPower (testVector.m_pt, a, b);
230
      double resultW =   pow (10.0, resultdBm/10.0)/1000;
365
      double resultW =   pow (10.0, resultdBm / 10.0) / 1000;
231
      NS_TEST_EXPECT_MSG_EQ_TOL (resultW, testVector.m_pr, testVector.m_tolerance, "Got unexpected rcv power");
366
      NS_TEST_EXPECT_MSG_EQ_TOL (resultW, testVector.m_pr, testVector.m_tolerance, "Got unexpected rcv power");
232
    }
367
    }
233
	
368
	
 Lines 244-249    Link Here 
244
  : TestSuite ("propagation-loss-model", UNIT)
379
  : TestSuite ("propagation-loss-model", UNIT)
245
{
380
{
246
  AddTestCase (new FriisPropagationLossModelTestCase);
381
  AddTestCase (new FriisPropagationLossModelTestCase);
382
  AddTestCase (new TwoRayGroundPropagationLossModelTestCase);
247
  AddTestCase (new LogDistancePropagationLossModelTestCase);
383
  AddTestCase (new LogDistancePropagationLossModelTestCase);
248
}
384
}
249
385
(-)a/src/devices/wifi/propagation-loss-model.cc (-60 / +239 lines)
 Lines 17-22    Link Here 
17
 *
17
 *
18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
 * Contributions: Timo Bingmann <timo.bingmann@student.kit.edu>
19
 * Contributions: Timo Bingmann <timo.bingmann@student.kit.edu>
20
 * Contributions: Tom Hewer <tomhewer@mac.com> for Two Ray Ground Model
20
 */
21
 */
21
22
22
#include "propagation-loss-model.h"
23
#include "propagation-loss-model.h"
 Lines 39-62    Link Here 
39
{
40
{
40
  static TypeId tid = TypeId ("ns3::PropagationLossModel")
41
  static TypeId tid = TypeId ("ns3::PropagationLossModel")
41
    .SetParent<Object> ()
42
    .SetParent<Object> ()
42
    ;
43
  ;
43
  return tid;
44
  return tid;
44
}
45
}
45
46
46
PropagationLossModel::PropagationLossModel ()
47
PropagationLossModel::PropagationLossModel ()
47
  : m_next (0)
48
  : m_next (0)
48
{}
49
{
50
}
49
51
50
PropagationLossModel::~PropagationLossModel ()
52
PropagationLossModel::~PropagationLossModel ()
51
{}
53
{
54
}
52
55
53
void 
56
void
54
PropagationLossModel::SetNext (Ptr<PropagationLossModel> next)
57
PropagationLossModel::SetNext (Ptr<PropagationLossModel> next)
55
{
58
{
56
  m_next = next;
59
  m_next = next;
57
}
60
}
58
61
59
double 
62
double
60
PropagationLossModel::CalcRxPower (double txPowerDbm,
63
PropagationLossModel::CalcRxPower (double txPowerDbm,
61
                                   Ptr<MobilityModel> a,
64
                                   Ptr<MobilityModel> a,
62
                                   Ptr<MobilityModel> b) const
65
                                   Ptr<MobilityModel> b) const
 Lines 83-105    Link Here 
83
                   RandomVariableValue (ConstantVariable (1.0)),
86
                   RandomVariableValue (ConstantVariable (1.0)),
84
                   MakeRandomVariableAccessor (&RandomPropagationLossModel::m_variable),
87
                   MakeRandomVariableAccessor (&RandomPropagationLossModel::m_variable),
85
                   MakeRandomVariableChecker ())
88
                   MakeRandomVariableChecker ())
86
    ;
89
  ;
87
  return tid;
90
  return tid;
88
}
91
}
89
RandomPropagationLossModel::RandomPropagationLossModel ()
92
RandomPropagationLossModel::RandomPropagationLossModel ()
90
  : PropagationLossModel ()
93
  : PropagationLossModel ()
91
{}
94
{
95
}
92
96
93
RandomPropagationLossModel::~RandomPropagationLossModel ()
97
RandomPropagationLossModel::~RandomPropagationLossModel ()
94
{}
98
{
99
}
95
100
96
double 
101
double
97
RandomPropagationLossModel::DoCalcRxPower (double txPowerDbm,
102
RandomPropagationLossModel::DoCalcRxPower (double txPowerDbm,
98
                                           Ptr<MobilityModel> a,
103
                                           Ptr<MobilityModel> a,
99
                                           Ptr<MobilityModel> b) const
104
                                           Ptr<MobilityModel> b) const
100
{
105
{
101
  double rxc = -m_variable.GetValue ();
106
  double rxc = -m_variable.GetValue ();
102
  NS_LOG_DEBUG ("attenuation coefficent="<<rxc<<"Db");
107
  NS_LOG_DEBUG ("attenuation coefficent=" << rxc << "Db");
103
  return txPowerDbm + rxc;
108
  return txPowerDbm + rxc;
104
}
109
}
105
110
 Lines 130-181    Link Here 
130
                   MakeDoubleAccessor (&FriisPropagationLossModel::SetMinDistance,
135
                   MakeDoubleAccessor (&FriisPropagationLossModel::SetMinDistance,
131
                                       &FriisPropagationLossModel::GetMinDistance),
136
                                       &FriisPropagationLossModel::GetMinDistance),
132
                   MakeDoubleChecker<double> ())
137
                   MakeDoubleChecker<double> ())
133
    ;
138
  ;
134
  return tid;
139
  return tid;
135
}
140
}
136
141
137
FriisPropagationLossModel::FriisPropagationLossModel ()
142
FriisPropagationLossModel::FriisPropagationLossModel ()
138
{}
143
{
139
void 
144
}
145
void
140
FriisPropagationLossModel::SetSystemLoss (double systemLoss)
146
FriisPropagationLossModel::SetSystemLoss (double systemLoss)
141
{
147
{
142
  m_systemLoss = systemLoss;
148
  m_systemLoss = systemLoss;
143
}
149
}
144
double 
150
double
145
FriisPropagationLossModel::GetSystemLoss (void) const
151
FriisPropagationLossModel::GetSystemLoss (void) const
146
{
152
{
147
  return m_systemLoss;
153
  return m_systemLoss;
148
}
154
}
149
void 
155
void
150
FriisPropagationLossModel::SetMinDistance (double minDistance)
156
FriisPropagationLossModel::SetMinDistance (double minDistance)
151
{
157
{
152
  m_minDistance = minDistance;
158
  m_minDistance = minDistance;
153
}
159
}
154
double 
160
double
155
FriisPropagationLossModel::GetMinDistance (void) const
161
FriisPropagationLossModel::GetMinDistance (void) const
156
{
162
{
157
  return m_minDistance;
163
  return m_minDistance;
158
}
164
}
159
void 
165
void
160
FriisPropagationLossModel::SetLambda (double frequency, double speed)
166
FriisPropagationLossModel::SetLambda (double frequency, double speed)
161
{
167
{
162
  m_lambda = speed / frequency;
168
  m_lambda = speed / frequency;
163
}
169
}
164
void 
170
void
165
FriisPropagationLossModel::SetLambda (double lambda)
171
FriisPropagationLossModel::SetLambda (double lambda)
166
{
172
{
167
  m_lambda = lambda;
173
  m_lambda = lambda;
168
}
174
}
169
double 
175
double
170
FriisPropagationLossModel::GetLambda (void) const
176
FriisPropagationLossModel::GetLambda (void) const
171
{
177
{
172
  return m_lambda;
178
  return m_lambda;
173
}
179
}
174
180
175
double 
181
double
176
FriisPropagationLossModel::DbmToW (double dbm) const
182
FriisPropagationLossModel::DbmToW (double dbm) const
177
{
183
{
178
  double mw = pow(10.0,dbm/10.0);
184
  double mw = pow (10.0,dbm / 10.0);
179
  return mw / 1000.0;
185
  return mw / 1000.0;
180
}
186
}
181
187
 Lines 228-235    Link Here 
228
  double numerator = m_lambda * m_lambda;
234
  double numerator = m_lambda * m_lambda;
229
  double denominator = 16 * PI * PI * distance * distance * m_systemLoss;
235
  double denominator = 16 * PI * PI * distance * distance * m_systemLoss;
230
  double pr = 10 * log10 (numerator / denominator);
236
  double pr = 10 * log10 (numerator / denominator);
231
  NS_LOG_DEBUG ("distance="<<distance<<"m, attenuation coefficient="<<pr<<"dB");
237
  NS_LOG_DEBUG ("distance=" << distance << "m, attenuation coefficient=" << pr << "dB");
232
  return txPowerDbm + pr;
238
  return txPowerDbm + pr;
239
}
240
241
// ------------------------------------------------------------------------- //
242
// -- Two-Ray Ground Model ported from NS-2 -- tomhewer@mac.com -- Nov09 //
243
244
NS_OBJECT_ENSURE_REGISTERED (TwoRayGroundPropagationLossModel);
245
246
const double TwoRayGroundPropagationLossModel::PI = 3.14159265358979323846;
247
248
TypeId 
249
TwoRayGroundPropagationLossModel::GetTypeId (void)
250
{
251
  static TypeId tid = TypeId ("ns3::TwoRayGroundPropagationLossModel")
252
    .SetParent<PropagationLossModel> ()
253
    .AddConstructor<TwoRayGroundPropagationLossModel> ()
254
    .AddAttribute ("Lambda",
255
                   "The wavelength  (default is 5.15 GHz at 300 000 km/s).",
256
                   DoubleValue (300000000.0 / 5.150e9),
257
                   MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::m_lambda),
258
                   MakeDoubleChecker<double> ())
259
    .AddAttribute ("SystemLoss", "The system loss",
260
                   DoubleValue (1.0),
261
                   MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::m_systemLoss),
262
                   MakeDoubleChecker<double> ())
263
    .AddAttribute ("MinDistance",
264
                   "The distance under which the propagation model refuses to give results (m)",
265
                   DoubleValue (0.5),
266
                   MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::SetMinDistance,
267
                                       &TwoRayGroundPropagationLossModel::GetMinDistance),
268
                   MakeDoubleChecker<double> ())
269
    .AddAttribute ("HeightAboveZ",
270
                   "The height of the antenna (m) above the node's Z coordinate",
271
                   DoubleValue (0),
272
                   MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::m_heightAboveZ),
273
                   MakeDoubleChecker<double> ())
274
  ;
275
  return tid;
276
}
277
278
TwoRayGroundPropagationLossModel::TwoRayGroundPropagationLossModel ()
279
{
280
}
281
void
282
TwoRayGroundPropagationLossModel::SetSystemLoss (double systemLoss)
283
{
284
  m_systemLoss = systemLoss;
285
}
286
double
287
TwoRayGroundPropagationLossModel::GetSystemLoss (void) const
288
{
289
  return m_systemLoss;
290
}
291
void
292
TwoRayGroundPropagationLossModel::SetMinDistance (double minDistance)
293
{
294
  m_minDistance = minDistance;
295
}
296
double
297
TwoRayGroundPropagationLossModel::GetMinDistance (void) const
298
{
299
  return m_minDistance;
300
}
301
void
302
TwoRayGroundPropagationLossModel::SetHeightAboveZ (double heightAboveZ)
303
{
304
  m_heightAboveZ = heightAboveZ;
305
}
306
void 
307
TwoRayGroundPropagationLossModel::SetLambda (double frequency, double speed)
308
{
309
  m_lambda = speed / frequency;
310
}
311
void 
312
TwoRayGroundPropagationLossModel::SetLambda (double lambda)
313
{
314
  m_lambda = lambda;
315
}
316
double 
317
TwoRayGroundPropagationLossModel::GetLambda (void) const
318
{
319
  return m_lambda;
320
}
321
322
double 
323
TwoRayGroundPropagationLossModel::DbmToW (double dbm) const
324
{
325
  double mw = pow (10.0,dbm / 10.0);
326
  return mw / 1000.0;
327
}
328
329
double
330
TwoRayGroundPropagationLossModel::DbmFromW (double w) const
331
{
332
  double dbm = log10 (w * 1000.0) * 10.0;
333
  return dbm;
334
}
335
336
double 
337
TwoRayGroundPropagationLossModel::DoCalcRxPower (double txPowerDbm,
338
                                                 Ptr<MobilityModel> a,
339
                                                 Ptr<MobilityModel> b) const
340
{
341
  /*
342
   * Two-Ray Ground equation:
343
   *
344
   * where Pt, Gt and Gr are in dBm units
345
   * L, Ht and Hr are in meter units.
346
   *
347
   *   Pr      Gt * Gr * (Ht^2 * Hr^2)
348
   *   -- =  (-------------------------)
349
   *	 Pt            d^4 * L
350
   *
351
   * Gt: tx gain (unit-less)
352
   * Gr: rx gain (unit-less)
353
   * Pt: tx power (dBm)
354
   * d: distance (m)
355
   * L: system loss
356
   * Ht: Tx antenna height (m)
357
   * Hr: Rx antenna height (m)
358
   * lambda: wavelength (m)
359
   *
360
   * As with the Friis model we ignore tx and rx gain and output values
361
   * are in dB or dBm
362
   *
363
   *						  (Ht * Ht) * (Hr * Hr)
364
   * rx = tx + 10 log10	(-----------------------)
365
   *						   (d * d * d * d) * L
366
   */
367
  double distance = a->GetDistanceFrom (b);
368
  if (distance <= m_minDistance)
369
    {
370
      return txPowerDbm;
371
    }
372
373
  // Set the height of the Tx and Rx antennae
374
  double txAntHeight = a->GetPosition ().z + m_heightAboveZ;
375
  double rxAntHeight = b->GetPosition ().z + m_heightAboveZ;
376
377
  // Calculate a crossover distance, under which we use Friis
378
  /*
379
   * 
380
   * dCross = (4 * pi * Ht * Hr) / lambda
381
   *
382
   */
383
384
  double dCross = (4 * PI * txAntHeight * rxAntHeight) / GetLambda ();
385
  double tmp = 0;
386
  if (distance <= dCross)
387
    {
388
      // We use Friis
389
      double numerator = m_lambda * m_lambda;
390
      tmp = PI * distance;
391
      double denominator = 16 * tmp * tmp * m_systemLoss;
392
      double pr = 10 * log10 (numerator / denominator);
393
      NS_LOG_DEBUG ("Receiver within crossover (" << dCross << "m) for Two_ray path; using Friis");
394
      NS_LOG_DEBUG ("distance=" << distance << "m, attenuation coefficient=" << pr << "dB");
395
      return txPowerDbm + pr;
396
    }
397
  else   // Use Two-Ray Pathloss
398
    {
399
      tmp = txAntHeight * rxAntHeight;
400
      double rayNumerator = tmp * tmp;
401
      tmp = distance * distance;
402
      double rayDenominator = tmp * tmp * m_systemLoss;
403
      double rayPr = 10 * log10 (rayNumerator / rayDenominator);
404
      NS_LOG_DEBUG ("distance=" << distance << "m, attenuation coefficient=" << rayPr << "dB");
405
      return txPowerDbm + rayPr;
406
407
    }
233
}
408
}
234
409
235
// ------------------------------------------------------------------------- //
410
// ------------------------------------------------------------------------- //
 Lines 257-288    Link Here 
257
                   DoubleValue (46.6777),
432
                   DoubleValue (46.6777),
258
                   MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceLoss),
433
                   MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceLoss),
259
                   MakeDoubleChecker<double> ())
434
                   MakeDoubleChecker<double> ())
260
    ;
435
  ;
261
  return tid;
436
  return tid;
262
                   
437
263
}
438
}
264
439
265
LogDistancePropagationLossModel::LogDistancePropagationLossModel ()
440
LogDistancePropagationLossModel::LogDistancePropagationLossModel ()
266
{}
441
{
442
}
267
443
268
void 
444
void
269
LogDistancePropagationLossModel::SetPathLossExponent (double n)
445
LogDistancePropagationLossModel::SetPathLossExponent (double n)
270
{
446
{
271
  m_exponent = n;
447
  m_exponent = n;
272
}
448
}
273
void 
449
void
274
LogDistancePropagationLossModel::SetReference (double referenceDistance, double referenceLoss)
450
LogDistancePropagationLossModel::SetReference (double referenceDistance, double referenceLoss)
275
{
451
{
276
  m_referenceDistance = referenceDistance;
452
  m_referenceDistance = referenceDistance;
277
  m_referenceLoss = referenceLoss;
453
  m_referenceLoss = referenceLoss;
278
}
454
}
279
double 
455
double
280
LogDistancePropagationLossModel::GetPathLossExponent (void) const
456
LogDistancePropagationLossModel::GetPathLossExponent (void) const
281
{
457
{
282
  return m_exponent;
458
  return m_exponent;
283
}
459
}
284
  
460
285
double 
461
double
286
LogDistancePropagationLossModel::DoCalcRxPower (double txPowerDbm,
462
LogDistancePropagationLossModel::DoCalcRxPower (double txPowerDbm,
287
                                                Ptr<MobilityModel> a,
463
                                                Ptr<MobilityModel> a,
288
                                                Ptr<MobilityModel> b) const
464
                                                Ptr<MobilityModel> b) const
 Lines 308-315    Link Here 
308
   */
484
   */
309
  double pathLossDb = 10 * m_exponent * log10 (distance / m_referenceDistance);
485
  double pathLossDb = 10 * m_exponent * log10 (distance / m_referenceDistance);
310
  double rxc = -m_referenceLoss - pathLossDb;
486
  double rxc = -m_referenceLoss - pathLossDb;
311
  NS_LOG_DEBUG ("distance="<<distance<<"m, reference-attenuation="<<-m_referenceLoss<<"dB, "<<
487
  NS_LOG_DEBUG ("distance=" << distance << "m, reference-attenuation=" << -m_referenceLoss << "dB, " <<
312
		"attenuation coefficient="<<rxc<<"db");
488
                "attenuation coefficient=" << rxc << "db");
313
  return txPowerDbm + rxc;
489
  return txPowerDbm + rxc;
314
}
490
}
315
491
 Lines 358-366    Link Here 
358
                   DoubleValue (46.6777),
534
                   DoubleValue (46.6777),
359
                   MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_referenceLoss),
535
                   MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_referenceLoss),
360
                   MakeDoubleChecker<double> ())
536
                   MakeDoubleChecker<double> ())
361
    ;
537
  ;
362
  return tid;
538
  return tid;
363
                   
539
364
}
540
}
365
541
366
ThreeLogDistancePropagationLossModel::ThreeLogDistancePropagationLossModel ()
542
ThreeLogDistancePropagationLossModel::ThreeLogDistancePropagationLossModel ()
 Lines 373-379    Link Here 
373
                                                     Ptr<MobilityModel> b) const
549
                                                     Ptr<MobilityModel> b) const
374
{
550
{
375
  double distance = a->GetDistanceFrom (b);
551
  double distance = a->GetDistanceFrom (b);
376
  NS_ASSERT(distance >= 0);
552
  NS_ASSERT (distance >= 0);
377
553
378
  // See doxygen comments for the formula and explanation
554
  // See doxygen comments for the formula and explanation
379
555
 Lines 386-405    Link Here 
386
  else if (distance < m_distance1)
562
  else if (distance < m_distance1)
387
    {
563
    {
388
      pathLossDb = m_referenceLoss
564
      pathLossDb = m_referenceLoss
389
        + 10 * m_exponent0 * log10(distance / m_distance0);
565
        + 10 * m_exponent0 * log10 (distance / m_distance0);
390
    }
566
    }
391
  else if (distance < m_distance2)
567
  else if (distance < m_distance2)
392
    {
568
    {
393
      pathLossDb = m_referenceLoss
569
      pathLossDb = m_referenceLoss
394
        + 10 * m_exponent0 * log10(m_distance1 / m_distance0)
570
        + 10 * m_exponent0 * log10 (m_distance1 / m_distance0)
395
        + 10 * m_exponent1 * log10(distance / m_distance1);
571
        + 10 * m_exponent1 * log10 (distance / m_distance1);
396
    }
572
    }
397
  else
573
  else
398
    {
574
    {
399
      pathLossDb = m_referenceLoss
575
      pathLossDb = m_referenceLoss
400
        + 10 * m_exponent0 * log10(m_distance1 / m_distance0)
576
        + 10 * m_exponent0 * log10 (m_distance1 / m_distance0)
401
        + 10 * m_exponent1 * log10(m_distance2 / m_distance1)
577
        + 10 * m_exponent1 * log10 (m_distance2 / m_distance1)
402
        + 10 * m_exponent2 * log10(distance / m_distance2);
578
        + 10 * m_exponent2 * log10 (distance / m_distance2);
403
    }
579
    }
404
580
405
  NS_LOG_DEBUG ("ThreeLogDistance distance=" << distance << "m, " <<
581
  NS_LOG_DEBUG ("ThreeLogDistance distance=" << distance << "m, " <<
 Lines 443-457    Link Here 
443
                   DoubleValue (0.75),
619
                   DoubleValue (0.75),
444
                   MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m2),
620
                   MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m2),
445
                   MakeDoubleChecker<double> ())
621
                   MakeDoubleChecker<double> ())
446
    ;
622
  ;
447
  return tid;
623
  return tid;
448
                   
624
449
}
625
}
450
626
451
NakagamiPropagationLossModel::NakagamiPropagationLossModel ()
627
NakagamiPropagationLossModel::NakagamiPropagationLossModel ()
452
{}
628
{
629
}
453
630
454
double 
631
double
455
NakagamiPropagationLossModel::DoCalcRxPower (double txPowerDbm,
632
NakagamiPropagationLossModel::DoCalcRxPower (double txPowerDbm,
456
                                             Ptr<MobilityModel> a,
633
                                             Ptr<MobilityModel> a,
457
                                             Ptr<MobilityModel> b) const
634
                                             Ptr<MobilityModel> b) const
 Lines 459-465    Link Here 
459
  // select m parameter
636
  // select m parameter
460
637
461
  double distance = a->GetDistanceFrom (b);
638
  double distance = a->GetDistanceFrom (b);
462
  NS_ASSERT(distance >= 0);
639
  NS_ASSERT (distance >= 0);
463
640
464
  double m;
641
  double m;
465
  if (distance < m_distance1)
642
  if (distance < m_distance1)
 Lines 474-503    Link Here 
474
    {
651
    {
475
      m = m_m2;
652
      m = m_m2;
476
    }
653
    }
477
  
654
478
  // the current power unit is dBm, but Watt is put into the Nakagami /
655
  // the current power unit is dBm, but Watt is put into the Nakagami /
479
  // Rayleigh distribution.
656
  // Rayleigh distribution.
480
  double powerW = pow(10, (txPowerDbm - 30) / 10);
657
  double powerW = pow (10, (txPowerDbm - 30) / 10);
481
658
482
  double resultPowerW;
659
  double resultPowerW;
483
660
484
  // switch between Erlang- and Gamma distributions: this is only for
661
  // switch between Erlang- and Gamma distributions: this is only for
485
  // speed. (Gamma is equal to Erlang for any positive integer m.)
662
  // speed. (Gamma is equal to Erlang for any positive integer m.)
486
  unsigned int int_m = static_cast<unsigned int>(floor(m));
663
  unsigned int int_m = static_cast<unsigned int> (floor (m));
487
664
488
  if (int_m == m)
665
  if (int_m == m)
489
    {
666
    {
490
      resultPowerW = m_erlangRandomVariable.GetValue(int_m, powerW / m);
667
      resultPowerW = m_erlangRandomVariable.GetValue (int_m, powerW / m);
491
    }
668
    }
492
  else
669
  else
493
    {
670
    {
494
      resultPowerW = m_gammaRandomVariable.GetValue(m, powerW / m);
671
      resultPowerW = m_gammaRandomVariable.GetValue (m, powerW / m);
495
    }
672
    }
496
673
497
  double resultPowerDbm = 10 * log10(resultPowerW) + 30;
674
  double resultPowerDbm = 10 * log10 (resultPowerW) + 30;
498
675
499
  NS_LOG_DEBUG ("Nakagami distance=" << distance << "m, " <<
676
  NS_LOG_DEBUG ("Nakagami distance=" << distance << "m, " <<
500
                "power=" << powerW <<"W, " <<
677
                "power=" << powerW << "W, " <<
501
                "resultPower=" << resultPowerW << "W=" << resultPowerDbm << "dBm");
678
                "resultPower=" << resultPowerW << "W=" << resultPowerDbm << "dBm");
502
679
503
  return resultPowerDbm;
680
  return resultPowerDbm;
 Lines 517-542    Link Here 
517
                   DoubleValue (-150.0),
694
                   DoubleValue (-150.0),
518
                   MakeDoubleAccessor (&FixedRssLossModel::m_rss),
695
                   MakeDoubleAccessor (&FixedRssLossModel::m_rss),
519
                   MakeDoubleChecker<double> ())
696
                   MakeDoubleChecker<double> ())
520
    ;
697
  ;
521
  return tid;
698
  return tid;
522
}
699
}
523
FixedRssLossModel::FixedRssLossModel ()
700
FixedRssLossModel::FixedRssLossModel ()
524
  : PropagationLossModel ()
701
  : PropagationLossModel ()
525
{}
702
{
703
}
526
704
527
FixedRssLossModel::~FixedRssLossModel ()
705
FixedRssLossModel::~FixedRssLossModel ()
528
{}
706
{
707
}
529
708
530
void 
709
void
531
FixedRssLossModel::SetRss (double rss)
710
FixedRssLossModel::SetRss (double rss)
532
{
711
{
533
  m_rss = rss;
712
  m_rss = rss;
534
}
713
}
535
714
536
double 
715
double
537
FixedRssLossModel::DoCalcRxPower (double txPowerDbm,
716
FixedRssLossModel::DoCalcRxPower (double txPowerDbm,
538
                                           Ptr<MobilityModel> a,
717
                                  Ptr<MobilityModel> a,
539
                                           Ptr<MobilityModel> b) const
718
                                  Ptr<MobilityModel> b) const
540
{
719
{
541
  return m_rss;
720
  return m_rss;
542
}
721
}
(-)a/src/devices/wifi/propagation-loss-model.h (-4 / +94 lines)
 Lines 18-23    Link Here 
18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
 * Contributions: Timo Bingmann <timo.bingmann@student.kit.edu>
19
 * Contributions: Timo Bingmann <timo.bingmann@student.kit.edu>
20
 * Contributions: Gary Pei <guangyu.pei@boeing.com> for fixed RSS
20
 * Contributions: Gary Pei <guangyu.pei@boeing.com> for fixed RSS
21
 * Contributions: Tom Hewer <tomhewer@mac.com> for porting Two Ray Ground
21
 */
22
 */
22
23
23
#ifndef PROPAGATION_LOSS_MODEL_H
24
#ifndef PROPAGATION_LOSS_MODEL_H
 Lines 182-187    Link Here 
182
  double m_minDistance;
183
  double m_minDistance;
183
};
184
};
184
185
186
/*
187
 *
188
 * \brief a Two-Ray Ground propagation loss model ported from NS2
189
 *
190
 * Two-ray ground reflection model.
191
 *
192
 * \f$ Pr = \frac{Pt * Gt * Gr * (ht^2 * hr^2)}{d^4 * L} \f$
193
 *
194
 * The original equation in Rappaport's book assumes L = 1.
195
 * To be consistant with the free space equation, L is added here.
196
 *
197
 * Ht and Hr are set at the respective nodes z coordinate plus a model parameter
198
 * set via SetHeightAboveZ.
199
 *
200
 * The two-ray model does not give a good result for short distances, due to the
201
 * oscillation caused by constructive and destructive combination of the two
202
 * rays. Instead the Friis free-space model is used for small distances. 
203
 *
204
 * The crossover distance, below which Friis is used, is calculated as follows:
205
 *
206
 * \f$ dCross = \frac{(4 * pi * Ht * Hr)}{lambda} \f$
207
 */
208
209
class TwoRayGroundPropagationLossModel : public PropagationLossModel
210
{
211
public:
212
  static TypeId GetTypeId (void);
213
  TwoRayGroundPropagationLossModel ();
214
  /**
215
   * \param frequency (Hz)
216
   * \param speed (m/s)
217
   *
218
   * Set the main wavelength used in the TwoRayGround model 
219
   * calculation.
220
   */
221
  void SetLambda (double frequency, double speed);
222
  /**
223
   * \param lambda (m) the wavelength
224
   *
225
   * Set the main wavelength used in the TwoRayGround model 
226
   * calculation.
227
   */
228
  void SetLambda (double lambda);
229
  /**
230
   * \param systemLoss (dimension-less)
231
   *
232
   * Set the system loss used by the TwoRayGround propagation model.
233
   */
234
  void SetSystemLoss (double systemLoss);
235
  /**
236
   * \param minDistance the minimum distance
237
   *
238
   * Below this distance, the txpower is returned
239
   * unmodified as the rxpower.
240
   */
241
  void SetMinDistance (double minDistance);
242
  /**
243
   * \returns the minimum distance.
244
   */
245
  double GetMinDistance (void) const;
246
  /**
247
   * \returns the current wavelength (m)
248
   */
249
  double GetLambda (void) const;
250
  /**
251
   * \returns the current system loss (dimention-less)
252
   */
253
  double GetSystemLoss (void) const;
254
  /**
255
   * \Set the model antenna height above the node's Z coordinate
256
   */
257
  void SetHeightAboveZ (double heightAboveZ);
258
259
private:
260
  TwoRayGroundPropagationLossModel (const TwoRayGroundPropagationLossModel &o);
261
  TwoRayGroundPropagationLossModel & operator = (const TwoRayGroundPropagationLossModel &o);
262
  virtual double DoCalcRxPower (double txPowerDbm,
263
                                Ptr<MobilityModel> a,
264
                                Ptr<MobilityModel> b) const;
265
  double DbmToW (double dbm) const;
266
  double DbmFromW (double w) const;
267
268
  static const double PI;
269
  double m_lambda;
270
  double m_systemLoss;
271
  double m_minDistance;
272
  double m_heightAboveZ;
273
};
274
185
/**
275
/**
186
 * \brief a log distance propagation model.
276
 * \brief a log distance propagation model.
187
 *
277
 *
 Lines 217-223    Link Here 
217
  double GetPathLossExponent (void) const;
307
  double GetPathLossExponent (void) const;
218
308
219
  void SetReference (double referenceDistance, double referenceLoss);
309
  void SetReference (double referenceDistance, double referenceLoss);
220
  
310
221
private:
311
private:
222
  LogDistancePropagationLossModel (const LogDistancePropagationLossModel &o);
312
  LogDistancePropagationLossModel (const LogDistancePropagationLossModel &o);
223
  LogDistancePropagationLossModel & operator = (const LogDistancePropagationLossModel &o);
313
  LogDistancePropagationLossModel & operator = (const LogDistancePropagationLossModel &o);
 Lines 251-259    Link Here 
251
 *
341
 *
252
 * \f[\displaystyle L =
342
 * \f[\displaystyle L =
253
\begin{cases}
343
\begin{cases}
254
0 & d < d_0 \\
344
0 & d < d_0 \ \
255
L_0 + 10 \cdot n_0 \log_{10}(\frac{d}{d_0}) & d_0 \leq d < d_1 \\
345
L_0 + 10 \cdot n_0 \log_{10}(\frac{d}{d_0}) & d_0 \leq d < d_1 \ \
256
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 \\
346
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 \ \
257
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
347
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
258
\end{cases}\f]
348
\end{cases}\f]
259
 *
349
 *

Return to bug 787