-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlte-ue-rrc.cc
3396 lines (2969 loc) · 122 KB
/
lte-ue-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, 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
* Copyright (c) 2018 Fraunhofer ESK : RLF extensions
*
* 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
*
* Author: Nicola Baldo <[email protected]>
* Budiarto Herman <[email protected]>
* Modified by:
* Danilo Abrignani <[email protected]> (Carrier Aggregation - GSoC 2015)
* Biljana Bojovic <[email protected]> (Carrier Aggregation)
* Vignesh Babu <[email protected]> (RLF extensions)
*/
#include "lte-ue-rrc.h"
#include <ns3/fatal-error.h>
#include <ns3/log.h>
#include <ns3/object-map.h>
#include <ns3/object-factory.h>
#include <ns3/simulator.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>
#include <ns3/lte-radio-bearer-info.h>
#include "cell-individual-offset.h" // edit this out to remove CIO capabilities
#include <cmath>
namespace ns3 {
NS_LOG_COMPONENT_DEFINE ("LteUeRrc");
/////////////////////////////
// CMAC SAP forwarder
/////////////////////////////
/// UeMemberLteUeCmacSapUser class
class UeMemberLteUeCmacSapUser : public LteUeCmacSapUser
{
public:
/**
* Constructor
*
* \param rrc the RRC class
*/
UeMemberLteUeCmacSapUser (LteUeRrc* rrc);
virtual void SetTemporaryCellRnti (uint16_t rnti);
virtual void NotifyRandomAccessSuccessful ();
virtual void NotifyRandomAccessFailed ();
private:
LteUeRrc* m_rrc; ///< the RRC class
};
UeMemberLteUeCmacSapUser::UeMemberLteUeCmacSapUser (LteUeRrc* rrc)
: m_rrc (rrc)
{
}
void
UeMemberLteUeCmacSapUser::SetTemporaryCellRnti (uint16_t rnti)
{
m_rrc->DoSetTemporaryCellRnti (rnti);
}
void
UeMemberLteUeCmacSapUser::NotifyRandomAccessSuccessful ()
{
m_rrc->DoNotifyRandomAccessSuccessful ();
}
void
UeMemberLteUeCmacSapUser::NotifyRandomAccessFailed ()
{
m_rrc->DoNotifyRandomAccessFailed ();
}
/// Map each of UE RRC states to its string representation.
static const std::string g_ueRrcStateName[LteUeRrc::NUM_STATES] =
{
"IDLE_START",
"IDLE_CELL_SEARCH",
"IDLE_WAIT_MIB_SIB1",
"IDLE_WAIT_MIB",
"IDLE_WAIT_SIB1",
"IDLE_CAMPED_NORMALLY",
"IDLE_WAIT_SIB2",
"IDLE_RANDOM_ACCESS",
"IDLE_CONNECTING",
"CONNECTED_NORMALLY",
"CONNECTED_HANDOVER",
"CONNECTED_PHY_PROBLEM",
"CONNECTED_REESTABLISHING"
};
/**
* \param s The UE RRC state.
* \return The string representation of the given state.
*/
static const std::string & ToString (LteUeRrc::State s)
{
return g_ueRrcStateName[s];
}
/////////////////////////////
// ue RRC methods
/////////////////////////////
NS_OBJECT_ENSURE_REGISTERED (LteUeRrc);
LteUeRrc::LteUeRrc ()
: m_cmacSapProvider (0),
m_rrcSapUser (0),
m_macSapProvider (0),
m_asSapUser (0),
m_ccmRrcSapProvider (0),
m_state (IDLE_START),
m_imsi (0),
m_rnti (0),
m_cellId (0),
m_useRlcSm (true),
m_connectionPending (false),
m_hasReceivedMib (false),
m_hasReceivedSib1 (false),
m_hasReceivedSib2 (false),
m_csgWhiteList (0),
m_noOfSyncIndications (0),
m_leaveConnectedMode (false),
m_previousCellId (0),
m_connEstFailCountLimit (0),
m_connEstFailCount (0),
m_numberOfComponentCarriers (MIN_NO_CC)
{
NS_LOG_FUNCTION (this);
m_cphySapUser.push_back (new MemberLteUeCphySapUser<LteUeRrc> (this));
m_cmacSapUser.push_back (new UeMemberLteUeCmacSapUser (this));
m_cphySapProvider.push_back(0);
m_cmacSapProvider.push_back(0);
m_rrcSapProvider = new MemberLteUeRrcSapProvider<LteUeRrc> (this);
m_drbPdcpSapUser = new LtePdcpSpecificLtePdcpSapUser<LteUeRrc> (this);
m_asSapProvider = new MemberLteAsSapProvider<LteUeRrc> (this);
m_ccmRrcSapUser = new MemberLteUeCcmRrcSapUser<LteUeRrc> (this);
}
LteUeRrc::~LteUeRrc ()
{
NS_LOG_FUNCTION (this);
}
void
LteUeRrc::DoDispose ()
{
NS_LOG_FUNCTION (this);
for ( uint16_t i = 0; i < m_numberOfComponentCarriers; i++)
{
delete m_cphySapUser.at(i);
delete m_cmacSapUser.at(i);
}
m_cphySapUser.clear ();
m_cmacSapUser.clear ();
delete m_rrcSapProvider;
delete m_drbPdcpSapUser;
delete m_asSapProvider;
delete m_ccmRrcSapUser;
m_cphySapProvider.erase(m_cphySapProvider.begin(), m_cphySapProvider.end());
m_cphySapProvider.clear();
m_cmacSapProvider.erase(m_cmacSapProvider.begin(), m_cmacSapProvider.end());
m_cmacSapProvider.clear();
m_drbMap.clear ();
}
TypeId
LteUeRrc::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::LteUeRrc")
.SetParent<Object> ()
.SetGroupName ("Lte")
.AddConstructor<LteUeRrc> ()
.AddAttribute ("DataRadioBearerMap", "List of UE RadioBearerInfo for Data Radio Bearers by LCID.",
ObjectMapValue (),
MakeObjectMapAccessor (&LteUeRrc::m_drbMap),
MakeObjectMapChecker<LteDataRadioBearerInfo> ())
.AddAttribute ("Srb0", "SignalingRadioBearerInfo for SRB0",
PointerValue (),
MakePointerAccessor (&LteUeRrc::m_srb0),
MakePointerChecker<LteSignalingRadioBearerInfo> ())
.AddAttribute ("Srb1", "SignalingRadioBearerInfo for SRB1",
PointerValue (),
MakePointerAccessor (&LteUeRrc::m_srb1),
MakePointerChecker<LteSignalingRadioBearerInfo> ())
.AddAttribute ("CellId",
"Serving cell identifier",
UintegerValue (0), // unused, read-only attribute
MakeUintegerAccessor (&LteUeRrc::GetCellId),
MakeUintegerChecker<uint16_t> ())
.AddAttribute ("C-RNTI",
"Cell Radio Network Temporary Identifier",
UintegerValue (0), // unused, read-only attribute
MakeUintegerAccessor (&LteUeRrc::GetRnti),
MakeUintegerChecker<uint16_t> ())
.AddAttribute ("T300",
"Timer for the RRC Connection Establishment procedure "
"(i.e., the procedure is deemed as failed if it takes longer than this). "
"Standard values: 100ms, 200ms, 300ms, 400ms, 600ms, 1000ms, 1500ms, 2000ms",
TimeValue (MilliSeconds (100)), //see 3GPP 36.331 UE-TimersAndConstants & RLF-TimersAndConstants
MakeTimeAccessor (&LteUeRrc::m_t300),
MakeTimeChecker (MilliSeconds (100), MilliSeconds (2000)))
.AddAttribute ("T310",
"Timer for detecting the Radio link failure "
"(i.e., the radio link is deemed as failed if this timer expires). "
"Standard values: 0ms 50ms, 100ms, 200ms, 500ms, 1000ms, 2000ms",
TimeValue (MilliSeconds (1000)), //see 3GPP 36.331 UE-TimersAndConstants & RLF-TimersAndConstants
MakeTimeAccessor (&LteUeRrc::m_t310),
MakeTimeChecker (MilliSeconds (0), MilliSeconds (2000)))
.AddAttribute ("N310",
"This specifies the maximum number of out-of-sync indications. "
"Standard values: 1, 2, 3, 4, 6, 8, 10, 20",
UintegerValue (6), //see 3GPP 36.331 UE-TimersAndConstants & RLF-TimersAndConstants
MakeUintegerAccessor (&LteUeRrc::m_n310),
MakeUintegerChecker<uint8_t> (1, 20))
.AddAttribute ("N311",
"This specifies the maximum number of in-sync indications. "
"Standard values: 1, 2, 3, 4, 5, 6, 8, 10",
UintegerValue (2), //see 3GPP 36.331 UE-TimersAndConstants & RLF-TimersAndConstants
MakeUintegerAccessor (&LteUeRrc::m_n311),
MakeUintegerChecker<uint8_t> (1, 10))
.AddTraceSource ("MibReceived",
"trace fired upon reception of Master Information Block",
MakeTraceSourceAccessor (&LteUeRrc::m_mibReceivedTrace),
"ns3::LteUeRrc::MibSibHandoverTracedCallback")
.AddTraceSource ("Sib1Received",
"trace fired upon reception of System Information Block Type 1",
MakeTraceSourceAccessor (&LteUeRrc::m_sib1ReceivedTrace),
"ns3::LteUeRrc::MibSibHandoverTracedCallback")
.AddTraceSource ("Sib2Received",
"trace fired upon reception of System Information Block Type 2",
MakeTraceSourceAccessor (&LteUeRrc::m_sib2ReceivedTrace),
"ns3::LteUeRrc::ImsiCidRntiTracedCallback")
.AddTraceSource ("StateTransition",
"trace fired upon every UE RRC state transition",
MakeTraceSourceAccessor (&LteUeRrc::m_stateTransitionTrace),
"ns3::LteUeRrc::StateTracedCallback")
.AddTraceSource ("InitialCellSelectionEndOk",
"trace fired upon successful initial cell selection procedure",
MakeTraceSourceAccessor (&LteUeRrc::m_initialCellSelectionEndOkTrace),
"ns3::LteUeRrc::CellSelectionTracedCallback")
.AddTraceSource ("InitialCellSelectionEndError",
"trace fired upon failed initial cell selection procedure",
MakeTraceSourceAccessor (&LteUeRrc::m_initialCellSelectionEndErrorTrace),
"ns3::LteUeRrc::CellSelectionTracedCallback")
.AddTraceSource ("RandomAccessSuccessful",
"trace fired upon successful completion of the random access procedure",
MakeTraceSourceAccessor (&LteUeRrc::m_randomAccessSuccessfulTrace),
"ns3::LteUeRrc::ImsiCidRntiTracedCallback")
.AddTraceSource ("RandomAccessError",
"trace fired upon failure of the random access procedure",
MakeTraceSourceAccessor (&LteUeRrc::m_randomAccessErrorTrace),
"ns3::LteUeRrc::ImsiCidRntiTracedCallback")
.AddTraceSource ("ConnectionEstablished",
"trace fired upon successful RRC connection establishment",
MakeTraceSourceAccessor (&LteUeRrc::m_connectionEstablishedTrace),
"ns3::LteUeRrc::ImsiCidRntiTracedCallback")
.AddTraceSource ("ConnectionTimeout",
"trace fired upon timeout RRC connection establishment because of T300",
MakeTraceSourceAccessor (&LteUeRrc::m_connectionTimeoutTrace),
"ns3::LteUeRrc::ImsiCidRntiCountTracedCallback")
.AddTraceSource ("ConnectionReconfiguration",
"trace fired upon RRC connection reconfiguration",
MakeTraceSourceAccessor (&LteUeRrc::m_connectionReconfigurationTrace),
"ns3::LteUeRrc::ImsiCidRntiTracedCallback")
.AddTraceSource ("HandoverStart",
"trace fired upon start of a handover procedure",
MakeTraceSourceAccessor (&LteUeRrc::m_handoverStartTrace),
"ns3::LteUeRrc::MibSibHandoverTracedCallback")
.AddTraceSource ("HandoverEndOk",
"trace fired upon successful termination of a handover procedure",
MakeTraceSourceAccessor (&LteUeRrc::m_handoverEndOkTrace),
"ns3::LteUeRrc::ImsiCidRntiTracedCallback")
.AddTraceSource ("HandoverEndError",
"trace fired upon failure of a handover procedure",
MakeTraceSourceAccessor (&LteUeRrc::m_handoverEndErrorTrace),
"ns3::LteUeRrc::ImsiCidRntiTracedCallback")
.AddTraceSource ("SCarrierConfigured",
"trace fired after configuring secondary carriers",
MakeTraceSourceAccessor (&LteUeRrc::m_sCarrierConfiguredTrace),
"ns3::LteUeRrc::SCarrierConfiguredTracedCallback")
.AddTraceSource ("Srb1Created",
"trace fired after SRB1 is created",
MakeTraceSourceAccessor (&LteUeRrc::m_srb1CreatedTrace),
"ns3::LteUeRrc::ImsiCidRntiTracedCallback")
.AddTraceSource ("DrbCreated",
"trace fired after DRB is created",
MakeTraceSourceAccessor (&LteUeRrc::m_drbCreatedTrace),
"ns3::LteUeRrc::ImsiCidRntiLcIdTracedCallback")
.AddTraceSource ("RadioLinkFailure",
"trace fired upon failure of radio link",
MakeTraceSourceAccessor (&LteUeRrc::m_radioLinkFailureTrace),
"ns3::LteUeRrc::ImsiCidRntiTracedCallback")
.AddTraceSource ("PhySyncDetection",
"trace fired upon receiving in Sync or out of Sync indications from UE PHY",
MakeTraceSourceAccessor (&LteUeRrc::m_phySyncDetectionTrace),
"ns3::LteUeRrc::PhySyncDetectionTracedCallback")
;
return tid;
}
void
LteUeRrc::SetLteUeCphySapProvider (LteUeCphySapProvider * s)
{
NS_LOG_FUNCTION (this << s);
m_cphySapProvider.at(0) = s;
}
void
LteUeRrc::SetLteUeCphySapProvider (LteUeCphySapProvider * s, uint8_t index)
{
NS_LOG_FUNCTION (this << s);
m_cphySapProvider.at(index) = s;
}
LteUeCphySapUser*
LteUeRrc::GetLteUeCphySapUser ()
{
NS_LOG_FUNCTION (this);
return m_cphySapUser.at(0);
}
LteUeCphySapUser*
LteUeRrc::GetLteUeCphySapUser (uint8_t index)
{
NS_LOG_FUNCTION (this);
return m_cphySapUser.at(index);
}
void
LteUeRrc::SetLteUeCmacSapProvider (LteUeCmacSapProvider * s)
{
NS_LOG_FUNCTION (this << s);
m_cmacSapProvider.at (0) = s;
}
void
LteUeRrc::SetLteUeCmacSapProvider (LteUeCmacSapProvider * s, uint8_t index)
{
NS_LOG_FUNCTION (this << s);
m_cmacSapProvider.at (index) = s;
}
LteUeCmacSapUser*
LteUeRrc::GetLteUeCmacSapUser ()
{
NS_LOG_FUNCTION (this);
return m_cmacSapUser.at (0);
}
LteUeCmacSapUser*
LteUeRrc::GetLteUeCmacSapUser (uint8_t index)
{
NS_LOG_FUNCTION (this);
return m_cmacSapUser.at (index);
}
void
LteUeRrc::SetLteUeRrcSapUser (LteUeRrcSapUser * s)
{
NS_LOG_FUNCTION (this << s);
m_rrcSapUser = s;
}
LteUeRrcSapProvider*
LteUeRrc::GetLteUeRrcSapProvider ()
{
NS_LOG_FUNCTION (this);
return m_rrcSapProvider;
}
void
LteUeRrc::SetLteMacSapProvider (LteMacSapProvider * s)
{
NS_LOG_FUNCTION (this << s);
m_macSapProvider = s;
}
void
LteUeRrc::SetLteCcmRrcSapProvider (LteUeCcmRrcSapProvider * s)
{
NS_LOG_FUNCTION (this << s);
m_ccmRrcSapProvider = s;
}
LteUeCcmRrcSapUser*
LteUeRrc::GetLteCcmRrcSapUser ()
{
NS_LOG_FUNCTION (this);
return m_ccmRrcSapUser;
}
void
LteUeRrc::SetAsSapUser (LteAsSapUser* s)
{
m_asSapUser = s;
}
LteAsSapProvider*
LteUeRrc::GetAsSapProvider ()
{
return m_asSapProvider;
}
void
LteUeRrc::SetImsi (uint64_t imsi)
{
NS_LOG_FUNCTION (this << imsi);
m_imsi = imsi;
//Communicate the IMSI to MACs and PHYs for all the component carriers
for (uint16_t i = 0; i < m_numberOfComponentCarriers; i++)
{
m_cmacSapProvider.at(i)->SetImsi (m_imsi);
m_cphySapProvider.at(i)->SetImsi (m_imsi);
}
}
void
LteUeRrc::StorePreviousCellId (uint16_t cellId)
{
NS_LOG_FUNCTION (this << cellId);
m_previousCellId = cellId;
}
uint64_t
LteUeRrc::GetImsi (void) const
{
return m_imsi;
}
uint16_t
LteUeRrc::GetRnti () const
{
NS_LOG_FUNCTION (this);
return m_rnti;
}
uint16_t
LteUeRrc::GetCellId () const
{
NS_LOG_FUNCTION (this);
return m_cellId;
}
uint8_t
LteUeRrc::GetUlBandwidth () const
{
NS_LOG_FUNCTION (this);
return m_ulBandwidth;
}
uint8_t
LteUeRrc::GetDlBandwidth () const
{
NS_LOG_FUNCTION (this);
return m_dlBandwidth;
}
uint32_t
LteUeRrc::GetDlEarfcn () const
{
return m_dlEarfcn;
}
uint32_t
LteUeRrc::GetUlEarfcn () const
{
NS_LOG_FUNCTION (this);
return m_ulEarfcn;
}
LteUeRrc::State
LteUeRrc::GetState (void) const
{
NS_LOG_FUNCTION (this);
return m_state;
}
uint16_t
LteUeRrc::GetPreviousCellId () const
{
NS_LOG_FUNCTION (this);
return m_previousCellId;
}
void
LteUeRrc::SetUseRlcSm (bool val)
{
NS_LOG_FUNCTION (this);
m_useRlcSm = val;
}
void
LteUeRrc::DoInitialize (void)
{
NS_LOG_FUNCTION (this);
// setup the UE side of SRB0
uint8_t lcid = 0;
Ptr<LteRlc> rlc = CreateObject<LteRlcTm> ()->GetObject<LteRlc> ();
rlc->SetLteMacSapProvider (m_macSapProvider);
rlc->SetRnti (m_rnti);
rlc->SetLcId (lcid);
m_srb0 = CreateObject<LteSignalingRadioBearerInfo> ();
m_srb0->m_rlc = rlc;
m_srb0->m_srbIdentity = 0;
LteUeRrcSapUser::SetupParameters ueParams;
ueParams.srb0SapProvider = m_srb0->m_rlc->GetLteRlcSapProvider ();
ueParams.srb1SapProvider = 0;
m_rrcSapUser->Setup (ueParams);
// CCCH (LCID 0) is pre-configured, here is the hardcoded configuration:
LteUeCmacSapProvider::LogicalChannelConfig lcConfig;
lcConfig.priority = 0; // highest priority
lcConfig.prioritizedBitRateKbps = 65535; // maximum
lcConfig.bucketSizeDurationMs = 65535; // maximum
lcConfig.logicalChannelGroup = 0; // all SRBs mapped to LCG 0
LteMacSapUser* msu = m_ccmRrcSapProvider->ConfigureSignalBearer(lcid, lcConfig, rlc->GetLteMacSapUser ());
m_cmacSapProvider.at (0)->AddLc (lcid, lcConfig, msu);
}
void
LteUeRrc::InitializeSap (void)
{
if (m_numberOfComponentCarriers < MIN_NO_CC || m_numberOfComponentCarriers > MAX_NO_CC)
{
// this check is needed in order to maintain backward compatibility with scripts and tests
// if case lte-helper is not used (like in several tests) the m_numberOfComponentCarriers
// is not set and then an error is raised
// In this case m_numberOfComponentCarriers is set to 1
m_numberOfComponentCarriers = MIN_NO_CC;
}
if (m_numberOfComponentCarriers > MIN_NO_CC )
{
for ( uint16_t i = 1; i < m_numberOfComponentCarriers; i++)
{
m_cphySapUser.push_back(new MemberLteUeCphySapUser<LteUeRrc> (this));
m_cmacSapUser.push_back(new UeMemberLteUeCmacSapUser (this));
m_cphySapProvider.push_back(0);
m_cmacSapProvider.push_back(0);
}
}
}
void
LteUeRrc::DoSendData (Ptr<Packet> packet, uint8_t bid)
{
NS_LOG_FUNCTION (this << packet);
uint8_t drbid = Bid2Drbid (bid);
if (drbid != 0)
{
std::map<uint8_t, Ptr<LteDataRadioBearerInfo> >::iterator it = m_drbMap.find (drbid);
NS_ASSERT_MSG (it != m_drbMap.end (), "could not find bearer with drbid == " << drbid);
LtePdcpSapProvider::TransmitPdcpSduParameters params;
params.pdcpSdu = packet;
params.rnti = m_rnti;
params.lcid = it->second->m_logicalChannelIdentity;
NS_LOG_LOGIC (this << " RNTI=" << m_rnti << " sending packet " << packet
<< " on DRBID " << (uint32_t) drbid
<< " (LCID " << (uint32_t) params.lcid << ")"
<< " (" << packet->GetSize () << " bytes)");
it->second->m_pdcp->GetLtePdcpSapProvider ()->TransmitPdcpSdu (params);
}
}
void
LteUeRrc::DoDisconnect ()
{
NS_LOG_FUNCTION (this);
switch (m_state)
{
case IDLE_START:
case IDLE_CELL_SEARCH:
case IDLE_WAIT_MIB_SIB1:
case IDLE_WAIT_MIB:
case IDLE_WAIT_SIB1:
case IDLE_CAMPED_NORMALLY:
NS_LOG_INFO ("already disconnected");
break;
case IDLE_WAIT_SIB2:
case IDLE_CONNECTING:
NS_FATAL_ERROR ("cannot abort connection setup procedure");
break;
case CONNECTED_NORMALLY:
case CONNECTED_HANDOVER:
case CONNECTED_PHY_PROBLEM:
case CONNECTED_REESTABLISHING:
LeaveConnectedMode ();
break;
default: // i.e. IDLE_RANDOM_ACCESS
NS_FATAL_ERROR ("method unexpected in state " << ToString (m_state));
break;
}
}
void
LteUeRrc::DoReceivePdcpSdu (LtePdcpSapUser::ReceivePdcpSduParameters params)
{
NS_LOG_FUNCTION (this);
m_asSapUser->RecvData (params.pdcpSdu);
}
void
LteUeRrc::DoSetTemporaryCellRnti (uint16_t rnti)
{
NS_LOG_FUNCTION (this << rnti);
m_rnti = rnti;
m_srb0->m_rlc->SetRnti (m_rnti);
m_cphySapProvider.at(0)->SetRnti (m_rnti);
}
void
LteUeRrc::DoNotifyRandomAccessSuccessful ()
{
NS_LOG_FUNCTION (this << m_imsi << ToString (m_state));
m_randomAccessSuccessfulTrace (m_imsi, m_cellId, m_rnti);
switch (m_state)
{
case IDLE_RANDOM_ACCESS:
{
// we just received a RAR with a T-C-RNTI and an UL grant
// send RRC connection request as message 3 of the random access procedure
SwitchToState (IDLE_CONNECTING);
LteRrcSap::RrcConnectionRequest msg;
msg.ueIdentity = m_imsi;
m_rrcSapUser->SendRrcConnectionRequest (msg);
m_connectionTimeout = Simulator::Schedule (m_t300,
&LteUeRrc::ConnectionTimeout,
this);
}
break;
case CONNECTED_HANDOVER:
{
LteRrcSap::RrcConnectionReconfigurationCompleted msg;
msg.rrcTransactionIdentifier = m_lastRrcTransactionIdentifier;
m_rrcSapUser->SendRrcConnectionReconfigurationCompleted (msg);
// 3GPP TS 36.331 section 5.5.6.1 Measurements related actions upon handover
std::map<uint8_t, LteRrcSap::MeasIdToAddMod>::iterator measIdIt;
for (measIdIt = m_varMeasConfig.measIdList.begin ();
measIdIt != m_varMeasConfig.measIdList.end ();
++measIdIt)
{
VarMeasReportListClear (measIdIt->second.measId);
}
SwitchToState (CONNECTED_NORMALLY);
m_cmacSapProvider.at (0)->NotifyConnectionSuccessful (); //RA successful during handover
m_handoverEndOkTrace (m_imsi, m_cellId, m_rnti);
}
break;
default:
NS_FATAL_ERROR ("unexpected event in state " << ToString (m_state));
break;
}
}
void
LteUeRrc::DoNotifyRandomAccessFailed ()
{
NS_LOG_FUNCTION (this << m_imsi << ToString (m_state));
m_randomAccessErrorTrace (m_imsi, m_cellId, m_rnti);
switch (m_state)
{
case IDLE_RANDOM_ACCESS:
{
SwitchToState (IDLE_CAMPED_NORMALLY);
m_asSapUser->NotifyConnectionFailed ();
}
break;
case CONNECTED_HANDOVER:
{
m_handoverEndErrorTrace (m_imsi, m_cellId, m_rnti);
/**
* \todo After a handover failure because of a random access failure,
* send an RRC Connection Re-establishment and switch to
* CONNECTED_REESTABLISHING state.
*/
}
break;
default:
NS_FATAL_ERROR ("unexpected event in state " << ToString (m_state));
break;
}
}
void
LteUeRrc::DoSetCsgWhiteList (uint32_t csgId)
{
NS_LOG_FUNCTION (this << m_imsi << csgId);
m_csgWhiteList = csgId;
}
void
LteUeRrc::DoStartCellSelection (uint32_t dlEarfcn)
{
NS_LOG_FUNCTION (this << m_imsi << dlEarfcn);
NS_ASSERT_MSG (m_state == IDLE_START,
"cannot start cell selection from state " << ToString (m_state));
m_dlEarfcn = dlEarfcn;
m_cphySapProvider.at(0)->StartCellSearch (dlEarfcn);
SwitchToState (IDLE_CELL_SEARCH);
}
void
LteUeRrc::DoForceCampedOnEnb (uint16_t cellId, uint32_t dlEarfcn)
{
NS_LOG_FUNCTION (this << m_imsi << cellId << dlEarfcn);
switch (m_state)
{
case IDLE_START:
m_cellId = cellId;
m_dlEarfcn = dlEarfcn;
m_cphySapProvider.at(0)->SynchronizeWithEnb (m_cellId, m_dlEarfcn);
SwitchToState (IDLE_WAIT_MIB);
break;
case IDLE_CELL_SEARCH:
case IDLE_WAIT_MIB_SIB1:
case IDLE_WAIT_SIB1:
NS_FATAL_ERROR ("cannot abort cell selection " << ToString (m_state));
break;
case IDLE_WAIT_MIB:
NS_LOG_INFO ("already forced to camp to cell " << m_cellId);
break;
case IDLE_CAMPED_NORMALLY:
case IDLE_WAIT_SIB2:
case IDLE_RANDOM_ACCESS:
case IDLE_CONNECTING:
NS_LOG_INFO ("already camped to cell " << m_cellId);
break;
case CONNECTED_NORMALLY:
case CONNECTED_HANDOVER:
case CONNECTED_PHY_PROBLEM:
case CONNECTED_REESTABLISHING:
NS_LOG_INFO ("already connected to cell " << m_cellId);
break;
default:
NS_FATAL_ERROR ("unexpected event in state " << ToString (m_state));
break;
}
}
void
LteUeRrc::DoConnect ()
{
NS_LOG_FUNCTION (this << m_imsi);
switch (m_state)
{
case IDLE_START:
case IDLE_CELL_SEARCH:
case IDLE_WAIT_MIB_SIB1:
case IDLE_WAIT_SIB1:
case IDLE_WAIT_MIB:
m_connectionPending = true;
break;
case IDLE_CAMPED_NORMALLY:
m_connectionPending = true;
SwitchToState (IDLE_WAIT_SIB2);
break;
case IDLE_WAIT_SIB2:
case IDLE_RANDOM_ACCESS:
case IDLE_CONNECTING:
NS_LOG_INFO ("already connecting");
break;
case CONNECTED_NORMALLY:
case CONNECTED_REESTABLISHING:
case CONNECTED_HANDOVER:
NS_LOG_INFO ("already connected");
break;
default:
NS_FATAL_ERROR ("unexpected event in state " << ToString (m_state));
break;
}
}
// CPHY SAP methods
void
LteUeRrc::DoRecvMasterInformationBlock (uint16_t cellId,
LteRrcSap::MasterInformationBlock msg)
{
m_dlBandwidth = msg.dlBandwidth;
m_cphySapProvider.at(0)->SetDlBandwidth (msg.dlBandwidth);
m_hasReceivedMib = true;
m_mibReceivedTrace (m_imsi, m_cellId, m_rnti, cellId);
switch (m_state)
{
case IDLE_WAIT_MIB:
// manual attachment
SwitchToState (IDLE_CAMPED_NORMALLY);
break;
case IDLE_WAIT_MIB_SIB1:
// automatic attachment from Idle mode cell selection
SwitchToState (IDLE_WAIT_SIB1);
break;
default:
// do nothing extra
break;
}
}
void
LteUeRrc::DoRecvSystemInformationBlockType1 (uint16_t cellId,
LteRrcSap::SystemInformationBlockType1 msg)
{
NS_LOG_FUNCTION (this);
switch (m_state)
{
case IDLE_WAIT_SIB1:
NS_ASSERT_MSG (cellId == msg.cellAccessRelatedInfo.cellIdentity,
"Cell identity in SIB1 does not match with the originating cell");
m_hasReceivedSib1 = true;
m_lastSib1 = msg;
m_sib1ReceivedTrace (m_imsi, m_cellId, m_rnti, cellId);
EvaluateCellForSelection ();
break;
case IDLE_CAMPED_NORMALLY:
case IDLE_RANDOM_ACCESS:
case IDLE_CONNECTING:
case CONNECTED_NORMALLY:
case CONNECTED_HANDOVER:
case CONNECTED_PHY_PROBLEM:
case CONNECTED_REESTABLISHING:
NS_ASSERT_MSG (cellId == msg.cellAccessRelatedInfo.cellIdentity,
"Cell identity in SIB1 does not match with the originating cell");
m_hasReceivedSib1 = true;
m_lastSib1 = msg;
m_sib1ReceivedTrace (m_imsi, m_cellId, m_rnti, cellId);
break;
case IDLE_WAIT_MIB_SIB1:
// MIB has not been received, so ignore this SIB1
break;
default: // e.g. IDLE_START, IDLE_CELL_SEARCH, IDLE_WAIT_MIB, IDLE_WAIT_SIB2
// do nothing
break;
}
}
void
LteUeRrc::DoReportUeMeasurements (LteUeCphySapUser::UeMeasurementsParameters params)
{
NS_LOG_FUNCTION (this);
// layer 3 filtering does not apply in IDLE mode
bool useLayer3Filtering = (m_state == CONNECTED_NORMALLY);
bool triggering = true;
std::vector <LteUeCphySapUser::UeMeasurementsElement>::iterator newMeasIt;
for (newMeasIt = params.m_ueMeasurementsList.begin ();
newMeasIt != params.m_ueMeasurementsList.end (); ++newMeasIt)
{
if (params.m_componentCarrierId != 0)
{
triggering = false; // report is triggered only when an event is on the primary carrier
// in this case the measurement received is related to secondary carriers
// measurements related to secondary carriers are saved on a different portion of memory
SaveScellUeMeasurements (newMeasIt->m_cellId, newMeasIt->m_rsrp,
newMeasIt->m_rsrq, useLayer3Filtering,
params.m_componentCarrierId );
}
else
{
SaveUeMeasurements (newMeasIt->m_cellId, newMeasIt->m_rsrp,
newMeasIt->m_rsrq, useLayer3Filtering);
}
}
if (m_state == IDLE_CELL_SEARCH)
{
// start decoding BCH
SynchronizeToStrongestCell ();
}
else
{
if (triggering)
{
std::map<uint8_t, LteRrcSap::MeasIdToAddMod>::iterator measIdIt;
for (measIdIt = m_varMeasConfig.measIdList.begin ();
measIdIt != m_varMeasConfig.measIdList.end (); ++measIdIt)
{
MeasurementReportTriggering (measIdIt->first);
}
}
}
} // end of LteUeRrc::DoReportUeMeasurements
// RRC SAP methods
void
LteUeRrc::DoCompleteSetup (LteUeRrcSapProvider::CompleteSetupParameters params)
{
NS_LOG_FUNCTION (this << " RNTI " << m_rnti);
m_srb0->m_rlc->SetLteRlcSapUser (params.srb0SapUser);
if (m_srb1)
{
m_srb1->m_pdcp->SetLtePdcpSapUser (params.srb1SapUser);
}
}
void
LteUeRrc::DoRecvSystemInformation (LteRrcSap::SystemInformation msg)
{
NS_LOG_FUNCTION (this << " RNTI " << m_rnti);
if (msg.haveSib2)
{
switch (m_state)
{
case IDLE_CAMPED_NORMALLY:
case IDLE_WAIT_SIB2:
case IDLE_RANDOM_ACCESS:
case IDLE_CONNECTING:
case CONNECTED_NORMALLY:
case CONNECTED_HANDOVER:
case CONNECTED_PHY_PROBLEM:
case CONNECTED_REESTABLISHING:
m_hasReceivedSib2 = true;
m_ulBandwidth = msg.sib2.freqInfo.ulBandwidth;
m_ulEarfcn = msg.sib2.freqInfo.ulCarrierFreq;
m_sib2ReceivedTrace (m_imsi, m_cellId, m_rnti);
LteUeCmacSapProvider::RachConfig rc;
rc.numberOfRaPreambles = msg.sib2.radioResourceConfigCommon.rachConfigCommon.preambleInfo.numberOfRaPreambles;
rc.preambleTransMax = msg.sib2.radioResourceConfigCommon.rachConfigCommon.raSupervisionInfo.preambleTransMax;