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).
31 * Create and pack an x2ap setup request.
32 * Verify the packed representation matches the want value.
34 func TestPackEndcX2apSetupRequest(t *testing.T) {
35 pLMNId := []byte{0xbb, 0xbc, 0xcc}
36 ricFlag := []byte{0xbb, 0xbc, 0xcc} /*pLMNId [3]bytes*/
38 var testCases = []struct {
44 eNBId: []byte{0xab, 0xcd, 0x2}, /*00000010 -> 10000000*/
45 eNBIdBitqty: ShortMacro_eNB_ID,
46 packedPdu: "0024003200000100f4002b0000020015000900bbbccc8003abcd8000fa0017000001f700bbbcccabcd80000000bbbccc000000000001",
50 eNBId: []byte{0xab, 0xcd, 0xe},
51 eNBIdBitqty: Macro_eNB_ID,
52 packedPdu: "0024003100000100f4002a0000020015000800bbbccc00abcde000fa0017000001f700bbbcccabcde0000000bbbccc000000000001",
55 eNBId: []byte{0xab, 0xcd, 0x7}, /*00000111 -> 00111000*/
56 eNBIdBitqty: LongMacro_eNB_ID,
57 //packedPdu: "0024003200000100f4002b0000020015000900bbbccc8103abcd3800fa0017000001f700bbbcccabcd38000000bbbccc000000000001",
58 packedPdu: "0024003200000100f4002b0000020015000900bbbcccc003abcd3800fa0017000001f700bbbcccabcd38000000bbbccc000000000001",
61 eNBId: []byte{0xab, 0xcd, 0xef, 0x8},
62 eNBIdBitqty: Home_eNB_ID,
63 packedPdu: "0024003200000100f4002b0000020015000900bbbccc40abcdef8000fa0017000001f700bbbcccabcdef800000bbbccc000000000001",
67 for _, tc := range testCases {
68 t.Run(tc.packedPdu, func(t *testing.T) {
70 payload, _, err := preparePackedEndcX2SetupRequest(MaxAsn1PackedBufferSize /*max packed buffer*/, MaxAsn1CodecMessageBufferSize /*max message buffer*/, pLMNId, tc.eNBId, tc.eNBIdBitqty, ricFlag)
72 t.Errorf("want: success, got: pack failed. Error: %v\n", err)
74 t.Logf("packed X2AP setup request(size=%d): %x\n", len(payload), payload)
75 tmp := fmt.Sprintf("%x", payload)
76 if len(tmp) != len(tc.packedPdu) {
77 t.Errorf("want packed len:%d, got: %d\n", len(tc.packedPdu)/2, len(payload)/2)
80 if strings.Compare(tmp, tc.packedPdu) != 0 {
81 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", tc.packedPdu, tmp)
90 func TestPackEndcX2apSetupRequestPackError(t *testing.T) {
91 pLMNId := []byte{0xbb, 0xbc, 0xcc}
92 ricFlag := []byte{0xbb, 0xbc, 0xcc} /*pLMNId [3]bytes*/
93 eNBId := []byte{0xab, 0xcd, 0x2}
94 eNBIdBitqty := uint(Macro_eNB_ID)
95 wantError := "packing error: #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big:53"
97 _, _, err := preparePackedEndcX2SetupRequest(40 /*max packed buffer*/, MaxAsn1CodecMessageBufferSize /*max message buffer*/, pLMNId, eNBId, eNBIdBitqty, ricFlag)
99 if 0 != strings.Compare(fmt.Sprintf("%s", err), wantError) {
100 t.Errorf("want failure: %s, got: %s", wantError, err)
103 t.Errorf("want failure: %s, got: success", wantError)