2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 // platform project (RICP).
23 // #cgo LDFLAGS: -L/usr/local/lib -lrmr_nng -lnng
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) *MBuf {
44 func NewContext(maxMsgSize int, flags int, ctx unsafe.Pointer, logger *logger.Logger) *Context {
46 MaxMsgSize: maxMsgSize,
53 //TODO: consider declaring using its own type
56 RanConnected = C.RAN_CONNECTED
57 RanRestarted = C.RAN_RESTARTED
58 RanReconfigured = C.RAN_RECONFIGURED
59 RicResStatusResp = C.RIC_RES_STATUS_RESP
60 RicResStatusFailure = C.RIC_RES_STATUS_FAILURE
61 RicResStatusReq = C.RIC_RES_STATUS_REQ
65 RMR_MAX_XACTION_LEN = int(C.RMR_MAX_XID)
66 RMR_MAX_MEID_LEN = int(C.RMR_MAX_MEID)
70 RMR_ERR_BADARG = C.RMR_ERR_BADARG
71 RMR_ERR_NOENDPT = C.RMR_ERR_NOENDPT
72 RMR_ERR_EMPTY = C.RMR_ERR_EMPTY
73 RMR_ERR_NOHDR = C.RMR_ERR_NOHDR
74 RMR_ERR_SENDFAILED = C.RMR_ERR_SENDFAILED
75 RMR_ERR_CALLFAILED = C.RMR_ERR_CALLFAILED
76 RMR_ERR_NOWHOPEN = C.RMR_ERR_NOWHOPEN
77 RMR_ERR_WHID = C.RMR_ERR_WHID
78 RMR_ERR_OVERFLOW = C.RMR_ERR_OVERFLOW
79 RMR_ERR_RETRY = C.RMR_ERR_RETRY
80 RMR_ERR_RCVFAILED = C.RMR_ERR_RCVFAILED
81 RMR_ERR_TIMEOUT = C.RMR_ERR_TIMEOUT
82 RMR_ERR_UNSET = C.RMR_ERR_UNSET
83 RMR_ERR_TRUNC = C.RMR_ERR_TRUNC
84 RMR_ERR_INITFAILED = C.RMR_ERR_INITFAILED
87 var states = map[int]string{
88 RMR_OK: "state is good",
89 RMR_ERR_BADARG: "argument passd to function was unusable",
90 RMR_ERR_NOENDPT: "send/call could not find an endpoint based on msg type",
91 RMR_ERR_EMPTY: "msg received had no payload; attempt to send an empty message",
92 RMR_ERR_NOHDR: "message didn't contain a valid header",
93 RMR_ERR_SENDFAILED: "send failed; errno has nano reason",
94 RMR_ERR_CALLFAILED: "unable to send call() message",
95 RMR_ERR_NOWHOPEN: "no wormholes are open",
96 RMR_ERR_WHID: "wormhole id was invalid",
97 RMR_ERR_OVERFLOW: "operation would have busted through a buffer/field size",
98 RMR_ERR_RETRY: "request (send/call/rts) failed, but caller should retry (EAGAIN for wrappers)",
99 RMR_ERR_RCVFAILED: "receive failed (hard error)",
100 RMR_ERR_TIMEOUT: "message processing call timed out",
101 RMR_ERR_UNSET: "the message hasn't been populated with a transport buffer",
102 RMR_ERR_TRUNC: "received message likely truncated",
103 RMR_ERR_INITFAILED: "initialisation of something (probably message) failed",
109 Meid string //Managed entity id (RAN name)
114 func (m MBuf) String() string {
115 return fmt.Sprintf("{ MType: %d, Len: %d, Meid: %q, Xaction: %q, Payload: [%x] }", m.MType, m.Len, m.Meid, m.XAction, m.Payload)
118 type Context struct {
121 RmrCtx unsafe.Pointer
122 Logger *logger.Logger
125 type RmrMessenger interface {
126 Init(readyIntervalSec int, port string, maxMsgSize int, flags int, logger *logger.Logger) RmrMessenger
127 SendMsg(msg *MBuf) (*MBuf, error)
128 RecvMsg() (*MBuf, error)