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

(-)a/src/devices/wifi/propagation-loss-model-test-suite.cc (+101 lines)
 Lines 145-150    Link Here 
145
  return GetErrorStatus ();
145
  return GetErrorStatus ();
146
}
146
}
147
147
148
// Added for Two-Ray Ground Model - T.Hewer@cs.ucl.ac.uk
149
150
class TwoRayGroundPropagationLossModelTestCase : public TestCase
151
{
152
public:
153
	TwoRayGroundPropagationLossModelTestCase ();
154
	virtual ~TwoRayGroundPropagationLossModelTestCase ();
155
	
156
private:
157
	virtual bool DoRun (void);
158
	
159
	typedef struct {
160
		Vector m_position;
161
		double m_pt;  // dBm
162
		double m_pr;  // W
163
		double m_tolerance;
164
	} TestVector;
165
	
166
	TestVectors<TestVector> m_testVectors;
167
};
168
169
TwoRayGroundPropagationLossModelTestCase::TwoRayGroundPropagationLossModelTestCase ()
170
: TestCase ("Check to see that the ns-3 TwoRayGround propagation loss model provides correct received power"), m_testVectors ()
171
{
172
}
173
174
TwoRayGroundPropagationLossModelTestCase::~TwoRayGroundPropagationLossModelTestCase ()
175
{
176
}
177
178
bool
179
TwoRayGroundPropagationLossModelTestCase::DoRun (void)
180
{
181
	// wavelength at 2.4 GHz is 0.125m
182
	Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::Lambda", DoubleValue (0.125));
183
	Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::SystemLoss", DoubleValue (1.0));
184
	
185
	// Select a reference transmit power of 17.0206 dBm
186
	// Pt = 10^(17.0206/10)/10^3 = .05035702 W
187
	double txPowerW = 0.05035702;
188
	double txPowerdBm = 10 * log10 (txPowerW) + 30;
189
	
190
	//
191
	// As with the Friis tests above, we want to test the propagation loss 
192
	// model calculations at a few chosen distances and compare the results 
193
	// to those we can manually calculate. Let us test the ns-3 calculated 
194
	// value for agreement to be within 5e-16, as above.
195
	//
196
	TestVector testVector;
197
	
198
	// Below the Crossover distance use Friis so this test should be the same as that above
199
	// Crossover = (4 * PI * RxAntennaHeight * RxAntennaHeight) / Lamdba
200
	// Crossover = (4 * PI * 1.5 * 1.5) / 0.125 = 226.1946m
201
	
202
	testVector.m_position = Vector (100, 0, 0);
203
	testVector.m_pt = txPowerdBm;
204
	testVector.m_pr = 4.98265e-10;
205
	testVector.m_tolerance = 5e-16;
206
	m_testVectors.Add (testVector);
207
	
208
	// These values are above the crossover distance and therefore use the Two Ray calculation
209
	
210
	testVector.m_position = Vector (500, 0, 0);
211
	testVector.m_pt = txPowerdBm;
212
	testVector.m_pr = 4.07891862e-12;
213
	testVector.m_tolerance = 5e-16;
214
	m_testVectors.Add (testVector);
215
	
216
	testVector.m_position = Vector (1000, 0, 0);
217
	testVector.m_pt = txPowerdBm;
218
	testVector.m_pr = 2.5493241375e-13;
219
	testVector.m_tolerance = 5e-16;
220
	m_testVectors.Add (testVector);
221
	
222
	testVector.m_position = Vector (2000, 0, 0);
223
	testVector.m_pt = txPowerdBm;
224
	testVector.m_pr = 1.593327585938e-14;
225
	testVector.m_tolerance = 5e-16;
226
	m_testVectors.Add (testVector);
227
	
228
	// Now, check that the received power values are expected
229
	
230
	Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel> (); 
231
	a->SetPosition (Vector (0,0,0));
232
	Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel> (); 
233
	
234
	Ptr<TwoRayGroundPropagationLossModel> lossModel = CreateObject<TwoRayGroundPropagationLossModel> (); 
235
	for (uint32_t i = 0; i < m_testVectors.GetN (); ++i)
236
    {
237
		testVector = m_testVectors.Get (i);
238
		b->SetPosition (testVector.m_position);
239
		double resultdBm = lossModel->CalcRxPower (testVector.m_pt, a, b);
240
		double resultW =   pow (10.0, resultdBm/10.0)/1000;
241
		NS_TEST_EXPECT_MSG_EQ_TOL (resultW, testVector.m_pr, testVector.m_tolerance, "Got unexpected rcv power");
242
    }
243
	
244
	return GetErrorStatus ();
245
}
246
247
148
class LogDistancePropagationLossModelTestCase : public TestCase
248
class LogDistancePropagationLossModelTestCase : public TestCase
149
{
249
{
150
public:
250
public:
 Lines 244-249    Link Here 
244
  : TestSuite ("propagation-loss-model", UNIT)
344
  : TestSuite ("propagation-loss-model", UNIT)
245
{
345
{
246
  AddTestCase (new FriisPropagationLossModelTestCase);
346
  AddTestCase (new FriisPropagationLossModelTestCase);
347
  AddTestCase (new TwoRayGroundPropagationLossModelTestCase);
247
  AddTestCase (new LogDistancePropagationLossModelTestCase);
348
  AddTestCase (new LogDistancePropagationLossModelTestCase);
248
}
349
}
249
350
(-)a/src/devices/wifi/propagation-loss-model.cc (-514 / +694 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 <t.hewer@cs.ucl.ac.uk> for Two Ray Ground Model
20
 */
21
 */
21
22
22
#include "propagation-loss-model.h"
23
#include "propagation-loss-model.h"
 Lines 29-546    Link Here 
29
NS_LOG_COMPONENT_DEFINE ("PropagationLossModel");
30
NS_LOG_COMPONENT_DEFINE ("PropagationLossModel");
30
31
31
namespace ns3 {
32
namespace ns3 {
32
33
	
33
// ------------------------------------------------------------------------- //
34
	// ------------------------------------------------------------------------- //
34
35
	
35
NS_OBJECT_ENSURE_REGISTERED (PropagationLossModel);
36
	NS_OBJECT_ENSURE_REGISTERED (PropagationLossModel);
36
37
	
37
TypeId 
38
	TypeId 
38
PropagationLossModel::GetTypeId (void)
39
	PropagationLossModel::GetTypeId (void)
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
	{}
49
50
	
50
PropagationLossModel::~PropagationLossModel ()
51
	PropagationLossModel::~PropagationLossModel ()
51
{}
52
	{}
52
53
	
53
void 
54
	void 
54
PropagationLossModel::SetNext (Ptr<PropagationLossModel> next)
55
	PropagationLossModel::SetNext (Ptr<PropagationLossModel> next)
55
{
56
	{
56
  m_next = next;
57
		m_next = next;
57
}
58
	}
58
59
	
59
double 
60
	double 
60
PropagationLossModel::CalcRxPower (double txPowerDbm,
61
	PropagationLossModel::CalcRxPower (double txPowerDbm,
61
                                   Ptr<MobilityModel> a,
62
									   Ptr<MobilityModel> a,
62
                                   Ptr<MobilityModel> b) const
63
									   Ptr<MobilityModel> b) const
63
{
64
	{
64
  double self = DoCalcRxPower (txPowerDbm, a, b);
65
		double self = DoCalcRxPower (txPowerDbm, a, b);
65
  if (m_next != 0)
66
		if (m_next != 0)
66
    {
67
		{
67
      self = m_next->CalcRxPower (self, a, b);
68
			self = m_next->CalcRxPower (self, a, b);
68
    }
69
		}
69
  return self;
70
		return self;
70
}
71
	}
71
72
	
72
// ------------------------------------------------------------------------- //
73
	// ------------------------------------------------------------------------- //
73
74
	
74
NS_OBJECT_ENSURE_REGISTERED (RandomPropagationLossModel);
75
	NS_OBJECT_ENSURE_REGISTERED (RandomPropagationLossModel);
75
76
	
76
TypeId 
77
	TypeId 
77
RandomPropagationLossModel::GetTypeId (void)
78
	RandomPropagationLossModel::GetTypeId (void)
78
{
79
	{
79
  static TypeId tid = TypeId ("ns3::RandomPropagationLossModel")
80
		static TypeId tid = TypeId ("ns3::RandomPropagationLossModel")
80
    .SetParent<PropagationLossModel> ()
81
		.SetParent<PropagationLossModel> ()
81
    .AddConstructor<RandomPropagationLossModel> ()
82
		.AddConstructor<RandomPropagationLossModel> ()
82
    .AddAttribute ("Variable", "The random variable used to pick a loss everytime CalcRxPower is invoked.",
83
		.AddAttribute ("Variable", "The random variable used to pick a loss everytime CalcRxPower is invoked.",
83
                   RandomVariableValue (ConstantVariable (1.0)),
84
					   RandomVariableValue (ConstantVariable (1.0)),
84
                   MakeRandomVariableAccessor (&RandomPropagationLossModel::m_variable),
85
					   MakeRandomVariableAccessor (&RandomPropagationLossModel::m_variable),
85
                   MakeRandomVariableChecker ())
86
					   MakeRandomVariableChecker ())
86
    ;
87
		;
87
  return tid;
88
		return tid;
88
}
89
	}
89
RandomPropagationLossModel::RandomPropagationLossModel ()
90
	RandomPropagationLossModel::RandomPropagationLossModel ()
90
  : PropagationLossModel ()
91
	: PropagationLossModel ()
91
{}
92
	{}
92
93
	
93
RandomPropagationLossModel::~RandomPropagationLossModel ()
94
	RandomPropagationLossModel::~RandomPropagationLossModel ()
94
{}
95
	{}
95
96
	
96
double 
97
	double 
97
RandomPropagationLossModel::DoCalcRxPower (double txPowerDbm,
98
	RandomPropagationLossModel::DoCalcRxPower (double txPowerDbm,
98
                                           Ptr<MobilityModel> a,
99
											   Ptr<MobilityModel> a,
99
                                           Ptr<MobilityModel> b) const
100
											   Ptr<MobilityModel> b) const
100
{
101
	{
101
  double rxc = -m_variable.GetValue ();
102
		double rxc = -m_variable.GetValue ();
102
  NS_LOG_DEBUG ("attenuation coefficent="<<rxc<<"Db");
103
		NS_LOG_DEBUG ("attenuation coefficent="<<rxc<<"Db");
103
  return txPowerDbm + rxc;
104
		return txPowerDbm + rxc;
104
}
105
	}
105
106
	
106
// ------------------------------------------------------------------------- //
107
	// ------------------------------------------------------------------------- //
107
108
	
108
NS_OBJECT_ENSURE_REGISTERED (FriisPropagationLossModel);
109
	NS_OBJECT_ENSURE_REGISTERED (FriisPropagationLossModel);
109
110
	
110
const double FriisPropagationLossModel::PI = 3.14159265358979323846;
111
	const double FriisPropagationLossModel::PI = 3.14159265358979323846;
111
112
	
112
TypeId 
113
	TypeId 
113
FriisPropagationLossModel::GetTypeId (void)
114
	FriisPropagationLossModel::GetTypeId (void)
114
{
115
	{
115
  static TypeId tid = TypeId ("ns3::FriisPropagationLossModel")
116
		static TypeId tid = TypeId ("ns3::FriisPropagationLossModel")
116
    .SetParent<PropagationLossModel> ()
117
		.SetParent<PropagationLossModel> ()
117
    .AddConstructor<FriisPropagationLossModel> ()
118
		.AddConstructor<FriisPropagationLossModel> ()
118
    .AddAttribute ("Lambda", 
119
		.AddAttribute ("Lambda", 
119
                   "The wavelength  (default is 5.15 GHz at 300 000 km/s).",
120
					   "The wavelength  (default is 5.15 GHz at 300 000 km/s).",
120
                   DoubleValue (300000000.0 / 5.150e9),
121
					   DoubleValue (300000000.0 / 5.150e9),
121
                   MakeDoubleAccessor (&FriisPropagationLossModel::m_lambda),
122
					   MakeDoubleAccessor (&FriisPropagationLossModel::m_lambda),
122
                   MakeDoubleChecker<double> ())
123
					   MakeDoubleChecker<double> ())
123
    .AddAttribute ("SystemLoss", "The system loss",
124
		.AddAttribute ("SystemLoss", "The system loss",
124
                   DoubleValue (1.0),
125
					   DoubleValue (1.0),
125
                   MakeDoubleAccessor (&FriisPropagationLossModel::m_systemLoss),
126
					   MakeDoubleAccessor (&FriisPropagationLossModel::m_systemLoss),
126
                   MakeDoubleChecker<double> ())
127
					   MakeDoubleChecker<double> ())
127
    .AddAttribute ("MinDistance", 
128
		.AddAttribute ("MinDistance", 
128
                   "The distance under which the propagation model refuses to give results (m)",
129
					   "The distance under which the propagation model refuses to give results (m)",
129
                   DoubleValue (0.5),
130
					   DoubleValue (0.5),
130
                   MakeDoubleAccessor (&FriisPropagationLossModel::SetMinDistance,
131
					   MakeDoubleAccessor (&FriisPropagationLossModel::SetMinDistance,
131
                                       &FriisPropagationLossModel::GetMinDistance),
132
										   &FriisPropagationLossModel::GetMinDistance),
132
                   MakeDoubleChecker<double> ())
133
					   MakeDoubleChecker<double> ())
133
    ;
134
		;
134
  return tid;
135
		return tid;
135
}
136
	}
136
137
	
137
FriisPropagationLossModel::FriisPropagationLossModel ()
138
	FriisPropagationLossModel::FriisPropagationLossModel ()
138
{}
139
	{}
139
void 
140
	void 
140
FriisPropagationLossModel::SetSystemLoss (double systemLoss)
141
	FriisPropagationLossModel::SetSystemLoss (double systemLoss)
141
{
142
	{
142
  m_systemLoss = systemLoss;
143
		m_systemLoss = systemLoss;
143
}
144
	}
144
double 
145
	double 
145
FriisPropagationLossModel::GetSystemLoss (void) const
146
	FriisPropagationLossModel::GetSystemLoss (void) const
146
{
147
	{
147
  return m_systemLoss;
148
		return m_systemLoss;
148
}
149
	}
149
void 
150
	void 
150
FriisPropagationLossModel::SetMinDistance (double minDistance)
151
	FriisPropagationLossModel::SetMinDistance (double minDistance)
151
{
152
	{
152
  m_minDistance = minDistance;
153
		m_minDistance = minDistance;
153
}
154
	}
154
double 
155
	double 
155
FriisPropagationLossModel::GetMinDistance (void) const
156
	FriisPropagationLossModel::GetMinDistance (void) const
156
{
157
	{
157
  return m_minDistance;
158
		return m_minDistance;
158
}
159
	}
159
void 
160
	void 
160
FriisPropagationLossModel::SetLambda (double frequency, double speed)
161
	FriisPropagationLossModel::SetLambda (double frequency, double speed)
161
{
162
	{
162
  m_lambda = speed / frequency;
163
		m_lambda = speed / frequency;
163
}
164
	}
164
void 
165
	void 
165
FriisPropagationLossModel::SetLambda (double lambda)
166
	FriisPropagationLossModel::SetLambda (double lambda)
166
{
167
	{
167
  m_lambda = lambda;
168
		m_lambda = lambda;
168
}
169
	}
169
double 
170
	double 
170
FriisPropagationLossModel::GetLambda (void) const
171
	FriisPropagationLossModel::GetLambda (void) const
171
{
172
	{
172
  return m_lambda;
173
		return m_lambda;
173
}
174
	}
174
175
	
175
double 
176
	double 
176
FriisPropagationLossModel::DbmToW (double dbm) const
177
	FriisPropagationLossModel::DbmToW (double dbm) const
177
{
178
	{
178
  double mw = pow(10.0,dbm/10.0);
179
		double mw = pow(10.0,dbm/10.0);
179
  return mw / 1000.0;
180
		return mw / 1000.0;
180
}
181
	}
181
182
	
182
double
183
	double
183
FriisPropagationLossModel::DbmFromW (double w) const
184
	FriisPropagationLossModel::DbmFromW (double w) const
184
{
185
	{
185
  double dbm = log10 (w * 1000.0) * 10.0;
186
		double dbm = log10 (w * 1000.0) * 10.0;
186
  return dbm;
187
		return dbm;
187
}
188
	}
188
189
	
189
double 
190
	double 
190
FriisPropagationLossModel::DoCalcRxPower (double txPowerDbm,
191
	FriisPropagationLossModel::DoCalcRxPower (double txPowerDbm,
191
                                          Ptr<MobilityModel> a,
192
											  Ptr<MobilityModel> a,
192
                                          Ptr<MobilityModel> b) const
193
											  Ptr<MobilityModel> b) const
193
{
194
	{
194
  /*
195
		/*
195
   * Friis free space equation:
196
		 * Friis free space equation:
196
   * where Pt, Gr, Gr and P are in Watt units
197
		 * where Pt, Gr, Gr and P are in Watt units
197
   * L is in meter units.
198
		 * L is in meter units.
198
   *
199
		 *
199
   *    P     Gt * Gr * (lambda^2)
200
		 *    P     Gt * Gr * (lambda^2)
200
   *   --- = ---------------------
201
		 *   --- = ---------------------
201
   *    Pt     (4 * pi * d)^2 * L
202
		 *    Pt     (4 * pi * d)^2 * L
202
   *
203
		 *
203
   * Gt: tx gain (unit-less)
204
		 * Gt: tx gain (unit-less)
204
   * Gr: rx gain (unit-less)
205
		 * Gr: rx gain (unit-less)
205
   * Pt: tx power (W)
206
		 * Pt: tx power (W)
206
   * d: distance (m)
207
		 * d: distance (m)
207
   * L: system loss
208
		 * L: system loss
208
   * lambda: wavelength (m)
209
		 * lambda: wavelength (m)
209
   *
210
		 *
210
   * Here, we ignore tx and rx gain and the input and output values 
211
		 * Here, we ignore tx and rx gain and the input and output values 
211
   * are in dB or dBm:
212
		 * are in dB or dBm:
212
   *
213
		 *
213
   *                           lambda^2
214
		 *                           lambda^2
214
   * rx = tx +  10 log10 (-------------------)
215
		 * rx = tx +  10 log10 (-------------------)
215
   *                       (4 * pi * d)^2 * L
216
		 *                       (4 * pi * d)^2 * L
216
   *
217
		 *
217
   * rx: rx power (dB)
218
		 * rx: rx power (dB)
218
   * tx: tx power (dB)
219
		 * tx: tx power (dB)
219
   * d: distance (m)
220
		 * d: distance (m)
220
   * L: system loss (unit-less)
221
		 * L: system loss (unit-less)
221
   * lambda: wavelength (m)
222
		 * lambda: wavelength (m)
222
   */
223
		 */
223
  double distance = a->GetDistanceFrom (b);
224
		double distance = a->GetDistanceFrom (b);
224
  if (distance <= m_minDistance)
225
		if (distance <= m_minDistance)
225
    {
226
		{
226
      return txPowerDbm;
227
			return txPowerDbm;
227
    }
228
		}
228
  double numerator = m_lambda * m_lambda;
229
		double numerator = m_lambda * m_lambda;
229
  double denominator = 16 * PI * PI * distance * distance * m_systemLoss;
230
		double denominator = 16 * PI * PI * distance * distance * m_systemLoss;
230
  double pr = 10 * log10 (numerator / denominator);
231
		double pr = 10 * log10 (numerator / denominator);
231
  NS_LOG_DEBUG ("distance="<<distance<<"m, attenuation coefficient="<<pr<<"dB");
232
		NS_LOG_DEBUG ("distance="<<distance<<"m, attenuation coefficient="<<pr<<"dB");
232
  return txPowerDbm + pr;
233
		return txPowerDbm + pr;
233
}
234
	}
234
235
	
235
// ------------------------------------------------------------------------- //
236
	// ------------------------------------------------------------------------- //
236
237
	// -- Two-Ray Ground Model ported from NS-2 -- T.Hewer@cs.ucl.ac.uk -- Nov09 //
237
NS_OBJECT_ENSURE_REGISTERED (LogDistancePropagationLossModel);
238
	
238
239
	NS_OBJECT_ENSURE_REGISTERED (TwoRayGroundPropagationLossModel);
239
TypeId
240
	
240
LogDistancePropagationLossModel::GetTypeId (void)
241
	const double TwoRayGroundPropagationLossModel::PI = 3.14159265358979323846;
241
{
242
	
242
  static TypeId tid = TypeId ("ns3::LogDistancePropagationLossModel")
243
	TypeId 
243
    .SetParent<PropagationLossModel> ()
244
	TwoRayGroundPropagationLossModel::GetTypeId (void)
244
    .AddConstructor<LogDistancePropagationLossModel> ()
245
	{
245
    .AddAttribute ("Exponent",
246
		static TypeId tid = TypeId ("ns3::TwoRayGroundPropagationLossModel")
246
                   "The exponent of the Path Loss propagation model",
247
		.SetParent<PropagationLossModel> ()
247
                   DoubleValue (3.0),
248
		.AddConstructor<TwoRayGroundPropagationLossModel> ()
248
                   MakeDoubleAccessor (&LogDistancePropagationLossModel::m_exponent),
249
		.AddAttribute ("Lambda", 
249
                   MakeDoubleChecker<double> ())
250
					   "The wavelength  (default is 5.15 GHz at 300 000 km/s).",
250
    .AddAttribute ("ReferenceDistance",
251
					   DoubleValue (300000000.0 / 5.150e9),
251
                   "The distance at which the reference loss is calculated (m)",
252
					   MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::m_lambda),
252
                   DoubleValue (1.0),
253
					   MakeDoubleChecker<double> ())
253
                   MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceDistance),
254
		.AddAttribute ("SystemLoss", "The system loss",
254
                   MakeDoubleChecker<double> ())
255
					   DoubleValue (1.0),
255
    .AddAttribute ("ReferenceLoss",
256
					   MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::m_systemLoss),
256
                   "The reference loss at reference distance (dB). (Default is Friis at 1m with 5.15 GHz)",
257
					   MakeDoubleChecker<double> ())
257
                   DoubleValue (46.6777),
258
		.AddAttribute ("MinDistance", 
258
                   MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceLoss),
259
					   "The distance under which the propagation model refuses to give results (m)",
259
                   MakeDoubleChecker<double> ())
260
					   DoubleValue (0.5),
260
    ;
261
					   MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::SetMinDistance,
261
  return tid;
262
										   &TwoRayGroundPropagationLossModel::GetMinDistance),
262
                   
263
					   MakeDoubleChecker<double> ())
263
}
264
		.AddAttribute ("TxAntHeight", 
264
265
					   "The height of the transmitting antenna (m)",
265
LogDistancePropagationLossModel::LogDistancePropagationLossModel ()
266
					   DoubleValue (1.5),
266
{}
267
					   MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::m_txAntHeight),
267
268
					   MakeDoubleChecker<double> ())
