Updated xapp-frame to 0.4.18. Updated rmr to 4.1.2.
[ric-plt/submgr.git] / pkg / teststubdummy / stubRmrDummy.go
1 /*
2 ==================================================================================
3   Copyright (c) 2019 AT&T Intellectual Property.
4   Copyright (c) 2019 Nokia
5
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
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
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.
17 ==================================================================================
18 */
19
20 //
21 // EXAMPLE HOW TO HAVE RMR STUB
22 //
23
24 package teststubdummy
25
26 import (
27         "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub"
28         "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
29         "testing"
30 )
31
32 //-----------------------------------------------------------------------------
33 //
34 //-----------------------------------------------------------------------------
35 type RmrDummyStub struct {
36         teststub.RmrStubControl
37         reqMsg  int
38         respMsg int
39 }
40
41 //-----------------------------------------------------------------------------
42 //
43 //-----------------------------------------------------------------------------
44 func CreateNewRmrDummyStub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int) *RmrDummyStub {
45         dummyStub := &RmrDummyStub{}
46         dummyStub.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed)
47         dummyStub.reqMsg = mtypeseed + 1
48         dummyStub.respMsg = mtypeseed + 2
49         return dummyStub
50 }
51
52 //-----------------------------------------------------------------------------
53 //
54 //-----------------------------------------------------------------------------
55
56 func (tc *RmrDummyStub) SendReq(t *testing.T, plen int) {
57         tc.Info("SendReq")
58         len := plen
59         if len == 0 {
60                 len = 100
61         }
62         params := &xapp.RMRParams{}
63         params.Mtype = tc.reqMsg
64         params.SubId = -1
65
66         params.Payload = make([]byte, len)
67         params.PayloadLen = 0
68         params.Meid = &xapp.RMRMeid{RanName: "TEST"}
69         params.Xid = "TEST"
70         params.Mbuf = nil
71
72         snderr := tc.SendWithRetry(params, false, 5)
73         if snderr != nil {
74                 tc.TestError(t, "%s", snderr.Error())
75         }
76         return
77 }
78
79 func (tc *RmrDummyStub) SendResp(t *testing.T, plen int) {
80         tc.Info("SendReq")
81         len := plen
82         if len == 0 {
83                 len = 100
84         }
85         params := &xapp.RMRParams{}
86         params.Mtype = tc.respMsg
87         params.SubId = -1
88         params.Payload = make([]byte, len)
89         params.PayloadLen = 0
90         params.Meid = &xapp.RMRMeid{RanName: "TEST"}
91         params.Xid = "TEST"
92         params.Mbuf = nil
93
94         snderr := tc.SendWithRetry(params, false, 5)
95         if snderr != nil {
96                 tc.TestError(t, "%s", snderr.Error())
97         }
98         return
99 }
100
101 func (tc *RmrDummyStub) RecvReq(t *testing.T) bool {
102         tc.Info("RecvReq")
103
104         msg := tc.WaitMsg(15)
105         if msg != nil {
106                 if msg.Mtype != tc.reqMsg {
107                         tc.TestError(t, "Received wrong mtype expected %d got %d, error", tc.reqMsg, msg.Mtype)
108                         return false
109                 }
110                 return true
111         } else {
112                 tc.TestError(t, "Not Received msg within %d secs", 15)
113         }
114         return false
115 }
116
117 func (tc *RmrDummyStub) RecvResp(t *testing.T) bool {
118         tc.Info("RecvResp")
119
120         msg := tc.WaitMsg(15)
121         if msg != nil {
122                 if msg.Mtype != tc.respMsg {
123                         tc.TestError(t, "Received wrong mtype expected %d got %d, error", tc.respMsg, msg.Mtype)
124                         return false
125                 }
126                 return true
127         } else {
128                 tc.TestError(t, "Not Received msg within %d secs", 15)
129         }
130         return false
131 }