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 ==================================================================================
28 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
29 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap_wrapper"
30 "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub"
31 clientmodel "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientmodel"
32 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
38 var e2asnpacker e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
43 type RmrTransactionId struct {
48 type E2RestIds struct {
54 func (trans *RmrTransactionId) String() string {
56 if trans.meid != nil {
57 meidstr = trans.meid.String()
59 return "trans(" + trans.xid + "/" + meidstr + ")"
63 teststub.RmrStubControl
67 CallBackNotification chan int64
68 RESTNotification chan uint32
69 CallBackListedNotifications chan E2RestIds
70 ListedRESTNotifications chan E2RestIds
71 clientEndpoint clientmodel.SubscriptionParamsClientEndpoint
73 restSubsIdList []string
76 //-----------------------------------------------------------------------------
78 //-----------------------------------------------------------------------------
79 func CreateNewE2Stub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int, ranName string, host string, RMRPort int64, HTTPPort int64) *E2Stub {
81 tc.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed)
84 tc.CallBackNotification = make(chan int64)
85 tc.RESTNotification = make(chan uint32)
86 tc.CallBackListedNotifications = make(chan E2RestIds)
87 tc.ListedRESTNotifications = make(chan E2RestIds, 2)
88 var endPoint clientmodel.SubscriptionParamsClientEndpoint
90 endPoint.HTTPPort = &HTTPPort
91 endPoint.RMRPort = &RMRPort
92 tc.clientEndpoint = endPoint
97 //-----------------------------------------------------------------------------
99 //-----------------------------------------------------------------------------
100 func CreateNewE2termStub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int) *E2Stub {
102 tc.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed)
104 tc.SetCheckXid(false)
108 //-----------------------------------------------------------------------------
110 //-----------------------------------------------------------------------------
111 func (tc *E2Stub) NewRmrTransactionId(xid string, ranname string) *RmrTransactionId {
112 trans := &RmrTransactionId{}
114 trans.xid = tc.GetDesc() + "_XID_" + strconv.FormatUint(uint64(tc.xid_seq), 10)
119 trans.meid = &xapp.RMRMeid{RanName: ranname}
120 tc.Info("New test %s", trans.String())
124 //-----------------------------------------------------------------------------
126 //-----------------------------------------------------------------------------
127 type E2StubSubsReqParams struct {
128 Req *e2ap.E2APSubscriptionRequest
131 func (p *E2StubSubsReqParams) Init() {
132 p.Req = &e2ap.E2APSubscriptionRequest{}
134 p.Req.RequestId.Id = 1
135 p.Req.RequestId.InstanceId = 0
138 // gnb -> enb outgoing
139 // enb -> gnb incoming
141 p.Req.EventTriggerDefinition.Data.Length = 1
142 p.Req.EventTriggerDefinition.Data.Data = make([]uint8, p.Req.EventTriggerDefinition.Data.Length)
143 p.Req.EventTriggerDefinition.Data.Data[0] = 1
145 p.Req.ActionSetups = make([]e2ap.ActionToBeSetupItem, 1)
147 p.Req.ActionSetups[0].ActionId = 0
148 p.Req.ActionSetups[0].ActionType = e2ap.E2AP_ActionTypeReport
149 p.Req.ActionSetups[0].RicActionDefinitionPresent = true
151 p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Length = 1
152 p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Data = make([]uint8, p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Length)
153 p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Data[0] = 1
155 p.Req.ActionSetups[0].SubsequentAction.Present = true
156 p.Req.ActionSetups[0].SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeContinue
157 p.Req.ActionSetups[0].SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitZero
160 //-----------------------------------------------------------------------------
162 //-----------------------------------------------------------------------------
164 type E2StubSubsFailParams struct {
165 Req *e2ap.E2APSubscriptionRequest
166 Fail *e2ap.E2APSubscriptionFailure
169 func (p *E2StubSubsFailParams) Set(req *e2ap.E2APSubscriptionRequest) {
172 p.Fail = &e2ap.E2APSubscriptionFailure{}
173 p.Fail.RequestId.Id = p.Req.RequestId.Id
174 p.Fail.RequestId.InstanceId = p.Req.RequestId.InstanceId
175 p.Fail.FunctionId = p.Req.FunctionId
176 p.Fail.ActionNotAdmittedList.Items = make([]e2ap.ActionNotAdmittedItem, len(p.Req.ActionSetups))
177 for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ {
178 p.Fail.ActionNotAdmittedList.Items[index].ActionId = p.Req.ActionSetups[index].ActionId
179 p.SetCauseVal(index, 5, 1)
183 func (p *E2StubSubsFailParams) SetCauseVal(ind int, content uint8, causeval uint8) {
186 for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ {
187 p.Fail.ActionNotAdmittedList.Items[index].Cause.Content = content
188 p.Fail.ActionNotAdmittedList.Items[index].Cause.Value = causeval
192 p.Fail.ActionNotAdmittedList.Items[ind].Cause.Content = content
193 p.Fail.ActionNotAdmittedList.Items[ind].Cause.Value = causeval
196 //-----------------------------------------------------------------------------
198 //-----------------------------------------------------------------------------
200 func (tc *E2Stub) SendSubsReq(t *testing.T, rparams *E2StubSubsReqParams, oldTrans *RmrTransactionId) *RmrTransactionId {
204 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
207 tc.Info("SendSubsReq %s", trans.String())
208 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
210 //---------------------------------
211 // xapp activity: Send Subs Req
212 //---------------------------------
216 myparams = &E2StubSubsReqParams{}
220 err, packedMsg := e2SubsReq.Pack(myparams.Req)
222 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
225 tc.Debug("%s %s", trans.String(), e2SubsReq.String())
227 params := &xapp.RMRParams{}
228 params.Mtype = xapp.RIC_SUB_REQ
230 params.Payload = packedMsg.Buf
231 params.PayloadLen = len(packedMsg.Buf)
232 params.Meid = trans.meid
233 params.Xid = trans.xid
236 tc.Info("SEND SUB REQ: %s", params.String())
237 snderr := tc.SendWithRetry(params, false, 5)
239 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
245 //-----------------------------------------------------------------------------
247 //-----------------------------------------------------------------------------
248 func (tc *E2Stub) RecvSubsReq(t *testing.T) (*e2ap.E2APSubscriptionRequest, *xapp.RMRParams) {
249 tc.Info("RecvSubsReq")
250 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
252 //---------------------------------
253 // e2term activity: Recv Subs Req
254 //---------------------------------
255 msg := tc.WaitMsg(15)
257 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] {
258 tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_REQ", xapp.RicMessageTypeToName[msg.Mtype])
260 tc.Info("Recv Subs Req")
261 packedData := &e2ap.PackedData{}
262 packedData.Buf = msg.Payload
263 unpackerr, req := e2SubsReq.UnPack(packedData)
264 if unpackerr != nil {
265 tc.TestError(t, "RIC_SUB_REQ unpack failed err: %s", unpackerr.Error())
270 tc.TestError(t, "Not Received msg within %d secs", 15)
276 //-----------------------------------------------------------------------------
278 //-----------------------------------------------------------------------------
279 func (tc *E2Stub) SendSubsResp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *xapp.RMRParams) {
280 tc.Info("SendSubsResp")
281 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
283 //---------------------------------
284 // e2term activity: Send Subs Resp
285 //---------------------------------
286 resp := &e2ap.E2APSubscriptionResponse{}
288 resp.RequestId.Id = req.RequestId.Id
289 resp.RequestId.InstanceId = req.RequestId.InstanceId
290 resp.FunctionId = req.FunctionId
292 resp.ActionAdmittedList.Items = make([]e2ap.ActionAdmittedItem, len(req.ActionSetups))
293 for index := int(0); index < len(req.ActionSetups); index++ {
294 resp.ActionAdmittedList.Items[index].ActionId = req.ActionSetups[index].ActionId
297 for index := uint64(0); index < 1; index++ {
298 item := e2ap.ActionNotAdmittedItem{}
299 item.ActionId = index
300 item.Cause.Content = 1
302 resp.ActionNotAdmittedList.Items = append(resp.ActionNotAdmittedList.Items, item)
305 packerr, packedMsg := e2SubsResp.Pack(resp)
307 tc.TestError(t, "pack NOK %s", packerr.Error())
309 tc.Debug("%s", e2SubsResp.String())
311 params := &xapp.RMRParams{}
312 params.Mtype = xapp.RIC_SUB_RESP
313 //params.SubId = msg.SubId
315 params.Payload = packedMsg.Buf
316 params.PayloadLen = len(packedMsg.Buf)
317 params.Meid = msg.Meid
318 //params.Xid = msg.Xid
321 tc.Info("SEND SUB RESP: %s", params.String())
322 snderr := tc.SendWithRetry(params, false, 5)
324 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
328 //-----------------------------------------------------------------------------
330 //-----------------------------------------------------------------------------
331 func (tc *E2Stub) SendInvalidE2Asn1Resp(t *testing.T, msg *xapp.RMRParams, msgType int) {
333 params := &xapp.RMRParams{}
334 params.Mtype = msgType
336 params.Payload = []byte{1, 2, 3, 4, 5}
337 params.PayloadLen = 5
338 params.Meid = msg.Meid
342 if params.Mtype == xapp.RIC_SUB_RESP {
343 tc.Info("SEND INVALID ASN.1 SUB RESP")
345 } else if params.Mtype == xapp.RIC_SUB_FAILURE {
346 tc.Info("SEND INVALID ASN.1 SUB FAILURE")
348 } else if params.Mtype == xapp.RIC_SUB_DEL_RESP {
349 tc.Info("SEND INVALID ASN.1 SUB DEL RESP")
351 } else if params.Mtype == xapp.RIC_SUB_DEL_FAILURE {
352 tc.Info("SEND INVALID ASN.1 SUB DEL FAILURE")
354 snderr := tc.SendWithRetry(params, false, 5)
356 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
360 //-----------------------------------------------------------------------------
362 //-----------------------------------------------------------------------------
363 func (tc *E2Stub) RecvSubsResp(t *testing.T, trans *RmrTransactionId) uint32 {
364 tc.Info("RecvSubsResp")
365 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
368 //---------------------------------
369 // xapp activity: Recv Subs Resp
370 //---------------------------------
371 msg := tc.WaitMsg(15)
373 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
374 tc.TestError(t, "Received RIC_SUB_RESP wrong mtype expected %s got %s, error", "RIC_SUB_RESP", xapp.RicMessageTypeToName[msg.Mtype])
376 } else if msg.Xid != trans.xid {
377 tc.TestError(t, "Received RIC_SUB_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
380 packedData := &e2ap.PackedData{}
381 packedData.Buf = msg.Payload
383 e2SubsId = uint32(msg.SubId)
387 unpackerr, resp := e2SubsResp.UnPack(packedData)
388 if unpackerr != nil {
389 tc.TestError(t, "RIC_SUB_RESP unpack failed err: %s", unpackerr.Error())
391 tc.Info("Recv Subs Resp rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
395 tc.TestError(t, "Not Received msg within %d secs", 15)
400 //-----------------------------------------------------------------------------
402 //-----------------------------------------------------------------------------
404 func (tc *E2Stub) SendSubsFail(t *testing.T, fparams *E2StubSubsFailParams, msg *xapp.RMRParams) {
405 tc.Info("SendSubsFail")
406 e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
408 //---------------------------------
409 // e2term activity: Send Subs Fail
410 //---------------------------------
411 packerr, packedMsg := e2SubsFail.Pack(fparams.Fail)
413 tc.TestError(t, "pack NOK %s", packerr.Error())
415 tc.Debug("%s", e2SubsFail.String())
417 params := &xapp.RMRParams{}
418 params.Mtype = xapp.RIC_SUB_FAILURE
419 params.SubId = msg.SubId
420 params.Payload = packedMsg.Buf
421 params.PayloadLen = len(packedMsg.Buf)
422 params.Meid = msg.Meid
426 tc.Info("SEND SUB FAIL: %s", params.String())
427 snderr := tc.SendWithRetry(params, false, 5)
429 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
433 //-----------------------------------------------------------------------------
435 //-----------------------------------------------------------------------------
436 func (tc *E2Stub) RecvSubsFail(t *testing.T, trans *RmrTransactionId) uint32 {
437 tc.Info("RecvSubsFail")
438 e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
441 //-------------------------------
442 // xapp activity: Recv Subs Fail
443 //-------------------------------
444 msg := tc.WaitMsg(15)
446 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_FAILURE"] {
447 tc.TestError(t, "Received RIC_SUB_FAILURE wrong mtype expected %s got %s, error", "RIC_SUB_FAILURE", xapp.RicMessageTypeToName[msg.Mtype])
449 } else if msg.Xid != trans.xid {
450 tc.TestError(t, "Received RIC_SUB_FAILURE wrong xid expected %s got %s, error", trans.xid, msg.Xid)
453 packedData := &e2ap.PackedData{}
454 packedData.Buf = msg.Payload
456 e2SubsId = uint32(msg.SubId)
460 unpackerr, resp := e2SubsFail.UnPack(packedData)
461 if unpackerr != nil {
462 tc.TestError(t, "RIC_SUB_FAILURE unpack failed err: %s", unpackerr.Error())
464 tc.Info("Recv Subs Fail rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
468 tc.TestError(t, "Not Received msg within %d secs", 15)
473 //-----------------------------------------------------------------------------
475 //-----------------------------------------------------------------------------
476 func (tc *E2Stub) SendSubsDelReq(t *testing.T, oldTrans *RmrTransactionId, e2SubsId uint32) *RmrTransactionId {
480 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
483 tc.Info("SendSubsDelReq %s", trans.String())
484 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
485 //---------------------------------
486 // xapp activity: Send Subs Del Req
487 //---------------------------------
488 req := &e2ap.E2APSubscriptionDeleteRequest{}
490 req.RequestId.InstanceId = e2SubsId
493 err, packedMsg := e2SubsDelReq.Pack(req)
495 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
498 tc.Debug("%s %s", trans.String(), e2SubsDelReq.String())
500 params := &xapp.RMRParams{}
501 params.Mtype = xapp.RIC_SUB_DEL_REQ
502 params.SubId = int(e2SubsId)
503 params.Payload = packedMsg.Buf
504 params.PayloadLen = len(packedMsg.Buf)
505 params.Meid = trans.meid
506 params.Xid = trans.xid
509 tc.Info("SEND SUB DEL REQ: %s", params.String())
510 snderr := tc.SendWithRetry(params, false, 5)
512 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
518 //-----------------------------------------------------------------------------
520 //-----------------------------------------------------------------------------
521 func (tc *E2Stub) RecvSubsDelReq(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *xapp.RMRParams) {
522 tc.Info("RecvSubsDelReq")
523 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
525 //---------------------------------
526 // e2term activity: Recv Subs Del Req
527 //---------------------------------
528 msg := tc.WaitMsg(15)
530 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] {
531 tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_DEL_REQ", xapp.RicMessageTypeToName[msg.Mtype])
533 tc.Info("Recv Subs Del Req")
535 packedData := &e2ap.PackedData{}
536 packedData.Buf = msg.Payload
537 unpackerr, req := e2SubsDelReq.UnPack(packedData)
538 if unpackerr != nil {
539 tc.TestError(t, "RIC_SUB_DEL_REQ unpack failed err: %s", unpackerr.Error())
544 tc.TestError(t, "Not Received msg within %d secs", 15)
549 //-----------------------------------------------------------------------------
551 //-----------------------------------------------------------------------------
552 func (tc *E2Stub) SendSubsDelResp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapp.RMRParams) {
553 tc.Info("SendSubsDelResp")
554 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
556 //---------------------------------
557 // e2term activity: Send Subs Del Resp
558 //---------------------------------
559 resp := &e2ap.E2APSubscriptionDeleteResponse{}
560 resp.RequestId.Id = req.RequestId.Id
561 resp.RequestId.InstanceId = req.RequestId.InstanceId
562 resp.FunctionId = req.FunctionId
564 packerr, packedMsg := e2SubsDelResp.Pack(resp)
566 tc.TestError(t, "pack NOK %s", packerr.Error())
568 tc.Debug("%s", e2SubsDelResp.String())
570 params := &xapp.RMRParams{}
571 params.Mtype = xapp.RIC_SUB_DEL_RESP
572 params.SubId = msg.SubId
573 params.Payload = packedMsg.Buf
574 params.PayloadLen = len(packedMsg.Buf)
575 params.Meid = msg.Meid
579 tc.Info("SEND SUB DEL RESP: %s", params.String())
580 snderr := tc.SendWithRetry(params, false, 5)
582 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
586 //-----------------------------------------------------------------------------
588 //-----------------------------------------------------------------------------
589 func (tc *E2Stub) RecvSubsDelResp(t *testing.T, trans *RmrTransactionId) {
590 tc.Info("RecvSubsDelResp")
591 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
593 //---------------------------------
594 // xapp activity: Recv Subs Del Resp
595 //---------------------------------
596 msg := tc.WaitMsg(15)
598 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
599 tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong mtype expected %s got %s, error", "RIC_SUB_DEL_RESP", xapp.RicMessageTypeToName[msg.Mtype])
601 } else if trans != nil && msg.Xid != trans.xid {
602 tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
605 packedData := &e2ap.PackedData{}
606 packedData.Buf = msg.Payload
607 unpackerr, resp := e2SubsDelResp.UnPack(packedData)
608 if unpackerr != nil {
609 tc.TestError(t, "RIC_SUB_DEL_RESP unpack failed err: %s", unpackerr.Error())
611 tc.Info("Recv Subs Del Resp rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
615 tc.TestError(t, "Not Received msg within %d secs", 15)
619 //-----------------------------------------------------------------------------
621 //-----------------------------------------------------------------------------
622 func (tc *E2Stub) SendSubsDelFail(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapp.RMRParams) {
623 tc.Info("SendSubsDelFail")
624 e2SubsDelFail := e2asnpacker.NewPackerSubscriptionDeleteFailure()
626 //---------------------------------
627 // e2term activity: Send Subs Del Fail
628 //---------------------------------
629 resp := &e2ap.E2APSubscriptionDeleteFailure{}
630 resp.RequestId.Id = req.RequestId.Id
631 resp.RequestId.InstanceId = req.RequestId.InstanceId
632 resp.FunctionId = req.FunctionId
633 resp.Cause.Content = 5 // CauseMisc
634 resp.Cause.Value = 3 // unspecified
636 packerr, packedMsg := e2SubsDelFail.Pack(resp)
638 tc.TestError(t, "pack NOK %s", packerr.Error())
640 tc.Debug("%s", e2SubsDelFail.String())
642 params := &xapp.RMRParams{}
643 params.Mtype = xapp.RIC_SUB_DEL_FAILURE
644 params.SubId = msg.SubId
645 params.Payload = packedMsg.Buf
646 params.PayloadLen = len(packedMsg.Buf)
647 params.Meid = msg.Meid
651 tc.Info("SEND SUB DEL FAIL: %s", params.String())
652 snderr := tc.SendWithRetry(params, false, 5)
654 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
658 // REST code below all
660 /*****************************************************************************/
661 // REST interface specific functions are below
663 //-----------------------------------------------------------------------------
664 // Callback handler for subscription response notifications
665 //-----------------------------------------------------------------------------
666 func (tc *E2Stub) SubscriptionRespHandler(resp *clientmodel.SubscriptionResponse) {
667 if tc.subscriptionId == "SUBSCRIPTIONID NOT SET" {
668 tc.Info("REST notification received for %v while no SubscriptionID was not set for E2EventInstanceID=%v, XappEventInstanceID=%v (%v)",
669 *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
670 tc.CallBackNotification <- *resp.SubscriptionInstances[0].E2EventInstanceID
671 } else if tc.subscriptionId == *resp.SubscriptionID {
672 tc.Info("REST notification received SubscriptionID=%s, E2EventInstanceID=%v, RequestorID=%v (%v)",
673 *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
674 tc.CallBackNotification <- *resp.SubscriptionInstances[0].E2EventInstanceID
676 tc.Info("MISMATCHING REST notification received SubscriptionID=%s<>%s, E2EventInstanceID=%v, XappEventInstanceID=%v (%v)",
677 tc.subscriptionId, *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
681 //-----------------------------------------------------------------------------
683 //-----------------------------------------------------------------------------
685 func (tc *E2Stub) ExpectRESTNotification(t *testing.T, restSubsId string) {
686 tc.expectNotification(t, restSubsId, "")
689 func (tc *E2Stub) ExpectRESTNotificationOk(t *testing.T, restSubsId string) {
690 tc.expectNotification(t, restSubsId, "allOk")
693 func (tc *E2Stub) ExpectRESTNotificationNok(t *testing.T, restSubsId string, expectError string) {
694 tc.expectNotification(t, restSubsId, expectError)
697 func (tc *E2Stub) expectNotification(t *testing.T, restSubsId string, expectError string) {
699 tc.Info("### 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)
700 tc.restSubsIdList = []string{restSubsId}
701 xapp.Subscription.SetResponseCB(tc.ListedRestNotifHandler)
702 if tc.requestCount == 0 {
703 tc.TestError(t, "### NO REST notifications SET received for endpoint=%s, request zount ZERO! (%v)", tc.clientEndpoint, tc)
707 case e2Ids := <-tc.CallBackListedNotifications:
708 if tc.requestCount == 0 {
709 tc.TestError(t, "### REST notification count unexpectedly ZERO for %s (%v)", restSubsId, tc)
710 } else if e2Ids.RestSubsId != restSubsId {
711 tc.TestError(t, "### Unexpected REST notifications received |%s:%s| (%v)", e2Ids.RestSubsId, restSubsId, tc)
712 } else if e2Ids.ErrorCause == "" && expectError == "allFail" {
713 tc.TestError(t, "### Unexpected ok cause received from REST notifications |%s:%s| (%v)", e2Ids.RestSubsId, restSubsId, tc)
714 } else if e2Ids.ErrorCause != "" && expectError == "allOk" {
715 tc.TestError(t, "### Unexpected error cause (%s) received from REST notifications |%s:%s| (%v)", e2Ids.ErrorCause, e2Ids.RestSubsId, restSubsId, tc)
718 if tc.requestCount == 0 {
719 tc.Info("### All expected REST notifications received for %s (%v)", e2Ids.RestSubsId, tc)
721 tc.Info("### Expected REST notifications received for %s, (%v)", e2Ids.RestSubsId, tc)
723 if e2Ids.ErrorCause != "" && expectError == "allFail" {
724 tc.Info("### REST Notification: %s, ErrorCause: %v", e2Ids.RestSubsId, e2Ids.ErrorCause)
726 tc.Info("### REST Notification received Notif for %s : %v", e2Ids.RestSubsId, e2Ids.E2SubsId)
727 tc.ListedRESTNotifications <- e2Ids
729 case <-time.After(15 * time.Second):
730 err := fmt.Errorf("### Timeout 15s expired while expecting REST notification for subsId: %v", restSubsId)
731 tc.TestError(t, "%s", err.Error())
736 func (tc *E2Stub) WaitRESTNotification(t *testing.T, restSubsId string) uint32 {
738 case e2SubsId := <-tc.ListedRESTNotifications:
739 if e2SubsId.RestSubsId == restSubsId {
740 tc.Info("### Expected REST notifications received %s, e2SubsId %v for endpoint=%s, (%v)", e2SubsId.RestSubsId, e2SubsId.E2SubsId, tc.clientEndpoint, tc)
741 return e2SubsId.E2SubsId
743 tc.TestError(t, "### Unexpected REST notifications received %s, expected %s for endpoint=%s, (%v)", e2SubsId.RestSubsId, restSubsId, tc.clientEndpoint, tc)
746 case <-time.After(15 * time.Second):
747 err := fmt.Errorf("### Timeout 15s expired while waiting REST notification for subsId: %v", restSubsId)
748 tc.TestError(t, "%s", err.Error())
749 panic("WaitRESTNotification - timeout error")
754 func (tc *E2Stub) WaitRESTNotificationForAnySubscriptionId(t *testing.T) {
756 tc.Info("### REST notifications received for endpoint=%s, (%v)", tc.clientEndpoint, tc)
758 case e2SubsId := <-tc.CallBackNotification:
759 tc.Info("### REST notifications received e2SubsId %v for endpoint=%s, (%v)", e2SubsId, tc.clientEndpoint, tc)
760 tc.RESTNotification <- (uint32)(e2SubsId)
761 case <-time.After(15 * time.Second):
762 err := fmt.Errorf("### Timeout 15s expired while waiting REST notification")
763 tc.TestError(t, "%s", err.Error())
764 tc.RESTNotification <- 0
769 func (tc *E2Stub) ListedRestNotifHandler(resp *clientmodel.SubscriptionResponse) {
771 if len(tc.restSubsIdList) == 0 {
772 tc.Error("Unexpected listed REST notifications received for endpoint=%s, expected restSubsId list size was ZERO!", tc.clientEndpoint)
774 for i, subsId := range tc.restSubsIdList {
775 if *resp.SubscriptionID == subsId {
776 //tc.Info("Listed REST notifications received SubscriptionID=%s, InstanceID=%v, XappEventInstanceID=%v",
777 // *resp.SubscriptionID, *resp.SubscriptionInstances[0].InstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID)
779 tc.restSubsIdList = append(tc.restSubsIdList[:i], tc.restSubsIdList[i+1:]...)
780 //tc.Info("Removed %s from Listed REST notifications, %v entries left", *resp.SubscriptionID, len(tc.restSubsIdList))
782 if resp.SubscriptionInstances[0].ErrorCause != nil {
783 tc.CallBackListedNotifications <- E2RestIds{*resp.SubscriptionID, uint32(*resp.SubscriptionInstances[0].E2EventInstanceID), *resp.SubscriptionInstances[0].ErrorCause}
785 tc.CallBackListedNotifications <- E2RestIds{*resp.SubscriptionID, uint32(*resp.SubscriptionInstances[0].E2EventInstanceID), ""}
788 if len(tc.restSubsIdList) == 0 {
789 //tc.Info("All listed REST notifications received for endpoint=%s", tc.clientEndpoint)
795 tc.Error("UNKONWN REST notification received SubscriptionID=%s<>%s, InstanceID=%v, XappEventInstanceID=%v (%v)",
796 tc.subscriptionId, *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
800 //-----------------------------------------------------------------------------
802 //-----------------------------------------------------------------------------
803 func (tc *E2Stub) WaitListedRestNotifications(t *testing.T, restSubsIds []string) {
804 tc.Info("Started to wait REST notifications %v on port %v f(RMR port %v)", restSubsIds, *tc.clientEndpoint.HTTPPort, *tc.clientEndpoint.RMRPort)
806 tc.restSubsIdList = restSubsIds
807 xapp.Subscription.SetResponseCB(tc.ListedRestNotifHandler)
809 for i := 0; i < len(restSubsIds); i++ {
812 case e2Ids := <-tc.CallBackListedNotifications:
813 tc.Info("Listed Notification waiter received Notif for %s : %v", e2Ids.RestSubsId, e2Ids.E2SubsId)
814 tc.ListedRESTNotifications <- e2Ids
815 case <-time.After(15 * time.Second):
816 err := fmt.Errorf("Timeout 15s expired while waiting Listed REST notification")
817 tc.TestError(t, "%s", err.Error())
818 tc.RESTNotification <- 0
824 //-----------------------------------------------------------------------------
826 //-----------------------------------------------------------------------------
827 func (tc *E2Stub) SendRESTSubsReq(t *testing.T, params *RESTSubsReqParams) string { // This need to be edited according to new specification
828 tc.Info("======== Posting REST Report subscriptions to Submgr ======")
831 tc.Info("SendRESTReportSubsReq: params == nil")
835 tc.subscriptionId = "SUBSCIPTIONID NOT SET"
837 resp, err := xapp.Subscription.Subscribe(¶ms.SubsReqParams)
839 // Swagger generated code makes checks for the values that are inserted the subscription function
840 // If error cause is unknown and POST is not done, the problem is in the inserted values
841 tc.Error("======== REST report subscriptions failed %s ========", err.Error())
844 tc.subscriptionId = *resp.SubscriptionID
845 tc.Info("======== REST report subscriptions posted successfully. SubscriptionID = %s, RequestCount = %v ========", *resp.SubscriptionID, tc.requestCount)
846 return *resp.SubscriptionID
849 //-----------------------------------------------------------------------------
851 //-----------------------------------------------------------------------------
852 func (tc *E2Stub) GetRESTSubsReqReportParams(subReqCount int) *RESTSubsReqParams {
854 reportParams := RESTSubsReqParams{}
855 reportParams.GetRESTSubsReqReportParams(subReqCount, &tc.clientEndpoint, &tc.meid)
856 tc.requestCount = subReqCount
860 //-----------------------------------------------------------------------------
862 //-----------------------------------------------------------------------------
863 type RESTSubsReqParams struct {
864 SubsReqParams clientmodel.SubscriptionParams
867 func (p *RESTSubsReqParams) GetRESTSubsReqReportParams(subReqCount int, clientEndpoint *clientmodel.SubscriptionParamsClientEndpoint, meid *string) {
870 p.SubsReqParams.ClientEndpoint = clientEndpoint
871 p.SubsReqParams.Meid = meid
872 var rANFunctionID int64 = 33
873 p.SubsReqParams.RANFunctionID = &rANFunctionID
878 actionType := "report"
879 subsequestActioType := "continue"
880 timeToWait := "w10ms"
882 for requestCount := 0; requestCount < subReqCount; requestCount++ {
883 reqId := int64(requestCount) + 1
884 subscriptionDetail := &clientmodel.SubscriptionDetail{
885 XappEventInstanceID: &reqId,
886 EventTriggers: clientmodel.EventTriggerDefinition{
887 int64(1234 + requestCount),
889 ActionToBeSetupList: clientmodel.ActionsToBeSetup{
890 &clientmodel.ActionToBeSetup{
892 ActionType: &actionType,
893 ActionDefinition: clientmodel.ActionDefinition{
894 int64(5678 + requestCount),
896 SubsequentAction: &clientmodel.SubsequentAction{
897 SubsequentActionType: &subsequestActioType,
898 TimeToWait: &timeToWait,
903 p.SubsReqParams.SubscriptionDetails = append(p.SubsReqParams.SubscriptionDetails, subscriptionDetail)
908 func (p *RESTSubsReqParams) SetMeid(MEID string) {
909 p.SubsReqParams.Meid = &MEID
912 func (p *RESTSubsReqParams) SetEndpoint(HTTP_port int64, RMR_port int64, host string) {
913 var endpoint clientmodel.SubscriptionParamsClientEndpoint
914 endpoint.HTTPPort = &HTTP_port
915 endpoint.RMRPort = &RMR_port
917 p.SubsReqParams.ClientEndpoint = &endpoint
920 func (p *RESTSubsReqParams) SetEndpointHost(host string) {
922 if p.SubsReqParams.ClientEndpoint.Host != "" {
923 if p.SubsReqParams.ClientEndpoint.Host != host {
924 // Renaming toto, print something tc.Info("Posting REST subscription request to Submgr")
925 err := fmt.Errorf("hostname change attempt: %s -> %s", p.SubsReqParams.ClientEndpoint.Host, host)
929 p.SubsReqParams.ClientEndpoint.Host = host
932 func (p *RESTSubsReqParams) SetHTTPEndpoint(HTTP_port int64, host string) {
934 p.SubsReqParams.ClientEndpoint.HTTPPort = &HTTP_port
936 p.SetEndpointHost(host)
938 if p.SubsReqParams.ClientEndpoint.RMRPort == nil {
940 p.SubsReqParams.ClientEndpoint.RMRPort = &RMR_port
944 func (p *RESTSubsReqParams) SetSubActionTypes(actionType string) {
946 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
947 for _, action := range subDetail.ActionToBeSetupList {
949 action.ActionType = &actionType
955 func (p *RESTSubsReqParams) SetSubActionIDs(actionId int64) {
957 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
958 for _, action := range subDetail.ActionToBeSetupList {
960 action.ActionID = &actionId
966 func (p *RESTSubsReqParams) SetSubActionDefinition(actionDefinition []int64) {
968 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
969 for _, action := range subDetail.ActionToBeSetupList {
971 action.ActionDefinition = actionDefinition
977 func (p *RESTSubsReqParams) SetSubEventTriggerDefinition(eventTriggerDefinition []int64) {
979 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
980 if subDetail != nil {
981 subDetail.EventTriggers = eventTriggerDefinition
986 func (p *RESTSubsReqParams) AppendActionToActionToBeSetupList(actionId int64, actionType string, actionDefinition []int64, subsequentActionType string, timeToWait string) {
988 actionToBeSetup := &clientmodel.ActionToBeSetup{
990 ActionType: &actionType,
991 ActionDefinition: clientmodel.ActionDefinition(actionDefinition),
992 SubsequentAction: &clientmodel.SubsequentAction{
993 SubsequentActionType: &subsequentActionType,
994 TimeToWait: &timeToWait,
998 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
999 if subDetail != nil {
1000 subDetail.ActionToBeSetupList = append(subDetail.ActionToBeSetupList, actionToBeSetup)
1005 func (p *RESTSubsReqParams) SetRMREndpoint(RMR_port int64, host string) {
1007 p.SubsReqParams.ClientEndpoint.RMRPort = &RMR_port
1009 p.SetEndpointHost(host)
1011 if p.SubsReqParams.ClientEndpoint.HTTPPort == nil {
1013 p.SubsReqParams.ClientEndpoint.HTTPPort = &HTTP_port
1017 func (p *RESTSubsReqParams) SetTimeToWait(timeToWait string) {
1019 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1020 for _, action := range subDetail.ActionToBeSetupList {
1021 if action != nil && action.SubsequentAction != nil {
1022 action.SubsequentAction.TimeToWait = &timeToWait
1028 func (p *RESTSubsReqParams) SetSubscriptionID(SubscriptionID *string) {
1030 if *SubscriptionID == "" {
1033 p.SubsReqParams.SubscriptionID = *SubscriptionID
1036 //-----------------------------------------------------------------------------
1038 //-----------------------------------------------------------------------------
1039 func (tc *E2Stub) SendRESTSubsDelReq(t *testing.T, subscriptionID *string) {
1041 if *subscriptionID == "" {
1042 tc.Error("REST error in deleting subscriptions. Empty SubscriptionID = %s", *subscriptionID)
1044 tc.Info("REST deleting E2 subscriptions. SubscriptionID = %s", *subscriptionID)
1046 err := xapp.Subscription.Unsubscribe(*subscriptionID)
1048 tc.Error("REST Delete subscription failed %s", err.Error())
1050 tc.Info("REST delete subscription pushed to submgr successfully. SubscriptionID = %s", *subscriptionID)
1053 //-----------------------------------------------------------------------------
1055 //-----------------------------------------------------------------------------
1056 func (tc *E2Stub) GetRESTSubsReqPolicyParams(subReqCount int) *RESTSubsReqParams {
1058 policyParams := RESTSubsReqParams{}
1059 policyParams.GetRESTSubsReqPolicyParams(subReqCount, &tc.clientEndpoint, &tc.meid)
1060 tc.requestCount = subReqCount
1061 return &policyParams
1064 //-----------------------------------------------------------------------------
1066 //-----------------------------------------------------------------------------
1067 func (p *RESTSubsReqParams) GetRESTSubsReqPolicyParams(subReqCount int, clientEndpoint *clientmodel.SubscriptionParamsClientEndpoint, meid *string) {
1069 p.SubsReqParams.ClientEndpoint = clientEndpoint
1070 p.SubsReqParams.Meid = meid
1071 var rANFunctionID int64 = 33
1072 p.SubsReqParams.RANFunctionID = &rANFunctionID
1074 // reqId := int64(1)
1076 actionId := int64(1)
1077 actionType := "policy"
1078 subsequestActioType := "continue"
1079 timeToWait := "w10ms"
1081 for requestCount := 0; requestCount < subReqCount; requestCount++ {
1082 reqId := int64(requestCount) + 1
1083 subscriptionDetail := &clientmodel.SubscriptionDetail{
1084 XappEventInstanceID: &reqId,
1085 EventTriggers: clientmodel.EventTriggerDefinition{
1086 int64(1234 + requestCount),
1088 ActionToBeSetupList: clientmodel.ActionsToBeSetup{
1089 &clientmodel.ActionToBeSetup{
1090 ActionID: &actionId,
1091 ActionType: &actionType,
1092 ActionDefinition: clientmodel.ActionDefinition{
1093 int64(5678 + requestCount),
1095 SubsequentAction: &clientmodel.SubsequentAction{
1096 SubsequentActionType: &subsequestActioType,
1097 TimeToWait: &timeToWait,
1102 p.SubsReqParams.SubscriptionDetails = append(p.SubsReqParams.SubscriptionDetails, subscriptionDetail)