[RIC-248] RAN Health Check Request API - Implementation
[ric-plt/e2mgr.git] / E2Manager / tests / payloadProvider.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 //  This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 //  platform project (RICP).
19
20
21 package tests
22
23 // #cgo CFLAGS: -I../3rdparty/asn1codec/inc/ -I../3rdparty/asn1codec/e2ap_engine/
24 // #cgo LDFLAGS: -L ../3rdparty/asn1codec/lib/ -L../3rdparty/asn1codec/e2ap_engine/ -le2ap_codec -lasncodec
25 // #include <asn1codec_utils.h>
26 // #include <SuccessfulOutcome.h>
27 //
28 // bool
29 // build_pack_x2_reset_response(size_t* packed_buf_size, unsigned char* packed_buf, size_t err_buf_size, char* err_buf){
30 //     bool rc = true;
31 //     E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t));
32 //     SuccessfulOutcome_t *successfulOutcome = calloc(1, sizeof(SuccessfulOutcome_t));
33 //     ResetResponse_t *resetResponse;
34 //     ResetResponse_IEs_t *resetResponse_IEs = calloc(1, sizeof(ResetResponse_IEs_t));
35 //
36 //     assert(pdu != 0);
37 //     assert(successfulOutcome != 0);
38 //     assert(resetResponse_IEs != 0);
39 //
40 //     pdu->present = E2AP_PDU_PR_successfulOutcome;
41 //     pdu->choice.successfulOutcome = successfulOutcome;
42 //
43 //     successfulOutcome->procedureCode = ProcedureCode_id_reset;
44 //     successfulOutcome->criticality = Criticality_reject;
45 //     successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetResponse;
46 //     resetResponse = &successfulOutcome->value.choice.ResetResponse;
47 //
48 //     CriticalityDiagnostics_IE_List_t *critList = calloc(1, sizeof(CriticalityDiagnostics_IE_List_t));
49 //     assert(critList != 0);
50 //     resetResponse_IEs->id = ProtocolIE_ID_id_CriticalityDiagnostics;
51 //     resetResponse_IEs->criticality = Criticality_ignore;
52 //     resetResponse_IEs->value.present =  ResetResponse_IEs__value_PR_CriticalityDiagnostics;
53 //     ASN_SEQUENCE_ADD(resetResponse_IEs->value.choice.CriticalityDiagnostics.iEsCriticalityDiagnostics,critList);
54 //
55 //     CriticalityDiagnostics_IE_List__Member *member= calloc(1, sizeof(CriticalityDiagnostics_IE_List__Member));
56 //     assert(member != 0);
57 //     ASN_SEQUENCE_ADD(critList ,member);
58 //
59 //     ASN_SEQUENCE_ADD(&resetResponse->protocolIEs, resetResponse_IEs);
60 //
61 //     rc = per_pack_pdu(pdu, packed_buf_size, packed_buf,err_buf_size, err_buf);
62 //
63 //     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
64 //     return rc;
65 // }
66 import "C"
67 import (
68         "errors"
69         "fmt"
70         "unsafe"
71 )
72 const PackedBufferSize = 4096
73
74 func BuildPackedX2ResetResponse()([]byte, error){
75         payloadSize := C.ulong(PackedBufferSize)
76         packedBuffer := [PackedBufferSize]C.uchar{}
77         errorBuffer := [PackedBufferSize]C.char{}
78         res := bool(C.build_pack_x2_reset_response(&payloadSize, &packedBuffer[0], PackedBufferSize, &errorBuffer[0]))
79         if !res {
80                 return nil, errors.New(fmt.Sprintf("packing error: %s", C.GoString(&errorBuffer[0])))
81         }
82         return C.GoBytes(unsafe.Pointer(&packedBuffer), C.int(payloadSize)), nil
83 }