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 *******************************************************************************/
28 * Unpack an x2setup response returned from RAN.
29 * Verify it matches the want pdu.
32 func TestUnpackX2apSetupResponse(t *testing.T) {
33 logger, _ := logger.InitLogger(logger.DebugLevel)
35 wantPduAsStr := `SuccessfulOutcome ::= {
37 criticality: 0 (reject)
38 value: X2SetupResponse ::= {
39 protocolIEs: ProtocolIE-Container ::= {
40 X2SetupResponse-IEs ::= {
42 criticality: 0 (reject)
43 value: GlobalENB-ID ::= {
44 pLMN-Identity: 02 F8 29
45 eNB-ID: 00 7A 80 (4 bits unused)
48 X2SetupResponse-IEs ::= {
50 criticality: 0 (reject)
51 value: ServedCells ::= {
53 servedCellInfo: ServedCell-Information ::= {
56 pLMN-Identity: 02 F8 29
57 eUTRANcellIdentifier: 00 07 AB 50 (4 bits unused)
60 broadcastPLMNs: BroadcastPLMNs-Item ::= {
63 eUTRA-Mode-Info: FDD-Info ::= {
66 uL-Transmission-Bandwidth: 3 (bw50)
67 dL-Transmission-Bandwidth: 3 (bw50)
77 inputPayloadAsStr := "2006002a000002001500080002f82900007a8000140017000000630002f8290007ab50102002f829000001000133"
80 _, err := fmt.Sscanf(inputPayloadAsStr, "%x", &payload)
82 t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err)
85 response, err := unpackX2apPduAndRefine(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, len(payload), payload, MaxAsn1CodecMessageBufferSize /*message buffer*/)
87 t.Errorf("want: success, got: unpack failed. Error: %v\n", err)
90 want:= strings.Fields(wantPduAsStr)
91 got:= strings.Fields(response.pduPrint)
92 if len(want) != len(got) {
93 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", wantPduAsStr, response.pduPrint)
95 for i:=0; i < len(want); i++ {
96 if strings.Compare(want[i], got[i] ) != 0 {
97 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", wantPduAsStr, strings.TrimSpace(response.pduPrint))
105 func TestUnpackX2apSetupResponseUnpackError(t *testing.T) {
106 logger, _ := logger.InitLogger(logger.InfoLevel)
108 wantError := "unpacking error: #src/asn1codec_utils.c.unpack_pdu_aux - Failed to decode E2AP-PDU (consumed 0), error = 0 Success"
109 //--------------------2006002a
110 inputPayloadAsStr := "2006002b000002001500080002f82900007a8000140017000000630002f8290007ab50102002f829000001000133"
112 _, err := fmt.Sscanf(inputPayloadAsStr, "%x", &payload)
114 t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err)
117 _, err = unpackX2apPduAndRefine(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, len(payload), payload, MaxAsn1CodecMessageBufferSize /*message buffer*/)
119 if 0 != strings.Compare(fmt.Sprintf("%s", err), wantError) {
120 t.Errorf("want failure: %s, got: %s", wantError, err)
123 t.Errorf("want failure: %s, got: success", wantError)