author | CTTC |
Thu, 10 Mar 2011 18:15:26 +0100 | |
changeset 7886 | b65c16d4da83 |
parent 6852 | 8f1a53d3f6ca |
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> |
|
26 |
#include "ns3/spectrum-error-model.h" |
|
27 |
#include "enb-phy.h" |
|
28 |
#include "lte-net-device.h" |
|
29 |
#include "lte-spectrum-value-helper.h" |
|
30 |
#include "ideal-control-messages.h" |
|
31 |
#include "enb-net-device.h" |
|
7886 | 32 |
#include "lte-enb-mac.h" |
33 |
||
6705 | 34 |
|
35 |
NS_LOG_COMPONENT_DEFINE ("EnbLtePhy"); |
|
36 |
||
37 |
namespace ns3 { |
|
38 |
||
39 |
||
7886 | 40 |
//////////////////////////////////////// |
41 |
// member SAP forwarders |
|
42 |
//////////////////////////////////////// |
|
43 |
||
44 |
||
45 |
class EnbMemberLteEnbPhySapProvider : public LteEnbPhySapProvider |
|
46 |
{ |
|
47 |
public: |
|
48 |
EnbMemberLteEnbPhySapProvider (EnbLtePhy* phy); |
|
49 |
||
50 |
// inherited from LteEnbPhySapProvider |
|
51 |
virtual void SendMacPdu (Ptr<Packet> p); |
|
52 |
virtual void SetBandwidth (uint8_t ulBandwidth, uint8_t dlBandwidth); |
|
53 |
virtual void SetCellId (uint16_t cellId); |
|
54 |
virtual void SendIdealControlMessage (Ptr<IdealControlMessage> msg); |
|
55 |
||
56 |
private: |
|
57 |
EnbLtePhy* m_phy; |
|
58 |
}; |
|
59 |
||
60 |
EnbMemberLteEnbPhySapProvider::EnbMemberLteEnbPhySapProvider (EnbLtePhy* phy) : m_phy (phy) |
|
61 |
{ |
|
62 |
||
63 |
} |
|
64 |
||
65 |
||
66 |
void |
|
67 |
EnbMemberLteEnbPhySapProvider::SendMacPdu (Ptr<Packet> p) |
|
68 |
{ |
|
69 |
m_phy->DoSendMacPdu (p); |
|
70 |
} |
|
71 |
||
72 |
void |
|
73 |
EnbMemberLteEnbPhySapProvider::SetBandwidth (uint8_t ulBandwidth, uint8_t dlBandwidth) |
|
74 |
{ |
|
75 |
m_phy->DoSetBandwidth (ulBandwidth, dlBandwidth); |
|
76 |
} |
|
77 |
||
78 |
void |
|
79 |
EnbMemberLteEnbPhySapProvider::SetCellId (uint16_t cellId) |
|
80 |
{ |
|
81 |
m_phy->DoSetCellId (cellId); |
|
82 |
} |
|
83 |
||
84 |
void |
|
85 |
EnbMemberLteEnbPhySapProvider::SendIdealControlMessage (Ptr<IdealControlMessage> msg) |
|
86 |
{ |
|
87 |
m_phy->DoSendIdealControlMessage (msg); |
|
88 |
} |
|
89 |
||
90 |
||
91 |
//////////////////////////////////////// |
|
92 |
// generic EnbLtePhy methods |
|
93 |
//////////////////////////////////////// |
|
94 |
||
95 |
||
96 |
||
6705 | 97 |
NS_OBJECT_ENSURE_REGISTERED (EnbLtePhy); |
98 |
||
99 |
||
100 |
EnbLtePhy::EnbLtePhy () |
|
7886 | 101 |
: m_nrFrames (0), |
102 |
m_nrSubFrames (0) |
|
6705 | 103 |
{ |
7886 | 104 |
m_enbPhySapProvider = new EnbMemberLteEnbPhySapProvider (this); |
6705 | 105 |
} |
106 |
||
107 |
||
108 |
TypeId |
|
109 |
EnbLtePhy::GetTypeId (void) |
|
110 |
{ |
|
111 |
static TypeId tid = TypeId ("ns3::EnbLtePhy") |
|
6707
2ac68a0381ca
improved module after Tom's review
Giuseppe Piro <g.piro@poliba.it>
parents:
6705
diff
changeset
|
112 |
.SetParent<LtePhy> () |
6705 | 113 |
.AddConstructor<EnbLtePhy> () |
114 |
; |
|
115 |
return tid; |
|
116 |
} |
|
117 |
||
118 |
||
119 |
EnbLtePhy::~EnbLtePhy () |
|
120 |
{ |
|
121 |
} |
|
122 |
||
7886 | 123 |
void |
124 |
EnbLtePhy::SetLteEnbPhySapUser (LteEnbPhySapUser* s) |
|
125 |
{ |
|
126 |
m_enbPhySapUser = s; |
|
127 |
} |
|
128 |
||
129 |
LteEnbPhySapProvider* |
|
130 |
EnbLtePhy::GetLteEnbPhySapProvider () |
|
131 |
{ |
|
132 |
return (m_enbPhySapProvider); |
|
133 |
} |
|
134 |
||
135 |
||
136 |
||
137 |
bool |
|
138 |
EnbLtePhy::AddUePhy (uint8_t rnti, Ptr<UeLtePhy> phy) |
|
139 |
{ |
|
140 |
std::map <uint8_t, Ptr<UeLtePhy> >::iterator it; |
|
141 |
it = m_ueAttached.find (rnti); |
|
142 |
if (it == m_ueAttached.end ()) |
|
143 |
{ |
|
144 |
m_ueAttached.insert (std::pair<uint8_t, Ptr<UeLtePhy> > (rnti, phy)); |
|
145 |
return (true); |
|
146 |
} |
|
147 |
else |
|
148 |
{ |
|
149 |
NS_LOG_ERROR ("UE already attached"); |
|
150 |
return (false); |
|
151 |
} |
|
152 |
} |
|
6705 | 153 |
|
154 |
bool |
|
7886 | 155 |
EnbLtePhy::DeleteUePhy (uint8_t rnti) |
6705 | 156 |
{ |
7886 | 157 |
std::map <uint8_t, Ptr<UeLtePhy> >::iterator it; |
158 |
it = m_ueAttached.find (rnti); |
|
159 |
if (it == m_ueAttached.end ()) |
|
160 |
{ |
|
161 |
NS_LOG_ERROR ("UE not attached"); |
|
162 |
return (false); |
|
163 |
} |
|
164 |
else |
|
165 |
{ |
|
166 |
m_ueAttached.erase (it); |
|
167 |
return (true); |
|
168 |
} |
|
169 |
} |
|
170 |
||
171 |
||
172 |
||
173 |
void |
|
174 |
EnbLtePhy::DoSendMacPdu (Ptr<Packet> p) |
|
175 |
{ |
|
176 |
// NS_LOG_FUNCTION (this << pb->GetNPackets () << pb->GetSize ()); |
|
177 |
// return GetDownlinkSpectrumPhy ()->StartTx (pb); |
|
178 |
||
179 |
NS_LOG_FUNCTION (this); |
|
180 |
SetMacPdu (p); |
|
181 |
} |
|
182 |
||
183 |
||
184 |
void |
|
185 |
EnbLtePhy::PhyPduReceived (Ptr<Packet> p) |
|
186 |
{ |
|
187 |
NS_LOG_FUNCTION (this); |
|
188 |
m_enbPhySapUser->ReceivePhyPdu (p); |
|
6705 | 189 |
} |
190 |
||
191 |
void |
|
192 |
EnbLtePhy::DoSetDownlinkSubChannels () |
|
193 |
{ |
|
194 |
NS_LOG_FUNCTION (this); |
|
195 |
Ptr<SpectrumValue> txPsd = CreateTxPowerSpectralDensity (); |
|
196 |
GetDownlinkSpectrumPhy ()->SetTxPowerSpectralDensity (txPsd); |
|
197 |
} |
|
198 |
||
199 |
||
200 |
Ptr<SpectrumValue> |
|
201 |
EnbLtePhy::CreateTxPowerSpectralDensity () |
|
202 |
{ |
|
203 |
NS_LOG_FUNCTION (this); |
|
204 |
||
205 |
LteSpectrumValueHelper psdHelper; |
|
206 |
Ptr<SpectrumValue> psd = psdHelper.CreateDownlinkTxPowerSpectralDensity (GetTxPower (), GetDownlinkSubChannels ()); |
|
207 |
||
208 |
return psd; |
|
209 |
} |
|
210 |
||
211 |
||
212 |
void |
|
213 |
EnbLtePhy::CalcChannelQualityForUe (std::vector <double> sinr, Ptr<LteSpectrumPhy> ue) |
|
214 |
{ |
|
215 |
NS_LOG_FUNCTION (this); |
|
216 |
} |
|
217 |
||
7886 | 218 |
|
6705 | 219 |
void |
7886 | 220 |
EnbLtePhy::DoSendIdealControlMessage (Ptr<IdealControlMessage> msg) |
6705 | 221 |
{ |
222 |
NS_LOG_FUNCTION (this << msg); |
|
7886 | 223 |
// queues the message (wait for MAC-PHY delay) |
224 |
SetControlMessages (msg); |
|
6705 | 225 |
} |
226 |
||
227 |
||
7886 | 228 |
|
6705 | 229 |
void |
6710
3cd651349cb6
lte examples now passing valgrind tests
Nicola Baldo <nbaldo@cttc.es>
parents:
6707
diff
changeset
|
230 |
EnbLtePhy::ReceiveIdealControlMessage (Ptr<IdealControlMessage> msg) |
6705 | 231 |
{ |
232 |
NS_LOG_FUNCTION (this << msg); |
|
7886 | 233 |
m_enbPhySapUser->ReceiveIdealControlMessage (msg); |
6705 | 234 |
} |
235 |
||
236 |
||
237 |
||
238 |
void |
|
239 |
EnbLtePhy::StartFrame (void) |
|
240 |
{ |
|
7886 | 241 |
NS_LOG_FUNCTION (this); |
6705 | 242 |
|
7886 | 243 |
++m_nrFrames; |
244 |
NS_LOG_INFO ("-----frame " << m_nrFrames << "-----"); |
|
245 |
m_nrSubFrames = 0; |
|
6705 | 246 |
StartSubFrame (); |
247 |
} |
|
248 |
||
249 |
||
250 |
void |
|
251 |
EnbLtePhy::StartSubFrame (void) |
|
252 |
{ |
|
7886 | 253 |
NS_LOG_FUNCTION (this); |
6705 | 254 |
|
7886 | 255 |
++m_nrSubFrames; |
256 |
NS_LOG_INFO ("-----sub frame " << m_nrSubFrames << "-----"); |
|
257 |
||
258 |
// send the current burst of control messages |
|
259 |
std::list<Ptr<IdealControlMessage> > ctrlMsg = GetControlMessages (); |
|
260 |
std::vector <int> dlRb; |
|
261 |
if (ctrlMsg.size () > 0) |
|
262 |
{ |
|
263 |
std::list<Ptr<IdealControlMessage> >::iterator it; |
|
264 |
it = ctrlMsg.begin (); |
|
265 |
while (it != ctrlMsg.end ()) |
|
266 |
{ |
|
267 |
Ptr<IdealControlMessage> msg = (*it); |
|
268 |
if (msg->GetMessageType () == IdealControlMessage::DL_DCI) |
|
269 |
{ |
|
270 |
std::map <uint8_t, Ptr<UeLtePhy> >::iterator it2; |
|
271 |
Ptr<DlDciIdealControlMessage> dci = DynamicCast<DlDciIdealControlMessage> (msg); |
|
272 |
it2 = m_ueAttached.find (dci->GetDci ().m_rnti); |
|
273 |
||
274 |
if (it2 == m_ueAttached.end ()) |
|
275 |
{ |
|
276 |
NS_LOG_ERROR ("UE not attached"); |
|
277 |
} |
|
278 |
else |
|
279 |
{ |
|
280 |
// get the tx power spectral density according to DL-DCI(s) |
|
281 |
// translate the DCI to Spectrum framework |
|
282 |
uint32_t mask = 0x1; |
|
283 |
for (int i = 0; i < 32; i++) |
|
284 |
{ |
|
285 |
if (((dci->GetDci ().m_rbBitmap & mask) >> i) == 1) |
|
286 |
{ |
|
287 |
for (int k = 0; k < GetRbgSize (); k++) |
|
288 |
{ |
|
289 |
dlRb.push_back ((i * GetRbgSize ()) + k); |
|
290 |
//NS_LOG_DEBUG(this << " [enb]DL-DCI allocated PRB " << (i*GetRbgSize()) + k); |
|
291 |
} |
|
292 |
} |
|
293 |
mask = (mask << 1); |
|
294 |
} |
|
295 |
(*it2).second->ReceiveIdealControlMessage (msg); |
|
296 |
} |
|
297 |
} |
|
298 |
else if (msg->GetMessageType () == IdealControlMessage::UL_DCI) |
|
299 |
{ |
|
300 |
std::map <uint8_t, Ptr<UeLtePhy> >::iterator it2; |
|
301 |
Ptr<UlDciIdealControlMessage> dci = DynamicCast<UlDciIdealControlMessage> (msg); |
|
302 |
it2 = m_ueAttached.find (dci->GetDci ().m_rnti); |
|
303 |
||
304 |
if (it2 == m_ueAttached.end ()) |
|
305 |
{ |
|
306 |
NS_LOG_ERROR ("UE not attached"); |
|
307 |
} |
|
308 |
else |
|
309 |
{ |
|
310 |
(*it2).second->ReceiveIdealControlMessage (msg); |
|
311 |
} |
|
312 |
} |
|
313 |
ctrlMsg.pop_front (); |
|
314 |
it = ctrlMsg.begin (); |
|
315 |
} |
|
316 |
} |
|
317 |
// set the current tx power spectral density |
|
318 |
SetDownlinkSubChannels (dlRb); |
|
319 |
// send the current burts of packets |
|
320 |
Ptr<PacketBurst> pb = GetPacketBurst (); |
|
321 |
if (pb) |
|
322 |
{ |
|
323 |
GetDownlinkSpectrumPhy ()->StartTx (pb); |
|
324 |
} |
|
6705 | 325 |
|
7886 | 326 |
// trigger the MAC |
327 |
Ptr<LteEnbMac> macEntity = GetDevice ()->GetObject<EnbNetDevice> ()->GetMac (); |
|
6705 | 328 |
|
7886 | 329 |
m_enbPhySapUser->SubframeIndication (m_nrFrames, m_nrSubFrames); |
330 |
||
331 |
||
332 |
// trigger the UE(s) |
|
333 |
std::map <uint8_t, Ptr<UeLtePhy> >::iterator it; |
|
334 |
for (it = m_ueAttached.begin (); it != m_ueAttached.end (); it++) |
|
335 |
{ |
|
336 |
(*it).second->SubframeIndication (m_nrFrames, m_nrSubFrames); |
|
337 |
} |
|
6705 | 338 |
|
339 |
Simulator::Schedule (Seconds (GetTti ()), |
|
340 |
&EnbLtePhy::EndSubFrame, |
|
341 |
this); |
|
342 |
||
343 |
} |
|
344 |
||
345 |
||
346 |
void |
|
347 |
EnbLtePhy::EndSubFrame (void) |
|
348 |
{ |
|
349 |
NS_LOG_FUNCTION (this << Simulator::Now ().GetSeconds ()); |
|
7886 | 350 |
if (m_nrSubFrames == 10) |
6705 | 351 |
{ |
352 |
Simulator::ScheduleNow (&EnbLtePhy::EndFrame, this); |
|
353 |
} |
|
354 |
else |
|
355 |
{ |
|
356 |
Simulator::ScheduleNow (&EnbLtePhy::StartSubFrame, this); |
|
357 |
} |
|
358 |
} |
|
359 |
||
360 |
||
361 |
void |
|
362 |
EnbLtePhy::EndFrame (void) |
|
363 |
{ |
|
364 |
NS_LOG_FUNCTION (this << Simulator::Now ().GetSeconds ()); |
|
365 |
Simulator::ScheduleNow (&EnbLtePhy::StartFrame, this); |
|
366 |
} |
|
367 |
||
368 |
||
7886 | 369 |
void |
370 |
EnbLtePhy::GenerateCqiFeedback (const SpectrumValue& sinr) |
|
371 |
{ |
|
372 |
NS_LOG_FUNCTION (this << sinr); |
|
373 |
} |
|
6705 | 374 |
|
375 |
}; |