[RICPLT-1853] Add UT & more
[ric-plt/e2mgr.git] / E2Manager / handlers / x2apSetupRequest_asn1_packer.go
1 //
2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
4 //
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
8 //
9 //      http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 package handlers
19
20 // #cgo CFLAGS: -I../asn1codec/inc/  -I../asn1codec/e2ap_engine/
21 // #cgo LDFLAGS: -L ../asn1codec/lib/ -L../asn1codec/e2ap_engine/ -le2ap_codec -lasncodec
22 // #include <asn1codec_utils.h>
23 // #include <x2setup_request_wrapper.h>
24 import "C"
25 import (
26         "e2mgr/logger"
27         "fmt"
28         "github.com/pkg/errors"
29         "unsafe"
30 )
31
32 func packX2apSetupRequest(logger *logger.Logger, allocationBufferSize int, maxPackedBufferSize int, maxMessageBufferSize int, pLMNId []byte, eNB_Id []byte /*18, 20, 21, 28 bits length*/, bitqty uint) ([]byte, error) {
33         packedBuf := make([]byte, maxPackedBufferSize)
34         errBuf := make([]C.char, maxMessageBufferSize)
35         packedBufSize := C.ulong(len(packedBuf))
36
37         if !C.build_pack_x2setup_request((*C.uchar)(unsafe.Pointer(&pLMNId[0])) /*pLMN_Identity*/,
38                 (*C.uchar)(unsafe.Pointer(&eNB_Id[0])), C.uint(bitqty),(*C.uchar)(unsafe.Pointer(&ricFlag[0])) /*pLMN_Identity*/,
39                 &packedBufSize, (*C.uchar)(unsafe.Pointer(&packedBuf[0])), C.ulong(len(errBuf)), &errBuf[0]) {
40                 return nil, errors.New(fmt.Sprintf("packing error: %s", C.GoString(&errBuf[0])))
41         }
42
43         if logger.DebugEnabled() {
44                 pdu:= C.new_pdu(C.size_t(allocationBufferSize))
45                 defer C.delete_pdu(pdu)
46                 if C.per_unpack_pdu(pdu, packedBufSize, (*C.uchar)(unsafe.Pointer(&packedBuf[0])),C.size_t(len(errBuf)), &errBuf[0]){
47                         C.asn1_pdu_printer(pdu, C.size_t(len(errBuf)), &errBuf[0])
48                         logger.Debugf("#x2apSetupRequest_asn1_packer.packX2apSetupRequest - PDU:%s\n\npacked (%d):%x", C.GoString(&errBuf[0]), packedBufSize, packedBuf[:packedBufSize])
49                 }
50         }
51         return packedBuf[:packedBufSize], nil
52
53 }
54