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) {
668 if tc.subscriptionId == "SUBSCRIPTIONID NOT SET" {
669 tc.Info("REST notification received for %v while no SubscriptionID was not set for E2EventInstanceID=%v, XappEventInstanceID=%v (%v)",
670 *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
671 tc.CallBackNotification <- *resp.SubscriptionInstances[0].E2EventInstanceID
672 } else if tc.subscriptionId == *resp.SubscriptionID {
673 tc.Info("REST notification received SubscriptionID=%s, E2EventInstanceID=%v, RequestorID=%v (%v)",
674 *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
675 tc.CallBackNotification <- *resp.SubscriptionInstances[0].E2EventInstanceID
677 tc.Info("MISMATCHING REST notification received SubscriptionID=%s<>%s, E2EventInstanceID=%v, XappEventInstanceID=%v (%v)",
678 tc.subscriptionId, *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
682 //-----------------------------------------------------------------------------
684 //-----------------------------------------------------------------------------
686 func (tc *E2Stub) ExpectRESTNotification(t *testing.T, restSubsId string) {
687 tc.expectNotification(t, restSubsId, "")
690 func (tc *E2Stub) ExpectRESTNotificationOk(t *testing.T, restSubsId string) {
691 tc.expectNotification(t, restSubsId, "allOk")
694 func (tc *E2Stub) ExpectRESTNotificationNok(t *testing.T, restSubsId string, expectError string) {
695 tc.expectNotification(t, restSubsId, expectError)
698 func (tc *E2Stub) expectNotification(t *testing.T, restSubsId string, expectError string) {
700 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)
701 tc.restSubsIdList = []string{restSubsId}
702 xapp.Subscription.SetResponseCB(tc.ListedRestNotifHandler)
703 if tc.requestCount == 0 {
704 tc.TestError(t, "### NO REST notifications SET received for endpoint=%s, request zount ZERO! (%v)", tc.clientEndpoint, tc)
708 case e2Ids := <-tc.CallBackListedNotifications:
709 if tc.requestCount == 0 {
710 tc.TestError(t, "### REST notification count unexpectedly ZERO for %s (%v)", restSubsId, tc)
711 } else if e2Ids.RestSubsId != restSubsId {
712 tc.TestError(t, "### Unexpected REST notifications received |%s:%s| (%v)", e2Ids.RestSubsId, restSubsId, tc)
713 } else if e2Ids.ErrorCause == "" && expectError == "allFail" {
714 tc.TestError(t, "### Unexpected ok cause received from REST notifications |%s:%s| (%v)", e2Ids.RestSubsId, restSubsId, tc)
715 } else if e2Ids.ErrorCause != "" && expectError == "allOk" {
716 tc.TestError(t, "### Unexpected error cause (%s) received from REST notifications |%s:%s| (%v)", e2Ids.ErrorCause, e2Ids.RestSubsId, restSubsId, tc)
719 if tc.requestCount == 0 {
720 tc.Info("### All expected REST notifications received for %s (%v)", e2Ids.RestSubsId, tc)
722 tc.Info("### Expected REST notifications received for %s, (%v)", e2Ids.RestSubsId, tc)
724 if e2Ids.ErrorCause != "" && expectError == "allFail" {
725 tc.Info("### REST Notification: %s, ErrorCause: %v", e2Ids.RestSubsId, e2Ids.ErrorCause)
727 tc.Info("### REST Notification received Notif for %s : %v", e2Ids.RestSubsId, e2Ids.E2SubsId)
728 tc.ListedRESTNotifications <- e2Ids
730 case <-time.After(15 * time.Second):
731 err := fmt.Errorf("### Timeout 15s expired while expecting REST notification for subsId: %v", restSubsId)
732 tc.TestError(t, "%s", err.Error())
737 func (tc *E2Stub) WaitRESTNotification(t *testing.T, restSubsId string) uint32 {
739 case e2SubsId := <-tc.ListedRESTNotifications:
740 if e2SubsId.RestSubsId == restSubsId {
741 tc.Info("### Expected REST notifications received %s, e2SubsId %v for endpoint=%s, (%v)", e2SubsId.RestSubsId, e2SubsId.E2SubsId, tc.clientEndpoint, tc)
742 return e2SubsId.E2SubsId
744 tc.TestError(t, "### Unexpected REST notifications received %s, expected %s for endpoint=%s, (%v)", e2SubsId.RestSubsId, restSubsId, tc.clientEndpoint, tc)
747 case <-time.After(15 * time.Second):
748 err := fmt.Errorf("### Timeout 15s expired while waiting REST notification for subsId: %v", restSubsId)
749 tc.TestError(t, "%s", err.Error())
750 panic("WaitRESTNotification - timeout error")
755 func (tc *E2Stub) WaitRESTNotificationForAnySubscriptionId(t *testing.T) {
757 tc.Info("### REST notifications received for endpoint=%s, (%v)", tc.clientEndpoint, tc)
759 case e2SubsId := <-tc.CallBackNotification:
760 tc.Info("### REST notifications received e2SubsId %v for endpoint=%s, (%v)", e2SubsId, tc.clientEndpoint, tc)
761 tc.RESTNotification <- (uint32)(e2SubsId)
762 case <-time.After(15 * time.Second):
763 err := fmt.Errorf("### Timeout 15s expired while waiting REST notification")
764 tc.TestError(t, "%s", err.Error())
765 tc.RESTNotification <- 0
770 func (tc *E2Stub) ListedRestNotifHandler(resp *clientmodel.SubscriptionResponse) {
772 if len(tc.restSubsIdList) == 0 {
773 tc.Error("Unexpected listed REST notifications received for endpoint=%s, expected restSubsId list size was ZERO!", tc.clientEndpoint)
775 for i, subsId := range tc.restSubsIdList {
776 if *resp.SubscriptionID == subsId {
777 //tc.Info("Listed REST notifications received SubscriptionID=%s, InstanceID=%v, XappEventInstanceID=%v",
778 // *resp.SubscriptionID, *resp.SubscriptionInstances[0].InstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID)
780 tc.restSubsIdList = append(tc.restSubsIdList[:i], tc.restSubsIdList[i+1:]...)
781 //tc.Info("Removed %s from Listed REST notifications, %v entries left", *resp.SubscriptionID, len(tc.restSubsIdList))
783 if resp.SubscriptionInstances[0].ErrorCause != nil {
784 tc.CallBackListedNotifications <- E2RestIds{*resp.SubscriptionID, uint32(*resp.SubscriptionInstances[0].E2EventInstanceID), *resp.SubscriptionInstances[0].ErrorCause}
786 tc.CallBackListedNotifications <- E2RestIds{*resp.SubscriptionID, uint32(*resp.SubscriptionInstances[0].E2EventInstanceID), ""}
789 if len(tc.restSubsIdList) == 0 {
790 //tc.Info("All listed REST notifications received for endpoint=%s", tc.clientEndpoint)
796 tc.Error("UNKONWN REST notification received SubscriptionID=%s<>%s, InstanceID=%v, XappEventInstanceID=%v (%v)",
797 tc.subscriptionId, *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
801 //-----------------------------------------------------------------------------
803 //-----------------------------------------------------------------------------
804 func (tc *E2Stub) WaitListedRestNotifications(t *testing.T, restSubsIds []string) {
805 tc.Info("Started to wait REST notifications %v on port %v f(RMR port %v)", restSubsIds, *tc.clientEndpoint.HTTPPort, *tc.clientEndpoint.RMRPort)
807 tc.restSubsIdList = restSubsIds
808 xapp.Subscription.SetResponseCB(tc.ListedRestNotifHandler)
810 for i := 0; i < len(restSubsIds); i++ {
813 case e2Ids := <-tc.CallBackListedNotifications:
814 tc.Info("Listed Notification waiter received Notif for %s : %v", e2Ids.RestSubsId, e2Ids.E2SubsId)
815 tc.ListedRESTNotifications <- e2Ids
816 case <-time.After(15 * time.Second):
817 err := fmt.Errorf("Timeout 15s expired while waiting Listed REST notification")
818 tc.TestError(t, "%s", err.Error())
819 tc.RESTNotification <- 0
825 //-----------------------------------------------------------------------------
827 //-----------------------------------------------------------------------------
828 func (tc *E2Stub) SendRESTSubsReq(t *testing.T, params *RESTSubsReqParams) string { // This need to be edited according to new specification
829 tc.Info("======== Posting REST Report subscriptions to Submgr ======")
832 tc.Info("SendRESTReportSubsReq: params == nil")
836 tc.subscriptionId = "SUBSCRIPTIONID NOT SET"
838 resp, err := xapp.Subscription.Subscribe(¶ms.SubsReqParams)
840 // Swagger generated code makes checks for the values that are inserted the subscription function
841 // If error cause is unknown and POST is not done, the problem is in the inserted values
842 tc.Error("======== REST report subscriptions failed %s ========", err.Error())
845 tc.subscriptionId = *resp.SubscriptionID
846 tc.Info("======== REST report subscriptions posted successfully. SubscriptionID = %s, RequestCount = %v ========", *resp.SubscriptionID, tc.requestCount)
847 return *resp.SubscriptionID
850 //-----------------------------------------------------------------------------
852 //-----------------------------------------------------------------------------
853 func (tc *E2Stub) GetRESTSubsReqReportParams(subReqCount int) *RESTSubsReqParams {
855 reportParams := RESTSubsReqParams{}
856 reportParams.GetRESTSubsReqReportParams(subReqCount, &tc.clientEndpoint, &tc.meid)
857 tc.requestCount = subReqCount
861 //-----------------------------------------------------------------------------
863 //-----------------------------------------------------------------------------
864 type RESTSubsReqParams struct {
865 SubsReqParams clientmodel.SubscriptionParams
868 func (p *RESTSubsReqParams) GetRESTSubsReqReportParams(subReqCount int, clientEndpoint *clientmodel.SubscriptionParamsClientEndpoint, meid *string) {
871 p.SubsReqParams.ClientEndpoint = clientEndpoint
872 p.SubsReqParams.Meid = meid
873 var rANFunctionID int64 = 33
874 p.SubsReqParams.RANFunctionID = &rANFunctionID
879 actionType := "report"
880 subsequestActioType := "continue"
881 timeToWait := "w10ms"
883 for requestCount := 0; requestCount < subReqCount; requestCount++ {
884 reqId := int64(requestCount) + 1
885 subscriptionDetail := &clientmodel.SubscriptionDetail{
886 XappEventInstanceID: &reqId,
887 EventTriggers: clientmodel.EventTriggerDefinition{
888 int64(1234 + requestCount),
890 ActionToBeSetupList: clientmodel.ActionsToBeSetup{
891 &clientmodel.ActionToBeSetup{
893 ActionType: &actionType,
894 ActionDefinition: clientmodel.ActionDefinition{
895 int64(5678 + requestCount),
897 SubsequentAction: &clientmodel.SubsequentAction{
898 SubsequentActionType: &subsequestActioType,
899 TimeToWait: &timeToWait,
904 p.SubsReqParams.SubscriptionDetails = append(p.SubsReqParams.SubscriptionDetails, subscriptionDetail)
909 func (p *RESTSubsReqParams) SetMeid(MEID string) {
910 p.SubsReqParams.Meid = &MEID
913 func (p *RESTSubsReqParams) SetEndpoint(HTTP_port int64, RMR_port int64, host string) {
914 var endpoint clientmodel.SubscriptionParamsClientEndpoint
915 endpoint.HTTPPort = &HTTP_port
916 endpoint.RMRPort = &RMR_port
918 p.SubsReqParams.ClientEndpoint = &endpoint
921 func (p *RESTSubsReqParams) SetEndpointHost(host string) {
923 if p.SubsReqParams.ClientEndpoint.Host != "" {
924 if p.SubsReqParams.ClientEndpoint.Host != host {
925 // Renaming toto, print something tc.Info("Posting REST subscription request to Submgr")
926 err := fmt.Errorf("hostname change attempt: %s -> %s", p.SubsReqParams.ClientEndpoint.Host, host)
930 p.SubsReqParams.ClientEndpoint.Host = host
933 func (p *RESTSubsReqParams) SetHTTPEndpoint(HTTP_port int64, host string) {
935 p.SubsReqParams.ClientEndpoint.HTTPPort = &HTTP_port
937 p.SetEndpointHost(host)
939 if p.SubsReqParams.ClientEndpoint.RMRPort == nil {
941 p.SubsReqParams.ClientEndpoint.RMRPort = &RMR_port
945 func (p *RESTSubsReqParams) SetSubActionTypes(actionType string) {
947 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
948 for _, action := range subDetail.ActionToBeSetupList {
950 action.ActionType = &actionType
956 func (p *RESTSubsReqParams) SetSubActionIDs(actionId int64) {
958 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
959 for _, action := range subDetail.ActionToBeSetupList {
961 action.ActionID = &actionId
967 func (p *RESTSubsReqParams) SetSubActionDefinition(actionDefinition []int64) {
969 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
970 for _, action := range subDetail.ActionToBeSetupList {
972 action.ActionDefinition = actionDefinition
978 func (p *RESTSubsReqParams) SetSubEventTriggerDefinition(eventTriggerDefinition []int64) {
980 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
981 if subDetail != nil {
982 subDetail.EventTriggers = eventTriggerDefinition
987 func (p *RESTSubsReqParams) AppendActionToActionToBeSetupList(actionId int64, actionType string, actionDefinition []int64, subsequentActionType string, timeToWait string) {
989 actionToBeSetup := &clientmodel.ActionToBeSetup{
991 ActionType: &actionType,
992 ActionDefinition: clientmodel.ActionDefinition(actionDefinition),
993 SubsequentAction: &clientmodel.SubsequentAction{
994 SubsequentActionType: &subsequentActionType,
995 TimeToWait: &timeToWait,
999 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1000 if subDetail != nil {
1001 subDetail.ActionToBeSetupList = append(subDetail.ActionToBeSetupList, actionToBeSetup)
1006 func (p *RESTSubsReqParams) SetRMREndpoint(RMR_port int64, host string) {
1008 p.SubsReqParams.ClientEndpoint.RMRPort = &RMR_port
1010 p.SetEndpointHost(host)
1012 if p.SubsReqParams.ClientEndpoint.HTTPPort == nil {
1014 p.SubsReqParams.ClientEndpoint.HTTPPort = &HTTP_port
1018 func (p *RESTSubsReqParams) SetTimeToWait(timeToWait string) {
1020 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1021 for _, action := range subDetail.ActionToBeSetupList {
1022 if action != nil && action.SubsequentAction != nil {
1023 action.SubsequentAction.TimeToWait = &timeToWait
1029 func (p *RESTSubsReqParams) SetSubscriptionID(SubscriptionID *string) {
1031 if *SubscriptionID == "" {
1034 p.SubsReqParams.SubscriptionID = *SubscriptionID
1037 //-----------------------------------------------------------------------------
1039 //-----------------------------------------------------------------------------
1040 func (tc *E2Stub) SendRESTSubsDelReq(t *testing.T, subscriptionID *string) {
1042 if *subscriptionID == "" {
1043 tc.Error("REST error in deleting subscriptions. Empty SubscriptionID = %s", *subscriptionID)
1045 tc.Info("REST deleting E2 subscriptions. SubscriptionID = %s", *subscriptionID)
1047 err := xapp.Subscription.Unsubscribe(*subscriptionID)
1049 tc.Error("REST Delete subscription failed %s", err.Error())
1051 tc.Info("REST delete subscription pushed to submgr successfully. SubscriptionID = %s", *subscriptionID)
1054 //-----------------------------------------------------------------------------
1056 //-----------------------------------------------------------------------------
1057 func (tc *E2Stub) GetRESTSubsReqPolicyParams(subReqCount int) *RESTSubsReqParams {
1059 policyParams := RESTSubsReqParams{}
1060 policyParams.GetRESTSubsReqPolicyParams(subReqCount, &tc.clientEndpoint, &tc.meid)
1061 tc.requestCount = subReqCount
1062 return &policyParams
1065 //-----------------------------------------------------------------------------
1067 //-----------------------------------------------------------------------------
1068 func (p *RESTSubsReqParams) GetRESTSubsReqPolicyParams(subReqCount int, clientEndpoint *clientmodel.SubscriptionParamsClientEndpoint, meid *string) {
1070 p.SubsReqParams.ClientEndpoint = clientEndpoint
1071 p.SubsReqParams.Meid = meid
1072 var rANFunctionID int64 = 33
1073 p.SubsReqParams.RANFunctionID = &rANFunctionID
1075 // reqId := int64(1)
1077 actionId := int64(1)
1078 actionType := "policy"
1079 subsequestActioType := "continue"
1080 timeToWait := "w10ms"
1082 for requestCount := 0; requestCount < subReqCount; requestCount++ {
1083 reqId := int64(requestCount) + 1
1084 subscriptionDetail := &clientmodel.SubscriptionDetail{
1085 XappEventInstanceID: &reqId,
1086 EventTriggers: clientmodel.EventTriggerDefinition{
1087 int64(1234 + requestCount),
1089 ActionToBeSetupList: clientmodel.ActionsToBeSetup{
1090 &clientmodel.ActionToBeSetup{
1091 ActionID: &actionId,
1092 ActionType: &actionType,
1093 ActionDefinition: clientmodel.ActionDefinition{
1094 int64(5678 + requestCount),
1096 SubsequentAction: &clientmodel.SubsequentAction{
1097 SubsequentActionType: &subsequestActioType,
1098 TimeToWait: &timeToWait,
1103 p.SubsReqParams.SubscriptionDetails = append(p.SubsReqParams.SubscriptionDetails, subscriptionDetail)