2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
4 // Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
10 // http://www.apache.org/licenses/LICENSE-2.0
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
18 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 // platform project (RICP).
23 // #cgo LDFLAGS: -L/usr/local/lib -lrmr_si
24 // #include <rmr/rmr.h>
25 // #include <rmr/RIC_message_types.h>
26 // #include <stdlib.h>
34 func NewMBuf(mType int, len int, meid string, payload *[]byte, xAction *[]byte, msgSrc unsafe.Pointer) *MBuf {
45 func NewContext(maxMsgSize int, flags int, ctx unsafe.Pointer, logger *logger.Logger) *Context {
47 MaxMsgSize: maxMsgSize,
54 //TODO: consider declaring using its own type
57 RIC_X2_SETUP_REQ = C.RIC_X2_SETUP_REQ
58 RIC_X2_SETUP_RESP = C.RIC_X2_SETUP_RESP
59 RIC_X2_SETUP_FAILURE = C.RIC_X2_SETUP_FAILURE
60 RIC_ENDC_X2_SETUP_REQ = C.RIC_ENDC_X2_SETUP_REQ
61 RIC_ENDC_X2_SETUP_RESP = C.RIC_ENDC_X2_SETUP_RESP
62 RIC_ENDC_X2_SETUP_FAILURE = C.RIC_ENDC_X2_SETUP_FAILURE
63 RIC_SCTP_CONNECTION_FAILURE = C.RIC_SCTP_CONNECTION_FAILURE
64 RIC_ENB_LOAD_INFORMATION = C.RIC_ENB_LOAD_INFORMATION
65 RIC_ENB_CONF_UPDATE = C.RIC_ENB_CONF_UPDATE
66 RIC_ENB_CONFIGURATION_UPDATE_ACK = C.RIC_ENB_CONF_UPDATE_ACK
67 RIC_ENB_CONFIGURATION_UPDATE_FAILURE = C.RIC_ENB_CONF_UPDATE_FAILURE
68 RIC_ENDC_CONF_UPDATE = C.RIC_ENDC_CONF_UPDATE
69 RIC_ENDC_CONF_UPDATE_ACK = C.RIC_ENDC_CONF_UPDATE_ACK
70 RIC_ENDC_CONF_UPDATE_FAILURE = C.RIC_ENDC_CONF_UPDATE_FAILURE
71 RIC_SCTP_CLEAR_ALL = C.RIC_SCTP_CLEAR_ALL
72 RIC_X2_RESET_RESP = C.RIC_X2_RESET_RESP
73 RIC_X2_RESET = C.RIC_X2_RESET
74 RIC_E2_TERM_INIT = C.E2_TERM_INIT
75 RAN_CONNECTED = C.RAN_CONNECTED
76 RAN_RESTARTED = C.RAN_RESTARTED
77 RAN_RECONFIGURED = C.RAN_RECONFIGURED
78 E2_TERM_KEEP_ALIVE_REQ = C.E2_TERM_KEEP_ALIVE_REQ
79 E2_TERM_KEEP_ALIVE_RESP = C.E2_TERM_KEEP_ALIVE_RESP
80 RIC_E2_SETUP_REQ = C.RIC_E2_SETUP_REQ
81 RIC_E2_SETUP_RESP = C.RIC_E2_SETUP_RESP
82 RIC_E2_SETUP_FAILURE = C.RIC_E2_SETUP_FAILURE
83 RIC_SERVICE_QUERY = C.RIC_SERVICE_QUERY
84 RIC_SERVICE_UPDATE = C.RIC_SERVICE_UPDATE
85 RIC_SERVICE_UPDATE_ACK = C.RIC_SERVICE_UPDATE_ACK
86 RIC_SERVICE_UPDATE_FAILURE = C.RIC_SERVICE_UPDATE_FAILURE
87 RIC_E2NODE_CONFIG_UPDATE = C.RIC_E2NODE_CONFIG_UPDATE
88 RIC_E2NODE_CONFIG_UPDATE_ACK = C.RIC_E2NODE_CONFIG_UPDATE_ACK
89 RIC_E2NODE_CONFIG_UPDATE_FAILURE = C.RIC_E2NODE_CONFIG_UPDATE_FAILURE
90 RIC_E2_RESET_REQ = C.RIC_E2_RESET_REQ
91 RIC_E2_RESET_RESP = C.RIC_E2_RESET_RESP
92 RIC_E2_RIC_ERROR_INDICATION = C.RIC_E2_RIC_ERROR_INDICATION
96 RMR_MAX_XACTION_LEN = int(C.RMR_MAX_XID)
97 RMR_MAX_MEID_LEN = int(C.RMR_MAX_MEID)
98 RMR_MAX_SRC_LEN = int(C.RMR_MAX_SRC)
102 RMR_ERR_BADARG = C.RMR_ERR_BADARG
103 RMR_ERR_NOENDPT = C.RMR_ERR_NOENDPT
104 RMR_ERR_EMPTY = C.RMR_ERR_EMPTY
105 RMR_ERR_NOHDR = C.RMR_ERR_NOHDR
106 RMR_ERR_SENDFAILED = C.RMR_ERR_SENDFAILED
107 RMR_ERR_CALLFAILED = C.RMR_ERR_CALLFAILED
108 RMR_ERR_NOWHOPEN = C.RMR_ERR_NOWHOPEN
109 RMR_ERR_WHID = C.RMR_ERR_WHID
110 RMR_ERR_OVERFLOW = C.RMR_ERR_OVERFLOW
111 RMR_ERR_RETRY = C.RMR_ERR_RETRY
112 RMR_ERR_RCVFAILED = C.RMR_ERR_RCVFAILED
113 RMR_ERR_TIMEOUT = C.RMR_ERR_TIMEOUT
114 RMR_ERR_UNSET = C.RMR_ERR_UNSET
115 RMR_ERR_TRUNC = C.RMR_ERR_TRUNC
116 RMR_ERR_INITFAILED = C.RMR_ERR_INITFAILED
119 var states = map[int]string{
120 RMR_OK: "state is good",
121 RMR_ERR_BADARG: "argument passd to function was unusable",
122 RMR_ERR_NOENDPT: "send/call could not find an endpoint based on msg type",
123 RMR_ERR_EMPTY: "msg received had no payload; attempt to send an empty message",
124 RMR_ERR_NOHDR: "message didn't contain a valid header",
125 RMR_ERR_SENDFAILED: "send failed; errno has nano reason",
126 RMR_ERR_CALLFAILED: "unable to send call() message",
127 RMR_ERR_NOWHOPEN: "no wormholes are open",
128 RMR_ERR_WHID: "wormhole id was invalid",
129 RMR_ERR_OVERFLOW: "operation would have busted through a buffer/field size",
130 RMR_ERR_RETRY: "request (send/call/rts) failed, but caller should retry (EAGAIN for wrappers)",
131 RMR_ERR_RCVFAILED: "receive failed (hard error)",
132 RMR_ERR_TIMEOUT: "message processing call timed out",
133 RMR_ERR_UNSET: "the message hasn't been populated with a transport buffer",
134 RMR_ERR_TRUNC: "received message likely truncated",
135 RMR_ERR_INITFAILED: "initialisation of something (probably message) failed",
141 Meid string //Managed entity id (RAN name)
144 msgSrc unsafe.Pointer
147 func (m MBuf) String() string {
148 return fmt.Sprintf("{ MType: %d, Len: %d, Meid: %q, Xaction: %q, Payload: [%x] }", m.MType, m.Len, m.Meid, m.XAction, m.Payload)
151 func (m MBuf) GetMsgSrc() unsafe.Pointer {
155 type Context struct {
158 RmrCtx unsafe.Pointer
159 Logger *logger.Logger
162 type RmrMessenger interface {
163 Init(port string, maxMsgSize int, flags int, logger *logger.Logger) RmrMessenger
164 SendMsg(msg *MBuf, printLogs bool) (*MBuf, error)
165 WhSendMsg(msg *MBuf, printLogs bool) (*MBuf, error)
166 RecvMsg() (*MBuf, error)