/
nrrg.go
5744 lines (5172 loc) · 275 KB
/
nrrg.go
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
/*
Copyright © 2020 Zhengwei Gao<28912001@qq.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd
import (
"errors"
"fmt"
mapset "github.com/deckarep/golang-set"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/xuri/excelize/v2"
"github.com/zhenggao2/ngapp/nrgrid"
"github.com/zhenggao2/ngapp/utils"
"math"
"sort"
"strconv"
"strings"
"time"
)
var (
flags NrrgFlags
rgd NrrgData
minChBw int
//boldRed = color.New(color.FgHiRed).Add(color.Bold).SprintFunc()
regRed = color.New(color.FgHiRed)
//boldGreen = color.New(color.FgHiGreen).Add(color.Bold).SprintFunc()
regGreen = color.New(color.FgHiGreen)
//boldBlue = color.New(color.FgHiBlue).Add(color.Bold).SprintFunc()
regBlue = color.New(color.FgHiBlue)
//boldYellow = color.New(color.FgHiYellow).Add(color.Bold).SprintFunc()
regYellow = color.New(color.FgHiYellow)
//boldMagenta = color.New(color.FgHiMagenta).Add(color.Bold).SprintFunc()
regMagenta = color.New(color.FgHiMagenta)
//boldCyan = color.New(color.FgHiCyan).Add(color.Bold).SprintFunc()
regCyan = color.New(color.FgHiCyan)
)
type NrrgFlags struct {
gridsetting GridSettingFlags
tdduldl TddUlDlFlags
searchspace SearchSpaceFlags
dldci DlDciFlags
uldci UlDciFlags
bwp BwpFlags
rach RachFlags
dmrsCommon DmrsCommonFlags
pdsch PdschFlags
pusch PuschFlags
pucch PucchFlags
csi CsiFlags
srs SrsFlags
advanced AdvancedFlags
}
// grid setting flags
type GridSettingFlags struct {
scs string // Unified subcarrier spacing of SSB, RMSI, carrier and BWP
band string // NR frequency band, n1~n256 for FR1, n257~n512 for FR2-1 and FR2-2
_duplexMode string // Duplex mode, which can be FDD/TDD/SUL/SDL
_maxDlFreq int // Maximum DL frequency in MHz
_freqRange string // Type of frequency range, which can be FR1, FR2-1 or FR2-2
_unlicensed bool // Whether the frequency band can be used for NR-U
_ssbScs string // Subcarrier spacing of SSB
gscn int // GSCN of SSB
_ssbPattern string // SSB pattern, which can be Case A, Case B, Case C, Case D, Case E, Case F, and Case G
_kSsbScs float64 // Subcarrier spacing of k_SSB
_kSsb int // The k_SSB which is determined by the ssb-SubcarrierOffset of MIB and PBCH payload
_nCrbSsbScs float64 // Subcarrier spacing of N_CRB_SSB
_nCrbSsb int // The N_CRB_SSB which can be obtained from offsetToPointA
ssbPeriod string // Periodicity of SSB
_maxLBar int // Maximum number of SSBs in a half frame
_maxL int // Maximum number of transmitted SSBs within a half frame in a cell
candSsbIndex []int // List of candidate SSB index
_carrierScs string // The subcarrierSpacing of SCS-SpecificCarrier
bw string // Channel bandwidth of the carrier in MHz
dlArfcn int // DL ARFCN of the carrier
_carrierNumRbs int // The carrierBandwidth of SCS-SpecificCarrier
_offsetToCarrier int // The offsetToCarrier of SCS-SpecificCarrier
pci int // Physical cell identity, which can be 0~1007
_mibCommonScs string // The subCarrierSpacingCommon of MIB
rmsiCoreset0 int // The pdcch-ConfigSIB1 of MIB which determines CORESET0
_coreset0MultiplexingPat int // The multiplexing pattern of CORESET0, which can be multiplexing pattern 1/2/3
_coreset0NumRbs int // Number of RBs of CORESET0
_coreset0NumSymbs int // Number of OFDM symbols of CORESET0
_coreset0OffsetList []int // List of offset of CORESET0
_coreset0Offset int // Actual offset of CORESET0
rmsiCss0 int // The pdcch-ConfigSIB1 of MIB which determines CSS0
_css0AggLevel int // CCE aggregation level of the PDCCH candidates of CSS0
_css0NumCandidates string // Number of PDCCH candidates of CSS0
dmrsTypeAPos string // The dmrs-TypeA-Position of MIB
_sfn int // The systemFrameNumber of MIB
_hrf int // The half-frame indicator for SSB transmission
}
// common setting flags
type TddUlDlFlags struct {
_refScs string // The referenceSubcarrierSpacing of TDD-UL-DL-ConfigCommon
patPeriod []string // The dl-UL-TransmissionPeriodicityv of TDD-UL-DL-Pattern, and max length is 2
patNumDlSlots []int // The nrofDownlinkSlots of TDD-UL-DL-Pattern, and max length is 2
patNumDlSymbs []int // The nrofDownlinkSymbols of TDD-UL-DL-Pattern, and max length is 2
patNumUlSymbs []int // The nrofUplinkSymbols of TDD-UL-DL-Pattern, and max length is 2
patNumUlSlots []int // The nrofUplinkSlots of TDD-UL-DL-Pattern, and max length is 2
}
// initial/dedicated UL/DL BWP
type BwpFlags struct {
_bwpType []string
_bwpId []int
_bwpScs []string
_bwpCp []string
_bwpLocAndBw []int
_bwpStartRb []int
_bwpNumRbs []int
}
const (
// BWP tags, not the BWP-Id
INI_DL_BWP int = 0
DED_DL_BWP int = 1
INI_UL_BWP int = 2
DED_UL_BWP int = 3
// DL DCI tags
DCI_10_SIB1 int = 0 // rnti = SI-RNTI
DCI_10_MSG2 int = 1 // rnti = RA-RNTI
DCI_10_MSG4 int = 2 // rnti = TC-RNTI
DCI_11_PDSCH int = 3 // rnti = C-RNTI
DCI_10_MSGB int = 4 // rnti = MSGB-RNTI (two-steps CBRA)
// UL DCI tags
RAR_UL_MSG3 int = 0 // rnti = RA-RNTI (for RAR UL grant)
DCI_01_PUSCH int = 1 // rnti = C-RNTI
RA_UL_MSGA int = 2 // rnti = RA-RNTI, together with RAPID (two-steps CBRA)
FBRAR_UL_MSG3 int = 3 // rnti = TC-RNTI (two-steps CBRA)
// Common DMRS tags
DMRS_DCI_10_SIB1 int = 0
DMRS_DCI_10_MSG2 int = 1
DMRS_DCI_10_MSG4 int = 2
DMRS_RAR_UL_MSG3 int = 3
// NR resource tags
NR_RES_PSS int = 0
NR_RES_SSS int = 1
NR_RES_PBCH int = 2
NR_RES_SIB1 int = 3
NR_RES_PDCCH_CANDIDATE int = 400
NR_RES_PDSCH int = 5
NR_RES_CSI_RS int = 6
NR_RES_MSG2 int = 7
NR_RES_MSG4 int = 8
NR_RES_PRACH int = 10
// NR_RES_PUCCH int = 11
NR_RES_PUCCH_SR int = 90
NR_RES_PUCCH_ACK int = 91
NR_RES_PUCCH_CSI int = 92
NR_RES_PUCCH_SR_CSI int = 93
NR_RES_PUCCH_ACK_CSI int = 94
NR_RES_PUSCH int = 12
NR_RES_MSG3 int = 13
NR_RES_SRS0 int = 14
NR_RES_SRS0_2 int = 15
NR_RES_SRS1_3 int = 16
NR_RES_SRS0_1 int = 17
NR_RES_SRS0_1_2_3 int = 18
NR_RES_DMRS_PBCH int = 20
NR_RES_DMRS_SIB1 int = 21
NR_RES_DMRS_PDCCH int = 22
NR_RES_DMRS_PDSCH int = 23
NR_RES_DMRS_MSG2 int = 24
NR_RES_DMRS_MSG4 int = 25
NR_RES_DMRS_PUCCH int = 30
NR_RES_DMRS_PUSCH int = 31
NR_RES_DMRS_MSG3 int = 32
NR_RES_PTRS_PDSCH int = 40
NR_RES_PTRS_PUSCH int = 41
NR_RES_DTX int = 50
NR_RES_D int = 60
NR_RES_F int = 61
NR_RES_U int = 62
NR_RES_GB int = 63
NR_RES_CORESET0 int = 70
NR_RES_CORESET1 int = 71
NR_RES_CSI_IM int = 80
NR_RES_TRS int = 81
NR_RES_CSI_RS_CDM_GRP_0 int = 82
NR_RES_CSI_RS_CDM_GRP_1 int = 83
NR_RES_CSI_RS_CDM_GRP_2 int = 84
NR_RES_CSI_RS_CDM_GRP_3 int = 85
NR_RES_CSI_RS_CDM_GRP_4 int = 86
NR_RES_CSI_RS_CDM_GRP_5 int = 87
NR_RES_CSI_RS_CDM_GRP_6 int = 88
NR_RES_CSI_RS_CDM_GRP_7 int = 89
NR_RES_CSI_RS_CDM_GRP_8 int = 90
NR_RES_CSI_RS_CDM_GRP_9 int = 91
NR_RES_CSI_RS_CDM_GRP_10 int = 92
NR_RES_CSI_RS_CDM_GRP_11 int = 93
NR_RES_CSI_RS_CDM_GRP_12 int = 94
NR_RES_CSI_RS_CDM_GRP_13 int = 95
NR_RES_CSI_RS_CDM_GRP_14 int = 96
NR_RES_CSI_RS_CDM_GRP_15 int = 97
NR_RES_BUTT int = 999
)
// Search space
type SearchSpaceFlags struct {
_coreset1FdRes string // the frequencyDomainResources of ControlResourceSet, the length of which is 45 bits
coreset1StartCrb int // the starting CRB, which must fulfill coreset1StartCrb % 6 == 0
coreset1NumRbs int // number of RBs, which must fulfill coreset1NumRbs % 6 == 0
_coreset1Duration int // the duration of ControlResourceSet, which can be 1/2/3; fixed to 1 for simplicity
coreset1CceRegMappingType string // the cce-REG-MappingType of ControlResourceSet, which can be interleaved or nonInterleaved
coreset1RegBundleSize string // the reg-BundleSize of ControlResourceSet when cce-REG-MappingType is interleaved, which can be n2/n3/n6
coreset1InterleaverSize string // the interleaverSize of ControlResourceSet when cce-REG-MappingType is interleaved, which can be n2/n3/n6
_coreset1ShiftIndex int // the shiftIndex of ControlResourceSet when coreset1CceRegMappingType is interleaved
// coreset1PrecoderGranularity string
_ssId []int // the searchSpaceId of SearchSpace
_ssType []string // the type of search space, which can be type0a/type1/type2/type3/uss
_ssCoresetId []int // the controlResourceSetId of SearchSpace
_ssDuration []int // the duration of SearchSpace
_ssMonitoringSymbolWithinSlot []string // the monitoringSymbolsWithinSlot of SearchSpace, which can be 100/110/111 corresponding to the first 3 symbols
ssAggregationLevel []string // the aggregationLevel of SearchSpace, which can be AL1/AL2/AL4/AL8/AL16
ssNumOfPdcchCandidates []string // the nrofCandidates of SearchSpace, which can be n0/n1/n2/n3/n4/n5/n6/n8
_ssPeriodicity []string // the monitoringSlotPeriodicityAndOffset of SearchSpace
_ssSlotOffset []int // the monitoringSlotPeriodicityAndOffset of SearchSpace
}
// DL DCI 1_0/1_1 for PDSCH scheduling
type DlDciFlags struct {
_tag []string // tag of DL DCI, such as DCI_10_SIB1, DCI_10_MSG2, DCI_10_MSG4, DCI_11_PDSCH
_rnti []string // the n_RNTI used for PDSCH scrambling (38.211 7.3.1.1 Scrambling)
_muPdcch []int // the u_PDCCH used for Ks calculation (38.214 5.1.2.1 Resource allocation in time domain)
_muPdsch []int // the u_PDSCH used for Ks calculation (38.214 5.1.2.1 Resource allocation in time domain)
_indicatedBwp []int // the "Bandwidth part indicator" field of DCI 1_1, which should be 0(initial DL BWP) for DCI 1_0
tdra []int // the "Time domain resource assignment" field of DCI 1_0/1_1
_tdMappingType []string // the PDSCH mapping type, which can be typeA or typeB (38.214 Table 5.1.2.1-1: Valid S and L combinations)
_tdK0 []int // the K0 of PDSCH TDRA (38.214 5.1.2.1.1 Determination of the resource allocation table to be used for PDSCH)
_tdSliv []int // the SLIV of PDSCH TDRA (38.214 5.1.2.1 Resource allocation in time domain)
_tdStartSymb []int // the starting symbol S (38.214 5.1.2.1 Resource allocation in time domain)
_tdNumSymbs []int // the number of consecutive symbols L (38.214 5.1.2.1 Resource allocation in time domain)
_fdRaType []string // the PDSCH resource allocation type, which can be raType0 or raType1 (38.214 5.1.2.2 Resource allocation in frequency domain)
_fdBitsRaType0 int // the number of bits of the "Frequency domain resource assignment" field when raType0 is configured
_fdBitsRaType1 []int // the number of bits of the "Frequency domain resource assignment" field when raType1 is configured
_fdRa []string // the "Frequency domain resource assignment" field of DCI 1_0/1_1
fdStartRb []int // the starting VRB RB_start (38.214 5.1.2.2 Resource allocation in frequency domain)
fdNumRbs []int // the number of contiguously allocated resource blocks L_RBs (38.214 5.1.2.2 Resource allocation in frequency domain)
fdVrbPrbMappingType []string // the "VRB-to-PRB mapping" field of DCI 1_0/1_1
fdBundleSize []string // the vrb-ToPRB-Interleaver of PDSCH-Config, which can be n2 or n4
mcsCw0 []int // the "Modulation and coding scheme" field for transport block 1 of DCI 1_0/1_1
_tbsCw0 []int // the calculated TBS of transport block 1
mcsCw1 int // the "Modulation and coding scheme" field for transport block 2 of DCI 1_1
_tbsCw1 int // the calculated TBS of transport block 2
tbScalingFactor float64 // the TB scaling factor S (38.214 Table 5.1.3.2-2: Scaling factor of Ninfo for P-RNTI, RA-RNTI and MSGB-RNTI)
deltaPri int // the "PUCCH resource indicator" field of DCI 1_0/1_1
tdK1 int // the "PDSCH-to-HARQ_feedback timing indicator" field of DCI 1_0/1_1
antennaPorts int // the "Antenna port(s)" field of DCI 1_1
}
// UL DCI 0_1 or RAR UL grant for PUSCH scheduling
type UlDciFlags struct {
_tag []string // tag of UL DCI, such as RAR_UL_MSG3, DCI_01_PUSCH, RA_UL_MSGA, FBRAR_UL_MSG3
_rnti []string // the n_RNTI used for PUSCH scrambling (38.211 6.3.1.1 Scrambling)
_muPdcch []int // the u_PDCCH used for Ks calculation (38.214 6.1.2.1 Resource allocation in time domain)
_muPusch []int // the u_PUSCH used for Ks calculation (38.214 6.1.2.1 Resource allocation in time domain)
_indicatedBwp []int // the "Bandwidth part indicator" field of DCI 0_1, which should be 0(initial UL BWP) for Msg3 scheduled by RAR UL grant
tdra []int // the "Time domain resource assignment" field of DCI 0_1 or RAR UL grant
_tdMappingType []string // the PUSCH mapping type, which can be typeA or typeB (38.214 Table 6.1.2.1-1: Valid S and L combinations)
_tdK2 []int // the K2 of PUSCH TDRA (38.214 6.1.2.1.1 Determination of the resource allocation table to be used for PUSCH)
_tdDelta int // the delta for Msg3 PUSCH scheduled by RAR UL grant (38.213 8.3 PUSCH scheduled by RAR UL grant)
_tdSliv []int // the SLIV of PUSCH TDRA (38.214 6.1.2.1 Resource allocation in time domain)
_tdStartSymb []int // the starting symbol S (38.214 6.1.2.1 Resource allocation in time domain)
_tdNumSymbs []int // the number of consecutive symbols L (38.214 6.1.2.1 Resource allocation in time domain)
_fdRaType []string // the PUSCH resource allocation type, which can be raType0 or raType1 (38.214 6.1.2.2 Resource allocation in frequency domain)
fdFreqHop []string // the "Frequency hopping flag" field of DCI 0_1 or RAR UL grant (38.214 6.3 UE PUSCH frequency hopping procedure)
_fdFreqHopOffset []int // the frequency offset of 2nd hop (38.214 6.3 UE PUSCH frequency hopping procedure)
_fdBitsRaType0 int // the number of bits of the "Frequency domain resource assignment" field when raType0 is configured
_fdBitsRaType1 []int // the number of bits of the "Frequency domain resource assignment" field when raType1 is configured
_fdRa []string // the "Frequency domain resource assignment" field of DCI 0_1 or RAR UL grant
fdStartRb []int // the starting VRB RB_start (38.214 5.1.2.2 Resource allocation in frequency domain)
fdNumRbs []int // the number of contiguously allocated resource blocks L_RBs (38.214 6.1.2.2 Resource allocation in frequency domain)
mcsCw0 []int // the "Modulation and coding scheme" field for transport block 1 of DCI 0_1 or RAR UL grant
_tbs []int // the calculated TBS of transport block 1
precodingInfoNumLayers int // the "Precoding information and number of layers" field of DCI 0_1
srsResIndicator int // the "SRS resource indicator" field of DCI 0_1
antennaPorts int // the "Antenna ports" field of DCI 0_1
ptrsDmrsAssociation int // the "PTRS-DMRS association" field of DCI 0_1
}
// random access
type RachFlags struct {
prachConfId int
_raFormat string
_raX int
_raY []int
_raSubfNumFr1SlotNumFr2 []int
_raStartingSymb int
_raNumSlotsPerSubfFr1Per60KSlotFr2 int
_raNumOccasionsPerSlot int
_raDuration int
_msg1Scs string // the msg1-SubcarrierSpacing of RACH-ConfigCommon, which can be 15/30KHz for FR1, 60/120KHz for FR2-1 and 120/480/960KHz for FR2-2
msg1Fdm int
msg1FreqStart int
totNumPreambs int
ssbPerRachOccasion string
cbPreambsPerSsb int
raRespWin string
msg3Tp string
contResTimer string
_raLen int
_raNumRbs int
_raKBar int
}
// SIB1/Msg2/Msg4/Msg3 DMRS flags
type DmrsCommonFlags struct {
_tag []string // tag of DMRS, such as DCI_10_SIB1, DCI_10_MSG2, DCI_10_MSG4, RAR_UL_MSG3, FBRAR_UL_MSG3
_dmrsType []string // the dmrs-Type, which can be type1 or type2
_dmrsAddPos []string // the dmrs-AdditionalPosition, which can be pos0, pos1, pos2 or pos3
_maxLength []string // the maxLength, which can be len1 or len2
_dmrsPorts []int // DMRS antenna port(s)
_cdmGroupsWoData []int // number of CDM groups without data
_numFrontLoadSymbs []int // number of front-load OFDM symbol(s) for DMRS
_tdL [][]int // TD pattern of DMRS in a single slot
_tdL2 []int // TD pattern of DMRS in a single slot, only valid for the 2nd hop of Msg3 DMRS when intra-slot frequency hopping is enabled
_fdK [][]int // FD pattern of DMRS in a single PRB
}
// PDSCH-config and PDSCH-ServingCellConfig
type PdschFlags struct {
_pdschAggFactor string // the pdsch-AggregationFactor of PDSCH-Config, which can be n1, n2, n4 or n8
pdschRbgCfg string // the rbg-Size of PDSCH-Config, which can be config1 or config2
_rbgSize int // the Nominal RBG size P of FDRA type 0
pdschMcsTable string // the mcs-Table or mcs-Table-r17 of PDSCH-Config, which can be qam64, qam256, qam1024, qam64LowSE
pdschXOh string // the xOverhead of PDSCH-ServingCellConfig, which can be xoh0, xoh6, xoh12, xoh18
pdschMaxLayers int // the maxMIMO-Layers of PDSCH-ServingCellConfig
pdschDmrsType string // the dmrs-Type of DMRS-DownlinkConfig, which can be type1 or type2
pdschDmrsAddPos string // the dmrs-AdditionalPosition of DMRS-DownlinkConfig, which can be pos0, pos1, pos2 or pos3
pdschMaxLength string // the maxLength of DMRS-DownlinkConfig, which can be len1 or len2
_dmrsPorts []int // DMRS antenna port(s)
_cdmGroupsWoData int // number of CDM groups without data
_numFrontLoadSymbs int // number of front-load OFDM symbol(s) for DMRS
_tdL []int // TD pattern of DMRS in a single slot
_fdK []int // FD pattern of DMRS in a single PRB
pdschPtrsEnabled bool
pdschPtrsTimeDensity int
pdschPtrsFreqDensity int
pdschPtrsReOffset string
_ptrsDmrsPorts int
}
// PUSCH-config and PUSCH-ServingCellConfig
type PuschFlags struct {
puschTxCfg string // the txConfig of PUSCH-Config, which can be codebook or nonCodebook
puschCbSubset string // the codebookSubset of PUSCH-Config, which can be fullyAndPartialAndNonCoherent, partialAndNonCoherent or nonCoherent
puschCbMaxRankNonCbMaxLayers int // the maxRank of PUSCH-Config in case of CB PUSCH or the maxNumberMIMO-LayersNonCB-PUSCH in case of nonCB PUSCH
puschTp string // the transformPrecoder of PUSCH-Config
_puschAggFactor string // the pusch-AggregationFactor of PUSCH-Config, which can be n1, n2, n4 or n8
puschRbgCfg string // the rbg-Size of PUSCH-Config, which can be config1 or config2
_rbgSize int // the Nominal RBG size P of FDRA type 0
puschMcsTable string // the mcs-Table or mcs-TableTransformPrecoder of PUSCH-Config, which can be qam64, qam256 or qam64LowSE
puschXOh string // the xOverhead of PUSCH-ServingCellConfig, which can be xoh0, xoh6, xoh12, xoh18
_puschRepType string // pusch-RepTypeIndicatorDCI-0-1-r16 or pusch-RepTypeIndicatorDCI-0-2-r16 of PUSCH-Config, which can be typeA or typeB
puschDmrsType string // the dmrs-Type of DMRS-UplinkConfig, which can be type1 or type2
puschDmrsAddPos string // the dmrs-AdditionalPosition of DMRS-UplinkConfig, which can be pos0, pos1, pos2 or pos3
puschMaxLength string // the maxLength of DMRS-UplinkConfig, which can be len1 or len2
_dmrsPorts []int // DMRS antenna port(s)
_cdmGroupsWoData int // number of CDM groups without data
_numFrontLoadSymbs int // number of front-load OFDM symbol(s) for DMRS
_tdL []int // TD pattern of DMRS in a single slot
_tdL2 []int // TD pattern of DMRS in a single slot, only valid for the 2nd hop of DMRS for PUSCH when intra-slot frequency hopping is enabled
_fdK []int // FD pattern of DMRS in a single PRB
_nonCbSri []int // list of SRI(s) in case of nonCodebook transmission
_dmrsPosLBar []int // PUSCH DMRS positions l_bar when intra-slot FH is disabled, or l_bar of 1st hop when intra-slot FH is enabled
_dmrsPosLBarSecondHop []int // PUSCH DMRS positions l_bar of 2nd hop when intra-slot is enabled
puschPtrsEnabled bool
puschPtrsTimeDensity int
puschPtrsFreqDensity int
puschPtrsReOffset string
puschPtrsMaxNumPorts string
puschPtrsTimeDensityTp int
puschPtrsGrpPatternTp string
_numGrpsTp int
_samplesPerGrpTp int
_ptrsDmrsPorts []int
}
// PUCCH-Config
type PucchFlags struct {
_numSlots string // the nrofSlots of PUCCH-FormatConfig, which can be n1/n2/n4/n8
_interSlotFreqHop string // the interslotFrequencyHopping of PUSCH-FormatConfig, which can be enabled or disabled
_addDmrs bool // the additionalDMRS of PUSCH-FormatConfig
_simHarqAckCsi bool // the simultaneousHARQ-ACK-CSI of PUSCH-FormatConfig
_pucchResId []int // the pucch-ResourceId of PUCCH-Resource
_pucchFormat []string // the format of PUCCH-Resource, which can be format1/format3
//_pucchResSetId []int
_pucchStartRb []int // the startingPRB of PUCCH-Resource
_pucchIntraSlotFreqHop []string // the intraSlotFrequencyHopping of PUCCH-Resource, which can be enabled or disabled
_pucchSecondHopPrb []int // the secondHopPRB of PUCCH-Resource
_pucchNumRbs []int // the nrofPRBs of PUCCH-format1 and PUCCH-format3
_pucchStartSymb []int // the startingSymbolIndex of PUCCH-format1 and PUCCH-format3
_pucchNumSymbs []int // the nrofSymbols of PUCCH-format1 and PUCCH-format3
//_dsrResId []int
dsrPeriod string // the periodicityAndOffset of SchedulingRequestResourceConfig
dsrOffset int // the periodicityAndOffset of SchedulingRequestResourceConfig
_dsrPucchRes int // the resource of SchedulingRequestResourceConfig
}
// NZP-CSI-RS resources for channel measurement, TRS and CSI-IM resource (ZP-CSI-RS)
type CsiFlags struct {
_resSetId []int
_trsInfo []string
_resId []int
freqAllocRow []string
freqAllocBits []string
_numPorts []string
_cdmType []string
_density []string
_firstSymb []int
//_firstSymb2 []int
_startRb []int
_numRbs []int
period []string
offset []int
_tdLoc [2]nrgrid.CsiRsLocInfo
_csiImRePattern string
_csiImScLoc string
_csiImSymbLoc int
_csiImStartRb int
_csiImNumRbs int
_csiImPeriod string
_csiImOffset int
_resType string
_repCfgType string
csiRepPeriod string
csiRepOffset int
_csiRepPucchRes int
_quantity string
}
// SRS resource
type SrsFlags struct {
_resId []int
srsNumPorts []string
_srsNonCbPtrsPort []string
srsNumCombs []string
srsCombOff []int
srsCs []int
srsStartPos []int
srsNumSymbs []string
srsRepetition []string
srsFreqPos []int
srsFreqShift []int
srsCSrs []int
srsBSrs []int
srsBHop []int
_resType []string
srsPeriod []string
srsOffset []int
_mSRSb []string
_Nb []string
// SRS resource set
_resSetId []int
srsSetResIdList []string
_resSetType []string
_usage []string
}
// Advanced settings
type AdvancedFlags struct {
bestSsb int
pdcchSlotSib1 int
prachOccMsg1 int
pdcchOccMsg2 int
pdcchOccMsg4 int
//dsrRes int
}
type DataPerRf struct {
res []int // REs in a slot, ordering: subcarriers per symbol, then symbols per radio frame
tags []mapset.Set // physical signals/channels mapped per slot
}
//
type NrrgData struct {
subfPerRf int
slotPerSubf int
slotPerRf int
symbPerSlot int
symbPerSubf int
symbPerRf int
scPerRb int
scPerSymb int
scPerSlot int
scPerSubf int
scPerRf int
gridTdd map[int]DataPerRf // TDD only (key=SFN, val=data per radio frame)
tddPatEvenRf []string
tddPatOddRf []string
gridFddUl map[int]DataPerRf // FDD UL only (key=SFN, val=data per radio frame)
gridFddDl map[int]DataPerRf // FDD DL only (key=SFN, val=data per radio frame)
ssbFirstSymbs []int
trSsb map[int]bool // whether SSB is transmitted in certain SFN?
ssbSymbs map[int][]int // SSB symbols per radio frame
ssbSc0Rb0 int
coreset0Sc0Rb0 int
coreset0NumCces int
coreset0RegBundles []nrgrid.RegInfo
coreset0Cces []int
css0TdOccasions map[string][]nrgrid.Css0OccasionTd
occCss0 map[int]bool // whether PDCCH occasions for CSS0 is determined in certain SFN?
trPdcchSib1 map[int]bool // whether PDCCH for SIB1 is transmitted in certain SFN?
css0PdcchCandidates map[string][]nrgrid.Css0PdcchCandidate
coreset1NumCces int
coreset1RegBundles []nrgrid.RegInfo
coreset1Cces []int
dci10Sib1Prbs []int
dci10Msg2Prbs []int
dci10Msg4Prbs []int
dci11Prbs []int
msg4Recved bool
resMap map[int]nrgrid.NrResExt
}
// nrrgCmd represents the "nrrg" command
var nrrgCmd = &cobra.Command{
Use: "nrrg",
Short: "NR resource grid tool",
Long: `CMD "nrrg" generates NR resource grid according to configurations.`,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
viper.WriteConfig()
},
}
// gridSettingCmd represents the "nrrg gridsetting" command
var gridSettingCmd = &cobra.Command{
Use: "gridsetting",
Short: "",
Long: `CMD "nrrg gridsetting" can be used to get/set resource grid settings.`,
PreRun: func(cmd *cobra.Command, args []string) {
loadNrrgFlags()
// initialization
if flags.dmrsCommon._tdL == nil {
flags.dmrsCommon._tdL = make([][]int, 4)
}
if flags.dmrsCommon._fdK == nil {
flags.dmrsCommon._fdK = make([][]int, 4)
}
},
Run: func(cmd *cobra.Command, args []string) {
viper.WatchConfig()
// process gridsetting.band
if cmd.Flags().Lookup("band").Changed {
regGreen.Printf("[INFO]: Processing gridSetting.band...\n")
band := flags.gridsetting.band
p, exist := nrgrid.OpBands[band]
if !exist {
regRed.Printf("[ERR]: Invalid frequency band(FreqBandIndicatorNR): %v\n", band)
return
}
v, _ := strconv.Atoi(band[1:])
var fr string
if v >= 1 && v <= 256 {
fr = "FR1"
} else if v >= 257 && v <= 262 {
fr = "FR2-1" // FR2-1 24250 MHz – 52600 MHz
} else {
fr = "FR2-2" // FR2-2 52600 MHz – 71000 MHz
}
if p.DuplexMode == "TDD" {
fmt.Printf("Frequency Band Info [%v]: UL/DL: %v, %v, %v\n", band, p.UlBand, p.DuplexMode, fr)
} else if p.DuplexMode == "FDD" {
fmt.Printf("Frequency Band Info [%v]: UL: %v, DL: %v, %v, %v\n", band, p.UlBand, p.DlBand, p.DuplexMode, fr)
} else if p.DuplexMode == "SDL" {
fmt.Printf("Frequency Band Info [%v]: DL: %v, %v, %v\n", band, p.DlBand, p.DuplexMode, fr)
} else {
fmt.Printf("Frequency Band Info [%v]: UL: %v, %v, %v\n", band, p.UlBand, p.DuplexMode, fr)
}
// update band info
flags.gridsetting._duplexMode = p.DuplexMode
flags.gridsetting._maxDlFreq = p.MaxDlFreq
flags.gridsetting._freqRange = fr
if v == 46 || v == 96 || v == 102 {
flags.gridsetting._unlicensed = true
} else {
flags.gridsetting._unlicensed = false
}
// FR2-1 and FR2-2 are not supported!
//if v > 256 {
// regRed.Printf("[ERR]: FR2-1 and FR2-2 are not supported!\n")
// return
//}
// SDL and SUL are not supported!
if p.DuplexMode == "SDL" || p.DuplexMode == "SUL" {
regRed.Printf("[ERR]: %v is not supported!\n", p.DuplexMode)
return
}
// NR-U is not supported!
if band == "n46" || band == "n96" || band == "n102" {
regRed.Printf("[ERR]: NR-U [Band n46/n96/n102] is not supported!\n")
return
}
// get available SSB scs
var ssbScsSet []string
for _, v := range nrgrid.SsbRasters[band] {
ssbScsSet = append(ssbScsSet, v[0])
}
fmt.Printf("Available SSB SCS: %v\n", ssbScsSet)
// get available RMSI scs and carrier scs
var rmsiScsSet []string
var carrierScsSet []string
if flags.gridsetting._freqRange == "FR1" {
rmsiScsSet = append(rmsiScsSet, []string{"15KHz", "30KHz"}...)
scsFr1 := []int{15, 30, 60}
for _, scs := range scsFr1 {
key := fmt.Sprintf("%v_%v", band, scs)
valid := false
for _, i := range nrgrid.BandScs2BwFr1[key] {
if i > 0 {
valid = true
break
}
}
if valid {
carrierScsSet = append(carrierScsSet, fmt.Sprintf("%vKHz", scs))
}
}
} else if flags.gridsetting._freqRange == "FR2-1" {
rmsiScsSet = append(rmsiScsSet, []string{"60KHz", "120KHz"}...)
carrierScsSet = append(carrierScsSet, []string{"60KHz", "120KHz"}...)
} else if flags.gridsetting._freqRange == "FR2-2" {
rmsiScsSet = ssbScsSet
carrierScsSet = append(carrierScsSet, []string{"120KHz", "480KHz", "960KHz"}...)
}
fmt.Printf("Available RMSI SCS(subcarrierSpacingCommon of MIB): %v\n", rmsiScsSet)
fmt.Printf("Available Carrier SCS(subcarrierSpacing of SCS-SpecificCarrier): %v\n", carrierScsSet)
}
// process gridsetting.scs
if cmd.Flags().Lookup("scs").Changed {
regGreen.Printf("[INFO]: Processing gridSetting.scs...\n")
// set SCS for SSB/RMSI/Carrier
flags.gridsetting._ssbScs = flags.gridsetting.scs
flags.gridsetting._carrierScs = flags.gridsetting.scs
if flags.gridsetting._freqRange == "FR2-2" {
// refer to 38.311 vh30
// subCarrierSpacingCommon of MIB
// For operation with shared spectrum channel access in FR1 (see 37.213 [48]) and for operation in FR2-2, the subcarrier spacing for SIB1, Msg.2/4 and MsgB for initial access, paging and broadcast SI-messages is same as that for the corresponding SSB.
flags.gridsetting._mibCommonScs = flags.gridsetting._ssbScs
} else {
flags.gridsetting._mibCommonScs = flags.gridsetting.scs
}
// update SSB pattern
band := flags.gridsetting.band
scs := flags.gridsetting._ssbScs
for _, v := range nrgrid.SsbRasters[band] {
if v[0] == scs {
fmt.Printf("SSB Raster Info: %v\n", v)
flags.gridsetting._ssbPattern = v[1]
}
}
// update SSB burst (refer to 3GPP TS 38.213 vh40: 4.1 Cell search)
pat := flags.gridsetting._ssbPattern
dm := flags.gridsetting._duplexMode
freq := flags.gridsetting._maxDlFreq
nru := flags.gridsetting._unlicensed
if (pat == "Case A" && !nru) || pat == "Case B" || (pat == "Case C" && !nru && dm == "FDD") {
if freq <= 3000 {
flags.gridsetting._maxLBar = 4
flags.gridsetting._maxL = 4
} else {
flags.gridsetting._maxLBar = 8
flags.gridsetting._maxL = 8
}
} else if pat == "Case C" && !nru && dm == "TDD" {
if freq < 1880 {
flags.gridsetting._maxLBar = 4
flags.gridsetting._maxL = 4
} else {
flags.gridsetting._maxLBar = 8
flags.gridsetting._maxL = 8
}
} else if pat == "Case A" && nru {
flags.gridsetting._maxLBar = 10
flags.gridsetting._maxL = 8
} else if pat == "Case C" && nru {
flags.gridsetting._maxLBar = 20
flags.gridsetting._maxL = 8
} else {
// pat == "Case D/E or Case F/G(for FR2-2)
flags.gridsetting._maxLBar = 64
flags.gridsetting._maxL = 64
}
// update refScs of TDD-UL-DL-Config
flags.tdduldl._refScs = scs
// update u_PDCCH/u_PDSCH/u_PUSCH in DCI 0_1/1_1 and Msg3 PUSCH
u := nrgrid.Scs2Mu[flags.gridsetting._carrierScs]
flags.uldci._muPdcch = []int{u, u}
flags.uldci._muPusch = []int{u, u}
flags.uldci._tdDelta = nrgrid.PuschTimeAllocMsg3K2Delta[flags.gridsetting._carrierScs]
// update SCS of initial UL BWP and dedicated UL/DL BWP
flags.bwp._bwpScs[DED_DL_BWP] = flags.gridsetting._carrierScs
flags.bwp._bwpScs[INI_UL_BWP] = flags.gridsetting._carrierScs
flags.bwp._bwpScs[DED_UL_BWP] = flags.gridsetting._carrierScs
// get SR periodicity and offset(38.331 vh30 periodicityAndOffset and periodicityAndOffset-r17 of SchedulingRequestResourceConfig)
fmt.Printf("Available SR periodicity: %v\n", nrgrid.SrPeriodSet[flags.gridsetting._carrierScs])
// update TRS periodicity (2023/2/20: For simplicity, TRS is not supported!)
fmt.Printf("Available TRS periodicity: %v\n", []string{"slots10", "slots20", "slots40", "slots80", "slots160", "slots320", "slots640"}[u:u+4])
// update u_PDCCH/u_PDSCH for SIB1/Msg2/Msg4
u = nrgrid.Scs2Mu[flags.gridsetting._mibCommonScs]
flags.dldci._muPdcch = []int{u, u, u, u}
flags.dldci._muPdsch = []int{u, u, u, u}
// update SCS for initial DL BWP
// refer to 3GPP TS 38.331 vh30: subcarrierSpacing of BWP
// For the initial DL BWP and operation in licensed spectrum this field has the same value as the field subCarrierSpacingCommon in MIB of the same serving cell.
flags.bwp._bwpScs[INI_DL_BWP] = flags.gridsetting._mibCommonScs
// update ra-ResponseWindow
// refer to 3GPP TS 38.331 vh30: ra-ResponseWindow of RACH-ConfigGeneric
// The network configures a value lower than or equal to 10 ms when Msg2 is transmitted in licensed spectrum and a value lower than or equal to 40 ms when Msg2 is transmitted with shared spectrum channel access (see TS 38.321 [3], clause 5.1.4).
var rarWinSet []string
switch flags.gridsetting._mibCommonScs {
case "15KHz":
rarWinSet = append(rarWinSet, []string{"sl1", "sl2", "sl4", "sl8", "sl10"}...)
case "30KHz":
rarWinSet = append(rarWinSet, []string{"sl1", "sl2", "sl4", "sl8", "sl10", "sl20"}...)
case "60KHz":
rarWinSet = append(rarWinSet, []string{"sl1", "sl2", "sl4", "sl8", "sl10", "sl20", "sl40"}...)
case "120KHz":
rarWinSet = append(rarWinSet, []string{"sl1", "sl2", "sl4", "sl8", "sl10", "sl20", "sl40", "sl80"}...)
}
fmt.Printf("Available ra-ResponseWindow: %v\n", rarWinSet)
}
// process gridsetting.bw
if cmd.Flags().Lookup("bw").Changed {
regGreen.Printf("[INFO]: Processing gridSetting.bw...\n")
// update N_RB of carrier and initial DL BWP
fr := flags.gridsetting._freqRange
bw := flags.gridsetting.bw
carrierScsVal, _ := strconv.Atoi(flags.gridsetting._carrierScs[:len(flags.gridsetting._carrierScs)-3])
var idx int
if fr == "FR1" {
idx = utils.IndexStr(nrgrid.BwSetFr1, bw)
} else if fr == "FR2-1" {
idx = utils.IndexStr(nrgrid.BwSetFr21, bw)
} else if fr == "FR2-2" {
idx = utils.IndexStr(nrgrid.BwSetFr22, bw)
}
if idx < 0 {
regRed.Printf("[ERR]: Invalid carrier bandwidth for %v: carrierBw=%v\n", fr, bw)
return
}
flags.gridsetting._carrierNumRbs = nrgrid.NrbFr1[carrierScsVal][idx]
// update RB_Start and L_RB for initial UL BWP and dedicated UL/DL BWP
flags.bwp._bwpStartRb[DED_DL_BWP] = 0
flags.bwp._bwpNumRbs[DED_DL_BWP] = flags.gridsetting._carrierNumRbs
flags.bwp._bwpLocAndBw[DED_DL_BWP], _ = makeRiv(flags.gridsetting._carrierNumRbs, 0, 275)
flags.bwp._bwpStartRb[INI_UL_BWP] = 0
flags.bwp._bwpNumRbs[INI_UL_BWP] = flags.gridsetting._carrierNumRbs
flags.bwp._bwpLocAndBw[INI_UL_BWP], _ = makeRiv(flags.gridsetting._carrierNumRbs, 0, 275)
flags.bwp._bwpStartRb[DED_UL_BWP] = 0
flags.bwp._bwpNumRbs[DED_UL_BWP] = flags.gridsetting._carrierNumRbs
flags.bwp._bwpLocAndBw[DED_UL_BWP], _ = makeRiv(flags.gridsetting._carrierNumRbs, 0, 275)
// update number of bits of FDRA field
bitsRaType0Dl := utils.CeilInt(float64(flags.gridsetting._carrierNumRbs) / float64(flags.pdsch._rbgSize))
bitsRaType0Ul := utils.CeilInt(float64(flags.gridsetting._carrierNumRbs) / float64(flags.pusch._rbgSize))
bitsRaType1Bwp0 := utils.CeilInt(math.Log2(float64(flags.gridsetting._coreset0NumRbs) * (float64(flags.gridsetting._coreset0NumRbs) + 1) / 2))
bitsRaType1Bwp1 := utils.CeilInt(math.Log2(float64(flags.gridsetting._carrierNumRbs) * (float64(flags.gridsetting._carrierNumRbs) + 1) / 2))
flags.dldci._fdBitsRaType0 = bitsRaType0Dl
flags.dldci._fdBitsRaType1 = []int{}
for i, _ := range flags.dldci._rnti {
if i == DCI_10_SIB1 || i == DCI_10_MSG2 || i == DCI_10_MSG4 {
flags.dldci._fdBitsRaType1 = append(flags.dldci._fdBitsRaType1, bitsRaType1Bwp0)
} else if i == DCI_11_PDSCH {
flags.dldci._fdBitsRaType1 = append(flags.dldci._fdBitsRaType1, bitsRaType1Bwp1)
} else if i == DCI_10_MSGB {
flags.dldci._fdBitsRaType1 = append(flags.dldci._fdBitsRaType1, bitsRaType1Bwp0)
}
}
flags.uldci._fdBitsRaType0 = bitsRaType0Ul
flags.uldci._fdBitsRaType1 = []int{}
for i, _ := range flags.uldci._rnti {
if i == RAR_UL_MSG3 || i == FBRAR_UL_MSG3 {
flags.uldci._fdBitsRaType1 = append(flags.uldci._fdBitsRaType1, 14)
} else if i == DCI_01_PUSCH {
flags.uldci._fdBitsRaType1 = append(flags.uldci._fdBitsRaType1, bitsRaType1Bwp1)
} else if i == RA_UL_MSGA {
// For MsgA, FDRA is signalling via msgA-PUSCH-Config-r16: frequencyStartMsgA-PUSCH-r16 and nrofPRBs-PerMsgA-PO-r16
flags.uldci._fdBitsRaType1 = append(flags.uldci._fdBitsRaType1, -1)
}
}
// update frequency offset for 2nd hop when intra-slot frequency hopping is enabled for PUSCH
// refer to 38.213 vh40
// Table 8.3-1: Frequency offset for second hop of PUSCH transmission with frequency hopping scheduled by RAR UL grant or of Msg3 PUSCH retransmission
// refer to 38.214 vh40
// 6.3.1 Frequency hopping for PUSCH repetition Type A and for TB processing over multiple slots
// For simplicity, assume that only codepoint 0 or 00 is used!
flags.uldci._fdFreqHopOffset = []int{}
for range flags.uldci._rnti {
flags.uldci._fdFreqHopOffset = append(flags.uldci._fdFreqHopOffset, utils.FloorInt(float64(flags.gridsetting._carrierNumRbs)/2))
}
}
// process gridsetting.dmrsTypeAPos
if cmd.Flags().Lookup("dmrsTypeAPos").Changed {
regGreen.Printf("[INFO]: Processing gridSetting.dmrsTypeAPos...\n")
dmrsTypeAPos := flags.gridsetting.dmrsTypeAPos
// validate CORESET duration
// refer to 3GPP TS 38.211 vf80: 7.3.2.2 Control-resource set (CORESET)
// N_CORESET_symb = 3 is supported only if the higher-layer parameter dmrs-TypeA-Position equals 3;
if flags.gridsetting._coreset0NumSymbs == 3 && dmrsTypeAPos != "pos3" {
fmt.Printf("coreset0NumSymbs can be 3 only if dmrs-TypeA-Position is pos3! (corest0NumSymbs=%v,dmrsTypeAPos=%v)\n", flags.gridsetting._coreset0NumSymbs, flags.gridsetting.dmrsTypeAPos)
return
}
if flags.searchspace._coreset1Duration == 3 && dmrsTypeAPos != "pos3" {
fmt.Printf("coreset1Duration can be 3 only if dmrs-TypeA-Position is pos3! (coreset1Duration=%v,dmrsTypeAPos=%v)\n", flags.searchspace._coreset1Duration, flags.gridsetting.dmrsTypeAPos)
return
}
// validate TDRA of DCI 1_0/1_1
err := validatePdsch()
if err != nil {
regRed.Printf("[ERR]: " + err.Error())
return
}
// validate TDRA of Msg3 PUSCH scheduled by RAR Msg2
err = validatePusch()
if err != nil {
regRed.Printf("[ERR]: " + err.Error())
return
}
}
// process gridsetting.pci
if cmd.Flags().Lookup("pci").Changed {
flags.searchspace._coreset1ShiftIndex = flags.gridsetting.pci
}
regGreen.Printf("[INFO]: Post-processing...\n")
// update rach info
err := updateRach()
if err != nil {
regRed.Printf("[ERR]: %v\n", err.Error())
return
}
// update n_CRB_SSB/k_SSB
updateKSsbAndNCrbSsb()
// validate CORESET0
err = validateCoreset0()
if err != nil {
regRed.Printf("[ERR]: %s\n", err.Error())
return
}
// validate CSS0
err = validateCss0()
if err != nil {
regRed.Printf("[ERR]: %s\n", err.Error())
return
}
// validate search space
err = validateSearchSpace()
if err != nil {
regRed.Printf("[ERR]: %s\n", err.Error())
return
}
// validate PUCCH
err = validatePucch()
if err != nil {
regRed.Printf("[ERR]: %s\n", err.Error())
return
}
// validate CSI-RS
err = validateCsi()
if err != nil {
regRed.Printf("[ERR]: %s\n", err.Error())
return
}
laPrint(cmd, args)
viper.WriteConfig()
// trigger NRRG simulation
regGreen.Printf("[INFO]: Init NRRG data...\n")
err = initNrrgData()
if err != nil {
regRed.Printf("[ERR]: %s\n", err.Error())
return
}
// trigger NRRG simulation
regGreen.Printf("[INFO]: Start 5GNR simulation...\n")
sfn := flags.gridsetting._sfn
slot := 0
// DL always-on transmission
regYellow.Printf("[5GNR SIM]Init always-on-transmission(SSB/PDCCH/SIB1) @ [SFN=%d, Slot=%d]\n", sfn, slot)
err = alwaysOnTr(sfn, slot)
if err != nil {
regRed.Printf("[ERR]: %s\n", err.Error())
return
}
/*
// receiving SIB1
regYellow.Printf("[5GNR SIM]UE recv SSB/SIB1 @ [SFN=%d]\n", sfn)
sfn, slot, err = recvSib1(sfn)
if err != nil {
regRed.Printf("[ERR]: %s\n", err.Error())
return
}
// sending Msg1(PRACH)
regYellow.Printf("[5GNR SIM]UE send PRACH(Msg1) @ [SFN=%d, Slot=%d]\n", sfn, slot)
sfn, slot, err = sendMsg1(sfn, slot)
if err != nil {
regRed.Printf("[ERR]: %s\n", err.Error())
return
}