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 func TestPreparePackedEndcX2SetupRequest(t *testing.T) {
29 _,err := logger.InitLogger(logger.InfoLevel)
31 t.Errorf("failed to initialize logger, error: %s", err)
33 packedPdu := "0024003100000100f4002a0000020015000800bbbccc00abcde000fa0017000001f700bbbcccabcde0000000bbbccc000000000001"
34 packedEndcX2setupRequest := PackedEndcX2setupRequest
36 tmp := fmt.Sprintf("%x", packedEndcX2setupRequest)
37 if len(tmp) != len(packedPdu) {
38 t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcX2setupRequest)/2)
41 if strings.Compare(tmp, packedPdu) != 0 {
42 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
46 func TestPreparePackedX2SetupRequest(t *testing.T) {
47 _,err := logger.InitLogger(logger.InfoLevel)
49 t.Errorf("failed to initialize logger, error: %s", err)
51 packedPdu := "0006002a0000020015000800bbbccc00abcde000140017000001f700bbbcccabcde0000000bbbccc000000000001"
52 packedX2setupRequest := PackedX2setupRequest
54 tmp := fmt.Sprintf("%x", packedX2setupRequest)
55 if len(tmp) != len(packedPdu) {
56 t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedX2setupRequest)/2)
59 if strings.Compare(tmp, packedPdu) != 0 {
60 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
64 func TestPreparePackedX2SetupRequestFailure(t *testing.T) {
65 _, err := logger.InitLogger(logger.InfoLevel)
67 t.Errorf("failed to initialize logger, error: %s", err)
70 _, _, err = preparePackedX2SetupRequest(1, 4096, pLMNId, eNBId, eNBIdBitqty, ricFlag)
72 t.Errorf("want: error, got: success.\n")
75 expected:= "packing error: #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
76 if !strings.Contains(err.Error(), expected) {
77 t.Errorf("want :[%s], got: [%s]\n", expected, err)
81 func TestPreparePackedEndcSetupRequestFailure(t *testing.T) {
82 _, err := logger.InitLogger(logger.InfoLevel)
84 t.Errorf("failed to initialize logger, error: %s", err)
87 _, _, err = preparePackedEndcX2SetupRequest(1, 4096, pLMNId, eNBId, eNBIdBitqty, ricFlag)
89 t.Errorf("want: error, got: success.\n")
92 expected:= "packing error: #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
93 if !strings.Contains(err.Error(), expected) {
94 t.Errorf("want :[%s], got: [%s]\n", expected, err)
98 func TestParseRicId(t *testing.T) {
99 var testCases = []struct {
107 ricId: "bbbccc-abcd02/18",
108 pLMNId: []byte{0xbb, 0xbc, 0xcc},
109 eNBId: []byte{0xab, 0xcd, 0x2}, /*00000010 -> 10000000*/
110 eNBIdBitqty: ShortMacro_eNB_ID,
113 ricId: "bbbccc-abcd0e/20",
114 pLMNId: []byte{0xbb, 0xbc, 0xcc},
115 eNBId: []byte{0xab, 0xcd, 0xe},
116 eNBIdBitqty: Macro_eNB_ID,
119 ricId: "bbbccc-abcd07/21",
120 pLMNId: []byte{0xbb, 0xbc, 0xcc},
121 eNBId: []byte{0xab, 0xcd, 0x7}, /*00000111 -> 00111000*/
122 eNBIdBitqty: LongMacro_eNB_ID,
125 ricId: "bbbccc-abcdef08/28",
126 pLMNId: []byte{0xbb, 0xbc, 0xcc},
127 eNBId: []byte{0xab, 0xcd, 0xef, 0x8},
128 eNBIdBitqty: Home_eNB_ID,
132 failure: fmt.Errorf("unable to extract the value of RIC_ID: EOF"),
137 failure: fmt.Errorf("unable to extract the value of RIC_ID: unexpected EOF"),
141 failure: fmt.Errorf("unable to extract the value of RIC_ID: EOF"),
145 failure: fmt.Errorf("%s", "unable to extract the value of RIC_ID: no hex data for %x string"),
149 failure: fmt.Errorf("%s", "unable to extract the value of RIC_ID: no hex data for %x string"),
152 ricId: "bbbcccdd-abcdef08/28", // pLMNId too long
153 failure: fmt.Errorf("unable to extract the value of RIC_ID: input does not match format"),
156 ricId: "bbbccc-abcdef0809/28", // eNBId too long
157 failure: fmt.Errorf("unable to extract the value of RIC_ID: input does not match format"),
161 ricId: "bbbc-abcdef08/28", // pLMNId too short
162 failure: fmt.Errorf("invalid value for RIC_ID, len(pLMNId:[187 188]) != 3"),
165 ricId: "bbbccc-abcd/28", // eNBId too short
166 failure: fmt.Errorf("invalid value for RIC_ID, len(eNBId:[171 205]) != 3 or 4"),
169 ricId: "bbbccc-abcdef08/239", // bit quantity too long - no error, will return 23 (which is invalid)
170 failure: fmt.Errorf("invalid value for RIC_ID, eNBIdBitqty: 23"),
174 for _, tc := range testCases {
175 t.Run(tc.ricId, func(t *testing.T) {
177 err := parseRicID(tc.ricId)
179 if tc.failure == nil {
180 t.Errorf("want: success, got: parse failed. Error: %v\n", err)
182 if strings.Compare(err.Error(), tc.failure.Error()) != 0 {
183 t.Errorf("want: %s, got: %s\n", err, tc.failure)
187 if bytes.Compare(tc.pLMNId, pLMNId) != 0 {
188 t.Errorf("want: pLMNId = %v, got: pLMNId = %v", tc.pLMNId, pLMNId)
191 if bytes.Compare(tc.eNBId, eNBId) != 0 {
192 t.Errorf("want: eNBId = %v, got: eNBId = %v", tc.eNBId, eNBId)
195 if tc.eNBIdBitqty != eNBIdBitqty {
196 t.Errorf("want: eNBIdBitqty = %d, got: eNBIdBitqty = %d", tc.eNBIdBitqty, eNBIdBitqty)