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).
32 func TestPreparePackedEndcX2SetupRequest(t *testing.T) {
33 _,err := logger.InitLogger(logger.InfoLevel)
35 t.Errorf("failed to initialize logger, error: %s", err)
37 packedPdu := "0024003100000100f4002a0000020015000800bbbccc00abcde000fa0017000001f700bbbcccabcde0000000bbbccc000000000001"
38 packedEndcX2setupRequest := PackedEndcX2setupRequest
40 tmp := fmt.Sprintf("%x", packedEndcX2setupRequest)
41 if len(tmp) != len(packedPdu) {
42 t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcX2setupRequest)/2)
45 if strings.Compare(tmp, packedPdu) != 0 {
46 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
50 func TestPreparePackedX2SetupRequest(t *testing.T) {
51 _,err := logger.InitLogger(logger.InfoLevel)
53 t.Errorf("failed to initialize logger, error: %s", err)
55 packedPdu := "0006002a0000020015000800bbbccc00abcde000140017000001f700bbbcccabcde0000000bbbccc000000000001"
56 packedX2setupRequest := PackedX2setupRequest
58 tmp := fmt.Sprintf("%x", packedX2setupRequest)
59 if len(tmp) != len(packedPdu) {
60 t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedX2setupRequest)/2)
63 if strings.Compare(tmp, packedPdu) != 0 {
64 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
68 func TestPreparePackedX2SetupRequestFailure(t *testing.T) {
69 _, err := logger.InitLogger(logger.InfoLevel)
71 t.Errorf("failed to initialize logger, error: %s", err)
74 _, _, err = preparePackedX2SetupRequest(1, 4096, pLMNId, eNBId, eNBIdBitqty, ricFlag)
76 t.Errorf("want: error, got: success.\n")
79 expected:= "packing error: #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
80 if !strings.Contains(err.Error(), expected) {
81 t.Errorf("want :[%s], got: [%s]\n", expected, err)
85 func TestPreparePackedEndcSetupRequestFailure(t *testing.T) {
86 _, err := logger.InitLogger(logger.InfoLevel)
88 t.Errorf("failed to initialize logger, error: %s", err)
91 _, _, err = preparePackedEndcX2SetupRequest(1, 4096, pLMNId, eNBId, eNBIdBitqty, ricFlag)
93 t.Errorf("want: error, got: success.\n")
96 expected:= "packing error: #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
97 if !strings.Contains(err.Error(), expected) {
98 t.Errorf("want :[%s], got: [%s]\n", expected, err)
102 func TestParseRicId(t *testing.T) {
103 var testCases = []struct {
111 ricId: "bbbccc-abcd02/18",
112 pLMNId: []byte{0xbb, 0xbc, 0xcc},
113 eNBId: []byte{0xab, 0xcd, 0x2}, /*00000010 -> 10000000*/
114 eNBIdBitqty: ShortMacro_eNB_ID,
117 ricId: "bbbccc-abcd0e/20",
118 pLMNId: []byte{0xbb, 0xbc, 0xcc},
119 eNBId: []byte{0xab, 0xcd, 0xe},
120 eNBIdBitqty: Macro_eNB_ID,
123 ricId: "bbbccc-abcd07/21",
124 pLMNId: []byte{0xbb, 0xbc, 0xcc},
125 eNBId: []byte{0xab, 0xcd, 0x7}, /*00000111 -> 00111000*/
126 eNBIdBitqty: LongMacro_eNB_ID,
129 ricId: "bbbccc-abcdef08/28",
130 pLMNId: []byte{0xbb, 0xbc, 0xcc},
131 eNBId: []byte{0xab, 0xcd, 0xef, 0x8},
132 eNBIdBitqty: Home_eNB_ID,
136 failure: fmt.Errorf("unable to extract the value of RIC_ID: EOF"),
141 failure: fmt.Errorf("unable to extract the value of RIC_ID: unexpected EOF"),
145 failure: fmt.Errorf("unable to extract the value of RIC_ID: EOF"),
149 failure: fmt.Errorf("%s", "unable to extract the value of RIC_ID: no hex data for %x string"),
153 failure: fmt.Errorf("%s", "unable to extract the value of RIC_ID: no hex data for %x string"),
156 ricId: "bbbcccdd-abcdef08/28", // pLMNId too long
157 failure: fmt.Errorf("unable to extract the value of RIC_ID: input does not match format"),
160 ricId: "bbbccc-abcdef0809/28", // eNBId too long
161 failure: fmt.Errorf("unable to extract the value of RIC_ID: input does not match format"),
165 ricId: "bbbc-abcdef08/28", // pLMNId too short
166 failure: fmt.Errorf("invalid value for RIC_ID, len(pLMNId:[187 188]) != 3"),
169 ricId: "bbbccc-abcd/28", // eNBId too short
170 failure: fmt.Errorf("invalid value for RIC_ID, len(eNBId:[171 205]) != 3 or 4"),
173 ricId: "bbbccc-abcdef08/239", // bit quantity too long - no error, will return 23 (which is invalid)
174 failure: fmt.Errorf("invalid value for RIC_ID, eNBIdBitqty: 23"),
178 for _, tc := range testCases {
179 t.Run(tc.ricId, func(t *testing.T) {
181 err := parseRicID(tc.ricId)
183 if tc.failure == nil {
184 t.Errorf("want: success, got: parse failed. Error: %v\n", err)
186 if strings.Compare(err.Error(), tc.failure.Error()) != 0 {
187 t.Errorf("want: %s, got: %s\n", err, tc.failure)
191 if bytes.Compare(tc.pLMNId, pLMNId) != 0 {
192 t.Errorf("want: pLMNId = %v, got: pLMNId = %v", tc.pLMNId, pLMNId)
195 if bytes.Compare(tc.eNBId, eNBId) != 0 {
196 t.Errorf("want: eNBId = %v, got: eNBId = %v", tc.eNBId, eNBId)
199 if tc.eNBIdBitqty != eNBIdBitqty {
200 t.Errorf("want: eNBIdBitqty = %d, got: eNBIdBitqty = %d", tc.eNBIdBitqty, eNBIdBitqty)