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).
24 // #cgo CFLAGS: -I../3rdparty/asn1codec/inc/ -I../3rdparty/asn1codec/e2ap_engine/
25 // #cgo LDFLAGS: -L ../3rdparty/asn1codec/lib/ -L../3rdparty/asn1codec/e2ap_engine/ -le2ap_codec -lasncodec
26 // #include <stdlib.h>
27 // #include <asn1codec_utils.h>
28 // #include <resource_status_request_wrapper.h>
32 "github.com/pkg/errors"
38 MaxAsn1PackedBufferSize = 4096
39 MaxAsn1CodecMessageBufferSize = 4096
42 type Measurement_ID int64
44 type ResourceStatusRequestData struct {
45 CellIdList []string // PLMNIdentifier:eUTRANCellIdentifier
46 MeasurementID Measurement_ID
47 MeasurementID2 Measurement_ID
48 PartialSuccessAllowed bool
50 TnlLoadIndPeriodic bool
51 HwLoadIndPeriodic bool
52 AbsStatusPeriodic bool
53 RsrpMeasurementPeriodic bool
55 PeriodicityMS enums.ReportingPeriodicity
56 PeriodicityRsrpMeasurementMS enums.ReportingPeriodicityRSRPMR
57 PeriodicityCsiMS enums.ReportingPeriodicityCSIR
60 func BuildPackedResourceStatusRequest(registrationRequest enums.Registration_Request, request *ResourceStatusRequestData, maxAsn1PackedBufferSize int, maxAsn1CodecMessageBufferSize int, withDebug bool) ([]byte, string, error) {
62 packedBuf := make([]byte, maxAsn1PackedBufferSize)
63 errBuf := make([]C.char, maxAsn1CodecMessageBufferSize)
64 packedBufSize := C.ulong(len(packedBuf))
67 pLMNIdentities := make([]*C.uchar, len(request.CellIdList))
68 eUTRANCellIdentifiers := make([]*C.uchar, len(request.CellIdList))
70 for i, cellID := range request.CellIdList {
71 var pLMNIdentity, eUTRANCellIdentifier []byte
72 if _, err := fmt.Sscanf(cellID, "%x:%x", &pLMNIdentity, &eUTRANCellIdentifier); err != nil {
73 return nil, "", fmt.Errorf("BuildPackedResourceStatusRequest() - unexpected CellID value [%s]@%d (want: \"<PLMNIdentifier>:<eUTRANCellIdentifier>\"), err: %s", cellID, i, err)
75 pLMNIdentities[i], eUTRANCellIdentifiers[i] = (*C.uchar)(C.CBytes(pLMNIdentity)), (*C.uchar)(C.CBytes(eUTRANCellIdentifier))
79 for _, cPtr := range pLMNIdentities {
80 C.free(unsafe.Pointer(cPtr))
83 for _, cPtr := range eUTRANCellIdentifiers {
84 C.free(unsafe.Pointer(cPtr))
91 When specifying information elements which are to be represented by bit strings, if not otherwise specifically stated in the semantics description of the concerned IE or elsewhere, the following principle applies with regards to the ordering of bits:
92 - The first bit (leftmost bit) contains the most significant bit (MSB);
93 - The last bit (rightmost bit) contains the least significant bit (LSB);
94 - When importing bit strings from other specifications, the first bit of the bit string contains the first bit of the concerned information.
97 /*reportCharacteristics:
98 1) First Bit = PRB Periodic.
99 2) Second Bit = TNL load Ind Periodic.
100 3) Third Bit = HW Load Ind Periodic.
101 4) Fourth Bit = Composite Available Capacity Periodic, this bit should be set to 1 if at least one of the First, Second or Third bits is set to 1.
102 5) Fifth Bit = ABPartialSuccessIndicator_tS Status Periodic.
103 6) Sixth Bit = RSRP Measurement Report Periodic.
104 7) Seventh Bit = CSI Report Periodic.
106 var prbPeriodic, tnlLoadIndPeriodic, hwLoadIndPeriodic, compositeAvailablCapacityPeriodic, absStatusPeriodic, rsrpMeasurementPeriodic, csiPeriodic int
107 var partialSuccessAllowed C.PartialSuccessIndicator_t
109 if request.PartialSuccessAllowed {
110 partialSuccessAllowed = C.PartialSuccessIndicator_partial_success_allowed
112 partialSuccessAllowed = C.PartialSuccessIndicator_t(-1)
114 if request.PrbPeriodic {
117 if request.TnlLoadIndPeriodic {
118 tnlLoadIndPeriodic = 1
120 if request.HwLoadIndPeriodic {
121 hwLoadIndPeriodic = 1
123 if request.PrbPeriodic || request.TnlLoadIndPeriodic || request.HwLoadIndPeriodic {
124 compositeAvailablCapacityPeriodic = 1
126 if request.AbsStatusPeriodic {
127 absStatusPeriodic = 1
129 if request.RsrpMeasurementPeriodic {
130 rsrpMeasurementPeriodic = 1
132 if request.CsiPeriodic {
135 reportCharacteristics := uint32(prbPeriodic<<7 | tnlLoadIndPeriodic<<6 | hwLoadIndPeriodic<<5 | compositeAvailablCapacityPeriodic<<4 | absStatusPeriodic<<3 | rsrpMeasurementPeriodic<<2 | csiPeriodic<<1)
137 if !C.build_pack_resource_status_request(
138 (**C.uchar)(unsafe.Pointer(&pLMNIdentities[0])),
139 (**C.uchar)(unsafe.Pointer(&eUTRANCellIdentifiers[0])),
140 C.ulong(len(request.CellIdList)),
141 C.Measurement_ID_t(request.MeasurementID),
142 C.Measurement_ID_t(request.MeasurementID2),
143 C.Registration_Request_t(registrationRequest),
144 C.uint(reportCharacteristics),
145 C.ReportingPeriodicity_t(request.PeriodicityMS-1),
146 partialSuccessAllowed,
147 C.ReportingPeriodicityRSRPMR_t(request.PeriodicityRsrpMeasurementMS-1),
148 C.ReportingPeriodicityCSIR_t(request.PeriodicityCsiMS-1),
150 (*C.uchar)(unsafe.Pointer(&packedBuf[0])),
151 C.ulong(len(errBuf)),
153 return nil, "", errors.New(fmt.Sprintf("BuildPackedResourceStatusRequest - packing error: %s", C.GoString(&errBuf[0])))
158 defer C.delete_pdu(pdu)
159 if C.per_unpack_pdu(pdu, packedBufSize, (*C.uchar)(unsafe.Pointer(&packedBuf[0])), C.size_t(len(errBuf)), &errBuf[0]) {
160 C.asn1_pdu_printer(pdu, C.size_t(len(errBuf)), &errBuf[0])
161 pduAsString = C.GoString(&errBuf[0])
165 return packedBuf[:packedBufSize], pduAsString, nil