author | Nicola Baldo <nicola@baldo.biz> |
Sun, 13 Nov 2011 16:08:44 +0100 | |
changeset 7581 | 6ac3fa410583 |
parent 7553 | 2b93d333dea6 |
child 7836 | 9cf68ee51869 |
child 8339 | bfa05e51eecf |
permissions | -rw-r--r-- |
7385
10beb0e53130
standardize emacs c++ mode comments
Vedran Miletić <rivanvx@gmail.com>
parents:
7177
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
6705 | 2 |
/* |
3 |
* Copyright (c) 2009 CTTC |
|
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: Nicola Baldo <nbaldo@cttc.es> |
|
19 |
* Giuseppe Piro <g.piro@poliba.it> |
|
20 |
*/ |
|
21 |
||
22 |
||
23 |
#include <ns3/waveform-generator.h> |
|
24 |
#include <ns3/object-factory.h> |
|
25 |
#include <ns3/log.h> |
|
26 |
#include <math.h> |
|
27 |
#include <ns3/simulator.h> |
|
28 |
#include <ns3/trace-source-accessor.h> |
|
29 |
#include "ns3/spectrum-error-model.h" |
|
30 |
#include "lte-spectrum-phy.h" |
|
7581 | 31 |
#include "lte-spectrum-signal-parameters.h" |
6705 | 32 |
#include "lte-net-device.h" |
33 |
||
34 |
NS_LOG_COMPONENT_DEFINE ("LteSpectrumPhy"); |
|
35 |
||
36 |
namespace ns3 { |
|
37 |
||
38 |
||
39 |
NS_OBJECT_ENSURE_REGISTERED (LteSpectrumPhy); |
|
40 |
||
41 |
LteSpectrumPhy::LteSpectrumPhy () |
|
42 |
: m_mobility (0), |
|
43 |
m_device (0), |
|
44 |
m_channel (0), |
|
45 |
m_txPsd (0), |
|
46 |
m_state (IDLE) |
|
47 |
{ |
|
48 |
//m_interference = CreateObject<SpectrumInterference> (); |
|
49 |
//m_interference->SetErrorModel (CreateObject<LteSpectrumErrorModel> ()); |
|
50 |
} |
|
51 |
||
52 |
||
53 |
LteSpectrumPhy::~LteSpectrumPhy () |
|
54 |
{ |
|
55 |
||
56 |
} |
|
57 |
||
58 |
std::ostream& operator<< (std::ostream& os, LteSpectrumPhy::State s) |
|
59 |
{ |
|
60 |
switch (s) |
|
61 |
{ |
|
62 |
case LteSpectrumPhy::IDLE: |
|
63 |
os << "IDLE"; |
|
64 |
break; |
|
65 |
case LteSpectrumPhy::RX: |
|
66 |
os << "RX"; |
|
67 |
break; |
|
68 |
case LteSpectrumPhy::TX: |
|
69 |
os << "TX"; |
|
70 |
break; |
|
71 |
default: |
|
72 |
os << "UNKNOWN"; |
|
73 |
break; |
|
74 |
} |
|
75 |
return os; |
|
76 |
} |
|
77 |
||
78 |
||
79 |
TypeId |
|
80 |
LteSpectrumPhy::GetTypeId (void) |
|
81 |
{ |
|
82 |
static TypeId tid = TypeId ("ns3::LteSpectrumPhy") |
|
83 |
.SetParent<SpectrumPhy> () |
|
84 |
.AddTraceSource ("TxStart", |
|
85 |
"Trace fired when a new transmission is started", |
|
86 |
MakeTraceSourceAccessor (&LteSpectrumPhy::m_phyTxStartTrace)) |
|
87 |
.AddTraceSource ("TxEnd", |
|
88 |
"Trace fired when a previosuly started transmission is finished", |
|
89 |
MakeTraceSourceAccessor (&LteSpectrumPhy::m_phyTxEndTrace)) |
|
90 |
.AddTraceSource ("RxStart", |
|
91 |
"Trace fired when the start of a signal is detected", |
|
92 |
MakeTraceSourceAccessor (&LteSpectrumPhy::m_phyRxStartTrace)) |
|
93 |
.AddTraceSource ("RxAbort", |
|
94 |
"Trace fired when a previously started RX is aborted before time", |
|
95 |
MakeTraceSourceAccessor (&LteSpectrumPhy::m_phyRxAbortTrace)) |
|
96 |
.AddTraceSource ("RxEndOk", |
|
97 |
"Trace fired when a previosuly started RX terminates successfully", |
|
98 |
MakeTraceSourceAccessor (&LteSpectrumPhy::m_phyRxEndOkTrace)) |
|
99 |
.AddTraceSource ("RxEndError", |
|
100 |
"Trace fired when a previosuly started RX terminates with an error (packet is corrupted)", |
|
101 |
MakeTraceSourceAccessor (&LteSpectrumPhy::m_phyRxEndErrorTrace)) |
|
102 |
; |
|
103 |
return tid; |
|
104 |
} |
|
105 |
||
106 |
||
107 |
||
7553
2b93d333dea6
Bug 1271 - stronger type checking in SpectrumPhy
Nicola Baldo <nbaldo@cttc.es>
parents:
7385
diff
changeset
|
108 |
Ptr<NetDevice> |
6705 | 109 |
LteSpectrumPhy::GetDevice () |
110 |
{ |
|
111 |
NS_LOG_FUNCTION (this); |
|
112 |
return m_device; |
|
113 |
} |
|
114 |
||
115 |
||
7553
2b93d333dea6
Bug 1271 - stronger type checking in SpectrumPhy
Nicola Baldo <nbaldo@cttc.es>
parents:
7385
diff
changeset
|
116 |
Ptr<MobilityModel> |
6705 | 117 |
LteSpectrumPhy::GetMobility () |
118 |
{ |
|
119 |
NS_LOG_FUNCTION (this); |
|
120 |
return m_mobility; |
|
121 |
} |
|
122 |
||
123 |
||
124 |
void |
|
7553
2b93d333dea6
Bug 1271 - stronger type checking in SpectrumPhy
Nicola Baldo <nbaldo@cttc.es>
parents:
7385
diff
changeset
|
125 |
LteSpectrumPhy::SetDevice (Ptr<NetDevice> d) |
6705 | 126 |
{ |
127 |
NS_LOG_FUNCTION (this << d); |
|
128 |
m_device = d; |
|
129 |
} |
|
130 |
||
131 |
||
132 |
void |
|
7553
2b93d333dea6
Bug 1271 - stronger type checking in SpectrumPhy
Nicola Baldo <nbaldo@cttc.es>
parents:
7385
diff
changeset
|
133 |
LteSpectrumPhy::SetMobility (Ptr<MobilityModel> m) |
6705 | 134 |
{ |
135 |
NS_LOG_FUNCTION (this << m); |
|
136 |
m_mobility = m; |
|
137 |
} |
|
138 |
||
139 |
||
140 |
void |
|
141 |
LteSpectrumPhy::SetChannel (Ptr<SpectrumChannel> c) |
|
142 |
{ |
|
143 |
NS_LOG_FUNCTION (this << c); |
|
144 |
m_channel = c; |
|
145 |
} |
|
146 |
||
147 |
||
148 |
Ptr<SpectrumChannel> |
|
149 |
LteSpectrumPhy::GetChannel (void) |
|
150 |
{ |
|
151 |
return m_channel; |
|
152 |
} |
|
153 |
||
154 |
||
155 |
Ptr<const SpectrumModel> |
|
156 |
LteSpectrumPhy::GetRxSpectrumModel () const |
|
157 |
{ |
|
158 |
if (m_txPsd) |
|
159 |
{ |
|
160 |
return m_txPsd->GetSpectrumModel (); |
|
161 |
} |
|
162 |
else |
|
163 |
{ |
|
164 |
return 0; |
|
165 |
} |
|
166 |
} |
|
167 |
||
168 |
||
169 |
void |
|
170 |
LteSpectrumPhy::SetTxPowerSpectralDensity (Ptr<SpectrumValue> txPsd) |
|
171 |
{ |
|
172 |
NS_LOG_FUNCTION (this << txPsd); |
|
173 |
NS_ASSERT (txPsd); |
|
174 |
m_txPsd = txPsd; |
|
175 |
NS_LOG_INFO ("\t computed tx_psd: " << *txPsd << "\t stored tx_psd: " << *m_txPsd); |
|
176 |
} |
|
177 |
||
178 |
||
179 |
void |
|
180 |
LteSpectrumPhy::SetNoisePowerSpectralDensity (Ptr<const SpectrumValue> noisePsd) |
|
181 |
{ |
|
182 |
NS_LOG_FUNCTION (this << noisePsd); |
|
183 |
NS_LOG_INFO ("\t computed noise_psd: " << *noisePsd ); |
|
184 |
NS_ASSERT (noisePsd); |
|
185 |
m_noise = noisePsd; |
|
186 |
} |
|
187 |
||
7581 | 188 |
Ptr<const SpectrumValue> |
6705 | 189 |
LteSpectrumPhy::GetNoisePowerSpectralDensity (void) |
7581 | 190 |
{ |
6705 | 191 |
NS_LOG_FUNCTION (this); |
192 |
return m_noise; |
|
193 |
} |
|
194 |
||
195 |
||
196 |
void |
|
6969 | 197 |
LteSpectrumPhy::SetGenericPhyTxEndCallback (GenericPhyTxEndCallback c) |
6705 | 198 |
{ |
199 |
NS_LOG_FUNCTION (this); |
|
200 |
m_phyMacTxEndCallback = c; |
|
201 |
} |
|
202 |
||
203 |
||
204 |
void |
|
6969 | 205 |
LteSpectrumPhy::SetGenericPhyRxStartCallback (GenericPhyRxStartCallback c) |
6705 | 206 |
{ |
207 |
NS_LOG_FUNCTION (this); |
|
208 |
m_phyMacRxStartCallback = c; |
|
209 |
} |
|
210 |
||
211 |
||
212 |
void |
|
6969 | 213 |
LteSpectrumPhy::SetGenericPhyRxEndErrorCallback (GenericPhyRxEndErrorCallback c) |
6705 | 214 |
{ |
215 |
NS_LOG_FUNCTION (this); |
|
216 |
m_phyMacRxEndErrorCallback = c; |
|
217 |
} |
|
218 |
||
219 |
||
220 |
void |
|
6969 | 221 |
LteSpectrumPhy::SetGenericPhyRxEndOkCallback (GenericPhyRxEndOkCallback c) |
6705 | 222 |
{ |
223 |
NS_LOG_FUNCTION (this); |
|
224 |
m_phyMacRxEndOkCallback = c; |
|
225 |
} |
|
226 |
||
227 |
||
228 |
void |
|
229 |
LteSpectrumPhy::SetState (State newState) |
|
230 |
{ |
|
231 |
ChangeState (newState); |
|
232 |
} |
|
233 |
||
234 |
||
235 |
void |
|
236 |
LteSpectrumPhy::ChangeState (State newState) |
|
237 |
{ |
|
238 |
NS_LOG_LOGIC (this << " state: " << m_state << " -> " << newState); |
|
239 |
m_state = newState; |
|
240 |
} |
|
241 |
||
242 |
||
243 |
bool |
|
244 |
LteSpectrumPhy::StartTx (Ptr<PacketBurst> pb) |
|
245 |
{ |
|
246 |
NS_LOG_FUNCTION (this << pb); |
|
247 |
NS_LOG_LOGIC (this << "state: " << m_state); |
|
248 |
||
249 |
||
250 |
for (std::list<Ptr<Packet> >::const_iterator iter = pb->Begin (); iter |
|
251 |
!= pb->End (); ++iter) |
|
252 |
{ |
|
253 |
Ptr<Packet> packet = (*iter)->Copy (); |
|
254 |
m_phyTxStartTrace (packet); |
|
255 |
} |
|
256 |
||
257 |
||
258 |
if (m_state == LteSpectrumPhy::RX) |
|
259 |
{ |
|
260 |
/* |
|
261 |
* NS FATAL ERROR: according to FDD channel acces, |
|
262 |
* the physical layer for transmission cannot be used for reception. |
|
263 |
*/ |
|
264 |
NS_FATAL_ERROR ("FDD ERROR: R State while sending packet"); |
|
265 |
} |
|
266 |
||
267 |
if (m_state == LteSpectrumPhy::IDLE) |
|
268 |
{ |
|
269 |
||
270 |
/* |
|
271 |
m_txPsd must be setted by the device, according to |
|
272 |
(i) the available subchannel for transmission |
|
273 |
(ii) the power transmission |
|
274 |
*/ |
|
275 |
NS_ASSERT (m_txPsd); |
|
276 |
||
277 |
m_txPacket = pb; |
|
278 |
ChangeState (TX); |
|
279 |
NS_ASSERT (m_channel); |
|
280 |
double tti = 0.001; |
|
7581 | 281 |
Ptr<LteSpectrumSignalParameters> txParams = Create<LteSpectrumSignalParameters> (); |
282 |
txParams->duration = Seconds (tti); |
|
283 |
txParams->txPhy = GetObject<SpectrumPhy> (); |
|
284 |
txParams->psd = m_txPsd; |
|
285 |
txParams->packetBurst = pb; |
|
286 |
m_channel->StartTx (txParams); |
|
6705 | 287 |
Simulator::Schedule (Seconds (tti), &LteSpectrumPhy::EndTx, this); |
288 |
return false; |
|
289 |
} |
|
290 |
else |
|
291 |
{ |
|
292 |
// The device have already started the transmission. |
|
293 |
return true; |
|
294 |
} |
|
295 |
} |
|
296 |
||
297 |
||
298 |
void |
|
299 |
LteSpectrumPhy::EndTx () |
|
300 |
{ |
|
301 |
NS_LOG_FUNCTION (this); |
|
302 |
NS_LOG_LOGIC (this << "state: " << m_state); |
|
303 |
||
304 |
NS_ASSERT (m_state == TX); |
|
305 |
||
306 |
for (std::list<Ptr<Packet> >::const_iterator iter = m_txPacket->Begin (); iter |
|
307 |
!= m_txPacket->End (); ++iter) |
|
308 |
{ |
|
309 |
Ptr<Packet> packet = (*iter)->Copy (); |
|
310 |
m_phyTxEndTrace (packet); |
|
311 |
} |
|
312 |
||
313 |
if (!m_phyMacTxEndCallback.IsNull ()) |
|
314 |
{ |
|
315 |
for (std::list<Ptr<Packet> >::const_iterator iter = m_txPacket->Begin (); iter |
|
316 |
!= m_txPacket->End (); ++iter) |
|
317 |
{ |
|
318 |
Ptr<Packet> packet = (*iter)->Copy (); |
|
319 |
m_phyMacTxEndCallback (packet); |
|
320 |
} |
|
321 |
} |
|
322 |
||
323 |
m_txPacket = 0; |
|
324 |
ChangeState (IDLE); |
|
325 |
} |
|
326 |
||
327 |
||
328 |
void |
|
7581 | 329 |
LteSpectrumPhy::StartRx (Ptr<SpectrumSignalParameters> spectrumRxParams) |
6705 | 330 |
{ |
7581 | 331 |
NS_LOG_FUNCTION (this << spectrumRxParams); |
6705 | 332 |
NS_LOG_LOGIC (this << "state: " << m_state); |
333 |
||
334 |
||
335 |
// interference will happen regardless of the state of the receiver |
|
336 |
// m_interference->AddSignal (rxPsd, duration); |
|
337 |
||
7581 | 338 |
Ptr<LteSpectrumSignalParameters> lteRxParams = DynamicCast<LteSpectrumSignalParameters> (spectrumRxParams); |
6705 | 339 |
// the device might start RX only if the signal is of a type understood by this device |
340 |
// this corresponds in real device to preamble detection |
|
7581 | 341 |
if (lteRxParams != 0) |
6705 | 342 |
{ |
343 |
switch (m_state) |
|
344 |
{ |
|
345 |
case TX: |
|
346 |
/* |
|
347 |
* NS FATAL ERROR: according to FDD channel acces, |
|
348 |
* the physical layer for reception cannot be used for transmission. |
|
349 |
*/ |
|
350 |
NS_FATAL_ERROR ("FDD ERROR: TX State while receiving packet"); |
|
351 |
||
352 |
break; |
|
353 |
||
354 |
case RX: |
|
355 |
break; |
|
356 |
||
357 |
case IDLE: |
|
358 |
// preamble detection and synchronization is supposed to be always successful. |
|
359 |
NS_LOG_LOGIC (this << " receiving new packet"); |
|
360 |
||
7581 | 361 |
for (std::list<Ptr<Packet> >::const_iterator iter = lteRxParams->packetBurst->Begin (); iter |
362 |
!= lteRxParams->packetBurst->End (); ++iter) |
|
6705 | 363 |
{ |
364 |
Ptr<Packet> packet = (*iter)->Copy (); |
|
365 |
m_phyRxStartTrace (packet); |
|
366 |
} |
|
367 |
||
368 |
||
7581 | 369 |
m_rxPacket = lteRxParams->packetBurst; |
370 |
m_rxPsd = lteRxParams->psd; |
|
371 |
Time duration = lteRxParams->duration; |
|
6705 | 372 |
|
373 |
ChangeState (RX); |
|
374 |
||
375 |
if (!m_phyMacRxStartCallback.IsNull ()) |
|
376 |
{ |
|
377 |
NS_LOG_LOGIC (this << " calling m_phyMacRxStartCallback"); |
|
378 |
m_phyMacRxStartCallback (); |
|
379 |
} |
|
380 |
else |
|
381 |
{ |
|
382 |
NS_LOG_LOGIC (this << " m_phyMacRxStartCallback is NULL"); |
|
383 |
} |
|
384 |
||
385 |
// XXX: modify SpectrumInterference in order to compute |
|
386 |
// the correct/erroneus reception of PacketBurst!!! |
|
7581 | 387 |
/* |
6705 | 388 |
for (std::list<Ptr<Packet> >::const_iterator iter = pb->Begin (); iter |
389 |
!= pb->End (); ++iter) |
|
390 |
{ |
|
391 |
Ptr<Packet> packet = (*iter)->Copy (); |
|
392 |
m_interference->StartRx (packet, rxPsd); |
|
393 |
} |
|
394 |
*/ |
|
395 |
||
396 |
||
397 |
NS_LOG_LOGIC (this << " scheduling EndRx with delay " << duration); |
|
398 |
m_endRxEventId = Simulator::Schedule (duration, &LteSpectrumPhy::EndRx, this); |
|
399 |
||
400 |
break; |
|
401 |
||
402 |
} |
|
403 |
} |
|
404 |
||
405 |
NS_LOG_LOGIC (this << "state: " << m_state); |
|
406 |
} |
|
407 |
||
408 |
||
409 |
void |
|
410 |
LteSpectrumPhy::AbortRx () |
|
411 |
{ |
|
412 |
NS_LOG_FUNCTION (this); |
|
413 |
NS_LOG_LOGIC (this << "state: " << m_state); |
|
414 |
||
415 |
NS_ASSERT (m_state == RX); |
|
416 |
||
417 |
for (std::list<Ptr<Packet> >::const_iterator iter = m_rxPacket->Begin (); iter |
|
418 |
!= m_rxPacket->End (); ++iter) |
|
419 |
{ |
|
420 |
Ptr<Packet> packet = (*iter)->Copy (); |
|
421 |
m_phyRxAbortTrace (packet); |
|
422 |
} |
|
423 |
||
424 |
m_endRxEventId.Cancel (); |
|
425 |
m_rxPacket = 0; |
|
426 |
ChangeState (IDLE); |
|
427 |
} |
|
428 |
||
429 |
||
430 |
void |
|
431 |
LteSpectrumPhy::EndRx () |
|
432 |
{ |
|
433 |
NS_LOG_FUNCTION (this); |
|
434 |
NS_LOG_LOGIC (this << "state: " << m_state); |
|
435 |
||
436 |
NS_ASSERT (m_state == RX); |
|
437 |
||
438 |
CalcSinrValues (m_rxPsd, GetNoisePowerSpectralDensity ()); |
|
439 |
||
440 |
bool rxOk = true; //m_interference->EndRx (); |
|
441 |
||
442 |
NS_LOG_FUNCTION (rxOk); |
|
443 |
if (rxOk) |
|
444 |
{ |
|
445 |
||
446 |
for (std::list<Ptr<Packet> >::const_iterator iter = m_rxPacket->Begin (); iter |
|
447 |
!= m_rxPacket->End (); ++iter) |
|
448 |
{ |
|
449 |
Ptr<Packet> packet = (*iter)->Copy (); |
|
450 |
m_phyRxEndOkTrace (packet); |
|
451 |
} |
|
452 |
||
453 |
if (!m_phyMacRxEndOkCallback.IsNull ()) |
|
454 |
{ |
|
455 |
NS_LOG_LOGIC (this << " calling m_phyMacRxEndOkCallback"); |
|
456 |
||
457 |
for (std::list<Ptr<Packet> >::const_iterator iter = m_rxPacket->Begin (); iter |
|
458 |
!= m_rxPacket->End (); ++iter) |
|
459 |
{ |
|
460 |
Ptr<Packet> packet = (*iter)->Copy (); |
|
461 |
m_phyMacRxEndOkCallback (packet); |
|
462 |
} |
|
463 |
} |
|
464 |
else |
|
465 |
{ |
|
466 |
NS_LOG_LOGIC (this << " m_phyMacRxEndOkCallback is NULL"); |
|
467 |
} |
|
468 |
} |
|
469 |
else |
|
470 |
{ |
|
471 |
for (std::list<Ptr<Packet> >::const_iterator iter = m_rxPacket->Begin (); iter |
|
472 |
!= m_rxPacket->End (); ++iter) |
|
473 |
{ |
|
474 |
Ptr<Packet> packet = (*iter)->Copy (); |
|
475 |
m_phyRxEndErrorTrace (packet); |
|
476 |
} |
|
477 |
||
478 |
if (!m_phyMacRxEndErrorCallback.IsNull ()) |
|
479 |
{ |
|
480 |
NS_LOG_LOGIC (this << " calling m_phyMacRxEndErrorCallback"); |
|
481 |
||
482 |
for (std::list<Ptr<Packet> >::const_iterator iter = m_rxPacket->Begin (); iter |
|
483 |
!= m_rxPacket->End (); ++iter) |
|
484 |
{ |
|
485 |
Ptr<Packet> packet = (*iter)->Copy (); |
|
486 |
m_phyMacRxEndOkCallback (packet); |
|
487 |
} |
|
488 |
||
489 |
} |
|
490 |
else |
|
491 |
{ |
|
492 |
NS_LOG_LOGIC (this << " m_phyMacRxEndErrorCallback is NULL"); |
|
493 |
} |
|
494 |
} |
|
495 |
||
496 |
ChangeState (IDLE); |
|
497 |
m_rxPacket = 0; |
|
498 |
m_rxPsd = 0; |
|
499 |
} |
|
500 |
||
501 |
||
502 |
} // namespace ns3 |