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 ==================================================================================
29 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
30 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap_wrapper"
31 "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub"
32 clientmodel "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientmodel"
33 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
39 var e2asnpacker e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
44 type RmrTransactionId struct {
49 type E2RestIds struct {
57 func (trans *RmrTransactionId) String() string {
59 if trans.meid != nil {
60 meidstr = trans.meid.String()
62 return "trans(" + trans.xid + "/" + meidstr + ")"
66 teststub.RmrStubControl
70 CallBackNotification chan int64
71 RESTNotification chan uint32
72 CallBackListedNotifications chan E2RestIds
73 ListedRESTNotifications chan E2RestIds
74 clientEndpoint clientmodel.SubscriptionParamsClientEndpoint
76 restSubsIdList []string
79 //-----------------------------------------------------------------------------
81 //-----------------------------------------------------------------------------
82 func CreateNewE2Stub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int, ranName string, host string, RMRPort int64, HTTPPort int64) *E2Stub {
84 tc.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed)
87 tc.CallBackNotification = make(chan int64)
88 tc.RESTNotification = make(chan uint32)
89 tc.CallBackListedNotifications = make(chan E2RestIds)
90 tc.ListedRESTNotifications = make(chan E2RestIds, 2)
91 var endPoint clientmodel.SubscriptionParamsClientEndpoint
93 endPoint.HTTPPort = &HTTPPort
94 endPoint.RMRPort = &RMRPort
95 tc.clientEndpoint = endPoint
100 //-----------------------------------------------------------------------------
102 //-----------------------------------------------------------------------------
103 func CreateNewE2termStub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int) *E2Stub {
105 tc.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed)
107 tc.SetCheckXid(false)
111 //-----------------------------------------------------------------------------
113 //-----------------------------------------------------------------------------
114 func (tc *E2Stub) NewRmrTransactionId(xid string, ranname string) *RmrTransactionId {
115 trans := &RmrTransactionId{}
117 trans.xid = tc.GetDesc() + "_XID_" + strconv.FormatUint(uint64(tc.xid_seq), 10)
122 trans.meid = &xapp.RMRMeid{RanName: ranname}
123 tc.Debug("New test %s", trans.String())
127 //-----------------------------------------------------------------------------
129 //-----------------------------------------------------------------------------
130 type E2StubSubsReqParams struct {
131 Req *e2ap.E2APSubscriptionRequest
134 func (p *E2StubSubsReqParams) Init() {
135 p.Req = &e2ap.E2APSubscriptionRequest{}
137 p.Req.RequestId.Id = 1
138 p.Req.RequestId.InstanceId = 0
141 // gnb -> enb outgoing
142 // enb -> gnb incoming
144 p.Req.EventTriggerDefinition.Data.Length = 1
145 p.Req.EventTriggerDefinition.Data.Data = make([]uint8, p.Req.EventTriggerDefinition.Data.Length)
146 p.Req.EventTriggerDefinition.Data.Data[0] = 1
148 p.Req.ActionSetups = make([]e2ap.ActionToBeSetupItem, 1)
150 p.Req.ActionSetups[0].ActionId = 0
151 p.Req.ActionSetups[0].ActionType = e2ap.E2AP_ActionTypeReport
152 p.Req.ActionSetups[0].RicActionDefinitionPresent = true
154 p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Length = 1
155 p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Data = make([]uint8, p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Length)
156 p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Data[0] = 1
158 p.Req.ActionSetups[0].SubsequentAction.Present = true
159 p.Req.ActionSetups[0].SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeContinue
160 p.Req.ActionSetups[0].SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitZero
163 //-----------------------------------------------------------------------------
165 //-----------------------------------------------------------------------------
167 type E2StubSubsFailParams struct {
168 Req *e2ap.E2APSubscriptionRequest
169 Fail *e2ap.E2APSubscriptionFailure
172 func (p *E2StubSubsFailParams) Set(req *e2ap.E2APSubscriptionRequest) {
175 p.Fail = &e2ap.E2APSubscriptionFailure{}
176 p.Fail.RequestId.Id = p.Req.RequestId.Id
177 p.Fail.RequestId.InstanceId = p.Req.RequestId.InstanceId
178 p.Fail.FunctionId = p.Req.FunctionId
179 p.Fail.Cause.Content = e2ap.E2AP_CauseContent_RICrequest
180 p.Fail.Cause.Value = e2ap.E2AP_CauseValue_RICrequest_control_message_invalid
183 func (p *E2StubSubsFailParams) SetCauseVal(ind int, content uint8, causeval uint8) {
185 p.Fail.Cause.Content = content
186 p.Fail.Cause.Value = causeval
189 //-----------------------------------------------------------------------------
191 //-----------------------------------------------------------------------------
193 func (tc *E2Stub) SendSubsReq(t *testing.T, rparams *E2StubSubsReqParams, oldTrans *RmrTransactionId) *RmrTransactionId {
197 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
200 tc.Debug("SendSubsReq %s", trans.String())
201 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
203 //---------------------------------
204 // xapp activity: Send Subs Req
205 //---------------------------------
209 myparams = &E2StubSubsReqParams{}
213 err, packedMsg := e2SubsReq.Pack(myparams.Req)
215 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
218 tc.Debug("%s %s", trans.String(), e2SubsReq.String())
220 params := &xapp.RMRParams{}
221 params.Mtype = xapp.RIC_SUB_REQ
223 params.Payload = packedMsg.Buf
224 params.PayloadLen = len(packedMsg.Buf)
225 params.Meid = trans.meid
226 params.Xid = trans.xid
229 tc.Debug("SEND SUB REQ: %s", params.String())
230 snderr := tc.SendWithRetry(params, false, 5)
232 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
238 //-----------------------------------------------------------------------------
240 //-----------------------------------------------------------------------------
241 func (tc *E2Stub) RecvSubsReq(t *testing.T) (*e2ap.E2APSubscriptionRequest, *xapp.RMRParams) {
242 tc.Debug("RecvSubsReq")
243 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
245 //---------------------------------
246 // e2term activity: Recv Subs Req
247 //---------------------------------
248 msg := tc.WaitMsg(15)
250 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] {
251 tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_REQ", xapp.RicMessageTypeToName[msg.Mtype])
253 tc.Debug("Recv Subs Req")
254 packedData := &e2ap.PackedData{}
255 packedData.Buf = msg.Payload
256 unpackerr, req := e2SubsReq.UnPack(packedData)
257 if unpackerr != nil {
258 tc.TestError(t, "RIC_SUB_REQ unpack failed err: %s", unpackerr.Error())
263 tc.TestError(t, "Not Received msg within %d secs", 15)
269 //-----------------------------------------------------------------------------
271 //-----------------------------------------------------------------------------
272 func (tc *E2Stub) SendSubsResp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *xapp.RMRParams) {
273 tc.Debug("SendSubsResp")
274 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
276 //---------------------------------
277 // e2term activity: Send Subs Resp
278 //---------------------------------
279 resp := &e2ap.E2APSubscriptionResponse{}
281 resp.RequestId.Id = req.RequestId.Id
282 resp.RequestId.InstanceId = req.RequestId.InstanceId
283 resp.FunctionId = req.FunctionId
285 resp.ActionAdmittedList.Items = make([]e2ap.ActionAdmittedItem, len(req.ActionSetups))
286 for index := int(0); index < len(req.ActionSetups); index++ {
287 resp.ActionAdmittedList.Items[index].ActionId = req.ActionSetups[index].ActionId
290 packerr, packedMsg := e2SubsResp.Pack(resp)
292 tc.TestError(t, "pack NOK %s", packerr.Error())
294 tc.Debug("%s", e2SubsResp.String())
296 params := &xapp.RMRParams{}
297 params.Mtype = xapp.RIC_SUB_RESP
298 //params.SubId = msg.SubId
300 params.Payload = packedMsg.Buf
301 params.PayloadLen = len(packedMsg.Buf)
302 params.Meid = msg.Meid
303 //params.Xid = msg.Xid
306 tc.Debug("SEND SUB RESP: %s", params.String())
307 snderr := tc.SendWithRetry(params, false, 5)
309 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
313 //-----------------------------------------------------------------------------
315 //-----------------------------------------------------------------------------
316 func (tc *E2Stub) SendPartialSubsResp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *xapp.RMRParams, actionNotAdmittedList e2ap.ActionNotAdmittedList) {
317 tc.Debug("SendPartialSubsResp")
319 if len(actionNotAdmittedList.Items) == 0 {
320 tc.TestError(t, "SendPartialSubsResp() Empty actionNotAdmittedList.Items")
324 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
326 //---------------------------------
327 // e2term activity: Send Subs Resp
328 //---------------------------------
329 resp := &e2ap.E2APSubscriptionResponse{}
331 resp.RequestId.Id = req.RequestId.Id
332 resp.RequestId.InstanceId = req.RequestId.InstanceId
333 resp.FunctionId = req.FunctionId
335 for index, actionNotAdmittedItem := range actionNotAdmittedList.Items {
336 for _, ActionToBeSetupItem := range req.ActionSetups {
337 if ActionToBeSetupItem.ActionId == actionNotAdmittedItem.ActionId {
338 actionNotAdmittedItem := e2ap.ActionNotAdmittedItem{}
339 actionNotAdmittedItem.ActionId = ActionToBeSetupItem.ActionId
340 actionNotAdmittedItem.Cause.Content = 1
341 actionNotAdmittedItem.Cause.Value = 8
342 resp.ActionNotAdmittedList.Items = append(resp.ActionNotAdmittedList.Items, actionNotAdmittedItem)
343 // Remove the element
344 req.ActionSetups = append(req.ActionSetups[:index], req.ActionSetups[index+1:]...)
349 for _, ActionToBeSetupItem := range req.ActionSetups {
350 actionAdmittedItem := e2ap.ActionAdmittedItem{}
351 actionAdmittedItem.ActionId = ActionToBeSetupItem.ActionId
352 resp.ActionAdmittedList.Items = append(resp.ActionAdmittedList.Items, actionAdmittedItem)
355 packerr, packedMsg := e2SubsResp.Pack(resp)
357 tc.TestError(t, "pack NOK %s", packerr.Error())
359 tc.Debug("%s", e2SubsResp.String())
361 params := &xapp.RMRParams{}
362 params.Mtype = xapp.RIC_SUB_RESP
363 //params.SubId = msg.SubId
365 params.Payload = packedMsg.Buf
366 params.PayloadLen = len(packedMsg.Buf)
367 params.Meid = msg.Meid
368 //params.Xid = msg.Xid
371 tc.Debug("SEND SUB RESP: %s", params.String())
372 snderr := tc.SendWithRetry(params, false, 5)
374 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
378 //-----------------------------------------------------------------------------
380 //-----------------------------------------------------------------------------
381 func (tc *E2Stub) SendInvalidE2Asn1Resp(t *testing.T, msg *xapp.RMRParams, msgType int) {
383 params := &xapp.RMRParams{}
384 params.Mtype = msgType
386 params.Payload = []byte{1, 2, 3, 4, 5}
387 params.PayloadLen = 5
388 params.Meid = msg.Meid
392 if params.Mtype == xapp.RIC_SUB_RESP {
393 tc.Debug("SEND INVALID ASN.1 SUB RESP")
395 } else if params.Mtype == xapp.RIC_SUB_FAILURE {
396 tc.Debug("SEND INVALID ASN.1 SUB FAILURE")
398 } else if params.Mtype == xapp.RIC_SUB_DEL_RESP {
399 tc.Debug("SEND INVALID ASN.1 SUB DEL RESP")
401 } else if params.Mtype == xapp.RIC_SUB_DEL_FAILURE {
402 tc.Debug("SEND INVALID ASN.1 SUB DEL FAILURE")
404 snderr := tc.SendWithRetry(params, false, 5)
406 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
410 //-----------------------------------------------------------------------------
412 //-----------------------------------------------------------------------------
413 func (tc *E2Stub) RecvSubsResp(t *testing.T, trans *RmrTransactionId) uint32 {
414 tc.Debug("RecvSubsResp")
415 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
418 //---------------------------------
419 // xapp activity: Recv Subs Resp
420 //---------------------------------
421 msg := tc.WaitMsg(15)
423 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
424 tc.TestError(t, "Received RIC_SUB_RESP wrong mtype expected %s got %s, error", "RIC_SUB_RESP", xapp.RicMessageTypeToName[msg.Mtype])
426 } else if msg.Xid != trans.xid {
427 tc.TestError(t, "Received RIC_SUB_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
430 packedData := &e2ap.PackedData{}
431 packedData.Buf = msg.Payload
433 e2SubsId = uint32(msg.SubId)
437 unpackerr, resp := e2SubsResp.UnPack(packedData)
438 if unpackerr != nil {
439 tc.TestError(t, "RIC_SUB_RESP unpack failed err: %s", unpackerr.Error())
441 tc.Debug("Recv Subs Resp rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
445 tc.TestError(t, "Not Received msg within %d secs", 15)
450 //-----------------------------------------------------------------------------
452 //-----------------------------------------------------------------------------
454 func (tc *E2Stub) SendSubsFail(t *testing.T, fparams *E2StubSubsFailParams, msg *xapp.RMRParams) {
455 tc.Debug("SendSubsFail")
456 e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
458 //---------------------------------
459 // e2term activity: Send Subs Fail
460 //---------------------------------
461 packerr, packedMsg := e2SubsFail.Pack(fparams.Fail)
463 tc.TestError(t, "pack NOK %s", packerr.Error())
465 tc.Debug("%s", e2SubsFail.String())
467 params := &xapp.RMRParams{}
468 params.Mtype = xapp.RIC_SUB_FAILURE
469 params.SubId = msg.SubId
470 params.Payload = packedMsg.Buf
471 params.PayloadLen = len(packedMsg.Buf)
472 params.Meid = msg.Meid
476 tc.Debug("SEND SUB FAIL: %s", params.String())
477 snderr := tc.SendWithRetry(params, false, 5)
479 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
483 //-----------------------------------------------------------------------------
485 //-----------------------------------------------------------------------------
486 func (tc *E2Stub) RecvSubsFail(t *testing.T, trans *RmrTransactionId) uint32 {
487 tc.Debug("RecvSubsFail")
488 e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
491 //-------------------------------
492 // xapp activity: Recv Subs Fail
493 //-------------------------------
494 msg := tc.WaitMsg(15)
496 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_FAILURE"] {
497 tc.TestError(t, "Received RIC_SUB_FAILURE wrong mtype expected %s got %s, error", "RIC_SUB_FAILURE", xapp.RicMessageTypeToName[msg.Mtype])
499 } else if msg.Xid != trans.xid {
500 tc.TestError(t, "Received RIC_SUB_FAILURE wrong xid expected %s got %s, error", trans.xid, msg.Xid)
503 packedData := &e2ap.PackedData{}
504 packedData.Buf = msg.Payload
506 e2SubsId = uint32(msg.SubId)
510 unpackerr, resp := e2SubsFail.UnPack(packedData)
511 if unpackerr != nil {
512 tc.TestError(t, "RIC_SUB_FAILURE unpack failed err: %s", unpackerr.Error())
514 tc.Debug("Recv Subs Fail rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
518 tc.TestError(t, "Not Received msg within %d secs", 15)
523 //-----------------------------------------------------------------------------
525 //-----------------------------------------------------------------------------
526 func (tc *E2Stub) SendSubsDelReq(t *testing.T, oldTrans *RmrTransactionId, e2SubsId uint32) *RmrTransactionId {
530 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
533 tc.Debug("SendSubsDelReq %s", trans.String())
534 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
535 //---------------------------------
536 // xapp activity: Send Subs Del Req
537 //---------------------------------
538 req := &e2ap.E2APSubscriptionDeleteRequest{}
540 req.RequestId.InstanceId = e2SubsId
543 err, packedMsg := e2SubsDelReq.Pack(req)
545 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
548 tc.Debug("%s %s", trans.String(), e2SubsDelReq.String())
550 params := &xapp.RMRParams{}
551 params.Mtype = xapp.RIC_SUB_DEL_REQ
552 params.SubId = int(e2SubsId)
553 params.Payload = packedMsg.Buf
554 params.PayloadLen = len(packedMsg.Buf)
555 params.Meid = trans.meid
556 params.Xid = trans.xid
559 tc.Debug("SEND SUB DEL REQ: %s", params.String())
560 snderr := tc.SendWithRetry(params, false, 5)
562 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
568 //-----------------------------------------------------------------------------
570 //-----------------------------------------------------------------------------
571 func (tc *E2Stub) RecvSubsDelReq(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *xapp.RMRParams) {
572 tc.Debug("RecvSubsDelReq")
573 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
575 //---------------------------------
576 // e2term activity: Recv Subs Del Req
577 //---------------------------------
578 msg := tc.WaitMsg(15)
580 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] {
581 tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_DEL_REQ", xapp.RicMessageTypeToName[msg.Mtype])
583 tc.Debug("Recv Subs Del Req")
585 packedData := &e2ap.PackedData{}
586 packedData.Buf = msg.Payload
587 unpackerr, req := e2SubsDelReq.UnPack(packedData)
588 if unpackerr != nil {
589 tc.TestError(t, "RIC_SUB_DEL_REQ unpack failed err: %s", unpackerr.Error())
594 tc.TestError(t, "Not Received msg within %d secs", 15)
599 //-----------------------------------------------------------------------------
601 //-----------------------------------------------------------------------------
602 func (tc *E2Stub) SendSubsDelResp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapp.RMRParams) {
603 tc.Debug("SendSubsDelResp")
604 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
606 //---------------------------------
607 // e2term activity: Send Subs Del Resp
608 //---------------------------------
609 resp := &e2ap.E2APSubscriptionDeleteResponse{}
610 resp.RequestId.Id = req.RequestId.Id
611 resp.RequestId.InstanceId = req.RequestId.InstanceId
612 resp.FunctionId = req.FunctionId
614 packerr, packedMsg := e2SubsDelResp.Pack(resp)
616 tc.TestError(t, "pack NOK %s", packerr.Error())
618 tc.Debug("%s", e2SubsDelResp.String())
620 params := &xapp.RMRParams{}
621 params.Mtype = xapp.RIC_SUB_DEL_RESP
622 params.SubId = msg.SubId
623 params.Payload = packedMsg.Buf
624 params.PayloadLen = len(packedMsg.Buf)
625 params.Meid = msg.Meid
629 tc.Debug("SEND SUB DEL RESP: %s", params.String())
630 snderr := tc.SendWithRetry(params, false, 5)
632 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
636 //-----------------------------------------------------------------------------
638 //-----------------------------------------------------------------------------
639 func (tc *E2Stub) RecvSubsDelResp(t *testing.T, trans *RmrTransactionId) {
640 tc.Debug("RecvSubsDelResp")
641 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
643 //---------------------------------
644 // xapp activity: Recv Subs Del Resp
645 //---------------------------------
646 msg := tc.WaitMsg(15)
648 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
649 tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong mtype expected %s got %s, error", "RIC_SUB_DEL_RESP", xapp.RicMessageTypeToName[msg.Mtype])
651 } else if trans != nil && msg.Xid != trans.xid {
652 tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
655 packedData := &e2ap.PackedData{}
656 packedData.Buf = msg.Payload
657 unpackerr, resp := e2SubsDelResp.UnPack(packedData)
658 if unpackerr != nil {
659 tc.TestError(t, "RIC_SUB_DEL_RESP unpack failed err: %s", unpackerr.Error())
661 tc.Debug("Recv Subs Del Resp rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
665 tc.TestError(t, "Not Received msg within %d secs", 15)
669 //-----------------------------------------------------------------------------
671 //-----------------------------------------------------------------------------
672 func (tc *E2Stub) SendSubsDelFail(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapp.RMRParams) {
673 tc.Debug("SendSubsDelFail")
674 e2SubsDelFail := e2asnpacker.NewPackerSubscriptionDeleteFailure()
676 //---------------------------------
677 // e2term activity: Send Subs Del Fail
678 //---------------------------------
679 resp := &e2ap.E2APSubscriptionDeleteFailure{}
680 resp.RequestId.Id = req.RequestId.Id
681 resp.RequestId.InstanceId = req.RequestId.InstanceId
682 resp.FunctionId = req.FunctionId
683 resp.Cause.Content = 5 // CauseMisc
684 resp.Cause.Value = 3 // unspecified
686 packerr, packedMsg := e2SubsDelFail.Pack(resp)
688 tc.TestError(t, "pack NOK %s", packerr.Error())
690 tc.Debug("%s", e2SubsDelFail.String())
692 params := &xapp.RMRParams{}
693 params.Mtype = xapp.RIC_SUB_DEL_FAILURE
694 params.SubId = msg.SubId
695 params.Payload = packedMsg.Buf
696 params.PayloadLen = len(packedMsg.Buf)
697 params.Meid = msg.Meid
701 tc.Debug("SEND SUB DEL FAIL: %s", params.String())
702 snderr := tc.SendWithRetry(params, false, 5)
704 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
708 // REST code below all
710 /*****************************************************************************/
711 // REST interface specific functions are below
713 //-----------------------------------------------------------------------------
714 // Callback handler for subscription response notifications
715 //-----------------------------------------------------------------------------
716 func (tc *E2Stub) SubscriptionRespHandler(resp *clientmodel.SubscriptionResponse) {
718 if tc.subscriptionId == "SUBSCRIPTIONID NOT SET" {
719 tc.Debug("REST notification received for %v while no SubscriptionID was not set for E2EventInstanceID=%v, XappEventInstanceID=%v",
720 *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID)
721 tc.CallBackNotification <- *resp.SubscriptionInstances[0].E2EventInstanceID
722 } else if tc.subscriptionId == *resp.SubscriptionID {
723 tc.Debug("REST notification received SubscriptionID=%s, E2EventInstanceID=%v, RequestorID=%v",
724 *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID)
725 tc.CallBackNotification <- *resp.SubscriptionInstances[0].E2EventInstanceID
727 tc.Debug("MISMATCHING REST notification received SubscriptionID=%s<>%s, E2EventInstanceID=%v, XappEventInstanceID=%v",
728 tc.subscriptionId, *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID)
732 //-----------------------------------------------------------------------------
734 //-----------------------------------------------------------------------------
736 func (tc *E2Stub) ExpectRESTNotification(t *testing.T, restSubsId string) {
737 tc.expectNotification(t, restSubsId, "")
740 func (tc *E2Stub) ExpectRESTNotificationOk(t *testing.T, restSubsId string) {
741 tc.expectNotification(t, restSubsId, "allOk")
744 func (tc *E2Stub) ExpectRESTNotificationNok(t *testing.T, restSubsId string, expectError string) {
745 tc.expectNotification(t, restSubsId, expectError)
748 func (tc *E2Stub) expectNotification(t *testing.T, restSubsId string, expectError string) {
750 tc.Debug("### Started to wait REST notification for restSubsId= %v, RMRPort=%v, requestCount=%v responses expected", restSubsId, *tc.clientEndpoint.RMRPort, tc.requestCount)
751 tc.restSubsIdList = []string{restSubsId}
752 xapp.Subscription.SetResponseCB(tc.ListedRestNotifHandler)
753 if tc.requestCount == 0 {
754 tc.TestError(t, "### NO REST notifications SET received for restSubsId= %v, RMRPort=%v, request count ZERO!", restSubsId, *tc.clientEndpoint.RMRPort)
758 case e2Ids := <-tc.CallBackListedNotifications:
759 if tc.requestCount == 0 {
760 tc.TestError(t, "### REST notification count unexpectedly ZERO for restSubsId= %v", restSubsId)
761 } else if e2Ids.RestSubsId != restSubsId {
762 tc.TestError(t, "### Unexpected REST notifications received, expected %s but got %s instead", e2Ids.RestSubsId, restSubsId)
763 } else if e2Ids.ErrorCause == "" && expectError == "allFail" {
764 tc.TestError(t, "### Unexpected ok cause received from REST notifications |%s:%s|", e2Ids.RestSubsId, restSubsId)
765 } else if e2Ids.ErrorCause != "" && expectError == "allOk" {
766 tc.TestError(t, "### Unexpected ErrorCause: (%s), ErrorSource: (%s), TimeoutType: (%s) received from REST notifications |%s:%s|", e2Ids.ErrorCause, e2Ids.ErrorSource, e2Ids.TimeoutType, e2Ids.RestSubsId, restSubsId)
769 if tc.requestCount == 0 {
770 tc.Debug("### All expected REST notifications received for restSubsId= %v)", e2Ids.RestSubsId)
772 tc.Debug("### Expected REST notifications received for restSubsId= %v", e2Ids.RestSubsId)
774 if e2Ids.ErrorCause != "" && expectError == "allFail" {
775 tc.Debug("### REST Notification: RestSubsId: %s, ErrorCause: %s, ErrorSource: (%s), TimeoutType: (%s)", e2Ids.RestSubsId, e2Ids.ErrorCause, e2Ids.ErrorSource, e2Ids.TimeoutType)
777 tc.Debug("### REST Notification received Notif for %s : %v", e2Ids.RestSubsId, e2Ids.E2SubsId)
778 tc.ListedRESTNotifications <- e2Ids
779 if len(tc.ListedRESTNotifications) > 1 {
780 panic("expectNotification - ListedRESTNotifications stacking up")
783 case <-time.After(15 * time.Second):
784 err := fmt.Errorf("### Timeout 15s expired while expecting REST notification for subsId: %v", restSubsId)
785 tc.TestError(t, "%s", err.Error())
790 func (tc *E2Stub) WaitRESTNotification(t *testing.T, restSubsId string) uint32 {
792 stack := string(debug.Stack())
795 case e2SubsId := <-tc.ListedRESTNotifications:
796 if e2SubsId.RestSubsId == restSubsId {
797 tc.Debug("### Expected REST notifications received %s, e2SubsId %v", e2SubsId.RestSubsId, e2SubsId.E2SubsId)
798 return e2SubsId.E2SubsId
800 tc.TestError(t, "### Unexpected REST notification %s received, expected %v", e2SubsId.RestSubsId, restSubsId)
801 xapp.Logger.Debug("CALL STACK:\n %s", stack)
804 case <-time.After(15 * time.Second):
805 err := fmt.Errorf("### Timeout 15s expired while waiting REST notification for subsId: %v", restSubsId)
806 tc.TestError(t, "%s", err.Error())
807 xapp.Logger.Debug("CALL STACK:\n %s", stack)
808 panic("WaitRESTNotification - timeout error")
812 // Note, this function should be followed by a handling of <-xappConn1.RESTNotification.
813 func (tc *E2Stub) ExpectAnyNotification(t *testing.T) {
815 tc.Debug("### Started waiting ANY REST notifications received for RMRPort=%v", *tc.clientEndpoint.RMRPort)
817 case e2SubsId := <-tc.CallBackNotification:
818 tc.Debug("### ANY REST notifications received for e2SubsId %v RMRPort=%v", e2SubsId, *tc.clientEndpoint.RMRPort)
819 tc.RESTNotification <- (uint32)(e2SubsId)
820 case <-time.After(15 * time.Second):
821 err := fmt.Errorf("### Timeout 15s expired while waiting ANY REST notification")
822 tc.TestError(t, "%s", err.Error())
823 tc.RESTNotification <- 0
828 func (tc *E2Stub) WaitAnyRESTNotification(t *testing.T) uint32 {
831 case e2SubsId := <-tc.RESTNotification:
832 tc.Debug("### Expected ANY REST notification received for e2SubsId %v", e2SubsId)
835 case <-time.After(15 * time.Second):
836 err := fmt.Errorf("### Timeout 15s expired while waiting ANY REST notification")
837 tc.TestError(t, "%s", err.Error())
838 panic("WaitRESTNotification - timeout error")
842 func (tc *E2Stub) ListedRestNotifHandler(resp *clientmodel.SubscriptionResponse) {
844 if len(tc.restSubsIdList) == 0 {
845 tc.Error("Unexpected listed REST notifications received for SubscriptionID=%s, expected restSubsId list size was ZERO!", *resp.SubscriptionID)
847 for i, subsId := range tc.restSubsIdList {
848 if *resp.SubscriptionID == subsId {
849 //tc.Debug("Listed REST notifications received SubscriptionID=%s, InstanceID=%v, XappEventInstanceID=%v",
850 // *resp.SubscriptionID, *resp.SubscriptionInstances[0].InstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID)
852 tc.restSubsIdList = append(tc.restSubsIdList[:i], tc.restSubsIdList[i+1:]...)
853 //tc.Debug("Removed %s from Listed REST notifications, %v entries left", *resp.SubscriptionID, len(tc.restSubsIdList))
855 // if resp.SubscriptionInstances[0].ErrorCause != nil {
856 tc.CallBackListedNotifications <- *tc.GetE2RestIds(resp)
858 // tc.CallBackListedNotifications <- E2RestIds{*resp.SubscriptionID, uint32(*resp.SubscriptionInstances[0].E2EventInstanceID), "", "", ""}
861 if len(tc.restSubsIdList) == 0 {
862 tc.Debug("All listed REST notifications received for SubscriptionID=%s", *resp.SubscriptionID)
868 tc.Error("UNKONWN REST notification received SubscriptionID=%s<>%s, InstanceID=%v, XappEventInstanceID=%v",
869 tc.subscriptionId, *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID)
873 //-----------------------------------------------------------------------------
875 //-----------------------------------------------------------------------------
876 func (tc *E2Stub) GetE2RestIds(resp *clientmodel.SubscriptionResponse) *E2RestIds {
878 e2RestIds := &E2RestIds{}
880 if resp.SubscriptionID != nil {
881 e2RestIds.RestSubsId = *resp.SubscriptionID
883 if resp.SubscriptionInstances != nil {
884 if resp.SubscriptionInstances[0].E2EventInstanceID != nil {
885 e2RestIds.E2SubsId = uint32(*resp.SubscriptionInstances[0].E2EventInstanceID)
887 e2RestIds.ErrorCause = resp.SubscriptionInstances[0].ErrorCause
888 e2RestIds.ErrorSource = resp.SubscriptionInstances[0].ErrorSource
889 e2RestIds.TimeoutType = resp.SubscriptionInstances[0].TimeoutType
895 //-----------------------------------------------------------------------------
897 //-----------------------------------------------------------------------------
898 func (tc *E2Stub) WaitListedRestNotifications(t *testing.T, restSubsIds []string) {
899 tc.Debug("Started to wait REST notifications for restSubsIds=%v, RMRPort=%v", restSubsIds, *tc.clientEndpoint.RMRPort)
901 tc.restSubsIdList = restSubsIds
902 xapp.Subscription.SetResponseCB(tc.ListedRestNotifHandler)
904 for i := 0; i < len(restSubsIds); i++ {
907 case e2Ids := <-tc.CallBackListedNotifications:
908 tc.Debug("Listed Notification waiter received Notif for %s : %v", e2Ids.RestSubsId, e2Ids.E2SubsId)
909 tc.ListedRESTNotifications <- e2Ids
910 case <-time.After(15 * time.Second):
911 err := fmt.Errorf("Timeout 15s expired while waiting Listed REST notification")
912 tc.TestError(t, "%s", err.Error())
913 tc.RESTNotification <- 0
919 //-----------------------------------------------------------------------------
921 //-----------------------------------------------------------------------------
922 func (tc *E2Stub) SendRESTSubsReq(t *testing.T, params *RESTSubsReqParams) string {
923 tc.Debug("======== Posting REST subscriptions to Submgr ======")
926 tc.Debug("SendRESTReportSubsReq: params == nil")
930 tc.subscriptionId = "SUBSCRIPTIONID NOT SET"
932 resp, err := xapp.Subscription.Subscribe(¶ms.SubsReqParams)
934 // Swagger generated code makes checks for the values that are inserted the subscription function
935 // If error cause is unknown and POST is not done, the problem is in the inserted values
936 tc.Error("======== REST subscription request failed %s ========", err.Error())
939 tc.subscriptionId = *resp.SubscriptionID
940 tc.Debug("======== REST subscriptions posted successfully. SubscriptionID = %s, RequestCount = %v ========", *resp.SubscriptionID, tc.requestCount)
941 return *resp.SubscriptionID
944 //-----------------------------------------------------------------------------
946 //-----------------------------------------------------------------------------
947 func (tc *E2Stub) GetRESTSubsReqReportParams(subReqCount int) *RESTSubsReqParams {
949 reportParams := RESTSubsReqParams{}
950 reportParams.GetRESTSubsReqReportParams(subReqCount, &tc.clientEndpoint, &tc.meid)
951 tc.requestCount = subReqCount
955 //-----------------------------------------------------------------------------
957 //-----------------------------------------------------------------------------
958 type RESTSubsReqParams struct {
959 SubsReqParams clientmodel.SubscriptionParams
962 func (p *RESTSubsReqParams) GetRESTSubsReqReportParams(subReqCount int, clientEndpoint *clientmodel.SubscriptionParamsClientEndpoint, meid *string) {
965 p.SubsReqParams.ClientEndpoint = clientEndpoint
966 p.SubsReqParams.Meid = meid
967 var rANFunctionID int64 = 33
968 p.SubsReqParams.RANFunctionID = &rANFunctionID
971 actionType := "report"
972 subsequestActioType := "continue"
973 timeToWait := "w10ms"
975 for requestCount := 0; requestCount < subReqCount; requestCount++ {
976 reqId := int64(requestCount) + 1
977 subscriptionDetail := &clientmodel.SubscriptionDetail{
978 XappEventInstanceID: &reqId,
979 EventTriggers: clientmodel.EventTriggerDefinition{
980 int64(1234 + requestCount),
982 ActionToBeSetupList: clientmodel.ActionsToBeSetup{
983 &clientmodel.ActionToBeSetup{
985 ActionType: &actionType,
986 ActionDefinition: clientmodel.ActionDefinition{
987 int64(5678 + requestCount),
989 SubsequentAction: &clientmodel.SubsequentAction{
990 SubsequentActionType: &subsequestActioType,
991 TimeToWait: &timeToWait,
996 p.SubsReqParams.SubscriptionDetails = append(p.SubsReqParams.SubscriptionDetails, subscriptionDetail)
1001 func (p *RESTSubsReqParams) SetMeid(MEID string) {
1002 p.SubsReqParams.Meid = &MEID
1005 func (p *RESTSubsReqParams) SetEndpoint(HTTP_port int64, RMR_port int64, host string) {
1006 var endpoint clientmodel.SubscriptionParamsClientEndpoint
1007 endpoint.HTTPPort = &HTTP_port
1008 endpoint.RMRPort = &RMR_port
1009 endpoint.Host = host
1010 p.SubsReqParams.ClientEndpoint = &endpoint
1013 func (p *RESTSubsReqParams) SetEndpointHost(host string) {
1015 if p.SubsReqParams.ClientEndpoint.Host != "" {
1016 if p.SubsReqParams.ClientEndpoint.Host != host {
1017 // Renaming toto, print something tc.Debug("Posting REST subscription request to Submgr")
1018 err := fmt.Errorf("hostname change attempt: %s -> %s", p.SubsReqParams.ClientEndpoint.Host, host)
1022 p.SubsReqParams.ClientEndpoint.Host = host
1025 func (p *RESTSubsReqParams) SetHTTPEndpoint(HTTP_port int64, host string) {
1027 p.SubsReqParams.ClientEndpoint.HTTPPort = &HTTP_port
1029 p.SetEndpointHost(host)
1031 if p.SubsReqParams.ClientEndpoint.RMRPort == nil {
1033 p.SubsReqParams.ClientEndpoint.RMRPort = &RMR_port
1037 func (p *RESTSubsReqParams) SetE2SubscriptionDirectives(E2RetryCount int64, E2TimeoutTimerValue int64, RMRRoutingNeeded bool) {
1039 E2SubscriptionDirectives := &clientmodel.SubscriptionParamsE2SubscriptionDirectives{}
1040 p.SubsReqParams.E2SubscriptionDirectives = E2SubscriptionDirectives
1041 p.SubsReqParams.E2SubscriptionDirectives.E2RetryCount = &E2RetryCount
1042 p.SubsReqParams.E2SubscriptionDirectives.E2TimeoutTimerValue = E2TimeoutTimerValue
1043 p.SubsReqParams.E2SubscriptionDirectives.RMRRoutingNeeded = RMRRoutingNeeded
1046 func (p *RESTSubsReqParams) RemoveE2SubscriptionDirectives() {
1048 p.SubsReqParams.E2SubscriptionDirectives = nil
1051 func (p *RESTSubsReqParams) SetSubActionTypes(actionType string) {
1053 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1054 for _, action := range subDetail.ActionToBeSetupList {
1056 action.ActionType = &actionType
1062 func (p *RESTSubsReqParams) SetSubActionIDs(actionId int64) {
1064 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1065 for _, action := range subDetail.ActionToBeSetupList {
1067 action.ActionID = &actionId
1073 func (p *RESTSubsReqParams) SetSubActionDefinition(actionDefinition []int64) {
1075 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1076 for _, action := range subDetail.ActionToBeSetupList {
1078 action.ActionDefinition = actionDefinition
1084 func (p *RESTSubsReqParams) SetSubEventTriggerDefinition(eventTriggerDefinition []int64) {
1086 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1087 if subDetail != nil {
1088 subDetail.EventTriggers = eventTriggerDefinition
1093 func (p *RESTSubsReqParams) AppendActionToActionToBeSetupList(actionId int64, actionType string, actionDefinition []int64, subsequentActionType string, timeToWait string) {
1095 actionToBeSetup := &clientmodel.ActionToBeSetup{
1096 ActionID: &actionId,
1097 ActionType: &actionType,
1098 ActionDefinition: clientmodel.ActionDefinition(actionDefinition),
1099 SubsequentAction: &clientmodel.SubsequentAction{
1100 SubsequentActionType: &subsequentActionType,
1101 TimeToWait: &timeToWait,
1105 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1106 if subDetail != nil {
1107 subDetail.ActionToBeSetupList = append(subDetail.ActionToBeSetupList, actionToBeSetup)
1112 func (p *RESTSubsReqParams) SetRMREndpoint(RMR_port int64, host string) {
1114 p.SubsReqParams.ClientEndpoint.RMRPort = &RMR_port
1116 p.SetEndpointHost(host)
1118 if p.SubsReqParams.ClientEndpoint.HTTPPort == nil {
1120 p.SubsReqParams.ClientEndpoint.HTTPPort = &HTTP_port
1124 func (p *RESTSubsReqParams) SetTimeToWait(timeToWait string) {
1126 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1127 for _, action := range subDetail.ActionToBeSetupList {
1128 if action != nil && action.SubsequentAction != nil {
1129 action.SubsequentAction.TimeToWait = &timeToWait
1135 func (p *RESTSubsReqParams) SetSubscriptionID(SubscriptionID *string) {
1137 if *SubscriptionID == "" {
1140 p.SubsReqParams.SubscriptionID = *SubscriptionID
1143 func (p *RESTSubsReqParams) SetXappEventInstanceID(xappEventInstanceId int64) {
1145 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1146 if subDetail != nil {
1147 subDetail.XappEventInstanceID = &xappEventInstanceId
1152 //-----------------------------------------------------------------------------
1154 //-----------------------------------------------------------------------------
1155 func (tc *E2Stub) SendRESTSubsDelReq(t *testing.T, subscriptionID *string) {
1157 tc.Debug("======== Posting REST DELETE subscription(s) to Submgr ======")
1159 if *subscriptionID == "" {
1160 tc.Error("REST error in deleting subscriptions. Empty SubscriptionID = %s", *subscriptionID)
1162 tc.Debug("REST deleting E2 subscriptions. SubscriptionID = %s", *subscriptionID)
1164 err := xapp.Subscription.Unsubscribe(*subscriptionID)
1166 tc.Error("REST Delete subscription failed %s", err.Error())
1168 tc.Debug("REST delete subscription pushed to submgr successfully. SubscriptionID = %s", *subscriptionID)
1171 //-----------------------------------------------------------------------------
1173 //-----------------------------------------------------------------------------
1174 func (tc *E2Stub) GetRESTSubsReqPolicyParams(subReqCount int) *RESTSubsReqParams {
1176 policyParams := RESTSubsReqParams{}
1177 policyParams.GetRESTSubsReqPolicyParams(subReqCount, &tc.clientEndpoint, &tc.meid)
1178 tc.requestCount = subReqCount
1179 return &policyParams
1182 //-----------------------------------------------------------------------------
1184 //-----------------------------------------------------------------------------
1185 func (tc *E2Stub) DecrementRequestCount() {
1186 if tc.requestCount > 0 {
1187 tc.requestCount -= 1
1189 tc.Error("FAILED to decrement request count, count already ZERO")
1193 //-----------------------------------------------------------------------------
1195 //-----------------------------------------------------------------------------
1196 func (p *RESTSubsReqParams) GetRESTSubsReqPolicyParams(subReqCount int, clientEndpoint *clientmodel.SubscriptionParamsClientEndpoint, meid *string) {
1198 p.SubsReqParams.ClientEndpoint = clientEndpoint
1199 p.SubsReqParams.Meid = meid
1200 var rANFunctionID int64 = 33
1201 p.SubsReqParams.RANFunctionID = &rANFunctionID
1202 actionId := int64(1)
1203 actionType := "policy"
1204 subsequestActioType := "continue"
1205 timeToWait := "w10ms"
1207 for requestCount := 0; requestCount < subReqCount; requestCount++ {
1208 reqId := int64(requestCount) + 1
1209 subscriptionDetail := &clientmodel.SubscriptionDetail{
1210 XappEventInstanceID: &reqId,
1211 EventTriggers: clientmodel.EventTriggerDefinition{
1212 int64(1234 + requestCount),
1214 ActionToBeSetupList: clientmodel.ActionsToBeSetup{
1215 &clientmodel.ActionToBeSetup{
1216 ActionID: &actionId,
1217 ActionType: &actionType,
1218 ActionDefinition: clientmodel.ActionDefinition{
1219 int64(5678 + requestCount),
1221 SubsequentAction: &clientmodel.SubsequentAction{
1222 SubsequentActionType: &subsequestActioType,
1223 TimeToWait: &timeToWait,
1228 p.SubsReqParams.SubscriptionDetails = append(p.SubsReqParams.SubscriptionDetails, subscriptionDetail)
1232 func (p *RESTSubsReqParams) SetSubscriptionDirectives(e2Timeout int64, e2RetryCount int64, routingNeeded bool) {
1234 e2SubscriptionDirectives := &clientmodel.SubscriptionParamsE2SubscriptionDirectives{}
1235 e2SubscriptionDirectives.E2TimeoutTimerValue = e2Timeout
1236 e2SubscriptionDirectives.E2RetryCount = &e2RetryCount
1237 e2SubscriptionDirectives.RMRRoutingNeeded = routingNeeded
1238 p.SubsReqParams.E2SubscriptionDirectives = e2SubscriptionDirectives