1 /*******************************************************************************
3 * Copyright (c) 2019 AT&T Intellectual Property.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 *******************************************************************************/
20 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
21 * platform project (RICP).
35 * Unpack a response returned from RAN.
36 * Verify it matches the want pdu.
39 func TestResourceStatusFailureConverter(t *testing.T) {
40 logger, _ := logger.InitLogger(logger.DebugLevel)
41 unpacker := NewX2apPduUnpacker(logger, e2pdus.MaxAsn1CodecMessageBufferSize)
42 rsFailureConverter := NewResourceStatusFailureConverter(unpacker)
44 var testCases = []struct {
49 response: "ENB1_Measurement_ID: 15, ENB2_Measurement_ID: 13, MeasurementInitiationResults:[ CellId: 02f829:0007ab50, MeasurementFailureCauses: [ MeasurementFailedReportCharacteristics: 00000007 ] ]",
51 UnsuccessfulOutcome ::= {
53 criticality: 0 (reject)
54 value: ResourceStatusFailure ::= {
55 protocolIEs: ProtocolIE-Container ::= {
56 ResourceStatusFailure-IEs ::= {
58 criticality: 0 (reject)
61 ResourceStatusFailure-IEs ::= {
63 criticality: 0 (reject)
66 ResourceStatusFailure-IEs ::= {
68 criticality: 1 (ignore)
69 value: 1 (hardware-failure)
71 ResourceStatusFailure-IEs ::= {
73 criticality: 1 (ignore)
74 value: CompleteFailureCauseInformation-List ::= {
75 ProtocolIE-Single-Container ::= {
77 criticality: 1 (ignore)
78 value: CompleteFailureCauseInformation-Item ::= {
80 pLMN-Identity: 02 F8 29
81 eUTRANcellIdentifier: 00 07 AB 50 (4 bits unused)
83 measurementFailureCause-List: MeasurementFailureCause-List ::= {
84 ProtocolIE-Single-Container ::= {
86 criticality: 1 (ignore)
87 value: MeasurementFailureCause-Item ::= {
88 measurementFailedReportCharacteristics: 00 00 00 07
89 cause: 0 (transfer-syntax-error)
101 packedPdu: "400900320000040027000300000e0028000300000c00054001620044401800004540130002f8290007ab500000434006000000000740",
104 response: "ENB1_Measurement_ID: 1, ENB2_Measurement_ID: 74, MeasurementInitiationResults:[ ]",
106 UnsuccessfulOutcome ::= {
108 criticality: 0 (reject)
109 value: ResourceStatusFailure ::= {
110 protocolIEs: ProtocolIE-Container ::= {
111 ResourceStatusFailure-IEs ::= {
113 criticality: 0 (reject)
116 ResourceStatusFailure-IEs ::= {
118 criticality: 0 (reject)
121 ResourceStatusFailure-IEs ::= {
123 criticality: 1 (ignore)
124 value: 21 (unspecified)
130 packedPdu: "400900170000030027000300000000280003000049000540020a80",
134 for _, tc := range testCases {
135 t.Run(tc.packedPdu, func(t *testing.T) {
138 _, err := fmt.Sscanf(tc.packedPdu, "%x", &payload)
140 t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err)
143 response, err := rsFailureConverter.Convert(payload)
145 t.Errorf("want: success, got: unpack failed. Error: %v\n", err)
148 got := response.String()
149 if len(tc.response) != len(got) {
150 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", tc.response, response)
152 if strings.Compare(tc.response, got) != 0 {
153 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", tc.response, got)
161 func TestResourceStatusFailureConverterError(t *testing.T) {
162 logger, _ := logger.InitLogger(logger.InfoLevel)
163 unpacker := NewX2apPduUnpacker(logger, e2pdus.MaxAsn1CodecMessageBufferSize)
164 rsFailureConverter := NewResourceStatusFailureConverter(unpacker)
165 wantError := "unpacking error: #src/asn1codec_utils.c.unpack_pdu_aux - Failed to decode E2AP-PDU (consumed 0), error = 0 Success"
166 //--------------------2006002a
167 inputPayloadAsStr := "2006002b000002001500080002f82900007a8000140017000000630002f8290007ab50102002f829000001000133"
169 _, err := fmt.Sscanf(inputPayloadAsStr, "%x", &payload)
171 t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err)
174 _, err = rsFailureConverter.Convert(payload)
176 if 0 != strings.Compare(fmt.Sprintf("%s", err), wantError) {
177 t.Errorf("want failure: %s, got: %s", wantError, err)
180 t.Errorf("want failure: %s, got: success", wantError)
185 func TestResourceStatusFailureConverterPduOfSuccess(t *testing.T) {
186 logger, _ := logger.InitLogger(logger.InfoLevel)
187 unpacker := NewX2apPduUnpacker(logger, e2pdus.MaxAsn1CodecMessageBufferSize)
188 rsFailureConverter := NewResourceStatusFailureConverter(unpacker)
189 wantError := "unexpected PDU, 2"
190 inputPayloadAsStr := "200900220000030027000300000e0028000300000c0041400d00004240080002f8290007ab50"
192 _, err := fmt.Sscanf(inputPayloadAsStr, "%x", &payload)
194 t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err)
197 _, err = rsFailureConverter.Convert(payload)
199 if 0 != strings.Compare(fmt.Sprintf("%s", err), wantError) {
200 t.Errorf("want failure: %s, got: %s", wantError, err)
203 t.Errorf("want failure: %s, got: success", wantError)
208 func TestResourceStatusFailureConverterWrongPdu(t *testing.T) {
209 logger, _ := logger.InitLogger(logger.InfoLevel)
210 unpacker := NewX2apPduUnpacker(logger, e2pdus.MaxAsn1CodecMessageBufferSize)
211 rsFailureConverter := NewResourceStatusFailureConverter(unpacker)
212 wantError := "unexpected PDU - not a resource status failure"
213 inputPayloadAsStr := "4006001a0000030005400200000016400100001140087821a00000008040"
215 _, err := fmt.Sscanf(inputPayloadAsStr, "%x", &payload)
217 t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err)
220 _, err = rsFailureConverter.Convert(payload)
222 if 0 != strings.Compare(fmt.Sprintf("%s", err), wantError) {
223 t.Errorf("want failure: %s, got: %s", wantError, err)
226 t.Errorf("want failure: %s, got: success", wantError)