/* ================================================================================== Copyright (c) 2019 AT&T Intellectual Property. Copyright (c) 2019 Nokia Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================================================== */ // // EXAMPLE HOW TO HAVE RMR STUB // package teststubdummy import ( "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub" "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/xapptweaks" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" "testing" ) //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- type RmrDummyStub struct { teststub.RmrStubControl reqMsg int respMsg int } //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- func CreateNewRmrDummyStub(desc string, rtfile string, port string, stat string, mtypeseed int) *RmrDummyStub { dummyStub := &RmrDummyStub{} dummyStub.RmrStubControl.Init(desc, rtfile, port, stat, mtypeseed) dummyStub.reqMsg = mtypeseed + 1 dummyStub.respMsg = mtypeseed + 2 return dummyStub } //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- func (tc *RmrDummyStub) SendReq(t *testing.T) { tc.Logger.Info("SendReq") var dummyBuf []byte = make([]byte, 100) params := xapptweaks.NewParams(nil) params.Mtype = tc.reqMsg params.SubId = -1 params.Payload = dummyBuf params.PayloadLen = 100 params.Meid = &xapp.RMRMeid{RanName: "TEST"} params.Xid = "TEST" params.Mbuf = nil snderr := tc.RmrSend(params) if snderr != nil { tc.TestError(t, "%s", snderr.Error()) } return } func (tc *RmrDummyStub) RecvResp(t *testing.T) bool { tc.Logger.Info("RecvResp") msg := tc.WaitMsg(15) if msg != nil { if msg.Mtype != tc.respMsg { tc.TestError(t, "Received wrong mtype expected %d got %d, error", tc.respMsg, msg.Mtype) return false } return true } else { tc.TestError(t, "Not Received msg within %d secs", 15) } return false } //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- func RmrDummyHandleMessage(msg *xapptweaks.RMRParams, mtypeseed int, rmr xapptweaks.XAppWrapperIf) (bool, error) { if msg.Mtype == mtypeseed+1 { var dummyBuf []byte = make([]byte, 100) params := xapptweaks.NewParams(nil) params.Mtype = mtypeseed + 2 params.SubId = msg.SubId params.Payload = dummyBuf params.PayloadLen = 100 params.Meid = msg.Meid params.Xid = msg.Xid params.Mbuf = nil rmr.GetLogger().Info("SEND DUMMY RESP: %s", params.String()) err := rmr.RmrSend(params) if err != nil { rmr.GetLogger().Error("RmrDummyHandleMessage: err(%s)", err.Error()) } return true, err } return false, nil }