2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
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
10 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================================
22 "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/xapptweaks"
23 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
33 type RmrStubControl struct {
36 RecvChan chan *xapptweaks.RMRParams
42 func (tc *RmrStubControl) SetActive() {
46 func (tc *RmrStubControl) IsActive() bool {
50 func (tc *RmrStubControl) SetCheckXid(val bool) {
54 func (tc *RmrStubControl) IsCheckXid() bool {
58 func (tc *RmrStubControl) IsChanEmpty() bool {
59 if len(tc.RecvChan) > 0 {
65 func (tc *RmrStubControl) TestMsgChanEmpty(t *testing.T) {
66 if tc.IsChanEmpty() == false {
67 tc.TestError(t, "message channel not empty")
71 func (tc *RmrStubControl) Init(desc string, srcId RmrSrcId, rtgSvc RmrRtgSvc, stat string, initMsg int) {
74 tc.RecvChan = make(chan *xapptweaks.RMRParams)
75 tc.RmrControl.Init(desc, srcId, rtgSvc)
78 tc.Rmr = xapp.NewRMRClientWithParams("tcp:"+strconv.FormatUint(uint64(srcId.Port), 10), 65534, 1, 0, stat)
79 tc.Rmr.SetReadyCB(tc.ReadyCB, nil)
83 allRmrStubs = append(allRmrStubs, tc)
86 func (tc *RmrStubControl) Consume(params *xapp.RMRParams) (err error) {
87 defer tc.Rmr.Free(params.Mbuf)
88 msg := xapptweaks.NewParams(params)
91 if msg.Mtype == tc.InitMsg {
92 tc.Logger.Info("Testing message ignore %s", msg.String())
97 if tc.IsCheckXid() == true && strings.Contains(msg.Xid, tc.GetDesc()) == false {
98 tc.Logger.Info("Ignore %s", msg.String())
102 tc.Logger.Info("Consume %s", msg.String())
107 func (tc *RmrStubControl) PushMsg(msg *xapptweaks.RMRParams) {
108 tc.Logger.Debug("RmrStubControl PushMsg ... msg(%d) waiting", msg.Mtype)
110 tc.Logger.Debug("RmrStubControl PushMsg ... done")
113 func (tc *RmrStubControl) WaitMsg(secs time.Duration) *xapptweaks.RMRParams {
114 tc.Logger.Debug("RmrStubControl WaitMsg ... waiting")
117 tc.Logger.Debug("RmrStubControl WaitMsg ... msg(%d) done", msg.Mtype)
121 case msg := <-tc.RecvChan:
122 tc.Logger.Debug("RmrStubControl WaitMsg ... msg(%d) done", msg.Mtype)
124 case <-time.After(secs * time.Second):
125 tc.Logger.Debug("RmrStubControl WaitMsg ... timeout")
128 tc.Logger.Debug("RmrStubControl WaitMsg ... error")
132 var allRmrStubs []*RmrStubControl
134 //-----------------------------------------------------------------------------
136 //-----------------------------------------------------------------------------
138 func RmrStubControlWaitAlive(seconds int, mtype int, rmr xapptweaks.XAppWrapperIf) bool {
140 var dummyBuf []byte = make([]byte, 100)
142 params := xapptweaks.NewParams(nil)
145 params.Payload = dummyBuf
146 params.PayloadLen = 100
147 params.Meid = &xapp.RMRMeid{RanName: "TESTPING"}
148 params.Xid = "TESTPING"
151 if len(allRmrStubs) == 0 {
152 rmr.GetLogger().Info("No rmr stubs so no need to wait those to be alive")
157 for ; i <= seconds*2 && status == false; i++ {
159 rmr.GetLogger().Info("SEND TESTPING: %s", params.String())
160 rmr.RmrSend(params, 0)
163 for _, val := range allRmrStubs {
164 if val.IsActive() == false {
172 rmr.GetLogger().Info("Sleep 0.5 secs and try routes again")
173 time.Sleep(500 * time.Millisecond)
177 rmr.GetLogger().Error("Could not initialize routes")