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 ==================================================================================
23 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
24 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap_wrapper"
25 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
33 var e2t_e2asnpacker e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
38 type testingE2termStub struct {
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
45 func createNewE2termStub(desc string, rtfile string, port string, stat string) *testingE2termStub {
46 e2termCtrl := &testingE2termStub{}
47 e2termCtrl.testingRmrStubControl.init(desc, rtfile, port, stat, e2termCtrl)
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
54 func (tc *testingE2termStub) Consume(params *xapp.RMRParams) (err error) {
55 xapp.Rmr.Free(params.Mbuf)
57 msg := &RMRParams{params}
59 if params.Mtype == 55555 {
60 xapp.Logger.Info("(%s) Testing message ignore %s", tc.GetDesc(), msg.String())
65 xapp.Logger.Info("(%s) Consume %s", tc.GetDesc(), msg.String())
70 //-----------------------------------------------------------------------------
72 //-----------------------------------------------------------------------------
73 func (e2termConn *testingE2termStub) handle_e2term_subs_req(t *testing.T) (*e2ap.E2APSubscriptionRequest, *RMRParams) {
74 xapp.Logger.Info("(%s) handle_e2term_subs_req", e2termConn.GetDesc())
75 e2SubsReq := e2t_e2asnpacker.NewPackerSubscriptionRequest()
77 //---------------------------------
78 // e2term activity: Recv Subs Req
79 //---------------------------------
81 case msg := <-e2termConn.rmrConChan:
82 e2termConn.DecMsgCnt()
83 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] {
84 testError(t, "(%s) Received wrong mtype expected %s got %s, error", e2termConn.GetDesc(), "RIC_SUB_REQ", xapp.RicMessageTypeToName[msg.Mtype])
86 xapp.Logger.Info("(%s) Recv Subs Req", e2termConn.GetDesc())
87 packedData := &e2ap.PackedData{}
88 packedData.Buf = msg.Payload
89 unpackerr, req := e2SubsReq.UnPack(packedData)
91 testError(t, "(%s) RIC_SUB_REQ unpack failed err: %s", e2termConn.GetDesc(), unpackerr.Error())
95 case <-time.After(15 * time.Second):
96 testError(t, "(%s) Not Received RIC_SUB_REQ within 15 secs", e2termConn.GetDesc())
101 func (e2termConn *testingE2termStub) handle_e2term_subs_resp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *RMRParams) {
102 xapp.Logger.Info("(%s) handle_e2term_subs_resp", e2termConn.GetDesc())
103 e2SubsResp := e2t_e2asnpacker.NewPackerSubscriptionResponse()
105 //---------------------------------
106 // e2term activity: Send Subs Resp
107 //---------------------------------
108 xapp.Logger.Info("(%s) Send Subs Resp", e2termConn.GetDesc())
110 resp := &e2ap.E2APSubscriptionResponse{}
112 resp.RequestId.Id = req.RequestId.Id
113 resp.RequestId.Seq = req.RequestId.Seq
114 resp.FunctionId = req.FunctionId
116 resp.ActionAdmittedList.Items = make([]e2ap.ActionAdmittedItem, len(req.ActionSetups))
117 for index := int(0); index < len(req.ActionSetups); index++ {
118 resp.ActionAdmittedList.Items[index].ActionId = req.ActionSetups[index].ActionId
121 for index := uint64(0); index < 1; index++ {
122 item := e2ap.ActionNotAdmittedItem{}
123 item.ActionId = index
124 item.Cause.Content = 1
125 item.Cause.CauseVal = 1
126 resp.ActionNotAdmittedList.Items = append(resp.ActionNotAdmittedList.Items, item)
129 packerr, packedMsg := e2SubsResp.Pack(resp)
131 testError(t, "(%s) pack NOK %s", e2termConn.GetDesc(), packerr.Error())
133 xapp.Logger.Debug("(%s) %s", e2termConn.GetDesc(), e2SubsResp.String())
135 params := &RMRParams{&xapp.RMRParams{}}
136 params.Mtype = xapp.RIC_SUB_RESP
137 //params.SubId = msg.SubId
139 params.Payload = packedMsg.Buf
140 params.Meid = msg.Meid
141 //params.Xid = msg.Xid
144 snderr := e2termConn.RmrSend(params)
146 testError(t, "(%s) RMR SEND FAILED: %s", e2termConn.GetDesc(), snderr.Error())
150 //-----------------------------------------------------------------------------
152 //-----------------------------------------------------------------------------
153 type test_subs_fail_params struct {
154 req *e2ap.E2APSubscriptionRequest
155 fail *e2ap.E2APSubscriptionFailure
158 func (p *test_subs_fail_params) Set(req *e2ap.E2APSubscriptionRequest) {
161 p.fail = &e2ap.E2APSubscriptionFailure{}
162 p.fail.RequestId.Id = p.req.RequestId.Id
163 p.fail.RequestId.Seq = p.req.RequestId.Seq
164 p.fail.FunctionId = p.req.FunctionId
165 p.fail.ActionNotAdmittedList.Items = make([]e2ap.ActionNotAdmittedItem, len(p.req.ActionSetups))
166 for index := int(0); index < len(p.fail.ActionNotAdmittedList.Items); index++ {
167 p.fail.ActionNotAdmittedList.Items[index].ActionId = p.req.ActionSetups[index].ActionId
168 p.SetCauseVal(index, 5, 1)
172 func (p *test_subs_fail_params) SetCauseVal(ind int, content uint8, causeval uint8) {
175 for index := int(0); index < len(p.fail.ActionNotAdmittedList.Items); index++ {
176 p.fail.ActionNotAdmittedList.Items[index].Cause.Content = content
177 p.fail.ActionNotAdmittedList.Items[index].Cause.CauseVal = causeval
181 p.fail.ActionNotAdmittedList.Items[ind].Cause.Content = content
182 p.fail.ActionNotAdmittedList.Items[ind].Cause.CauseVal = causeval
185 func (e2termConn *testingE2termStub) handle_e2term_subs_fail(t *testing.T, fparams *test_subs_fail_params, msg *RMRParams) {
186 xapp.Logger.Info("(%s) handle_e2term_subs_fail", e2termConn.GetDesc())
187 e2SubsFail := e2t_e2asnpacker.NewPackerSubscriptionFailure()
189 //---------------------------------
190 // e2term activity: Send Subs Fail
191 //---------------------------------
192 xapp.Logger.Info("(%s) Send Subs Fail", e2termConn.GetDesc())
194 packerr, packedMsg := e2SubsFail.Pack(fparams.fail)
196 testError(t, "(%s) pack NOK %s", e2termConn.GetDesc(), packerr.Error())
198 xapp.Logger.Debug("(%s) %s", e2termConn.GetDesc(), e2SubsFail.String())
200 params := &RMRParams{&xapp.RMRParams{}}
201 params.Mtype = xapp.RIC_SUB_FAILURE
202 params.SubId = msg.SubId
203 params.Payload = packedMsg.Buf
204 params.Meid = msg.Meid
208 snderr := e2termConn.RmrSend(params)
210 testError(t, "(%s) RMR SEND FAILED: %s", e2termConn.GetDesc(), snderr.Error())
214 //-----------------------------------------------------------------------------
216 //-----------------------------------------------------------------------------
217 func (e2termConn *testingE2termStub) handle_e2term_subs_del_req(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *RMRParams) {
218 xapp.Logger.Info("(%s) handle_e2term_subs_del_req", e2termConn.GetDesc())
219 e2SubsDelReq := e2t_e2asnpacker.NewPackerSubscriptionDeleteRequest()
221 //---------------------------------
222 // e2term activity: Recv Subs Del Req
223 //---------------------------------
225 case msg := <-e2termConn.rmrConChan:
226 e2termConn.DecMsgCnt()
227 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] {
228 testError(t, "(%s) Received wrong mtype expected %s got %s, error", e2termConn.GetDesc(), "RIC_SUB_DEL_REQ", xapp.RicMessageTypeToName[msg.Mtype])
230 xapp.Logger.Info("(%s) Recv Subs Del Req", e2termConn.GetDesc())
232 packedData := &e2ap.PackedData{}
233 packedData.Buf = msg.Payload
234 unpackerr, req := e2SubsDelReq.UnPack(packedData)
235 if unpackerr != nil {
236 testError(t, "(%s) RIC_SUB_DEL_REQ unpack failed err: %s", e2termConn.GetDesc(), unpackerr.Error())
240 case <-time.After(15 * time.Second):
241 testError(t, "(%s) Not Received RIC_SUB_DEL_REQ within 15 secs", e2termConn.GetDesc())
246 func handle_e2term_recv_empty() bool {
247 if len(e2termConn.rmrConChan) > 0 {
253 func (e2termConn *testingE2termStub) handle_e2term_subs_del_resp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *RMRParams) {
254 xapp.Logger.Info("(%s) handle_e2term_subs_del_resp", e2termConn.GetDesc())
255 e2SubsDelResp := e2t_e2asnpacker.NewPackerSubscriptionDeleteResponse()
257 //---------------------------------
258 // e2term activity: Send Subs Del Resp
259 //---------------------------------
260 xapp.Logger.Info("(%s) Send Subs Del Resp", e2termConn.GetDesc())
262 resp := &e2ap.E2APSubscriptionDeleteResponse{}
263 resp.RequestId.Id = req.RequestId.Id
264 resp.RequestId.Seq = req.RequestId.Seq
265 resp.FunctionId = req.FunctionId
267 packerr, packedMsg := e2SubsDelResp.Pack(resp)
269 testError(t, "(%s) pack NOK %s", e2termConn.GetDesc(), packerr.Error())
271 xapp.Logger.Debug("(%s) %s", e2termConn.GetDesc(), e2SubsDelResp.String())
273 params := &RMRParams{&xapp.RMRParams{}}
274 params.Mtype = xapp.RIC_SUB_DEL_RESP
275 params.SubId = msg.SubId
276 params.Payload = packedMsg.Buf
277 params.Meid = msg.Meid
281 snderr := e2termConn.RmrSend(params)
283 testError(t, "(%s) RMR SEND FAILED: %s", e2termConn.GetDesc(), snderr.Error())
287 //-----------------------------------------------------------------------------
289 //-----------------------------------------------------------------------------
290 func (e2termConn *testingE2termStub) handle_e2term_subs_del_fail(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *RMRParams) {
291 xapp.Logger.Info("(%s) handle_e2term_del_subs_fail", e2termConn.GetDesc())
292 e2SubsDelFail := e2t_e2asnpacker.NewPackerSubscriptionDeleteFailure()
294 //---------------------------------
295 // e2term activity: Send Subs Del Fail
296 //---------------------------------
297 xapp.Logger.Info("(%s) Send Subs Del Fail", e2termConn.GetDesc())
299 resp := &e2ap.E2APSubscriptionDeleteFailure{}
300 resp.RequestId.Id = req.RequestId.Id
301 resp.RequestId.Seq = req.RequestId.Seq
302 resp.FunctionId = req.FunctionId
303 resp.Cause.Content = 3 // CauseMisc
304 resp.Cause.CauseVal = 4 // unspecified
306 packerr, packedMsg := e2SubsDelFail.Pack(resp)
308 testError(t, "(%s) pack NOK %s", e2termConn.GetDesc(), packerr.Error())
310 xapp.Logger.Debug("(%s) %s", e2termConn.GetDesc(), e2SubsDelFail.String())
312 params := &RMRParams{&xapp.RMRParams{}}
313 params.Mtype = xapp.RIC_SUB_DEL_FAILURE
314 params.SubId = msg.SubId
315 params.Payload = packedMsg.Buf
316 params.Meid = msg.Meid
320 snderr := e2termConn.RmrSend(params)
322 testError(t, "(%s) RMR SEND FAILED: %s", e2termConn.GetDesc(), snderr.Error())