Adding new comments for Oran in all files with licenses
[ric-plt/e2mgr.git] / E2Manager / rmrCgo / rmrCgoTypes.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 rmrCgo
22
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>
27 import "C"
28 import (
29         "e2mgr/logger"
30         "fmt"
31         "unsafe"
32 )
33
34 func NewMBuf(mType int, len int, meid string, payload *[]byte, xAction *[]byte) *MBuf {
35         return &MBuf{
36                 MType:   mType,
37                 Len:     len,
38                 Meid:    meid,
39                 Payload: payload,
40                 XAction: xAction,
41         }
42 }
43
44 func NewContext(maxMsgSize int, flags int, ctx unsafe.Pointer, logger *logger.Logger) *Context {
45         return &Context{
46                 MaxMsgSize: maxMsgSize,
47                 Flags:      flags,
48                 RmrCtx:     ctx,
49                 Logger:     logger,
50         }
51 }
52
53 //TODO: consider declaring using its own type
54 const (
55         // messages
56         RIC_X2_SETUP_REQ                     = C.RIC_X2_SETUP_REQ
57         RIC_X2_SETUP_RESP                    = C.RIC_X2_SETUP_RESP
58         RIC_X2_SETUP_FAILURE                 = C.RIC_X2_SETUP_FAILURE
59         RIC_ENDC_X2_SETUP_REQ                = C.RIC_ENDC_X2_SETUP_REQ
60         RIC_ENDC_X2_SETUP_RESP               = C.RIC_ENDC_X2_SETUP_RESP
61         RIC_ENDC_X2_SETUP_FAILURE            = C.RIC_ENDC_X2_SETUP_FAILURE
62         RIC_SCTP_CONNECTION_FAILURE          = C.RIC_SCTP_CONNECTION_FAILURE
63         RIC_ENB_LOAD_INFORMATION             = C.RIC_ENB_LOAD_INFORMATION
64         RIC_ENB_CONF_UPDATE                  = C.RIC_ENB_CONF_UPDATE
65         RIC_ENB_CONFIGURATION_UPDATE_ACK     = C.RIC_ENB_CONF_UPDATE_ACK
66         RIC_ENB_CONFIGURATION_UPDATE_FAILURE = C.RIC_ENB_CONF_UPDATE_FAILURE
67         RIC_ENDC_CONF_UPDATE                 = C.RIC_ENDC_CONF_UPDATE
68         RIC_ENDC_CONF_UPDATE_ACK             = C.RIC_ENDC_CONF_UPDATE_ACK
69         RIC_ENDC_CONF_UPDATE_FAILURE         = C.RIC_ENDC_CONF_UPDATE_FAILURE
70         RIC_SCTP_CLEAR_ALL                   = C.RIC_SCTP_CLEAR_ALL
71         RIC_X2_RESET_RESP                    = C.RIC_X2_RESET_RESP
72         RIC_X2_RESET                         = C.RIC_X2_RESET
73         RIC_E2_TERM_INIT                                         = C.E2_TERM_INIT
74         RAN_CONNECTED                                            = C.RAN_CONNECTED
75         RAN_RESTARTED                                            = C.RAN_RESTARTED
76         RAN_RECONFIGURED                                         = C.RAN_RECONFIGURED
77 )
78
79 const (
80         RMR_MAX_XACTION_LEN = int(C.RMR_MAX_XID)
81         RMR_MAX_MEID_LEN    = int(C.RMR_MAX_MEID)
82
83         //states
84         RMR_OK             = C.RMR_OK
85         RMR_ERR_BADARG     = C.RMR_ERR_BADARG
86         RMR_ERR_NOENDPT    = C.RMR_ERR_NOENDPT
87         RMR_ERR_EMPTY      = C.RMR_ERR_EMPTY
88         RMR_ERR_NOHDR      = C.RMR_ERR_NOHDR
89         RMR_ERR_SENDFAILED = C.RMR_ERR_SENDFAILED
90         RMR_ERR_CALLFAILED = C.RMR_ERR_CALLFAILED
91         RMR_ERR_NOWHOPEN   = C.RMR_ERR_NOWHOPEN
92         RMR_ERR_WHID       = C.RMR_ERR_WHID
93         RMR_ERR_OVERFLOW   = C.RMR_ERR_OVERFLOW
94         RMR_ERR_RETRY      = C.RMR_ERR_RETRY
95         RMR_ERR_RCVFAILED  = C.RMR_ERR_RCVFAILED
96         RMR_ERR_TIMEOUT    = C.RMR_ERR_TIMEOUT
97         RMR_ERR_UNSET      = C.RMR_ERR_UNSET
98         RMR_ERR_TRUNC      = C.RMR_ERR_TRUNC
99         RMR_ERR_INITFAILED = C.RMR_ERR_INITFAILED
100 )
101
102 var states = map[int]string{
103         RMR_OK:             "state is good",
104         RMR_ERR_BADARG:     "argument passd to function was unusable",
105         RMR_ERR_NOENDPT:    "send/call could not find an endpoint based on msg type",
106         RMR_ERR_EMPTY:      "msg received had no payload; attempt to send an empty message",
107         RMR_ERR_NOHDR:      "message didn't contain a valid header",
108         RMR_ERR_SENDFAILED: "send failed; errno has nano reason",
109         RMR_ERR_CALLFAILED: "unable to send call() message",
110         RMR_ERR_NOWHOPEN:   "no wormholes are open",
111         RMR_ERR_WHID:       "wormhole id was invalid",
112         RMR_ERR_OVERFLOW:   "operation would have busted through a buffer/field size",
113         RMR_ERR_RETRY:      "request (send/call/rts) failed, but caller should retry (EAGAIN for wrappers)",
114         RMR_ERR_RCVFAILED:  "receive failed (hard error)",
115         RMR_ERR_TIMEOUT:    "message processing call timed out",
116         RMR_ERR_UNSET:      "the message hasn't been populated with a transport buffer",
117         RMR_ERR_TRUNC:      "received message likely truncated",
118         RMR_ERR_INITFAILED: "initialisation of something (probably message) failed",
119 }
120
121 type MBuf struct {
122         MType   int
123         Len     int
124         Meid    string //Managed entity id (RAN name)
125         Payload *[]byte
126         XAction *[]byte
127 }
128
129 func (m MBuf) String() string {
130         return fmt.Sprintf("{ MType: %d, Len: %d, Meid: %q, Xaction: %q, Payload: [%x] }", m.MType, m.Len, m.Meid, m.XAction, m.Payload)
131 }
132
133 type Context struct {
134         MaxMsgSize int
135         Flags      int
136         RmrCtx     unsafe.Pointer
137         Logger     *logger.Logger
138 }
139
140 type RmrMessenger interface {
141         Init(port string, maxMsgSize int, flags int, logger *logger.Logger) *RmrMessenger
142         SendMsg(msg *MBuf) (*MBuf, error)
143         RecvMsg() (*MBuf, error)
144         RtsMsg(msg *MBuf)
145         IsReady() bool
146         Close()
147 }