[RIC-430] - Update Connection Status on RAN List
[ric-plt/e2mgr.git] / E2Manager / e2pdus / endc_x2_setup_request_test.go
1 /*
2  *   Copyright (c) 2019 AT&T Intellectual Property.
3  *
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
7  *
8  *       http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /*
18  * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19  * platform project (RICP).
20  */
21
22 package e2pdus
23
24 import (
25         "fmt"
26         "strings"
27         "testing"
28 )
29
30 /*
31  * Create and pack an x2ap setup request.
32  * Verify the packed representation matches the want value.
33  */
34 func TestPackEndcX2apSetupRequest(t *testing.T) {
35         pLMNId := []byte{0xbb, 0xbc, 0xcc}
36         ricFlag := []byte{0xbb, 0xbc, 0xcc} /*pLMNId [3]bytes*/
37
38         var testCases = []struct {
39                 eNBId       []byte
40                 eNBIdBitqty uint
41                 packedPdu   string
42         }{
43                 {
44                         eNBId:       []byte{0xab, 0xcd, 0x2}, /*00000010 -> 10000000*/
45                         eNBIdBitqty: ShortMacro_eNB_ID,
46                         packedPdu:   "0024003200000100f4002b0000020015000900bbbccc8003abcd8000fa0017000001f700bbbcccabcd80000000bbbccc000000000001",
47                 },
48
49                 {
50                         eNBId:       []byte{0xab, 0xcd, 0xe},
51                         eNBIdBitqty: Macro_eNB_ID,
52                         packedPdu:   "0024003100000100f4002a0000020015000800bbbccc00abcde000fa0017000001f700bbbcccabcde0000000bbbccc000000000001",
53                 },
54                 {
55                         eNBId:       []byte{0xab, 0xcd, 0x7}, /*00000111 -> 00111000*/
56                         eNBIdBitqty: LongMacro_eNB_ID,
57                         //packedPdu: "0024003200000100f4002b0000020015000900bbbccc8103abcd3800fa0017000001f700bbbcccabcd38000000bbbccc000000000001",
58                         packedPdu: "0024003200000100f4002b0000020015000900bbbcccc003abcd3800fa0017000001f700bbbcccabcd38000000bbbccc000000000001",
59                 },
60                 {
61                         eNBId:       []byte{0xab, 0xcd, 0xef, 0x8},
62                         eNBIdBitqty: Home_eNB_ID,
63                         packedPdu:   "0024003200000100f4002b0000020015000900bbbccc40abcdef8000fa0017000001f700bbbcccabcdef800000bbbccc000000000001",
64                 },
65         }
66
67         for _, tc := range testCases {
68                 t.Run(tc.packedPdu, func(t *testing.T) {
69
70                         payload, _, err := preparePackedEndcX2SetupRequest(MaxAsn1PackedBufferSize /*max packed buffer*/, MaxAsn1CodecMessageBufferSize /*max message buffer*/, pLMNId, tc.eNBId, tc.eNBIdBitqty, ricFlag)
71                         if err != nil {
72                                 t.Errorf("want: success, got: pack failed. Error: %v\n", err)
73                         } else {
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)
78                                 }
79
80                                 if strings.Compare(tmp, tc.packedPdu) != 0 {
81                                         t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", tc.packedPdu, tmp)
82                                 }
83                         }
84                 })
85         }
86 }
87
88 /*Packing error*/
89
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"
96
97         _, _, err := preparePackedEndcX2SetupRequest(40 /*max packed buffer*/, MaxAsn1CodecMessageBufferSize /*max message buffer*/, pLMNId, eNBId, eNBIdBitqty, ricFlag)
98         if err != nil {
99                 if 0 != strings.Compare(fmt.Sprintf("%s", err), wantError) {
100                         t.Errorf("want failure: %s, got: %s", wantError, err)
101                 }
102         } else {
103                 t.Errorf("want failure: %s, got: success", wantError)
104
105         }
106 }