X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fxapp%2Frmr.go;h=0aeced219009dd3d54e3aa8d2477bd94c0ef6f12;hb=5953f7e372df54c71f526e9519e8eb0ee7ee6f72;hp=fc354c3db21243331795679040a585d7181d0fb4;hpb=b4c7039b6a720c2b35deb79b3018472243677c70;p=ric-plt%2Fxapp-frame.git diff --git a/pkg/xapp/rmr.go b/pkg/xapp/rmr.go index fc354c3..0aeced2 100755 --- a/pkg/xapp/rmr.go +++ b/pkg/xapp/rmr.go @@ -32,7 +32,7 @@ void write_bytes_array(unsigned char *dst, void *data, int len) { } #cgo CFLAGS: -I../ -#cgo LDFLAGS: -lrmr_nng -lnng +#cgo LDFLAGS: -lrmr_si */ import "C" @@ -81,15 +81,21 @@ type RMRParams struct { SubId int Src string Mbuf *C.rmr_mbuf_t + Whid int + Callid int + Timeout int status int } -func NewRMRClientWithParams(protPort string, maxSize int, numWorkers int, statDesc string) *RMRClient { +func NewRMRClientWithParams(protPort string, maxSize int, numWorkers int, threadType int, statDesc string) *RMRClient { p := C.CString(protPort) m := C.int(maxSize) + c := C.int(threadType) defer C.free(unsafe.Pointer(p)) - ctx := C.rmr_init(p, m, C.int(0)) + //ctx := C.rmr_init(p, m, C.int(0)) + //ctx := C.rmr_init(p, m, C.RMRFL_NOTHREAD) + ctx := C.rmr_init(p, m, c) if ctx == nil { Logger.Error("rmrClient: Initializing RMR context failed, bailing out!") } @@ -104,7 +110,7 @@ func NewRMRClientWithParams(protPort string, maxSize int, numWorkers int, statDe } func NewRMRClient() *RMRClient { - return NewRMRClientWithParams(viper.GetString("rmr.protPort"), viper.GetInt("rmr.maxSize"), viper.GetInt("rmr.numWorkers"), "RMR") + return NewRMRClientWithParams(viper.GetString("rmr.protPort"), viper.GetInt("rmr.maxSize"), viper.GetInt("rmr.numWorkers"), viper.GetInt("rmr.threadType"), "RMR") } func (m *RMRClient) Start(c MessageConsumer) { @@ -229,12 +235,12 @@ func (m *RMRClient) SendRts(params *RMRParams) bool { return m.Send(params, true) } -func (m *RMRClient) Send(params *RMRParams, isRts bool) bool { +func (m *RMRClient) CopyBuffer(params *RMRParams) *C.rmr_mbuf_t { txBuffer := params.Mbuf if txBuffer == nil { txBuffer = m.Allocate() if txBuffer == nil { - return false + return nil } } @@ -261,25 +267,37 @@ func (m *RMRClient) Send(params *RMRParams, isRts bool) bool { } } C.write_bytes_array(txBuffer.payload, datap, txBuffer.len) + return txBuffer +} + +func (m *RMRClient) Send(params *RMRParams, isRts bool) bool { - params.status = m.SendBuf(txBuffer, isRts) + txBuffer := m.CopyBuffer(params) + if txBuffer == nil { + return false + } + params.status = m.SendBuf(txBuffer, isRts, params.Whid) if params.status == int(C.RMR_OK) { return true } return false } -func (m *RMRClient) SendBuf(txBuffer *C.rmr_mbuf_t, isRts bool) int { +func (m *RMRClient) SendBuf(txBuffer *C.rmr_mbuf_t, isRts bool, whid int) int { var ( currBuffer *C.rmr_mbuf_t counterName string = "Transmitted" ) txBuffer.state = 0 - if isRts { - currBuffer = C.rmr_rts_msg(m.context, txBuffer) + if whid != 0 { + currBuffer = C.rmr_wh_send_msg(m.context, C.rmr_whid_t(whid), txBuffer) } else { - currBuffer = C.rmr_send_msg(m.context, txBuffer) + if isRts { + currBuffer = C.rmr_rts_msg(m.context, txBuffer) + } else { + currBuffer = C.rmr_send_msg(m.context, txBuffer) + } } if currBuffer == nil { @@ -294,10 +312,14 @@ func (m *RMRClient) SendBuf(txBuffer *C.rmr_mbuf_t, isRts bool) int { } for j := 0; j < maxRetryOnFailure && currBuffer != nil && currBuffer.state == C.RMR_ERR_RETRY; j++ { - if isRts { - currBuffer = C.rmr_rts_msg(m.context, currBuffer) + if whid != 0 { + currBuffer = C.rmr_wh_send_msg(m.context, C.rmr_whid_t(whid), txBuffer) } else { - currBuffer = C.rmr_send_msg(m.context, currBuffer) + if isRts { + currBuffer = C.rmr_rts_msg(m.context, txBuffer) + } else { + currBuffer = C.rmr_send_msg(m.context, txBuffer) + } } } @@ -307,11 +329,61 @@ func (m *RMRClient) SendBuf(txBuffer *C.rmr_mbuf_t, isRts bool) int { } m.UpdateStatCounter(counterName) - m.Free(currBuffer) + defer m.Free(currBuffer) return int(currBuffer.state) } +func (m *RMRClient) SendCallMsg(params *RMRParams) (int, string) { + var ( + currBuffer *C.rmr_mbuf_t + counterName string = "Transmitted" + ) + txBuffer := m.CopyBuffer(params) + if txBuffer == nil { + return C.RMR_ERR_INITFAILED, "" + } + + txBuffer.state = 0 + + currBuffer = C.rmr_wh_call(m.context, C.int(params.Whid), txBuffer, C.int(params.Callid), C.int(params.Timeout)) + + if currBuffer == nil { + m.UpdateStatCounter("TransmitError") + return m.LogMBufError("SendBuf failed", txBuffer), "" + } + + if currBuffer.state != C.RMR_OK { + counterName = "TransmitError" + m.LogMBufError("SendBuf failed", currBuffer) + } + + m.UpdateStatCounter(counterName) + defer m.Free(currBuffer) + + cptr := unsafe.Pointer(currBuffer.payload) + payload := C.GoBytes(cptr, C.int(currBuffer.len)) + + return int(currBuffer.state), string(payload) +} + +func (m *RMRClient) Openwh(target string) C.rmr_whid_t { + return m.Wh_open(target) +} + +func (m *RMRClient) Wh_open(target string) C.rmr_whid_t { + endpoint := C.CString(target) + return C.rmr_wh_open(m.context, endpoint) +} + +func (m *RMRClient) Closewh(whid int) { + m.Wh_close(C.rmr_whid_t(whid)) +} + +func (m *RMRClient) Wh_close(whid C.rmr_whid_t) { + C.rmr_wh_close(m.context, whid) +} + func (m *RMRClient) IsRetryError(params *RMRParams) bool { if params.status == int(C.RMR_ERR_RETRY) { return true