Added wormhole call API's -2 75/2875/2 v0.4.2
authorwahidw <abdulwahid.w@nokia.com>
Thu, 19 Mar 2020 14:49:41 +0000 (14:49 +0000)
committerwahidw <abdulwahid.w@nokia.com>
Thu, 19 Mar 2020 15:09:32 +0000 (15:09 +0000)
Change-Id: I5746a874447e2c55eb73681301b44080c335b5c1
Signed-off-by: wahidw <abdulwahid.w@nokia.com>
ci/Dockerfile
pkg/xapp/rmr.go
pkg/xapp/xapp_test.go

index 99768a7..c9886e2 100755 (executable)
@@ -35,7 +35,7 @@ RUN apt-get update -y \
 RUN curl -s https://packagecloud.io/install/repositories/o-ran-sc/master/script.deb.sh | bash
 
 # RMR
-ARG RMRVERSION=3.5.0
+ARG RMRVERSION=3.5.2
 #RUN apt-get install -y rmr=${RMRVERSION} rmr-dev=${RMRVERSION}
 RUN wget --content-disposition https://packagecloud.io/o-ran-sc/staging/packages/debian/stretch/rmr_${RMRVERSION}_amd64.deb/download.deb && dpkg -i rmr_${RMRVERSION}_amd64.deb
 RUN wget --content-disposition https://packagecloud.io/o-ran-sc/staging/packages/debian/stretch/rmr-dev_${RMRVERSION}_amd64.deb/download.deb && dpkg -i rmr-dev_${RMRVERSION}_amd64.deb
index 44f0178..0aeced2 100755 (executable)
@@ -82,6 +82,8 @@ type RMRParams struct {
        Src        string
        Mbuf       *C.rmr_mbuf_t
        Whid       int
+       Callid     int
+       Timeout    int
        status     int
 }
 
@@ -233,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
                }
        }
 
@@ -265,7 +267,15 @@ 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 {
 
+       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
@@ -324,6 +334,39 @@ func (m *RMRClient) SendBuf(txBuffer *C.rmr_mbuf_t, isRts bool, whid int) int {
        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)
 }
index e36d1cb..e52c3ee 100755 (executable)
@@ -189,6 +189,47 @@ func TestMessagesReceivedSuccessfullyUsingWh(t *testing.T) {
        Rmr.Closewh(int(whid))
 }
 
+func TestMessagesReceivedSuccessfullyUsingWhCall(t *testing.T) {
+        time.Sleep(time.Duration(5) * time.Second)
+        whid := Rmr.Openwh("localhost:4560")
+                params := &RMRParams{}
+                params.Payload = []byte("newrt|start\nnewrt|end\n")
+                params.Whid = int(whid)
+               params.Callid = 4
+               params.Timeout = 1000
+               Rmr.SendCallMsg(params)
+
+       // Allow time to process the messages
+       time.Sleep(time.Duration(2) * time.Second)
+
+        waitForSdl := viper.GetBool("db.waitForSdl")
+        stats := getMetrics(t)
+        if !strings.Contains(stats, "ricxapp_RMR_Transmitted 200") {
+                t.Errorf("Error: ricxapp_RMR_Transmitted value incorrect: %v", stats)
+        }
+
+        if !strings.Contains(stats, "ricxapp_RMR_Received 201") {
+                t.Errorf("Error: ricxapp_RMR_Received value incorrect: %v", stats)
+        }
+
+        if !strings.Contains(stats, "ricxapp_RMR_TransmitError 1") {
+                t.Errorf("Error: ricxapp_RMR_TransmitError value incorrect")
+        }
+
+        if !strings.Contains(stats, "ricxapp_RMR_ReceiveError 0") {
+                t.Errorf("Error: ricxapp_RMR_ReceiveError value incorrect")
+        }
+
+        if waitForSdl && !strings.Contains(stats, "ricxapp_SDL_Stored 201") {
+                t.Errorf("Error: ricxapp_SDL_Stored value incorrect")
+        }
+
+        if waitForSdl && !strings.Contains(stats, "ricxapp_SDL_StoreError 0") {
+                t.Errorf("Error: ricxapp_SDL_StoreError value incorrect")
+        }
+        Rmr.Closewh(int(whid))
+}
+
 func TestSubscribeChannels(t *testing.T) {
        if !viper.GetBool("db.waitForSdl") {
                return