268
void 
269
		.AddAttribute ("RxAntHeight", 
269
LogDistancePropagationLossModel::SetPathLossExponent (double n)
270
					   "The height of the receiving antenna (m)",
270
{
271
					   DoubleValue (1.5),
271
  m_exponent = n;
272
					   MakeDoubleAccessor (&TwoRayGroundPropagationLossModel::m_rxAntHeight),
272
}
273
					   MakeDoubleChecker<double> ())
273
void 
274
		;
274
LogDistancePropagationLossModel::SetReference (double referenceDistance, double referenceLoss)
275
		return tid;
275
{
276
	}
276
  m_referenceDistance = referenceDistance;
277
	
277
  m_referenceLoss = referenceLoss;
278
	TwoRayGroundPropagationLossModel::TwoRayGroundPropagationLossModel ()
278
}
279
	{}
279
double 
280
	void 
280
LogDistancePropagationLossModel::GetPathLossExponent (void) const
281
	TwoRayGroundPropagationLossModel::SetSystemLoss (double systemLoss)
281
{
282
	{
282
  return m_exponent;
283
		m_systemLoss = systemLoss;
283
}
284
	}
284
  
285
	double 
285
double 
286
	TwoRayGroundPropagationLossModel::GetSystemLoss (void) const
286
LogDistancePropagationLossModel::DoCalcRxPower (double txPowerDbm,
287
	{
287
                                                Ptr<MobilityModel> a,
288
		return m_systemLoss;
288
                                                Ptr<MobilityModel> b) const
289
	}
