author | Nicola Baldo <nbaldo@cttc.es> |
Wed, 06 Apr 2011 14:50:49 +0200 | |
changeset 7950 | 4a4009fdd6b8 |
parent 7949 | 3bf9450ac03f |
parent 7947 | 4ed7cfac199d |
child 7953 | 1db2126cb7c9 |
permissions | -rw-r--r-- |
6705 | 1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2010 TELEMATICS LAB, DEE - Politecnico di Bari |
|
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: Giuseppe Piro <g.piro@poliba.it> |
|
7886 | 19 |
* Marco Miozzo <mmiozzo@cttc.es> |
6705 | 20 |
*/ |
21 |
||
22 |
#include <ns3/object-factory.h> |
|
23 |
#include <ns3/log.h> |
|
24 |
#include <math.h> |
|
25 |
#include <ns3/simulator.h> |
|
7949 | 26 |
#include <ns3/attribute-accessor-helper.h> |
27 |
#include <ns3/double.h> |
|
28 |
||
29 |
||
7887 | 30 |
#include "lte-enb-phy.h" |
6705 | 31 |
#include "lte-net-device.h" |
32 |
#include "lte-spectrum-value-helper.h" |
|
33 |
#include "ideal-control-messages.h" |
|
7887 | 34 |
#include "lte-enb-net-device.h" |
7886 | 35 |
#include "lte-enb-mac.h" |
7947 | 36 |
#include <ns3/lte-common.h> |
7886 | 37 |
|
6705 | 38 |
|
7887 | 39 |
NS_LOG_COMPONENT_DEFINE ("LteEnbPhy"); |
6705 | 40 |
|
41 |
namespace ns3 { |
|
42 |
||
43 |
||
7886 | 44 |
//////////////////////////////////////// |
45 |
// member SAP forwarders |
|
46 |
//////////////////////////////////////// |
|
47 |
||
48 |
||
49 |
class EnbMemberLteEnbPhySapProvider : public LteEnbPhySapProvider |
|
50 |
{ |
|
51 |
public: |
|
7887 | 52 |
EnbMemberLteEnbPhySapProvider (LteEnbPhy* phy); |
7886 | 53 |
|
54 |
// inherited from LteEnbPhySapProvider |
|
55 |
virtual void SendMacPdu (Ptr<Packet> p); |
|
56 |
virtual void SetBandwidth (uint8_t ulBandwidth, uint8_t dlBandwidth); |
|
57 |
virtual void SetCellId (uint16_t cellId); |
|
58 |
virtual void SendIdealControlMessage (Ptr<IdealControlMessage> msg); |
|
59 |
||
60 |
private: |
|
7887 | 61 |
LteEnbPhy* m_phy; |
7886 | 62 |
}; |
63 |
||
7887 | 64 |
EnbMemberLteEnbPhySapProvider::EnbMemberLteEnbPhySapProvider (LteEnbPhy* phy) : m_phy (phy) |
7886 | 65 |
{ |
66 |
||
67 |
} |
|
68 |
||
69 |
||
70 |
void |
|
71 |
EnbMemberLteEnbPhySapProvider::SendMacPdu (Ptr<Packet> p) |
|
72 |
{ |
|
73 |
m_phy->DoSendMacPdu (p); |
|
74 |
} |
|
75 |
||
76 |
void |
|
77 |
EnbMemberLteEnbPhySapProvider::SetBandwidth (uint8_t ulBandwidth, uint8_t dlBandwidth) |
|
78 |
{ |
|
79 |
m_phy->DoSetBandwidth (ulBandwidth, dlBandwidth); |
|
80 |
} |
|
81 |
||
82 |
void |
|
83 |
EnbMemberLteEnbPhySapProvider::SetCellId (uint16_t cellId) |
|
84 |
{ |
|
85 |
m_phy->DoSetCellId (cellId); |
|
86 |
} |
|
87 |
||
88 |
void |
|
89 |
EnbMemberLteEnbPhySapProvider::SendIdealControlMessage (Ptr<IdealControlMessage> msg) |
|
90 |
{ |
|
91 |
m_phy->DoSendIdealControlMessage (msg); |
|
92 |
} |
|
93 |
||
94 |
||
95 |
//////////////////////////////////////// |
|
7887 | 96 |
// generic LteEnbPhy methods |
7886 | 97 |
//////////////////////////////////////// |
98 |
||
99 |
||
100 |
||
7887 | 101 |
NS_OBJECT_ENSURE_REGISTERED (LteEnbPhy); |
6705 | 102 |
|
103 |
||
7887 | 104 |
LteEnbPhy::LteEnbPhy () |
7886 | 105 |
: m_nrFrames (0), |
106 |
m_nrSubFrames (0) |
|
6705 | 107 |
{ |
7886 | 108 |
m_enbPhySapProvider = new EnbMemberLteEnbPhySapProvider (this); |
7944
f7e5e0540487
connection of SAPs moved from EnbNetDevice to LenaHelper
Nicola Baldo <nicola@baldo.biz>
parents:
7943
diff
changeset
|
109 |
Simulator::ScheduleNow (&LteEnbPhy::StartFrame, this); |
6705 | 110 |
} |
111 |
||
112 |
||
113 |
TypeId |
|
7887 | 114 |
LteEnbPhy::GetTypeId (void) |
6705 | 115 |
{ |
7887 | 116 |
static TypeId tid = TypeId ("ns3::LteEnbPhy") |
6707
2ac68a0381ca
improved module after Tom's review
Giuseppe Piro <g.piro@poliba.it>
parents:
6705
diff
changeset
|
117 |
.SetParent<LtePhy> () |
7887 | 118 |
.AddConstructor<LteEnbPhy> () |
7949 | 119 |
.AddAttribute ("TxPower", |
120 |
"Transmission power in dBm", |
|
121 |
DoubleValue (30.0), |
|
122 |
MakeDoubleAccessor (&LteEnbPhy::SetTxPower, |
|
123 |
&LteEnbPhy::GetTxPower), |
|
124 |
MakeDoubleChecker<double> ()) |
|
6705 | 125 |
; |
126 |
return tid; |
|
127 |
} |
|
128 |
||
129 |
||
7887 | 130 |
LteEnbPhy::~LteEnbPhy () |
6705 | 131 |
{ |
132 |
} |
|
133 |
||
7886 | 134 |
void |
7913
ed3a9f8a76d7
added DoDispose to lte-phy and lte-spectrum-phy
Nicola Baldo <nbaldo@cttc.es>
parents:
7887
diff
changeset
|
135 |
LteEnbPhy::DoDispose () |
ed3a9f8a76d7
added DoDispose to lte-phy and lte-spectrum-phy
Nicola Baldo <nbaldo@cttc.es>
parents:
7887
diff
changeset
|
136 |
{ |
ed3a9f8a76d7
added DoDispose to lte-phy and lte-spectrum-phy
Nicola Baldo <nbaldo@cttc.es>
parents:
7887
diff
changeset
|
137 |
NS_LOG_FUNCTION (this); |
7921 | 138 |
m_ueAttached.clear (); |
7930
ccb40542ae88
fixed memory leak in PHY SAP usage
Nicola Baldo <nbaldo@cttc.es>
parents:
7928
diff
changeset
|
139 |
delete m_enbPhySapProvider; |
7913
ed3a9f8a76d7
added DoDispose to lte-phy and lte-spectrum-phy
Nicola Baldo <nbaldo@cttc.es>
parents:
7887
diff
changeset
|
140 |
LtePhy::DoDispose (); |
ed3a9f8a76d7
added DoDispose to lte-phy and lte-spectrum-phy
Nicola Baldo <nbaldo@cttc.es>
parents:
7887
diff
changeset
|
141 |
} |
ed3a9f8a76d7
added DoDispose to lte-phy and lte-spectrum-phy
Nicola Baldo <nbaldo@cttc.es>
parents:
7887
diff
changeset
|
142 |
|
ed3a9f8a76d7
added DoDispose to lte-phy and lte-spectrum-phy
Nicola Baldo <nbaldo@cttc.es>
parents:
7887
diff
changeset
|
143 |
void |
7887 | 144 |
LteEnbPhy::SetLteEnbPhySapUser (LteEnbPhySapUser* s) |
7886 | 145 |
{ |
146 |
m_enbPhySapUser = s; |
|
147 |
} |
|
148 |
||
149 |
LteEnbPhySapProvider* |
|
7887 | 150 |
LteEnbPhy::GetLteEnbPhySapProvider () |
7886 | 151 |
{ |
152 |
return (m_enbPhySapProvider); |
|
153 |
} |
|
154 |
||
7949 | 155 |
void |
156 |
LteEnbPhy::SetTxPower (double pow) |
|
157 |
{ |
|
158 |
NS_LOG_FUNCTION (this << pow); |
|
159 |
m_txPower = pow; |
|
160 |
} |
|
7886 | 161 |
|
7949 | 162 |
double |
163 |
LteEnbPhy::GetTxPower () const |
|
164 |
{ |
|
165 |
NS_LOG_FUNCTION (this); |
|
166 |
return m_txPower; |
|
167 |
} |
|
7886 | 168 |
|
169 |
bool |
|
7887 | 170 |
LteEnbPhy::AddUePhy (uint8_t rnti, Ptr<LteUePhy> phy) |
7886 | 171 |
{ |
7887 | 172 |
std::map <uint8_t, Ptr<LteUePhy> >::iterator it; |
7886 | 173 |
it = m_ueAttached.find (rnti); |
174 |
if (it == m_ueAttached.end ()) |
|
175 |
{ |
|
7887 | 176 |
m_ueAttached.insert (std::pair<uint8_t, Ptr<LteUePhy> > (rnti, phy)); |
7886 | 177 |
return (true); |
178 |
} |
|
179 |
else |
|
180 |
{ |
|
181 |
NS_LOG_ERROR ("UE already attached"); |
|
182 |
return (false); |
|
183 |
} |
|
184 |
} |
|
6705 | 185 |
|
186 |
bool |
|
7887 | 187 |
LteEnbPhy::DeleteUePhy (uint8_t rnti) |
6705 | 188 |
{ |
7887 | 189 |
std::map <uint8_t, Ptr<LteUePhy> >::iterator it; |
7886 | 190 |
it = m_ueAttached.find (rnti); |
191 |
if (it == m_ueAttached.end ()) |
|
192 |
{ |
|
193 |
NS_LOG_ERROR ("UE not attached"); |
|
194 |
return (false); |
|
195 |
} |
|
196 |
else |
|
197 |
{ |
|
198 |
m_ueAttached.erase (it); |
|
199 |
return (true); |
|
200 |
} |
|
201 |
} |
|
202 |
||
203 |
||
204 |
||
205 |
void |
|
7887 | 206 |
LteEnbPhy::DoSendMacPdu (Ptr<Packet> p) |
7886 | 207 |
{ |
208 |
// NS_LOG_FUNCTION (this << pb->GetNPackets () << pb->GetSize ()); |
|
209 |
// return GetDownlinkSpectrumPhy ()->StartTx (pb); |
|
210 |
||
211 |
NS_LOG_FUNCTION (this); |
|
212 |
SetMacPdu (p); |
|
213 |
} |
|
214 |
||
215 |
||
216 |
void |
|
7887 | 217 |
LteEnbPhy::PhyPduReceived (Ptr<Packet> p) |
7886 | 218 |
{ |
219 |
NS_LOG_FUNCTION (this); |
|
220 |
m_enbPhySapUser->ReceivePhyPdu (p); |
|
6705 | 221 |
} |
222 |
||
223 |
void |
|
7887 | 224 |
LteEnbPhy::DoSetDownlinkSubChannels () |
6705 | 225 |
{ |
226 |
NS_LOG_FUNCTION (this); |
|
227 |
Ptr<SpectrumValue> txPsd = CreateTxPowerSpectralDensity (); |
|
7928
b736f63e9bdf
removed LtePhy::Get{Up,Down}linkSpectrumPhy methods which are evil
Nicola Baldo <nbaldo@cttc.es>
parents:
7921
diff
changeset
|
228 |
m_downlinkSpectrumPhy->SetTxPowerSpectralDensity (txPsd); |
6705 | 229 |
} |
230 |
||
231 |
||
232 |
Ptr<SpectrumValue> |
|
7887 | 233 |
LteEnbPhy::CreateTxPowerSpectralDensity () |
6705 | 234 |
{ |
235 |
NS_LOG_FUNCTION (this); |
|
236 |
||
237 |
LteSpectrumValueHelper psdHelper; |
|
238 |
Ptr<SpectrumValue> psd = psdHelper.CreateDownlinkTxPowerSpectralDensity (GetTxPower (), GetDownlinkSubChannels ()); |
|
239 |
||
240 |
return psd; |
|
241 |
} |
|
242 |
||
243 |
||
244 |
void |
|
7887 | 245 |
LteEnbPhy::CalcChannelQualityForUe (std::vector <double> sinr, Ptr<LteSpectrumPhy> ue) |
6705 | 246 |
{ |
247 |
NS_LOG_FUNCTION (this); |
|
248 |
} |
|
249 |
||
7886 | 250 |
|
6705 | 251 |
void |
7887 | 252 |
LteEnbPhy::DoSendIdealControlMessage (Ptr<IdealControlMessage> msg) |
6705 | 253 |
{ |
254 |
NS_LOG_FUNCTION (this << msg); |
|
7886 | 255 |
// queues the message (wait for MAC-PHY delay) |
256 |
SetControlMessages (msg); |
|
6705 | 257 |
} |
258 |
||
259 |
||
7886 | 260 |
|
6705 | 261 |
void |
7887 | 262 |
LteEnbPhy::ReceiveIdealControlMessage (Ptr<IdealControlMessage> msg) |
6705 | 263 |
{ |
264 |
NS_LOG_FUNCTION (this << msg); |
|
7886 | 265 |
m_enbPhySapUser->ReceiveIdealControlMessage (msg); |
6705 | 266 |
} |
267 |
||
268 |
||
269 |
||
270 |
void |
|
7887 | 271 |
LteEnbPhy::StartFrame (void) |
6705 | 272 |
{ |
7886 | 273 |
NS_LOG_FUNCTION (this); |
6705 | 274 |
|
7886 | 275 |
++m_nrFrames; |
276 |
NS_LOG_INFO ("-----frame " << m_nrFrames << "-----"); |
|
277 |
m_nrSubFrames = 0; |
|
6705 | 278 |
StartSubFrame (); |
279 |
} |
|
280 |
||
281 |
||
282 |
void |
|
7887 | 283 |
LteEnbPhy::StartSubFrame (void) |
6705 | 284 |
{ |
7886 | 285 |
NS_LOG_FUNCTION (this); |
6705 | 286 |
|
7886 | 287 |
++m_nrSubFrames; |
288 |
NS_LOG_INFO ("-----sub frame " << m_nrSubFrames << "-----"); |
|
289 |
||
290 |
// send the current burst of control messages |
|
291 |
std::list<Ptr<IdealControlMessage> > ctrlMsg = GetControlMessages (); |
|
292 |
std::vector <int> dlRb; |
|
293 |
if (ctrlMsg.size () > 0) |
|
294 |
{ |
|
295 |
std::list<Ptr<IdealControlMessage> >::iterator it; |
|
296 |
it = ctrlMsg.begin (); |
|
297 |
while (it != ctrlMsg.end ()) |
|
298 |
{ |
|
299 |
Ptr<IdealControlMessage> msg = (*it); |
|
300 |
if (msg->GetMessageType () == IdealControlMessage::DL_DCI) |
|
301 |
{ |
|
7887 | 302 |
std::map <uint8_t, Ptr<LteUePhy> >::iterator it2; |
7886 | 303 |
Ptr<DlDciIdealControlMessage> dci = DynamicCast<DlDciIdealControlMessage> (msg); |
304 |
it2 = m_ueAttached.find (dci->GetDci ().m_rnti); |
|
305 |
||
306 |
if (it2 == m_ueAttached.end ()) |
|
307 |
{ |
|
308 |
NS_LOG_ERROR ("UE not attached"); |
|
309 |
} |
|
310 |
else |
|
311 |
{ |
|
312 |
// get the tx power spectral density according to DL-DCI(s) |
|
313 |
// translate the DCI to Spectrum framework |
|
314 |
uint32_t mask = 0x1; |
|
315 |
for (int i = 0; i < 32; i++) |
|
316 |
{ |
|
317 |
if (((dci->GetDci ().m_rbBitmap & mask) >> i) == 1) |
|
318 |
{ |
|
319 |
for (int k = 0; k < GetRbgSize (); k++) |
|
320 |
{ |
|
321 |
dlRb.push_back ((i * GetRbgSize ()) + k); |
|
322 |
//NS_LOG_DEBUG(this << " [enb]DL-DCI allocated PRB " << (i*GetRbgSize()) + k); |
|
323 |
} |
|
324 |
} |
|
325 |
mask = (mask << 1); |
|
326 |
} |
|
327 |
(*it2).second->ReceiveIdealControlMessage (msg); |
|
328 |
} |
|
329 |
} |
|
330 |
else if (msg->GetMessageType () == IdealControlMessage::UL_DCI) |
|
331 |
{ |
|
7887 | 332 |
std::map <uint8_t, Ptr<LteUePhy> >::iterator it2; |
7886 | 333 |
Ptr<UlDciIdealControlMessage> dci = DynamicCast<UlDciIdealControlMessage> (msg); |
334 |
it2 = m_ueAttached.find (dci->GetDci ().m_rnti); |
|
335 |
||
336 |
if (it2 == m_ueAttached.end ()) |
|
337 |
{ |
|
338 |
NS_LOG_ERROR ("UE not attached"); |
|
339 |
} |
|
340 |
else |
|
341 |
{ |
|
342 |
(*it2).second->ReceiveIdealControlMessage (msg); |
|
343 |
} |
|
344 |
} |
|
345 |
ctrlMsg.pop_front (); |
|
346 |
it = ctrlMsg.begin (); |
|
347 |
} |
|
348 |
} |
|
349 |
// set the current tx power spectral density |
|
350 |
SetDownlinkSubChannels (dlRb); |
|
351 |
// send the current burts of packets |
|
352 |
Ptr<PacketBurst> pb = GetPacketBurst (); |
|
353 |
if (pb) |
|
354 |
{ |
|
7928
b736f63e9bdf
removed LtePhy::Get{Up,Down}linkSpectrumPhy methods which are evil
Nicola Baldo <nbaldo@cttc.es>
parents:
7921
diff
changeset
|
355 |
m_downlinkSpectrumPhy->StartTx (pb); |
7886 | 356 |
} |
6705 | 357 |
|
7886 | 358 |
// trigger the MAC |
7887 | 359 |
Ptr<LteEnbMac> macEntity = GetDevice ()->GetObject<LteEnbNetDevice> ()->GetMac (); |
6705 | 360 |
|
7886 | 361 |
m_enbPhySapUser->SubframeIndication (m_nrFrames, m_nrSubFrames); |
362 |
||
363 |
||
364 |
// trigger the UE(s) |
|
7887 | 365 |
std::map <uint8_t, Ptr<LteUePhy> >::iterator it; |
7886 | 366 |
for (it = m_ueAttached.begin (); it != m_ueAttached.end (); it++) |
367 |
{ |
|
368 |
(*it).second->SubframeIndication (m_nrFrames, m_nrSubFrames); |
|
369 |
} |
|
6705 | 370 |
|
371 |
Simulator::Schedule (Seconds (GetTti ()), |
|
7887 | 372 |
&LteEnbPhy::EndSubFrame, |
6705 | 373 |
this); |
374 |
||
375 |
} |
|
376 |
||
377 |
||
378 |
void |
|
7887 | 379 |
LteEnbPhy::EndSubFrame (void) |
6705 | 380 |
{ |
381 |
NS_LOG_FUNCTION (this << Simulator::Now ().GetSeconds ()); |
|
7886 | 382 |
if (m_nrSubFrames == 10) |
6705 | 383 |
{ |
7887 | 384 |
Simulator::ScheduleNow (&LteEnbPhy::EndFrame, this); |
6705 | 385 |
} |
386 |
else |
|
387 |
{ |
|
7887 | 388 |
Simulator::ScheduleNow (&LteEnbPhy::StartSubFrame, this); |
6705 | 389 |
} |
390 |
} |
|
391 |
||
392 |
||
393 |
void |
|
7887 | 394 |
LteEnbPhy::EndFrame (void) |
6705 | 395 |
{ |
396 |
NS_LOG_FUNCTION (this << Simulator::Now ().GetSeconds ()); |
|
7887 | 397 |
Simulator::ScheduleNow (&LteEnbPhy::StartFrame, this); |
6705 | 398 |
} |
399 |
||
400 |
||
7886 | 401 |
void |
7887 | 402 |
LteEnbPhy::GenerateCqiFeedback (const SpectrumValue& sinr) |
7886 | 403 |
{ |
404 |
NS_LOG_FUNCTION (this << sinr); |
|
7910 | 405 |
Ptr<LteEnbNetDevice> thisDevice = GetDevice ()->GetObject<LteEnbNetDevice> (); |
7934
0f09fc707a8c
Convert UL-CQI from IdealControlMessage to PhySap Primitive
mmiozzo
parents:
7930
diff
changeset
|
406 |
|
0f09fc707a8c
Convert UL-CQI from IdealControlMessage to PhySap Primitive
mmiozzo
parents:
7930
diff
changeset
|
407 |
m_enbPhySapUser->UlCqiReport (CreateUlCqiReport (sinr)); |
7910 | 408 |
|
409 |
||
410 |
} |
|
411 |
||
412 |
||
7934
0f09fc707a8c
Convert UL-CQI from IdealControlMessage to PhySap Primitive
mmiozzo
parents:
7930
diff
changeset
|
413 |
UlCqi_s |
0f09fc707a8c
Convert UL-CQI from IdealControlMessage to PhySap Primitive
mmiozzo
parents:
7930
diff
changeset
|
414 |
LteEnbPhy::CreateUlCqiReport (const SpectrumValue& sinr) |
7910 | 415 |
{ |
416 |
NS_LOG_FUNCTION (this << sinr); |
|
417 |
Values::const_iterator it; |
|
418 |
UlCqi_s ulcqi; |
|
419 |
ulcqi.m_type = UlCqi_s::PUSCH; |
|
420 |
int i = 0; |
|
421 |
for (it = sinr.ConstValuesBegin (); it != sinr.ConstValuesEnd (); it++) |
|
422 |
{ |
|
7947 | 423 |
double sinrdb = 10*log10 ((*it)); |
424 |
// convert from double to fixed point notation Sxxxxxxxxxxx.xxx |
|
425 |
int16_t sinrFp = LteFfConverter::double2fpS11dot3 (sinrdb); |
|
426 |
ulcqi.m_sinr.push_back (sinrFp); |
|
427 |
//NS_LOG_DEBUG(this << " RB " << i << " SINR FP " << sinrFp << " orig " << sinrdb); |
|
7910 | 428 |
i++; |
429 |
} |
|
7934
0f09fc707a8c
Convert UL-CQI from IdealControlMessage to PhySap Primitive
mmiozzo
parents:
7930
diff
changeset
|
430 |
return (ulcqi); |
7910 | 431 |
|
7886 | 432 |
} |
6705 | 433 |
|
434 |
}; |