blob: b11ac6f08dd3ea31ff4771f0277cd2e321ce9aa0 [file] [log] [blame]
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +02001/*
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
24package teststubdummy
25
26import (
27 "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub"
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020028 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
29 "testing"
30)
31
32//-----------------------------------------------------------------------------
33//
34//-----------------------------------------------------------------------------
35type RmrDummyStub struct {
36 teststub.RmrStubControl
37 reqMsg int
38 respMsg int
39}
40
41//-----------------------------------------------------------------------------
42//
43//-----------------------------------------------------------------------------
Juha Hyttinencd78aee2020-04-07 17:49:08 +030044func CreateNewRmrDummyStub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int) *RmrDummyStub {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020045 dummyStub := &RmrDummyStub{}
Juha Hyttinencd78aee2020-04-07 17:49:08 +030046 dummyStub.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed)
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020047 dummyStub.reqMsg = mtypeseed + 1
48 dummyStub.respMsg = mtypeseed + 2
49 return dummyStub
50}
51
52//-----------------------------------------------------------------------------
53//
54//-----------------------------------------------------------------------------
55
Juha Hyttinencd78aee2020-04-07 17:49:08 +030056func (tc *RmrDummyStub) SendReq(t *testing.T, plen int) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +030057 tc.Debug("SendReq")
Juha Hyttinencd78aee2020-04-07 17:49:08 +030058 len := plen
59 if len == 0 {
60 len = 100
61 }
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +030062 params := &xapp.RMRParams{}
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020063 params.Mtype = tc.reqMsg
64 params.SubId = -1
Juha Hyttinencd78aee2020-04-07 17:49:08 +030065
66 params.Payload = make([]byte, len)
67 params.PayloadLen = 0
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020068 params.Meid = &xapp.RMRMeid{RanName: "TEST"}
69 params.Xid = "TEST"
70 params.Mbuf = nil
71
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +030072 snderr := tc.SendWithRetry(params, false, 5)
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020073 if snderr != nil {
74 tc.TestError(t, "%s", snderr.Error())
75 }
76 return
77}
78
Juha Hyttinencd78aee2020-04-07 17:49:08 +030079func (tc *RmrDummyStub) SendResp(t *testing.T, plen int) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +030080 tc.Debug("SendReq")
Juha Hyttinencd78aee2020-04-07 17:49:08 +030081 len := plen
82 if len == 0 {
83 len = 100
84 }
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +030085 params := &xapp.RMRParams{}
Juha Hyttinencd78aee2020-04-07 17:49:08 +030086 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
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +030094 snderr := tc.SendWithRetry(params, false, 5)
Juha Hyttinencd78aee2020-04-07 17:49:08 +030095 if snderr != nil {
96 tc.TestError(t, "%s", snderr.Error())
97 }
98 return
99}
100
101func (tc *RmrDummyStub) RecvReq(t *testing.T) bool {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300102 tc.Debug("RecvReq")
Juha Hyttinencd78aee2020-04-07 17:49:08 +0300103
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
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200117func (tc *RmrDummyStub) RecvResp(t *testing.T) bool {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300118 tc.Debug("RecvResp")
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200119
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}