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) {
39 logger, _ := logger.InitLogger(DebugLevel)
41 wantPduAsStr := `SuccessfulOutcome ::= {
43 criticality: 0 (reject)
44 value: X2SetupResponse ::= {
45 protocolIEs: ProtocolIE-Container ::= {
46 X2SetupResponse-IEs ::= {
48 criticality: 0 (reject)
49 value: GlobalENB-ID ::= {
50 pLMN-Identity: 02 F8 29
51 eNB-ID: 00 7A 80 (4 bits unused)
54 X2SetupResponse-IEs ::= {
56 criticality: 0 (reject)
57 value: ServedCells ::= {
59 servedCellInfo: ServedCell-Information ::= {
62 pLMN-Identity: 02 F8 29
63 eUTRANcellIdentifier: 00 07 AB 50 (4 bits unused)
66 broadcastPLMNs: BroadcastPLMNs-Item ::= {
69 eUTRA-Mode-Info: FDD-Info ::= {
72 uL-Transmission-Bandwidth: 3 (bw50)
73 dL-Transmission-Bandwidth: 3 (bw50)
83 inputPayloadAsStr := "2006002a000002001500080002f82900007a8000140017000000630002f8290007ab50102002f829000001000133"
86 _, err := fmt.Sscanf(inputPayloadAsStr, "%x", &payload)
88 t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err)
91 response, err := UnpackX2apPduAndRefine(logger, e2pdus.MaxAsn1CodecAllocationBufferSize , len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/)
93 t.Errorf("want: success, got: unpack failed. Error: %v\n", err)
96 want := strings.Fields(wantPduAsStr)
97 got := strings.Fields(response.PduPrint)
98 if len(want) != len(got) {
99 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", wantPduAsStr, response.PduPrint)
101 for i := 0; i < len(want); i++ {
102 if strings.Compare(want[i], got[i]) != 0 {
103 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", wantPduAsStr, strings.TrimSpace(response.PduPrint))
111 func TestUnpackX2apSetupResponseUnpackError(t *testing.T) {
113 logger, _ := logger.InitLogger(InfoLevel)
115 wantError := "unpacking error: #src/asn1codec_utils.c.unpack_pdu_aux - Failed to decode E2AP-PDU (consumed 0), error = 0 Success"
116 //--------------------2006002a
117 inputPayloadAsStr := "2006002b000002001500080002f82900007a8000140017000000630002f8290007ab50102002f829000001000133"
119 _, err := fmt.Sscanf(inputPayloadAsStr, "%x", &payload)
121 t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err)
124 _, err = UnpackX2apPduAndRefine(logger, e2pdus.MaxAsn1CodecAllocationBufferSize , len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/)
126 if 0 != strings.Compare(fmt.Sprintf("%s", err), wantError) {
127 t.Errorf("want failure: %s, got: %s", wantError, err)
130 t.Errorf("want failure: %s, got: success", wantError)