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 *******************************************************************************/
29 * Unpack a response returned from RAN.
30 * Verify it matches the want pdu.
33 func TestUnpackX2apPduResponse(t *testing.T) {
34 logger, _ := logger.InitLogger(logger.DebugLevel)
35 unpacker := NewX2apPduUnpacker(logger)
37 wantPduAsStr := `UnsuccessfulOutcome ::= {
39 criticality: 0 (reject)
40 value: ResourceStatusFailure ::= {
41 protocolIEs: ProtocolIE-Container ::= {
42 ResourceStatusFailure-IEs ::= {
44 criticality: 0 (reject)
47 ResourceStatusFailure-IEs ::= {
49 criticality: 0 (reject)
52 ResourceStatusFailure-IEs ::= {
54 criticality: 1 (ignore)
55 value: 1 (hardware-failure)
57 ResourceStatusFailure-IEs ::= {
59 criticality: 1 (ignore)
60 value: CompleteFailureCauseInformation-List ::= {
61 ProtocolIE-Single-Container ::= {
63 criticality: 1 (ignore)
64 value: CompleteFailureCauseInformation-Item ::= {
66 pLMN-Identity: 02 F8 29
67 eUTRANcellIdentifier: 00 07 AB 50 (4 bits unused)
69 measurementFailureCause-List: MeasurementFailureCause-List ::= {
70 ProtocolIE-Single-Container ::= {
72 criticality: 1 (ignore)
73 value: MeasurementFailureCause-Item ::= {
74 measurementFailedReportCharacteristics: 00 00 00 07
75 cause: 0 (transfer-syntax-error)
87 inputPayloadAsStr := "400900320000040027000300000e0028000300000c00054001620044401800004540130002f8290007ab500000434006000000000740"
90 _, err := fmt.Sscanf(inputPayloadAsStr, "%x", &payload)
92 t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err)
95 response, err := unpacker.UnpackX2apPduAsString(len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/)
97 t.Errorf("want: success, got: unpack failed. Error: %v\n", err)
100 want := strings.Fields(wantPduAsStr)
101 got := strings.Fields(response)
102 if len(want) != len(got) {
103 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", wantPduAsStr, response)
105 for i := 0; i < len(want); i++ {
106 if strings.Compare(want[i], got[i]) != 0 {
107 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", wantPduAsStr, strings.TrimSpace(response))
115 func TestUnpackX2apPduError(t *testing.T) {
116 logger, _ := logger.InitLogger(logger.InfoLevel)
117 unpacker := NewX2apPduUnpacker(logger)
119 wantError := "unpacking error: #src/asn1codec_utils.c.unpack_pdu_aux - Failed to decode E2AP-PDU (consumed 0), error = 0 Success"
120 //--------------------2006002a
121 inputPayloadAsStr := "2006002b000002001500080002f82900007a8000140017000000630002f8290007ab50102002f829000001000133"
123 _, err := fmt.Sscanf(inputPayloadAsStr, "%x", &payload)
125 t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err)
128 _, err = unpacker.UnpackX2apPduAsString(len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/)
130 if 0 != strings.Compare(fmt.Sprintf("%s", err), wantError) {
131 t.Errorf("want failure: %s, got: %s", wantError, err)
134 t.Errorf("want failure: %s, got: success", wantError)