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 an x2setup response returned from RAN.
34 * Verify it matches the want pdu.
37 func TestUnpackX2apSetupResponse(t *testing.T) {
38 logger, _ := logger.InitLogger(logger.DebugLevel)
40 wantPduAsStr := `SuccessfulOutcome ::= {
42 criticality: 0 (reject)
43 value: X2SetupResponse ::= {
44 protocolIEs: ProtocolIE-Container ::= {
45 X2SetupResponse-IEs ::= {
47 criticality: 0 (reject)
48 value: GlobalENB-ID ::= {
49 pLMN-Identity: 02 F8 29
50 eNB-ID: 00 7A 80 (4 bits unused)
53 X2SetupResponse-IEs ::= {
55 criticality: 0 (reject)
56 value: ServedCells ::= {
58 servedCellInfo: ServedCell-Information ::= {
61 pLMN-Identity: 02 F8 29
62 eUTRANcellIdentifier: 00 07 AB 50 (4 bits unused)
65 broadcastPLMNs: BroadcastPLMNs-Item ::= {
68 eUTRA-Mode-Info: FDD-Info ::= {
71 uL-Transmission-Bandwidth: 3 (bw50)
72 dL-Transmission-Bandwidth: 3 (bw50)
82 inputPayloadAsStr := "2006002a000002001500080002f82900007a8000140017000000630002f8290007ab50102002f829000001000133"
85 _, err := fmt.Sscanf(inputPayloadAsStr, "%x", &payload)
87 t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err)
90 response, err := UnpackX2apPduAndRefine(logger, e2pdus.MaxAsn1CodecAllocationBufferSize , len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/)
92 t.Errorf("want: success, got: unpack failed. Error: %v\n", err)
95 want := strings.Fields(wantPduAsStr)
96 got := strings.Fields(response.PduPrint)
97 if len(want) != len(got) {
98 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", wantPduAsStr, response.PduPrint)
100 for i := 0; i < len(want); i++ {
101 if strings.Compare(want[i], got[i]) != 0 {
102 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", wantPduAsStr, strings.TrimSpace(response.PduPrint))
110 func TestUnpackX2apSetupResponseUnpackError(t *testing.T) {
111 logger, _ := logger.InitLogger(logger.InfoLevel)
113 wantError := "unpacking error: #src/asn1codec_utils.c.unpack_pdu_aux - Failed to decode E2AP-PDU (consumed 0), error = 0 Success"
114 //--------------------2006002a
115 inputPayloadAsStr := "2006002b000002001500080002f82900007a8000140017000000630002f8290007ab50102002f829000001000133"
117 _, err := fmt.Sscanf(inputPayloadAsStr, "%x", &payload)
119 t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err)
122 _, err = UnpackX2apPduAndRefine(logger, e2pdus.MaxAsn1CodecAllocationBufferSize , len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/)
124 if 0 != strings.Compare(fmt.Sprintf("%s", err), wantError) {
125 t.Errorf("want failure: %s, got: %s", wantError, err)
128 t.Errorf("want failure: %s, got: success", wantError)