1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4 * Copyright (c) 2018 Fraunhofer ESK : RLF extensions
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation;
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Authors: Nicola Baldo <nbaldo@cttc.es>
20 * Marco Miozzo <mmiozzo@cttc.es>
21 * Manuel Requena <manuel.requena@cttc.es>
22 * Modified by: Danilo Abrignani <danilo.abrignani@unibo.it> (Carrier Aggregation - GSoC 2015),
23 * Biljana Bojovic <biljana.bojovic@cttc.es> (Carrier Aggregation)
24 * Vignesh Babu <ns3-dev@esk.fraunhofer.de> (RLF extensions)
25 */
26
27 #include "lte-enb-rrc.h"
28
29 #include <ns3/fatal-error.h>
30 #include <ns3/log.h>
31 #include <ns3/abort.h>
32
33 #include <ns3/pointer.h>
34 #include <ns3/object-map.h>
35 #include <ns3/object-factory.h>
36 #include <ns3/simulator.h>
37
38 #include <ns3/lte-radio-bearer-info.h>
39 #include <ns3/eps-bearer-tag.h>
40 #include <ns3/packet.h>
41
42 #include <ns3/lte-rlc.h>
43 #include <ns3/lte-rlc-tm.h>
44 #include <ns3/lte-rlc-um.h>
45 #include <ns3/lte-rlc-am.h>
46 #include <ns3/lte-pdcp.h>
47
48
49
50
51 namespace ns3 {
52
53 NS_LOG_COMPONENT_DEFINE ("LteEnbRrc");
54
55 ///////////////////////////////////////////
56 // CMAC SAP forwarder
57 ///////////////////////////////////////////
58
59 /**
60 * \brief Class for forwarding CMAC SAP User functions.
61 */
62 class EnbRrcMemberLteEnbCmacSapUser : public LteEnbCmacSapUser
63 {
64 public:
65 /**
66 * Constructor
67 *
68 * \param rrc ENB RRC
69 * \param componentCarrierId
70 */
71 EnbRrcMemberLteEnbCmacSapUser (LteEnbRrc* rrc, uint8_t componentCarrierId);
72
73 virtual uint16_t AllocateTemporaryCellRnti ();
74 virtual void NotifyLcConfigResult (uint16_t rnti, uint8_t lcid, bool success);
75 virtual void RrcConfigurationUpdateInd (UeConfig params);
76 virtual bool IsRandomAccessCompleted (uint16_t rnti);
77
78 private:
79 LteEnbRrc* m_rrc; ///< the RRC
80 uint8_t m_componentCarrierId; ///< Component carrier ID
81 };
82
EnbRrcMemberLteEnbCmacSapUser(LteEnbRrc * rrc,uint8_t componentCarrierId)83 EnbRrcMemberLteEnbCmacSapUser::EnbRrcMemberLteEnbCmacSapUser (LteEnbRrc* rrc, uint8_t componentCarrierId)
84 : m_rrc (rrc)
85 , m_componentCarrierId {componentCarrierId}
86 {
87 }
88
89 uint16_t
AllocateTemporaryCellRnti()90 EnbRrcMemberLteEnbCmacSapUser::AllocateTemporaryCellRnti ()
91 {
92 return m_rrc->DoAllocateTemporaryCellRnti (m_componentCarrierId);
93 }
94
95 void
NotifyLcConfigResult(uint16_t rnti,uint8_t lcid,bool success)96 EnbRrcMemberLteEnbCmacSapUser::NotifyLcConfigResult (uint16_t rnti, uint8_t lcid, bool success)
97 {
98 m_rrc->DoNotifyLcConfigResult (rnti, lcid, success);
99 }
100
101 void
RrcConfigurationUpdateInd(UeConfig params)102 EnbRrcMemberLteEnbCmacSapUser::RrcConfigurationUpdateInd (UeConfig params)
103 {
104 m_rrc->DoRrcConfigurationUpdateInd (params);
105 }
106
107 bool
IsRandomAccessCompleted(uint16_t rnti)108 EnbRrcMemberLteEnbCmacSapUser::IsRandomAccessCompleted (uint16_t rnti)
109 {
110 return m_rrc->IsRandomAccessCompleted (rnti);
111 }
112
113
114
115 ///////////////////////////////////////////
116 // UeManager
117 ///////////////////////////////////////////
118
119
120 /// Map each of UE Manager states to its string representation.
121 static const std::string g_ueManagerStateName[UeManager::NUM_STATES] =
122 {
123 "INITIAL_RANDOM_ACCESS",
124 "CONNECTION_SETUP",
125 "CONNECTION_REJECTED",
126 "ATTACH_REQUEST",
127 "CONNECTED_NORMALLY",
128 "CONNECTION_RECONFIGURATION",
129 "CONNECTION_REESTABLISHMENT",
130 "HANDOVER_PREPARATION",
131 "HANDOVER_JOINING",
132 "HANDOVER_PATH_SWITCH",
133 "HANDOVER_LEAVING",
134 };
135
136 /**
137 * \param s The UE manager state.
138 * \return The string representation of the given state.
139 */
ToString(UeManager::State s)140 static const std::string & ToString (UeManager::State s)
141 {
142 return g_ueManagerStateName[s];
143 }
144
145
146 NS_OBJECT_ENSURE_REGISTERED (UeManager);
147
148
UeManager()149 UeManager::UeManager ()
150 {
151 NS_FATAL_ERROR ("this constructor is not expected to be used");
152 }
153
154
UeManager(Ptr<LteEnbRrc> rrc,uint16_t rnti,State s,uint8_t componentCarrierId)155 UeManager::UeManager (Ptr<LteEnbRrc> rrc, uint16_t rnti, State s, uint8_t componentCarrierId)
156 : m_lastAllocatedDrbid (0),
157 m_rnti (rnti),
158 m_imsi (0),
159 m_componentCarrierId (componentCarrierId),
160 m_lastRrcTransactionIdentifier (0),
161 m_rrc (rrc),
162 m_state (s),
163 m_pendingRrcConnectionReconfiguration (false),
164 m_sourceX2apId (0),
165 m_sourceCellId (0),
166 m_needPhyMacConfiguration (false),
167 m_caSupportConfigured (false),
168 m_pendingStartDataRadioBearers (false)
169 {
170 NS_LOG_FUNCTION (this);
171 }
172
173 void
DoInitialize()174 UeManager::DoInitialize ()
175 {
176 NS_LOG_FUNCTION (this);
177 m_drbPdcpSapUser = new LtePdcpSpecificLtePdcpSapUser<UeManager> (this);
178
179 m_physicalConfigDedicated.haveAntennaInfoDedicated = true;
180 m_physicalConfigDedicated.antennaInfo.transmissionMode = m_rrc->m_defaultTransmissionMode;
181 m_physicalConfigDedicated.haveSoundingRsUlConfigDedicated = true;
182 m_physicalConfigDedicated.soundingRsUlConfigDedicated.srsConfigIndex = m_rrc->GetNewSrsConfigurationIndex ();
183 m_physicalConfigDedicated.soundingRsUlConfigDedicated.type = LteRrcSap::SoundingRsUlConfigDedicated::SETUP;
184 m_physicalConfigDedicated.soundingRsUlConfigDedicated.srsBandwidth = 0;
185 m_physicalConfigDedicated.havePdschConfigDedicated = true;
186 m_physicalConfigDedicated.pdschConfigDedicated.pa = LteRrcSap::PdschConfigDedicated::dB0;
187
188
189 for (uint8_t i = 0; i < m_rrc->m_numberOfComponentCarriers; i++)
190 {
191 m_rrc->m_cmacSapProvider.at (i)->AddUe (m_rnti);
192 m_rrc->m_cphySapProvider.at (i)->AddUe (m_rnti);
193 }
194
195 // setup the eNB side of SRB0
196 {
197 uint8_t lcid = 0;
198
199 Ptr<LteRlc> rlc = CreateObject<LteRlcTm> ()->GetObject<LteRlc> ();
200 rlc->SetLteMacSapProvider (m_rrc->m_macSapProvider);
201 rlc->SetRnti (m_rnti);
202 rlc->SetLcId (lcid);
203
204 m_srb0 = CreateObject<LteSignalingRadioBearerInfo> ();
205 m_srb0->m_rlc = rlc;
206 m_srb0->m_srbIdentity = 0;
207 // no need to store logicalChannelConfig as SRB0 is pre-configured
208
209 LteEnbCmacSapProvider::LcInfo lcinfo;
210 lcinfo.rnti = m_rnti;
211 lcinfo.lcId = lcid;
212 // Initialise the rest of lcinfo structure even if CCCH (LCID 0) is pre-configured, and only m_rnti and lcid will be used from passed lcinfo structure.
213 // See FF LTE MAC Scheduler Iinterface Specification v1.11, 4.3.4 logicalChannelConfigListElement
214 lcinfo.lcGroup = 0;
215 lcinfo.qci = 0;
216 lcinfo.isGbr = false;
217 lcinfo.mbrUl = 0;
218 lcinfo.mbrDl = 0;
219 lcinfo.gbrUl = 0;
220 lcinfo.gbrDl = 0;
221
222 // MacSapUserForRlc in the ComponentCarrierManager MacSapUser
223 LteMacSapUser* lteMacSapUser = m_rrc->m_ccmRrcSapProvider->ConfigureSignalBearer(lcinfo, rlc->GetLteMacSapUser ());
224 // Signal Channel are only on Primary Carrier
225 m_rrc->m_cmacSapProvider.at (m_componentCarrierId)->AddLc (lcinfo, lteMacSapUser);
226 m_rrc->m_ccmRrcSapProvider->AddLc (lcinfo, lteMacSapUser);
227 }
228
229 // setup the eNB side of SRB1; the UE side will be set up upon RRC connection establishment
230 {
231 uint8_t lcid = 1;
232
233 Ptr<LteRlc> rlc = CreateObject<LteRlcAm> ()->GetObject<LteRlc> ();
234 rlc->SetLteMacSapProvider (m_rrc->m_macSapProvider);
235 rlc->SetRnti (m_rnti);
236 rlc->SetLcId (lcid);
237
238 Ptr<LtePdcp> pdcp = CreateObject<LtePdcp> ();
239 pdcp->SetRnti (m_rnti);
240 pdcp->SetLcId (lcid);
241 pdcp->SetLtePdcpSapUser (m_drbPdcpSapUser);
242 pdcp->SetLteRlcSapProvider (rlc->GetLteRlcSapProvider ());
243 rlc->SetLteRlcSapUser (pdcp->GetLteRlcSapUser ());
244
245 m_srb1 = CreateObject<LteSignalingRadioBearerInfo> ();
246 m_srb1->m_rlc = rlc;
247 m_srb1->m_pdcp = pdcp;
248 m_srb1->m_srbIdentity = 1;
249 m_srb1->m_logicalChannelConfig.priority = 1;
250 m_srb1->m_logicalChannelConfig.prioritizedBitRateKbps = 100;
251 m_srb1->m_logicalChannelConfig.bucketSizeDurationMs = 100;
252 m_srb1->m_logicalChannelConfig.logicalChannelGroup = 0;
253
254 LteEnbCmacSapProvider::LcInfo lcinfo;
255 lcinfo.rnti = m_rnti;
256 lcinfo.lcId = lcid;
257 lcinfo.lcGroup = 0; // all SRBs always mapped to LCG 0
258 lcinfo.qci = EpsBearer::GBR_CONV_VOICE; // not sure why the FF API requires a CQI even for SRBs...
259 lcinfo.isGbr = true;
260 lcinfo.mbrUl = 1e6;
261 lcinfo.mbrDl = 1e6;
262 lcinfo.gbrUl = 1e4;
263 lcinfo.gbrDl = 1e4;
264 // MacSapUserForRlc in the ComponentCarrierManager MacSapUser
265 LteMacSapUser* MacSapUserForRlc = m_rrc->m_ccmRrcSapProvider->ConfigureSignalBearer(lcinfo, rlc->GetLteMacSapUser ());
266 // Signal Channel are only on Primary Carrier
267 m_rrc->m_cmacSapProvider.at (m_componentCarrierId)->AddLc (lcinfo, MacSapUserForRlc);
268 m_rrc->m_ccmRrcSapProvider->AddLc (lcinfo, MacSapUserForRlc);
269 }
270
271 LteEnbRrcSapUser::SetupUeParameters ueParams;
272 ueParams.srb0SapProvider = m_srb0->m_rlc->GetLteRlcSapProvider ();
273 ueParams.srb1SapProvider = m_srb1->m_pdcp->GetLtePdcpSapProvider ();
274 m_rrc->m_rrcSapUser->SetupUe (m_rnti, ueParams);
275
276 // configure MAC (and scheduler)
277 LteEnbCmacSapProvider::UeConfig req;
278 req.m_rnti = m_rnti;
279 req.m_transmissionMode = m_physicalConfigDedicated.antennaInfo.transmissionMode;
280
281 // configure PHY
282 for (uint16_t i = 0; i < m_rrc->m_numberOfComponentCarriers; i++)
283 {
284 m_rrc->m_cmacSapProvider.at (i)->UeUpdateConfigurationReq (req);
285 m_rrc->m_cphySapProvider.at (i)->SetTransmissionMode (m_rnti, m_physicalConfigDedicated.antennaInfo.transmissionMode);
286 m_rrc->m_cphySapProvider.at (i)->SetSrsConfigurationIndex (m_rnti, m_physicalConfigDedicated.soundingRsUlConfigDedicated.srsConfigIndex);
287 }
288 // schedule this UeManager instance to be deleted if the UE does not give any sign of life within a reasonable time
289 Time maxConnectionDelay;
290 switch (m_state)
291 {
292 case INITIAL_RANDOM_ACCESS:
293 m_connectionRequestTimeout = Simulator::Schedule (m_rrc->m_connectionRequestTimeoutDuration,
294 &LteEnbRrc::ConnectionRequestTimeout,
295 m_rrc, m_rnti);
296 break;
297
298 case HANDOVER_JOINING:
299 m_handoverJoiningTimeout = Simulator::Schedule (m_rrc->m_handoverJoiningTimeoutDuration,
300 &LteEnbRrc::HandoverJoiningTimeout,
301 m_rrc, m_rnti);
302 break;
303
304 default:
305 NS_FATAL_ERROR ("unexpected state " << ToString (m_state));
306 break;
307 }
308 m_caSupportConfigured = false;
309 }
310
311
~UeManager(void)312 UeManager::~UeManager (void)
313 {
314 }
315
316 void
DoDispose()317 UeManager::DoDispose ()
318 {
319 delete m_drbPdcpSapUser;
320 // delete eventual X2-U TEIDs
321 for (std::map <uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator it = m_drbMap.begin ();
322 it != m_drbMap.end ();
323 ++it)
324 {
325 m_rrc->m_x2uTeidInfoMap.erase (it->second->m_gtpTeid);
326 }
327
328 }
329
GetTypeId(void)330 TypeId UeManager::GetTypeId (void)
331 {
332 static TypeId tid = TypeId ("ns3::UeManager")
333 .SetParent<Object> ()
334 .AddConstructor<UeManager> ()
335 .AddAttribute ("DataRadioBearerMap", "List of UE DataRadioBearerInfo by DRBID.",
336 ObjectMapValue (),
337 MakeObjectMapAccessor (&UeManager::m_drbMap),
338 MakeObjectMapChecker<LteDataRadioBearerInfo> ())
339 .AddAttribute ("Srb0", "SignalingRadioBearerInfo for SRB0",
340 PointerValue (),
341 MakePointerAccessor (&UeManager::m_srb0),
342 MakePointerChecker<LteSignalingRadioBearerInfo> ())
343 .AddAttribute ("Srb1", "SignalingRadioBearerInfo for SRB1",
344 PointerValue (),
345 MakePointerAccessor (&UeManager::m_srb1),
346 MakePointerChecker<LteSignalingRadioBearerInfo> ())
347 .AddAttribute ("C-RNTI",
348 "Cell Radio Network Temporary Identifier",
349 TypeId::ATTR_GET, // read-only attribute
350 UintegerValue (0), // unused, read-only attribute
351 MakeUintegerAccessor (&UeManager::m_rnti),
352 MakeUintegerChecker<uint16_t> ())
353 .AddTraceSource ("StateTransition",
354 "fired upon every UE state transition seen by the "
355 "UeManager at the eNB RRC",
356 MakeTraceSourceAccessor (&UeManager::m_stateTransitionTrace),
357 "ns3::UeManager::StateTracedCallback")
358 .AddTraceSource ("DrbCreated",
359 "trace fired after DRB is created",
360 MakeTraceSourceAccessor (&UeManager::m_drbCreatedTrace),
361 "ns3::UeManager::ImsiCidRntiLcIdTracedCallback")
362 ;
363 return tid;
364 }
365
366 void
SetSource(uint16_t sourceCellId,uint16_t sourceX2apId)367 UeManager::SetSource (uint16_t sourceCellId, uint16_t sourceX2apId)
368 {
369 m_sourceX2apId = sourceX2apId;
370 m_sourceCellId = sourceCellId;
371 }
372
373 void
SetImsi(uint64_t imsi)374 UeManager::SetImsi (uint64_t imsi)
375 {
376 m_imsi = imsi;
377 }
378
379 void
InitialContextSetupRequest()380 UeManager::InitialContextSetupRequest ()
381 {
382 NS_LOG_FUNCTION (this << m_rnti);
383
384 if (m_state == ATTACH_REQUEST)
385 {
386 SwitchToState (CONNECTED_NORMALLY);
387 }
388 else
389 {
390 NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
391 }
392 }
393
394 void
SetupDataRadioBearer(EpsBearer bearer,uint8_t bearerId,uint32_t gtpTeid,Ipv4Address transportLayerAddress)395 UeManager::SetupDataRadioBearer (EpsBearer bearer, uint8_t bearerId, uint32_t gtpTeid, Ipv4Address transportLayerAddress)
396 {
397 NS_LOG_FUNCTION (this << (uint32_t) m_rnti);
398
399 Ptr<LteDataRadioBearerInfo> drbInfo = CreateObject<LteDataRadioBearerInfo> ();
400 uint8_t drbid = AddDataRadioBearerInfo (drbInfo);
401 uint8_t lcid = Drbid2Lcid (drbid);
402 uint8_t bid = Drbid2Bid (drbid);
403 NS_ASSERT_MSG ( bearerId == 0 || bid == bearerId, "bearer ID mismatch (" << (uint32_t) bid << " != " << (uint32_t) bearerId << ", the assumption that ID are allocated in the same way by MME and RRC is not valid any more");
404 drbInfo->m_epsBearer = bearer;
405 drbInfo->m_epsBearerIdentity = bid;
406 drbInfo->m_drbIdentity = drbid;
407 drbInfo->m_logicalChannelIdentity = lcid;
408 drbInfo->m_gtpTeid = gtpTeid;
409 drbInfo->m_transportLayerAddress = transportLayerAddress;
410
411 if (m_state == HANDOVER_JOINING)
412 {
413 // setup TEIDs for receiving data eventually forwarded over X2-U
414 LteEnbRrc::X2uTeidInfo x2uTeidInfo;
415 x2uTeidInfo.rnti = m_rnti;
416 x2uTeidInfo.drbid = drbid;
417 std::pair<std::map<uint32_t, LteEnbRrc::X2uTeidInfo>::iterator, bool>
418 ret = m_rrc->m_x2uTeidInfoMap.insert (std::pair<uint32_t, LteEnbRrc::X2uTeidInfo> (gtpTeid, x2uTeidInfo));
419 NS_ASSERT_MSG (ret.second == true, "overwriting a pre-existing entry in m_x2uTeidInfoMap");
420 }
421
422 TypeId rlcTypeId = m_rrc->GetRlcType (bearer);
423
424 ObjectFactory rlcObjectFactory;
425 rlcObjectFactory.SetTypeId (rlcTypeId);
426 Ptr<LteRlc> rlc = rlcObjectFactory.Create ()->GetObject<LteRlc> ();
427 rlc->SetLteMacSapProvider (m_rrc->m_macSapProvider);
428 rlc->SetRnti (m_rnti);
429
430 drbInfo->m_rlc = rlc;
431
432 rlc->SetLcId (lcid);
433
434 // we need PDCP only for real RLC, i.e., RLC/UM or RLC/AM
435 // if we are using RLC/SM we don't care of anything above RLC
436 if (rlcTypeId != LteRlcSm::GetTypeId ())
437 {
438 Ptr<LtePdcp> pdcp = CreateObject<LtePdcp> ();
439 pdcp->SetRnti (m_rnti);
440 pdcp->SetLcId (lcid);
441 pdcp->SetLtePdcpSapUser (m_drbPdcpSapUser);
442 pdcp->SetLteRlcSapProvider (rlc->GetLteRlcSapProvider ());
443 rlc->SetLteRlcSapUser (pdcp->GetLteRlcSapUser ());
444 drbInfo->m_pdcp = pdcp;
445 }
446
447 m_drbCreatedTrace (m_imsi, m_rrc->ComponentCarrierToCellId (m_componentCarrierId), m_rnti, lcid);
448
449 std::vector<LteCcmRrcSapProvider::LcsConfig> lcOnCcMapping = m_rrc->m_ccmRrcSapProvider->SetupDataRadioBearer (bearer, bearerId, m_rnti, lcid, m_rrc->GetLogicalChannelGroup (bearer), rlc->GetLteMacSapUser ());
450 // LteEnbCmacSapProvider::LcInfo lcinfo;
451 // lcinfo.rnti = m_rnti;
452 // lcinfo.lcId = lcid;
453 // lcinfo.lcGroup = m_rrc->GetLogicalChannelGroup (bearer);
454 // lcinfo.qci = bearer.qci;
455 // lcinfo.isGbr = bearer.IsGbr ();
456 // lcinfo.mbrUl = bearer.gbrQosInfo.mbrUl;
457 // lcinfo.mbrDl = bearer.gbrQosInfo.mbrDl;
458 // lcinfo.gbrUl = bearer.gbrQosInfo.gbrUl;
459 // lcinfo.gbrDl = bearer.gbrQosInfo.gbrDl;
460 // use a for cycle to send the AddLc to the appropriate Mac Sap
461 // if the sap is not initialized the appropriated method has to be called
462 std::vector<LteCcmRrcSapProvider::LcsConfig>::iterator itLcOnCcMapping = lcOnCcMapping.begin ();
463 NS_ASSERT_MSG (itLcOnCcMapping != lcOnCcMapping.end (), "Problem");
464 for (itLcOnCcMapping = lcOnCcMapping.begin (); itLcOnCcMapping != lcOnCcMapping.end (); ++itLcOnCcMapping)
465 {
466 NS_LOG_DEBUG (this << " RNTI " << itLcOnCcMapping->lc.rnti << "Lcid " << (uint16_t) itLcOnCcMapping->lc.lcId << " lcGroup " << (uint16_t) itLcOnCcMapping->lc.lcGroup << " ComponentCarrierId " << itLcOnCcMapping->componentCarrierId);
467 uint8_t index = itLcOnCcMapping->componentCarrierId;
468 LteEnbCmacSapProvider::LcInfo lcinfo = itLcOnCcMapping->lc;
469 LteMacSapUser *msu = itLcOnCcMapping->msu;
470 m_rrc->m_cmacSapProvider.at (index)->AddLc (lcinfo, msu);
471 m_rrc->m_ccmRrcSapProvider->AddLc (lcinfo, msu);
472 }
473
474 if (rlcTypeId == LteRlcAm::GetTypeId ())
475 {
476 drbInfo->m_rlcConfig.choice = LteRrcSap::RlcConfig::AM;
477 }
478 else
479 {
480 drbInfo->m_rlcConfig.choice = LteRrcSap::RlcConfig::UM_BI_DIRECTIONAL;
481 }
482
483 drbInfo->m_logicalChannelIdentity = lcid;
484 drbInfo->m_logicalChannelConfig.priority = m_rrc->GetLogicalChannelPriority (bearer);
485 drbInfo->m_logicalChannelConfig.logicalChannelGroup = m_rrc->GetLogicalChannelGroup (bearer);
486 if (bearer.IsGbr ())
487 {
488 drbInfo->m_logicalChannelConfig.prioritizedBitRateKbps = bearer.gbrQosInfo.gbrUl;
489 }
490 else
491 {
492 drbInfo->m_logicalChannelConfig.prioritizedBitRateKbps = 0;
493 }
494 drbInfo->m_logicalChannelConfig.bucketSizeDurationMs = 1000;
495
496 ScheduleRrcConnectionReconfiguration ();
497 }
498
499 void
RecordDataRadioBearersToBeStarted()500 UeManager::RecordDataRadioBearersToBeStarted ()
501 {
502 NS_LOG_FUNCTION (this << (uint32_t) m_rnti);
503 for (std::map <uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator it = m_drbMap.begin ();
504 it != m_drbMap.end ();
505 ++it)
506 {
507 m_drbsToBeStarted.push_back (it->first);
508 }
509 }
510
511 void
StartDataRadioBearers()512 UeManager::StartDataRadioBearers ()
513 {
514 NS_LOG_FUNCTION (this << (uint32_t) m_rnti);
515 for (std::list <uint8_t>::iterator drbIdIt = m_drbsToBeStarted.begin ();
516 drbIdIt != m_drbsToBeStarted.end ();
517 ++drbIdIt)
518 {
519 std::map <uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator drbIt = m_drbMap.find (*drbIdIt);
520 NS_ASSERT (drbIt != m_drbMap.end ());
521 drbIt->second->m_rlc->Initialize ();
522 if (drbIt->second->m_pdcp)
523 {
524 drbIt->second->m_pdcp->Initialize ();
525 }
526 }
527 m_drbsToBeStarted.clear ();
528 }
529
530
531 void
ReleaseDataRadioBearer(uint8_t drbid)532 UeManager::ReleaseDataRadioBearer (uint8_t drbid)
533 {
534 NS_LOG_FUNCTION (this << (uint32_t) m_rnti << (uint32_t) drbid);
535 uint8_t lcid = Drbid2Lcid (drbid);
536 std::map <uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator it = m_drbMap.find (drbid);
537 NS_ASSERT_MSG (it != m_drbMap.end (), "request to remove radio bearer with unknown drbid " << drbid);
538
539 // first delete eventual X2-U TEIDs
540 m_rrc->m_x2uTeidInfoMap.erase (it->second->m_gtpTeid);
541
542 m_drbMap.erase (it);
543 std::vector<uint8_t> ccToRelease = m_rrc->m_ccmRrcSapProvider->ReleaseDataRadioBearer (m_rnti, lcid);
544 std::vector<uint8_t>::iterator itCcToRelease = ccToRelease.begin ();
545 NS_ASSERT_MSG (itCcToRelease != ccToRelease.end (), "request to remove radio bearer with unknown drbid (ComponentCarrierManager)");
546 for (itCcToRelease = ccToRelease.begin (); itCcToRelease != ccToRelease.end (); ++itCcToRelease)
547 {
548 m_rrc->m_cmacSapProvider.at (*itCcToRelease)->ReleaseLc (m_rnti, lcid);
549 }
550 LteRrcSap::RadioResourceConfigDedicated rrcd;
551 rrcd.havePhysicalConfigDedicated = false;
552 rrcd.drbToReleaseList.push_back (drbid);
553 //populating RadioResourceConfigDedicated information element as per 3GPP TS 36.331 version 9.2.0
554 rrcd.havePhysicalConfigDedicated = true;
555 rrcd.physicalConfigDedicated = m_physicalConfigDedicated;
556
557 //populating RRCConnectionReconfiguration message as per 3GPP TS 36.331 version 9.2.0 Release 9
558 LteRrcSap::RrcConnectionReconfiguration msg;
559 msg.haveMeasConfig = false;
560 msg.haveMobilityControlInfo = false;
561 msg.radioResourceConfigDedicated = rrcd;
562 msg.haveRadioResourceConfigDedicated = true;
563 // ToDo: Resend in any case this configuration
564 // needs to be initialized
565 msg.haveNonCriticalExtension = false;
566 //RRC Connection Reconfiguration towards UE
567 m_rrc->m_rrcSapUser->SendRrcConnectionReconfiguration (m_rnti, msg);
568 }
569
570 void
DoSendReleaseDataRadioBearer(uint64_t imsi,uint16_t rnti,uint8_t bearerId)571 LteEnbRrc::DoSendReleaseDataRadioBearer (uint64_t imsi, uint16_t rnti, uint8_t bearerId)
572 {
573 NS_LOG_FUNCTION (this << imsi << rnti << (uint16_t) bearerId);
574 Ptr<UeManager> ueManager = GetUeManager (rnti);
575 // Bearer de-activation towards UE
576 ueManager->ReleaseDataRadioBearer (bearerId);
577 // Bearer de-activation indication towards epc-enb application
578 m_s1SapProvider->DoSendReleaseIndication (imsi,rnti,bearerId);
579 }
580
581 void
RecvIdealUeContextRemoveRequest(uint16_t rnti)582 UeManager::RecvIdealUeContextRemoveRequest (uint16_t rnti)
583 {
584 NS_LOG_FUNCTION (this << m_rnti);
585
586 //release the bearer info for the UE at SGW/PGW
587 if (m_rrc->m_s1SapProvider != 0) //if EPC is enabled
588 {
589 for (const auto &it:m_drbMap)
590 {
591 NS_LOG_DEBUG ("Sending release of bearer id : " << (uint16_t) (it.first)
592 << "LCID : "
593 << (uint16_t) (it.second->m_logicalChannelIdentity));
594 // Bearer de-activation indication towards epc-enb application
595 m_rrc->m_s1SapProvider->DoSendReleaseIndication (GetImsi (), rnti, it.first);
596 }
597 }
598 }
599
600 void
ScheduleRrcConnectionReconfiguration()601 UeManager::ScheduleRrcConnectionReconfiguration ()
602 {
603 NS_LOG_FUNCTION (this);
604 switch (m_state)
605 {
606 case INITIAL_RANDOM_ACCESS:
607 case CONNECTION_SETUP:
608 case ATTACH_REQUEST:
609 case CONNECTION_RECONFIGURATION:
610 case CONNECTION_REESTABLISHMENT:
611 case HANDOVER_PREPARATION:
612 case HANDOVER_JOINING:
613 case HANDOVER_LEAVING:
614 // a previous reconfiguration still ongoing, we need to wait for it to be finished
615 m_pendingRrcConnectionReconfiguration = true;
616 break;
617
618 case CONNECTED_NORMALLY:
619 {
620 m_pendingRrcConnectionReconfiguration = false;
621 LteRrcSap::RrcConnectionReconfiguration msg = BuildRrcConnectionReconfiguration ();
622 m_rrc->m_rrcSapUser->SendRrcConnectionReconfiguration (m_rnti, msg);
623 RecordDataRadioBearersToBeStarted ();
624 SwitchToState (CONNECTION_RECONFIGURATION);
625 }
626 break;
627
628 default:
629 NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
630 break;
631 }
632 }
633
634 void
PrepareHandover(uint16_t cellId)635 UeManager::PrepareHandover (uint16_t cellId)
636 {
637 NS_LOG_FUNCTION (this << cellId);
638 switch (m_state)
639 {
640 case CONNECTED_NORMALLY:
641 {
642 m_targetCellId = cellId;
643 EpcX2SapProvider::HandoverRequestParams params;
644 params.oldEnbUeX2apId = m_rnti;
645 params.cause = EpcX2SapProvider::HandoverDesirableForRadioReason;
646 params.sourceCellId = m_rrc->ComponentCarrierToCellId (m_componentCarrierId);
647 params.targetCellId = cellId;
648 params.mmeUeS1apId = m_imsi;
649 params.ueAggregateMaxBitRateDownlink = 200 * 1000;
650 params.ueAggregateMaxBitRateUplink = 100 * 1000;
651 params.bearers = GetErabList ();
652
653 LteRrcSap::HandoverPreparationInfo hpi;
654 hpi.asConfig.sourceUeIdentity = m_rnti;
655 hpi.asConfig.sourceDlCarrierFreq = m_rrc->m_dlEarfcn;
656 hpi.asConfig.sourceMeasConfig = m_rrc->m_ueMeasConfig;
657 hpi.asConfig.sourceRadioResourceConfig = GetRadioResourceConfigForHandoverPreparationInfo ();
658 hpi.asConfig.sourceMasterInformationBlock.dlBandwidth = m_rrc->m_dlBandwidth;
659 hpi.asConfig.sourceMasterInformationBlock.systemFrameNumber = 0;
660 hpi.asConfig.sourceSystemInformationBlockType1.cellAccessRelatedInfo.plmnIdentityInfo.plmnIdentity = m_rrc->m_sib1.at (m_componentCarrierId).cellAccessRelatedInfo.plmnIdentityInfo.plmnIdentity;
661 hpi.asConfig.sourceSystemInformationBlockType1.cellAccessRelatedInfo.cellIdentity = m_rrc->ComponentCarrierToCellId (m_componentCarrierId);
662 hpi.asConfig.sourceSystemInformationBlockType1.cellAccessRelatedInfo.csgIndication = m_rrc->m_sib1.at (m_componentCarrierId).cellAccessRelatedInfo.csgIndication;
663 hpi.asConfig.sourceSystemInformationBlockType1.cellAccessRelatedInfo.csgIdentity = m_rrc->m_sib1.at (m_componentCarrierId).cellAccessRelatedInfo.csgIdentity;
664 LteEnbCmacSapProvider::RachConfig rc = m_rrc->m_cmacSapProvider.at (m_componentCarrierId)->GetRachConfig ();
665 hpi.asConfig.sourceSystemInformationBlockType2.radioResourceConfigCommon.rachConfigCommon.preambleInfo.numberOfRaPreambles = rc.numberOfRaPreambles;
666 hpi.asConfig.sourceSystemInformationBlockType2.radioResourceConfigCommon.rachConfigCommon.raSupervisionInfo.preambleTransMax = rc.preambleTransMax;
667 hpi.asConfig.sourceSystemInformationBlockType2.radioResourceConfigCommon.rachConfigCommon.raSupervisionInfo.raResponseWindowSize = rc.raResponseWindowSize;
668 hpi.asConfig.sourceSystemInformationBlockType2.radioResourceConfigCommon.rachConfigCommon.txFailParam.connEstFailCount = rc.connEstFailCount;
669 hpi.asConfig.sourceSystemInformationBlockType2.freqInfo.ulCarrierFreq = m_rrc->m_ulEarfcn;
670 hpi.asConfig.sourceSystemInformationBlockType2.freqInfo.ulBandwidth = m_rrc->m_ulBandwidth;
671 params.rrcContext = m_rrc->m_rrcSapUser->EncodeHandoverPreparationInformation (hpi);
672
673 NS_LOG_LOGIC ("oldEnbUeX2apId = " << params.oldEnbUeX2apId);
674 NS_LOG_LOGIC ("sourceCellId = " << params.sourceCellId);
675 NS_LOG_LOGIC ("targetCellId = " << params.targetCellId);
676 NS_LOG_LOGIC ("mmeUeS1apId = " << params.mmeUeS1apId);
677 NS_LOG_LOGIC ("rrcContext = " << params.rrcContext);
678
679 m_rrc->m_x2SapProvider->SendHandoverRequest (params);
680 SwitchToState (HANDOVER_PREPARATION);
681 }
682 break;
683
684 default:
685 NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
686 break;
687 }
688
689 }
690
691 void
RecvHandoverRequestAck(EpcX2SapUser::HandoverRequestAckParams params)692 UeManager::RecvHandoverRequestAck (EpcX2SapUser::HandoverRequestAckParams params)
693 {
694 NS_LOG_FUNCTION (this);
695
696 NS_ASSERT_MSG (params.notAdmittedBearers.empty (), "not admission of some bearers upon handover is not supported");
697 NS_ASSERT_MSG (params.admittedBearers.size () == m_drbMap.size (), "not enough bearers in admittedBearers");
698
699 // note: the Handover command from the target eNB to the source eNB
700 // is expected to be sent transparently to the UE; however, here we
701 // decode the message and eventually re-encode it. This way we can
702 // support both a real RRC protocol implementation and an ideal one
703 // without actual RRC protocol encoding.
704
705 Ptr<Packet> encodedHandoverCommand = params.rrcContext;
706 LteRrcSap::RrcConnectionReconfiguration handoverCommand = m_rrc->m_rrcSapUser->DecodeHandoverCommand (encodedHandoverCommand);
707 if (handoverCommand.haveNonCriticalExtension)
708 {
709 //Total number of component carriers = handoverCommand.nonCriticalExtension.sCellsToAddModList.size() + 1 (Primary carrier)
710 if (handoverCommand.nonCriticalExtension.sCellsToAddModList.size() + 1 != m_rrc->m_numberOfComponentCarriers)
711 {
712 //Currently handover is only possible if source and target eNBs have equal number of component carriers
713 NS_FATAL_ERROR ("The source and target eNBs have unequal number of component carriers. Target eNB CCs = "
714 << handoverCommand.nonCriticalExtension.sCellsToAddModList.size() + 1
715 << " Source eNB CCs = " << m_rrc->m_numberOfComponentCarriers);
716 }
717 }
718 m_rrc->m_rrcSapUser->SendRrcConnectionReconfiguration (m_rnti, handoverCommand);
719 SwitchToState (HANDOVER_LEAVING);
720 m_handoverLeavingTimeout = Simulator::Schedule (m_rrc->m_handoverLeavingTimeoutDuration,
721 &LteEnbRrc::HandoverLeavingTimeout,
722 m_rrc, m_rnti);
723 NS_ASSERT (handoverCommand.haveMobilityControlInfo);
724 m_rrc->m_handoverStartTrace (m_imsi, m_rrc->ComponentCarrierToCellId (m_componentCarrierId), m_rnti, handoverCommand.mobilityControlInfo.targetPhysCellId);
725
726 //Set the target cell ID and the RNTI so that handover cancel message can be sent if required
727 m_targetX2apId = params.newEnbUeX2apId;
728 m_targetCellId = params.targetCellId;
729
730 EpcX2SapProvider::SnStatusTransferParams sst;
731 sst.oldEnbUeX2apId = params.oldEnbUeX2apId;
732 sst.newEnbUeX2apId = params.newEnbUeX2apId;
733 sst.sourceCellId = params.sourceCellId;
734 sst.targetCellId = params.targetCellId;
735 for ( std::map <uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator drbIt = m_drbMap.begin ();
736 drbIt != m_drbMap.end ();
737 ++drbIt)
738 {
739 // SN status transfer is only for AM RLC
740 if (0 != drbIt->second->m_rlc->GetObject<LteRlcAm> ())
741 {
742 LtePdcp::Status status = drbIt->second->m_pdcp->GetStatus ();
743 EpcX2Sap::ErabsSubjectToStatusTransferItem i;
744 i.dlPdcpSn = status.txSn;
745 i.ulPdcpSn = status.rxSn;
746 sst.erabsSubjectToStatusTransferList.push_back (i);
747 }
748 }
749 m_rrc->m_x2SapProvider->SendSnStatusTransfer (sst);
750 }
751
752
753 LteRrcSap::RadioResourceConfigDedicated
GetRadioResourceConfigForHandoverPreparationInfo()754 UeManager::GetRadioResourceConfigForHandoverPreparationInfo ()
755 {
756 NS_LOG_FUNCTION (this);
757 return BuildRadioResourceConfigDedicated ();
758 }
759
760 LteRrcSap::RrcConnectionReconfiguration
GetRrcConnectionReconfigurationForHandover()761 UeManager::GetRrcConnectionReconfigurationForHandover ()
762 {
763 NS_LOG_FUNCTION (this);
764 return BuildRrcConnectionReconfiguration ();
765 }
766
767 void
SendPacket(uint8_t bid,Ptr<Packet> p)768 UeManager::SendPacket (uint8_t bid, Ptr<Packet> p)
769 {
770 NS_LOG_FUNCTION (this << p << (uint16_t) bid);
771 LtePdcpSapProvider::TransmitPdcpSduParameters params;
772 params.pdcpSdu = p;
773 params.rnti = m_rnti;
774 params.lcid = Bid2Lcid (bid);
775 uint8_t drbid = Bid2Drbid (bid);
776 // Transmit PDCP sdu only if DRB ID found in drbMap
777 std::map<uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator it = m_drbMap.find (drbid);
778 if (it != m_drbMap.end ())
779 {
780 Ptr<LteDataRadioBearerInfo> bearerInfo = GetDataRadioBearerInfo (drbid);
781 if (bearerInfo != NULL)
782 {
783 LtePdcpSapProvider* pdcpSapProvider = bearerInfo->m_pdcp->GetLtePdcpSapProvider ();
784 pdcpSapProvider->TransmitPdcpSdu (params);
785 }
786 }
787 }
788
789 void
SendData(uint8_t bid,Ptr<Packet> p)790 UeManager::SendData (uint8_t bid, Ptr<Packet> p)
791 {
792 NS_LOG_FUNCTION (this << p << (uint16_t) bid);
793 switch (m_state)
794 {
795 case INITIAL_RANDOM_ACCESS:
796 case CONNECTION_SETUP:
797 NS_LOG_WARN ("not connected, discarding packet");
798 return;
799 break;
800
801 case CONNECTED_NORMALLY:
802 case CONNECTION_RECONFIGURATION:
803 case CONNECTION_REESTABLISHMENT:
804 case HANDOVER_PREPARATION:
805 case HANDOVER_PATH_SWITCH:
806 {
807 NS_LOG_LOGIC ("queueing data on PDCP for transmission over the air");
808 SendPacket (bid, p);
809 }
810 break;
811
812 case HANDOVER_JOINING:
813 {
814 // Buffer data until RRC Connection Reconfiguration Complete message is received
815 NS_LOG_LOGIC ("buffering data");
816 m_packetBuffer.push_back (std::make_pair (bid, p));
817 }
818 break;
819
820 case HANDOVER_LEAVING:
821 {
822 NS_LOG_LOGIC ("forwarding data to target eNB over X2-U");
823 uint8_t drbid = Bid2Drbid (bid);
824 EpcX2Sap::UeDataParams params;
825 params.sourceCellId = m_rrc->ComponentCarrierToCellId (m_componentCarrierId);
826 params.targetCellId = m_targetCellId;
827 params.gtpTeid = GetDataRadioBearerInfo (drbid)->m_gtpTeid;
828 params.ueData = p;
829 m_rrc->m_x2SapProvider->SendUeData (params);
830 }
831 break;
832
833 default:
834 NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
835 break;
836 }
837 }
838
839 std::vector<EpcX2Sap::ErabToBeSetupItem>
GetErabList()840 UeManager::GetErabList ()
841 {
842 NS_LOG_FUNCTION (this);
843 std::vector<EpcX2Sap::ErabToBeSetupItem> ret;
844 for (std::map <uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator it = m_drbMap.begin ();
845 it != m_drbMap.end ();
846 ++it)
847 {
848 EpcX2Sap::ErabToBeSetupItem etbsi;
849 etbsi.erabId = it->second->m_epsBearerIdentity;
850 etbsi.erabLevelQosParameters = it->second->m_epsBearer;
851 etbsi.dlForwarding = false;
852 etbsi.transportLayerAddress = it->second->m_transportLayerAddress;
853 etbsi.gtpTeid = it->second->m_gtpTeid;
854 ret.push_back (etbsi);
855 }
856 return ret;
857 }
858
859 void
SendUeContextRelease()860 UeManager::SendUeContextRelease ()
861 {
862 NS_LOG_FUNCTION (this);
863 switch (m_state)
864 {
865 case HANDOVER_PATH_SWITCH:
866 NS_LOG_INFO ("Send UE CONTEXT RELEASE from target eNB to source eNB");
867 EpcX2SapProvider::UeContextReleaseParams ueCtxReleaseParams;
868 ueCtxReleaseParams.oldEnbUeX2apId = m_sourceX2apId;
869 ueCtxReleaseParams.newEnbUeX2apId = m_rnti;
870 ueCtxReleaseParams.sourceCellId = m_sourceCellId;
871 ueCtxReleaseParams.targetCellId = m_targetCellId;
872 m_rrc->m_x2SapProvider->SendUeContextRelease (ueCtxReleaseParams);
873 SwitchToState (CONNECTED_NORMALLY);
874 m_rrc->m_handoverEndOkTrace (m_imsi, m_rrc->ComponentCarrierToCellId (m_componentCarrierId), m_rnti);
875 break;
876
877 default:
878 NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
879 break;
880 }
881 }
882
883 void
RecvHandoverPreparationFailure(uint16_t cellId)884 UeManager::RecvHandoverPreparationFailure (uint16_t cellId)
885 {
886 NS_LOG_FUNCTION (this << cellId);
887 switch (m_state)
888 {
889 case HANDOVER_PREPARATION:
890 NS_ASSERT (cellId == m_targetCellId);
891 NS_LOG_INFO ("target eNB sent HO preparation failure, aborting HO");
892 SwitchToState (CONNECTED_NORMALLY);
893 break;
894
895 default:
896 NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
897 break;
898 }
899 }
900
901 void
RecvSnStatusTransfer(EpcX2SapUser::SnStatusTransferParams params)902 UeManager::RecvSnStatusTransfer (EpcX2SapUser::SnStatusTransferParams params)
903 {
904 NS_LOG_FUNCTION (this);
905 for (std::vector<EpcX2Sap::ErabsSubjectToStatusTransferItem>::iterator erabIt
906 = params.erabsSubjectToStatusTransferList.begin ();
907 erabIt != params.erabsSubjectToStatusTransferList.end ();
908 ++erabIt)
909 {
910 // LtePdcp::Status status;
911 // status.txSn = erabIt->dlPdcpSn;
912 // status.rxSn = erabIt->ulPdcpSn;
913 // uint8_t drbId = Bid2Drbid (erabIt->erabId);
914 // std::map <uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator drbIt = m_drbMap.find (drbId);
915 // NS_ASSERT_MSG (drbIt != m_drbMap.end (), "could not find DRBID " << (uint32_t) drbId);
916 // drbIt->second->m_pdcp->SetStatus (status);
917 }
918 }
919
920 void
RecvUeContextRelease(EpcX2SapUser::UeContextReleaseParams params)921 UeManager::RecvUeContextRelease (EpcX2SapUser::UeContextReleaseParams params)
922 {
923 NS_LOG_FUNCTION (this);
924 NS_ASSERT_MSG (m_state == HANDOVER_LEAVING, "method unexpected in state " << ToString (m_state));
925 m_handoverLeavingTimeout.Cancel ();
926 }
927
928
929 // methods forwarded from RRC SAP
930
931 void
CompleteSetupUe(LteEnbRrcSapProvider::CompleteSetupUeParameters params)932 UeManager::CompleteSetupUe (LteEnbRrcSapProvider::CompleteSetupUeParameters params)
933 {
934 NS_LOG_FUNCTION (this);
935 m_srb0->m_rlc->SetLteRlcSapUser (params.srb0SapUser);
936 m_srb1->m_pdcp->SetLtePdcpSapUser (params.srb1SapUser);
937 }
938
939 void
RecvRrcConnectionRequest(LteRrcSap::RrcConnectionRequest msg)940 UeManager::RecvRrcConnectionRequest (LteRrcSap::RrcConnectionRequest msg)
941 {
942 NS_LOG_FUNCTION (this);
943 switch (m_state)
944 {
945 case INITIAL_RANDOM_ACCESS:
946 {
947 m_connectionRequestTimeout.Cancel ();
948
949 if (m_rrc->m_admitRrcConnectionRequest == true)
950 {
951 m_imsi = msg.ueIdentity;
952
953 // send RRC CONNECTION SETUP to UE
954 LteRrcSap::RrcConnectionSetup msg2;
955 msg2.rrcTransactionIdentifier = GetNewRrcTransactionIdentifier ();
956 msg2.radioResourceConfigDedicated = BuildRadioResourceConfigDedicated ();
957 m_rrc->m_rrcSapUser->SendRrcConnectionSetup (m_rnti, msg2);
958
959 RecordDataRadioBearersToBeStarted ();
960 m_connectionSetupTimeout = Simulator::Schedule (
961 m_rrc->m_connectionSetupTimeoutDuration,
962 &LteEnbRrc::ConnectionSetupTimeout, m_rrc, m_rnti);
963 SwitchToState (CONNECTION_SETUP);
964 }
965 else
966 {
967 NS_LOG_INFO ("rejecting connection request for RNTI " << m_rnti);
968
969 // send RRC CONNECTION REJECT to UE
970 LteRrcSap::RrcConnectionReject rejectMsg;
971 rejectMsg.waitTime = 3;
972 m_rrc->m_rrcSapUser->SendRrcConnectionReject (m_rnti, rejectMsg);
973
974 m_connectionRejectedTimeout = Simulator::Schedule (
975 m_rrc->m_connectionRejectedTimeoutDuration,
976 &LteEnbRrc::ConnectionRejectedTimeout, m_rrc, m_rnti);
977 SwitchToState (CONNECTION_REJECTED);
978 }
979 }
980 break;
981
982 default:
983 NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
984 break;
985 }
986 }
987
988 void
RecvRrcConnectionSetupCompleted(LteRrcSap::RrcConnectionSetupCompleted msg)989 UeManager::RecvRrcConnectionSetupCompleted (LteRrcSap::RrcConnectionSetupCompleted msg)
990 {
991 NS_LOG_FUNCTION (this);
992 switch (m_state)
993 {
994 case CONNECTION_SETUP:
995 m_connectionSetupTimeout.Cancel ();
996 if ( m_caSupportConfigured == false && m_rrc->m_numberOfComponentCarriers > 1)
997 {
998 m_pendingRrcConnectionReconfiguration = true; // Force Reconfiguration
999 m_pendingStartDataRadioBearers = true;
1000 }
1001
1002 if (m_rrc->m_s1SapProvider != 0)
1003 {
1004 m_rrc->m_s1SapProvider->InitialUeMessage (m_imsi, m_rnti);
1005 SwitchToState (ATTACH_REQUEST);
1006 }
1007 else
1008 {
1009 SwitchToState (CONNECTED_NORMALLY);
1010 }
1011 m_rrc->m_connectionEstablishedTrace (m_imsi, m_rrc->ComponentCarrierToCellId (m_componentCarrierId), m_rnti);
1012 break;
1013
1014 default:
1015 NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
1016 break;
1017 }
1018 }
1019
1020 void
RecvRrcConnectionReconfigurationCompleted(LteRrcSap::RrcConnectionReconfigurationCompleted msg)1021 UeManager::RecvRrcConnectionReconfigurationCompleted (LteRrcSap::RrcConnectionReconfigurationCompleted msg)
1022 {
1023 NS_LOG_FUNCTION (this);
1024 switch (m_state)
1025 {
1026 case CONNECTION_RECONFIGURATION:
1027 StartDataRadioBearers ();
1028 if (m_needPhyMacConfiguration)
1029 {
1030 // configure MAC (and scheduler)
1031 LteEnbCmacSapProvider::UeConfig req;
1032 req.m_rnti = m_rnti;
1033 req.m_transmissionMode = m_physicalConfigDedicated.antennaInfo.transmissionMode;
1034 for (uint8_t i = 0; i < m_rrc->m_numberOfComponentCarriers; i++)
1035 {
1036 m_rrc->m_cmacSapProvider.at (i)->UeUpdateConfigurationReq (req);
1037
1038 // configure PHY
1039 m_rrc->m_cphySapProvider.at (i)->SetTransmissionMode (req.m_rnti, req.m_transmissionMode);
1040 double paDouble = LteRrcSap::ConvertPdschConfigDedicated2Double (m_physicalConfigDedicated.pdschConfigDedicated);
1041 m_rrc->m_cphySapProvider.at (i)->SetPa (m_rnti, paDouble);
1042 }
1043
1044 m_needPhyMacConfiguration = false;
1045 }
1046 SwitchToState (CONNECTED_NORMALLY);
1047 m_rrc->m_connectionReconfigurationTrace (m_imsi, m_rrc->ComponentCarrierToCellId (m_componentCarrierId), m_rnti);
1048 break;
1049
1050 // This case is added to NS-3 in order to handle bearer de-activation scenario for CONNECTED state UE
1051 case CONNECTED_NORMALLY:
1052 NS_LOG_INFO ("ignoring RecvRrcConnectionReconfigurationCompleted in state " << ToString (m_state));
1053 break;
1054
1055 case HANDOVER_LEAVING:
1056 NS_LOG_INFO ("ignoring RecvRrcConnectionReconfigurationCompleted in state " << ToString (m_state));
1057 break;
1058
1059 case HANDOVER_JOINING:
1060 {
1061 m_handoverJoiningTimeout.Cancel ();
1062
1063 while (!m_packetBuffer.empty ())
1064 {
1065 NS_LOG_LOGIC ("dequeueing data from buffer");
1066 std::pair <uint8_t, Ptr<Packet> > bidPacket = m_packetBuffer.front ();
1067 uint8_t bid = bidPacket.first;
1068 Ptr<Packet> p = bidPacket.second;
1069
1070 NS_LOG_LOGIC ("queueing data on PDCP for transmission over the air");
1071 SendPacket (bid, p);
1072
1073 m_packetBuffer.pop_front ();
1074 }
1075
1076 NS_LOG_INFO ("Send PATH SWITCH REQUEST to the MME");
1077 EpcEnbS1SapProvider::PathSwitchRequestParameters params;
1078 params.rnti = m_rnti;
1079 params.cellId = m_rrc->ComponentCarrierToCellId (m_componentCarrierId);
1080 params.mmeUeS1Id = m_imsi;
1081 SwitchToState (HANDOVER_PATH_SWITCH);
1082 for (std::map <uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator it = m_drbMap.begin ();
1083 it != m_drbMap.end ();
1084 ++it)
1085 {
1086 EpcEnbS1SapProvider::BearerToBeSwitched b;
1087 b.epsBearerId = it->second->m_epsBearerIdentity;
1088 b.teid = it->second->m_gtpTeid;
1089 params.bearersToBeSwitched.push_back (b);
1090 }
1091 m_rrc->m_s1SapProvider->PathSwitchRequest (params);
1092 }
1093 break;
1094
1095 default:
1096 NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
1097 break;
1098 }
1099 }
1100
1101 void
RecvRrcConnectionReestablishmentRequest(LteRrcSap::RrcConnectionReestablishmentRequest msg)1102 UeManager::RecvRrcConnectionReestablishmentRequest (LteRrcSap::RrcConnectionReestablishmentRequest msg)
1103 {
1104 NS_LOG_FUNCTION (this);
1105 switch (m_state)
1106 {
1107 case CONNECTED_NORMALLY:
1108 break;
1109
1110 case HANDOVER_LEAVING:
1111 m_handoverLeavingTimeout.Cancel ();
1112 break;
1113
1114 default:
1115 NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
1116 break;
1117 }
1118
1119 LteRrcSap::RrcConnectionReestablishment msg2;
1120 msg2.rrcTransactionIdentifier = GetNewRrcTransactionIdentifier ();
1121 msg2.radioResourceConfigDedicated = BuildRadioResourceConfigDedicated ();
1122 m_rrc->m_rrcSapUser->SendRrcConnectionReestablishment (m_rnti, msg2);
1123 SwitchToState (CONNECTION_REESTABLISHMENT);
1124 }
1125
1126 void
RecvRrcConnectionReestablishmentComplete(LteRrcSap::RrcConnectionReestablishmentComplete msg)1127 UeManager::RecvRrcConnectionReestablishmentComplete (LteRrcSap::RrcConnectionReestablishmentComplete msg)
1128 {
1129 NS_LOG_FUNCTION (this);
1130 SwitchToState (CONNECTED_NORMALLY);
1131 }
1132
1133 void
RecvMeasurementReport(LteRrcSap::MeasurementReport msg)1134 UeManager::RecvMeasurementReport (LteRrcSap::MeasurementReport msg)
1135 {
1136 uint8_t measId = msg.measResults.measId;
1137 NS_LOG_FUNCTION (this << (uint16_t) measId);
1138 NS_LOG_LOGIC ("measId " << (uint16_t) measId
1139 << " haveMeasResultNeighCells " << msg.measResults.haveMeasResultNeighCells
1140 << " measResultListEutra " << msg.measResults.measResultListEutra.size ()
1141 << " haveScellsMeas " << msg.measResults.haveScellsMeas
1142 << " measScellResultList " << msg.measResults.measScellResultList.measResultScell.size ());
1143 NS_LOG_LOGIC ("serving cellId " << m_rrc->ComponentCarrierToCellId (m_componentCarrierId)
1144 << " RSRP " << (uint16_t) msg.measResults.rsrpResult
1145 << " RSRQ " << (uint16_t) msg.measResults.rsrqResult);
1146
1147 for (std::list <LteRrcSap::MeasResultEutra>::iterator it = msg.measResults.measResultListEutra.begin ();
1148 it != msg.measResults.measResultListEutra.end ();
1149 ++it)
1150 {
1151 NS_LOG_LOGIC ("neighbour cellId " << it->physCellId
1152 << " RSRP " << (it->haveRsrpResult ? (uint16_t) it->rsrpResult : 255)
1153 << " RSRQ " << (it->haveRsrqResult ? (uint16_t) it->rsrqResult : 255));
1154 }
1155
1156 if ((m_rrc->m_handoverManagementSapProvider != 0)
1157 && (m_rrc->m_handoverMeasIds.find (measId) != m_rrc->m_handoverMeasIds.end ()))
1158 {
1159 // this measurement was requested by the handover algorithm
1160 m_rrc->m_handoverManagementSapProvider->ReportUeMeas (m_rnti,
1161 msg.measResults);
1162 }
1163
1164 if ((m_rrc->m_ccmRrcSapProvider != 0)
1165 && (m_rrc->m_componentCarrierMeasIds.find (measId) != m_rrc->m_componentCarrierMeasIds.end ()))
1166 {
1167 // this measurement was requested by the handover algorithm
1168 m_rrc->m_ccmRrcSapProvider->ReportUeMeas (m_rnti,
1169 msg.measResults);
1170 }
1171
1172 if ((m_rrc->m_anrSapProvider != 0)
1173 && (m_rrc->m_anrMeasIds.find (measId) != m_rrc->m_anrMeasIds.end ()))
1174 {
1175 // this measurement was requested by the ANR function
1176 m_rrc->m_anrSapProvider->ReportUeMeas (msg.measResults);
1177 }
1178
1179 if ((m_rrc->m_ffrRrcSapProvider.size () > 0)
1180 && (m_rrc->m_ffrMeasIds.find (measId) != m_rrc->m_ffrMeasIds.end ()))
1181 {
1182 // this measurement was requested by the FFR function
1183 m_rrc->m_ffrRrcSapProvider.at (0)->ReportUeMeas (m_rnti, msg.measResults);
1184 }
1185 if (msg.measResults.haveScellsMeas == true)
1186 {
1187 for (std::list <LteRrcSap::MeasResultScell>::iterator it = msg.measResults.measScellResultList.measResultScell.begin ();
1188 it != msg.measResults.measScellResultList.measResultScell.end ();
1189 ++it)
1190 {
1191 m_rrc->m_ffrRrcSapProvider.at (it->servFreqId)->ReportUeMeas (m_rnti, msg.measResults);
1192 /// ToDo: implement on Ffr algorithm the code to properly parsing the new measResults message format
1193 /// alternatively it is needed to 'repack' properly the measResults message before sending to Ffr
1194 }
1195 }
1196
1197 ///Report any measurements to ComponentCarrierManager, so it can react to any change or activate the SCC
1198 m_rrc->m_ccmRrcSapProvider->ReportUeMeas (m_rnti, msg.measResults);
1199 // fire a trace source
1200 m_rrc->m_recvMeasurementReportTrace (m_imsi, m_rrc->ComponentCarrierToCellId (m_componentCarrierId), m_rnti, msg);
1201
1202 } // end of UeManager::RecvMeasurementReport
1203
1204
1205 // methods forwarded from CMAC SAP
1206
1207 void
CmacUeConfigUpdateInd(LteEnbCmacSapUser::UeConfig cmacParams)1208 UeManager::CmacUeConfigUpdateInd (LteEnbCmacSapUser::UeConfig cmacParams)
1209 {
1210 NS_LOG_FUNCTION (this << m_rnti);
1211 // at this stage used only by the scheduler for updating txMode
1212
1213 m_physicalConfigDedicated.antennaInfo.transmissionMode = cmacParams.m_transmissionMode;
1214
1215 m_needPhyMacConfiguration = true;
1216
1217 // reconfigure the UE RRC
1218 ScheduleRrcConnectionReconfiguration ();
1219 }
1220
1221
1222 // methods forwarded from PDCP SAP
1223
1224 void
DoReceivePdcpSdu(LtePdcpSapUser::ReceivePdcpSduParameters params)1225 UeManager::DoReceivePdcpSdu (LtePdcpSapUser::ReceivePdcpSduParameters params)
1226 {
1227 NS_LOG_FUNCTION (this);
1228 if (params.lcid > 2)
1229 {
1230 // data radio bearer
1231 EpsBearerTag tag;
1232 tag.SetRnti (params.rnti);
1233 tag.SetBid (Lcid2Bid (params.lcid));
1234 params.pdcpSdu->AddPacketTag (tag);
1235 m_rrc->m_forwardUpCallback (params.pdcpSdu);
1236 }
1237 }
1238
1239
1240 uint16_t
GetRnti(void) const1241 UeManager::GetRnti (void) const
1242 {
1243 return m_rnti;
1244 }
1245
1246 uint64_t
GetImsi(void) const1247 UeManager::GetImsi (void) const
1248 {
1249 return m_imsi;
1250 }
1251
1252 uint8_t
GetComponentCarrierId() const1253 UeManager::GetComponentCarrierId () const
1254 {
1255 return m_componentCarrierId;
1256 }
1257
1258 uint16_t
GetSrsConfigurationIndex(void) const1259 UeManager::GetSrsConfigurationIndex (void) const
1260 {
1261 return m_physicalConfigDedicated.soundingRsUlConfigDedicated.srsConfigIndex;
1262 }
1263
1264 void
SetSrsConfigurationIndex(uint16_t srsConfIndex)1265 UeManager::SetSrsConfigurationIndex (uint16_t srsConfIndex)
1266 {
1267 NS_LOG_FUNCTION (this);
1268 m_physicalConfigDedicated.soundingRsUlConfigDedicated.srsConfigIndex = srsConfIndex;
1269 for (uint16_t i = 0; i < m_rrc->m_numberOfComponentCarriers; i++)
1270 {
1271 m_rrc->m_cphySapProvider.at (i)->SetSrsConfigurationIndex (m_rnti, srsConfIndex);
1272 }
1273 switch (m_state)
1274 {
1275 case INITIAL_RANDOM_ACCESS:
1276 // do nothing, srs conf index will be correctly enforced upon
1277 // RRC connection establishment
1278 break;
1279
1280 default:
1281 ScheduleRrcConnectionReconfiguration ();
1282 break;
1283 }
1284 }
1285
1286 UeManager::State
GetState(void) const1287 UeManager::GetState (void) const
1288 {
1289 return m_state;
1290 }
1291
1292 void
SetPdschConfigDedicated(LteRrcSap::PdschConfigDedicated pdschConfigDedicated)1293 UeManager::SetPdschConfigDedicated (LteRrcSap::PdschConfigDedicated pdschConfigDedicated)
1294 {
1295 NS_LOG_FUNCTION (this);
1296 m_physicalConfigDedicated.pdschConfigDedicated = pdschConfigDedicated;
1297
1298 m_needPhyMacConfiguration = true;
1299
1300 // reconfigure the UE RRC
1301 ScheduleRrcConnectionReconfiguration ();
1302 }
1303
1304 void
CancelPendingEvents()1305 UeManager::CancelPendingEvents ()
1306 {
1307 NS_LOG_FUNCTION (this);
1308 m_connectionRequestTimeout.Cancel ();
1309 m_connectionRejectedTimeout.Cancel ();
1310 m_connectionSetupTimeout.Cancel ();
1311 m_handoverJoiningTimeout.Cancel ();
1312 m_handoverLeavingTimeout.Cancel ();
1313 }
1314
1315 uint8_t
AddDataRadioBearerInfo(Ptr<LteDataRadioBearerInfo> drbInfo)1316 UeManager::AddDataRadioBearerInfo (Ptr<LteDataRadioBearerInfo> drbInfo)
1317 {
1318 NS_LOG_FUNCTION (this);
1319 const uint8_t MAX_DRB_ID = 32;
1320 for (int drbid = (m_lastAllocatedDrbid + 1) % MAX_DRB_ID;
1321 drbid != m_lastAllocatedDrbid;
1322 drbid = (drbid + 1) % MAX_DRB_ID)
1323 {
1324 if (drbid != 0) // 0 is not allowed
1325 {
1326 if (m_drbMap.find (drbid) == m_drbMap.end ())
1327 {
1328 m_drbMap.insert (std::pair<uint8_t, Ptr<LteDataRadioBearerInfo> > (drbid, drbInfo));
1329 drbInfo->m_drbIdentity = drbid;
1330 m_lastAllocatedDrbid = drbid;
1331 return drbid;
1332 }
1333 }
1334 }
1335 NS_FATAL_ERROR ("no more data radio bearer ids available");
1336 return 0;
1337 }
1338
1339 Ptr<LteDataRadioBearerInfo>
GetDataRadioBearerInfo(uint8_t drbid)1340 UeManager::GetDataRadioBearerInfo (uint8_t drbid)
1341 {
1342 NS_LOG_FUNCTION (this << (uint32_t) drbid);
1343 NS_ASSERT (0 != drbid);
1344 std::map<uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator it = m_drbMap.find (drbid);
1345 NS_ABORT_IF (it == m_drbMap.end ());
1346 return it->second;
1347 }
1348
1349
1350 void
RemoveDataRadioBearerInfo(uint8_t drbid)1351 UeManager::RemoveDataRadioBearerInfo (uint8_t drbid)
1352 {
1353 NS_LOG_FUNCTION (this << (uint32_t) drbid);
1354 std::map <uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator it = m_drbMap.find (drbid);
1355 NS_ASSERT_MSG (it != m_drbMap.end (), "request to remove radio bearer with unknown drbid " << drbid);
1356 m_drbMap.erase (it);
1357 }
1358
1359
1360 LteRrcSap::RrcConnectionReconfiguration
BuildRrcConnectionReconfiguration()1361 UeManager::BuildRrcConnectionReconfiguration ()
1362 {
1363 NS_LOG_FUNCTION (this);
1364 LteRrcSap::RrcConnectionReconfiguration msg;
1365 msg.rrcTransactionIdentifier = GetNewRrcTransactionIdentifier ();
1366 msg.haveRadioResourceConfigDedicated = true;
1367 msg.radioResourceConfigDedicated = BuildRadioResourceConfigDedicated ();
1368 msg.haveMobilityControlInfo = false;
1369 msg.haveMeasConfig = true;
1370 msg.measConfig = m_rrc->m_ueMeasConfig;
1371 if ( m_caSupportConfigured == false && m_rrc->m_numberOfComponentCarriers > 1)
1372 {
1373 m_caSupportConfigured = true;
1374 NS_LOG_FUNCTION ( this << "CA not configured. Configure now!" );
1375 msg.haveNonCriticalExtension = true;
1376 msg.nonCriticalExtension = BuildNonCriticalExtentionConfigurationCa ();
1377 NS_LOG_FUNCTION ( this << " haveNonCriticalExtension " << msg.haveNonCriticalExtension );
1378 }
1379 else
1380 {
1381 msg.haveNonCriticalExtension = false;
1382 }
1383
1384 return msg;
1385 }
1386
1387 LteRrcSap::RadioResourceConfigDedicated
BuildRadioResourceConfigDedicated()1388 UeManager::BuildRadioResourceConfigDedicated ()
1389 {
1390 NS_LOG_FUNCTION (this);
1391 LteRrcSap::RadioResourceConfigDedicated rrcd;
1392
1393 if (m_srb1 != 0)
1394 {
1395 LteRrcSap::SrbToAddMod stam;
1396 stam.srbIdentity = m_srb1->m_srbIdentity;
1397 stam.logicalChannelConfig = m_srb1->m_logicalChannelConfig;
1398 rrcd.srbToAddModList.push_back (stam);
1399 }
1400
1401 for (std::map <uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator it = m_drbMap.begin ();
1402 it != m_drbMap.end ();
1403 ++it)
1404 {
1405 LteRrcSap::DrbToAddMod dtam;
1406 dtam.epsBearerIdentity = it->second->m_epsBearerIdentity;
1407 dtam.drbIdentity = it->second->m_drbIdentity;
1408 dtam.rlcConfig = it->second->m_rlcConfig;
1409 dtam.logicalChannelIdentity = it->second->m_logicalChannelIdentity;
1410 dtam.logicalChannelConfig = it->second->m_logicalChannelConfig;
1411 rrcd.drbToAddModList.push_back (dtam);
1412 }
1413
1414 rrcd.havePhysicalConfigDedicated = true;
1415 rrcd.physicalConfigDedicated = m_physicalConfigDedicated;
1416 return rrcd;
1417 }
1418
1419 uint8_t
GetNewRrcTransactionIdentifier()1420 UeManager::GetNewRrcTransactionIdentifier ()
1421 {
1422 NS_LOG_FUNCTION (this);
1423 ++m_lastRrcTransactionIdentifier;
1424 m_lastRrcTransactionIdentifier %= 4;
1425 return m_lastRrcTransactionIdentifier;
1426 }
1427
1428 uint8_t
Lcid2Drbid(uint8_t lcid)1429 UeManager::Lcid2Drbid (uint8_t lcid)
1430 {
1431 NS_ASSERT (lcid > 2);
1432 return lcid - 2;
1433 }
1434
1435 uint8_t
Drbid2Lcid(uint8_t drbid)1436 UeManager::Drbid2Lcid (uint8_t drbid)
1437 {
1438 return drbid + 2;
1439 }
1440 uint8_t
Lcid2Bid(uint8_t lcid)1441 UeManager::Lcid2Bid (uint8_t lcid)
1442 {
1443 NS_ASSERT (lcid > 2);
1444 return lcid - 2;
1445 }
1446
1447 uint8_t
Bid2Lcid(uint8_t bid)1448 UeManager::Bid2Lcid (uint8_t bid)
1449 {
1450 return bid + 2;
1451 }
1452
1453 uint8_t
Drbid2Bid(uint8_t drbid)1454 UeManager::Drbid2Bid (uint8_t drbid)
1455 {
1456 return drbid;
1457 }
1458
1459 uint8_t
Bid2Drbid(uint8_t bid)1460 UeManager::Bid2Drbid (uint8_t bid)
1461 {
1462 return bid;
1463 }
1464
1465
1466 void
SwitchToState(State newState)1467 UeManager::SwitchToState (State newState)
1468 {
1469 NS_LOG_FUNCTION (this << ToString (newState));
1470 State oldState = m_state;
1471 m_state = newState;
1472 NS_LOG_INFO (this << " IMSI " << m_imsi << " RNTI " << m_rnti << " UeManager "
1473 << ToString (oldState) << " --> " << ToString (newState));
1474 m_stateTransitionTrace (m_imsi, m_rrc->ComponentCarrierToCellId (m_componentCarrierId), m_rnti, oldState, newState);
1475
1476 switch (newState)
1477 {
1478 case INITIAL_RANDOM_ACCESS:
1479 case HANDOVER_JOINING:
1480 NS_FATAL_ERROR ("cannot switch to an initial state");
1481 break;
1482
1483 case CONNECTION_SETUP:
1484 break;
1485
1486 case ATTACH_REQUEST:
1487 break;
1488
1489 case CONNECTED_NORMALLY:
1490 {
1491 if (m_pendingRrcConnectionReconfiguration == true)
1492 {
1493 ScheduleRrcConnectionReconfiguration ();
1494 }
1495 if (m_pendingStartDataRadioBearers == true && m_caSupportConfigured == true)
1496 {
1497 StartDataRadioBearers ();
1498 }
1499 }
1500 break;
1501
1502 case CONNECTION_RECONFIGURATION:
1503 break;
1504
1505 case CONNECTION_REESTABLISHMENT:
1506 break;
1507
1508 case HANDOVER_LEAVING:
1509 break;
1510
1511 default:
1512 break;
1513 }
1514 }
1515
1516 LteRrcSap::NonCriticalExtensionConfiguration
BuildNonCriticalExtentionConfigurationCa()1517 UeManager::BuildNonCriticalExtentionConfigurationCa ()
1518 {
1519 NS_LOG_FUNCTION ( this );
1520 LteRrcSap::NonCriticalExtensionConfiguration ncec;
1521
1522 // LteRrcSap::SCellToAddMod scell;
1523 std::list<LteRrcSap::SCellToAddMod> SccCon;
1524
1525 // sCellToReleaseList is always empty since no Scc is released
1526
1527 for (auto &it: m_rrc->m_componentCarrierPhyConf)
1528 {
1529 uint8_t ccId = it.first;
1530
1531 if (ccId == m_componentCarrierId)
1532 {
1533 // Skip primary CC.
1534 continue;
1535 }
1536 else if (ccId < m_componentCarrierId)
1537 {
1538 // Shift all IDs below PCC forward so PCC can use CC ID 1.
1539 ccId++;
1540 }
1541
1542 Ptr<ComponentCarrierBaseStation> eNbCcm = it.second;
1543 LteRrcSap::SCellToAddMod component;
1544 component.sCellIndex = ccId;
1545 component.cellIdentification.physCellId = eNbCcm->GetCellId ();
1546 component.cellIdentification.dlCarrierFreq = eNbCcm->GetDlEarfcn ();
1547 component.radioResourceConfigCommonSCell.haveNonUlConfiguration = true;
1548 component.radioResourceConfigCommonSCell.nonUlConfiguration.dlBandwidth = eNbCcm->GetDlBandwidth ();
1549 component.radioResourceConfigCommonSCell.nonUlConfiguration.antennaInfoCommon.antennaPortsCount = 0;
1550 component.radioResourceConfigCommonSCell.nonUlConfiguration.pdschConfigCommon.referenceSignalPower = m_rrc->m_cphySapProvider.at (0)->GetReferenceSignalPower ();
1551 component.radioResourceConfigCommonSCell.nonUlConfiguration.pdschConfigCommon.pb = 0;
1552 component.radioResourceConfigCommonSCell.haveUlConfiguration = true;
1553 component.radioResourceConfigCommonSCell.ulConfiguration.ulFreqInfo.ulCarrierFreq = eNbCcm->GetUlEarfcn ();
1554 component.radioResourceConfigCommonSCell.ulConfiguration.ulFreqInfo.ulBandwidth = eNbCcm->GetUlBandwidth ();
1555 component.radioResourceConfigCommonSCell.ulConfiguration.ulPowerControlCommonSCell.alpha = 0;
1556 //component.radioResourceConfigCommonSCell.ulConfiguration.soundingRsUlConfigCommon.type = LteRrcSap::SoundingRsUlConfigDedicated::SETUP;
1557 component.radioResourceConfigCommonSCell.ulConfiguration.soundingRsUlConfigCommon.srsBandwidthConfig = 0;
1558 component.radioResourceConfigCommonSCell.ulConfiguration.soundingRsUlConfigCommon.srsSubframeConfig = 0;
1559 component.radioResourceConfigCommonSCell.ulConfiguration.prachConfigSCell.index = 0;
1560
1561 if (true)
1562 {
1563 component.haveRadioResourceConfigDedicatedSCell = true;
1564 component.radioResourceConfigDedicateSCell.physicalConfigDedicatedSCell.haveNonUlConfiguration = true;
1565 component.radioResourceConfigDedicateSCell.physicalConfigDedicatedSCell.haveAntennaInfoDedicated = true;
1566 component.radioResourceConfigDedicateSCell.physicalConfigDedicatedSCell.antennaInfo.transmissionMode = m_rrc->m_defaultTransmissionMode;
1567 component.radioResourceConfigDedicateSCell.physicalConfigDedicatedSCell.crossCarrierSchedulingConfig = false;
1568 component.radioResourceConfigDedicateSCell.physicalConfigDedicatedSCell.havePdschConfigDedicated = true;
1569 component.radioResourceConfigDedicateSCell.physicalConfigDedicatedSCell.pdschConfigDedicated.pa = LteRrcSap::PdschConfigDedicated::dB0;
1570 component.radioResourceConfigDedicateSCell.physicalConfigDedicatedSCell.haveUlConfiguration = true;
1571 component.radioResourceConfigDedicateSCell.physicalConfigDedicatedSCell.haveAntennaInfoUlDedicated = true;
1572 component.radioResourceConfigDedicateSCell.physicalConfigDedicatedSCell.antennaInfoUl.transmissionMode = m_rrc->m_defaultTransmissionMode;
1573 component.radioResourceConfigDedicateSCell.physicalConfigDedicatedSCell.pushConfigDedicatedSCell.nPuschIdentity = 0;
1574 component.radioResourceConfigDedicateSCell.physicalConfigDedicatedSCell.ulPowerControlDedicatedSCell.pSrsOffset = 0;
1575 component.radioResourceConfigDedicateSCell.physicalConfigDedicatedSCell.haveSoundingRsUlConfigDedicated = true;
1576 component.radioResourceConfigDedicateSCell.physicalConfigDedicatedSCell.soundingRsUlConfigDedicated.srsConfigIndex = GetSrsConfigurationIndex();
1577 component.radioResourceConfigDedicateSCell.physicalConfigDedicatedSCell.soundingRsUlConfigDedicated.type = LteRrcSap::SoundingRsUlConfigDedicated::SETUP;
1578 component.radioResourceConfigDedicateSCell.physicalConfigDedicatedSCell.soundingRsUlConfigDedicated.srsBandwidth = 0;
1579 }
1580 else
1581 {
1582 component.haveRadioResourceConfigDedicatedSCell = false;
1583 }
1584 SccCon.push_back (component);
1585 }
1586 ncec.sCellsToAddModList = SccCon;
1587
1588 return ncec;
1589 }
1590
1591
1592 ///////////////////////////////////////////
1593 // eNB RRC methods
1594 ///////////////////////////////////////////
1595
1596 NS_OBJECT_ENSURE_REGISTERED (LteEnbRrc);
1597
LteEnbRrc()1598 LteEnbRrc::LteEnbRrc ()
1599 : m_x2SapProvider (0),
1600 m_cmacSapProvider (0),
1601 m_handoverManagementSapProvider (0),
1602 m_ccmRrcSapProvider (0),
1603 m_anrSapProvider (0),
1604 m_ffrRrcSapProvider (0),
1605 m_rrcSapUser (0),
1606 m_macSapProvider (0),
1607 m_s1SapProvider (0),
1608 m_cphySapProvider (0),
1609 m_configured (false),
1610 m_lastAllocatedRnti (0),
1611 m_srsCurrentPeriodicityId (0),
1612 m_lastAllocatedConfigurationIndex (0),
1613 m_reconfigureUes (false),
1614 m_numberOfComponentCarriers (0),
1615 m_carriersConfigured (false)
1616 {
1617 NS_LOG_FUNCTION (this);
1618 m_cmacSapUser.push_back (new EnbRrcMemberLteEnbCmacSapUser (this, 0));
1619 m_handoverManagementSapUser = new MemberLteHandoverManagementSapUser<LteEnbRrc> (this);
1620 m_anrSapUser = new MemberLteAnrSapUser<LteEnbRrc> (this);
1621 m_ffrRrcSapUser.push_back (new MemberLteFfrRrcSapUser<LteEnbRrc> (this));
1622 m_rrcSapProvider = new MemberLteEnbRrcSapProvider<LteEnbRrc> (this);
1623 m_x2SapUser = new EpcX2SpecificEpcX2SapUser<LteEnbRrc> (this);
1624 m_s1SapUser = new MemberEpcEnbS1SapUser<LteEnbRrc> (this);
1625 m_cphySapUser.push_back (new MemberLteEnbCphySapUser<LteEnbRrc> (this));
1626 m_ccmRrcSapUser = new MemberLteCcmRrcSapUser <LteEnbRrc>(this);
1627 }
1628
1629 void
ConfigureCarriers(std::map<uint8_t,Ptr<ComponentCarrierBaseStation>> ccPhyConf)1630 LteEnbRrc::ConfigureCarriers (std::map<uint8_t, Ptr<ComponentCarrierBaseStation>> ccPhyConf)
1631 {
1632 NS_ASSERT_MSG (!m_carriersConfigured, "Secondary carriers can be configured only once.");
1633 m_componentCarrierPhyConf = ccPhyConf;
1634 NS_ABORT_MSG_IF (m_numberOfComponentCarriers != m_componentCarrierPhyConf.size (), " Number of component carriers "
1635 "are not equal to the number of he component carrier configuration provided");
1636
1637 for (uint8_t i = 1; i < m_numberOfComponentCarriers; i++)
1638 {
1639 m_cphySapUser.push_back (new MemberLteEnbCphySapUser<LteEnbRrc> (this));
1640 m_cmacSapUser.push_back (new EnbRrcMemberLteEnbCmacSapUser (this, i));
1641 m_ffrRrcSapUser.push_back (new MemberLteFfrRrcSapUser<LteEnbRrc> (this));
1642 }
1643 m_carriersConfigured = true;
1644 Object::DoInitialize ();
1645 }
1646
~LteEnbRrc()1647 LteEnbRrc::~LteEnbRrc ()
1648 {
1649 NS_LOG_FUNCTION (this);
1650 }
1651
1652
1653 void
DoDispose()1654 LteEnbRrc::DoDispose ()
1655 {
1656 NS_LOG_FUNCTION (this);
1657 for ( uint8_t i = 0; i < m_numberOfComponentCarriers ; i++)
1658 {
1659 delete m_cphySapUser[i];
1660 delete m_cmacSapUser[i];
1661 delete m_ffrRrcSapUser[i];
1662 }
1663 //delete m_cphySapUser;
1664 m_cphySapUser.erase (m_cphySapUser.begin (),m_cphySapUser.end ());
1665 m_cphySapUser.clear ();
1666 //delete m_cmacSapUser;
1667 m_cmacSapUser.erase (m_cmacSapUser.begin (),m_cmacSapUser.end ());
1668 m_cmacSapUser.clear ();
1669 //delete m_ffrRrcSapUser;
1670 m_ffrRrcSapUser.erase (m_ffrRrcSapUser.begin (),m_ffrRrcSapUser.end ());
1671 m_ffrRrcSapUser.clear ();
1672 m_ueMap.clear ();
1673 delete m_handoverManagementSapUser;
1674 delete m_ccmRrcSapUser;
1675 delete m_anrSapUser;
1676 delete m_rrcSapProvider;
1677 delete m_x2SapUser;
1678 delete m_s1SapUser;
1679
1680 }
1681
1682 TypeId
GetTypeId(void)1683 LteEnbRrc::GetTypeId (void)
1684 {
1685 NS_LOG_FUNCTION ("LteEnbRrc::GetTypeId");
1686 static TypeId tid = TypeId ("ns3::LteEnbRrc")
1687 .SetParent<Object> ()
1688 .SetGroupName("Lte")
1689 .AddConstructor<LteEnbRrc> ()
1690 .AddAttribute ("UeMap", "List of UeManager by C-RNTI.",
1691 ObjectMapValue (),
1692 MakeObjectMapAccessor (&LteEnbRrc::m_ueMap),
1693 MakeObjectMapChecker<UeManager> ())
1694 .AddAttribute ("DefaultTransmissionMode",
1695 "The default UEs' transmission mode (0: SISO)",
1696 UintegerValue (0), // default tx-mode
1697 MakeUintegerAccessor (&LteEnbRrc::m_defaultTransmissionMode),
1698 MakeUintegerChecker<uint8_t> ())
1699 .AddAttribute ("EpsBearerToRlcMapping",
1700 "Specify which type of RLC will be used for each type of EPS bearer. ",
1701 EnumValue (RLC_SM_ALWAYS),
1702 MakeEnumAccessor (&LteEnbRrc::m_epsBearerToRlcMapping),
1703 MakeEnumChecker (RLC_SM_ALWAYS, "RlcSmAlways",
1704 RLC_UM_ALWAYS, "RlcUmAlways",
1705 RLC_AM_ALWAYS, "RlcAmAlways",
1706 PER_BASED, "PacketErrorRateBased"))
1707 .AddAttribute ("SystemInformationPeriodicity",
1708 "The interval for sending system information (Time value)",
1709 TimeValue (MilliSeconds (80)),
1710 MakeTimeAccessor (&LteEnbRrc::m_systemInformationPeriodicity),
1711 MakeTimeChecker ())
1712
1713 // SRS related attributes
1714 .AddAttribute ("SrsPeriodicity",
1715 "The SRS periodicity in milliseconds",
1716 UintegerValue (40),
1717 MakeUintegerAccessor (&LteEnbRrc::SetSrsPeriodicity,
1718 &LteEnbRrc::GetSrsPeriodicity),
1719 MakeUintegerChecker<uint32_t> ())
1720
1721 // Timeout related attributes
1722 .AddAttribute ("ConnectionRequestTimeoutDuration",
1723 "After a RA attempt, if no RRC CONNECTION REQUEST is "
1724 "received before this time, the UE context is destroyed. "
1725 "Must account for reception of RAR and transmission of "
1726 "RRC CONNECTION REQUEST over UL GRANT. The value of this"
1727 "timer should not be greater than T300 timer at UE RRC",
1728 TimeValue (MilliSeconds (15)),
1729 MakeTimeAccessor (&LteEnbRrc::m_connectionRequestTimeoutDuration),
1730 MakeTimeChecker (MilliSeconds (1), MilliSeconds (15)))
1731 .AddAttribute ("ConnectionSetupTimeoutDuration",
1732 "After accepting connection request, if no RRC CONNECTION "
1733 "SETUP COMPLETE is received before this time, the UE "
1734 "context is destroyed. Must account for the UE's reception "
1735 "of RRC CONNECTION SETUP and transmission of RRC CONNECTION "
1736 "SETUP COMPLETE.",
1737 TimeValue (MilliSeconds (150)),
1738 MakeTimeAccessor (&LteEnbRrc::m_connectionSetupTimeoutDuration),
1739 MakeTimeChecker ())
1740 .AddAttribute ("ConnectionRejectedTimeoutDuration",
1741 "Time to wait between sending a RRC CONNECTION REJECT and "
1742 "destroying the UE context",
1743 TimeValue (MilliSeconds (30)),
1744 MakeTimeAccessor (&LteEnbRrc::m_connectionRejectedTimeoutDuration),
1745 MakeTimeChecker ())
1746 .AddAttribute ("HandoverJoiningTimeoutDuration",
1747 "After accepting a handover request, if no RRC CONNECTION "
1748 "RECONFIGURATION COMPLETE is received before this time, the "
1749 "UE context is destroyed. Must account for reception of "
1750 "X2 HO REQ ACK by source eNB, transmission of the Handover "
1751 "Command, non-contention-based random access and reception "
1752 "of the RRC CONNECTION RECONFIGURATION COMPLETE message.",
1753 TimeValue (MilliSeconds (200)),
1754 MakeTimeAccessor (&LteEnbRrc::m_handoverJoiningTimeoutDuration),
1755 MakeTimeChecker ())
1756 .AddAttribute ("HandoverLeavingTimeoutDuration",
1757 "After issuing a Handover Command, if neither RRC "
1758 "CONNECTION RE-ESTABLISHMENT nor X2 UE Context Release has "
1759 "been previously received, the UE context is destroyed.",
1760 TimeValue (MilliSeconds (500)),
1761 MakeTimeAccessor (&LteEnbRrc::m_handoverLeavingTimeoutDuration),
1762 MakeTimeChecker ())
1763
1764 // Cell selection related attribute
1765 .AddAttribute ("QRxLevMin",
1766 "One of information transmitted within the SIB1 message, "
1767 "indicating the required minimum RSRP level that any UE must "
1768 "receive from this cell before it is allowed to camp to this "
1769 "cell. The default value -70 corresponds to -140 dBm and is "
1770 "the lowest possible value as defined by Section 6.3.4 of "
1771 "3GPP TS 36.133. This restriction, however, only applies to "
1772 "initial cell selection and EPC-enabled simulation.",
1773 TypeId::ATTR_GET | TypeId::ATTR_CONSTRUCT,
1774 IntegerValue (-70),
1775 MakeIntegerAccessor (&LteEnbRrc::m_qRxLevMin),
1776 MakeIntegerChecker<int8_t> (-70, -22))
1777 .AddAttribute ("NumberOfComponentCarriers",
1778 "Number of Component Carriers ",
1779 UintegerValue (1),
1780 MakeIntegerAccessor (&LteEnbRrc::m_numberOfComponentCarriers),
1781 MakeIntegerChecker<int16_t> (MIN_NO_CC, MAX_NO_CC))
1782
1783 // Handover related attributes
1784 .AddAttribute ("AdmitHandoverRequest",
1785 "Whether to admit an X2 handover request from another eNB",
1786 BooleanValue (true),
1787 MakeBooleanAccessor (&LteEnbRrc::m_admitHandoverRequest),
1788 MakeBooleanChecker ())
1789 .AddAttribute ("AdmitRrcConnectionRequest",
1790 "Whether to admit a connection request from a UE",
1791 BooleanValue (true),
1792 MakeBooleanAccessor (&LteEnbRrc::m_admitRrcConnectionRequest),
1793 MakeBooleanChecker ())
1794
1795 // UE measurements related attributes
1796 .AddAttribute ("RsrpFilterCoefficient",
1797 "Determines the strength of smoothing effect induced by "
1798 "layer 3 filtering of RSRP in all attached UE; "
1799 "if set to 0, no layer 3 filtering is applicable",
1800 // i.e. the variable k in 3GPP TS 36.331 section 5.5.3.2
1801 UintegerValue (4),
1802 MakeUintegerAccessor (&LteEnbRrc::m_rsrpFilterCoefficient),
1803 MakeUintegerChecker<uint8_t> (0))
1804 .AddAttribute ("RsrqFilterCoefficient",
1805 "Determines the strength of smoothing effect induced by "
1806 "layer 3 filtering of RSRQ in all attached UE; "
1807 "if set to 0, no layer 3 filtering is applicable",
1808 // i.e. the variable k in 3GPP TS 36.331 section 5.5.3.2
1809 UintegerValue (4),
1810 MakeUintegerAccessor (&LteEnbRrc::m_rsrqFilterCoefficient),
1811 MakeUintegerChecker<uint8_t> (0))
1812
1813 // Trace sources
1814 .AddTraceSource ("NewUeContext",
1815 "Fired upon creation of a new UE context.",
1816 MakeTraceSourceAccessor (&LteEnbRrc::m_newUeContextTrace),
1817 "ns3::LteEnbRrc::NewUeContextTracedCallback")
1818 .AddTraceSource ("ConnectionEstablished",
1819 "Fired upon successful RRC connection establishment.",
1820 MakeTraceSourceAccessor (&LteEnbRrc::m_connectionEstablishedTrace),
1821 "ns3::LteEnbRrc::ConnectionHandoverTracedCallback")
1822 .AddTraceSource ("ConnectionReconfiguration",
1823 "trace fired upon RRC connection reconfiguration",
1824 MakeTraceSourceAccessor (&LteEnbRrc::m_connectionReconfigurationTrace),
1825 "ns3::LteEnbRrc::ConnectionHandoverTracedCallback")
1826 .AddTraceSource ("HandoverStart",
1827 "trace fired upon start of a handover procedure",
1828 MakeTraceSourceAccessor (&LteEnbRrc::m_handoverStartTrace),
1829 "ns3::LteEnbRrc::HandoverStartTracedCallback")
1830 .AddTraceSource ("HandoverEndOk",
1831 "trace fired upon successful termination of a handover procedure",
1832 MakeTraceSourceAccessor (&LteEnbRrc::m_handoverEndOkTrace),
1833 "ns3::LteEnbRrc::ConnectionHandoverTracedCallback")
1834 .AddTraceSource ("RecvMeasurementReport",
1835 "trace fired when measurement report is received",
1836 MakeTraceSourceAccessor (&LteEnbRrc::m_recvMeasurementReportTrace),
1837 "ns3::LteEnbRrc::ReceiveReportTracedCallback")
1838 .AddTraceSource ("NotifyConnectionRelease",
1839 "trace fired when an UE is released",
1840 MakeTraceSourceAccessor (&LteEnbRrc::m_connectionReleaseTrace),
1841 "ns3::LteEnbRrc::ConnectionHandoverTracedCallback")
1842 .AddTraceSource ("RrcTimeout",
1843 "trace fired when a timer expires",
1844 MakeTraceSourceAccessor (&LteEnbRrc::m_rrcTimeoutTrace),
1845 "ns3::LteEnbRrc::TimerExpiryTracedCallback")
1846 ;
1847 return tid;
1848 }
1849
1850 void
SetEpcX2SapProvider(EpcX2SapProvider * s)1851 LteEnbRrc::SetEpcX2SapProvider (EpcX2SapProvider * s)
1852 {
1853 NS_LOG_FUNCTION (this << s);
1854 m_x2SapProvider = s;
1855 }
1856
1857 EpcX2SapUser*
GetEpcX2SapUser()1858 LteEnbRrc::GetEpcX2SapUser ()
1859 {
1860 NS_LOG_FUNCTION (this);
1861 return m_x2SapUser;
1862 }
1863
1864 void
SetLteEnbCmacSapProvider(LteEnbCmacSapProvider * s)1865 LteEnbRrc::SetLteEnbCmacSapProvider (LteEnbCmacSapProvider * s)
1866 {
1867 NS_LOG_FUNCTION (this << s);
1868 m_cmacSapProvider.at (0) = s;
1869 }
1870
1871 void
SetLteEnbCmacSapProvider(LteEnbCmacSapProvider * s,uint8_t pos)1872 LteEnbRrc::SetLteEnbCmacSapProvider (LteEnbCmacSapProvider * s, uint8_t pos)
1873 {
1874 NS_LOG_FUNCTION (this << s);
1875 if (m_cmacSapProvider.size () > pos)
1876 {
1877 m_cmacSapProvider.at (pos) = s;
1878 }
1879 else
1880 {
1881 m_cmacSapProvider.push_back (s);
1882 NS_ABORT_IF (m_cmacSapProvider.size () - 1 != pos);
1883 }
1884 }
1885
1886 LteEnbCmacSapUser*
GetLteEnbCmacSapUser()1887 LteEnbRrc::GetLteEnbCmacSapUser ()
1888 {
1889 NS_LOG_FUNCTION (this);
1890 return m_cmacSapUser.at (0);
1891 }
1892
1893 LteEnbCmacSapUser*
GetLteEnbCmacSapUser(uint8_t pos)1894 LteEnbRrc::GetLteEnbCmacSapUser (uint8_t pos)
1895 {
1896 NS_LOG_FUNCTION (this);
1897 return m_cmacSapUser.at (pos);
1898 }
1899
1900 void
SetLteHandoverManagementSapProvider(LteHandoverManagementSapProvider * s)1901 LteEnbRrc::SetLteHandoverManagementSapProvider (LteHandoverManagementSapProvider * s)
1902 {
1903 NS_LOG_FUNCTION (this << s);
1904 m_handoverManagementSapProvider = s;
1905 }
1906
1907 LteHandoverManagementSapUser*
GetLteHandoverManagementSapUser()1908 LteEnbRrc::GetLteHandoverManagementSapUser ()
1909 {
1910 NS_LOG_FUNCTION (this);
1911 return m_handoverManagementSapUser;
1912 }
1913
1914 void
SetLteCcmRrcSapProvider(LteCcmRrcSapProvider * s)1915 LteEnbRrc::SetLteCcmRrcSapProvider (LteCcmRrcSapProvider * s)
1916 {
1917 NS_LOG_FUNCTION (this << s);
1918 m_ccmRrcSapProvider = s;
1919 }
1920
1921 LteCcmRrcSapUser*
GetLteCcmRrcSapUser()1922 LteEnbRrc::GetLteCcmRrcSapUser ()
1923 {
1924 NS_LOG_FUNCTION (this);
1925 return m_ccmRrcSapUser;
1926 }
1927
1928 void
SetLteAnrSapProvider(LteAnrSapProvider * s)1929 LteEnbRrc::SetLteAnrSapProvider (LteAnrSapProvider * s)
1930 {
1931 NS_LOG_FUNCTION (this << s);
1932 m_anrSapProvider = s;
1933 }
1934
1935 LteAnrSapUser*
GetLteAnrSapUser()1936 LteEnbRrc::GetLteAnrSapUser ()
1937 {
1938 NS_LOG_FUNCTION (this);
1939 return m_anrSapUser;
1940 }
1941
1942 void
SetLteFfrRrcSapProvider(LteFfrRrcSapProvider * s)1943 LteEnbRrc::SetLteFfrRrcSapProvider (LteFfrRrcSapProvider * s)
1944 {
1945 NS_LOG_FUNCTION (this << s);
1946 if (m_ffrRrcSapProvider.size () > 0)
1947 {
1948 m_ffrRrcSapProvider.at (0) = s;
1949 }
1950 else
1951 {
1952 m_ffrRrcSapProvider.push_back (s);
1953 }
1954
1955 }
1956
1957 void
SetLteFfrRrcSapProvider(LteFfrRrcSapProvider * s,uint8_t index)1958 LteEnbRrc::SetLteFfrRrcSapProvider (LteFfrRrcSapProvider * s, uint8_t index)
1959 {
1960 NS_LOG_FUNCTION (this << s);
1961 if (m_ffrRrcSapProvider.size () > index)
1962 {
1963 m_ffrRrcSapProvider.at (index) = s;
1964 }
1965 else
1966 {
1967 m_ffrRrcSapProvider.push_back (s);
1968 NS_ABORT_MSG_IF (m_ffrRrcSapProvider.size () - 1 != index,
1969 "You meant to store the pointer at position " <<
1970 static_cast<uint32_t> (index) <<
1971 " but it went to " << m_ffrRrcSapProvider.size () - 1);
1972 }
1973 }
1974
1975 LteFfrRrcSapUser*
GetLteFfrRrcSapUser()1976 LteEnbRrc::GetLteFfrRrcSapUser ()
1977 {
1978 NS_LOG_FUNCTION (this);
1979 return m_ffrRrcSapUser.at (0);
1980 }
1981
1982 LteFfrRrcSapUser*
GetLteFfrRrcSapUser(uint8_t index)1983 LteEnbRrc::GetLteFfrRrcSapUser (uint8_t index)
1984 {
1985 NS_LOG_FUNCTION (this);
1986 NS_ASSERT_MSG (index < m_numberOfComponentCarriers, "Invalid component carrier index:"<<index<<" provided in order to obtain FfrRrcSapUser.");
1987 return m_ffrRrcSapUser.at (index);
1988 }
1989
1990 void
SetLteEnbRrcSapUser(LteEnbRrcSapUser * s)1991 LteEnbRrc::SetLteEnbRrcSapUser (LteEnbRrcSapUser * s)
1992 {
1993 NS_LOG_FUNCTION (this << s);
1994 m_rrcSapUser = s;
1995 }
1996
1997 LteEnbRrcSapProvider*
GetLteEnbRrcSapProvider()1998 LteEnbRrc::GetLteEnbRrcSapProvider ()
1999 {
2000 NS_LOG_FUNCTION (this);
2001 return m_rrcSapProvider;
2002 }
2003
2004 void
SetLteMacSapProvider(LteMacSapProvider * s)2005 LteEnbRrc::SetLteMacSapProvider (LteMacSapProvider * s)
2006 {
2007 NS_LOG_FUNCTION (this);
2008 m_macSapProvider = s;
2009 }
2010
2011 void
SetS1SapProvider(EpcEnbS1SapProvider * s)2012 LteEnbRrc::SetS1SapProvider (EpcEnbS1SapProvider * s)
2013 {
2014 m_s1SapProvider = s;
2015 }
2016
2017
2018 EpcEnbS1SapUser*
GetS1SapUser()2019 LteEnbRrc::GetS1SapUser ()
2020 {
2021 return m_s1SapUser;
2022 }
2023
2024 void
SetLteEnbCphySapProvider(LteEnbCphySapProvider * s)2025 LteEnbRrc::SetLteEnbCphySapProvider (LteEnbCphySapProvider * s)
2026 {
2027 NS_LOG_FUNCTION (this << s);
2028 if (m_cphySapProvider.size () > 0)
2029 {
2030 m_cphySapProvider.at (0) = s;
2031 }
2032 else
2033 {
2034 m_cphySapProvider.push_back (s);
2035 }
2036 }
2037
2038 LteEnbCphySapUser*
GetLteEnbCphySapUser()2039 LteEnbRrc::GetLteEnbCphySapUser ()
2040 {
2041 NS_LOG_FUNCTION (this);
2042 return m_cphySapUser.at(0);
2043 }
2044
2045 void
SetLteEnbCphySapProvider(LteEnbCphySapProvider * s,uint8_t pos)2046 LteEnbRrc::SetLteEnbCphySapProvider (LteEnbCphySapProvider * s, uint8_t pos)
2047 {
2048 NS_LOG_FUNCTION (this << s);
2049 if (m_cphySapProvider.size () > pos)
2050 {
2051 m_cphySapProvider.at(pos) = s;
2052 }
2053 else
2054 {
2055 m_cphySapProvider.push_back (s);
2056 NS_ABORT_IF (m_cphySapProvider.size () - 1 != pos);
2057 }
2058 }
2059
2060 LteEnbCphySapUser*
GetLteEnbCphySapUser(uint8_t pos)2061 LteEnbRrc::GetLteEnbCphySapUser (uint8_t pos)
2062 {
2063 NS_LOG_FUNCTION (this);
2064 return m_cphySapUser.at(pos);
2065 }
2066
2067 bool
HasUeManager(uint16_t rnti) const2068 LteEnbRrc::HasUeManager (uint16_t rnti) const
2069 {
2070 NS_LOG_FUNCTION (this << (uint32_t) rnti);
2071 std::map<uint16_t, Ptr<UeManager> >::const_iterator it = m_ueMap.find (rnti);
2072 return (it != m_ueMap.end ());
2073 }
2074
2075 Ptr<UeManager>
GetUeManager(uint16_t rnti)2076 LteEnbRrc::GetUeManager (uint16_t rnti)
2077 {
2078 NS_LOG_FUNCTION (this << (uint32_t) rnti);
2079 NS_ASSERT (0 != rnti);
2080 std::map<uint16_t, Ptr<UeManager> >::iterator it = m_ueMap.find (rnti);
2081 NS_ASSERT_MSG (it != m_ueMap.end (), "UE manager for RNTI " << rnti << " not found");
2082 return it->second;
2083 }
2084
2085 uint8_t
AddUeMeasReportConfig(LteRrcSap::ReportConfigEutra config)2086 LteEnbRrc::AddUeMeasReportConfig (LteRrcSap::ReportConfigEutra config)
2087 {
2088 NS_LOG_FUNCTION (this);
2089
2090 // SANITY CHECK
2091
2092 NS_ASSERT_MSG (m_ueMeasConfig.measIdToAddModList.size () == m_ueMeasConfig.reportConfigToAddModList.size (),
2093 "Measurement identities and reporting configuration should not have different quantity");
2094
2095 if (Simulator::Now () != Seconds (0))
2096 {
2097 NS_FATAL_ERROR ("AddUeMeasReportConfig may not be called after the simulation has run");
2098 }
2099
2100 // INPUT VALIDATION
2101
2102 switch (config.triggerQuantity)
2103 {
2104 case LteRrcSap::ReportConfigEutra::RSRP:
2105 if ((config.eventId == LteRrcSap::ReportConfigEutra::EVENT_A5)
2106 && (config.threshold2.choice != LteRrcSap::ThresholdEutra::THRESHOLD_RSRP))
2107 {
2108 NS_FATAL_ERROR ("The given triggerQuantity (RSRP) does not match with the given threshold2.choice");
2109 }
2110
2111 if (((config.eventId == LteRrcSap::ReportConfigEutra::EVENT_A1)
2112 || (config.eventId == LteRrcSap::ReportConfigEutra::EVENT_A2)
2113 || (config.eventId == LteRrcSap::ReportConfigEutra::EVENT_A4)
2114 || (config.eventId == LteRrcSap::ReportConfigEutra::EVENT_A5))
2115 && (config.threshold1.choice != LteRrcSap::ThresholdEutra::THRESHOLD_RSRP))
2116 {
2117 NS_FATAL_ERROR ("The given triggerQuantity (RSRP) does not match with the given threshold1.choice");
2118 }
2119 break;
2120
2121 case LteRrcSap::ReportConfigEutra::RSRQ:
2122 if ((config.eventId == LteRrcSap::ReportConfigEutra::EVENT_A5)
2123 && (config.threshold2.choice != LteRrcSap::ThresholdEutra::THRESHOLD_RSRQ))
2124 {
2125 NS_FATAL_ERROR ("The given triggerQuantity (RSRQ) does not match with the given threshold2.choice");
2126 }
2127
2128 if (((config.eventId == LteRrcSap::ReportConfigEutra::EVENT_A1)
2129 || (config.eventId == LteRrcSap::ReportConfigEutra::EVENT_A2)
2130 || (config.eventId == LteRrcSap::ReportConfigEutra::EVENT_A4)
2131 || (config.eventId == LteRrcSap::ReportConfigEutra::EVENT_A5))
2132 && (config.threshold1.choice != LteRrcSap::ThresholdEutra::THRESHOLD_RSRQ))
2133 {
2134 NS_FATAL_ERROR ("The given triggerQuantity (RSRQ) does not match with the given threshold1.choice");
2135 }
2136 break;
2137
2138 default:
2139 NS_FATAL_ERROR ("unsupported triggerQuantity");
2140 break;
2141 }
2142
2143 if (config.purpose != LteRrcSap::ReportConfigEutra::REPORT_STRONGEST_CELLS)
2144 {
2145 NS_FATAL_ERROR ("Only REPORT_STRONGEST_CELLS purpose is supported");
2146 }
2147
2148 if (config.reportQuantity != LteRrcSap::ReportConfigEutra::BOTH)
2149 {
2150 NS_LOG_WARN ("reportQuantity = BOTH will be used instead of the given reportQuantity");
2151 }
2152
2153 uint8_t nextId = m_ueMeasConfig.reportConfigToAddModList.size () + 1;
2154
2155 // create the reporting configuration
2156 LteRrcSap::ReportConfigToAddMod reportConfig;
2157 reportConfig.reportConfigId = nextId;
2158 reportConfig.reportConfigEutra = config;
2159
2160 // create the measurement identity
2161 LteRrcSap::MeasIdToAddMod measId;
2162 measId.measId = nextId;
2163 measId.measObjectId = 1;
2164 measId.reportConfigId = nextId;
2165
2166 // add both to the list of UE measurement configuration
2167 m_ueMeasConfig.reportConfigToAddModList.push_back (reportConfig);
2168 m_ueMeasConfig.measIdToAddModList.push_back (measId);
2169
2170 return nextId;
2171 }
2172
2173 void
ConfigureCell(std::map<uint8_t,Ptr<ComponentCarrierBaseStation>> ccPhyConf)2174 LteEnbRrc::ConfigureCell (std::map<uint8_t, Ptr<ComponentCarrierBaseStation>> ccPhyConf)
2175 {
2176 auto it = ccPhyConf.begin ();
2177 NS_ASSERT (it != ccPhyConf.end ());
2178 uint16_t ulBandwidth = it->second->GetUlBandwidth ();
2179 uint16_t dlBandwidth = it->second->GetDlBandwidth ();
2180 uint32_t ulEarfcn = it->second->GetUlEarfcn ();
2181 uint32_t dlEarfcn = it->second->GetDlEarfcn ();
2182 NS_LOG_FUNCTION (this << ulBandwidth << dlBandwidth
2183 << ulEarfcn << dlEarfcn);
2184 NS_ASSERT (!m_configured);
2185
2186 for (const auto &it: ccPhyConf)
2187 {
2188 m_cphySapProvider.at (it.first)->SetBandwidth (it.second->GetUlBandwidth (), it.second->GetDlBandwidth ());
2189 m_cphySapProvider.at (it.first)->SetEarfcn (it.second->GetUlEarfcn (), it.second->GetDlEarfcn ());
2190 m_cphySapProvider.at (it.first)->SetCellId (it.second->GetCellId ());
2191 m_cmacSapProvider.at (it.first)->ConfigureMac (it.second->GetUlBandwidth (), it.second->GetDlBandwidth ());
2192 if (m_ffrRrcSapProvider.size () > it.first)
2193 {
2194 m_ffrRrcSapProvider.at (it.first)->SetCellId (it.second->GetCellId ());
2195 m_ffrRrcSapProvider.at (it.first)->SetBandwidth (it.second->GetUlBandwidth (), it.second->GetDlBandwidth ());
2196 }
2197 }
2198
2199 m_dlEarfcn = dlEarfcn;
2200 m_ulEarfcn = ulEarfcn;
2201 m_dlBandwidth = dlBandwidth;
2202 m_ulBandwidth = ulBandwidth;
2203
2204 /*
2205 * Initializing the list of UE measurement configuration (m_ueMeasConfig).
2206 * Only intra-frequency measurements are supported, so only one measurement
2207 * object is created.
2208 */
2209
2210 LteRrcSap::MeasObjectToAddMod measObject;
2211 measObject.measObjectId = 1;
2212 measObject.measObjectEutra.carrierFreq = m_dlEarfcn;
2213 measObject.measObjectEutra.allowedMeasBandwidth = m_dlBandwidth;
2214 measObject.measObjectEutra.presenceAntennaPort1 = false;
2215 measObject.measObjectEutra.neighCellConfig = 0;
2216 measObject.measObjectEutra.offsetFreq = 0;
2217 measObject.measObjectEutra.haveCellForWhichToReportCGI = false;
2218
2219 m_ueMeasConfig.measObjectToAddModList.push_back (measObject);
2220 m_ueMeasConfig.haveQuantityConfig = true;
2221 m_ueMeasConfig.quantityConfig.filterCoefficientRSRP = m_rsrpFilterCoefficient;
2222 m_ueMeasConfig.quantityConfig.filterCoefficientRSRQ = m_rsrqFilterCoefficient;
2223 m_ueMeasConfig.haveMeasGapConfig = false;
2224 m_ueMeasConfig.haveSmeasure = false;
2225 m_ueMeasConfig.haveSpeedStatePars = false;
2226
2227 m_sib1.clear ();
2228 m_sib1.reserve (ccPhyConf.size ());
2229 for (const auto &it: ccPhyConf)
2230 {
2231 // Enabling MIB transmission
2232 LteRrcSap::MasterInformationBlock mib;
2233 mib.dlBandwidth = it.second->GetDlBandwidth ();
2234 mib.systemFrameNumber = 0;
2235 m_cphySapProvider.at (it.first)->SetMasterInformationBlock (mib);
2236
2237 // Enabling SIB1 transmission with default values
2238 LteRrcSap::SystemInformationBlockType1 sib1;
2239 sib1.cellAccessRelatedInfo.cellIdentity = it.second->GetCellId ();
2240 sib1.cellAccessRelatedInfo.csgIndication = false;
2241 sib1.cellAccessRelatedInfo.csgIdentity = 0;
2242 sib1.cellAccessRelatedInfo.plmnIdentityInfo.plmnIdentity = 0; // not used
2243 sib1.cellSelectionInfo.qQualMin = -34; // not used, set as minimum value
2244 sib1.cellSelectionInfo.qRxLevMin = m_qRxLevMin; // set as minimum value
2245 m_sib1.push_back (sib1);
2246 m_cphySapProvider.at (it.first)->SetSystemInformationBlockType1 (sib1);
2247 }
2248 /*
2249 * Enabling transmission of other SIB. The first time System Information is
2250 * transmitted is arbitrarily assumed to be at +0.016s, and then it will be
2251 * regularly transmitted every 80 ms by default (set the
2252 * SystemInformationPeriodicity attribute to configure this).
2253 */
2254 Simulator::Schedule (MilliSeconds (16), &LteEnbRrc::SendSystemInformation, this);
2255
2256 m_configured = true;
2257
2258 }
2259
2260
2261 void
SetCellId(uint16_t cellId)2262 LteEnbRrc::SetCellId (uint16_t cellId)
2263 {
2264 // update SIB1
2265 m_sib1.at (0).cellAccessRelatedInfo.cellIdentity = cellId;
2266 m_cphySapProvider.at (0)->SetSystemInformationBlockType1 (m_sib1.at (0));
2267 }
2268
2269 void
SetCellId(uint16_t cellId,uint8_t ccIndex)2270 LteEnbRrc::SetCellId (uint16_t cellId, uint8_t ccIndex)
2271 {
2272 // update SIB1
2273 m_sib1.at (ccIndex).cellAccessRelatedInfo.cellIdentity = cellId;
2274 m_cphySapProvider.at (ccIndex)->SetSystemInformationBlockType1 (m_sib1.at (ccIndex));
2275 }
2276
2277 uint8_t
CellToComponentCarrierId(uint16_t cellId)2278 LteEnbRrc::CellToComponentCarrierId (uint16_t cellId)
2279 {
2280 NS_LOG_FUNCTION (this << cellId);
2281 for (auto &it: m_componentCarrierPhyConf)
2282 {
2283 if (it.second->GetCellId () == cellId)
2284 {
2285 return it.first;
2286 }
2287 }
2288 NS_FATAL_ERROR ("Cell " << cellId << " not found in CC map");
2289 }
2290
2291 uint16_t
ComponentCarrierToCellId(uint8_t componentCarrierId)2292 LteEnbRrc::ComponentCarrierToCellId (uint8_t componentCarrierId)
2293 {
2294 NS_LOG_FUNCTION (this << +componentCarrierId);
2295 return m_componentCarrierPhyConf.at (componentCarrierId)->GetCellId ();
2296 }
2297
2298 bool
SendData(Ptr<Packet> packet)2299 LteEnbRrc::SendData (Ptr<Packet> packet)
2300 {
2301 NS_LOG_FUNCTION (this << packet);
2302
2303 EpsBearerTag tag;
2304 bool found = packet->RemovePacketTag (tag);
2305 NS_ASSERT_MSG (found, "no EpsBearerTag found in packet to be sent");
2306 Ptr<UeManager> ueManager = GetUeManager (tag.GetRnti ());
2307 ueManager->SendData (tag.GetBid (), packet);
2308
2309 return true;
2310 }
2311
2312 void
SetForwardUpCallback(Callback<void,Ptr<Packet>> cb)2313 LteEnbRrc::SetForwardUpCallback (Callback <void, Ptr<Packet> > cb)
2314 {
2315 m_forwardUpCallback = cb;
2316 }
2317
2318 void
ConnectionRequestTimeout(uint16_t rnti)2319 LteEnbRrc::ConnectionRequestTimeout (uint16_t rnti)
2320 {
2321 NS_LOG_FUNCTION (this << rnti);
2322 NS_ASSERT_MSG (GetUeManager (rnti)->GetState () == UeManager::INITIAL_RANDOM_ACCESS,
2323 "ConnectionRequestTimeout in unexpected state " << ToString (GetUeManager (rnti)->GetState ()));
2324 m_rrcTimeoutTrace (GetUeManager (rnti)->GetImsi (), rnti,
2325 ComponentCarrierToCellId (GetUeManager (rnti)->GetComponentCarrierId ()), "ConnectionRequestTimeout");
2326 RemoveUe (rnti);
2327 }
2328
2329 void
ConnectionSetupTimeout(uint16_t rnti)2330 LteEnbRrc::ConnectionSetupTimeout (uint16_t rnti)
2331 {
2332 NS_LOG_FUNCTION (this << rnti);
2333 NS_ASSERT_MSG (GetUeManager (rnti)->GetState () == UeManager::CONNECTION_SETUP,
2334 "ConnectionSetupTimeout in unexpected state " << ToString (GetUeManager (rnti)->GetState ()));
2335 m_rrcTimeoutTrace (GetUeManager (rnti)->GetImsi (), rnti,
2336 ComponentCarrierToCellId (GetUeManager (rnti)->GetComponentCarrierId ()), "ConnectionSetupTimeout");
2337 RemoveUe (rnti);
2338 }
2339
2340 void
ConnectionRejectedTimeout(uint16_t rnti)2341 LteEnbRrc::ConnectionRejectedTimeout (uint16_t rnti)
2342 {
2343 NS_LOG_FUNCTION (this << rnti);
2344 NS_ASSERT_MSG (GetUeManager (rnti)->GetState () == UeManager::CONNECTION_REJECTED,
2345 "ConnectionRejectedTimeout in unexpected state " << ToString (GetUeManager (rnti)->GetState ()));
2346 m_rrcTimeoutTrace (GetUeManager (rnti)->GetImsi (), rnti,
2347 ComponentCarrierToCellId (GetUeManager (rnti)->GetComponentCarrierId ()), "ConnectionRejectedTimeout");
2348 RemoveUe (rnti);
2349 }
2350
2351 void
HandoverJoiningTimeout(uint16_t rnti)2352 LteEnbRrc::HandoverJoiningTimeout (uint16_t rnti)
2353 {
2354 NS_LOG_FUNCTION (this << rnti);
2355 NS_ASSERT_MSG (GetUeManager (rnti)->GetState () == UeManager::HANDOVER_JOINING,
2356 "HandoverJoiningTimeout in unexpected state " << ToString (GetUeManager (rnti)->GetState ()));
2357 m_rrcTimeoutTrace (GetUeManager (rnti)->GetImsi (), rnti,
2358 ComponentCarrierToCellId (GetUeManager (rnti)->GetComponentCarrierId ()), "HandoverJoiningTimeout");
2359 RemoveUe (rnti);
2360 }
2361
2362 void
HandoverLeavingTimeout(uint16_t rnti)2363 LteEnbRrc::HandoverLeavingTimeout (uint16_t rnti)
2364 {
2365 NS_LOG_FUNCTION (this << rnti);
2366 NS_ASSERT_MSG (GetUeManager (rnti)->GetState () == UeManager::HANDOVER_LEAVING,
2367 "HandoverLeavingTimeout in unexpected state " << ToString (GetUeManager (rnti)->GetState ()));
2368 m_rrcTimeoutTrace (GetUeManager (rnti)->GetImsi (), rnti,
2369 ComponentCarrierToCellId (GetUeManager (rnti)->GetComponentCarrierId ()), "HandoverLeavingTimeout");
2370 RemoveUe (rnti);
2371 }
2372
2373 void
SendHandoverRequest(uint16_t rnti,uint16_t cellId)2374 LteEnbRrc::SendHandoverRequest (uint16_t rnti, uint16_t cellId)
2375 {
2376 NS_LOG_FUNCTION (this << rnti << cellId);
2377 NS_LOG_LOGIC ("Request to send HANDOVER REQUEST");
2378 NS_ASSERT (m_configured);
2379
2380 Ptr<UeManager> ueManager = GetUeManager (rnti);
2381 ueManager->PrepareHandover (cellId);
2382
2383 }
2384
2385 void
DoCompleteSetupUe(uint16_t rnti,LteEnbRrcSapProvider::CompleteSetupUeParameters params)2386 LteEnbRrc::DoCompleteSetupUe (uint16_t rnti, LteEnbRrcSapProvider::CompleteSetupUeParameters params)
2387 {
2388 NS_LOG_FUNCTION (this << rnti);
2389 GetUeManager (rnti)->CompleteSetupUe (params);
2390 }
2391
2392 void
DoRecvRrcConnectionRequest(uint16_t rnti,LteRrcSap::RrcConnectionRequest msg)2393 LteEnbRrc::DoRecvRrcConnectionRequest (uint16_t rnti, LteRrcSap::RrcConnectionRequest msg)
2394 {
2395 NS_LOG_FUNCTION (this << rnti);
2396 GetUeManager (rnti)->RecvRrcConnectionRequest (msg);
2397 }
2398
2399 void
DoRecvRrcConnectionSetupCompleted(uint16_t rnti,LteRrcSap::RrcConnectionSetupCompleted msg)2400 LteEnbRrc::DoRecvRrcConnectionSetupCompleted (uint16_t rnti, LteRrcSap::RrcConnectionSetupCompleted msg)
2401 {
2402 NS_LOG_FUNCTION (this << rnti);
2403 GetUeManager (rnti)->RecvRrcConnectionSetupCompleted (msg);
2404 }
2405
2406 void
DoRecvRrcConnectionReconfigurationCompleted(uint16_t rnti,LteRrcSap::RrcConnectionReconfigurationCompleted msg)2407 LteEnbRrc::DoRecvRrcConnectionReconfigurationCompleted (uint16_t rnti, LteRrcSap::RrcConnectionReconfigurationCompleted msg)
2408 {
2409 NS_LOG_FUNCTION (this << rnti);
2410 GetUeManager (rnti)->RecvRrcConnectionReconfigurationCompleted (msg);
2411 }
2412
2413 void
DoRecvRrcConnectionReestablishmentRequest(uint16_t rnti,LteRrcSap::RrcConnectionReestablishmentRequest msg)2414 LteEnbRrc::DoRecvRrcConnectionReestablishmentRequest (uint16_t rnti, LteRrcSap::RrcConnectionReestablishmentRequest msg)
2415 {
2416 NS_LOG_FUNCTION (this << rnti);
2417 GetUeManager (rnti)->RecvRrcConnectionReestablishmentRequest (msg);
2418 }
2419
2420 void
DoRecvRrcConnectionReestablishmentComplete(uint16_t rnti,LteRrcSap::RrcConnectionReestablishmentComplete msg)2421 LteEnbRrc::DoRecvRrcConnectionReestablishmentComplete (uint16_t rnti, LteRrcSap::RrcConnectionReestablishmentComplete msg)
2422 {
2423 NS_LOG_FUNCTION (this << rnti);
2424 GetUeManager (rnti)->RecvRrcConnectionReestablishmentComplete (msg);
2425 }
2426
2427 void
DoRecvMeasurementReport(uint16_t rnti,LteRrcSap::MeasurementReport msg)2428 LteEnbRrc::DoRecvMeasurementReport (uint16_t rnti, LteRrcSap::MeasurementReport msg)
2429 {
2430 NS_LOG_FUNCTION (this << rnti);
2431 GetUeManager (rnti)->RecvMeasurementReport (msg);
2432 }
2433
2434 void
DoInitialContextSetupRequest(EpcEnbS1SapUser::InitialContextSetupRequestParameters msg)2435 LteEnbRrc::DoInitialContextSetupRequest (EpcEnbS1SapUser::InitialContextSetupRequestParameters msg)
2436 {
2437 NS_LOG_FUNCTION (this);
2438 Ptr<UeManager> ueManager = GetUeManager (msg.rnti);
2439 ueManager->InitialContextSetupRequest ();
2440 }
2441
2442 void
DoRecvIdealUeContextRemoveRequest(uint16_t rnti)2443 LteEnbRrc::DoRecvIdealUeContextRemoveRequest (uint16_t rnti)
2444 {
2445 NS_LOG_FUNCTION (this << rnti);
2446 // TODO: remove after merge of ho_failure branch
2447 // check if the RNTI to be removed is not stale
2448 if (HasUeManager (rnti))
2449 {
2450 GetUeManager (rnti)->RecvIdealUeContextRemoveRequest (rnti);
2451 // delete the UE context at the eNB
2452 RemoveUe (rnti);
2453 }
2454 }
2455
2456 void
DoDataRadioBearerSetupRequest(EpcEnbS1SapUser::DataRadioBearerSetupRequestParameters request)2457 LteEnbRrc::DoDataRadioBearerSetupRequest (EpcEnbS1SapUser::DataRadioBearerSetupRequestParameters request)
2458 {
2459 NS_LOG_FUNCTION (this);
2460 Ptr<UeManager> ueManager = GetUeManager (request.rnti);
2461 ueManager->SetupDataRadioBearer (request.bearer, request.bearerId, request.gtpTeid, request.transportLayerAddress);
2462 }
2463
2464 void
DoPathSwitchRequestAcknowledge(EpcEnbS1SapUser::PathSwitchRequestAcknowledgeParameters params)2465 LteEnbRrc::DoPathSwitchRequestAcknowledge (EpcEnbS1SapUser::PathSwitchRequestAcknowledgeParameters params)
2466 {
2467 NS_LOG_FUNCTION (this);
2468 Ptr<UeManager> ueManager = GetUeManager (params.rnti);
2469 ueManager->SendUeContextRelease ();
2470 }
2471
2472 void
DoRecvHandoverRequest(EpcX2SapUser::HandoverRequestParams req)2473 LteEnbRrc::DoRecvHandoverRequest (EpcX2SapUser::HandoverRequestParams req)
2474 {
2475 NS_LOG_FUNCTION (this);
2476
2477 NS_LOG_LOGIC ("Recv X2 message: HANDOVER REQUEST");
2478
2479 NS_LOG_LOGIC ("oldEnbUeX2apId = " << req.oldEnbUeX2apId);
2480 NS_LOG_LOGIC ("sourceCellId = " << req.sourceCellId);
2481 NS_LOG_LOGIC ("targetCellId = " << req.targetCellId);
2482 NS_LOG_LOGIC ("mmeUeS1apId = " << req.mmeUeS1apId);
2483
2484 if (m_admitHandoverRequest == false)
2485 {
2486 NS_LOG_INFO ("rejecting handover request from cellId " << req.sourceCellId);
2487 EpcX2Sap::HandoverPreparationFailureParams res;
2488 res.oldEnbUeX2apId = req.oldEnbUeX2apId;
2489 res.sourceCellId = req.sourceCellId;
2490 res.targetCellId = req.targetCellId;
2491 res.cause = 0;
2492 res.criticalityDiagnostics = 0;
2493 m_x2SapProvider->SendHandoverPreparationFailure (res);
2494 return;
2495 }
2496
2497 uint16_t rnti = AddUe (UeManager::HANDOVER_JOINING, CellToComponentCarrierId (req.targetCellId));
2498 LteEnbCmacSapProvider::AllocateNcRaPreambleReturnValue anrcrv = m_cmacSapProvider.at (0)->AllocateNcRaPreamble (rnti);
2499 if (anrcrv.valid == false)
2500 {
2501 NS_LOG_INFO (this << " failed to allocate a preamble for non-contention based RA => cannot accept HO");
2502 RemoveUe (rnti);
2503 NS_FATAL_ERROR ("should trigger HO Preparation Failure, but it is not implemented");
2504 return;
2505 }
2506
2507 Ptr<UeManager> ueManager = GetUeManager (rnti);
2508 ueManager->SetSource (req.sourceCellId, req.oldEnbUeX2apId);
2509 ueManager->SetImsi (req.mmeUeS1apId);
2510
2511 EpcX2SapProvider::HandoverRequestAckParams ackParams;
2512 ackParams.oldEnbUeX2apId = req.oldEnbUeX2apId;
2513 ackParams.newEnbUeX2apId = rnti;
2514 ackParams.sourceCellId = req.sourceCellId;
2515 ackParams.targetCellId = req.targetCellId;
2516
2517 for (std::vector <EpcX2Sap::ErabToBeSetupItem>::iterator it = req.bearers.begin ();
2518 it != req.bearers.end ();
2519 ++it)
2520 {
2521 ueManager->SetupDataRadioBearer (it->erabLevelQosParameters, it->erabId, it->gtpTeid, it->transportLayerAddress);
2522 EpcX2Sap::ErabAdmittedItem i;
2523 i.erabId = it->erabId;
2524 ackParams.admittedBearers.push_back (i);
2525 }
2526
2527 LteRrcSap::RrcConnectionReconfiguration handoverCommand = ueManager->GetRrcConnectionReconfigurationForHandover ();
2528 handoverCommand.haveMobilityControlInfo = true;
2529 handoverCommand.mobilityControlInfo.targetPhysCellId = req.targetCellId;
2530 handoverCommand.mobilityControlInfo.haveCarrierFreq = true;
2531 handoverCommand.mobilityControlInfo.carrierFreq.dlCarrierFreq = m_dlEarfcn;
2532 handoverCommand.mobilityControlInfo.carrierFreq.ulCarrierFreq = m_ulEarfcn;
2533 handoverCommand.mobilityControlInfo.haveCarrierBandwidth = true;
2534 handoverCommand.mobilityControlInfo.carrierBandwidth.dlBandwidth = m_dlBandwidth;
2535 handoverCommand.mobilityControlInfo.carrierBandwidth.ulBandwidth = m_ulBandwidth;
2536 handoverCommand.mobilityControlInfo.newUeIdentity = rnti;
2537 handoverCommand.mobilityControlInfo.haveRachConfigDedicated = true;
2538 handoverCommand.mobilityControlInfo.rachConfigDedicated.raPreambleIndex = anrcrv.raPreambleId;
2539 handoverCommand.mobilityControlInfo.rachConfigDedicated.raPrachMaskIndex = anrcrv.raPrachMaskIndex;
2540
2541 LteEnbCmacSapProvider::RachConfig rc = m_cmacSapProvider.at (0)->GetRachConfig ();
2542 handoverCommand.mobilityControlInfo.radioResourceConfigCommon.rachConfigCommon.preambleInfo.numberOfRaPreambles = rc.numberOfRaPreambles;
2543 handoverCommand.mobilityControlInfo.radioResourceConfigCommon.rachConfigCommon.raSupervisionInfo.preambleTransMax = rc.preambleTransMax;
2544 handoverCommand.mobilityControlInfo.radioResourceConfigCommon.rachConfigCommon.raSupervisionInfo.raResponseWindowSize = rc.raResponseWindowSize;
2545 handoverCommand.mobilityControlInfo.radioResourceConfigCommon.rachConfigCommon.txFailParam.connEstFailCount = rc.connEstFailCount;
2546
2547 Ptr<Packet> encodedHandoverCommand = m_rrcSapUser->EncodeHandoverCommand (handoverCommand);
2548
2549 ackParams.rrcContext = encodedHandoverCommand;
2550
2551 NS_LOG_LOGIC ("Send X2 message: HANDOVER REQUEST ACK");
2552
2553 NS_LOG_LOGIC ("oldEnbUeX2apId = " << ackParams.oldEnbUeX2apId);
2554 NS_LOG_LOGIC ("newEnbUeX2apId = " << ackParams.newEnbUeX2apId);
2555 NS_LOG_LOGIC ("sourceCellId = " << ackParams.sourceCellId);
2556 NS_LOG_LOGIC ("targetCellId = " << ackParams.targetCellId);
2557
2558 m_x2SapProvider->SendHandoverRequestAck (ackParams);
2559 }
2560
2561 void
DoRecvHandoverRequestAck(EpcX2SapUser::HandoverRequestAckParams params)2562 LteEnbRrc::DoRecvHandoverRequestAck (EpcX2SapUser::HandoverRequestAckParams params)
2563 {
2564 NS_LOG_FUNCTION (this);
2565
2566 NS_LOG_LOGIC ("Recv X2 message: HANDOVER REQUEST ACK");
2567
2568 NS_LOG_LOGIC ("oldEnbUeX2apId = " << params.oldEnbUeX2apId);
2569 NS_LOG_LOGIC ("newEnbUeX2apId = " << params.newEnbUeX2apId);
2570 NS_LOG_LOGIC ("sourceCellId = " << params.sourceCellId);
2571 NS_LOG_LOGIC ("targetCellId = " << params.targetCellId);
2572
2573 uint16_t rnti = params.oldEnbUeX2apId;
2574 Ptr<UeManager> ueManager = GetUeManager (rnti);
2575 ueManager->RecvHandoverRequestAck (params);
2576 }
2577
2578 void
DoRecvHandoverPreparationFailure(EpcX2SapUser::HandoverPreparationFailureParams params)2579 LteEnbRrc::DoRecvHandoverPreparationFailure (EpcX2SapUser::HandoverPreparationFailureParams params)
2580 {
2581 NS_LOG_FUNCTION (this);
2582
2583 NS_LOG_LOGIC ("Recv X2 message: HANDOVER PREPARATION FAILURE");
2584
2585 NS_LOG_LOGIC ("oldEnbUeX2apId = " << params.oldEnbUeX2apId);
2586 NS_LOG_LOGIC ("sourceCellId = " << params.sourceCellId);
2587 NS_LOG_LOGIC ("targetCellId = " << params.targetCellId);
2588 NS_LOG_LOGIC ("cause = " << params.cause);
2589 NS_LOG_LOGIC ("criticalityDiagnostics = " << params.criticalityDiagnostics);
2590
2591 uint16_t rnti = params.oldEnbUeX2apId;
2592 Ptr<UeManager> ueManager = GetUeManager (rnti);
2593 ueManager->RecvHandoverPreparationFailure (params.targetCellId);
2594 }
2595
2596 void
DoRecvSnStatusTransfer(EpcX2SapUser::SnStatusTransferParams params)2597 LteEnbRrc::DoRecvSnStatusTransfer (EpcX2SapUser::SnStatusTransferParams params)
2598 {
2599 NS_LOG_FUNCTION (this);
2600
2601 NS_LOG_LOGIC ("Recv X2 message: SN STATUS TRANSFER");
2602
2603 NS_LOG_LOGIC ("oldEnbUeX2apId = " << params.oldEnbUeX2apId);
2604 NS_LOG_LOGIC ("newEnbUeX2apId = " << params.newEnbUeX2apId);
2605 NS_LOG_LOGIC ("erabsSubjectToStatusTransferList size = " << params.erabsSubjectToStatusTransferList.size ());
2606
2607 uint16_t rnti = params.newEnbUeX2apId;
2608 Ptr<UeManager> ueManager = GetUeManager (rnti);
2609 ueManager->RecvSnStatusTransfer (params);
2610 }
2611
2612 void
DoRecvUeContextRelease(EpcX2SapUser::UeContextReleaseParams params)2613 LteEnbRrc::DoRecvUeContextRelease (EpcX2SapUser::UeContextReleaseParams params)
2614 {
2615 NS_LOG_FUNCTION (this);
2616
2617 NS_LOG_LOGIC ("Recv X2 message: UE CONTEXT RELEASE");
2618
2619 NS_LOG_LOGIC ("oldEnbUeX2apId = " << params.oldEnbUeX2apId);
2620 NS_LOG_LOGIC ("newEnbUeX2apId = " << params.newEnbUeX2apId);
2621
2622 uint16_t rnti = params.oldEnbUeX2apId;
2623 GetUeManager (rnti)->RecvUeContextRelease (params);
2624 RemoveUe (rnti);
2625 }
2626
2627 void
DoRecvLoadInformation(EpcX2SapUser::LoadInformationParams params)2628 LteEnbRrc::DoRecvLoadInformation (EpcX2SapUser::LoadInformationParams params)
2629 {
2630 NS_LOG_FUNCTION (this);
2631
2632 NS_LOG_LOGIC ("Recv X2 message: LOAD INFORMATION");
2633
2634 NS_LOG_LOGIC ("Number of cellInformationItems = " << params.cellInformationList.size ());
2635
2636 NS_ABORT_IF (m_ffrRrcSapProvider.size () == 0);
2637 m_ffrRrcSapProvider.at (0)->RecvLoadInformation (params);
2638 }
2639
2640 void
DoRecvResourceStatusUpdate(EpcX2SapUser::ResourceStatusUpdateParams params)2641 LteEnbRrc::DoRecvResourceStatusUpdate (EpcX2SapUser::ResourceStatusUpdateParams params)
2642 {
2643 NS_LOG_FUNCTION (this);
2644
2645 NS_LOG_LOGIC ("Recv X2 message: RESOURCE STATUS UPDATE");
2646
2647 NS_LOG_LOGIC ("Number of cellMeasurementResultItems = " << params.cellMeasurementResultList.size ());
2648
2649 NS_ASSERT ("Processing of RESOURCE STATUS UPDATE X2 message IS NOT IMPLEMENTED");
2650 }
2651
2652 void
DoRecvUeData(EpcX2SapUser::UeDataParams params)2653 LteEnbRrc::DoRecvUeData (EpcX2SapUser::UeDataParams params)
2654 {
2655 NS_LOG_FUNCTION (this);
2656
2657 NS_LOG_LOGIC ("Recv UE DATA FORWARDING through X2 interface");
2658 NS_LOG_LOGIC ("sourceCellId = " << params.sourceCellId);
2659 NS_LOG_LOGIC ("targetCellId = " << params.targetCellId);
2660 NS_LOG_LOGIC ("gtpTeid = " << params.gtpTeid);
2661 NS_LOG_LOGIC ("ueData = " << params.ueData);
2662 NS_LOG_LOGIC ("ueData size = " << params.ueData->GetSize ());
2663
2664 std::map<uint32_t, X2uTeidInfo>::iterator
2665 teidInfoIt = m_x2uTeidInfoMap.find (params.gtpTeid);
2666 if (teidInfoIt != m_x2uTeidInfoMap.end ())
2667 {
2668 GetUeManager (teidInfoIt->second.rnti)->SendData (teidInfoIt->second.drbid, params.ueData);
2669 }
2670 else
2671 {
2672 NS_FATAL_ERROR ("X2-U data received but no X2uTeidInfo found");
2673 }
2674 }
2675
2676
2677 uint16_t
DoAllocateTemporaryCellRnti(uint8_t componentCarrierId)2678 LteEnbRrc::DoAllocateTemporaryCellRnti (uint8_t componentCarrierId)
2679 {
2680 NS_LOG_FUNCTION (this << +componentCarrierId);
2681 return AddUe (UeManager::INITIAL_RANDOM_ACCESS, componentCarrierId);
2682 }
2683
2684 void
DoRrcConfigurationUpdateInd(LteEnbCmacSapUser::UeConfig cmacParams)2685 LteEnbRrc::DoRrcConfigurationUpdateInd (LteEnbCmacSapUser::UeConfig cmacParams)
2686 {
2687 Ptr<UeManager> ueManager = GetUeManager (cmacParams.m_rnti);
2688 ueManager->CmacUeConfigUpdateInd (cmacParams);
2689 }
2690
2691 void
DoNotifyLcConfigResult(uint16_t rnti,uint8_t lcid,bool success)2692 LteEnbRrc::DoNotifyLcConfigResult (uint16_t rnti, uint8_t lcid, bool success)
2693 {
2694 NS_LOG_FUNCTION (this << (uint32_t) rnti);
2695 NS_FATAL_ERROR ("not implemented");
2696 }
2697
2698
2699 uint8_t
DoAddUeMeasReportConfigForHandover(LteRrcSap::ReportConfigEutra reportConfig)2700 LteEnbRrc::DoAddUeMeasReportConfigForHandover (LteRrcSap::ReportConfigEutra reportConfig)
2701 {
2702 NS_LOG_FUNCTION (this);
2703 uint8_t measId = AddUeMeasReportConfig (reportConfig);
2704 m_handoverMeasIds.insert (measId);
2705 return measId;
2706 }
2707
2708 uint8_t
DoAddUeMeasReportConfigForComponentCarrier(LteRrcSap::ReportConfigEutra reportConfig)2709 LteEnbRrc::DoAddUeMeasReportConfigForComponentCarrier (LteRrcSap::ReportConfigEutra reportConfig)
2710 {
2711 NS_LOG_FUNCTION (this);
2712 uint8_t measId = AddUeMeasReportConfig (reportConfig);
2713 m_componentCarrierMeasIds.insert (measId);
2714 return measId;
2715 }
2716
2717 void
DoSetNumberOfComponentCarriers(uint16_t numberOfComponentCarriers)2718 LteEnbRrc::DoSetNumberOfComponentCarriers (uint16_t numberOfComponentCarriers)
2719 {
2720 m_numberOfComponentCarriers = numberOfComponentCarriers;
2721 }
2722
2723 void
DoTriggerHandover(uint16_t rnti,uint16_t targetCellId)2724 LteEnbRrc::DoTriggerHandover (uint16_t rnti, uint16_t targetCellId)
2725 {
2726 NS_LOG_FUNCTION (this << rnti << targetCellId);
2727
2728 bool isHandoverAllowed = true;
2729
2730 Ptr<UeManager> ueManager = GetUeManager (rnti);
2731 NS_ASSERT_MSG (ueManager != 0, "Cannot find UE context with RNTI " << rnti);
2732
2733 if (m_anrSapProvider != 0)
2734 {
2735 // ensure that proper neighbour relationship exists between source and target cells
2736 bool noHo = m_anrSapProvider->GetNoHo (targetCellId);
2737 bool noX2 = m_anrSapProvider->GetNoX2 (targetCellId);
2738 NS_LOG_DEBUG (this << " cellId=" << ComponentCarrierToCellId (ueManager->GetComponentCarrierId ())
2739 << " targetCellId=" << targetCellId
2740 << " NRT.NoHo=" << noHo << " NRT.NoX2=" << noX2);
2741
2742 if (noHo || noX2)
2743 {
2744 isHandoverAllowed = false;
2745 NS_LOG_LOGIC (this << " handover to cell " << targetCellId
2746 << " is not allowed by ANR");
2747 }
2748 }
2749
2750 if (ueManager->GetState () != UeManager::CONNECTED_NORMALLY)
2751 {
2752 isHandoverAllowed = false;
2753 NS_LOG_LOGIC (this << " handover is not allowed because the UE"
2754 << " rnti=" << rnti << " is in "
2755 << ToString (ueManager->GetState ()) << " state");
2756 }
2757
2758 if (isHandoverAllowed)
2759 {
2760 // initiate handover execution
2761 ueManager->PrepareHandover (targetCellId);
2762 }
2763 }
2764
2765 uint8_t
DoAddUeMeasReportConfigForAnr(LteRrcSap::ReportConfigEutra reportConfig)2766 LteEnbRrc::DoAddUeMeasReportConfigForAnr (LteRrcSap::ReportConfigEutra reportConfig)
2767 {
2768 NS_LOG_FUNCTION (this);
2769 uint8_t measId = AddUeMeasReportConfig (reportConfig);
2770 m_anrMeasIds.insert (measId);
2771 return measId;
2772 }
2773
2774 uint8_t
DoAddUeMeasReportConfigForFfr(LteRrcSap::ReportConfigEutra reportConfig)2775 LteEnbRrc::DoAddUeMeasReportConfigForFfr (LteRrcSap::ReportConfigEutra reportConfig)
2776 {
2777 NS_LOG_FUNCTION (this);
2778 uint8_t measId = AddUeMeasReportConfig (reportConfig);
2779 m_ffrMeasIds.insert (measId);
2780 return measId;
2781 }
2782
2783 void
DoSetPdschConfigDedicated(uint16_t rnti,LteRrcSap::PdschConfigDedicated pdschConfigDedicated)2784 LteEnbRrc::DoSetPdschConfigDedicated (uint16_t rnti, LteRrcSap::PdschConfigDedicated pdschConfigDedicated)
2785 {
2786 NS_LOG_FUNCTION (this);
2787 Ptr<UeManager> ueManager = GetUeManager (rnti);
2788 ueManager->SetPdschConfigDedicated (pdschConfigDedicated);
2789 }
2790
2791 void
DoSendLoadInformation(EpcX2Sap::LoadInformationParams params)2792 LteEnbRrc::DoSendLoadInformation (EpcX2Sap::LoadInformationParams params)
2793 {
2794 NS_LOG_FUNCTION (this);
2795
2796 m_x2SapProvider->SendLoadInformation(params);
2797 }
2798
2799 uint16_t
AddUe(UeManager::State state,uint8_t componentCarrierId)2800 LteEnbRrc::AddUe (UeManager::State state, uint8_t componentCarrierId)
2801 {
2802 NS_LOG_FUNCTION (this);
2803 bool found = false;
2804 uint16_t rnti;
2805 for (rnti = m_lastAllocatedRnti + 1;
2806 (rnti != m_lastAllocatedRnti - 1) && (!found);
2807 ++rnti)
2808 {
2809 if ((rnti != 0) && (m_ueMap.find (rnti) == m_ueMap.end ()))
2810 {
2811 found = true;
2812 break;
2813 }
2814 }
2815
2816 NS_ASSERT_MSG (found, "no more RNTIs available (do you have more than 65535 UEs in a cell?)");
2817 m_lastAllocatedRnti = rnti;
2818 Ptr<UeManager> ueManager = CreateObject<UeManager> (this, rnti, state, componentCarrierId);
2819 m_ccmRrcSapProvider-> AddUe (rnti, (uint8_t)state);
2820 m_ueMap.insert (std::pair<uint16_t, Ptr<UeManager> > (rnti, ueManager));
2821 ueManager->Initialize ();
2822 const uint16_t cellId = ComponentCarrierToCellId (componentCarrierId);
2823 NS_LOG_DEBUG (this << " New UE RNTI " << rnti << " cellId " << cellId << " srs CI " << ueManager->GetSrsConfigurationIndex ());
2824 m_newUeContextTrace (cellId, rnti);
2825 return rnti;
2826 }
2827
2828 void
RemoveUe(uint16_t rnti)2829 LteEnbRrc::RemoveUe (uint16_t rnti)
2830 {
2831 NS_LOG_FUNCTION (this << (uint32_t) rnti);
2832 std::map <uint16_t, Ptr<UeManager> >::iterator it = m_ueMap.find (rnti);
2833 NS_ASSERT_MSG (it != m_ueMap.end (), "request to remove UE info with unknown rnti " << rnti);
2834 uint64_t imsi = it->second->GetImsi ();
2835 uint16_t srsCi = (*it).second->GetSrsConfigurationIndex ();
2836 //cancel pending events
2837 it->second->CancelPendingEvents ();
2838 // fire trace upon connection release
2839 m_connectionReleaseTrace (imsi, ComponentCarrierToCellId (it->second->GetComponentCarrierId ()), rnti);
2840 m_ueMap.erase (it);
2841 for (uint8_t i = 0; i < m_numberOfComponentCarriers; i++)
2842 {
2843 m_cmacSapProvider.at (i)->RemoveUe (rnti);
2844 m_cphySapProvider.at (i)->RemoveUe (rnti);
2845 }
2846 if (m_s1SapProvider != 0)
2847 {
2848 m_s1SapProvider->UeContextRelease (rnti);
2849 }
2850 m_ccmRrcSapProvider-> RemoveUe (rnti);
2851 // need to do this after UeManager has been deleted
2852 if (srsCi != 0)
2853 {
2854 RemoveSrsConfigurationIndex (srsCi);
2855 }
2856
2857 m_rrcSapUser->RemoveUe (rnti); // Remove UE context at RRC protocol
2858 }
2859
2860 TypeId
GetRlcType(EpsBearer bearer)2861 LteEnbRrc::GetRlcType (EpsBearer bearer)
2862 {
2863 switch (m_epsBearerToRlcMapping)
2864 {
2865 case RLC_SM_ALWAYS:
2866 return LteRlcSm::GetTypeId ();
2867 break;
2868
2869 case RLC_UM_ALWAYS:
2870 return LteRlcUm::GetTypeId ();
2871 break;
2872
2873 case RLC_AM_ALWAYS:
2874 return LteRlcAm::GetTypeId ();
2875 break;
2876
2877 case PER_BASED:
2878 if (bearer.GetPacketErrorLossRate () > 1.0e-5)
2879 {
2880 return LteRlcUm::GetTypeId ();
2881 }
2882 else
2883 {
2884 return LteRlcAm::GetTypeId ();
2885 }
2886 break;
2887
2888 default:
2889 return LteRlcSm::GetTypeId ();
2890 break;
2891 }
2892 }
2893
2894
2895 void
AddX2Neighbour(uint16_t cellId)2896 LteEnbRrc::AddX2Neighbour (uint16_t cellId)
2897 {
2898 NS_LOG_FUNCTION (this << cellId);
2899
2900 if (m_anrSapProvider != 0)
2901 {
2902 m_anrSapProvider->AddNeighbourRelation (cellId);
2903 }
2904 }
2905
2906 void
SetCsgId(uint32_t csgId,bool csgIndication)2907 LteEnbRrc::SetCsgId (uint32_t csgId, bool csgIndication)
2908 {
2909 NS_LOG_FUNCTION (this << csgId << csgIndication);
2910 for (uint8_t componentCarrierId = 0; componentCarrierId < m_sib1.size (); componentCarrierId++)
2911 {
2912 m_sib1.at (componentCarrierId).cellAccessRelatedInfo.csgIdentity = csgId;
2913 m_sib1.at (componentCarrierId).cellAccessRelatedInfo.csgIndication = csgIndication;
2914 m_cphySapProvider.at (componentCarrierId)->SetSystemInformationBlockType1 (m_sib1.at (componentCarrierId));
2915 }
2916 }
2917
2918 /// Number of distinct SRS periodicity plus one.
2919 static const uint8_t SRS_ENTRIES = 9;
2920 /**
2921 * Sounding Reference Symbol (SRS) periodicity (TSRS) in milliseconds. Taken
2922 * from 3GPP TS 36.213 Table 8.2-1. Index starts from 1.
2923 */
2924 static const uint16_t g_srsPeriodicity[SRS_ENTRIES] = {0, 2, 5, 10, 20, 40, 80, 160, 320};
2925 /**
2926 * The lower bound (inclusive) of the SRS configuration indices (ISRS) which
2927 * use the corresponding SRS periodicity (TSRS). Taken from 3GPP TS 36.213
2928 * Table 8.2-1. Index starts from 1.
2929 */
2930 static const uint16_t g_srsCiLow[SRS_ENTRIES] = {0, 0, 2, 7, 17, 37, 77, 157, 317};
2931 /**
2932 * The upper bound (inclusive) of the SRS configuration indices (ISRS) which
2933 * use the corresponding SRS periodicity (TSRS). Taken from 3GPP TS 36.213
2934 * Table 8.2-1. Index starts from 1.
2935 */
2936 static const uint16_t g_srsCiHigh[SRS_ENTRIES] = {0, 1, 6, 16, 36, 76, 156, 316, 636};
2937
2938 void
SetSrsPeriodicity(uint32_t p)2939 LteEnbRrc::SetSrsPeriodicity (uint32_t p)
2940 {
2941 NS_LOG_FUNCTION (this << p);
2942 for (uint32_t id = 1; id < SRS_ENTRIES; ++id)
2943 {
2944 if (g_srsPeriodicity[id] == p)
2945 {
2946 m_srsCurrentPeriodicityId = id;
2947 return;
2948 }
2949 }
2950 // no match found
2951 std::ostringstream allowedValues;
2952 for (uint32_t id = 1; id < SRS_ENTRIES; ++id)
2953 {
2954 allowedValues << g_srsPeriodicity[id] << " ";
2955 }
2956 NS_FATAL_ERROR ("illecit SRS periodicity value " << p << ". Allowed values: " << allowedValues.str ());
2957 }
2958
2959 uint32_t
GetSrsPeriodicity() const2960 LteEnbRrc::GetSrsPeriodicity () const
2961 {
2962 NS_LOG_FUNCTION (this);
2963 NS_ASSERT (m_srsCurrentPeriodicityId > 0);
2964 NS_ASSERT (m_srsCurrentPeriodicityId < SRS_ENTRIES);
2965 return g_srsPeriodicity[m_srsCurrentPeriodicityId];
2966 }
2967
2968
2969 uint16_t
GetNewSrsConfigurationIndex()2970 LteEnbRrc::GetNewSrsConfigurationIndex ()
2971 {
2972 NS_LOG_FUNCTION (this << m_ueSrsConfigurationIndexSet.size ());
2973 // SRS
2974 NS_ASSERT (m_srsCurrentPeriodicityId > 0);
2975 NS_ASSERT (m_srsCurrentPeriodicityId < SRS_ENTRIES);
2976 NS_LOG_DEBUG (this << " SRS p " << g_srsPeriodicity[m_srsCurrentPeriodicityId] << " set " << m_ueSrsConfigurationIndexSet.size ());
2977 if (m_ueSrsConfigurationIndexSet.size () >= g_srsPeriodicity[m_srsCurrentPeriodicityId])
2978 {
2979 NS_FATAL_ERROR ("too many UEs (" << m_ueSrsConfigurationIndexSet.size () + 1
2980 << ") for current SRS periodicity "
2981 << g_srsPeriodicity[m_srsCurrentPeriodicityId]
2982 << ", consider increasing the value of ns3::LteEnbRrc::SrsPeriodicity");
2983 }
2984
2985 if (m_ueSrsConfigurationIndexSet.empty ())
2986 {
2987 // first entry
2988 m_lastAllocatedConfigurationIndex = g_srsCiLow[m_srsCurrentPeriodicityId];
2989 m_ueSrsConfigurationIndexSet.insert (m_lastAllocatedConfigurationIndex);
2990 }
2991 else
2992 {
2993 // find a CI from the available ones
2994 std::set<uint16_t>::reverse_iterator rit = m_ueSrsConfigurationIndexSet.rbegin ();
2995 NS_ASSERT (rit != m_ueSrsConfigurationIndexSet.rend ());
2996 NS_LOG_DEBUG (this << " lower bound " << (*rit) << " of " << g_srsCiHigh[m_srsCurrentPeriodicityId]);
2997 if ((*rit) < g_srsCiHigh[m_srsCurrentPeriodicityId])
2998 {
2999 // got it from the upper bound
3000 m_lastAllocatedConfigurationIndex = (*rit) + 1;
3001 m_ueSrsConfigurationIndexSet.insert (m_lastAllocatedConfigurationIndex);
3002 }
3003 else
3004 {
3005 // look for released ones
3006 for (uint16_t srcCi = g_srsCiLow[m_srsCurrentPeriodicityId]; srcCi < g_srsCiHigh[m_srsCurrentPeriodicityId]; srcCi++)
3007 {
3008 std::set<uint16_t>::iterator it = m_ueSrsConfigurationIndexSet.find (srcCi);
3009 if (it == m_ueSrsConfigurationIndexSet.end ())
3010 {
3011 m_lastAllocatedConfigurationIndex = srcCi;
3012 m_ueSrsConfigurationIndexSet.insert (srcCi);
3013 break;
3014 }
3015 }
3016 }
3017 }
3018 return m_lastAllocatedConfigurationIndex;
3019
3020 }
3021
3022
3023 void
RemoveSrsConfigurationIndex(uint16_t srcCi)3024 LteEnbRrc::RemoveSrsConfigurationIndex (uint16_t srcCi)
3025 {
3026 NS_LOG_FUNCTION (this << srcCi);
3027 std::set<uint16_t>::iterator it = m_ueSrsConfigurationIndexSet.find (srcCi);
3028 NS_ASSERT_MSG (it != m_ueSrsConfigurationIndexSet.end (), "request to remove unkwown SRS CI " << srcCi);
3029 m_ueSrsConfigurationIndexSet.erase (it);
3030 }
3031
3032 uint8_t
GetLogicalChannelGroup(EpsBearer bearer)3033 LteEnbRrc::GetLogicalChannelGroup (EpsBearer bearer)
3034 {
3035 if (bearer.IsGbr ())
3036 {
3037 return 1;
3038 }
3039 else
3040 {
3041 return 2;
3042 }
3043 }
3044
3045 uint8_t
GetLogicalChannelPriority(EpsBearer bearer)3046 LteEnbRrc::GetLogicalChannelPriority (EpsBearer bearer)
3047 {
3048 return bearer.qci;
3049 }
3050
3051 void
SendSystemInformation()3052 LteEnbRrc::SendSystemInformation ()
3053 {
3054 // NS_LOG_FUNCTION (this);
3055
3056 for (auto &it: m_componentCarrierPhyConf)
3057 {
3058 uint8_t ccId = it.first;
3059
3060 LteRrcSap::SystemInformation si;
3061 si.haveSib2 = true;
3062 si.sib2.freqInfo.ulCarrierFreq = it.second->GetUlEarfcn ();
3063 si.sib2.freqInfo.ulBandwidth = it.second->GetUlBandwidth ();
3064 si.sib2.radioResourceConfigCommon.pdschConfigCommon.referenceSignalPower = m_cphySapProvider.at (ccId)->GetReferenceSignalPower ();
3065 si.sib2.radioResourceConfigCommon.pdschConfigCommon.pb = 0;
3066
3067 LteEnbCmacSapProvider::RachConfig rc = m_cmacSapProvider.at (ccId)->GetRachConfig ();
3068 LteRrcSap::RachConfigCommon rachConfigCommon;
3069 rachConfigCommon.preambleInfo.numberOfRaPreambles = rc.numberOfRaPreambles;
3070 rachConfigCommon.raSupervisionInfo.preambleTransMax = rc.preambleTransMax;
3071 rachConfigCommon.raSupervisionInfo.raResponseWindowSize = rc.raResponseWindowSize;
3072 rachConfigCommon.txFailParam.connEstFailCount = rc.connEstFailCount;
3073 si.sib2.radioResourceConfigCommon.rachConfigCommon = rachConfigCommon;
3074
3075 m_rrcSapUser->SendSystemInformation (it.second->GetCellId (), si);
3076 }
3077
3078 /*
3079 * For simplicity, we use the same periodicity for all SIBs. Note that in real
3080 * systems the periodicy of each SIBs could be different.
3081 */
3082 Simulator::Schedule (m_systemInformationPeriodicity, &LteEnbRrc::SendSystemInformation, this);
3083 }
3084
3085 bool
IsRandomAccessCompleted(uint16_t rnti)3086 LteEnbRrc::IsRandomAccessCompleted (uint16_t rnti)
3087 {
3088 NS_LOG_FUNCTION (this << (uint32_t) rnti);
3089 Ptr<UeManager> ueManager = GetUeManager (rnti);
3090 switch (ueManager->GetState ())
3091 {
3092 case UeManager::CONNECTED_NORMALLY:
3093 case UeManager::CONNECTION_RECONFIGURATION:
3094 return true;
3095 break;
3096 default:
3097 return false;
3098 break;
3099
3100 }
3101 }
3102
3103
3104 } // namespace ns3
3105
3106