289
{
290
	void 
290
  double distance = a->GetDistanceFrom (b);
291
	TwoRayGroundPropagationLossModel::SetMinDistance (double minDistance)
291
  if (distance <= m_referenceDistance)
292
	{
292
    {
293
		m_minDistance = minDistance;
293
      return txPowerDbm;
294
	}
294
    }
295
	double 
295
  /**
296
	TwoRayGroundPropagationLossModel::GetMinDistance (void) const
296
   * The formula is:
297
	{
297
   * rx = 10 * log (Pr0(tx)) - n * 10 * log (d/d0)
298
		return m_minDistance;
298
   *
299
	}
299
   * Pr0: rx power at reference distance d0 (W)
300
	void
300
   * d0: reference distance: 1.0 (m)
301
	TwoRayGroundPropagationLossModel::SetTxAntHeight (double txAntHeight)
301
   * d: distance (m)
302
	{
302
   * tx: tx power (dB)
303
		m_txAntHeight = txAntHeight;
303
   * rx: dB
304
	}
304
   *
305
	void
305
   * Which, in our case is:
306
	TwoRayGroundPropagationLossModel::SetRxAntHeight (double rxAntHeight)
306
   *
307
	{
307
   * rx = rx0(tx) - 10 * n * log (d/d0)
308
		m_rxAntHeight = rxAntHeight;
308
   */
309
	}
