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/submgr/pkg/teststub"
26 "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/xapptweaks"
27 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
35 var e2asnpacker e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
40 type RmrTransactionId struct {
45 func (trans *RmrTransactionId) String() string {
46 return "trans(" + trans.xid + "/" + (&xapptweaks.RMRMeid{trans.meid}).String() + ")"
50 teststub.RmrStubControl
54 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
57 func CreateNewE2Stub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int) *E2Stub {
59 tc.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed)
65 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
68 func CreateNewE2termStub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int) *E2Stub {
70 tc.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed)
76 //-----------------------------------------------------------------------------
78 //-----------------------------------------------------------------------------
79 func (tc *E2Stub) NewRmrTransactionId(xid string, ranname string) *RmrTransactionId {
80 trans := &RmrTransactionId{}
82 trans.xid = tc.GetDesc() + "_XID_" + strconv.FormatUint(uint64(tc.xid_seq), 10)
87 trans.meid = &xapp.RMRMeid{RanName: ranname}
88 tc.Logger.Info("New test %s", trans.String())
92 //-----------------------------------------------------------------------------
94 //-----------------------------------------------------------------------------
95 type E2StubSubsReqParams struct {
96 Req *e2ap.E2APSubscriptionRequest
99 func (p *E2StubSubsReqParams) Init() {
100 p.Req = &e2ap.E2APSubscriptionRequest{}
102 p.Req.RequestId.Id = 1
103 p.Req.RequestId.InstanceId = 0
106 // gnb -> enb outgoing
107 // enb -> gnb incoming
109 p.Req.EventTriggerDefinition.Data.Length = 1
110 p.Req.EventTriggerDefinition.Data.Data = make([]uint8, p.Req.EventTriggerDefinition.Data.Length)
111 p.Req.EventTriggerDefinition.Data.Data[0] = 1
113 p.Req.ActionSetups = make([]e2ap.ActionToBeSetupItem, 1)
115 p.Req.ActionSetups[0].ActionId = 0
116 p.Req.ActionSetups[0].ActionType = e2ap.E2AP_ActionTypeReport
117 p.Req.ActionSetups[0].RicActionDefinitionPresent = true
119 p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Length = 1
120 p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Data = make([]uint8, p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Length)
121 p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Data[0] = 1
123 p.Req.ActionSetups[0].SubsequentAction.Present = true
124 p.Req.ActionSetups[0].SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeContinue
125 p.Req.ActionSetups[0].SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitZero
128 //-----------------------------------------------------------------------------
130 //-----------------------------------------------------------------------------
132 type E2StubSubsFailParams struct {
133 Req *e2ap.E2APSubscriptionRequest
134 Fail *e2ap.E2APSubscriptionFailure
137 func (p *E2StubSubsFailParams) Set(req *e2ap.E2APSubscriptionRequest) {
140 p.Fail = &e2ap.E2APSubscriptionFailure{}
141 p.Fail.RequestId.Id = p.Req.RequestId.Id
142 p.Fail.RequestId.InstanceId = p.Req.RequestId.InstanceId
143 p.Fail.FunctionId = p.Req.FunctionId
144 p.Fail.ActionNotAdmittedList.Items = make([]e2ap.ActionNotAdmittedItem, len(p.Req.ActionSetups))
145 for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ {
146 p.Fail.ActionNotAdmittedList.Items[index].ActionId = p.Req.ActionSetups[index].ActionId
147 p.SetCauseVal(index, 5, 1)
151 func (p *E2StubSubsFailParams) SetCauseVal(ind int, content uint8, causeval uint8) {
154 for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ {
155 p.Fail.ActionNotAdmittedList.Items[index].Cause.Content = content
156 p.Fail.ActionNotAdmittedList.Items[index].Cause.Value = causeval
160 p.Fail.ActionNotAdmittedList.Items[ind].Cause.Content = content
161 p.Fail.ActionNotAdmittedList.Items[ind].Cause.Value = causeval
164 //-----------------------------------------------------------------------------
166 //-----------------------------------------------------------------------------
168 func (tc *E2Stub) SendSubsReq(t *testing.T, rparams *E2StubSubsReqParams, oldTrans *RmrTransactionId) *RmrTransactionId {
172 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
175 tc.Logger.Info("SendSubsReq %s", trans.String())
176 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
178 //---------------------------------
179 // xapp activity: Send Subs Req
180 //---------------------------------
184 myparams = &E2StubSubsReqParams{}
188 err, packedMsg := e2SubsReq.Pack(myparams.Req)
190 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
193 tc.Logger.Debug("%s %s", trans.String(), e2SubsReq.String())
195 params := xapptweaks.NewParams(nil)
196 params.Mtype = xapp.RIC_SUB_REQ
198 params.Payload = packedMsg.Buf
199 params.PayloadLen = len(packedMsg.Buf)
200 params.Meid = trans.meid
201 params.Xid = trans.xid
204 tc.Logger.Info("SEND SUB REQ: %s", params.String())
205 snderr := tc.RmrSend(params, 5)
207 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
213 //-----------------------------------------------------------------------------
215 //-----------------------------------------------------------------------------
216 func (tc *E2Stub) RecvSubsReq(t *testing.T) (*e2ap.E2APSubscriptionRequest, *xapptweaks.RMRParams) {
217 tc.Logger.Info("RecvSubsReq")
218 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
220 //---------------------------------
221 // e2term activity: Recv Subs Req
222 //---------------------------------
223 msg := tc.WaitMsg(15)
225 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] {
226 tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_REQ", xapp.RicMessageTypeToName[msg.Mtype])
228 tc.Logger.Info("Recv Subs Req")
229 packedData := &e2ap.PackedData{}
230 packedData.Buf = msg.Payload
231 unpackerr, req := e2SubsReq.UnPack(packedData)
232 if unpackerr != nil {
233 tc.TestError(t, "RIC_SUB_REQ unpack failed err: %s", unpackerr.Error())
238 tc.TestError(t, "Not Received msg within %d secs", 15)
244 //-----------------------------------------------------------------------------
246 //-----------------------------------------------------------------------------
247 func (tc *E2Stub) SendSubsResp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *xapptweaks.RMRParams) {
248 tc.Logger.Info("SendSubsResp")
249 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
251 //---------------------------------
252 // e2term activity: Send Subs Resp
253 //---------------------------------
254 resp := &e2ap.E2APSubscriptionResponse{}
256 resp.RequestId.Id = req.RequestId.Id
257 resp.RequestId.InstanceId = req.RequestId.InstanceId
258 resp.FunctionId = req.FunctionId
260 resp.ActionAdmittedList.Items = make([]e2ap.ActionAdmittedItem, len(req.ActionSetups))
261 for index := int(0); index < len(req.ActionSetups); index++ {
262 resp.ActionAdmittedList.Items[index].ActionId = req.ActionSetups[index].ActionId
265 for index := uint64(0); index < 1; index++ {
266 item := e2ap.ActionNotAdmittedItem{}
267 item.ActionId = index
268 item.Cause.Content = 1
270 resp.ActionNotAdmittedList.Items = append(resp.ActionNotAdmittedList.Items, item)
273 packerr, packedMsg := e2SubsResp.Pack(resp)
275 tc.TestError(t, "pack NOK %s", packerr.Error())
277 tc.Logger.Debug("%s", e2SubsResp.String())
279 params := xapptweaks.NewParams(nil)
280 params.Mtype = xapp.RIC_SUB_RESP
281 //params.SubId = msg.SubId
283 params.Payload = packedMsg.Buf
284 params.PayloadLen = len(packedMsg.Buf)
285 params.Meid = msg.Meid
286 //params.Xid = msg.Xid
289 tc.Logger.Info("SEND SUB RESP: %s", params.String())
290 snderr := tc.RmrSend(params, 5)
292 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
296 //-----------------------------------------------------------------------------
298 //-----------------------------------------------------------------------------
299 func (tc *E2Stub) RecvSubsResp(t *testing.T, trans *RmrTransactionId) uint32 {
300 tc.Logger.Info("RecvSubsResp")
301 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
304 //---------------------------------
305 // xapp activity: Recv Subs Resp
306 //---------------------------------
307 msg := tc.WaitMsg(15)
309 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
310 tc.TestError(t, "Received RIC_SUB_RESP wrong mtype expected %s got %s, error", "RIC_SUB_RESP", xapp.RicMessageTypeToName[msg.Mtype])
312 } else if msg.Xid != trans.xid {
313 tc.TestError(t, "Received RIC_SUB_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
316 packedData := &e2ap.PackedData{}
317 packedData.Buf = msg.Payload
319 e2SubsId = uint32(msg.SubId)
323 unpackerr, resp := e2SubsResp.UnPack(packedData)
324 if unpackerr != nil {
325 tc.TestError(t, "RIC_SUB_RESP unpack failed err: %s", unpackerr.Error())
327 tc.Logger.Info("Recv Subs Resp rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
331 tc.TestError(t, "Not Received msg within %d secs", 15)
336 //-----------------------------------------------------------------------------
338 //-----------------------------------------------------------------------------
340 func (tc *E2Stub) SendSubsFail(t *testing.T, fparams *E2StubSubsFailParams, msg *xapptweaks.RMRParams) {
341 tc.Logger.Info("SendSubsFail")
342 e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
344 //---------------------------------
345 // e2term activity: Send Subs Fail
346 //---------------------------------
347 packerr, packedMsg := e2SubsFail.Pack(fparams.Fail)
349 tc.TestError(t, "pack NOK %s", packerr.Error())
351 tc.Logger.Debug("%s", e2SubsFail.String())
353 params := xapptweaks.NewParams(nil)
354 params.Mtype = xapp.RIC_SUB_FAILURE
355 params.SubId = msg.SubId
356 params.Payload = packedMsg.Buf
357 params.PayloadLen = len(packedMsg.Buf)
358 params.Meid = msg.Meid
362 tc.Logger.Info("SEND SUB FAIL: %s", params.String())
363 snderr := tc.RmrSend(params, 5)
365 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
369 //-----------------------------------------------------------------------------
371 //-----------------------------------------------------------------------------
372 func (tc *E2Stub) RecvSubsFail(t *testing.T, trans *RmrTransactionId) uint32 {
373 tc.Logger.Info("RecvSubsFail")
374 e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
377 //-------------------------------
378 // xapp activity: Recv Subs Fail
379 //-------------------------------
380 msg := tc.WaitMsg(15)
382 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_FAILURE"] {
383 tc.TestError(t, "Received RIC_SUB_FAILURE wrong mtype expected %s got %s, error", "RIC_SUB_FAILURE", xapp.RicMessageTypeToName[msg.Mtype])
385 } else if msg.Xid != trans.xid {
386 tc.TestError(t, "Received RIC_SUB_FAILURE wrong xid expected %s got %s, error", trans.xid, msg.Xid)
389 packedData := &e2ap.PackedData{}
390 packedData.Buf = msg.Payload
392 e2SubsId = uint32(msg.SubId)
396 unpackerr, resp := e2SubsFail.UnPack(packedData)
397 if unpackerr != nil {
398 tc.TestError(t, "RIC_SUB_FAILURE unpack failed err: %s", unpackerr.Error())
400 tc.Logger.Info("Recv Subs Fail rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
404 tc.TestError(t, "Not Received msg within %d secs", 15)
409 //-----------------------------------------------------------------------------
411 //-----------------------------------------------------------------------------
412 func (tc *E2Stub) SendSubsDelReq(t *testing.T, oldTrans *RmrTransactionId, e2SubsId uint32) *RmrTransactionId {
416 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
419 tc.Logger.Info("SendSubsDelReq %s", trans.String())
420 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
421 //---------------------------------
422 // xapp activity: Send Subs Del Req
423 //---------------------------------
424 req := &e2ap.E2APSubscriptionDeleteRequest{}
426 req.RequestId.InstanceId = e2SubsId
429 err, packedMsg := e2SubsDelReq.Pack(req)
431 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
434 tc.Logger.Debug("%s %s", trans.String(), e2SubsDelReq.String())
436 params := xapptweaks.NewParams(nil)
437 params.Mtype = xapp.RIC_SUB_DEL_REQ
438 params.SubId = int(e2SubsId)
439 params.Payload = packedMsg.Buf
440 params.PayloadLen = len(packedMsg.Buf)
441 params.Meid = trans.meid
442 params.Xid = trans.xid
445 tc.Logger.Info("SEND SUB DEL REQ: %s", params.String())
446 snderr := tc.RmrSend(params, 5)
448 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
454 //-----------------------------------------------------------------------------
456 //-----------------------------------------------------------------------------
457 func (tc *E2Stub) RecvSubsDelReq(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *xapptweaks.RMRParams) {
458 tc.Logger.Info("RecvSubsDelReq")
459 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
461 //---------------------------------
462 // e2term activity: Recv Subs Del Req
463 //---------------------------------
464 msg := tc.WaitMsg(15)
466 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] {
467 tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_DEL_REQ", xapp.RicMessageTypeToName[msg.Mtype])
469 tc.Logger.Info("Recv Subs Del Req")
471 packedData := &e2ap.PackedData{}
472 packedData.Buf = msg.Payload
473 unpackerr, req := e2SubsDelReq.UnPack(packedData)
474 if unpackerr != nil {
475 tc.TestError(t, "RIC_SUB_DEL_REQ unpack failed err: %s", unpackerr.Error())
480 tc.TestError(t, "Not Received msg within %d secs", 15)
485 //-----------------------------------------------------------------------------
487 //-----------------------------------------------------------------------------
488 func (tc *E2Stub) SendSubsDelResp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapptweaks.RMRParams) {
489 tc.Logger.Info("SendSubsDelResp")
490 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
492 //---------------------------------
493 // e2term activity: Send Subs Del Resp
494 //---------------------------------
495 resp := &e2ap.E2APSubscriptionDeleteResponse{}
496 resp.RequestId.Id = req.RequestId.Id
497 resp.RequestId.InstanceId = req.RequestId.InstanceId
498 resp.FunctionId = req.FunctionId
500 packerr, packedMsg := e2SubsDelResp.Pack(resp)
502 tc.TestError(t, "pack NOK %s", packerr.Error())
504 tc.Logger.Debug("%s", e2SubsDelResp.String())
506 params := xapptweaks.NewParams(nil)
507 params.Mtype = xapp.RIC_SUB_DEL_RESP
508 params.SubId = msg.SubId
509 params.Payload = packedMsg.Buf
510 params.PayloadLen = len(packedMsg.Buf)
511 params.Meid = msg.Meid
515 tc.Logger.Info("SEND SUB DEL RESP: %s", params.String())
516 snderr := tc.RmrSend(params, 5)
518 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
522 //-----------------------------------------------------------------------------
524 //-----------------------------------------------------------------------------
525 func (tc *E2Stub) RecvSubsDelResp(t *testing.T, trans *RmrTransactionId) {
526 tc.Logger.Info("RecvSubsDelResp")
527 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
529 //---------------------------------
530 // xapp activity: Recv Subs Del Resp
531 //---------------------------------
532 msg := tc.WaitMsg(15)
534 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
535 tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong mtype expected %s got %s, error", "RIC_SUB_DEL_RESP", xapp.RicMessageTypeToName[msg.Mtype])
537 } else if trans != nil && msg.Xid != trans.xid {
538 tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
541 packedData := &e2ap.PackedData{}
542 packedData.Buf = msg.Payload
543 unpackerr, resp := e2SubsDelResp.UnPack(packedData)
544 if unpackerr != nil {
545 tc.TestError(t, "RIC_SUB_DEL_RESP unpack failed err: %s", unpackerr.Error())
547 tc.Logger.Info("Recv Subs Del Resp rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
551 tc.TestError(t, "Not Received msg within %d secs", 15)
555 //-----------------------------------------------------------------------------
557 //-----------------------------------------------------------------------------
558 func (tc *E2Stub) SendSubsDelFail(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapptweaks.RMRParams) {
559 tc.Logger.Info("SendSubsDelFail")
560 e2SubsDelFail := e2asnpacker.NewPackerSubscriptionDeleteFailure()
562 //---------------------------------
563 // e2term activity: Send Subs Del Fail
564 //---------------------------------
565 resp := &e2ap.E2APSubscriptionDeleteFailure{}
566 resp.RequestId.Id = req.RequestId.Id
567 resp.RequestId.InstanceId = req.RequestId.InstanceId
568 resp.FunctionId = req.FunctionId
569 resp.Cause.Content = 4 // CauseMisc
570 resp.Cause.Value = 3 // unspecified
572 packerr, packedMsg := e2SubsDelFail.Pack(resp)
574 tc.TestError(t, "pack NOK %s", packerr.Error())
576 tc.Logger.Debug("%s", e2SubsDelFail.String())
578 params := xapptweaks.NewParams(nil)
579 params.Mtype = xapp.RIC_SUB_DEL_FAILURE
580 params.SubId = msg.SubId
581 params.Payload = packedMsg.Buf
582 params.PayloadLen = len(packedMsg.Buf)
583 params.Meid = msg.Meid
587 tc.Logger.Info("SEND SUB DEL FAIL: %s", params.String())
588 snderr := tc.RmrSend(params, 5)
590 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())