Merge "merge of Natalia - change rnib errors"
[ric-plt/e2mgr.git] / E2Manager / handlers / enb_load_information_to_protobuf_test.go
1 /*******************************************************************************
2  *
3  *   Copyright (c) 2019 AT&T Intellectual Property.
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  *
17  *******************************************************************************/
18 package handlers
19
20 import (
21         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
22 )
23
24 /*
25 Test permutations of eNB Load Information to protobuf
26 */
27
28 type LoadInformationTestCaseName string
29
30 const LoadTimestamp = 1257894000000000000
31
32 const (
33         SingleCellWithCellIdOnly     LoadInformationTestCaseName = "SINGLE CELL WITH CELL ID ONLY"   //base
34         SingleCellPartiallyPopulated LoadInformationTestCaseName = "SINGLE CELL PARTIALLY POPULATED" //8
35         TwoCellsFullInfo             LoadInformationTestCaseName = "TWO CELLS FULLY POPULATED"       //13
36 )
37
38 type LoadInformationTestCase struct {
39         loadInformationTestCaseName LoadInformationTestCaseName
40         packedUperPdu               string
41         packedAperPdu               string
42         expectedLoadInformation     *entities.RanLoadInformation
43 }
44
45 var testCases = []LoadInformationTestCase{
46         {
47                 loadInformationTestCaseName: SingleCellWithCellIdOnly,
48                 packedAperPdu:               "000240140000010006400d00000740080002f8290007ab50",
49                 packedUperPdu:               "004898000400190d0000074200017c148003d5a80000",
50                 expectedLoadInformation:     GenerateSingleCellWithCellIdOnlyRanLoadInformation(),
51         },
52         {
53                 loadInformationTestCaseName: SingleCellPartiallyPopulated,
54                 packedAperPdu:               "", //TODO: populate and USE
55                 packedUperPdu:               "004b380004001961000007571e017c148003d5a8205000017c180003d5a875555003331420008007a85801f07c1f07c41f07c1e07801f2020000c680b0003220664102800d8908020000be0c4001ead4016e007ab50100002f8320067ab5005b8c1ead5070190c000000",
56                 expectedLoadInformation:     GenerateSingleCellPartiallyPopulatedLoadInformation(),
57         },
58         {
59                 loadInformationTestCaseName: TwoCellsFullInfo,
60                 packedAperPdu:               "", //TODO: populate and USE
61                 packedUperPdu:               "004c07080004001980da0100075bde017c148003d5a8205000017c180003d5a875555403331420000012883a0003547400cd20002801ea16007c1f07c1f107c1f0781e007c80800031a02c000c88199040a00352083669190000d8908020000be0c4001ead4016e007ab50100002f8320067ab5005b8c1ead5070190c00001d637805f220000f56a081400005f020000f56a1d555400ccc508002801ea16007c1f07c1f107c1f0781e007c80800031a02c000c88199040a00352083669190000d8908020000be044001ead4016e007ab50100002f8120067ab5005b8c1ead5070190c00000",
62                 expectedLoadInformation:     GenerateTwoCellsFullyPopulatedRanLoadInformation(),
63         },
64 }
65
66 //func TestExtractAndBuildRanLoadInformation(t *testing.T) {
67 //      logger, _ := logger.InitLogger(logger.InfoLevel)
68 //
69 //      for _, tc := range testCases {
70 //              t.Run(string(tc.loadInformationTestCaseName), func(t *testing.T) {
71 //
72 //                      var payload []byte
73 //                      _, err := fmt.Sscanf(tc.packedUperPdu, "%x", &payload)
74 //
75 //                      if err != nil {
76 //                              t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err)
77 //                      }
78 //
79 //                      pdu, err := unpackX2apPduUPer(logger, MaxAsn1CodecAllocationBufferSize, len(payload), payload, MaxAsn1CodecMessageBufferSize)
80 //
81 //                      actualRanLoadInformation := &entities.RanLoadInformation{LoadTimestamp: LoadTimestamp}
82 //
83 //                      err = extractAndBuildRanLoadInformation(pdu, actualRanLoadInformation)
84 //
85 //                      if err != nil {
86 //                              t.Errorf("want: success, got: error: %v\n", err)
87 //                      }
88 //
89 //                      if !assert.Equal(t, tc.expectedLoadInformation, actualRanLoadInformation) {
90 //                              t.Errorf("want: %v, got: %v", tc.expectedLoadInformation, actualRanLoadInformation)
91 //                      }
92 //              })
93 //      }
94 //}
95
96 func GenerateSingleCellWithCellIdOnlyRanLoadInformation() *entities.RanLoadInformation {
97         return &entities.RanLoadInformation{
98                 LoadTimestamp: LoadTimestamp,
99                 CellLoadInfos: []*entities.CellLoadInformation{
100                         {CellId: "02f829:0007ab50"},
101                 },
102         }
103 }
104
105 func GenerateSingleCellPartiallyPopulatedLoadInformation() *entities.RanLoadInformation {
106
107         ulInterferenceOverloadIndications := []entities.UlInterferenceOverloadIndication{
108                 entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE,
109                 entities.UlInterferenceOverloadIndication_MEDIUM_INTERFERENCE,
110                 entities.UlInterferenceOverloadIndication_LOW_INTERFERENCE,
111         }
112
113         rntp := entities.RelativeNarrowbandTxPower{
114                 RntpPerPrb:                       "cc",
115                 RntpThreshold:                    entities.RntpThreshold_NEG_6,
116                 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
117                 PB:                               2,
118                 PdcchInterferenceImpact:          1,
119         }
120
121         absInformation := entities.AbsInformation{
122                 Mode:                             entities.AbsInformationMode_ABS_INFO_FDD,
123                 AbsPatternInfo:                   "07c1f07c1f",
124                 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
125                 MeasurementSubset:                "83e0f83c0f",
126         }
127
128         extendedUlInterferenceOverloadInfo := entities.ExtendedUlInterferenceOverloadInfo{
129                 AssociatedSubframes:                       "c8",
130                 ExtendedUlInterferenceOverloadIndications: ulInterferenceOverloadIndications,
131         }
132
133         compInformationStartTime := entities.StartTime{
134                 StartSfn:            50,
135                 StartSubframeNumber: 3,
136         }
137
138         return &entities.RanLoadInformation{
139                 LoadTimestamp: LoadTimestamp,
140                 CellLoadInfos: []*entities.CellLoadInformation{
141                         {
142                                 CellId:                             "02f829:0007ab50",
143                                 UlInterferenceOverloadIndications:  ulInterferenceOverloadIndications,
144                                 UlHighInterferenceInfos:            []*entities.UlHighInterferenceInformation{{TargetCellId: "02f830:0007ab50", UlHighInterferenceIndication: "aaaa"}},
145                                 RelativeNarrowbandTxPower:          &rntp,
146                                 AbsInformation:                     &absInformation,
147                                 InvokeIndication:                   entities.InvokeIndication_ABS_INFORMATION,
148                                 IntendedUlDlConfiguration:          entities.SubframeAssignment_SA6,
149                                 ExtendedUlInterferenceOverloadInfo: &extendedUlInterferenceOverloadInfo,
150                                 CompInformation: &entities.CompInformation{
151                                         CompInformationItems: []*entities.CompInformationItem{
152                                                 {
153                                                         CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "02f831:0007ab50", CompHypothesis: "e007ab50"}},
154                                                         BenefitMetric:      -99,
155                                                 },
156                                                 {
157                                                         CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "02f832:0067ab50", CompHypothesis: "e307ab50"}},
158                                                         BenefitMetric:      30,
159                                                 },
160                                         },
161                                         CompInformationStartTime: &compInformationStartTime,
162                                 },
163                         },
164                 },
165         }
166
167 }
168
169 func GenerateTwoCellsFullyPopulatedRanLoadInformation() *entities.RanLoadInformation {
170
171         ulInterferenceOverloadIndications := []entities.UlInterferenceOverloadIndication{
172                 entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE,
173                 entities.UlInterferenceOverloadIndication_MEDIUM_INTERFERENCE,
174                 entities.UlInterferenceOverloadIndication_LOW_INTERFERENCE,
175         }
176
177         rntp := entities.RelativeNarrowbandTxPower{
178                 RntpPerPrb:                       "cc",
179                 RntpThreshold:                    entities.RntpThreshold_NEG_6,
180                 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
181                 PB:                               2,
182                 PdcchInterferenceImpact:          1,
183         }
184
185         enhancedRntp := entities.EnhancedRntp{
186                 EnhancedRntpBitmap:     "aa38",
187                 RntpHighPowerThreshold: entities.RntpThreshold_NEG_4,
188                 EnhancedRntpStartTime:  &entities.StartTime{StartSfn: 51, StartSubframeNumber: 9},
189         }
190
191         rntpWithEnhanced := rntp
192         rntpWithEnhanced.EnhancedRntp = &enhancedRntp
193
194         absInformation := entities.AbsInformation{
195                 Mode:                             entities.AbsInformationMode_ABS_INFO_FDD,
196                 AbsPatternInfo:                   "07c1f07c1f",
197                 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
198                 MeasurementSubset:                "83e0f83c0f",
199         }
200
201         extendedUlInterferenceOverloadInfo := entities.ExtendedUlInterferenceOverloadInfo{
202                 AssociatedSubframes:                       "c8",
203                 ExtendedUlInterferenceOverloadIndications: ulInterferenceOverloadIndications,
204         }
205
206         compInformationStartTime := entities.StartTime{
207                 StartSfn:            50,
208                 StartSubframeNumber: 3,
209         }
210
211         dynamicDlTransmissionInformation := entities.DynamicDlTransmissionInformation{
212                 State:             entities.NaicsState_NAICS_ACTIVE,
213                 TransmissionModes: "cd",
214                 PB:                0,
215                 PAList:            []entities.PA{entities.PA_DB_NEG_1_DOT_77, entities.PA_DB_NEG_3},
216         }
217
218         return &entities.RanLoadInformation{
219                 LoadTimestamp: LoadTimestamp,
220                 CellLoadInfos: []*entities.CellLoadInformation{
221                         {
222                                 CellId:                             "02f829:0007ab50",
223                                 UlInterferenceOverloadIndications:  ulInterferenceOverloadIndications,
224                                 UlHighInterferenceInfos:            []*entities.UlHighInterferenceInformation{{TargetCellId: "02f830:0007ab50", UlHighInterferenceIndication: "aaaa"}},
225                                 RelativeNarrowbandTxPower:          &rntpWithEnhanced,
226                                 AbsInformation:                     &absInformation,
227                                 InvokeIndication:                   entities.InvokeIndication_ABS_INFORMATION,
228                                 IntendedUlDlConfiguration:          entities.SubframeAssignment_SA6,
229                                 ExtendedUlInterferenceOverloadInfo: &extendedUlInterferenceOverloadInfo,
230                                 CompInformation: &entities.CompInformation{
231                                         CompInformationItems: []*entities.CompInformationItem{
232                                                 {
233                                                         CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "02f831:0007ab50", CompHypothesis: "e007ab50"}},
234                                                         BenefitMetric:      -99,
235                                                 },
236                                                 {
237                                                         CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "02f832:0067ab50", CompHypothesis: "e307ab50"}},
238                                                         BenefitMetric:      30,
239                                                 },
240                                         },
241                                         CompInformationStartTime: &compInformationStartTime,
242                                 },
243                                 DynamicDlTransmissionInformation: &dynamicDlTransmissionInformation,
244                         },
245                         {
246                                 CellId:                             "02f910:0007ab50",
247                                 UlInterferenceOverloadIndications:  ulInterferenceOverloadIndications,
248                                 UlHighInterferenceInfos:            []*entities.UlHighInterferenceInformation{{TargetCellId: "02f810:0007ab50", UlHighInterferenceIndication: "aaaa"}},
249                                 RelativeNarrowbandTxPower:          &rntp,
250                                 AbsInformation:                     &absInformation,
251                                 InvokeIndication:                   entities.InvokeIndication_ABS_INFORMATION,
252                                 IntendedUlDlConfiguration:          entities.SubframeAssignment_SA6,
253                                 ExtendedUlInterferenceOverloadInfo: &extendedUlInterferenceOverloadInfo,
254                                 CompInformation: &entities.CompInformation{
255                                         CompInformationItems: []*entities.CompInformationItem{
256                                                 {
257                                                         CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "02f811:0007ab50", CompHypothesis: "e007ab50"}},
258                                                         BenefitMetric:      -99,
259                                                 },
260                                                 {
261                                                         CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "02f812:0067ab50", CompHypothesis: "e307ab50"}},
262                                                         BenefitMetric:      30,
263                                                 },
264                                         },
265                                         CompInformationStartTime: &compInformationStartTime,
266                                 },
267                                 DynamicDlTransmissionInformation: &dynamicDlTransmissionInformation,
268                         },
269                 },
270         }
271 }