309
  double pathLossDb = 10 * m_exponent * log10 (distance / m_referenceDistance);
310
	double 
310
  double rxc = -m_referenceLoss - pathLossDb;
311
	TwoRayGroundPropagationLossModel::GetTxAntHeight (void) const
311
  NS_LOG_DEBUG ("distance="<<distance<<"m, reference-attenuation="<<-m_referenceLoss<<"dB, "<<
312
	{
312
		"attenuation coefficient="<<rxc<<"db");
313
		return m_txAntHeight;
313
  return txPowerDbm + rxc;
314
	}
314
}
315
	double 
315
316
	TwoRayGroundPropagationLossModel::GetRxAntHeight (void) const
316
// ------------------------------------------------------------------------- //
317
	{
317
318
		return m_rxAntHeight;
318
NS_OBJECT_ENSURE_REGISTERED (ThreeLogDistancePropagationLossModel);
319
	}
319
320
	void 
320
TypeId
321
	TwoRayGroundPropagationLossModel::SetLambda (double frequency, double speed)
321
ThreeLogDistancePropagationLossModel::GetTypeId (void)
322
	{
322
{
323
		m_lambda = speed / frequency;
323
  static TypeId tid = TypeId ("ns3::ThreeLogDistancePropagationLossModel")
324
	}
324
    .SetParent<PropagationLossModel> ()
325
	void 
325
    .AddConstructor<ThreeLogDistancePropagationLossModel> ()
326
	TwoRayGroundPropagationLossModel::SetLambda (double lambda)
326
    .AddAttribute ("Distance0",
327
	{
327
                   "Beginning of the first (near) distance field",
328
		m_lambda = lambda;
328
                   DoubleValue (1.0),
329
	}
329
                   MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance0),
330
	double 
330
                   MakeDoubleChecker<double> ())
