2 * Copyright (c) 2019 AT&T Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 * platform project (RICP).
33 * Unpack a response returned from RAN.
34 * Verify it matches the want pdu.
37 func TestUnpackX2apPduResponse(t *testing.T) {
38 logger, _ := logger.InitLogger(logger.DebugLevel)
39 unpacker := NewX2apPduUnpacker(logger)
41 wantPduAsStr := `UnsuccessfulOutcome ::= {
43 criticality: 0 (reject)
44 value: ResourceStatusFailure ::= {
45 protocolIEs: ProtocolIE-Container ::= {
46 ResourceStatusFailure-IEs ::= {
48 criticality: 0 (reject)
51 ResourceStatusFailure-IEs ::= {
53 criticality: 0 (reject)
56 ResourceStatusFailure-IEs ::= {
58 criticality: 1 (ignore)
59 value: 1 (hardware-failure)
61 ResourceStatusFailure-IEs ::= {
63 criticality: 1 (ignore)
64 value: CompleteFailureCauseInformation-List ::= {
65 ProtocolIE-Single-Container ::= {
67 criticality: 1 (ignore)
68 value: CompleteFailureCauseInformation-Item ::= {
70 pLMN-Identity: 02 F8 29
71 eUTRANcellIdentifier: 00 07 AB 50 (4 bits unused)
73 measurementFailureCause-List: MeasurementFailureCause-List ::= {
74 ProtocolIE-Single-Container ::= {
76 criticality: 1 (ignore)
77 value: MeasurementFailureCause-Item ::= {
78 measurementFailedReportCharacteristics: 00 00 00 07
79 cause: 0 (transfer-syntax-error)
91 inputPayloadAsStr := "400900320000040027000300000e0028000300000c00054001620044401800004540130002f8290007ab500000434006000000000740"
94 _, err := fmt.Sscanf(inputPayloadAsStr, "%x", &payload)
96 t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err)
99 response, err := unpacker.UnpackX2apPduAsString(len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/)
101 t.Errorf("want: success, got: unpack failed. Error: %v\n", err)
104 want := strings.Fields(wantPduAsStr)
105 got := strings.Fields(response)
106 if len(want) != len(got) {
107 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", wantPduAsStr, response)
109 for i := 0; i < len(want); i++ {
110 if strings.Compare(want[i], got[i]) != 0 {
111 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", wantPduAsStr, strings.TrimSpace(response))
119 func TestUnpackX2apPduError(t *testing.T) {
120 logger, _ := logger.InitLogger(logger.InfoLevel)
121 unpacker := NewX2apPduUnpacker(logger)
123 wantError := "unpacking error: #src/asn1codec_utils.c.unpack_pdu_aux - Failed to decode E2AP-PDU (consumed 0), error = 0 Success"
124 //--------------------2006002a
125 inputPayloadAsStr := "2006002b000002001500080002f82900007a8000140017000000630002f8290007ab50102002f829000001000133"
127 _, err := fmt.Sscanf(inputPayloadAsStr, "%x", &payload)
129 t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err)
132 _, err = unpacker.UnpackX2apPduAsString(len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/)
134 if 0 != strings.Compare(fmt.Sprintf("%s", err), wantError) {
135 t.Errorf("want failure: %s, got: %s", wantError, err)
138 t.Errorf("want failure: %s, got: success", wantError)