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 an x2setup response returned from RAN.
30 * Verify it matches the want pdu.
33 func TestUnpackX2apSetupResponse(t *testing.T) {
34 logger, _ := logger.InitLogger(logger.DebugLevel)
36 wantPduAsStr := `SuccessfulOutcome ::= {
38 criticality: 0 (reject)
39 value: X2SetupResponse ::= {
40 protocolIEs: ProtocolIE-Container ::= {
41 X2SetupResponse-IEs ::= {
43 criticality: 0 (reject)
44 value: GlobalENB-ID ::= {
45 pLMN-Identity: 02 F8 29
46 eNB-ID: 00 7A 80 (4 bits unused)
49 X2SetupResponse-IEs ::= {
51 criticality: 0 (reject)
52 value: ServedCells ::= {
54 servedCellInfo: ServedCell-Information ::= {
57 pLMN-Identity: 02 F8 29
58 eUTRANcellIdentifier: 00 07 AB 50 (4 bits unused)
61 broadcastPLMNs: BroadcastPLMNs-Item ::= {
64 eUTRA-Mode-Info: FDD-Info ::= {
67 uL-Transmission-Bandwidth: 3 (bw50)
68 dL-Transmission-Bandwidth: 3 (bw50)
78 inputPayloadAsStr := "2006002a000002001500080002f82900007a8000140017000000630002f8290007ab50102002f829000001000133"
81 _, err := fmt.Sscanf(inputPayloadAsStr, "%x", &payload)
83 t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err)
86 response, err := UnpackX2apPduAndRefine(logger, e2pdus.MaxAsn1CodecAllocationBufferSize , len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/)
88 t.Errorf("want: success, got: unpack failed. Error: %v\n", err)
91 want := strings.Fields(wantPduAsStr)
92 got := strings.Fields(response.PduPrint)
93 if len(want) != len(got) {
94 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", wantPduAsStr, response.PduPrint)
96 for i := 0; i < len(want); i++ {
97 if strings.Compare(want[i], got[i]) != 0 {
98 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", wantPduAsStr, strings.TrimSpace(response.PduPrint))
106 func TestUnpackX2apSetupResponseUnpackError(t *testing.T) {
107 logger, _ := logger.InitLogger(logger.InfoLevel)
109 wantError := "unpacking error: #src/asn1codec_utils.c.unpack_pdu_aux - Failed to decode E2AP-PDU (consumed 0), error = 0 Success"
110 //--------------------2006002a
111 inputPayloadAsStr := "2006002b000002001500080002f82900007a8000140017000000630002f8290007ab50102002f829000001000133"
113 _, err := fmt.Sscanf(inputPayloadAsStr, "%x", &payload)
115 t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err)
118 _, err = UnpackX2apPduAndRefine(logger, e2pdus.MaxAsn1CodecAllocationBufferSize , len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/)
120 if 0 != strings.Compare(fmt.Sprintf("%s", err), wantError) {
121 t.Errorf("want failure: %s, got: %s", wantError, err)
124 t.Errorf("want failure: %s, got: success", wantError)