-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlte-enb-rrc.cc
2513 lines (2152 loc) · 82.5 KB
/
lte-enb-rrc.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors: Nicola Baldo <nbaldo@cttc.es>
* Marco Miozzo <mmiozzo@cttc.es>
* Manuel Requena <manuel.requena@cttc.es>
*/
#include "lte-enb-rrc.h"
#include <ns3/fatal-error.h>
#include <ns3/log.h>
#include <ns3/abort.h>
#include <ns3/pointer.h>
#include <ns3/object-map.h>
#include <ns3/object-factory.h>
#include <ns3/simulator.h>
#include <ns3/lte-radio-bearer-info.h>
#include <ns3/eps-bearer-tag.h>
#include <ns3/packet.h>
#include <ns3/lte-rlc.h>
#include <ns3/lte-rlc-tm.h>
#include <ns3/lte-rlc-um.h>
#include <ns3/lte-rlc-am.h>
#include <ns3/lte-pdcp.h>
namespace ns3 {
NS_LOG_COMPONENT_DEFINE ("LteEnbRrc");
///////////////////////////////////////////
// CMAC SAP forwarder
///////////////////////////////////////////
/**
* \brief Class for forwarding CMAC SAP User functions.
*/
class EnbRrcMemberLteEnbCmacSapUser : public LteEnbCmacSapUser
{
public:
EnbRrcMemberLteEnbCmacSapUser (LteEnbRrc* rrc);
virtual uint16_t AllocateTemporaryCellRnti ();
virtual void NotifyLcConfigResult (uint16_t rnti, uint8_t lcid, bool success);
virtual void RrcConfigurationUpdateInd (UeConfig params);
private:
LteEnbRrc* m_rrc;
};
EnbRrcMemberLteEnbCmacSapUser::EnbRrcMemberLteEnbCmacSapUser (LteEnbRrc* rrc)
: m_rrc (rrc)
{
}
uint16_t
EnbRrcMemberLteEnbCmacSapUser::AllocateTemporaryCellRnti ()
{
return m_rrc->DoAllocateTemporaryCellRnti ();
}
void
EnbRrcMemberLteEnbCmacSapUser::NotifyLcConfigResult (uint16_t rnti, uint8_t lcid, bool success)
{
m_rrc->DoNotifyLcConfigResult (rnti, lcid, success);
}
void
EnbRrcMemberLteEnbCmacSapUser::RrcConfigurationUpdateInd (UeConfig params)
{
m_rrc->DoRrcConfigurationUpdateInd (params);
}
///////////////////////////////////////////
// UeManager
///////////////////////////////////////////
/// Map each of UE Manager states to its string representation.
static const std::string g_ueManagerStateName[UeManager::NUM_STATES] =
{
"INITIAL_RANDOM_ACCESS",
"CONNECTION_SETUP",
"CONNECTION_REJECTED",
"CONNECTED_NORMALLY",
"CONNECTION_RECONFIGURATION",
"CONNECTION_REESTABLISHMENT",
"HANDOVER_PREPARATION",
"HANDOVER_JOINING",
"HANDOVER_PATH_SWITCH",
"HANDOVER_LEAVING",
};
/**
* \param s The UE manager state.
* \return The string representation of the given state.
*/
static const std::string & ToString (UeManager::State s)
{
return g_ueManagerStateName[s];
}
NS_OBJECT_ENSURE_REGISTERED (UeManager);
UeManager::UeManager ()
{
NS_FATAL_ERROR ("this constructor is not espected to be used");
}
UeManager::UeManager (Ptr<LteEnbRrc> rrc, uint16_t rnti, State s)
: m_lastAllocatedDrbid (0),
m_rnti (rnti),
m_imsi (0),
m_lastRrcTransactionIdentifier (0),
m_rrc (rrc),
m_state (s),
m_pendingRrcConnectionReconfiguration (false),
m_sourceX2apId (0),
m_sourceCellId (0),
m_needPhyMacConfiguration (false)
{
NS_LOG_FUNCTION (this);
}
void
UeManager::DoInitialize ()
{
NS_LOG_FUNCTION (this);
m_drbPdcpSapUser = new LtePdcpSpecificLtePdcpSapUser<UeManager> (this);
m_physicalConfigDedicated.haveAntennaInfoDedicated = true;
m_physicalConfigDedicated.antennaInfo.transmissionMode = m_rrc->m_defaultTransmissionMode;
m_physicalConfigDedicated.haveSoundingRsUlConfigDedicated = true;
m_physicalConfigDedicated.soundingRsUlConfigDedicated.srsConfigIndex = m_rrc->GetNewSrsConfigurationIndex ();
m_physicalConfigDedicated.soundingRsUlConfigDedicated.type = LteRrcSap::SoundingRsUlConfigDedicated::SETUP;
m_physicalConfigDedicated.soundingRsUlConfigDedicated.srsBandwidth = 0;
m_physicalConfigDedicated.havePdschConfigDedicated = true;
m_physicalConfigDedicated.pdschConfigDedicated.pa = LteRrcSap::PdschConfigDedicated::dB0;
m_rrc->m_cmacSapProvider->AddUe (m_rnti);
m_rrc->m_cphySapProvider->AddUe (m_rnti);
// setup the eNB side of SRB0
{
uint8_t lcid = 0;
Ptr<LteRlc> rlc = CreateObject<LteRlcTm> ()->GetObject<LteRlc> ();
rlc->SetLteMacSapProvider (m_rrc->m_macSapProvider);
rlc->SetRnti (m_rnti);
rlc->SetLcId (lcid);
m_srb0 = CreateObject<LteSignalingRadioBearerInfo> ();
m_srb0->m_rlc = rlc;
m_srb0->m_srbIdentity = 0;
// no need to store logicalChannelConfig as SRB0 is pre-configured
LteEnbCmacSapProvider::LcInfo lcinfo;
lcinfo.rnti = m_rnti;
lcinfo.lcId = lcid;
// leave the rest of lcinfo empty as CCCH (LCID 0) is pre-configured
m_rrc->m_cmacSapProvider->AddLc (lcinfo, rlc->GetLteMacSapUser ());
}
// setup the eNB side of SRB1; the UE side will be set up upon RRC connection establishment
{
uint8_t lcid = 1;
Ptr<LteRlc> rlc = CreateObject<LteRlcAm> ()->GetObject<LteRlc> ();
rlc->SetLteMacSapProvider (m_rrc->m_macSapProvider);
rlc->SetRnti (m_rnti);
rlc->SetLcId (lcid);
Ptr<LtePdcp> pdcp = CreateObject<LtePdcp> ();
pdcp->SetRnti (m_rnti);
pdcp->SetLcId (lcid);
pdcp->SetLtePdcpSapUser (m_drbPdcpSapUser);
pdcp->SetLteRlcSapProvider (rlc->GetLteRlcSapProvider ());
rlc->SetLteRlcSapUser (pdcp->GetLteRlcSapUser ());
m_srb1 = CreateObject<LteSignalingRadioBearerInfo> ();
m_srb1->m_rlc = rlc;
m_srb1->m_pdcp = pdcp;
m_srb1->m_srbIdentity = 1;
m_srb1->m_logicalChannelConfig.priority = 0;
m_srb1->m_logicalChannelConfig.prioritizedBitRateKbps = 100;
m_srb1->m_logicalChannelConfig.bucketSizeDurationMs = 100;
m_srb1->m_logicalChannelConfig.logicalChannelGroup = 0;
LteEnbCmacSapProvider::LcInfo lcinfo;
lcinfo.rnti = m_rnti;
lcinfo.lcId = lcid;
lcinfo.lcGroup = 0; // all SRBs always mapped to LCG 0
lcinfo.qci = EpsBearer::GBR_CONV_VOICE; // not sure why the FF API requires a CQI even for SRBs...
lcinfo.isGbr = true;
lcinfo.mbrUl = 1e6;
lcinfo.mbrDl = 1e6;
lcinfo.gbrUl = 1e4;
lcinfo.gbrDl = 1e4;
m_rrc->m_cmacSapProvider->AddLc (lcinfo, rlc->GetLteMacSapUser ());
}
LteEnbRrcSapUser::SetupUeParameters ueParams;
ueParams.srb0SapProvider = m_srb0->m_rlc->GetLteRlcSapProvider ();
ueParams.srb1SapProvider = m_srb1->m_pdcp->GetLtePdcpSapProvider ();
m_rrc->m_rrcSapUser->SetupUe (m_rnti, ueParams);
// configure MAC (and scheduler)
LteEnbCmacSapProvider::UeConfig req;
req.m_rnti = m_rnti;
req.m_transmissionMode = m_physicalConfigDedicated.antennaInfo.transmissionMode;
m_rrc->m_cmacSapProvider->UeUpdateConfigurationReq (req);
// configure PHY
m_rrc->m_cphySapProvider->SetTransmissionMode (m_rnti, m_physicalConfigDedicated.antennaInfo.transmissionMode);
m_rrc->m_cphySapProvider->SetSrsConfigurationIndex (m_rnti, m_physicalConfigDedicated.soundingRsUlConfigDedicated.srsConfigIndex);
// schedule this UeManager instance to be deleted if the UE does not give any sign of life within a reasonable time
Time maxConnectionDelay;
switch (m_state)
{
case INITIAL_RANDOM_ACCESS:
m_connectionRequestTimeout = Simulator::Schedule (m_rrc->m_connectionRequestTimeoutDuration,
&LteEnbRrc::ConnectionRequestTimeout,
m_rrc, m_rnti);
break;
case HANDOVER_JOINING:
m_handoverJoiningTimeout = Simulator::Schedule (m_rrc->m_handoverJoiningTimeoutDuration,
&LteEnbRrc::HandoverJoiningTimeout,
m_rrc, m_rnti);
break;
default:
NS_FATAL_ERROR ("unexpected state " << ToString (m_state));
break;
}
}
UeManager::~UeManager (void)
{
}
void
UeManager::DoDispose ()
{
delete m_drbPdcpSapUser;
// delete eventual X2-U TEIDs
for (std::map <uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator it = m_drbMap.begin ();
it != m_drbMap.end ();
++it)
{
m_rrc->m_x2uTeidInfoMap.erase (it->second->m_gtpTeid);
}
}
TypeId UeManager::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::UeManager")
.SetParent<Object> ()
.AddConstructor<UeManager> ()
.AddAttribute ("DataRadioBearerMap", "List of UE DataRadioBearerInfo by DRBID.",
ObjectMapValue (),
MakeObjectMapAccessor (&UeManager::m_drbMap),
MakeObjectMapChecker<LteDataRadioBearerInfo> ())
.AddAttribute ("Srb0", "SignalingRadioBearerInfo for SRB0",
PointerValue (),
MakePointerAccessor (&UeManager::m_srb0),
MakePointerChecker<LteSignalingRadioBearerInfo> ())
.AddAttribute ("Srb1", "SignalingRadioBearerInfo for SRB1",
PointerValue (),
MakePointerAccessor (&UeManager::m_srb1),
MakePointerChecker<LteSignalingRadioBearerInfo> ())
.AddAttribute ("C-RNTI",
"Cell Radio Network Temporary Identifier",
TypeId::ATTR_GET, // read-only attribute
UintegerValue (0), // unused, read-only attribute
MakeUintegerAccessor (&UeManager::m_rnti),
MakeUintegerChecker<uint16_t> ())
.AddTraceSource ("StateTransition",
"fired upon every UE state transition seen by the "
"UeManager at the eNB RRC",
MakeTraceSourceAccessor (&UeManager::m_stateTransitionTrace),
"ns3::UeManager::StateTracedCallback")
;
return tid;
}
void
UeManager::SetSource (uint16_t sourceCellId, uint16_t sourceX2apId)
{
m_sourceX2apId = sourceX2apId;
m_sourceCellId = sourceCellId;
}
void
UeManager::SetImsi (uint64_t imsi)
{
m_imsi = imsi;
}
void
UeManager::SetupDataRadioBearer (EpsBearer bearer, uint8_t bearerId, uint32_t gtpTeid, Ipv4Address transportLayerAddress)
{
NS_LOG_FUNCTION (this << (uint32_t) m_rnti);
Ptr<LteDataRadioBearerInfo> drbInfo = CreateObject<LteDataRadioBearerInfo> ();
uint8_t drbid = AddDataRadioBearerInfo (drbInfo);
uint8_t lcid = Drbid2Lcid (drbid);
uint8_t bid = Drbid2Bid (drbid);
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");
drbInfo->m_epsBearerIdentity = bid;
drbInfo->m_drbIdentity = drbid;
drbInfo->m_logicalChannelIdentity = lcid;
drbInfo->m_gtpTeid = gtpTeid;
drbInfo->m_transportLayerAddress = transportLayerAddress;
if (m_state == HANDOVER_JOINING)
{
// setup TEIDs for receiving data eventually forwarded over X2-U
LteEnbRrc::X2uTeidInfo x2uTeidInfo;
x2uTeidInfo.rnti = m_rnti;
x2uTeidInfo.drbid = drbid;
std::pair<std::map<uint32_t, LteEnbRrc::X2uTeidInfo>::iterator, bool>
ret = m_rrc->m_x2uTeidInfoMap.insert (std::pair<uint32_t, LteEnbRrc::X2uTeidInfo> (gtpTeid, x2uTeidInfo));
NS_ASSERT_MSG (ret.second == true, "overwriting a pre-existing entry in m_x2uTeidInfoMap");
}
TypeId rlcTypeId = m_rrc->GetRlcType (bearer);
ObjectFactory rlcObjectFactory;
rlcObjectFactory.SetTypeId (rlcTypeId);
Ptr<LteRlc> rlc = rlcObjectFactory.Create ()->GetObject<LteRlc> ();
rlc->SetLteMacSapProvider (m_rrc->m_macSapProvider);
rlc->SetRnti (m_rnti);
drbInfo->m_rlc = rlc;
rlc->SetLcId (lcid);
// we need PDCP only for real RLC, i.e., RLC/UM or RLC/AM
// if we are using RLC/SM we don't care of anything above RLC
if (rlcTypeId != LteRlcSm::GetTypeId ())
{
Ptr<LtePdcp> pdcp = CreateObject<LtePdcp> ();
pdcp->SetRnti (m_rnti);
pdcp->SetLcId (lcid);
pdcp->SetLtePdcpSapUser (m_drbPdcpSapUser);
pdcp->SetLteRlcSapProvider (rlc->GetLteRlcSapProvider ());
rlc->SetLteRlcSapUser (pdcp->GetLteRlcSapUser ());
drbInfo->m_pdcp = pdcp;
}
LteEnbCmacSapProvider::LcInfo lcinfo;
lcinfo.rnti = m_rnti;
lcinfo.lcId = lcid;
lcinfo.lcGroup = m_rrc->GetLogicalChannelGroup (bearer);
lcinfo.qci = bearer.qci;
lcinfo.isGbr = bearer.IsGbr ();
lcinfo.mbrUl = bearer.gbrQosInfo.mbrUl;
lcinfo.mbrDl = bearer.gbrQosInfo.mbrDl;
lcinfo.gbrUl = bearer.gbrQosInfo.gbrUl;
lcinfo.gbrDl = bearer.gbrQosInfo.gbrDl;
m_rrc->m_cmacSapProvider->AddLc (lcinfo, rlc->GetLteMacSapUser ());
if (rlcTypeId == LteRlcAm::GetTypeId ())
{
drbInfo->m_rlcConfig.choice = LteRrcSap::RlcConfig::AM;
}
else
{
drbInfo->m_rlcConfig.choice = LteRrcSap::RlcConfig::UM_BI_DIRECTIONAL;
}
drbInfo->m_logicalChannelIdentity = lcid;
drbInfo->m_logicalChannelConfig.priority = m_rrc->GetLogicalChannelPriority (bearer);
drbInfo->m_logicalChannelConfig.logicalChannelGroup = m_rrc->GetLogicalChannelGroup (bearer);
if (bearer.IsGbr ())
{
drbInfo->m_logicalChannelConfig.prioritizedBitRateKbps = bearer.gbrQosInfo.gbrUl;
}
else
{
drbInfo->m_logicalChannelConfig.prioritizedBitRateKbps = 0;
}
drbInfo->m_logicalChannelConfig.bucketSizeDurationMs = 1000;
ScheduleRrcConnectionReconfiguration ();
}
void
UeManager::RecordDataRadioBearersToBeStarted ()
{
NS_LOG_FUNCTION (this << (uint32_t) m_rnti);
for (std::map <uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator it = m_drbMap.begin ();
it != m_drbMap.end ();
++it)
{
m_drbsToBeStarted.push_back (it->first);
}
}
void
UeManager::StartDataRadioBearers ()
{
NS_LOG_FUNCTION (this << (uint32_t) m_rnti);
for (std::list <uint8_t>::iterator drbIdIt = m_drbsToBeStarted.begin ();
drbIdIt != m_drbsToBeStarted.end ();
++drbIdIt)
{
std::map <uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator drbIt = m_drbMap.find (*drbIdIt);
NS_ASSERT (drbIt != m_drbMap.end ());
drbIt->second->m_rlc->Initialize ();
if (drbIt->second->m_pdcp)
{
drbIt->second->m_pdcp->Initialize ();
}
}
m_drbsToBeStarted.clear ();
}
void
UeManager::ReleaseDataRadioBearer (uint8_t drbid)
{
NS_LOG_FUNCTION (this << (uint32_t) m_rnti << (uint32_t) drbid);
uint8_t lcid = Drbid2Lcid (drbid);
std::map <uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator it = m_drbMap.find (drbid);
NS_ASSERT_MSG (it != m_drbMap.end (), "request to remove radio bearer with unknown drbid " << drbid);
// first delete eventual X2-U TEIDs
m_rrc->m_x2uTeidInfoMap.erase (it->second->m_gtpTeid);
m_drbMap.erase (it);
m_rrc->m_cmacSapProvider->ReleaseLc (m_rnti, lcid);
LteRrcSap::RadioResourceConfigDedicated rrcd;
rrcd.havePhysicalConfigDedicated = false;
rrcd.drbToReleaseList.push_back (drbid);
//populating RadioResourceConfigDedicated information element as per 3GPP TS 36.331 version 9.2.0
rrcd.havePhysicalConfigDedicated = true;
rrcd.physicalConfigDedicated = m_physicalConfigDedicated;
//populating RRCConnectionReconfiguration message as per 3GPP TS 36.331 version 9.2.0 Release 9
LteRrcSap::RrcConnectionReconfiguration msg;
msg.haveMeasConfig = false;
msg.haveMobilityControlInfo = false;
msg.radioResourceConfigDedicated = rrcd;
msg.haveRadioResourceConfigDedicated = true;
//RRC Connection Reconfiguration towards UE
m_rrc->m_rrcSapUser->SendRrcConnectionReconfiguration (m_rnti, msg);
}
void
LteEnbRrc::DoSendReleaseDataRadioBearer (uint64_t imsi, uint16_t rnti, uint8_t bearerId)
{
Ptr<UeManager> ueManager = GetUeManager (rnti);
// Bearer de-activation towards UE
ueManager->ReleaseDataRadioBearer (bearerId);
// Bearer de-activation indication towards epc-enb application
m_s1SapProvider->DoSendReleaseIndication (imsi,rnti,bearerId);
}
void
UeManager::ScheduleRrcConnectionReconfiguration ()
{
NS_LOG_FUNCTION (this);
switch (m_state)
{
case INITIAL_RANDOM_ACCESS:
case CONNECTION_SETUP:
case CONNECTION_RECONFIGURATION:
case CONNECTION_REESTABLISHMENT:
case HANDOVER_PREPARATION:
case HANDOVER_JOINING:
case HANDOVER_LEAVING:
// a previous reconfiguration still ongoing, we need to wait for it to be finished
m_pendingRrcConnectionReconfiguration = true;
break;
case CONNECTED_NORMALLY:
{
m_pendingRrcConnectionReconfiguration = false;
LteRrcSap::RrcConnectionReconfiguration msg = BuildRrcConnectionReconfiguration ();
m_rrc->m_rrcSapUser->SendRrcConnectionReconfiguration (m_rnti, msg);
RecordDataRadioBearersToBeStarted ();
SwitchToState (CONNECTION_RECONFIGURATION);
}
break;
default:
NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
break;
}
}
void
UeManager::PrepareHandover (uint16_t cellId)
{
NS_LOG_FUNCTION (this << cellId);
switch (m_state)
{
case CONNECTED_NORMALLY:
{
m_targetCellId = cellId;
EpcX2SapProvider::HandoverRequestParams params;
params.oldEnbUeX2apId = m_rnti;
params.cause = EpcX2SapProvider::HandoverDesirableForRadioReason;
params.sourceCellId = m_rrc->m_cellId;
params.targetCellId = cellId;
params.mmeUeS1apId = m_imsi;
params.ueAggregateMaxBitRateDownlink = 200 * 1000;
params.ueAggregateMaxBitRateUplink = 100 * 1000;
params.bearers = GetErabList ();
LteRrcSap::HandoverPreparationInfo hpi;
hpi.asConfig.sourceUeIdentity = m_rnti;
hpi.asConfig.sourceDlCarrierFreq = m_rrc->m_dlEarfcn;
hpi.asConfig.sourceMeasConfig = m_rrc->m_ueMeasConfig;
hpi.asConfig.sourceRadioResourceConfig = GetRadioResourceConfigForHandoverPreparationInfo ();
hpi.asConfig.sourceMasterInformationBlock.dlBandwidth = m_rrc->m_dlBandwidth;
hpi.asConfig.sourceMasterInformationBlock.systemFrameNumber = 0;
hpi.asConfig.sourceSystemInformationBlockType1.cellAccessRelatedInfo.plmnIdentityInfo.plmnIdentity = m_rrc->m_sib1.cellAccessRelatedInfo.plmnIdentityInfo.plmnIdentity;
hpi.asConfig.sourceSystemInformationBlockType1.cellAccessRelatedInfo.cellIdentity = m_rrc->m_cellId;
hpi.asConfig.sourceSystemInformationBlockType1.cellAccessRelatedInfo.csgIndication = m_rrc->m_sib1.cellAccessRelatedInfo.csgIndication;
hpi.asConfig.sourceSystemInformationBlockType1.cellAccessRelatedInfo.csgIdentity = m_rrc->m_sib1.cellAccessRelatedInfo.csgIdentity;
LteEnbCmacSapProvider::RachConfig rc = m_rrc->m_cmacSapProvider->GetRachConfig ();
hpi.asConfig.sourceSystemInformationBlockType2.radioResourceConfigCommon.rachConfigCommon.preambleInfo.numberOfRaPreambles = rc.numberOfRaPreambles;
hpi.asConfig.sourceSystemInformationBlockType2.radioResourceConfigCommon.rachConfigCommon.raSupervisionInfo.preambleTransMax = rc.preambleTransMax;
hpi.asConfig.sourceSystemInformationBlockType2.radioResourceConfigCommon.rachConfigCommon.raSupervisionInfo.raResponseWindowSize = rc.raResponseWindowSize;
hpi.asConfig.sourceSystemInformationBlockType2.freqInfo.ulCarrierFreq = m_rrc->m_ulEarfcn;
hpi.asConfig.sourceSystemInformationBlockType2.freqInfo.ulBandwidth = m_rrc->m_ulBandwidth;
params.rrcContext = m_rrc->m_rrcSapUser->EncodeHandoverPreparationInformation (hpi);
NS_LOG_LOGIC ("oldEnbUeX2apId = " << params.oldEnbUeX2apId);
NS_LOG_LOGIC ("sourceCellId = " << params.sourceCellId);
NS_LOG_LOGIC ("targetCellId = " << params.targetCellId);
NS_LOG_LOGIC ("mmeUeS1apId = " << params.mmeUeS1apId);
NS_LOG_LOGIC ("rrcContext = " << params.rrcContext);
m_rrc->m_x2SapProvider->SendHandoverRequest (params);
SwitchToState (HANDOVER_PREPARATION);
}
break;
default:
NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
break;
}
}
void
UeManager::RecvHandoverRequestAck (EpcX2SapUser::HandoverRequestAckParams params)
{
NS_LOG_FUNCTION (this);
NS_ASSERT_MSG (params.notAdmittedBearers.empty (), "not admission of some bearers upon handover is not supported");
NS_ASSERT_MSG (params.admittedBearers.size () == m_drbMap.size (), "not enough bearers in admittedBearers");
// note: the Handover command from the target eNB to the source eNB
// is expected to be sent transparently to the UE; however, here we
// decode the message and eventually reencode it. This way we can
// support both a real RRC protocol implementation and an ideal one
// without actual RRC protocol encoding.
Ptr<Packet> encodedHandoverCommand = params.rrcContext;
LteRrcSap::RrcConnectionReconfiguration handoverCommand = m_rrc->m_rrcSapUser->DecodeHandoverCommand (encodedHandoverCommand);
m_rrc->m_rrcSapUser->SendRrcConnectionReconfiguration (m_rnti, handoverCommand);
SwitchToState (HANDOVER_LEAVING);
m_handoverLeavingTimeout = Simulator::Schedule (m_rrc->m_handoverLeavingTimeoutDuration,
&LteEnbRrc::HandoverLeavingTimeout,
m_rrc, m_rnti);
NS_ASSERT (handoverCommand.haveMobilityControlInfo);
m_rrc->m_handoverStartTrace (m_imsi, m_rrc->m_cellId, m_rnti, handoverCommand.mobilityControlInfo.targetPhysCellId);
EpcX2SapProvider::SnStatusTransferParams sst;
sst.oldEnbUeX2apId = params.oldEnbUeX2apId;
sst.newEnbUeX2apId = params.newEnbUeX2apId;
sst.sourceCellId = params.sourceCellId;
sst.targetCellId = params.targetCellId;
for ( std::map <uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator drbIt = m_drbMap.begin ();
drbIt != m_drbMap.end ();
++drbIt)
{
// SN status transfer is only for AM RLC
if (0 != drbIt->second->m_rlc->GetObject<LteRlcAm> ())
{
LtePdcp::Status status = drbIt->second->m_pdcp->GetStatus ();
EpcX2Sap::ErabsSubjectToStatusTransferItem i;
i.dlPdcpSn = status.txSn;
i.ulPdcpSn = status.rxSn;
sst.erabsSubjectToStatusTransferList.push_back (i);
}
}
m_rrc->m_x2SapProvider->SendSnStatusTransfer (sst);
}
LteRrcSap::RadioResourceConfigDedicated
UeManager::GetRadioResourceConfigForHandoverPreparationInfo ()
{
NS_LOG_FUNCTION (this);
return BuildRadioResourceConfigDedicated ();
}
LteRrcSap::RrcConnectionReconfiguration
UeManager::GetRrcConnectionReconfigurationForHandover ()
{
NS_LOG_FUNCTION (this);
return BuildRrcConnectionReconfiguration ();
}
void
UeManager::SendData (uint8_t bid, Ptr<Packet> p)
{
NS_LOG_FUNCTION (this << p << (uint16_t) bid);
switch (m_state)
{
case INITIAL_RANDOM_ACCESS:
case CONNECTION_SETUP:
NS_LOG_WARN ("not connected, discarding packet");
return;
break;
case CONNECTED_NORMALLY:
case CONNECTION_RECONFIGURATION:
case CONNECTION_REESTABLISHMENT:
case HANDOVER_PREPARATION:
case HANDOVER_JOINING:
case HANDOVER_PATH_SWITCH:
{
NS_LOG_LOGIC ("queueing data on PDCP for transmission over the air");
LtePdcpSapProvider::TransmitPdcpSduParameters params;
params.pdcpSdu = p;
params.rnti = m_rnti;
params.lcid = Bid2Lcid (bid);
uint8_t drbid = Bid2Drbid (bid);
//Transmit PDCP sdu only if DRB ID found in drbMap
std::map<uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator it = m_drbMap.find (drbid);
if (it != m_drbMap.end ())
{
Ptr<LteDataRadioBearerInfo> bearerInfo = GetDataRadioBearerInfo (drbid);
if (bearerInfo != NULL)
{
LtePdcpSapProvider* pdcpSapProvider = bearerInfo->m_pdcp->GetLtePdcpSapProvider ();
pdcpSapProvider->TransmitPdcpSdu (params);
}
}
}
break;
case HANDOVER_LEAVING:
{
NS_LOG_LOGIC ("forwarding data to target eNB over X2-U");
uint8_t drbid = Bid2Drbid (bid);
EpcX2Sap::UeDataParams params;
params.sourceCellId = m_rrc->m_cellId;
params.targetCellId = m_targetCellId;
params.gtpTeid = GetDataRadioBearerInfo (drbid)->m_gtpTeid;
params.ueData = p;
m_rrc->m_x2SapProvider->SendUeData (params);
}
break;
default:
NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
break;
}
}
std::vector<EpcX2Sap::ErabToBeSetupItem>
UeManager::GetErabList ()
{
NS_LOG_FUNCTION (this);
std::vector<EpcX2Sap::ErabToBeSetupItem> ret;
for (std::map <uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator it = m_drbMap.begin ();
it != m_drbMap.end ();
++it)
{
EpcX2Sap::ErabToBeSetupItem etbsi;
etbsi.erabId = it->second->m_epsBearerIdentity;
etbsi.erabLevelQosParameters = it->second->m_epsBearer;
etbsi.dlForwarding = false;
etbsi.transportLayerAddress = it->second->m_transportLayerAddress;
etbsi.gtpTeid = it->second->m_gtpTeid;
ret.push_back (etbsi);
}
return ret;
}
void
UeManager::SendUeContextRelease ()
{
NS_LOG_FUNCTION (this);
switch (m_state)
{
case HANDOVER_PATH_SWITCH:
NS_LOG_INFO ("Send UE CONTEXT RELEASE from target eNB to source eNB");
EpcX2SapProvider::UeContextReleaseParams ueCtxReleaseParams;
ueCtxReleaseParams.oldEnbUeX2apId = m_sourceX2apId;
ueCtxReleaseParams.newEnbUeX2apId = m_rnti;
ueCtxReleaseParams.sourceCellId = m_sourceCellId;
m_rrc->m_x2SapProvider->SendUeContextRelease (ueCtxReleaseParams);
SwitchToState (CONNECTED_NORMALLY);
m_rrc->m_handoverEndOkTrace (m_imsi, m_rrc->m_cellId, m_rnti);
break;
default:
NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
break;
}
}
void
UeManager::RecvHandoverPreparationFailure (uint16_t cellId)
{
NS_LOG_FUNCTION (this << cellId);
switch (m_state)
{
case HANDOVER_PREPARATION:
NS_ASSERT (cellId == m_targetCellId);
NS_LOG_INFO ("target eNB sent HO preparation failure, aborting HO");
SwitchToState (CONNECTED_NORMALLY);
break;
default:
NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
break;
}
}
void
UeManager::RecvSnStatusTransfer (EpcX2SapUser::SnStatusTransferParams params)
{
NS_LOG_FUNCTION (this);
for (std::vector<EpcX2Sap::ErabsSubjectToStatusTransferItem>::iterator erabIt
= params.erabsSubjectToStatusTransferList.begin ();
erabIt != params.erabsSubjectToStatusTransferList.end ();
++erabIt)
{
// LtePdcp::Status status;
// status.txSn = erabIt->dlPdcpSn;
// status.rxSn = erabIt->ulPdcpSn;
// uint8_t drbId = Bid2Drbid (erabIt->erabId);
// std::map <uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator drbIt = m_drbMap.find (drbId);
// NS_ASSERT_MSG (drbIt != m_drbMap.end (), "could not find DRBID " << (uint32_t) drbId);
// drbIt->second->m_pdcp->SetStatus (status);
}
}
void
UeManager::RecvUeContextRelease (EpcX2SapUser::UeContextReleaseParams params)
{
NS_LOG_FUNCTION (this);
NS_ASSERT_MSG (m_state == HANDOVER_LEAVING, "method unexpected in state " << ToString (m_state));
m_handoverLeavingTimeout.Cancel ();
}
// methods forwarded from RRC SAP
void
UeManager::CompleteSetupUe (LteEnbRrcSapProvider::CompleteSetupUeParameters params)
{
NS_LOG_FUNCTION (this);
m_srb0->m_rlc->SetLteRlcSapUser (params.srb0SapUser);
m_srb1->m_pdcp->SetLtePdcpSapUser (params.srb1SapUser);
}
void
UeManager::RecvRrcConnectionRequest (LteRrcSap::RrcConnectionRequest msg)
{
NS_LOG_FUNCTION (this);
switch (m_state)
{
case INITIAL_RANDOM_ACCESS:
{
m_connectionRequestTimeout.Cancel ();
if (m_rrc->m_admitRrcConnectionRequest == true)
{
m_imsi = msg.ueIdentity;
if (m_rrc->m_s1SapProvider != 0)
{
m_rrc->m_s1SapProvider->InitialUeMessage (m_imsi, m_rnti);
}
// send RRC CONNECTION SETUP to UE
LteRrcSap::RrcConnectionSetup msg2;
msg2.rrcTransactionIdentifier = GetNewRrcTransactionIdentifier ();
msg2.radioResourceConfigDedicated = BuildRadioResourceConfigDedicated ();
m_rrc->m_rrcSapUser->SendRrcConnectionSetup (m_rnti, msg2);
RecordDataRadioBearersToBeStarted ();
m_connectionSetupTimeout = Simulator::Schedule (
m_rrc->m_connectionSetupTimeoutDuration,
&LteEnbRrc::ConnectionSetupTimeout, m_rrc, m_rnti);
SwitchToState (CONNECTION_SETUP);
}
else
{
NS_LOG_INFO ("rejecting connection request for RNTI " << m_rnti);
// send RRC CONNECTION REJECT to UE
LteRrcSap::RrcConnectionReject rejectMsg;
rejectMsg.waitTime = 3;
m_rrc->m_rrcSapUser->SendRrcConnectionReject (m_rnti, rejectMsg);
m_connectionRejectedTimeout = Simulator::Schedule (
m_rrc->m_connectionRejectedTimeoutDuration,
&LteEnbRrc::ConnectionRejectedTimeout, m_rrc, m_rnti);
SwitchToState (CONNECTION_REJECTED);
}
}
break;
default:
NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
break;
}
}
void
UeManager::RecvRrcConnectionSetupCompleted (LteRrcSap::RrcConnectionSetupCompleted msg)
{
NS_LOG_FUNCTION (this);
switch (m_state)
{
case CONNECTION_SETUP:
m_connectionSetupTimeout.Cancel ();
StartDataRadioBearers ();
SwitchToState (CONNECTED_NORMALLY);
m_rrc->m_connectionEstablishedTrace (m_imsi, m_rrc->m_cellId, m_rnti);
break;
default:
NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
break;
}
}
void
UeManager::RecvRrcConnectionReconfigurationCompleted (LteRrcSap::RrcConnectionReconfigurationCompleted msg)
{
NS_LOG_FUNCTION (this);
switch (m_state)
{
case CONNECTION_RECONFIGURATION:
StartDataRadioBearers ();
if (m_needPhyMacConfiguration)
{
// configure MAC (and scheduler)
LteEnbCmacSapProvider::UeConfig req;
req.m_rnti = m_rnti;
req.m_transmissionMode = m_physicalConfigDedicated.antennaInfo.transmissionMode;
m_rrc->m_cmacSapProvider->UeUpdateConfigurationReq (req);
// configure PHY
m_rrc->m_cphySapProvider->SetTransmissionMode (req.m_rnti, req.m_transmissionMode);
double paDouble = LteRrcSap::ConvertPdschConfigDedicated2Double (m_physicalConfigDedicated.pdschConfigDedicated);
m_rrc->m_cphySapProvider->SetPa (m_rnti, paDouble);
m_needPhyMacConfiguration = false;
}
SwitchToState (CONNECTED_NORMALLY);
m_rrc->m_connectionReconfigurationTrace (m_imsi, m_rrc->m_cellId, m_rnti);
break;
// This case is added to NS-3 in order to handle bearer de-activation scenario for CONNECTED state UE
case CONNECTED_NORMALLY:
NS_LOG_INFO ("ignoring RecvRrcConnectionReconfigurationCompleted in state " << ToString (m_state));
break;
case HANDOVER_LEAVING:
NS_LOG_INFO ("ignoring RecvRrcConnectionReconfigurationCompleted in state " << ToString (m_state));
break;
case HANDOVER_JOINING:
{
m_handoverJoiningTimeout.Cancel ();
NS_LOG_INFO ("Send PATH SWITCH REQUEST to the MME");
EpcEnbS1SapProvider::PathSwitchRequestParameters params;
params.rnti = m_rnti;
params.cellId = m_rrc->m_cellId;
params.mmeUeS1Id = m_imsi;
SwitchToState (HANDOVER_PATH_SWITCH);
for (std::map <uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator it = m_drbMap.begin ();
it != m_drbMap.end ();
++it)
{
EpcEnbS1SapProvider::BearerToBeSwitched b;
b.epsBearerId = it->second->m_epsBearerIdentity;
b.teid = it->second->m_gtpTeid;
params.bearersToBeSwitched.push_back (b);
}
m_rrc->m_s1SapProvider->PathSwitchRequest (params);
}
break;
default:
NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
break;
}
}
void
UeManager::RecvRrcConnectionReestablishmentRequest (LteRrcSap::RrcConnectionReestablishmentRequest msg)
{
NS_LOG_FUNCTION (this);
switch (m_state)
{
case CONNECTED_NORMALLY:
break;
case HANDOVER_LEAVING:
m_handoverLeavingTimeout.Cancel ();
break;
default:
NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
break;
}
LteRrcSap::RrcConnectionReestablishment msg2;
msg2.rrcTransactionIdentifier = GetNewRrcTransactionIdentifier ();
msg2.radioResourceConfigDedicated = BuildRadioResourceConfigDedicated ();
m_rrc->m_rrcSapUser->SendRrcConnectionReestablishment (m_rnti, msg2);
SwitchToState (CONNECTION_REESTABLISHMENT);
}
void
UeManager::RecvRrcConnectionReestablishmentComplete (LteRrcSap::RrcConnectionReestablishmentComplete msg)
{
NS_LOG_FUNCTION (this);
SwitchToState (CONNECTED_NORMALLY);
}
void
UeManager::RecvMeasurementReport (LteRrcSap::MeasurementReport msg)
{
uint8_t measId = msg.measResults.measId;
NS_LOG_FUNCTION (this << (uint16_t) measId);
NS_LOG_LOGIC ("measId " << (uint16_t) measId
<< " haveMeasResultNeighCells " << msg.measResults.haveMeasResultNeighCells
<< " measResultListEutra " << msg.measResults.measResultListEutra.size ());
NS_LOG_LOGIC ("serving cellId " << m_rrc->m_cellId
<< " RSRP " << (uint16_t) msg.measResults.rsrpResult
<< " RSRQ " << (uint16_t) msg.measResults.rsrqResult);
for (std::list <LteRrcSap::MeasResultEutra>::iterator it = msg.measResults.measResultListEutra.begin ();
it != msg.measResults.measResultListEutra.end ();
++it)
{
NS_LOG_LOGIC ("neighbour cellId " << it->physCellId
<< " RSRP " << (it->haveRsrpResult ? (uint16_t) it->rsrpResult : 255)
<< " RSRQ " << (it->haveRsrqResult ? (uint16_t) it->rsrqResult : 255));
}
if ((m_rrc->m_handoverManagementSapProvider != 0)
&& (m_rrc->m_handoverMeasIds.find (measId) != m_rrc->m_handoverMeasIds.end ()))
{
// this measurement was requested by the handover algorithm
m_rrc->m_handoverManagementSapProvider->ReportUeMeas (m_rnti,
msg.measResults);
}
if ((m_rrc->m_anrSapProvider != 0)
&& (m_rrc->m_anrMeasIds.find (measId) != m_rrc->m_anrMeasIds.end ()))
{
// this measurement was requested by the ANR function