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=%v, (%v)", e2SubsId.RestSubsId, e2SubsId.E2SubsId, tc.clientEndpoint, *tc)
752 return e2SubsId.E2SubsId
754 tc.TestError(t, "### Unexpected REST notification %s received, expected %v for endpoint=%v, (%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=%v, 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=%v", 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 e2RestIds.ErrorCause = resp.SubscriptionInstances[0].ErrorCause
842 e2RestIds.ErrorSource = resp.SubscriptionInstances[0].ErrorSource
843 e2RestIds.TimeoutType = resp.SubscriptionInstances[0].TimeoutType
849 //-----------------------------------------------------------------------------
851 //-----------------------------------------------------------------------------
852 func (tc *E2Stub) WaitListedRestNotifications(t *testing.T, restSubsIds []string) {
853 tc.Debug("Started to wait REST notifications %v on port %v f(RMR port %v)", restSubsIds, *tc.clientEndpoint.HTTPPort, *tc.clientEndpoint.RMRPort)
855 tc.restSubsIdList = restSubsIds
856 xapp.Subscription.SetResponseCB(tc.ListedRestNotifHandler)
858 for i := 0; i < len(restSubsIds); i++ {
861 case e2Ids := <-tc.CallBackListedNotifications:
862 tc.Debug("Listed Notification waiter received Notif for %s : %v", e2Ids.RestSubsId, e2Ids.E2SubsId)
863 tc.ListedRESTNotifications <- e2Ids
864 case <-time.After(15 * time.Second):
865 err := fmt.Errorf("Timeout 15s expired while waiting Listed REST notification")
866 tc.TestError(t, "%s", err.Error())
867 tc.RESTNotification <- 0
873 //-----------------------------------------------------------------------------
875 //-----------------------------------------------------------------------------
876 func (tc *E2Stub) SendRESTSubsReq(t *testing.T, params *RESTSubsReqParams) string {
877 tc.Debug("======== Posting REST subscriptions to Submgr ======")
880 tc.Debug("SendRESTReportSubsReq: params == nil")
884 tc.subscriptionId = "SUBSCRIPTIONID NOT SET"
886 resp, err := xapp.Subscription.Subscribe(¶ms.SubsReqParams)
888 // Swagger generated code makes checks for the values that are inserted the subscription function
889 // If error cause is unknown and POST is not done, the problem is in the inserted values
890 tc.Error("======== REST subscription request failed %s ========", err.Error())
893 tc.subscriptionId = *resp.SubscriptionID
894 tc.Debug("======== REST subscriptions posted successfully. SubscriptionID = %s, RequestCount = %v ========", *resp.SubscriptionID, tc.requestCount)
895 return *resp.SubscriptionID
898 //-----------------------------------------------------------------------------
900 //-----------------------------------------------------------------------------
901 func (tc *E2Stub) GetRESTSubsReqReportParams(subReqCount int) *RESTSubsReqParams {
903 reportParams := RESTSubsReqParams{}
904 reportParams.GetRESTSubsReqReportParams(subReqCount, &tc.clientEndpoint, &tc.meid)
905 tc.requestCount = subReqCount
909 //-----------------------------------------------------------------------------
911 //-----------------------------------------------------------------------------
912 type RESTSubsReqParams struct {
913 SubsReqParams clientmodel.SubscriptionParams
916 func (p *RESTSubsReqParams) GetRESTSubsReqReportParams(subReqCount int, clientEndpoint *clientmodel.SubscriptionParamsClientEndpoint, meid *string) {
919 p.SubsReqParams.ClientEndpoint = clientEndpoint
920 p.SubsReqParams.Meid = meid
921 var rANFunctionID int64 = 33
922 p.SubsReqParams.RANFunctionID = &rANFunctionID
925 actionType := "report"
926 subsequestActioType := "continue"
927 timeToWait := "w10ms"
929 for requestCount := 0; requestCount < subReqCount; requestCount++ {
930 reqId := int64(requestCount) + 1
931 subscriptionDetail := &clientmodel.SubscriptionDetail{
932 XappEventInstanceID: &reqId,
933 EventTriggers: clientmodel.EventTriggerDefinition{
934 int64(1234 + requestCount),
936 ActionToBeSetupList: clientmodel.ActionsToBeSetup{
937 &clientmodel.ActionToBeSetup{
939 ActionType: &actionType,
940 ActionDefinition: clientmodel.ActionDefinition{
941 int64(5678 + requestCount),
943 SubsequentAction: &clientmodel.SubsequentAction{
944 SubsequentActionType: &subsequestActioType,
945 TimeToWait: &timeToWait,
950 p.SubsReqParams.SubscriptionDetails = append(p.SubsReqParams.SubscriptionDetails, subscriptionDetail)
955 func (p *RESTSubsReqParams) SetMeid(MEID string) {
956 p.SubsReqParams.Meid = &MEID
959 func (p *RESTSubsReqParams) SetEndpoint(HTTP_port int64, RMR_port int64, host string) {
960 var endpoint clientmodel.SubscriptionParamsClientEndpoint
961 endpoint.HTTPPort = &HTTP_port
962 endpoint.RMRPort = &RMR_port
964 p.SubsReqParams.ClientEndpoint = &endpoint
967 func (p *RESTSubsReqParams) SetEndpointHost(host string) {
969 if p.SubsReqParams.ClientEndpoint.Host != "" {
970 if p.SubsReqParams.ClientEndpoint.Host != host {
971 // Renaming toto, print something tc.Debug("Posting REST subscription request to Submgr")
972 err := fmt.Errorf("hostname change attempt: %s -> %s", p.SubsReqParams.ClientEndpoint.Host, host)
976 p.SubsReqParams.ClientEndpoint.Host = host
979 func (p *RESTSubsReqParams) SetHTTPEndpoint(HTTP_port int64, host string) {
981 p.SubsReqParams.ClientEndpoint.HTTPPort = &HTTP_port
983 p.SetEndpointHost(host)
985 if p.SubsReqParams.ClientEndpoint.RMRPort == nil {
987 p.SubsReqParams.ClientEndpoint.RMRPort = &RMR_port
991 func (p *RESTSubsReqParams) SetE2SubscriptionDirectives(E2RetryCount int64, E2TimeoutTimerValue int64, RMRRoutingNeeded bool) {
993 E2SubscriptionDirectives := &clientmodel.SubscriptionParamsE2SubscriptionDirectives{}
994 p.SubsReqParams.E2SubscriptionDirectives = E2SubscriptionDirectives
995 p.SubsReqParams.E2SubscriptionDirectives.E2RetryCount = &E2RetryCount
996 p.SubsReqParams.E2SubscriptionDirectives.E2TimeoutTimerValue = E2TimeoutTimerValue
997 p.SubsReqParams.E2SubscriptionDirectives.RMRRoutingNeeded = RMRRoutingNeeded
1000 func (p *RESTSubsReqParams) RemoveE2SubscriptionDirectives() {
1002 p.SubsReqParams.E2SubscriptionDirectives = nil
1005 func (p *RESTSubsReqParams) SetSubActionTypes(actionType string) {
1007 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1008 for _, action := range subDetail.ActionToBeSetupList {
1010 action.ActionType = &actionType
1016 func (p *RESTSubsReqParams) SetSubActionIDs(actionId int64) {
1018 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1019 for _, action := range subDetail.ActionToBeSetupList {
1021 action.ActionID = &actionId
1027 func (p *RESTSubsReqParams) SetSubActionDefinition(actionDefinition []int64) {
1029 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1030 for _, action := range subDetail.ActionToBeSetupList {
1032 action.ActionDefinition = actionDefinition
1038 func (p *RESTSubsReqParams) SetSubEventTriggerDefinition(eventTriggerDefinition []int64) {
1040 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1041 if subDetail != nil {
1042 subDetail.EventTriggers = eventTriggerDefinition
1047 func (p *RESTSubsReqParams) AppendActionToActionToBeSetupList(actionId int64, actionType string, actionDefinition []int64, subsequentActionType string, timeToWait string) {
1049 actionToBeSetup := &clientmodel.ActionToBeSetup{
1050 ActionID: &actionId,
1051 ActionType: &actionType,
1052 ActionDefinition: clientmodel.ActionDefinition(actionDefinition),
1053 SubsequentAction: &clientmodel.SubsequentAction{
1054 SubsequentActionType: &subsequentActionType,
1055 TimeToWait: &timeToWait,
1059 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1060 if subDetail != nil {
1061 subDetail.ActionToBeSetupList = append(subDetail.ActionToBeSetupList, actionToBeSetup)
1066 func (p *RESTSubsReqParams) SetRMREndpoint(RMR_port int64, host string) {
1068 p.SubsReqParams.ClientEndpoint.RMRPort = &RMR_port
1070 p.SetEndpointHost(host)
1072 if p.SubsReqParams.ClientEndpoint.HTTPPort == nil {
1074 p.SubsReqParams.ClientEndpoint.HTTPPort = &HTTP_port
1078 func (p *RESTSubsReqParams) SetTimeToWait(timeToWait string) {
1080 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1081 for _, action := range subDetail.ActionToBeSetupList {
1082 if action != nil && action.SubsequentAction != nil {
1083 action.SubsequentAction.TimeToWait = &timeToWait
1089 func (p *RESTSubsReqParams) SetSubscriptionID(SubscriptionID *string) {
1091 if *SubscriptionID == "" {
1094 p.SubsReqParams.SubscriptionID = *SubscriptionID
1097 func (p *RESTSubsReqParams) SetXappEventInstanceID(xappEventInstanceId int64) {
1099 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1100 if subDetail != nil {
1101 subDetail.XappEventInstanceID = &xappEventInstanceId
1106 //-----------------------------------------------------------------------------
1108 //-----------------------------------------------------------------------------
1109 func (tc *E2Stub) SendRESTSubsDelReq(t *testing.T, subscriptionID *string) {
1111 tc.Debug("======== Posting REST DELETE subscription(s) to Submgr ======")
1113 if *subscriptionID == "" {
1114 tc.Error("REST error in deleting subscriptions. Empty SubscriptionID = %s", *subscriptionID)
1116 tc.Debug("REST deleting E2 subscriptions. SubscriptionID = %s", *subscriptionID)
1118 err := xapp.Subscription.Unsubscribe(*subscriptionID)
1120 tc.Error("REST Delete subscription failed %s", err.Error())
1122 tc.Debug("REST delete subscription pushed to submgr successfully. SubscriptionID = %s", *subscriptionID)
1125 //-----------------------------------------------------------------------------
1127 //-----------------------------------------------------------------------------
1128 func (tc *E2Stub) GetRESTSubsReqPolicyParams(subReqCount int) *RESTSubsReqParams {
1130 policyParams := RESTSubsReqParams{}
1131 policyParams.GetRESTSubsReqPolicyParams(subReqCount, &tc.clientEndpoint, &tc.meid)
1132 tc.requestCount = subReqCount
1133 return &policyParams
1136 //-----------------------------------------------------------------------------
1138 //-----------------------------------------------------------------------------
1139 func (tc *E2Stub) DecrementRequestCount() {
1140 if tc.requestCount > 0 {
1141 tc.requestCount -= 1
1143 tc.Error("FAILED to decrement request count, count already ZERO")
1147 //-----------------------------------------------------------------------------
1149 //-----------------------------------------------------------------------------
1150 func (p *RESTSubsReqParams) GetRESTSubsReqPolicyParams(subReqCount int, clientEndpoint *clientmodel.SubscriptionParamsClientEndpoint, meid *string) {
1152 p.SubsReqParams.ClientEndpoint = clientEndpoint
1153 p.SubsReqParams.Meid = meid
1154 var rANFunctionID int64 = 33
1155 p.SubsReqParams.RANFunctionID = &rANFunctionID
1156 actionId := int64(1)
1157 actionType := "policy"
1158 subsequestActioType := "continue"
1159 timeToWait := "w10ms"
1161 for requestCount := 0; requestCount < subReqCount; requestCount++ {
1162 reqId := int64(requestCount) + 1
1163 subscriptionDetail := &clientmodel.SubscriptionDetail{
1164 XappEventInstanceID: &reqId,
1165 EventTriggers: clientmodel.EventTriggerDefinition{
1166 int64(1234 + requestCount),
1168 ActionToBeSetupList: clientmodel.ActionsToBeSetup{
1169 &clientmodel.ActionToBeSetup{
1170 ActionID: &actionId,
1171 ActionType: &actionType,
1172 ActionDefinition: clientmodel.ActionDefinition{
1173 int64(5678 + requestCount),
1175 SubsequentAction: &clientmodel.SubsequentAction{
1176 SubsequentActionType: &subsequestActioType,
1177 TimeToWait: &timeToWait,
1182 p.SubsReqParams.SubscriptionDetails = append(p.SubsReqParams.SubscriptionDetails, subscriptionDetail)
1186 func (p *RESTSubsReqParams) SetSubscriptionDirectives(e2Timeout int64, e2RetryCount int64, routingNeeded bool) {
1188 e2SubscriptionDirectives := &clientmodel.SubscriptionParamsE2SubscriptionDirectives{}
1189 e2SubscriptionDirectives.E2TimeoutTimerValue = e2Timeout
1190 e2SubscriptionDirectives.E2RetryCount = &e2RetryCount
1191 e2SubscriptionDirectives.RMRRoutingNeeded = routingNeeded
1192 p.SubsReqParams.E2SubscriptionDirectives = e2SubscriptionDirectives