-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlte-enb-phy.cc
1120 lines (974 loc) · 32.2 KB
/
lte-enb-phy.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) 2010 TELEMATICS LAB, DEE - Politecnico di Bari
*
* 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: Giuseppe Piro <g.piro@poliba.it>
* Marco Miozzo <mmiozzo@cttc.es>
*/
#include <ns3/object-factory.h>
#include <ns3/log.h>
#include <cfloat>
#include <cmath>
#include <ns3/simulator.h>
#include <ns3/attribute-accessor-helper.h>
#include <ns3/double.h>
#include "lte-enb-phy.h"
#include "lte-ue-phy.h"
#include "lte-net-device.h"
#include "lte-spectrum-value-helper.h"
#include "lte-control-messages.h"
#include "lte-enb-net-device.h"
#include "lte-ue-rrc.h"
#include "lte-enb-mac.h"
#include <ns3/lte-common.h>
#include <ns3/lte-vendor-specific-parameters.h>
// WILD HACK for the inizialization of direct eNB-UE ctrl messaging
#include <ns3/node-list.h>
#include <ns3/node.h>
#include <ns3/lte-ue-net-device.h>
#include <ns3/pointer.h>
namespace ns3 {
NS_LOG_COMPONENT_DEFINE ("LteEnbPhy");
NS_OBJECT_ENSURE_REGISTERED (LteEnbPhy);
/**
* Duration of the data portion of a DL subframe.
* Equals to "TTI length * (11/14) - margin".
* Data portion is fixed to 11 symbols out of the available 14 symbols.
* 1 nanosecond margin is added to avoid overlapping simulator events.
*/
static const Time DL_DATA_DURATION = NanoSeconds (785714 -1);
/**
* Delay from the start of a DL subframe to transmission of the data portion.
* Equals to "TTI length * (3/14)".
* Control portion is fixed to 3 symbols out of the available 14 symbols.
*/
static const Time DL_CTRL_DELAY_FROM_SUBFRAME_START = NanoSeconds (214286);
////////////////////////////////////////
// member SAP forwarders
////////////////////////////////////////
/// \todo SetBandwidth() and SetCellId() can be removed.
class EnbMemberLteEnbPhySapProvider : public LteEnbPhySapProvider
{
public:
EnbMemberLteEnbPhySapProvider (LteEnbPhy* phy);
// inherited from LteEnbPhySapProvider
virtual void SendMacPdu (Ptr<Packet> p);
virtual void SetBandwidth (uint8_t ulBandwidth, uint8_t dlBandwidth);
virtual void SetCellId (uint16_t cellId);
virtual void SendLteControlMessage (Ptr<LteControlMessage> msg);
virtual uint8_t GetMacChTtiDelay ();
private:
LteEnbPhy* m_phy;
};
EnbMemberLteEnbPhySapProvider::EnbMemberLteEnbPhySapProvider (LteEnbPhy* phy) : m_phy (phy)
{
}
void
EnbMemberLteEnbPhySapProvider::SendMacPdu (Ptr<Packet> p)
{
m_phy->DoSendMacPdu (p);
}
void
EnbMemberLteEnbPhySapProvider::SetBandwidth (uint8_t ulBandwidth, uint8_t dlBandwidth)
{
m_phy->DoSetBandwidth (ulBandwidth, dlBandwidth);
}
void
EnbMemberLteEnbPhySapProvider::SetCellId (uint16_t cellId)
{
m_phy->DoSetCellId (cellId);
}
void
EnbMemberLteEnbPhySapProvider::SendLteControlMessage (Ptr<LteControlMessage> msg)
{
m_phy->DoSendLteControlMessage (msg);
}
uint8_t
EnbMemberLteEnbPhySapProvider::GetMacChTtiDelay ()
{
return (m_phy->DoGetMacChTtiDelay ());
}
////////////////////////////////////////
// generic LteEnbPhy methods
////////////////////////////////////////
LteEnbPhy::LteEnbPhy ()
{
NS_LOG_FUNCTION (this);
NS_FATAL_ERROR ("This constructor should not be called");
}
LteEnbPhy::LteEnbPhy (Ptr<LteSpectrumPhy> dlPhy, Ptr<LteSpectrumPhy> ulPhy)
: LtePhy (dlPhy, ulPhy),
m_enbPhySapUser (0),
m_enbCphySapUser (0),
m_nrFrames (0),
m_nrSubFrames (0),
m_srsPeriodicity (0),
m_srsStartTime (Seconds (0)),
m_currentSrsOffset (0),
m_interferenceSampleCounter (0)
{
m_enbPhySapProvider = new EnbMemberLteEnbPhySapProvider (this);
m_enbCphySapProvider = new MemberLteEnbCphySapProvider<LteEnbPhy> (this);
m_harqPhyModule = Create <LteHarqPhy> ();
m_downlinkSpectrumPhy->SetHarqPhyModule (m_harqPhyModule);
m_uplinkSpectrumPhy->SetHarqPhyModule (m_harqPhyModule);
}
TypeId
LteEnbPhy::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::LteEnbPhy")
.SetParent<LtePhy> ()
.SetGroupName("Lte")
.AddConstructor<LteEnbPhy> ()
.AddAttribute ("TxPower",
"Transmission power in dBm",
DoubleValue (0.0),
MakeDoubleAccessor (&LteEnbPhy::SetTxPower,
&LteEnbPhy::GetTxPower),
MakeDoubleChecker<double> ())
.AddAttribute ("NoiseFigure",
"Loss (dB) in the Signal-to-Noise-Ratio due to "
"non-idealities in the receiver. According to Wikipedia "
"(http://en.wikipedia.org/wiki/Noise_figure), this is "
"\"the difference in decibels (dB) between"
" the noise output of the actual receiver to "
"the noise output of an ideal receiver with "
"the same overall gain and bandwidth when the receivers "
"are connected to sources at the standard noise "
"temperature T0.\" In this model, we consider T0 = 290K.",
DoubleValue (5.0),
MakeDoubleAccessor (&LteEnbPhy::SetNoiseFigure,
&LteEnbPhy::GetNoiseFigure),
MakeDoubleChecker<double> ())
.AddAttribute ("MacToChannelDelay",
"The delay in TTI units that occurs between "
"a scheduling decision in the MAC and the actual "
"start of the transmission by the PHY. This is "
"intended to be used to model the latency of real PHY "
"and MAC implementations.",
UintegerValue (2),
MakeUintegerAccessor (&LteEnbPhy::SetMacChDelay,
&LteEnbPhy::GetMacChDelay),
MakeUintegerChecker<uint8_t> ())
.AddTraceSource ("ReportUeSinr",
"Report UEs' averaged linear SINR",
MakeTraceSourceAccessor (&LteEnbPhy::m_reportUeSinr),
"ns3::LteEnbPhy::ReportUeSinrTracedCallback")
.AddAttribute ("UeSinrSamplePeriod",
"The sampling period for reporting UEs' SINR stats.",
UintegerValue (1), /// \todo In what unit is this?
MakeUintegerAccessor (&LteEnbPhy::m_srsSamplePeriod),
MakeUintegerChecker<uint16_t> ())
.AddTraceSource ("ReportInterference",
"Report linear interference power per PHY RB",
MakeTraceSourceAccessor (&LteEnbPhy::m_reportInterferenceTrace),
"ns3::LteEnbPhy::ReportInterferenceTracedCallback")
.AddAttribute ("InterferenceSamplePeriod",
"The sampling period for reporting interference stats",
UintegerValue (1), /// \todo In what unit is this?
MakeUintegerAccessor (&LteEnbPhy::m_interferenceSamplePeriod),
MakeUintegerChecker<uint16_t> ())
.AddTraceSource ("DlPhyTransmission",
"DL transmission PHY layer statistics.",
MakeTraceSourceAccessor (&LteEnbPhy::m_dlPhyTransmission),
"ns3::PhyTransmissionStatParameters::TracedCallback")
.AddAttribute ("DlSpectrumPhy",
"The downlink LteSpectrumPhy associated to this LtePhy",
TypeId::ATTR_GET,
PointerValue (),
MakePointerAccessor (&LteEnbPhy::GetDlSpectrumPhy),
MakePointerChecker <LteSpectrumPhy> ())
.AddAttribute ("UlSpectrumPhy",
"The uplink LteSpectrumPhy associated to this LtePhy",
TypeId::ATTR_GET,
PointerValue (),
MakePointerAccessor (&LteEnbPhy::GetUlSpectrumPhy),
MakePointerChecker <LteSpectrumPhy> ())
;
return tid;
}
LteEnbPhy::~LteEnbPhy ()
{
}
void
LteEnbPhy::DoDispose ()
{
NS_LOG_FUNCTION (this);
m_ueAttached.clear ();
m_srsUeOffset.clear ();
delete m_enbPhySapProvider;
delete m_enbCphySapProvider;
LtePhy::DoDispose ();
}
void
LteEnbPhy::DoInitialize ()
{
NS_LOG_FUNCTION (this);
bool haveNodeId = false;
uint32_t nodeId = 0;
if (m_netDevice != 0)
{
Ptr<Node> node = m_netDevice->GetNode ();
if (node != 0)
{
nodeId = node->GetId ();
haveNodeId = true;
}
}
if (haveNodeId)
{
Simulator::ScheduleWithContext (nodeId, Seconds (0), &LteEnbPhy::StartFrame, this);
}
else
{
Simulator::ScheduleNow (&LteEnbPhy::StartFrame, this);
}
Ptr<SpectrumValue> noisePsd = LteSpectrumValueHelper::CreateNoisePowerSpectralDensity (m_ulEarfcn, m_ulBandwidth, m_noiseFigure);
m_uplinkSpectrumPhy->SetNoisePowerSpectralDensity (noisePsd);
LtePhy::DoInitialize ();
}
void
LteEnbPhy::SetLteEnbPhySapUser (LteEnbPhySapUser* s)
{
m_enbPhySapUser = s;
}
LteEnbPhySapProvider*
LteEnbPhy::GetLteEnbPhySapProvider ()
{
return (m_enbPhySapProvider);
}
void
LteEnbPhy::SetLteEnbCphySapUser (LteEnbCphySapUser* s)
{
NS_LOG_FUNCTION (this);
m_enbCphySapUser = s;
}
LteEnbCphySapProvider*
LteEnbPhy::GetLteEnbCphySapProvider ()
{
NS_LOG_FUNCTION (this);
return (m_enbCphySapProvider);
}
void
LteEnbPhy::SetTxPower (double pow)
{
NS_LOG_FUNCTION (this << pow);
m_txPower = pow;
}
double
LteEnbPhy::GetTxPower () const
{
NS_LOG_FUNCTION (this);
return m_txPower;
}
int8_t
LteEnbPhy::DoGetReferenceSignalPower () const
{
NS_LOG_FUNCTION (this);
return m_txPower;
}
void
LteEnbPhy::SetNoiseFigure (double nf)
{
NS_LOG_FUNCTION (this << nf);
m_noiseFigure = nf;
}
double
LteEnbPhy::GetNoiseFigure () const
{
NS_LOG_FUNCTION (this);
return m_noiseFigure;
}
void
LteEnbPhy::SetMacChDelay (uint8_t delay)
{
NS_LOG_FUNCTION (this);
m_macChTtiDelay = delay;
for (int i = 0; i < m_macChTtiDelay; i++)
{
Ptr<PacketBurst> pb = CreateObject <PacketBurst> ();
m_packetBurstQueue.push_back (pb);
std::list<Ptr<LteControlMessage> > l;
m_controlMessagesQueue.push_back (l);
std::list<UlDciLteControlMessage> l1;
m_ulDciQueue.push_back (l1);
}
for (int i = 0; i < UL_PUSCH_TTIS_DELAY; i++)
{
std::list<UlDciLteControlMessage> l1;
m_ulDciQueue.push_back (l1);
}
}
uint8_t
LteEnbPhy::GetMacChDelay (void) const
{
return (m_macChTtiDelay);
}
Ptr<LteSpectrumPhy>
LteEnbPhy::GetDlSpectrumPhy () const
{
return m_downlinkSpectrumPhy;
}
Ptr<LteSpectrumPhy>
LteEnbPhy::GetUlSpectrumPhy () const
{
return m_uplinkSpectrumPhy;
}
bool
LteEnbPhy::AddUePhy (uint16_t rnti)
{
NS_LOG_FUNCTION (this << rnti);
std::set <uint16_t>::iterator it;
it = m_ueAttached.find (rnti);
if (it == m_ueAttached.end ())
{
m_ueAttached.insert (rnti);
return (true);
}
else
{
NS_LOG_ERROR ("UE already attached");
return (false);
}
}
bool
LteEnbPhy::DeleteUePhy (uint16_t rnti)
{
NS_LOG_FUNCTION (this << rnti);
std::set <uint16_t>::iterator it;
it = m_ueAttached.find (rnti);
if (it == m_ueAttached.end ())
{
NS_LOG_ERROR ("UE not attached");
return (false);
}
else
{
m_ueAttached.erase (it);
return (true);
}
}
void
LteEnbPhy::DoSendMacPdu (Ptr<Packet> p)
{
NS_LOG_FUNCTION (this);
SetMacPdu (p);
}
uint8_t
LteEnbPhy::DoGetMacChTtiDelay ()
{
return (m_macChTtiDelay);
}
void
LteEnbPhy::PhyPduReceived (Ptr<Packet> p)
{
NS_LOG_FUNCTION (this);
m_enbPhySapUser->ReceivePhyPdu (p);
}
void
LteEnbPhy::SetDownlinkSubChannels (std::vector<int> mask)
{
NS_LOG_FUNCTION (this);
m_listOfDownlinkSubchannel = mask;
Ptr<SpectrumValue> txPsd = CreateTxPowerSpectralDensity ();
m_downlinkSpectrumPhy->SetTxPowerSpectralDensity (txPsd);
}
void
LteEnbPhy::SetDownlinkSubChannelsWithPowerAllocation (std::vector<int> mask)
{
NS_LOG_FUNCTION (this);
m_listOfDownlinkSubchannel = mask;
Ptr<SpectrumValue> txPsd = CreateTxPowerSpectralDensityWithPowerAllocation ();
m_downlinkSpectrumPhy->SetTxPowerSpectralDensity (txPsd);
}
std::vector<int>
LteEnbPhy::GetDownlinkSubChannels (void)
{
NS_LOG_FUNCTION (this);
return m_listOfDownlinkSubchannel;
}
void
LteEnbPhy::GeneratePowerAllocationMap (uint16_t rnti, int rbId)
{
NS_LOG_FUNCTION (this);
double rbgTxPower = m_txPower;
std::map<uint16_t, double>::iterator it = m_paMap.find (rnti);
if (it != m_paMap.end ())
{
rbgTxPower = m_txPower + it->second;
}
m_dlPowerAllocationMap.insert (std::pair<int, double> (rbId, rbgTxPower));
}
Ptr<SpectrumValue>
LteEnbPhy::CreateTxPowerSpectralDensity ()
{
NS_LOG_FUNCTION (this);
Ptr<SpectrumValue> psd = LteSpectrumValueHelper::CreateTxPowerSpectralDensity (m_dlEarfcn, m_dlBandwidth, m_txPower, GetDownlinkSubChannels ());
return psd;
}
Ptr<SpectrumValue>
LteEnbPhy::CreateTxPowerSpectralDensityWithPowerAllocation ()
{
NS_LOG_FUNCTION (this);
Ptr<SpectrumValue> psd = LteSpectrumValueHelper::CreateTxPowerSpectralDensity (m_dlEarfcn, m_dlBandwidth, m_txPower, m_dlPowerAllocationMap, GetDownlinkSubChannels ());
return psd;
}
void
LteEnbPhy::CalcChannelQualityForUe (std::vector <double> sinr, Ptr<LteSpectrumPhy> ue)
{
NS_LOG_FUNCTION (this);
}
void
LteEnbPhy::DoSendLteControlMessage (Ptr<LteControlMessage> msg)
{
NS_LOG_FUNCTION (this << msg);
// queues the message (wait for MAC-PHY delay)
SetControlMessages (msg);
}
void
LteEnbPhy::ReceiveLteControlMessage (Ptr<LteControlMessage> msg)
{
NS_FATAL_ERROR ("Obsolete function");
NS_LOG_FUNCTION (this << msg);
m_enbPhySapUser->ReceiveLteControlMessage (msg);
}
void
LteEnbPhy::ReceiveLteControlMessageList (std::list<Ptr<LteControlMessage> > msgList)
{
NS_LOG_FUNCTION (this);
std::list<Ptr<LteControlMessage> >::iterator it;
for (it = msgList.begin (); it != msgList.end (); it++)
{
switch ((*it)->GetMessageType ())
{
case LteControlMessage::RACH_PREAMBLE:
{
Ptr<RachPreambleLteControlMessage> rachPreamble = DynamicCast<RachPreambleLteControlMessage> (*it);
m_enbPhySapUser->ReceiveRachPreamble (rachPreamble->GetRapId ());
}
break;
case LteControlMessage::DL_CQI:
{
Ptr<DlCqiLteControlMessage> dlcqiMsg = DynamicCast<DlCqiLteControlMessage> (*it);
CqiListElement_s dlcqi = dlcqiMsg->GetDlCqi ();
// check whether the UE is connected
if (m_ueAttached.find (dlcqi.m_rnti) != m_ueAttached.end ())
{
m_enbPhySapUser->ReceiveLteControlMessage (*it);
}
}
break;
case LteControlMessage::BSR:
{
Ptr<BsrLteControlMessage> bsrMsg = DynamicCast<BsrLteControlMessage> (*it);
MacCeListElement_s bsr = bsrMsg->GetBsr ();
// check whether the UE is connected
if (m_ueAttached.find (bsr.m_rnti) != m_ueAttached.end ())
{
m_enbPhySapUser->ReceiveLteControlMessage (*it);
}
}
break;
case LteControlMessage::DL_HARQ:
{
Ptr<DlHarqFeedbackLteControlMessage> dlharqMsg = DynamicCast<DlHarqFeedbackLteControlMessage> (*it);
DlInfoListElement_s dlharq = dlharqMsg->GetDlHarqFeedback ();
// check whether the UE is connected
if (m_ueAttached.find (dlharq.m_rnti) != m_ueAttached.end ())
{
m_enbPhySapUser->ReceiveLteControlMessage (*it);
}
}
break;
default:
NS_FATAL_ERROR ("Unexpected LteControlMessage type");
break;
}
}
}
void
LteEnbPhy::StartFrame (void)
{
NS_LOG_FUNCTION (this);
++m_nrFrames;
NS_LOG_INFO ("-----frame " << m_nrFrames << "-----");
m_nrSubFrames = 0;
// send MIB at beginning of every frame
m_mib.systemFrameNumber = m_nrSubFrames;
Ptr<MibLteControlMessage> mibMsg = Create<MibLteControlMessage> ();
mibMsg->SetMib (m_mib);
m_controlMessagesQueue.at (0).push_back (mibMsg);
StartSubFrame ();
}
void
LteEnbPhy::StartSubFrame (void)
{
NS_LOG_FUNCTION (this);
++m_nrSubFrames;
/*
* Send SIB1 at 6th subframe of every odd-numbered radio frame. This is
* equivalent with Section 5.2.1.2 of 3GPP TS 36.331, where it is specified
* "repetitions are scheduled in subframe #5 of all other radio frames for
* which SFN mod 2 = 0," except that 3GPP counts frames and subframes starting
* from 0, while ns-3 counts starting from 1.
*/
if ((m_nrSubFrames == 6) && ((m_nrFrames % 2) == 1))
{
Ptr<Sib1LteControlMessage> msg = Create<Sib1LteControlMessage> ();
msg->SetSib1 (m_sib1);
m_controlMessagesQueue.at (0).push_back (msg);
}
if (m_srsPeriodicity>0)
{
// might be 0 in case the eNB has no UEs attached
NS_ASSERT_MSG (m_nrFrames > 1, "the SRS index check code assumes that frameNo starts at 1");
NS_ASSERT_MSG (m_nrSubFrames > 0 && m_nrSubFrames <= 10, "the SRS index check code assumes that subframeNo starts at 1");
m_currentSrsOffset = (((m_nrFrames-1)*10 + (m_nrSubFrames-1)) % m_srsPeriodicity);
}
NS_LOG_INFO ("-----sub frame " << m_nrSubFrames << "-----");
m_harqPhyModule->SubframeIndication (m_nrFrames, m_nrSubFrames);
// update info on TB to be received
std::list<UlDciLteControlMessage> uldcilist = DequeueUlDci ();
std::list<UlDciLteControlMessage>::iterator dciIt = uldcilist.begin ();
NS_LOG_DEBUG (this << " eNB Expected TBs " << uldcilist.size ());
for (dciIt = uldcilist.begin (); dciIt!=uldcilist.end (); dciIt++)
{
std::set <uint16_t>::iterator it2;
it2 = m_ueAttached.find ((*dciIt).GetDci ().m_rnti);
if (it2 == m_ueAttached.end ())
{
NS_LOG_ERROR ("UE not attached");
}
else
{
// send info of TB to LteSpectrumPhy
// translate to allocation map
std::vector <int> rbMap;
for (int i = (*dciIt).GetDci ().m_rbStart; i < (*dciIt).GetDci ().m_rbStart + (*dciIt).GetDci ().m_rbLen; i++)
{
rbMap.push_back (i);
}
m_uplinkSpectrumPhy->AddExpectedTb ((*dciIt).GetDci ().m_rnti, (*dciIt).GetDci ().m_ndi, (*dciIt).GetDci ().m_tbSize, (*dciIt).GetDci ().m_mcs, rbMap, 0 /* always SISO*/, 0 /* no HARQ proc id in UL*/, 0 /*evaluated by LteSpectrumPhy*/, false /* UL*/);
if ((*dciIt).GetDci ().m_ndi==1)
{
NS_LOG_DEBUG (this << " RNTI " << (*dciIt).GetDci ().m_rnti << " NEW TB");
}
else
{
NS_LOG_DEBUG (this << " RNTI " << (*dciIt).GetDci ().m_rnti << " HARQ RETX");
}
}
}
// process the current burst of control messages
std::list<Ptr<LteControlMessage> > ctrlMsg = GetControlMessages ();
m_dlDataRbMap.clear ();
m_dlPowerAllocationMap.clear ();
if (ctrlMsg.size () > 0)
{
std::list<Ptr<LteControlMessage> >::iterator it;
it = ctrlMsg.begin ();
while (it != ctrlMsg.end ())
{
Ptr<LteControlMessage> msg = (*it);
if (msg->GetMessageType () == LteControlMessage::DL_DCI)
{
Ptr<DlDciLteControlMessage> dci = DynamicCast<DlDciLteControlMessage> (msg);
// get the tx power spectral density according to DL-DCI(s)
// translate the DCI to Spectrum framework
uint32_t mask = 0x1;
for (int i = 0; i < 32; i++)
{
if (((dci->GetDci ().m_rbBitmap & mask) >> i) == 1)
{
for (int k = 0; k < GetRbgSize (); k++)
{
m_dlDataRbMap.push_back ((i * GetRbgSize ()) + k);
//NS_LOG_DEBUG(this << " [enb]DL-DCI allocated PRB " << (i*GetRbgSize()) + k);
GeneratePowerAllocationMap (dci->GetDci ().m_rnti, (i * GetRbgSize ()) + k );
}
}
mask = (mask << 1);
}
// fire trace of DL Tx PHY stats
for (uint8_t i = 0; i < dci->GetDci ().m_mcs.size (); i++)
{
PhyTransmissionStatParameters params;
params.m_cellId = m_cellId;
params.m_imsi = 0; // it will be set by DlPhyTransmissionCallback in LteHelper
params.m_timestamp = Simulator::Now ().GetMilliSeconds ();
params.m_rnti = dci->GetDci ().m_rnti;
params.m_txMode = 0; // TBD
params.m_layer = i;
params.m_mcs = dci->GetDci ().m_mcs.at (i);
params.m_size = dci->GetDci ().m_tbsSize.at (i);
params.m_rv = dci->GetDci ().m_rv.at (i);
params.m_ndi = dci->GetDci ().m_ndi.at (i);
m_dlPhyTransmission (params);
}
}
else if (msg->GetMessageType () == LteControlMessage::UL_DCI)
{
Ptr<UlDciLteControlMessage> dci = DynamicCast<UlDciLteControlMessage> (msg);
QueueUlDci (*dci);
}
else if (msg->GetMessageType () == LteControlMessage::RAR)
{
Ptr<RarLteControlMessage> rarMsg = DynamicCast<RarLteControlMessage> (msg);
for (std::list<RarLteControlMessage::Rar>::const_iterator it = rarMsg->RarListBegin (); it != rarMsg->RarListEnd (); ++it)
{
if (it->rarPayload.m_grant.m_ulDelay == true)
{
NS_FATAL_ERROR (" RAR delay is not yet implemented");
}
UlGrant_s ulGrant = it->rarPayload.m_grant;
// translate the UL grant in a standard UL-DCI and queue it
UlDciListElement_s dci;
dci.m_rnti = ulGrant.m_rnti;
dci.m_rbStart = ulGrant.m_rbStart;
dci.m_rbLen = ulGrant.m_rbLen;
dci.m_tbSize = ulGrant.m_tbSize;
dci.m_mcs = ulGrant.m_mcs;
dci.m_hopping = ulGrant.m_hopping;
dci.m_tpc = ulGrant.m_tpc;
dci.m_cqiRequest = ulGrant.m_cqiRequest;
dci.m_ndi = 1;
UlDciLteControlMessage msg;
msg.SetDci (dci);
QueueUlDci (msg);
}
}
it++;
}
}
SendControlChannels (ctrlMsg);
// send data frame
Ptr<PacketBurst> pb = GetPacketBurst ();
if (pb)
{
Simulator::Schedule (DL_CTRL_DELAY_FROM_SUBFRAME_START, // ctrl frame fixed to 3 symbols
&LteEnbPhy::SendDataChannels,
this,pb);
}
// trigger the MAC
m_enbPhySapUser->SubframeIndication (m_nrFrames, m_nrSubFrames);
Simulator::Schedule (Seconds (GetTti ()),
&LteEnbPhy::EndSubFrame,
this);
}
void
LteEnbPhy::SendControlChannels (std::list<Ptr<LteControlMessage> > ctrlMsgList)
{
NS_LOG_FUNCTION (this << " eNB " << m_cellId << " start tx ctrl frame");
// set the current tx power spectral density (full bandwidth)
std::vector <int> dlRb;
for (uint8_t i = 0; i < m_dlBandwidth; i++)
{
dlRb.push_back (i);
}
SetDownlinkSubChannels (dlRb);
NS_LOG_LOGIC (this << " eNB start TX CTRL");
bool pss = false;
if ((m_nrSubFrames == 1) || (m_nrSubFrames == 6))
{
pss = true;
}
m_downlinkSpectrumPhy->StartTxDlCtrlFrame (ctrlMsgList, pss);
}
void
LteEnbPhy::SendDataChannels (Ptr<PacketBurst> pb)
{
// set the current tx power spectral density
SetDownlinkSubChannelsWithPowerAllocation (m_dlDataRbMap);
// send the current burts of packets
NS_LOG_LOGIC (this << " eNB start TX DATA");
std::list<Ptr<LteControlMessage> > ctrlMsgList;
ctrlMsgList.clear ();
m_downlinkSpectrumPhy->StartTxDataFrame (pb, ctrlMsgList, DL_DATA_DURATION);
}
void
LteEnbPhy::EndSubFrame (void)
{
NS_LOG_FUNCTION (this << Simulator::Now ().GetSeconds ());
if (m_nrSubFrames == 10)
{
Simulator::ScheduleNow (&LteEnbPhy::EndFrame, this);
}
else
{
Simulator::ScheduleNow (&LteEnbPhy::StartSubFrame, this);
}
}
void
LteEnbPhy::EndFrame (void)
{
NS_LOG_FUNCTION (this << Simulator::Now ().GetSeconds ());
Simulator::ScheduleNow (&LteEnbPhy::StartFrame, this);
}
void
LteEnbPhy::GenerateCtrlCqiReport (const SpectrumValue& sinr)
{
NS_LOG_FUNCTION (this << sinr << Simulator::Now () << m_srsStartTime);
// avoid processing SRSs sent with an old SRS configuration index
if (Simulator::Now () > m_srsStartTime)
{
FfMacSchedSapProvider::SchedUlCqiInfoReqParameters ulcqi = CreateSrsCqiReport (sinr);
m_enbPhySapUser->UlCqiReport (ulcqi);
}
}
void
LteEnbPhy::GenerateDataCqiReport (const SpectrumValue& sinr)
{
NS_LOG_FUNCTION (this << sinr);
FfMacSchedSapProvider::SchedUlCqiInfoReqParameters ulcqi = CreatePuschCqiReport (sinr);
m_enbPhySapUser->UlCqiReport (ulcqi);
}
void
LteEnbPhy::ReportInterference (const SpectrumValue& interf)
{
NS_LOG_FUNCTION (this << interf);
Ptr<SpectrumValue> interfCopy = Create<SpectrumValue> (interf);
m_interferenceSampleCounter++;
if (m_interferenceSampleCounter == m_interferenceSamplePeriod)
{
m_reportInterferenceTrace (m_cellId, interfCopy);
m_interferenceSampleCounter = 0;
}
}
void
LteEnbPhy::ReportRsReceivedPower (const SpectrumValue& power)
{
// not used by eNB
}
FfMacSchedSapProvider::SchedUlCqiInfoReqParameters
LteEnbPhy::CreatePuschCqiReport (const SpectrumValue& sinr)
{
NS_LOG_FUNCTION (this << sinr);
Values::const_iterator it;
FfMacSchedSapProvider::SchedUlCqiInfoReqParameters ulcqi;
ulcqi.m_ulCqi.m_type = UlCqi_s::PUSCH;
int i = 0;
for (it = sinr.ConstValuesBegin (); it != sinr.ConstValuesEnd (); it++)
{
double sinrdb = 10 * std::log10 ((*it));
// NS_LOG_DEBUG ("ULCQI RB " << i << " value " << sinrdb);
// convert from double to fixed point notation Sxxxxxxxxxxx.xxx
int16_t sinrFp = LteFfConverter::double2fpS11dot3 (sinrdb);
ulcqi.m_ulCqi.m_sinr.push_back (sinrFp);
i++;
}
return (ulcqi);
}
void
LteEnbPhy::DoSetBandwidth (uint8_t ulBandwidth, uint8_t dlBandwidth)
{
NS_LOG_FUNCTION (this << (uint32_t) ulBandwidth << (uint32_t) dlBandwidth);
m_ulBandwidth = ulBandwidth;
m_dlBandwidth = dlBandwidth;
static const int Type0AllocationRbg[4] = {
10, // RGB size 1
26, // RGB size 2
63, // RGB size 3
110 // RGB size 4
}; // see table 7.1.6.1-1 of 36.213
for (int i = 0; i < 4; i++)
{
if (dlBandwidth < Type0AllocationRbg[i])
{
m_rbgSize = i + 1;
break;
}
}
}
void
LteEnbPhy::DoSetEarfcn (uint16_t ulEarfcn, uint16_t dlEarfcn)
{
NS_LOG_FUNCTION (this << ulEarfcn << dlEarfcn);
m_ulEarfcn = ulEarfcn;
m_dlEarfcn = dlEarfcn;
}
void
LteEnbPhy::DoAddUe (uint16_t rnti)
{
NS_LOG_FUNCTION (this << rnti);
bool success = AddUePhy (rnti);
NS_ASSERT_MSG (success, "AddUePhy() failed");
// add default P_A value
DoSetPa (rnti, 0);
}
void
LteEnbPhy::DoRemoveUe (uint16_t rnti)
{
NS_LOG_FUNCTION (this << rnti);
bool success = DeleteUePhy (rnti);
NS_ASSERT_MSG (success, "DeleteUePhy() failed");
// remove also P_A value
std::map<uint16_t, double>::iterator it = m_paMap.find (rnti);
if (it != m_paMap.end ())
{
m_paMap.erase (it);
}
}
void
LteEnbPhy::DoSetPa (uint16_t rnti, double pa)
{
NS_LOG_FUNCTION (this << rnti);
std::map<uint16_t, double>::iterator it = m_paMap.find (rnti);
if (it == m_paMap.end ())
{
m_paMap.insert (std::pair<uint16_t, double> (rnti, pa));
}
else
{
it->second = pa;
}
}
FfMacSchedSapProvider::SchedUlCqiInfoReqParameters
LteEnbPhy::CreateSrsCqiReport (const SpectrumValue& sinr)
{
NS_LOG_FUNCTION (this << sinr);
Values::const_iterator it;
FfMacSchedSapProvider::SchedUlCqiInfoReqParameters ulcqi;
ulcqi.m_ulCqi.m_type = UlCqi_s::SRS;
int i = 0;
double srsSum = 0.0;
for (it = sinr.ConstValuesBegin (); it != sinr.ConstValuesEnd (); it++)
{
double sinrdb = 10 * log10 ((*it));
// NS_LOG_DEBUG ("ULCQI RB " << i << " value " << sinrdb);
// convert from double to fixed point notation Sxxxxxxxxxxx.xxx
int16_t sinrFp = LteFfConverter::double2fpS11dot3 (sinrdb);
srsSum += (*it);
ulcqi.m_ulCqi.m_sinr.push_back (sinrFp);
i++;
}
// Insert the user generated the srs as a vendor specific parameter
NS_LOG_DEBUG (this << " ENB RX UL-CQI of " << m_srsUeOffset.at (m_currentSrsOffset));
VendorSpecificListElement_s vsp;
vsp.m_type = SRS_CQI_RNTI_VSP;
vsp.m_length = sizeof(SrsCqiRntiVsp);
Ptr<SrsCqiRntiVsp> rnti = Create <SrsCqiRntiVsp> (m_srsUeOffset.at (m_currentSrsOffset));
vsp.m_value = rnti;
ulcqi.m_vendorSpecificList.push_back (vsp);
// call SRS tracing method
CreateSrsReport (m_srsUeOffset.at (m_currentSrsOffset),
(i > 0) ? (srsSum / i) : DBL_MAX);
return (ulcqi);
}