331
	TwoRayGroundPropagationLossModel::GetLambda (void) const
331
    .AddAttribute ("Distance1",
332
	{
332
                   "Beginning of the second (middle) distance field.",
333
		return m_lambda;
333
                   DoubleValue (200.0),
334
	}
334
                   MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance1),
335
	
335
                   MakeDoubleChecker<double> ())
336
	double 
336
    .AddAttribute ("Distance2",
337
	TwoRayGroundPropagationLossModel::DbmToW (double dbm) const
337
                   "Beginning of the third (far) distance field.",
338
	{
338
                   DoubleValue (500.0),
339
		double mw = pow(10.0,dbm/10.0);
339
                   MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance2),
340
		return mw / 1000.0;
340
                   MakeDoubleChecker<double> ())
341
	}
341
    .AddAttribute ("Exponent0",
342
	
342
                   "The exponent for the first field.",
343
	double
343
                   DoubleValue (1.9),
344
	TwoRayGroundPropagationLossModel::DbmFromW (double w) const
344
                   MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent0),
345
	{
345
                   MakeDoubleChecker<double> ())
346
		double dbm = log10 (w * 1000.0) * 10.0;
346
    .AddAttribute ("Exponent1",
347
		return dbm;
347
                   "The exponent for the second field.",
348
	}
348
                   DoubleValue (3.8),
349
	
349
                   MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent1),
350
	double 
350
                   MakeDoubleChecker<double> ())
351
	TwoRayGroundPropagationLossModel::DoCalcRxPower (double txPowerDbm,
351
    .AddAttribute ("Exponent2",
352
													 Ptr<MobilityModel> a,
352
                   "The exponent for the third field.",
353
													 Ptr<MobilityModel> b) const
353
                   DoubleValue (3.8),
354
	{
354
                   MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent2),
355
		/*
355
                   MakeDoubleChecker<double> ())
356
		 * Two-Ray Ground equation:
356
    .AddAttribute ("ReferenceLoss",
357
		 *
357
                   "The reference loss at distance d0 (dB). (Default is Friis at 1m with 5.15 GHz)",
358
		 * where Pt, Gt and Gr are in dBm units
358
                   DoubleValue (46.6777),
359
		 * L, Ht and Hr are in meter units.
359
                   MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_referenceLoss),
360
		 *
360
                   MakeDoubleChecker<double> ())
361
		 *   Pr      Gt * Gr * (Ht^2 * Hr^2)
361
    ;
362
		 *   -- =  (-------------------------)
362
  return tid;
363
		 *	 Pt            d^4 * L
363
                   
364
		 *
364
}
365
		 * Gt: tx gain (unit-less)
365
366
		 * Gr: rx gain (unit-less)
366
ThreeLogDistancePropagationLossModel::ThreeLogDistancePropagationLossModel ()
367
		 * Pt: tx power (dBm)
367
{
368
		 * d: distance (m)
368
}
369
		 * L: system loss
369
370
		 * Ht: Tx antenna height (m)
370
double 
371
		 * Hr: Rx antenna height (m)
371
ThreeLogDistancePropagationLossModel::DoCalcRxPower (double txPowerDbm,
372
		 * lambda: wavelength (m)
372
                                                     Ptr<MobilityModel> a,
373
		 *
373
                                                     Ptr<MobilityModel> b) const
374
		 * As with the Friis model we ignore tx and rx gain and output values
374
{
375
		 * are in dB or dBm
375
  double distance = a->GetDistanceFrom (b);
376
		 *
376
  NS_ASSERT(distance >= 0);
377
		 *						  (Ht * Ht) * (Hr * Hr)
377
378
		 * rx = tx + 10 log10	(-----------------------)
378
  // See doxygen comments for the formula and explanation
379
		 *						   (d * d * d * d) * L
379
380
		 */
380
  double pathLossDb;
381
		double distance = a->GetDistanceFrom (b);
381
382
		if (distance <= m_minDistance)
382
  if (distance < m_distance0)
383
		{
383
    {
384
			return txPowerDbm;
384
      pathLossDb = 0;
385
		}
385
    }
386
		
386
  else if (distance < m_distance1)
387
		// Calculate a crossover distance, under which we use Friis
387
    {
388
		/*
388
      pathLossDb = m_referenceLoss
389
		 * 
389
        + 10 * m_exponent0 * log10(distance / m_distance0);
390
		 * dCross = (4 * pi * Ht * Hr) / lambda
390
    }
391
		 *
391
  else if (distance < m_distance2)
392
		 */
392
    {
393
		
393
      pathLossDb = m_referenceLoss
394
		double dCross = (4 * PI * m_txAntHeight * m_rxAntHeight) / GetLambda();
394
        + 10 * m_exponent0 * log10(m_distance1 / m_distance0)
395
		
395
        + 10 * m_exponent1 * log10(distance / m_distance1);
396
		if (distance <= dCross) {
396
    }
397
			// We use Friis
397
  else
398
			double numerator = m_lambda * m_lambda;
398
    {
399
			double denominator = 16 * PI * PI * distance * distance * m_systemLoss;
399
      pathLossDb = m_referenceLoss
400
			double pr = 10 * log10 (numerator / denominator);
400
        + 10 * m_exponent0 * log10(m_distance1 / m_distance0)
401
			NS_LOG_DEBUG ("Receiver within crossover ("<<dCross<<"m) for Two_ray path; using Friis");
401
        + 10 * m_exponent1 * log10(m_distance2 / m_distance1)
402
			NS_LOG_DEBUG ("distance="<<distance<<"m, attenuation coefficient="<<pr<<"dB");
402
        + 10 * m_exponent2 * log10(distance / m_distance2);
403
			return txPowerDbm + pr;
403
    }
404
		}
404
405
		else { // Use Two-Ray Pathloss		
405
  NS_LOG_DEBUG ("ThreeLogDistance distance=" << distance << "m, " <<
406
			double rayNumerator = (m_txAntHeight * m_txAntHeight) * 
406
                "attenuation=" << pathLossDb << "dB");
407
			(m_rxAntHeight * m_rxAntHeight);
407
408
			double rayDenominator = (distance * distance * distance * distance) * m_systemLoss;
408
  return txPowerDbm - pathLossDb;
409
			double rayPr = 10 * log10 (rayNumerator / rayDenominator);
409
}
410
			NS_LOG_DEBUG ("distance="<<distance<<"m, attenuation coefficient="<<rayPr<<"dB");
410
411
			return txPowerDbm + rayPr;
411
// ------------------------------------------------------------------------- //
412
		}
412
413
	}
413
NS_OBJECT_ENSURE_REGISTERED (NakagamiPropagationLossModel);
414
	
414
415
	// ------------------------------------------------------------------------- //
415
TypeId
416
	
416
NakagamiPropagationLossModel::GetTypeId (void)
417
	NS_OBJECT_ENSURE_REGISTERED (LogDistancePropagationLossModel);
