Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 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" |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 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 | //----------------------------------------------------------------------------- |
Juha Hyttinen | cd78aee | 2020-04-07 17:49:08 +0300 | [diff] [blame] | 44 | func CreateNewRmrDummyStub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int) *RmrDummyStub { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 45 | dummyStub := &RmrDummyStub{} |
Juha Hyttinen | cd78aee | 2020-04-07 17:49:08 +0300 | [diff] [blame] | 46 | dummyStub.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed) |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 47 | dummyStub.reqMsg = mtypeseed + 1 |
| 48 | dummyStub.respMsg = mtypeseed + 2 |
| 49 | return dummyStub |
| 50 | } |
| 51 | |
| 52 | //----------------------------------------------------------------------------- |
| 53 | // |
| 54 | //----------------------------------------------------------------------------- |
| 55 | |
Juha Hyttinen | cd78aee | 2020-04-07 17:49:08 +0300 | [diff] [blame] | 56 | func (tc *RmrDummyStub) SendReq(t *testing.T, plen int) { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 57 | tc.Debug("SendReq") |
Juha Hyttinen | cd78aee | 2020-04-07 17:49:08 +0300 | [diff] [blame] | 58 | len := plen |
| 59 | if len == 0 { |
| 60 | len = 100 |
| 61 | } |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 62 | params := &xapp.RMRParams{} |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 63 | params.Mtype = tc.reqMsg |
| 64 | params.SubId = -1 |
Juha Hyttinen | cd78aee | 2020-04-07 17:49:08 +0300 | [diff] [blame] | 65 | |
| 66 | params.Payload = make([]byte, len) |
| 67 | params.PayloadLen = 0 |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 68 | params.Meid = &xapp.RMRMeid{RanName: "TEST"} |
| 69 | params.Xid = "TEST" |
| 70 | params.Mbuf = nil |
| 71 | |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 72 | snderr := tc.SendWithRetry(params, false, 5) |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 73 | if snderr != nil { |
| 74 | tc.TestError(t, "%s", snderr.Error()) |
| 75 | } |
| 76 | return |
| 77 | } |
| 78 | |
Juha Hyttinen | cd78aee | 2020-04-07 17:49:08 +0300 | [diff] [blame] | 79 | func (tc *RmrDummyStub) SendResp(t *testing.T, plen int) { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 80 | tc.Debug("SendReq") |
Juha Hyttinen | cd78aee | 2020-04-07 17:49:08 +0300 | [diff] [blame] | 81 | len := plen |
| 82 | if len == 0 { |
| 83 | len = 100 |
| 84 | } |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 85 | params := &xapp.RMRParams{} |
Juha Hyttinen | cd78aee | 2020-04-07 17:49:08 +0300 | [diff] [blame] | 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 | |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 94 | snderr := tc.SendWithRetry(params, false, 5) |
Juha Hyttinen | cd78aee | 2020-04-07 17:49:08 +0300 | [diff] [blame] | 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 { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 102 | tc.Debug("RecvReq") |
Juha Hyttinen | cd78aee | 2020-04-07 17:49:08 +0300 | [diff] [blame] | 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 | |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 117 | func (tc *RmrDummyStub) RecvResp(t *testing.T) bool { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 118 | tc.Debug("RecvResp") |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 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 | } |