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 <asn1codec_utils.h>
27 // #include <resource_status_request_wrapper.h>
31 "github.com/pkg/errors"
37 MaxAsn1PackedBufferSize = 4096
38 MaxAsn1CodecMessageBufferSize = 4096
41 type Measurement_ID int64
43 type ResourceStatusRequestData struct {
44 CellID string // PLMNIdentifier:eUTRANCellIdentifier
45 MeasurementID Measurement_ID
46 MeasurementID2 Measurement_ID
47 PartialSuccessAllowed bool
49 TnlLoadIndPeriodic bool
50 HwLoadIndPeriodic bool
51 AbsStatusPeriodic bool
52 RsrpMeasurementPeriodic bool
54 PeriodicityMS enums.ReportingPeriodicity
55 PeriodicityRsrpMeasurementMS enums.ReportingPeriodicityRSRPMR
56 PeriodicityCsiMS enums.ReportingPeriodicityCSIR
59 func BuildPackedResourceStatusRequest(registrationRequest enums.Registration_Request, request *ResourceStatusRequestData, maxAsn1PackedBufferSize int, maxAsn1CodecMessageBufferSize int, withDebug bool) ([]byte, string, error) {
61 packedBuf := make([]byte, maxAsn1PackedBufferSize)
62 errBuf := make([]C.char, maxAsn1CodecMessageBufferSize)
63 packedBufSize := C.ulong(len(packedBuf))
66 var pLMNIdentifier, eUTRANCellIdentifier string
68 if _, err := fmt.Sscanf(request.CellID, "%x:%x", &pLMNIdentifier, &eUTRANCellIdentifier); err != nil {
69 return nil, "", fmt.Errorf("BuildPackedResourceStatusRequest() - unexpected CellID value [%s] (want: \"<PLMNIdentifier>:<eUTRANCellIdentifier>\"), err: %s", request.CellID, err)
74 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:
75 - The first bit (leftmost bit) contains the most significant bit (MSB);
76 - The last bit (rightmost bit) contains the least significant bit (LSB);
77 - When importing bit strings from other specifications, the first bit of the bit string contains the first bit of the concerned information.
80 /*reportCharacteristics:
81 1) First Bit = PRB Periodic.
82 2) Second Bit = TNL load Ind Periodic.
83 3) Third Bit = HW Load Ind Periodic.
84 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.
85 5) Fifth Bit = ABPartialSuccessIndicator_tS Status Periodic.
86 6) Sixth Bit = RSRP Measurement Report Periodic.
87 7) Seventh Bit = CSI Report Periodic.
89 var prbPeriodic, tnlLoadIndPeriodic, hwLoadIndPeriodic, compositeAvailablCapacityPeriodic, absStatusPeriodic, rsrpMeasurementPeriodic, csiPeriodic int
90 var partialSuccessAllowed C.PartialSuccessIndicator_t
92 if request.PartialSuccessAllowed {
93 partialSuccessAllowed = C.PartialSuccessIndicator_partial_success_allowed
95 partialSuccessAllowed = C.PartialSuccessIndicator_t(-1)
97 if request.PrbPeriodic {
100 if request.TnlLoadIndPeriodic {
101 tnlLoadIndPeriodic = 1
103 if request.HwLoadIndPeriodic {
104 hwLoadIndPeriodic = 1
106 if request.PrbPeriodic || request.TnlLoadIndPeriodic || request.HwLoadIndPeriodic {
107 compositeAvailablCapacityPeriodic = 1
109 if request.AbsStatusPeriodic {
110 absStatusPeriodic = 1
112 if request.RsrpMeasurementPeriodic {
113 rsrpMeasurementPeriodic = 1
115 if request.CsiPeriodic {
118 reportCharacteristics := uint32(prbPeriodic<<7 | tnlLoadIndPeriodic<<6 | hwLoadIndPeriodic<<5 | compositeAvailablCapacityPeriodic<<4 | absStatusPeriodic<<3 | rsrpMeasurementPeriodic<<2 | csiPeriodic<<1)
120 if !C.build_pack_resource_status_request(
121 (*C.uchar)(unsafe.Pointer(&[]byte(pLMNIdentifier)[0])),
122 (*C.uchar)(unsafe.Pointer(&[]byte(eUTRANCellIdentifier)[0])),
123 C.Measurement_ID_t(request.MeasurementID),
124 C.Measurement_ID_t(request.MeasurementID2),
125 C.Registration_Request_t(registrationRequest),
126 C.uint(reportCharacteristics),
127 C.ReportingPeriodicity_t(request.PeriodicityMS-1),
128 partialSuccessAllowed,
129 C.ReportingPeriodicityRSRPMR_t(request.PeriodicityRsrpMeasurementMS-1),
130 C.ReportingPeriodicityCSIR_t(request.PeriodicityCsiMS-1),
132 (*C.uchar)(unsafe.Pointer(&packedBuf[0])),
133 C.ulong(len(errBuf)),
135 return nil, "", errors.New(fmt.Sprintf("BuildPackedResourceStatusRequest - packing error: %s", C.GoString(&errBuf[0])))
140 defer C.delete_pdu(pdu)
141 if C.per_unpack_pdu(pdu, packedBufSize, (*C.uchar)(unsafe.Pointer(&packedBuf[0])), C.size_t(len(errBuf)), &errBuf[0]) {
142 C.asn1_pdu_printer(pdu, C.size_t(len(errBuf)), &errBuf[0])
143 pduAsString = C.GoString(&errBuf[0])
147 return packedBuf[:packedBufSize], pduAsString, nil