417
{
418
	
418
  static TypeId tid = TypeId ("ns3::NakagamiPropagationLossModel")
419
	TypeId
419
    .SetParent<PropagationLossModel> ()
420
	LogDistancePropagationLossModel::GetTypeId (void)
420
    .AddConstructor<NakagamiPropagationLossModel> ()
421
	{
421
    .AddAttribute ("Distance1",
422
		static TypeId tid = TypeId ("ns3::LogDistancePropagationLossModel")
422
                   "Beginning of the second distance field. Default is 80m.",
423
		.SetParent<PropagationLossModel> ()
423
                   DoubleValue (80.0),
424
		.AddConstructor<LogDistancePropagationLossModel> ()
424
                   MakeDoubleAccessor (&NakagamiPropagationLossModel::m_distance1),
425
		.AddAttribute ("Exponent",
425
                   MakeDoubleChecker<double> ())
426
					   "The exponent of the Path Loss propagation model",
426
    .AddAttribute ("Distance2",
427
					   DoubleValue (3.0),
427
                   "Beginning of the third distance field. Default is 200m.",
428
					   MakeDoubleAccessor (&LogDistancePropagationLossModel::m_exponent),
428
                   DoubleValue (200.0),
429
					   MakeDoubleChecker<double> ())
429
                   MakeDoubleAccessor (&NakagamiPropagationLossModel::m_distance2),
430
		.AddAttribute ("ReferenceDistance",
430
                   MakeDoubleChecker<double> ())
431
					   "The distance at which the reference loss is calculated (m)",
431
    .AddAttribute ("m0",
432
					   DoubleValue (1.0),
432
                   "m0 for distances smaller than Distance1. Default is 1.5.",
433
					   MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceDistance),
433
                   DoubleValue (1.5),
434
					   MakeDoubleChecker<double> ())
434
                   MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m0),
435
		.AddAttribute ("ReferenceLoss",
435
                   MakeDoubleChecker<double> ())
436
					   "The reference loss at reference distance (dB). (Default is Friis at 1m with 5.15 GHz)",
436
    .AddAttribute ("m1",
437
					   DoubleValue (46.6777),
437
                   "m1 for distances smaller than Distance2. Default is 0.75.",
438
					   MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceLoss),
438
                   DoubleValue (0.75),
439
					   MakeDoubleChecker<double> ())
439
                   MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m1),
440
		;
440
                   MakeDoubleChecker<double> ())
441
		return tid;
441
    .AddAttribute ("m2",
442
		
442
                   "m2 for distances greater than Distance2. Default is 0.75.",
443
	}
443
                   DoubleValue (0.75),
444
	
444
                   MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m2),
445
	LogDistancePropagationLossModel::LogDistancePropagationLossModel ()
445
                   MakeDoubleChecker<double> ())
446
	{}
446
    ;
447
	
447
  return tid;
448
	void 
448
                   
449
	LogDistancePropagationLossModel::SetPathLossExponent (double n)
449
}
450
	{
450
451
		m_exponent = n;
451
NakagamiPropagationLossModel::NakagamiPropagationLossModel ()
452
	}
452
{}
453
	void 
453
454
	LogDistancePropagationLossModel::SetReference (double referenceDistance, double referenceLoss)
454
double 
455
	{
455
NakagamiPropagationLossModel::DoCalcRxPower (double txPowerDbm,
456
		m_referenceDistance = referenceDistance;
456
                                             Ptr<MobilityModel> a,
457
		m_referenceLoss = referenceLoss;
457
                                             Ptr<MobilityModel> b) const
458
	}
458
{
459
	double 
459
  // select m parameter
460
	LogDistancePropagationLossModel::GetPathLossExponent (void) const
460
461
	{
461
  double distance = a->GetDistanceFrom (b);
462
		return m_exponent;
462
  NS_ASSERT(distance >= 0);
463
	}
463
464
	
464
  double m;
465
	double 
465
  if (distance < m_distance1)
466
	LogDistancePropagationLossModel::DoCalcRxPower (double txPowerDbm,
466
    {
467
													Ptr<MobilityModel> a,
467
      m = m_m0;
468
													Ptr<MobilityModel> b) const
468
    }
469
	{
469
  else if (distance < m_distance2)
470
		double distance = a->GetDistanceFrom (b);
470
    {
471
		if (distance <= m_referenceDistance)
471
      m = m_m1;
472
		{
472
    }
473
			return txPowerDbm;
473
  else
474
		}
474
    {
475
		/**
475
      m = m_m2;
476
		 * The formula is:
476
    }
477
		 * rx = 10 * log (Pr0(tx)) - n * 10 * log (d/d0)
477
  
478
		 *
478
  // the current power unit is dBm, but Watt is put into the Nakagami /
479
		 * Pr0: rx power at reference distance d0 (W)
479
  // Rayleigh distribution.
480
		 * d0: reference distance: 1.0 (m)
480
  double powerW = pow(10, (txPowerDbm - 30) / 10);
481
		 * d: distance (m)
481
482
		 * tx: tx power (dB)
482
  double resultPowerW;
483
		 * rx: dB
483
484
		 *
484
  // switch between Erlang- and Gamma distributions: this is only for
485
		 * Which, in our case is:
485
  // speed. (Gamma is equal to Erlang for any positive integer m.)
486
		 *
486
  unsigned int int_m = static_cast<unsigned int>(floor(m));
487
		 * rx = rx0(tx) - 10 * n * log (d/d0)
487
488
		 */
488
  if (int_m == m)
489
		double pathLossDb = 10 * m_exponent * log10 (distance / m_referenceDistance);
489
    {
490
		double rxc = -m_referenceLoss - pathLossDb;
490
      resultPowerW = m_erlangRandomVariable.GetValue(int_m, powerW / m);
491
		NS_LOG_DEBUG ("distance="<<distance<<"m, reference-attenuation="<<-m_referenceLoss<<"dB, "<<
491
    }
492
					  "attenuation coefficient="<<rxc<<"db");
492
  else
493
		return txPowerDbm + rxc;
493
    {
494
	}
494
      resultPowerW = m_gammaRandomVariable.GetValue(m, powerW / m);
495
	
495
    }
496
	// ------------------------------------------------------------------------- //
496
497
	
497
  double resultPowerDbm = 10 * log10(resultPowerW) + 30;
498
	NS_OBJECT_ENSURE_REGISTERED (ThreeLogDistancePropagationLossModel);
498
499
	
499
  NS_LOG_DEBUG ("Nakagami distance=" << distance << "m, " <<
500
	TypeId
500
                "power=" << powerW <<"W, " <<
501
	ThreeLogDistancePropagationLossModel::GetTypeId (void)
501
                "resultPower=" << resultPowerW << "W=" << resultPowerDbm << "dBm");
502
	{
502
503
		static TypeId tid = TypeId ("ns3::ThreeLogDistancePropagationLossModel")
503
  return resultPowerDbm;
504
		.SetParent<PropagationLossModel> ()
504
}
505
		.AddConstructor<ThreeLogDistancePropagationLossModel> ()
505
506
		.AddAttribute ("Distance0",
506
// ------------------------------------------------------------------------- //
507
					   "Beginning of the first (near) distance field",
507
508
					   DoubleValue (1.0),
508
NS_OBJECT_ENSURE_REGISTERED (FixedRssLossModel);
509
					   MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance0),
509
510
					   MakeDoubleChecker<double> ())
510
TypeId 
511
		.AddAttribute ("Distance1",
511
FixedRssLossModel::GetTypeId (void)
512
					   "Beginning of the second (middle) distance field.",
512
{
513
					   DoubleValue (200.0),
513
  static TypeId tid = TypeId ("ns3::FixedRssLossModel")
514
					   MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance1),
514
    .SetParent<PropagationLossModel> ()
515
					   MakeDoubleChecker<double> ())
515
    .AddConstructor<FixedRssLossModel> ()
516
		.AddAttribute ("Distance2",
516
    .AddAttribute ("Rss", "The fixed receiver Rss.",
517
					   "Beginning of the third (far) distance field.",
517
                   DoubleValue (-150.0),
518
					   DoubleValue (500.0),
518
                   MakeDoubleAccessor (&FixedRssLossModel::m_rss),
519
					   MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance2),
519
                   MakeDoubleChecker<double> ())
520
					   MakeDoubleChecker<double> ())
