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/xapp-frame/pkg/xapp"
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
32 type RmrStubControl struct {
35 RecvChan chan *xapp.RMRParams
41 func (tc *RmrStubControl) SetActive() {
45 func (tc *RmrStubControl) IsActive() bool {
49 func (tc *RmrStubControl) SetCheckXid(val bool) {
53 func (tc *RmrStubControl) IsCheckXid() bool {
57 func (tc *RmrStubControl) IsChanEmpty() bool {
58 if len(tc.RecvChan) > 0 {
64 func (tc *RmrStubControl) TestMsgChanEmpty(t *testing.T) {
65 if tc.IsChanEmpty() == false {
66 tc.TestError(t, "message channel not empty")
70 func (tc *RmrStubControl) Init(desc string, srcId RmrSrcId, rtgSvc RmrRtgSvc, stat string, initMsg int) {
73 tc.RecvChan = make(chan *xapp.RMRParams)
74 tc.RmrControl.Init(desc, srcId, rtgSvc)
76 tc.RMRClient = xapp.NewRMRClientWithParams(&xapp.RMRClientParams{
77 ProtPort: "tcp:" + strconv.FormatUint(uint64(srcId.Port), 10),
85 tc.RMRClient.SetReadyCB(tc.ReadyCB, nil)
86 go tc.RMRClient.Start(tc)
89 allRmrStubs = append(allRmrStubs, tc)
92 func (tc *RmrStubControl) Consume(msg *xapp.RMRParams) (err error) {
93 defer tc.RMRClient.Free(msg.Mbuf)
95 cPay := append(msg.Payload[:0:0], msg.Payload...)
97 msg.PayloadLen = len(cPay)
99 if msg.Mtype == tc.InitMsg {
100 tc.Info("Testing message ignore %s", msg.String())
105 if tc.IsCheckXid() == true && strings.Contains(msg.Xid, tc.GetDesc()) == false {
106 tc.Info("Ignore %s", msg.String())
110 tc.Info("Consume %s", msg.String())
115 func (tc *RmrStubControl) PushMsg(msg *xapp.RMRParams) {
116 tc.Debug("RmrStubControl PushMsg ... msg(%d) waiting", msg.Mtype)
118 tc.Debug("RmrStubControl PushMsg ... done")
121 func (tc *RmrStubControl) WaitMsg(secs time.Duration) *xapp.RMRParams {
122 tc.Debug("RmrStubControl WaitMsg ... waiting")
125 tc.Debug("RmrStubControl WaitMsg ... msg(%d) done", msg.Mtype)
129 case msg := <-tc.RecvChan:
130 tc.Debug("RmrStubControl WaitMsg ... msg(%d) done", msg.Mtype)
132 case <-time.After(secs * time.Second):
133 tc.Debug("RmrStubControl WaitMsg ... timeout")
136 tc.Debug("RmrStubControl WaitMsg ... error")
140 var allRmrStubs []*RmrStubControl
142 //-----------------------------------------------------------------------------
144 //-----------------------------------------------------------------------------
146 func RmrStubControlWaitAlive(seconds int, mtype int, rmr *xapp.RMRClient, tent *TestWrapper) bool {
148 var dummyBuf []byte = make([]byte, 100)
150 params := &xapp.RMRParams{}
153 params.Payload = dummyBuf
154 params.PayloadLen = 100
155 params.Meid = &xapp.RMRMeid{RanName: "TESTPING"}
156 params.Xid = "TESTPING"
159 if len(allRmrStubs) == 0 {
160 tent.Info("No rmr stubs so no need to wait those to be alive")
165 for ; i <= seconds*2 && status == false; i++ {
167 tent.Info("SEND TESTPING: %s", params.String())
168 rmr.SendWithRetry(params, false, 0)
171 for _, val := range allRmrStubs {
172 if val.IsActive() == false {
180 tent.Info("Sleep 0.5 secs and try routes again")
181 time.Sleep(500 * time.Millisecond)
185 tent.Error("Could not initialize routes")