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/models"
34 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
40 var e2asnpacker e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
45 type RmrTransactionId struct {
50 type E2RestIds struct {
58 func (trans *RmrTransactionId) String() string {
60 if trans.meid != nil {
61 meidstr = trans.meid.String()
63 return "trans(" + trans.xid + "/" + meidstr + ")"
67 teststub.RmrStubControl
71 CallBackNotification chan int64
72 RESTNotification chan uint32
73 CallBackListedNotifications chan E2RestIds
74 ListedRESTNotifications chan E2RestIds
75 clientEndpoint clientmodel.SubscriptionParamsClientEndpoint
77 restSubsIdList []string
80 //-----------------------------------------------------------------------------
82 //-----------------------------------------------------------------------------
83 func CreateNewE2Stub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int, ranName string, host string, RMRPort int64, HTTPPort int64) *E2Stub {
85 tc.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed)
88 tc.CallBackNotification = make(chan int64)
89 tc.RESTNotification = make(chan uint32)
90 tc.CallBackListedNotifications = make(chan E2RestIds)
91 tc.ListedRESTNotifications = make(chan E2RestIds, 2)
92 var endPoint clientmodel.SubscriptionParamsClientEndpoint
94 endPoint.HTTPPort = &HTTPPort
95 endPoint.RMRPort = &RMRPort
96 tc.clientEndpoint = endPoint
101 //-----------------------------------------------------------------------------
103 //-----------------------------------------------------------------------------
104 func CreateNewE2termStub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int) *E2Stub {
106 tc.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed)
108 tc.SetCheckXid(false)
112 //-----------------------------------------------------------------------------
114 //-----------------------------------------------------------------------------
115 func (tc *E2Stub) NewRmrTransactionId(xid string, ranname string) *RmrTransactionId {
116 trans := &RmrTransactionId{}
118 trans.xid = tc.GetDesc() + "_XID_" + strconv.FormatUint(uint64(tc.xid_seq), 10)
123 trans.meid = &xapp.RMRMeid{RanName: ranname}
124 tc.Debug("New test %s", trans.String())
128 //-----------------------------------------------------------------------------
130 //-----------------------------------------------------------------------------
131 type E2StubSubsReqParams struct {
132 Req *e2ap.E2APSubscriptionRequest
135 func (p *E2StubSubsReqParams) Init() {
136 p.Req = &e2ap.E2APSubscriptionRequest{}
138 p.Req.RequestId.Id = 1
139 p.Req.RequestId.InstanceId = 0
142 // gnb -> enb outgoing
143 // enb -> gnb incoming
145 p.Req.EventTriggerDefinition.Data.Length = 1
146 p.Req.EventTriggerDefinition.Data.Data = make([]uint8, p.Req.EventTriggerDefinition.Data.Length)
147 p.Req.EventTriggerDefinition.Data.Data[0] = 1
149 p.Req.ActionSetups = make([]e2ap.ActionToBeSetupItem, 1)
151 p.Req.ActionSetups[0].ActionId = 0
152 p.Req.ActionSetups[0].ActionType = e2ap.E2AP_ActionTypeReport
153 p.Req.ActionSetups[0].RicActionDefinitionPresent = true
155 p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Length = 1
156 p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Data = make([]uint8, p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Length)
157 p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Data[0] = 1
159 p.Req.ActionSetups[0].SubsequentAction.Present = true
160 p.Req.ActionSetups[0].SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeContinue
161 p.Req.ActionSetups[0].SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitZero
164 //-----------------------------------------------------------------------------
166 //-----------------------------------------------------------------------------
168 type E2StubSubsFailParams struct {
169 Req *e2ap.E2APSubscriptionRequest
170 Fail *e2ap.E2APSubscriptionFailure
173 func (p *E2StubSubsFailParams) Set(req *e2ap.E2APSubscriptionRequest) {
176 p.Fail = &e2ap.E2APSubscriptionFailure{}
177 p.Fail.RequestId.Id = p.Req.RequestId.Id
178 p.Fail.RequestId.InstanceId = p.Req.RequestId.InstanceId
179 p.Fail.FunctionId = p.Req.FunctionId
180 p.Fail.ActionNotAdmittedList.Items = make([]e2ap.ActionNotAdmittedItem, len(p.Req.ActionSetups))
181 for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ {
182 p.Fail.ActionNotAdmittedList.Items[index].ActionId = p.Req.ActionSetups[index].ActionId
183 p.SetCauseVal(index, 5, 1)
187 func (p *E2StubSubsFailParams) SetCauseVal(ind int, content uint8, causeval uint8) {
190 for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ {
191 p.Fail.ActionNotAdmittedList.Items[index].Cause.Content = content
192 p.Fail.ActionNotAdmittedList.Items[index].Cause.Value = causeval
196 p.Fail.ActionNotAdmittedList.Items[ind].Cause.Content = content
197 p.Fail.ActionNotAdmittedList.Items[ind].Cause.Value = causeval
200 //-----------------------------------------------------------------------------
202 //-----------------------------------------------------------------------------
204 func (tc *E2Stub) SendSubsReq(t *testing.T, rparams *E2StubSubsReqParams, oldTrans *RmrTransactionId) *RmrTransactionId {
208 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
211 tc.Debug("SendSubsReq %s", trans.String())
212 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
214 //---------------------------------
215 // xapp activity: Send Subs Req
216 //---------------------------------
220 myparams = &E2StubSubsReqParams{}
224 err, packedMsg := e2SubsReq.Pack(myparams.Req)
226 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
229 tc.Debug("%s %s", trans.String(), e2SubsReq.String())
231 params := &xapp.RMRParams{}
232 params.Mtype = xapp.RIC_SUB_REQ
234 params.Payload = packedMsg.Buf
235 params.PayloadLen = len(packedMsg.Buf)
236 params.Meid = trans.meid
237 params.Xid = trans.xid
240 tc.Debug("SEND SUB REQ: %s", params.String())
241 snderr := tc.SendWithRetry(params, false, 5)
243 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
249 //-----------------------------------------------------------------------------
251 //-----------------------------------------------------------------------------
252 func (tc *E2Stub) RecvSubsReq(t *testing.T) (*e2ap.E2APSubscriptionRequest, *xapp.RMRParams) {
253 tc.Debug("RecvSubsReq")
254 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
256 //---------------------------------
257 // e2term activity: Recv Subs Req
258 //---------------------------------
259 msg := tc.WaitMsg(15)
261 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] {
262 tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_REQ", xapp.RicMessageTypeToName[msg.Mtype])
264 tc.Debug("Recv Subs Req")
265 packedData := &e2ap.PackedData{}
266 packedData.Buf = msg.Payload
267 unpackerr, req := e2SubsReq.UnPack(packedData)
268 if unpackerr != nil {
269 tc.TestError(t, "RIC_SUB_REQ unpack failed err: %s", unpackerr.Error())
274 tc.TestError(t, "Not Received msg within %d secs", 15)
280 //-----------------------------------------------------------------------------
282 //-----------------------------------------------------------------------------
283 func (tc *E2Stub) SendSubsResp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *xapp.RMRParams) {
284 tc.Debug("SendSubsResp")
285 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
287 //---------------------------------
288 // e2term activity: Send Subs Resp
289 //---------------------------------
290 resp := &e2ap.E2APSubscriptionResponse{}
292 resp.RequestId.Id = req.RequestId.Id
293 resp.RequestId.InstanceId = req.RequestId.InstanceId
294 resp.FunctionId = req.FunctionId
296 resp.ActionAdmittedList.Items = make([]e2ap.ActionAdmittedItem, len(req.ActionSetups))
297 for index := int(0); index < len(req.ActionSetups); index++ {
298 resp.ActionAdmittedList.Items[index].ActionId = req.ActionSetups[index].ActionId
301 for index := uint64(0); index < 1; index++ {
302 item := e2ap.ActionNotAdmittedItem{}
303 item.ActionId = index
304 item.Cause.Content = 1
306 resp.ActionNotAdmittedList.Items = append(resp.ActionNotAdmittedList.Items, item)
309 packerr, packedMsg := e2SubsResp.Pack(resp)
311 tc.TestError(t, "pack NOK %s", packerr.Error())
313 tc.Debug("%s", e2SubsResp.String())
315 params := &xapp.RMRParams{}
316 params.Mtype = xapp.RIC_SUB_RESP
317 //params.SubId = msg.SubId
319 params.Payload = packedMsg.Buf
320 params.PayloadLen = len(packedMsg.Buf)
321 params.Meid = msg.Meid
322 //params.Xid = msg.Xid
325 tc.Debug("SEND SUB RESP: %s", params.String())
326 snderr := tc.SendWithRetry(params, false, 5)
328 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
332 //-----------------------------------------------------------------------------
334 //-----------------------------------------------------------------------------
335 func (tc *E2Stub) SendInvalidE2Asn1Resp(t *testing.T, msg *xapp.RMRParams, msgType int) {
337 params := &xapp.RMRParams{}
338 params.Mtype = msgType
340 params.Payload = []byte{1, 2, 3, 4, 5}
341 params.PayloadLen = 5
342 params.Meid = msg.Meid
346 if params.Mtype == xapp.RIC_SUB_RESP {
347 tc.Debug("SEND INVALID ASN.1 SUB RESP")
349 } else if params.Mtype == xapp.RIC_SUB_FAILURE {
350 tc.Debug("SEND INVALID ASN.1 SUB FAILURE")
352 } else if params.Mtype == xapp.RIC_SUB_DEL_RESP {
353 tc.Debug("SEND INVALID ASN.1 SUB DEL RESP")
355 } else if params.Mtype == xapp.RIC_SUB_DEL_FAILURE {
356 tc.Debug("SEND INVALID ASN.1 SUB DEL FAILURE")
358 snderr := tc.SendWithRetry(params, false, 5)
360 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
364 //-----------------------------------------------------------------------------
366 //-----------------------------------------------------------------------------
367 func (tc *E2Stub) RecvSubsResp(t *testing.T, trans *RmrTransactionId) uint32 {
368 tc.Debug("RecvSubsResp")
369 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
372 //---------------------------------
373 // xapp activity: Recv Subs Resp
374 //---------------------------------
375 msg := tc.WaitMsg(15)
377 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
378 tc.TestError(t, "Received RIC_SUB_RESP wrong mtype expected %s got %s, error", "RIC_SUB_RESP", xapp.RicMessageTypeToName[msg.Mtype])
380 } else if msg.Xid != trans.xid {
381 tc.TestError(t, "Received RIC_SUB_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
384 packedData := &e2ap.PackedData{}
385 packedData.Buf = msg.Payload
387 e2SubsId = uint32(msg.SubId)
391 unpackerr, resp := e2SubsResp.UnPack(packedData)
392 if unpackerr != nil {
393 tc.TestError(t, "RIC_SUB_RESP unpack failed err: %s", unpackerr.Error())
395 tc.Debug("Recv Subs Resp rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
399 tc.TestError(t, "Not Received msg within %d secs", 15)
404 //-----------------------------------------------------------------------------
406 //-----------------------------------------------------------------------------
408 func (tc *E2Stub) SendSubsFail(t *testing.T, fparams *E2StubSubsFailParams, msg *xapp.RMRParams) {
409 tc.Debug("SendSubsFail")
410 e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
412 //---------------------------------
413 // e2term activity: Send Subs Fail
414 //---------------------------------
415 packerr, packedMsg := e2SubsFail.Pack(fparams.Fail)
417 tc.TestError(t, "pack NOK %s", packerr.Error())
419 tc.Debug("%s", e2SubsFail.String())
421 params := &xapp.RMRParams{}
422 params.Mtype = xapp.RIC_SUB_FAILURE
423 params.SubId = msg.SubId
424 params.Payload = packedMsg.Buf
425 params.PayloadLen = len(packedMsg.Buf)
426 params.Meid = msg.Meid
430 tc.Debug("SEND SUB FAIL: %s", params.String())
431 snderr := tc.SendWithRetry(params, false, 5)
433 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
437 //-----------------------------------------------------------------------------
439 //-----------------------------------------------------------------------------
440 func (tc *E2Stub) RecvSubsFail(t *testing.T, trans *RmrTransactionId) uint32 {
441 tc.Debug("RecvSubsFail")
442 e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
445 //-------------------------------
446 // xapp activity: Recv Subs Fail
447 //-------------------------------
448 msg := tc.WaitMsg(15)
450 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_FAILURE"] {
451 tc.TestError(t, "Received RIC_SUB_FAILURE wrong mtype expected %s got %s, error", "RIC_SUB_FAILURE", xapp.RicMessageTypeToName[msg.Mtype])
453 } else if msg.Xid != trans.xid {
454 tc.TestError(t, "Received RIC_SUB_FAILURE wrong xid expected %s got %s, error", trans.xid, msg.Xid)
457 packedData := &e2ap.PackedData{}
458 packedData.Buf = msg.Payload
460 e2SubsId = uint32(msg.SubId)
464 unpackerr, resp := e2SubsFail.UnPack(packedData)
465 if unpackerr != nil {
466 tc.TestError(t, "RIC_SUB_FAILURE unpack failed err: %s", unpackerr.Error())
468 tc.Debug("Recv Subs Fail rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
472 tc.TestError(t, "Not Received msg within %d secs", 15)
477 //-----------------------------------------------------------------------------
479 //-----------------------------------------------------------------------------
480 func (tc *E2Stub) SendSubsDelReq(t *testing.T, oldTrans *RmrTransactionId, e2SubsId uint32) *RmrTransactionId {
484 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
487 tc.Debug("SendSubsDelReq %s", trans.String())
488 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
489 //---------------------------------
490 // xapp activity: Send Subs Del Req
491 //---------------------------------
492 req := &e2ap.E2APSubscriptionDeleteRequest{}
494 req.RequestId.InstanceId = e2SubsId
497 err, packedMsg := e2SubsDelReq.Pack(req)
499 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
502 tc.Debug("%s %s", trans.String(), e2SubsDelReq.String())
504 params := &xapp.RMRParams{}
505 params.Mtype = xapp.RIC_SUB_DEL_REQ
506 params.SubId = int(e2SubsId)
507 params.Payload = packedMsg.Buf
508 params.PayloadLen = len(packedMsg.Buf)
509 params.Meid = trans.meid
510 params.Xid = trans.xid
513 tc.Debug("SEND SUB DEL REQ: %s", params.String())
514 snderr := tc.SendWithRetry(params, false, 5)
516 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
522 //-----------------------------------------------------------------------------
524 //-----------------------------------------------------------------------------
525 func (tc *E2Stub) RecvSubsDelReq(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *xapp.RMRParams) {
526 tc.Debug("RecvSubsDelReq")
527 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
529 //---------------------------------
530 // e2term activity: Recv Subs Del Req
531 //---------------------------------
532 msg := tc.WaitMsg(15)
534 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] {
535 tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_DEL_REQ", xapp.RicMessageTypeToName[msg.Mtype])
537 tc.Debug("Recv Subs Del Req")
539 packedData := &e2ap.PackedData{}
540 packedData.Buf = msg.Payload
541 unpackerr, req := e2SubsDelReq.UnPack(packedData)
542 if unpackerr != nil {
543 tc.TestError(t, "RIC_SUB_DEL_REQ unpack failed err: %s", unpackerr.Error())
548 tc.TestError(t, "Not Received msg within %d secs", 15)
553 //-----------------------------------------------------------------------------
555 //-----------------------------------------------------------------------------
556 func (tc *E2Stub) SendSubsDelResp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapp.RMRParams) {
557 tc.Debug("SendSubsDelResp")
558 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
560 //---------------------------------
561 // e2term activity: Send Subs Del Resp
562 //---------------------------------
563 resp := &e2ap.E2APSubscriptionDeleteResponse{}
564 resp.RequestId.Id = req.RequestId.Id
565 resp.RequestId.InstanceId = req.RequestId.InstanceId
566 resp.FunctionId = req.FunctionId
568 packerr, packedMsg := e2SubsDelResp.Pack(resp)
570 tc.TestError(t, "pack NOK %s", packerr.Error())
572 tc.Debug("%s", e2SubsDelResp.String())
574 params := &xapp.RMRParams{}
575 params.Mtype = xapp.RIC_SUB_DEL_RESP
576 params.SubId = msg.SubId
577 params.Payload = packedMsg.Buf
578 params.PayloadLen = len(packedMsg.Buf)
579 params.Meid = msg.Meid
583 tc.Debug("SEND SUB DEL RESP: %s", params.String())
584 snderr := tc.SendWithRetry(params, false, 5)
586 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
590 //-----------------------------------------------------------------------------
592 //-----------------------------------------------------------------------------
593 func (tc *E2Stub) RecvSubsDelResp(t *testing.T, trans *RmrTransactionId) {
594 tc.Debug("RecvSubsDelResp")
595 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
597 //---------------------------------
598 // xapp activity: Recv Subs Del Resp
599 //---------------------------------
600 msg := tc.WaitMsg(15)
602 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
603 tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong mtype expected %s got %s, error", "RIC_SUB_DEL_RESP", xapp.RicMessageTypeToName[msg.Mtype])
605 } else if trans != nil && msg.Xid != trans.xid {
606 tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
609 packedData := &e2ap.PackedData{}
610 packedData.Buf = msg.Payload
611 unpackerr, resp := e2SubsDelResp.UnPack(packedData)
612 if unpackerr != nil {
613 tc.TestError(t, "RIC_SUB_DEL_RESP unpack failed err: %s", unpackerr.Error())
615 tc.Debug("Recv Subs Del Resp rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
619 tc.TestError(t, "Not Received msg within %d secs", 15)
623 //-----------------------------------------------------------------------------
625 //-----------------------------------------------------------------------------
626 func (tc *E2Stub) SendSubsDelFail(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapp.RMRParams) {
627 tc.Debug("SendSubsDelFail")
628 e2SubsDelFail := e2asnpacker.NewPackerSubscriptionDeleteFailure()
630 //---------------------------------
631 // e2term activity: Send Subs Del Fail
632 //---------------------------------
633 resp := &e2ap.E2APSubscriptionDeleteFailure{}
634 resp.RequestId.Id = req.RequestId.Id
635 resp.RequestId.InstanceId = req.RequestId.InstanceId
636 resp.FunctionId = req.FunctionId
637 resp.Cause.Content = 5 // CauseMisc
638 resp.Cause.Value = 3 // unspecified
640 packerr, packedMsg := e2SubsDelFail.Pack(resp)
642 tc.TestError(t, "pack NOK %s", packerr.Error())
644 tc.Debug("%s", e2SubsDelFail.String())
646 params := &xapp.RMRParams{}
647 params.Mtype = xapp.RIC_SUB_DEL_FAILURE
648 params.SubId = msg.SubId
649 params.Payload = packedMsg.Buf
650 params.PayloadLen = len(packedMsg.Buf)
651 params.Meid = msg.Meid
655 tc.Debug("SEND SUB DEL FAIL: %s", params.String())
656 snderr := tc.SendWithRetry(params, false, 5)
658 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
662 // REST code below all
664 /*****************************************************************************/
665 // REST interface specific functions are below
667 //-----------------------------------------------------------------------------
668 // Callback handler for subscription response notifications
669 //-----------------------------------------------------------------------------
670 func (tc *E2Stub) SubscriptionRespHandler(resp *clientmodel.SubscriptionResponse) {
672 if tc.subscriptionId == "SUBSCRIPTIONID NOT SET" {
673 tc.Debug("REST notification received for %v while no SubscriptionID was not set for E2EventInstanceID=%v, XappEventInstanceID=%v (%v)",
674 *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
675 tc.CallBackNotification <- *resp.SubscriptionInstances[0].E2EventInstanceID
676 } else if tc.subscriptionId == *resp.SubscriptionID {
677 tc.Debug("REST notification received SubscriptionID=%s, E2EventInstanceID=%v, RequestorID=%v (%v)",
678 *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
679 tc.CallBackNotification <- *resp.SubscriptionInstances[0].E2EventInstanceID
681 tc.Debug("MISMATCHING REST notification received SubscriptionID=%s<>%s, E2EventInstanceID=%v, XappEventInstanceID=%v (%v)",
682 tc.subscriptionId, *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
686 //-----------------------------------------------------------------------------
688 //-----------------------------------------------------------------------------
690 func (tc *E2Stub) ExpectRESTNotification(t *testing.T, restSubsId string) {
691 tc.expectNotification(t, restSubsId, "")
694 func (tc *E2Stub) ExpectRESTNotificationOk(t *testing.T, restSubsId string) {
695 tc.expectNotification(t, restSubsId, "allOk")
698 func (tc *E2Stub) ExpectRESTNotificationNok(t *testing.T, restSubsId string, expectError string) {
699 tc.expectNotification(t, restSubsId, expectError)
702 func (tc *E2Stub) expectNotification(t *testing.T, restSubsId string, expectError string) {
704 tc.Debug("### Started to wait REST notification for %v on port %v f(RMR port %v), %v responses expected", restSubsId, *tc.clientEndpoint.HTTPPort, *tc.clientEndpoint.RMRPort, tc.requestCount)
705 tc.restSubsIdList = []string{restSubsId}
706 xapp.Subscription.SetResponseCB(tc.ListedRestNotifHandler)
707 if tc.requestCount == 0 {
708 tc.TestError(t, "### NO REST notifications SET received for endpoint=%s, request zount ZERO! (%v)", tc.clientEndpoint, tc)
712 case e2Ids := <-tc.CallBackListedNotifications:
713 if tc.requestCount == 0 {
714 tc.TestError(t, "### REST notification count unexpectedly ZERO for %s (%v)", restSubsId, tc)
715 } else if e2Ids.RestSubsId != restSubsId {
716 tc.TestError(t, "### Unexpected REST notifications received, expected %s bunt got %s instead| (%v)", e2Ids.RestSubsId, restSubsId, tc)
717 } else if e2Ids.ErrorCause == "" && expectError == "allFail" {
718 tc.TestError(t, "### Unexpected ok cause received from REST notifications |%s:%s| (%v)", e2Ids.RestSubsId, restSubsId, tc)
719 } else if e2Ids.ErrorCause != "" && expectError == "allOk" {
720 tc.TestError(t, "### Unexpected ErrorCause: (%s), ErrorSource: (%s), TimeoutType: (%s) received from REST notifications |%s:%s| (%v)", e2Ids.ErrorCause, e2Ids.ErrorSource, e2Ids.TimeoutType, e2Ids.RestSubsId, restSubsId, tc)
723 if tc.requestCount == 0 {
724 tc.Debug("### All expected REST notifications received for %s (%v)", e2Ids.RestSubsId, tc)
726 tc.Debug("### Expected REST notifications received for %s, (%v)", e2Ids.RestSubsId, tc)
728 if e2Ids.ErrorCause != "" && expectError == "allFail" {
729 tc.Debug("### REST Notification: RestSubsId: %s, ErrorCause: %s, ErrorSource: (%s), TimeoutType: (%s)", e2Ids.RestSubsId, e2Ids.ErrorCause, e2Ids.ErrorSource, e2Ids.TimeoutType)
731 tc.Debug("### REST Notification received Notif for %s : %v", e2Ids.RestSubsId, e2Ids.E2SubsId)
732 tc.ListedRESTNotifications <- e2Ids
733 if len(tc.ListedRESTNotifications) > 1 {
734 panic("expectNotification - ListedRESTNotifications stacking up")
737 case <-time.After(15 * time.Second):
738 err := fmt.Errorf("### Timeout 15s expired while expecting REST notification for subsId: %v", restSubsId)
739 tc.TestError(t, "%s", err.Error())
744 func (tc *E2Stub) WaitRESTNotification(t *testing.T, restSubsId string) uint32 {
746 stack := string(debug.Stack())
749 case e2SubsId := <-tc.ListedRESTNotifications:
750 if e2SubsId.RestSubsId == restSubsId {
751 tc.Debug("### Expected REST notifications received %s, e2SubsId %v for endpoint=%s, (%v)", e2SubsId.RestSubsId, e2SubsId.E2SubsId, tc.clientEndpoint, tc)
752 return e2SubsId.E2SubsId
754 tc.TestError(t, "### Unexpected REST notification %s received, expected %s for endpoint=%s, (%v)", e2SubsId.RestSubsId, restSubsId, tc.clientEndpoint, tc)
755 xapp.Logger.Debug("CALL STACK:\n %s", stack)
758 case <-time.After(15 * time.Second):
759 err := fmt.Errorf("### Timeout 15s expired while waiting REST notification for subsId: %v", restSubsId)
760 tc.TestError(t, "%s", err.Error())
761 xapp.Logger.Debug("CALL STACK:\n %s", stack)
762 panic("WaitRESTNotification - timeout error")
766 // Note, this function should be followed by a handling of <-xappConn1.RESTNotification.
767 func (tc *E2Stub) ExpectAnyNotification(t *testing.T) {
769 tc.Debug("### Started waiting ANY REST notifications received for endpoint=%s, (%v)", tc.clientEndpoint, tc)
771 case e2SubsId := <-tc.CallBackNotification:
772 tc.Debug("### ANY REST notifications received e2SubsId %v for endpoint=%s, (%v) via CallBackNotification", e2SubsId, tc.clientEndpoint, tc)
773 tc.RESTNotification <- (uint32)(e2SubsId)
774 case <-time.After(15 * time.Second):
775 err := fmt.Errorf("### Timeout 15s expired while waiting ANY REST notification")
776 tc.TestError(t, "%s", err.Error())
777 tc.RESTNotification <- 0
782 func (tc *E2Stub) WaitAnyRESTNotification(t *testing.T) uint32 {
785 case e2SubsId := <-tc.RESTNotification:
786 tc.Debug("### Expected ANY REST notification received - e2SubsId %v for endpoint=%s, (%v)", e2SubsId, tc.clientEndpoint, tc)
789 case <-time.After(15 * time.Second):
790 err := fmt.Errorf("### Timeout 15s expired while waiting ANY REST notification")
791 tc.TestError(t, "%s", err.Error())
792 panic("WaitRESTNotification - timeout error")
796 func (tc *E2Stub) ListedRestNotifHandler(resp *clientmodel.SubscriptionResponse) {
798 if len(tc.restSubsIdList) == 0 {
799 tc.Error("Unexpected listed REST notifications received for endpoint=%s, expected restSubsId list size was ZERO!", tc.clientEndpoint)
801 for i, subsId := range tc.restSubsIdList {
802 if *resp.SubscriptionID == subsId {
803 //tc.Debug("Listed REST notifications received SubscriptionID=%s, InstanceID=%v, XappEventInstanceID=%v",
804 // *resp.SubscriptionID, *resp.SubscriptionInstances[0].InstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID)
806 tc.restSubsIdList = append(tc.restSubsIdList[:i], tc.restSubsIdList[i+1:]...)
807 //tc.Debug("Removed %s from Listed REST notifications, %v entries left", *resp.SubscriptionID, len(tc.restSubsIdList))
809 // if resp.SubscriptionInstances[0].ErrorCause != nil {
810 tc.CallBackListedNotifications <- *tc.GetE2RestIds(resp)
812 // tc.CallBackListedNotifications <- E2RestIds{*resp.SubscriptionID, uint32(*resp.SubscriptionInstances[0].E2EventInstanceID), "", "", ""}
815 if len(tc.restSubsIdList) == 0 {
816 tc.Debug("All listed REST notifications received for endpoint=%s", tc.clientEndpoint)
822 tc.Error("UNKONWN REST notification received SubscriptionID=%s<>%s, InstanceID=%v, XappEventInstanceID=%v (%v)",
823 tc.subscriptionId, *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
827 //-----------------------------------------------------------------------------
829 //-----------------------------------------------------------------------------
830 func (tc *E2Stub) GetE2RestIds(resp *clientmodel.SubscriptionResponse) *E2RestIds {
832 e2RestIds := &E2RestIds{}
834 if resp.SubscriptionID != nil {
835 e2RestIds.RestSubsId = *resp.SubscriptionID
837 if resp.SubscriptionInstances != nil {
838 if resp.SubscriptionInstances[0].E2EventInstanceID != nil {
839 e2RestIds.E2SubsId = uint32(*resp.SubscriptionInstances[0].E2EventInstanceID)
841 if resp.SubscriptionInstances[0].ErrorCause != nil {
842 e2RestIds.ErrorCause = *resp.SubscriptionInstances[0].ErrorCause
844 e2RestIds.ErrorCause = "nil"
846 if resp.SubscriptionInstances[0].ErrorSource != nil {
847 e2RestIds.ErrorSource = *resp.SubscriptionInstances[0].ErrorSource
849 e2RestIds.ErrorSource = "nil"
851 if resp.SubscriptionInstances[0].TimeoutType != nil {
852 e2RestIds.TimeoutType = *resp.SubscriptionInstances[0].TimeoutType
854 e2RestIds.TimeoutType = "nil"
861 //-----------------------------------------------------------------------------
863 //-----------------------------------------------------------------------------
864 func (tc *E2Stub) WaitListedRestNotifications(t *testing.T, restSubsIds []string) {
865 tc.Debug("Started to wait REST notifications %v on port %v f(RMR port %v)", restSubsIds, *tc.clientEndpoint.HTTPPort, *tc.clientEndpoint.RMRPort)
867 tc.restSubsIdList = restSubsIds
868 xapp.Subscription.SetResponseCB(tc.ListedRestNotifHandler)
870 for i := 0; i < len(restSubsIds); i++ {
873 case e2Ids := <-tc.CallBackListedNotifications:
874 tc.Debug("Listed Notification waiter received Notif for %s : %v", e2Ids.RestSubsId, e2Ids.E2SubsId)
875 tc.ListedRESTNotifications <- e2Ids
876 case <-time.After(15 * time.Second):
877 err := fmt.Errorf("Timeout 15s expired while waiting Listed REST notification")
878 tc.TestError(t, "%s", err.Error())
879 tc.RESTNotification <- 0
885 //-----------------------------------------------------------------------------
887 //-----------------------------------------------------------------------------
888 func (tc *E2Stub) SendRESTSubsReq(t *testing.T, params *RESTSubsReqParams) string {
889 tc.Debug("======== Posting REST subscriptions to Submgr ======")
892 tc.Debug("SendRESTReportSubsReq: params == nil")
896 tc.subscriptionId = "SUBSCRIPTIONID NOT SET"
898 resp, err := xapp.Subscription.Subscribe(¶ms.SubsReqParams)
900 // Swagger generated code makes checks for the values that are inserted the subscription function
901 // If error cause is unknown and POST is not done, the problem is in the inserted values
902 tc.Error("======== REST subscription request failed %s ========", err.Error())
904 tc.PrintSubscriptionInsctanceErrorInfo(resp)
906 tc.Error("Subscribe resp == nil")
910 tc.subscriptionId = *resp.SubscriptionID
911 tc.Debug("======== REST subscriptions posted successfully. SubscriptionID = %s, RequestCount = %v ========", *resp.SubscriptionID, tc.requestCount)
912 return *resp.SubscriptionID
915 //-----------------------------------------------------------------------------
917 //-----------------------------------------------------------------------------
918 func (tc *E2Stub) PrintSubscriptionInsctanceErrorInfo(resp *clientmodel.SubscriptionResponse) {
919 for _, subscriptionInstance := range resp.SubscriptionInstances {
920 if subscriptionInstance != nil {
921 if subscriptionInstance.RejectCause != nil {
922 tc.Error("subscriptionInstance.RejectCause= %s", *subscriptionInstance.RejectCause)
924 if subscriptionInstance.ErrorCause != nil {
925 tc.Error("subscriptionInstance.ErrorCause= %s", *subscriptionInstance.ErrorCause)
927 if subscriptionInstance.ErrorSource != nil {
928 tc.Error("subscriptionInstance.ErrorSource= %s", *subscriptionInstance.ErrorSource)
930 if subscriptionInstance.TimeoutType != nil {
931 tc.Error("subscriptionInstance.TimeoutType = %s", *subscriptionInstance.TimeoutType)
937 //-----------------------------------------------------------------------------
939 //-----------------------------------------------------------------------------
940 func (tc *E2Stub) GetRESTSubsReqReportParams(subReqCount int) *RESTSubsReqParams {
942 reportParams := RESTSubsReqParams{}
943 reportParams.GetRESTSubsReqReportParams(subReqCount, &tc.clientEndpoint, &tc.meid)
944 tc.requestCount = subReqCount
948 //-----------------------------------------------------------------------------
950 //-----------------------------------------------------------------------------
951 type RESTSubsReqParams struct {
952 SubsReqParams clientmodel.SubscriptionParams
955 func (p *RESTSubsReqParams) GetRESTSubsReqReportParams(subReqCount int, clientEndpoint *clientmodel.SubscriptionParamsClientEndpoint, meid *string) {
958 p.SubsReqParams.ClientEndpoint = clientEndpoint
959 p.SubsReqParams.Meid = meid
960 var rANFunctionID int64 = 33
961 p.SubsReqParams.RANFunctionID = &rANFunctionID
964 actionType := "report"
965 subsequestActioType := "continue"
966 timeToWait := "w10ms"
968 for requestCount := 0; requestCount < subReqCount; requestCount++ {
969 reqId := int64(requestCount) + 1
970 subscriptionDetail := &clientmodel.SubscriptionDetail{
971 XappEventInstanceID: &reqId,
972 EventTriggers: clientmodel.EventTriggerDefinition{
973 int64(1234 + requestCount),
975 ActionToBeSetupList: clientmodel.ActionsToBeSetup{
976 &clientmodel.ActionToBeSetup{
978 ActionType: &actionType,
979 ActionDefinition: clientmodel.ActionDefinition{
980 int64(5678 + requestCount),
982 SubsequentAction: &clientmodel.SubsequentAction{
983 SubsequentActionType: &subsequestActioType,
984 TimeToWait: &timeToWait,
989 p.SubsReqParams.SubscriptionDetails = append(p.SubsReqParams.SubscriptionDetails, subscriptionDetail)
994 func (p *RESTSubsReqParams) SetMeid(MEID string) {
995 p.SubsReqParams.Meid = &MEID
998 func (p *RESTSubsReqParams) SetEndpoint(HTTP_port int64, RMR_port int64, host string) {
999 var endpoint clientmodel.SubscriptionParamsClientEndpoint
1000 endpoint.HTTPPort = &HTTP_port
1001 endpoint.RMRPort = &RMR_port
1002 endpoint.Host = host
1003 p.SubsReqParams.ClientEndpoint = &endpoint
1006 func (p *RESTSubsReqParams) SetEndpointHost(host string) {
1008 if p.SubsReqParams.ClientEndpoint.Host != "" {
1009 if p.SubsReqParams.ClientEndpoint.Host != host {
1010 // Renaming toto, print something tc.Debug("Posting REST subscription request to Submgr")
1011 err := fmt.Errorf("hostname change attempt: %s -> %s", p.SubsReqParams.ClientEndpoint.Host, host)
1015 p.SubsReqParams.ClientEndpoint.Host = host
1018 func (p *RESTSubsReqParams) SetHTTPEndpoint(HTTP_port int64, host string) {
1020 p.SubsReqParams.ClientEndpoint.HTTPPort = &HTTP_port
1022 p.SetEndpointHost(host)
1024 if p.SubsReqParams.ClientEndpoint.RMRPort == nil {
1026 p.SubsReqParams.ClientEndpoint.RMRPort = &RMR_port
1030 func (p *RESTSubsReqParams) SetE2SubscriptionDirectives(E2RetryCount int64, E2TimeoutTimerValue int64, RMRRoutingNeeded bool) {
1032 E2SubscriptionDirectives := &clientmodel.SubscriptionParamsE2SubscriptionDirectives{}
1033 p.SubsReqParams.E2SubscriptionDirectives = E2SubscriptionDirectives
1034 p.SubsReqParams.E2SubscriptionDirectives.E2RetryCount = &E2RetryCount
1035 p.SubsReqParams.E2SubscriptionDirectives.E2TimeoutTimerValue = E2TimeoutTimerValue
1036 p.SubsReqParams.E2SubscriptionDirectives.RMRRoutingNeeded = &RMRRoutingNeeded
1039 func (p *RESTSubsReqParams) RemoveE2SubscriptionDirectives() {
1041 p.SubsReqParams.E2SubscriptionDirectives = nil
1044 func (p *RESTSubsReqParams) SetSubActionTypes(actionType string) {
1046 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1047 for _, action := range subDetail.ActionToBeSetupList {
1049 action.ActionType = &actionType
1055 func (p *RESTSubsReqParams) SetSubActionIDs(actionId int64) {
1057 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1058 for _, action := range subDetail.ActionToBeSetupList {
1060 action.ActionID = &actionId
1066 func (p *RESTSubsReqParams) SetSubActionDefinition(actionDefinition []int64) {
1068 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1069 for _, action := range subDetail.ActionToBeSetupList {
1071 action.ActionDefinition = actionDefinition
1077 func (p *RESTSubsReqParams) SetSubEventTriggerDefinition(eventTriggerDefinition []int64) {
1079 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1080 if subDetail != nil {
1081 subDetail.EventTriggers = eventTriggerDefinition
1086 func (p *RESTSubsReqParams) AppendActionToActionToBeSetupList(actionId int64, actionType string, actionDefinition []int64, subsequentActionType string, timeToWait string) {
1088 actionToBeSetup := &clientmodel.ActionToBeSetup{
1089 ActionID: &actionId,
1090 ActionType: &actionType,
1091 ActionDefinition: clientmodel.ActionDefinition(actionDefinition),
1092 SubsequentAction: &clientmodel.SubsequentAction{
1093 SubsequentActionType: &subsequentActionType,
1094 TimeToWait: &timeToWait,
1098 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1099 if subDetail != nil {
1100 subDetail.ActionToBeSetupList = append(subDetail.ActionToBeSetupList, actionToBeSetup)
1105 func (p *RESTSubsReqParams) SetRMREndpoint(RMR_port int64, host string) {
1107 p.SubsReqParams.ClientEndpoint.RMRPort = &RMR_port
1109 p.SetEndpointHost(host)
1111 if p.SubsReqParams.ClientEndpoint.HTTPPort == nil {
1113 p.SubsReqParams.ClientEndpoint.HTTPPort = &HTTP_port
1117 func (p *RESTSubsReqParams) SetTimeToWait(timeToWait string) {
1119 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1120 for _, action := range subDetail.ActionToBeSetupList {
1121 if action != nil && action.SubsequentAction != nil {
1122 action.SubsequentAction.TimeToWait = &timeToWait
1128 func (p *RESTSubsReqParams) SetSubscriptionID(SubscriptionID *string) {
1130 if *SubscriptionID == "" {
1133 p.SubsReqParams.SubscriptionID = *SubscriptionID
1136 func (p *RESTSubsReqParams) SetXappEventInstanceID(xappEventInstanceId int64) {
1138 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1139 if subDetail != nil {
1140 subDetail.XappEventInstanceID = &xappEventInstanceId
1145 //-----------------------------------------------------------------------------
1147 //-----------------------------------------------------------------------------
1148 func (tc *E2Stub) SendRESTSubsDelReq(t *testing.T, subscriptionID *string) {
1150 tc.Debug("======== Posting REST DELETE subscription(s) to Submgr ======")
1152 if *subscriptionID == "" {
1153 tc.Error("REST error in deleting subscriptions. Empty SubscriptionID = %s", *subscriptionID)
1155 tc.Debug("REST deleting E2 subscriptions. SubscriptionID = %s", *subscriptionID)
1157 err := xapp.Subscription.Unsubscribe(*subscriptionID)
1159 tc.Error("REST Delete subscription failed %s", err.Error())
1161 tc.Debug("REST delete subscription pushed to submgr successfully. SubscriptionID = %s", *subscriptionID)
1164 //-----------------------------------------------------------------------------
1166 //-----------------------------------------------------------------------------
1167 func (tc *E2Stub) GetRESTSubsReqPolicyParams(subReqCount int) *RESTSubsReqParams {
1169 policyParams := RESTSubsReqParams{}
1170 policyParams.GetRESTSubsReqPolicyParams(subReqCount, &tc.clientEndpoint, &tc.meid)
1171 tc.requestCount = subReqCount
1172 return &policyParams
1175 //-----------------------------------------------------------------------------
1177 //-----------------------------------------------------------------------------
1178 func (tc *E2Stub) DecrementRequestCount() {
1179 if tc.requestCount > 0 {
1180 tc.requestCount -= 1
1182 tc.Error("FAILED to decrement request count, count already ZERO")
1186 //-----------------------------------------------------------------------------
1188 //-----------------------------------------------------------------------------
1189 func (p *RESTSubsReqParams) GetRESTSubsReqPolicyParams(subReqCount int, clientEndpoint *clientmodel.SubscriptionParamsClientEndpoint, meid *string) {
1191 p.SubsReqParams.ClientEndpoint = clientEndpoint
1192 p.SubsReqParams.Meid = meid
1193 var rANFunctionID int64 = 33
1194 p.SubsReqParams.RANFunctionID = &rANFunctionID
1195 actionId := int64(1)
1196 actionType := "policy"
1197 subsequestActioType := "continue"
1198 timeToWait := "w10ms"
1200 for requestCount := 0; requestCount < subReqCount; requestCount++ {
1201 reqId := int64(requestCount) + 1
1202 subscriptionDetail := &clientmodel.SubscriptionDetail{
1203 XappEventInstanceID: &reqId,
1204 EventTriggers: clientmodel.EventTriggerDefinition{
1205 int64(1234 + requestCount),
1207 ActionToBeSetupList: clientmodel.ActionsToBeSetup{
1208 &clientmodel.ActionToBeSetup{
1209 ActionID: &actionId,
1210 ActionType: &actionType,
1211 ActionDefinition: clientmodel.ActionDefinition{
1212 int64(5678 + requestCount),
1214 SubsequentAction: &clientmodel.SubsequentAction{
1215 SubsequentActionType: &subsequestActioType,
1216 TimeToWait: &timeToWait,
1221 p.SubsReqParams.SubscriptionDetails = append(p.SubsReqParams.SubscriptionDetails, subscriptionDetail)
1225 func (p *RESTSubsReqParams) SetSubscriptionDirectives(e2Timeout int64, e2RetryCount int64, routingNeeded bool) {
1227 e2SubscriptionDirectives := &clientmodel.SubscriptionParamsE2SubscriptionDirectives{}
1228 e2SubscriptionDirectives.E2TimeoutTimerValue = e2Timeout
1229 e2SubscriptionDirectives.E2RetryCount = &e2RetryCount
1230 e2SubscriptionDirectives.RMRRoutingNeeded = &routingNeeded
1231 p.SubsReqParams.E2SubscriptionDirectives = e2SubscriptionDirectives