520
    ;
521
		.AddAttribute ("Exponent0",
521
  return tid;
522
					   "The exponent for the first field.",
522
}
523
					   DoubleValue (1.9),
523
FixedRssLossModel::FixedRssLossModel ()
524
					   MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent0),
524
  : PropagationLossModel ()
525
					   MakeDoubleChecker<double> ())
525
{}
526
		.AddAttribute ("Exponent1",
526
527
					   "The exponent for the second field.",
527
FixedRssLossModel::~FixedRssLossModel ()
528
					   DoubleValue (3.8),
528
{}
529
					   MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent1),
529
530
					   MakeDoubleChecker<double> ())
530
void 
531
		.AddAttribute ("Exponent2",
531
FixedRssLossModel::SetRss (double rss)
532
					   "The exponent for the third field.",
532
{
533
					   DoubleValue (3.8),
533
  m_rss = rss;
534
					   MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent2),
534
}
535
					   MakeDoubleChecker<double> ())
535
536
		.AddAttribute ("ReferenceLoss",
536
double 
537
					   "The reference loss at distance d0 (dB). (Default is Friis at 1m with 5.15 GHz)",
537
FixedRssLossModel::DoCalcRxPower (double txPowerDbm,
538
					   DoubleValue (46.6777),
538
                                           Ptr<MobilityModel> a,
539
					   MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_referenceLoss),
539
                                           Ptr<MobilityModel> b) const
540
					   MakeDoubleChecker<double> ())
540
{
541
		;
541
  return m_rss;
542
		return tid;
542
}
543
		
543
544
	}
544
// ------------------------------------------------------------------------- //
545
	
545
546
	ThreeLogDistancePropagationLossModel::ThreeLogDistancePropagationLossModel ()
547
	{
548
	}
549
	
550
	double 
551
	ThreeLogDistancePropagationLossModel::DoCalcRxPower (double txPowerDbm,
552
														 Ptr<MobilityModel> a,
553
														 Ptr<MobilityModel> b) const
554
	{
555
		double distance = a->GetDistanceFrom (b);
556
		NS_ASSERT(distance >= 0);
557
		
558
		// See doxygen comments for the formula and explanation
559
		
560
		double pathLossDb;
561
		
562
		if (distance < m_distance0)
563
		{
564
			pathLossDb = 0;
565
		}
566
		else if (distance < m_distance1)
567
		{
568
			pathLossDb = m_referenceLoss
569
			+ 10 * m_exponent0 * log10(distance / m_distance0);
570
		}
571
		else if (distance < m_distance2)
572
		{
573
			pathLossDb = m_referenceLoss
574
			+ 10 * m_exponent0 * log10(m_distance1 / m_distance0)
575
			+ 10 * m_exponent1 * log10(distance / m_distance1);
576
		}
577
		else
578
		{
579
			pathLossDb = m_referenceLoss
580
			+ 10 * m_exponent0 * log10(m_distance1 / m_distance0)
581
			+ 10 * m_exponent1 * log10(m_distance2 / m_distance1)
582
			+ 10 * m_exponent2 * log10(distance / m_distance2);
583
		}
584
		
585
		NS_LOG_DEBUG ("ThreeLogDistance distance=" << distance << "m, " <<
586
					  "attenuation=" << pathLossDb << "dB");
587
		
588
		return txPowerDbm - pathLossDb;
589
	}
590
	
591
	// ------------------------------------------------------------------------- //
592
	
593
	NS_OBJECT_ENSURE_REGISTERED (NakagamiPropagationLossModel);
594
	
595
	TypeId
596
	NakagamiPropagationLossModel::GetTypeId (void)
597
	{
598
		static TypeId tid = TypeId ("ns3::NakagamiPropagationLossModel")
599
		.SetParent<PropagationLossModel> ()
600
		.AddConstructor<NakagamiPropagationLossModel> ()
601
		.AddAttribute ("Distance1",
602
					   "Beginning of the second distance field. Default is 80m.",
603
					   DoubleValue (80.0),
604
					   MakeDoubleAccessor (&NakagamiPropagationLossModel::m_distance1),
605
					   MakeDoubleChecker<double> ())
606
		.AddAttribute ("Distance2",
607
					   "Beginning of the third distance field. Default is 200m.",
608
					   DoubleValue (200.0),
609
					   MakeDoubleAccessor (&NakagamiPropagationLossModel::m_distance2),
610
					   MakeDoubleChecker<double> ())
611
		.AddAttribute ("m0",
612
					   "m0 for distances smaller than Distance1. Default is 1.5.",
613
					   DoubleValue (1.5),
614
					   MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m0),
615
					   MakeDoubleChecker<double> ())
616
		.AddAttribute ("m1",
617
					   "m1 for distances smaller than Distance2. Default is 0.75.",
618
					   DoubleValue (0.75),
619
					   MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m1),
620
					   MakeDoubleChecker<double> ())
621
		.AddAttribute ("m2",
622
					   "m2 for distances greater than Distance2. Default is 0.75.",
623
					   DoubleValue (0.75),
624
					   MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m2),
625
					   MakeDoubleChecker<double> ())
626
		;
627
		return tid;
628
		
629
	}
630
	
631
	NakagamiPropagationLossModel::NakagamiPropagationLossModel ()
632
	{}
633
	
634
	double 
635
	NakagamiPropagationLossModel::DoCalcRxPower (double txPowerDbm,
636
												 Ptr<MobilityModel> a,
637
												 Ptr<MobilityModel> b) const
638
	{
639
		// select m parameter
640
		
641
		double distance = a->GetDistanceFrom (b);
642
		NS_ASSERT(distance >= 0);
643
		
644
		double m;
645
		if (distance < m_distance1)
646
		{
647
			m = m_m0;
648
		}
649
		else if (distance < m_distance2)
650
		{
651
			m = m_m1;
652
		}
653
		else
654
		{
655
			m = m_m2;
656
		}
657
		
658
		// the current power unit is dBm, but Watt is put into the Nakagami /
659
		// Rayleigh distribution.
660
		double powerW = pow(10, (txPowerDbm - 30) / 10);
661
		
662
		double resultPowerW;
663
		
664
		// switch between Erlang- and Gamma distributions: this is only for
665
		// speed. (Gamma is equal to Erlang for any positive integer m.)
666
		unsigned int int_m = static_cast<unsigned int>(floor(m));
667
		
668
		if (int_m == m)
669
		{
670
			resultPowerW = m_erlangRandomVariable.GetValue(int_m, powerW / m);
671
		}
672
		else
673
		{
674
			resultPowerW = m_gammaRandomVariable.GetValue(m, powerW / m);
675
		}
676
		
677
		double resultPowerDbm = 10 * log10(resultPowerW) + 30;
678
		
679
		NS_LOG_DEBUG ("Nakagami distance=" << distance << "m, " <<
680
					  "power=" << powerW <<"W, " <<
681
					  "resultPower=" << resultPowerW << "W=" << resultPowerDbm << "dBm");
682
		
683
		return resultPowerDbm;
684
	}
685
	
686
	// ------------------------------------------------------------------------- //
687
	
688
	NS_OBJECT_ENSURE_REGISTERED (FixedRssLossModel);
689
	
690
	TypeId 
691
	FixedRssLossModel::GetTypeId (void)
692
	{
693
		static TypeId tid = TypeId ("ns3::FixedRssLossModel")
694
		.SetParent<PropagationLossModel> ()
695
		.AddConstructor<FixedRssLossModel> ()
696
		.AddAttribute ("Rss", "The fixed receiver Rss.",
697
					   DoubleValue (-150.0),
698
					   MakeDoubleAccessor (&FixedRssLossModel::m_rss),
699
					   MakeDoubleChecker<double> ())
700
		;
701
		return tid;
702
	}
703
	FixedRssLossModel::FixedRssLossModel ()
704
	: PropagationLossModel ()
705
	{}
706
	
707
	FixedRssLossModel::~FixedRssLossModel ()
708
	{}
709
	
710
	void 
711
	FixedRssLossModel::SetRss (double rss)
712
	{
713
		m_rss = rss;
714
	}
715
	
716
	double 
717
	FixedRssLossModel::DoCalcRxPower (double txPowerDbm,
718
									  Ptr<MobilityModel> a,
719
									  Ptr<MobilityModel> b) const
720
	{
721
		return m_rss;
722
	}
723
	
724
	// ------------------------------------------------------------------------- //
725
	
546
} // namespace ns3
726
} // namespace ns3
(-)a/src/devices/wifi/propagation-loss-model.h (-2 / +103 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 <t.hewer@cs.ucl.ac.uk> for porting Two Ray Ground
21
 */
22
 */
22
23
23
#ifndef PROPAGATION_LOSS_MODEL_H
24
#ifndef PROPAGATION_LOSS_MODEL_H
 Lines 181-188    Link Here 
181
  double m_systemLoss;
182
  double m_systemLoss;
182
  double m_minDistance;
183
  double m_minDistance;
183
};
184
};
184
185
/************************************************************************************
185
/**
186
	 *
187
	 * \brief a Two-Ray Ground propagation loss model ported from NS2
188
	 *
189
	 *  Two-ray ground reflection model.
190
	 *
191
	 *	     Pt * Gt * Gr * (ht^2 * hr^2)
192
	 *  Pr = ----------------------------
193
	 *           d^4 * L
194
	 *
195
	 * The original equation in Rappaport's book assumes L = 1.
196
	 * To be consistant with the free space equation, L is added here.	 
197
	 *
198
	 * Ht and Hr are set by default to 1.5m
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-sapce model is used for small distances. */
203
	
204
	class TwoRayGroundPropagationLossModel : public PropagationLossModel
205
	{
206
	public:
207
		static TypeId GetTypeId (void);
208
		TwoRayGroundPropagationLossModel ();
209
		/**
210
		 * \param frequency (Hz)
211
		 * \param speed (m/s)
212
		 *
213
		 * Set the main wavelength used in the TwoRayGround model 
214
		 * calculation.
215
		 */
216
		void SetLambda (double frequency, double speed);
217
		/**
218
		 * \param lambda (m) the wavelength
219
		 *
220
		 * Set the main wavelength used in the TwoRayGround model 
221
		 * calculation.
222
		 */
223
		void SetLambda (double lambda);
224
		/**
225
		 * \param systemLoss (dimension-less)
226
		 *
227
		 * Set the system loss used by the TwoRayGround propagation model.
228
		 */
229
		void SetSystemLoss (double systemLoss);
230
		
231
		/**
232
		 * \param minDistance the minimum distance
233
		 *
234
		 * Below this distance, the txpower is returned
235
		 * unmodified as the rxpower.
236
		 */
237
		void SetMinDistance (double minDistance);
238
		
239
		/**
240
		 * \returns the minimum distance.
241
		 */
242
		double GetMinDistance (void) const;
243
		
244
		/**
245
		 * \returns the current wavelength (m)
246
		 */
247
		double GetLambda (void) const;
248
		/**
249
		 * \returns the current system loss (dimention-less)
250
		 */
251
		double GetSystemLoss (void) const;
252
		
253
		/**
254
		 * \Set the Tx antenna height
255
		 */
256
		void SetTxAntHeight (double txAntHeight);
257
		/**
258
		 * \Set the Rx antenna height
259
		 */
260
		void SetRxAntHeight (double rxAntHeight);
261
		/**
262
		 * \Returns the Tx antenna height
263
		 */
264
		double GetTxAntHeight (void) const;
265
		/**
266
		 * \Returns the Rx antenna height
267
		 */
268
		double GetRxAntHeight (void) const;
269
		
270
	private:
271
		TwoRayGroundPropagationLossModel (const TwoRayGroundPropagationLossModel &o);
272
		TwoRayGroundPropagationLossModel & operator = (const TwoRayGroundPropagationLossModel &o);
273
		virtual double DoCalcRxPower (double txPowerDbm,
274
									  Ptr<MobilityModel> a,
275
									  Ptr<MobilityModel> b) const;
276
		double DbmToW (double dbm) const;
277
		double DbmFromW (double w) const;
278
		
279
		static const double PI;
280
		double m_lambda;
281
		double m_systemLoss;
282
		double m_minDistance;
283
		double m_txAntHeight;
284
		double m_rxAntHeight;
285
	};
286
/****************************************************************************************************************	
186
 * \brief a log distance propagation model.
287
 * \brief a log distance propagation model.
187
 *
288
 *
188
 * This model calculates the reception power with a so-called
289
 * This model calculates the reception power with a so-called

Return to bug 787