2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
29 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
30 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap_wrapper"
31 "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub"
32 clientmodel "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientmodel"
33 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
39 var e2asnpacker e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
44 type RmrTransactionId struct {
49 type E2RestIds struct {
55 func (trans *RmrTransactionId) String() string {
57 if trans.meid != nil {
58 meidstr = trans.meid.String()
60 return "trans(" + trans.xid + "/" + meidstr + ")"
64 teststub.RmrStubControl
68 CallBackNotification chan int64
69 RESTNotification chan uint32
70 CallBackListedNotifications chan E2RestIds
71 ListedRESTNotifications chan E2RestIds
72 clientEndpoint clientmodel.SubscriptionParamsClientEndpoint
74 restSubsIdList []string
77 //-----------------------------------------------------------------------------
79 //-----------------------------------------------------------------------------
80 func CreateNewE2Stub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int, ranName string, host string, RMRPort int64, HTTPPort int64) *E2Stub {
82 tc.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed)
85 tc.CallBackNotification = make(chan int64)
86 tc.RESTNotification = make(chan uint32)
87 tc.CallBackListedNotifications = make(chan E2RestIds)
88 tc.ListedRESTNotifications = make(chan E2RestIds, 2)
89 var endPoint clientmodel.SubscriptionParamsClientEndpoint
91 endPoint.HTTPPort = &HTTPPort
92 endPoint.RMRPort = &RMRPort
93 tc.clientEndpoint = endPoint
98 //-----------------------------------------------------------------------------
100 //-----------------------------------------------------------------------------
101 func CreateNewE2termStub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int) *E2Stub {
103 tc.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed)
105 tc.SetCheckXid(false)
109 //-----------------------------------------------------------------------------
111 //-----------------------------------------------------------------------------
112 func (tc *E2Stub) NewRmrTransactionId(xid string, ranname string) *RmrTransactionId {
113 trans := &RmrTransactionId{}
115 trans.xid = tc.GetDesc() + "_XID_" + strconv.FormatUint(uint64(tc.xid_seq), 10)
120 trans.meid = &xapp.RMRMeid{RanName: ranname}
121 tc.Info("New test %s", trans.String())
125 //-----------------------------------------------------------------------------
127 //-----------------------------------------------------------------------------
128 type E2StubSubsReqParams struct {
129 Req *e2ap.E2APSubscriptionRequest
132 func (p *E2StubSubsReqParams) Init() {
133 p.Req = &e2ap.E2APSubscriptionRequest{}
135 p.Req.RequestId.Id = 1
136 p.Req.RequestId.InstanceId = 0
139 // gnb -> enb outgoing
140 // enb -> gnb incoming
142 p.Req.EventTriggerDefinition.Data.Length = 1
143 p.Req.EventTriggerDefinition.Data.Data = make([]uint8, p.Req.EventTriggerDefinition.Data.Length)
144 p.Req.EventTriggerDefinition.Data.Data[0] = 1
146 p.Req.ActionSetups = make([]e2ap.ActionToBeSetupItem, 1)
148 p.Req.ActionSetups[0].ActionId = 0
149 p.Req.ActionSetups[0].ActionType = e2ap.E2AP_ActionTypeReport
150 p.Req.ActionSetups[0].RicActionDefinitionPresent = true
152 p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Length = 1
153 p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Data = make([]uint8, p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Length)
154 p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Data[0] = 1
156 p.Req.ActionSetups[0].SubsequentAction.Present = true
157 p.Req.ActionSetups[0].SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeContinue
158 p.Req.ActionSetups[0].SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitZero
161 //-----------------------------------------------------------------------------
163 //-----------------------------------------------------------------------------
165 type E2StubSubsFailParams struct {
166 Req *e2ap.E2APSubscriptionRequest
167 Fail *e2ap.E2APSubscriptionFailure
170 func (p *E2StubSubsFailParams) Set(req *e2ap.E2APSubscriptionRequest) {
173 p.Fail = &e2ap.E2APSubscriptionFailure{}
174 p.Fail.RequestId.Id = p.Req.RequestId.Id
175 p.Fail.RequestId.InstanceId = p.Req.RequestId.InstanceId
176 p.Fail.FunctionId = p.Req.FunctionId
177 p.Fail.ActionNotAdmittedList.Items = make([]e2ap.ActionNotAdmittedItem, len(p.Req.ActionSetups))
178 for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ {
179 p.Fail.ActionNotAdmittedList.Items[index].ActionId = p.Req.ActionSetups[index].ActionId
180 p.SetCauseVal(index, 5, 1)
184 func (p *E2StubSubsFailParams) SetCauseVal(ind int, content uint8, causeval uint8) {
187 for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ {
188 p.Fail.ActionNotAdmittedList.Items[index].Cause.Content = content
189 p.Fail.ActionNotAdmittedList.Items[index].Cause.Value = causeval
193 p.Fail.ActionNotAdmittedList.Items[ind].Cause.Content = content
194 p.Fail.ActionNotAdmittedList.Items[ind].Cause.Value = causeval
197 //-----------------------------------------------------------------------------
199 //-----------------------------------------------------------------------------
201 func (tc *E2Stub) SendSubsReq(t *testing.T, rparams *E2StubSubsReqParams, oldTrans *RmrTransactionId) *RmrTransactionId {
205 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
208 tc.Info("SendSubsReq %s", trans.String())
209 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
211 //---------------------------------
212 // xapp activity: Send Subs Req
213 //---------------------------------
217 myparams = &E2StubSubsReqParams{}
221 err, packedMsg := e2SubsReq.Pack(myparams.Req)
223 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
226 tc.Debug("%s %s", trans.String(), e2SubsReq.String())
228 params := &xapp.RMRParams{}
229 params.Mtype = xapp.RIC_SUB_REQ
231 params.Payload = packedMsg.Buf
232 params.PayloadLen = len(packedMsg.Buf)
233 params.Meid = trans.meid
234 params.Xid = trans.xid
237 tc.Info("SEND SUB REQ: %s", params.String())
238 snderr := tc.SendWithRetry(params, false, 5)
240 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
246 //-----------------------------------------------------------------------------
248 //-----------------------------------------------------------------------------
249 func (tc *E2Stub) RecvSubsReq(t *testing.T) (*e2ap.E2APSubscriptionRequest, *xapp.RMRParams) {
250 tc.Info("RecvSubsReq")
251 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
253 //---------------------------------
254 // e2term activity: Recv Subs Req
255 //---------------------------------
256 msg := tc.WaitMsg(15)
258 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] {
259 tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_REQ", xapp.RicMessageTypeToName[msg.Mtype])
261 tc.Info("Recv Subs Req")
262 packedData := &e2ap.PackedData{}
263 packedData.Buf = msg.Payload
264 unpackerr, req := e2SubsReq.UnPack(packedData)
265 if unpackerr != nil {
266 tc.TestError(t, "RIC_SUB_REQ unpack failed err: %s", unpackerr.Error())
271 tc.TestError(t, "Not Received msg within %d secs", 15)
277 //-----------------------------------------------------------------------------
279 //-----------------------------------------------------------------------------
280 func (tc *E2Stub) SendSubsResp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *xapp.RMRParams) {
281 tc.Info("SendSubsResp")
282 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
284 //---------------------------------
285 // e2term activity: Send Subs Resp
286 //---------------------------------
287 resp := &e2ap.E2APSubscriptionResponse{}
289 resp.RequestId.Id = req.RequestId.Id
290 resp.RequestId.InstanceId = req.RequestId.InstanceId
291 resp.FunctionId = req.FunctionId
293 resp.ActionAdmittedList.Items = make([]e2ap.ActionAdmittedItem, len(req.ActionSetups))
294 for index := int(0); index < len(req.ActionSetups); index++ {
295 resp.ActionAdmittedList.Items[index].ActionId = req.ActionSetups[index].ActionId
298 for index := uint64(0); index < 1; index++ {
299 item := e2ap.ActionNotAdmittedItem{}
300 item.ActionId = index
301 item.Cause.Content = 1
303 resp.ActionNotAdmittedList.Items = append(resp.ActionNotAdmittedList.Items, item)
306 packerr, packedMsg := e2SubsResp.Pack(resp)
308 tc.TestError(t, "pack NOK %s", packerr.Error())
310 tc.Debug("%s", e2SubsResp.String())
312 params := &xapp.RMRParams{}
313 params.Mtype = xapp.RIC_SUB_RESP
314 //params.SubId = msg.SubId
316 params.Payload = packedMsg.Buf
317 params.PayloadLen = len(packedMsg.Buf)
318 params.Meid = msg.Meid
319 //params.Xid = msg.Xid
322 tc.Info("SEND SUB RESP: %s", params.String())
323 snderr := tc.SendWithRetry(params, false, 5)
325 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
329 //-----------------------------------------------------------------------------
331 //-----------------------------------------------------------------------------
332 func (tc *E2Stub) SendInvalidE2Asn1Resp(t *testing.T, msg *xapp.RMRParams, msgType int) {
334 params := &xapp.RMRParams{}
335 params.Mtype = msgType
337 params.Payload = []byte{1, 2, 3, 4, 5}
338 params.PayloadLen = 5
339 params.Meid = msg.Meid
343 if params.Mtype == xapp.RIC_SUB_RESP {
344 tc.Info("SEND INVALID ASN.1 SUB RESP")
346 } else if params.Mtype == xapp.RIC_SUB_FAILURE {
347 tc.Info("SEND INVALID ASN.1 SUB FAILURE")
349 } else if params.Mtype == xapp.RIC_SUB_DEL_RESP {
350 tc.Info("SEND INVALID ASN.1 SUB DEL RESP")
352 } else if params.Mtype == xapp.RIC_SUB_DEL_FAILURE {
353 tc.Info("SEND INVALID ASN.1 SUB DEL FAILURE")
355 snderr := tc.SendWithRetry(params, false, 5)
357 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
361 //-----------------------------------------------------------------------------
363 //-----------------------------------------------------------------------------
364 func (tc *E2Stub) RecvSubsResp(t *testing.T, trans *RmrTransactionId) uint32 {
365 tc.Info("RecvSubsResp")
366 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
369 //---------------------------------
370 // xapp activity: Recv Subs Resp
371 //---------------------------------
372 msg := tc.WaitMsg(15)
374 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
375 tc.TestError(t, "Received RIC_SUB_RESP wrong mtype expected %s got %s, error", "RIC_SUB_RESP", xapp.RicMessageTypeToName[msg.Mtype])
377 } else if msg.Xid != trans.xid {
378 tc.TestError(t, "Received RIC_SUB_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
381 packedData := &e2ap.PackedData{}
382 packedData.Buf = msg.Payload
384 e2SubsId = uint32(msg.SubId)
388 unpackerr, resp := e2SubsResp.UnPack(packedData)
389 if unpackerr != nil {
390 tc.TestError(t, "RIC_SUB_RESP unpack failed err: %s", unpackerr.Error())
392 tc.Info("Recv Subs Resp rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
396 tc.TestError(t, "Not Received msg within %d secs", 15)
401 //-----------------------------------------------------------------------------
403 //-----------------------------------------------------------------------------
405 func (tc *E2Stub) SendSubsFail(t *testing.T, fparams *E2StubSubsFailParams, msg *xapp.RMRParams) {
406 tc.Info("SendSubsFail")
407 e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
409 //---------------------------------
410 // e2term activity: Send Subs Fail
411 //---------------------------------
412 packerr, packedMsg := e2SubsFail.Pack(fparams.Fail)
414 tc.TestError(t, "pack NOK %s", packerr.Error())
416 tc.Debug("%s", e2SubsFail.String())
418 params := &xapp.RMRParams{}
419 params.Mtype = xapp.RIC_SUB_FAILURE
420 params.SubId = msg.SubId
421 params.Payload = packedMsg.Buf
422 params.PayloadLen = len(packedMsg.Buf)
423 params.Meid = msg.Meid
427 tc.Info("SEND SUB FAIL: %s", params.String())
428 snderr := tc.SendWithRetry(params, false, 5)
430 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
434 //-----------------------------------------------------------------------------
436 //-----------------------------------------------------------------------------
437 func (tc *E2Stub) RecvSubsFail(t *testing.T, trans *RmrTransactionId) uint32 {
438 tc.Info("RecvSubsFail")
439 e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
442 //-------------------------------
443 // xapp activity: Recv Subs Fail
444 //-------------------------------
445 msg := tc.WaitMsg(15)
447 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_FAILURE"] {
448 tc.TestError(t, "Received RIC_SUB_FAILURE wrong mtype expected %s got %s, error", "RIC_SUB_FAILURE", xapp.RicMessageTypeToName[msg.Mtype])
450 } else if msg.Xid != trans.xid {
451 tc.TestError(t, "Received RIC_SUB_FAILURE wrong xid expected %s got %s, error", trans.xid, msg.Xid)
454 packedData := &e2ap.PackedData{}
455 packedData.Buf = msg.Payload
457 e2SubsId = uint32(msg.SubId)
461 unpackerr, resp := e2SubsFail.UnPack(packedData)
462 if unpackerr != nil {
463 tc.TestError(t, "RIC_SUB_FAILURE unpack failed err: %s", unpackerr.Error())
465 tc.Info("Recv Subs Fail rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
469 tc.TestError(t, "Not Received msg within %d secs", 15)
474 //-----------------------------------------------------------------------------
476 //-----------------------------------------------------------------------------
477 func (tc *E2Stub) SendSubsDelReq(t *testing.T, oldTrans *RmrTransactionId, e2SubsId uint32) *RmrTransactionId {
481 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
484 tc.Info("SendSubsDelReq %s", trans.String())
485 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
486 //---------------------------------
487 // xapp activity: Send Subs Del Req
488 //---------------------------------
489 req := &e2ap.E2APSubscriptionDeleteRequest{}
491 req.RequestId.InstanceId = e2SubsId
494 err, packedMsg := e2SubsDelReq.Pack(req)
496 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
499 tc.Debug("%s %s", trans.String(), e2SubsDelReq.String())
501 params := &xapp.RMRParams{}
502 params.Mtype = xapp.RIC_SUB_DEL_REQ
503 params.SubId = int(e2SubsId)
504 params.Payload = packedMsg.Buf
505 params.PayloadLen = len(packedMsg.Buf)
506 params.Meid = trans.meid
507 params.Xid = trans.xid
510 tc.Info("SEND SUB DEL REQ: %s", params.String())
511 snderr := tc.SendWithRetry(params, false, 5)
513 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
519 //-----------------------------------------------------------------------------
521 //-----------------------------------------------------------------------------
522 func (tc *E2Stub) RecvSubsDelReq(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *xapp.RMRParams) {
523 tc.Info("RecvSubsDelReq")
524 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
526 //---------------------------------
527 // e2term activity: Recv Subs Del Req
528 //---------------------------------
529 msg := tc.WaitMsg(15)
531 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] {
532 tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_DEL_REQ", xapp.RicMessageTypeToName[msg.Mtype])
534 tc.Info("Recv Subs Del Req")
536 packedData := &e2ap.PackedData{}
537 packedData.Buf = msg.Payload
538 unpackerr, req := e2SubsDelReq.UnPack(packedData)
539 if unpackerr != nil {
540 tc.TestError(t, "RIC_SUB_DEL_REQ unpack failed err: %s", unpackerr.Error())
545 tc.TestError(t, "Not Received msg within %d secs", 15)
550 //-----------------------------------------------------------------------------
552 //-----------------------------------------------------------------------------
553 func (tc *E2Stub) SendSubsDelResp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapp.RMRParams) {
554 tc.Info("SendSubsDelResp")
555 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
557 //---------------------------------
558 // e2term activity: Send Subs Del Resp
559 //---------------------------------
560 resp := &e2ap.E2APSubscriptionDeleteResponse{}
561 resp.RequestId.Id = req.RequestId.Id
562 resp.RequestId.InstanceId = req.RequestId.InstanceId
563 resp.FunctionId = req.FunctionId
565 packerr, packedMsg := e2SubsDelResp.Pack(resp)
567 tc.TestError(t, "pack NOK %s", packerr.Error())
569 tc.Debug("%s", e2SubsDelResp.String())
571 params := &xapp.RMRParams{}
572 params.Mtype = xapp.RIC_SUB_DEL_RESP
573 params.SubId = msg.SubId
574 params.Payload = packedMsg.Buf
575 params.PayloadLen = len(packedMsg.Buf)
576 params.Meid = msg.Meid
580 tc.Info("SEND SUB DEL RESP: %s", params.String())
581 snderr := tc.SendWithRetry(params, false, 5)
583 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
587 //-----------------------------------------------------------------------------
589 //-----------------------------------------------------------------------------
590 func (tc *E2Stub) RecvSubsDelResp(t *testing.T, trans *RmrTransactionId) {
591 tc.Info("RecvSubsDelResp")
592 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
594 //---------------------------------
595 // xapp activity: Recv Subs Del Resp
596 //---------------------------------
597 msg := tc.WaitMsg(15)
599 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
600 tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong mtype expected %s got %s, error", "RIC_SUB_DEL_RESP", xapp.RicMessageTypeToName[msg.Mtype])
602 } else if trans != nil && msg.Xid != trans.xid {
603 tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
606 packedData := &e2ap.PackedData{}
607 packedData.Buf = msg.Payload
608 unpackerr, resp := e2SubsDelResp.UnPack(packedData)
609 if unpackerr != nil {
610 tc.TestError(t, "RIC_SUB_DEL_RESP unpack failed err: %s", unpackerr.Error())
612 tc.Info("Recv Subs Del Resp rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
616 tc.TestError(t, "Not Received msg within %d secs", 15)
620 //-----------------------------------------------------------------------------
622 //-----------------------------------------------------------------------------
623 func (tc *E2Stub) SendSubsDelFail(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapp.RMRParams) {
624 tc.Info("SendSubsDelFail")
625 e2SubsDelFail := e2asnpacker.NewPackerSubscriptionDeleteFailure()
627 //---------------------------------
628 // e2term activity: Send Subs Del Fail
629 //---------------------------------
630 resp := &e2ap.E2APSubscriptionDeleteFailure{}
631 resp.RequestId.Id = req.RequestId.Id
632 resp.RequestId.InstanceId = req.RequestId.InstanceId
633 resp.FunctionId = req.FunctionId
634 resp.Cause.Content = 5 // CauseMisc
635 resp.Cause.Value = 3 // unspecified
637 packerr, packedMsg := e2SubsDelFail.Pack(resp)
639 tc.TestError(t, "pack NOK %s", packerr.Error())
641 tc.Debug("%s", e2SubsDelFail.String())
643 params := &xapp.RMRParams{}
644 params.Mtype = xapp.RIC_SUB_DEL_FAILURE
645 params.SubId = msg.SubId
646 params.Payload = packedMsg.Buf
647 params.PayloadLen = len(packedMsg.Buf)
648 params.Meid = msg.Meid
652 tc.Info("SEND SUB DEL FAIL: %s", params.String())
653 snderr := tc.SendWithRetry(params, false, 5)
655 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
659 // REST code below all
661 /*****************************************************************************/
662 // REST interface specific functions are below
664 //-----------------------------------------------------------------------------
665 // Callback handler for subscription response notifications
666 //-----------------------------------------------------------------------------
667 func (tc *E2Stub) SubscriptionRespHandler(resp *clientmodel.SubscriptionResponse) {
669 if tc.subscriptionId == "SUBSCRIPTIONID NOT SET" {
670 tc.Info("REST notification received for %v while no SubscriptionID was not set for E2EventInstanceID=%v, XappEventInstanceID=%v (%v)",
671 *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
672 tc.CallBackNotification <- *resp.SubscriptionInstances[0].E2EventInstanceID
673 } else if tc.subscriptionId == *resp.SubscriptionID {
674 tc.Info("REST notification received SubscriptionID=%s, E2EventInstanceID=%v, RequestorID=%v (%v)",
675 *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
676 tc.CallBackNotification <- *resp.SubscriptionInstances[0].E2EventInstanceID
678 tc.Info("MISMATCHING REST notification received SubscriptionID=%s<>%s, E2EventInstanceID=%v, XappEventInstanceID=%v (%v)",
679 tc.subscriptionId, *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
683 //-----------------------------------------------------------------------------
685 //-----------------------------------------------------------------------------
687 func (tc *E2Stub) ExpectRESTNotification(t *testing.T, restSubsId string) {
688 tc.expectNotification(t, restSubsId, "")
691 func (tc *E2Stub) ExpectRESTNotificationOk(t *testing.T, restSubsId string) {
692 tc.expectNotification(t, restSubsId, "allOk")
695 func (tc *E2Stub) ExpectRESTNotificationNok(t *testing.T, restSubsId string, expectError string) {
696 tc.expectNotification(t, restSubsId, expectError)
699 func (tc *E2Stub) expectNotification(t *testing.T, restSubsId string, expectError string) {
701 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)
702 tc.restSubsIdList = []string{restSubsId}
703 xapp.Subscription.SetResponseCB(tc.ListedRestNotifHandler)
704 if tc.requestCount == 0 {
705 tc.TestError(t, "### NO REST notifications SET received for endpoint=%s, request zount ZERO! (%v)", tc.clientEndpoint, tc)
709 case e2Ids := <-tc.CallBackListedNotifications:
710 if tc.requestCount == 0 {
711 tc.TestError(t, "### REST notification count unexpectedly ZERO for %s (%v)", restSubsId, tc)
712 } else if e2Ids.RestSubsId != restSubsId {
713 tc.TestError(t, "### Unexpected REST notifications received, expected %s bunt got %s instead| (%v)", e2Ids.RestSubsId, restSubsId, tc)
714 } else if e2Ids.ErrorCause == "" && expectError == "allFail" {
715 tc.TestError(t, "### Unexpected ok cause received from REST notifications |%s:%s| (%v)", e2Ids.RestSubsId, restSubsId, tc)
716 } else if e2Ids.ErrorCause != "" && expectError == "allOk" {
717 tc.TestError(t, "### Unexpected error cause (%s) received from REST notifications |%s:%s| (%v)", e2Ids.ErrorCause, e2Ids.RestSubsId, restSubsId, tc)
720 if tc.requestCount == 0 {
721 tc.Info("### All expected REST notifications received for %s (%v)", e2Ids.RestSubsId, tc)
723 tc.Info("### Expected REST notifications received for %s, (%v)", e2Ids.RestSubsId, tc)
725 if e2Ids.ErrorCause != "" && expectError == "allFail" {
726 tc.Info("### REST Notification: %s, ErrorCause: %v", e2Ids.RestSubsId, e2Ids.ErrorCause)
728 tc.Info("### REST Notification received Notif for %s : %v", e2Ids.RestSubsId, e2Ids.E2SubsId)
729 tc.ListedRESTNotifications <- e2Ids
730 if len(tc.ListedRESTNotifications) > 1 {
731 panic("expectNotification - ListedRESTNotifications stacking up")
734 case <-time.After(15 * time.Second):
735 err := fmt.Errorf("### Timeout 15s expired while expecting REST notification for subsId: %v", restSubsId)
736 tc.TestError(t, "%s", err.Error())
741 func (tc *E2Stub) WaitRESTNotification(t *testing.T, restSubsId string) uint32 {
743 stack := string(debug.Stack())
746 case e2SubsId := <-tc.ListedRESTNotifications:
747 if e2SubsId.RestSubsId == restSubsId {
748 tc.Info("### Expected REST notifications received %s, e2SubsId %v for endpoint=%s, (%v)", e2SubsId.RestSubsId, e2SubsId.E2SubsId, tc.clientEndpoint, tc)
749 return e2SubsId.E2SubsId
751 tc.TestError(t, "### Unexpected REST notification %s received, expected %s for endpoint=%s, (%v)", e2SubsId.RestSubsId, restSubsId, tc.clientEndpoint, tc)
752 xapp.Logger.Info("CALL STACK:\n %s", stack)
755 case <-time.After(15 * time.Second):
756 err := fmt.Errorf("### Timeout 15s expired while waiting REST notification for subsId: %v", restSubsId)
757 tc.TestError(t, "%s", err.Error())
758 xapp.Logger.Info("CALL STACK:\n %s", stack)
759 panic("WaitRESTNotification - timeout error")
763 // Note, this function should be followed by a handling of <-xappConn1.RESTNotification.
764 func (tc *E2Stub) ExpectAnyNotification(t *testing.T) {
766 tc.Info("### Started waiting ANY REST notifications received for endpoint=%s, (%v)", tc.clientEndpoint, tc)
768 case e2SubsId := <-tc.CallBackNotification:
769 tc.Info("### ANY REST notifications received e2SubsId %v for endpoint=%s, (%v) via CallBackNotification", e2SubsId, tc.clientEndpoint, tc)
770 tc.RESTNotification <- (uint32)(e2SubsId)
771 case <-time.After(15 * time.Second):
772 err := fmt.Errorf("### Timeout 15s expired while waiting ANY REST notification")
773 tc.TestError(t, "%s", err.Error())
774 tc.RESTNotification <- 0
779 func (tc *E2Stub) WaitAnyRESTNotification(t *testing.T) uint32 {
782 case e2SubsId := <-tc.RESTNotification:
783 tc.Info("### Expected ANY REST notification received - e2SubsId %v for endpoint=%s, (%v)", e2SubsId, tc.clientEndpoint, tc)
786 case <-time.After(15 * time.Second):
787 err := fmt.Errorf("### Timeout 15s expired while waiting ANY REST notification")
788 tc.TestError(t, "%s", err.Error())
789 panic("WaitRESTNotification - timeout error")
793 func (tc *E2Stub) ListedRestNotifHandler(resp *clientmodel.SubscriptionResponse) {
795 if len(tc.restSubsIdList) == 0 {
796 tc.Error("Unexpected listed REST notifications received for endpoint=%s, expected restSubsId list size was ZERO!", tc.clientEndpoint)
798 for i, subsId := range tc.restSubsIdList {
799 if *resp.SubscriptionID == subsId {
800 //tc.Info("Listed REST notifications received SubscriptionID=%s, InstanceID=%v, XappEventInstanceID=%v",
801 // *resp.SubscriptionID, *resp.SubscriptionInstances[0].InstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID)
803 tc.restSubsIdList = append(tc.restSubsIdList[:i], tc.restSubsIdList[i+1:]...)
804 //tc.Info("Removed %s from Listed REST notifications, %v entries left", *resp.SubscriptionID, len(tc.restSubsIdList))
806 if resp.SubscriptionInstances[0].ErrorCause != nil {
807 tc.CallBackListedNotifications <- E2RestIds{*resp.SubscriptionID, uint32(*resp.SubscriptionInstances[0].E2EventInstanceID), *resp.SubscriptionInstances[0].ErrorCause}
809 tc.CallBackListedNotifications <- E2RestIds{*resp.SubscriptionID, uint32(*resp.SubscriptionInstances[0].E2EventInstanceID), ""}
812 if len(tc.restSubsIdList) == 0 {
813 tc.Info("All listed REST notifications received for endpoint=%s", tc.clientEndpoint)
819 tc.Error("UNKONWN REST notification received SubscriptionID=%s<>%s, InstanceID=%v, XappEventInstanceID=%v (%v)",
820 tc.subscriptionId, *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
824 //-----------------------------------------------------------------------------
826 //-----------------------------------------------------------------------------
827 func (tc *E2Stub) WaitListedRestNotifications(t *testing.T, restSubsIds []string) {
828 tc.Info("Started to wait REST notifications %v on port %v f(RMR port %v)", restSubsIds, *tc.clientEndpoint.HTTPPort, *tc.clientEndpoint.RMRPort)
830 tc.restSubsIdList = restSubsIds
831 xapp.Subscription.SetResponseCB(tc.ListedRestNotifHandler)
833 for i := 0; i < len(restSubsIds); i++ {
836 case e2Ids := <-tc.CallBackListedNotifications:
837 tc.Info("Listed Notification waiter received Notif for %s : %v", e2Ids.RestSubsId, e2Ids.E2SubsId)
838 tc.ListedRESTNotifications <- e2Ids
839 case <-time.After(15 * time.Second):
840 err := fmt.Errorf("Timeout 15s expired while waiting Listed REST notification")
841 tc.TestError(t, "%s", err.Error())
842 tc.RESTNotification <- 0
848 //-----------------------------------------------------------------------------
850 //-----------------------------------------------------------------------------
851 func (tc *E2Stub) SendRESTSubsReq(t *testing.T, params *RESTSubsReqParams) string { // This need to be edited according to new specification
852 tc.Info("======== Posting REST Report subscriptions to Submgr ======")
855 tc.Info("SendRESTReportSubsReq: params == nil")
859 tc.subscriptionId = "SUBSCRIPTIONID NOT SET"
861 resp, err := xapp.Subscription.Subscribe(¶ms.SubsReqParams)
863 // Swagger generated code makes checks for the values that are inserted the subscription function
864 // If error cause is unknown and POST is not done, the problem is in the inserted values
865 tc.Error("======== REST report subscriptions failed %s ========", err.Error())
868 tc.subscriptionId = *resp.SubscriptionID
869 tc.Info("======== REST report subscriptions posted successfully. SubscriptionID = %s, RequestCount = %v ========", *resp.SubscriptionID, tc.requestCount)
870 return *resp.SubscriptionID
873 //-----------------------------------------------------------------------------
875 //-----------------------------------------------------------------------------
876 func (tc *E2Stub) GetRESTSubsReqReportParams(subReqCount int) *RESTSubsReqParams {
878 reportParams := RESTSubsReqParams{}
879 reportParams.GetRESTSubsReqReportParams(subReqCount, &tc.clientEndpoint, &tc.meid)
880 tc.requestCount = subReqCount
884 //-----------------------------------------------------------------------------
886 //-----------------------------------------------------------------------------
887 type RESTSubsReqParams struct {
888 SubsReqParams clientmodel.SubscriptionParams
891 func (p *RESTSubsReqParams) GetRESTSubsReqReportParams(subReqCount int, clientEndpoint *clientmodel.SubscriptionParamsClientEndpoint, meid *string) {
894 p.SubsReqParams.ClientEndpoint = clientEndpoint
895 p.SubsReqParams.Meid = meid
896 var rANFunctionID int64 = 33
897 p.SubsReqParams.RANFunctionID = &rANFunctionID
902 actionType := "report"
903 subsequestActioType := "continue"
904 timeToWait := "w10ms"
906 for requestCount := 0; requestCount < subReqCount; requestCount++ {
907 reqId := int64(requestCount) + 1
908 subscriptionDetail := &clientmodel.SubscriptionDetail{
909 XappEventInstanceID: &reqId,
910 EventTriggers: clientmodel.EventTriggerDefinition{
911 int64(1234 + requestCount),
913 ActionToBeSetupList: clientmodel.ActionsToBeSetup{
914 &clientmodel.ActionToBeSetup{
916 ActionType: &actionType,
917 ActionDefinition: clientmodel.ActionDefinition{
918 int64(5678 + requestCount),
920 SubsequentAction: &clientmodel.SubsequentAction{
921 SubsequentActionType: &subsequestActioType,
922 TimeToWait: &timeToWait,
927 p.SubsReqParams.SubscriptionDetails = append(p.SubsReqParams.SubscriptionDetails, subscriptionDetail)
932 func (p *RESTSubsReqParams) SetMeid(MEID string) {
933 p.SubsReqParams.Meid = &MEID
936 func (p *RESTSubsReqParams) SetEndpoint(HTTP_port int64, RMR_port int64, host string) {
937 var endpoint clientmodel.SubscriptionParamsClientEndpoint
938 endpoint.HTTPPort = &HTTP_port
939 endpoint.RMRPort = &RMR_port
941 p.SubsReqParams.ClientEndpoint = &endpoint
944 func (p *RESTSubsReqParams) SetEndpointHost(host string) {
946 if p.SubsReqParams.ClientEndpoint.Host != "" {
947 if p.SubsReqParams.ClientEndpoint.Host != host {
948 // Renaming toto, print something tc.Info("Posting REST subscription request to Submgr")
949 err := fmt.Errorf("hostname change attempt: %s -> %s", p.SubsReqParams.ClientEndpoint.Host, host)
953 p.SubsReqParams.ClientEndpoint.Host = host
956 func (p *RESTSubsReqParams) SetHTTPEndpoint(HTTP_port int64, host string) {
958 p.SubsReqParams.ClientEndpoint.HTTPPort = &HTTP_port
960 p.SetEndpointHost(host)
962 if p.SubsReqParams.ClientEndpoint.RMRPort == nil {
964 p.SubsReqParams.ClientEndpoint.RMRPort = &RMR_port
968 func (p *RESTSubsReqParams) SetSubActionTypes(actionType string) {
970 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
971 for _, action := range subDetail.ActionToBeSetupList {
973 action.ActionType = &actionType
979 func (p *RESTSubsReqParams) SetSubActionIDs(actionId int64) {
981 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
982 for _, action := range subDetail.ActionToBeSetupList {
984 action.ActionID = &actionId
990 func (p *RESTSubsReqParams) SetSubActionDefinition(actionDefinition []int64) {
992 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
993 for _, action := range subDetail.ActionToBeSetupList {
995 action.ActionDefinition = actionDefinition
1001 func (p *RESTSubsReqParams) SetSubEventTriggerDefinition(eventTriggerDefinition []int64) {
1003 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1004 if subDetail != nil {
1005 subDetail.EventTriggers = eventTriggerDefinition
1010 func (p *RESTSubsReqParams) AppendActionToActionToBeSetupList(actionId int64, actionType string, actionDefinition []int64, subsequentActionType string, timeToWait string) {
1012 actionToBeSetup := &clientmodel.ActionToBeSetup{
1013 ActionID: &actionId,
1014 ActionType: &actionType,
1015 ActionDefinition: clientmodel.ActionDefinition(actionDefinition),
1016 SubsequentAction: &clientmodel.SubsequentAction{
1017 SubsequentActionType: &subsequentActionType,
1018 TimeToWait: &timeToWait,
1022 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1023 if subDetail != nil {
1024 subDetail.ActionToBeSetupList = append(subDetail.ActionToBeSetupList, actionToBeSetup)
1029 func (p *RESTSubsReqParams) SetRMREndpoint(RMR_port int64, host string) {
1031 p.SubsReqParams.ClientEndpoint.RMRPort = &RMR_port
1033 p.SetEndpointHost(host)
1035 if p.SubsReqParams.ClientEndpoint.HTTPPort == nil {
1037 p.SubsReqParams.ClientEndpoint.HTTPPort = &HTTP_port
1041 func (p *RESTSubsReqParams) SetTimeToWait(timeToWait string) {
1043 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1044 for _, action := range subDetail.ActionToBeSetupList {
1045 if action != nil && action.SubsequentAction != nil {
1046 action.SubsequentAction.TimeToWait = &timeToWait
1052 func (p *RESTSubsReqParams) SetSubscriptionID(SubscriptionID *string) {
1054 if *SubscriptionID == "" {
1057 p.SubsReqParams.SubscriptionID = *SubscriptionID
1060 //-----------------------------------------------------------------------------
1062 //-----------------------------------------------------------------------------
1063 func (tc *E2Stub) SendRESTSubsDelReq(t *testing.T, subscriptionID *string) {
1065 tc.Info("======== Posting REST DELETE subscription(s) to Submgr ======")
1067 if *subscriptionID == "" {
1068 tc.Error("REST error in deleting subscriptions. Empty SubscriptionID = %s", *subscriptionID)
1070 tc.Info("REST deleting E2 subscriptions. SubscriptionID = %s", *subscriptionID)
1072 err := xapp.Subscription.Unsubscribe(*subscriptionID)
1074 tc.Error("REST Delete subscription failed %s", err.Error())
1076 tc.Info("REST delete subscription pushed to submgr successfully. SubscriptionID = %s", *subscriptionID)
1079 //-----------------------------------------------------------------------------
1081 //-----------------------------------------------------------------------------
1082 func (tc *E2Stub) GetRESTSubsReqPolicyParams(subReqCount int) *RESTSubsReqParams {
1084 policyParams := RESTSubsReqParams{}
1085 policyParams.GetRESTSubsReqPolicyParams(subReqCount, &tc.clientEndpoint, &tc.meid)
1086 tc.requestCount = subReqCount
1087 return &policyParams
1090 //-----------------------------------------------------------------------------
1092 //-----------------------------------------------------------------------------
1093 func (tc *E2Stub) DecrementRequestCount() {
1094 if tc.requestCount > 0 {
1095 tc.requestCount -= 1
1097 tc.Error("FAILED to decrement request count, count already ZERO")
1101 //-----------------------------------------------------------------------------
1103 //-----------------------------------------------------------------------------
1104 func (p *RESTSubsReqParams) GetRESTSubsReqPolicyParams(subReqCount int, clientEndpoint *clientmodel.SubscriptionParamsClientEndpoint, meid *string) {
1106 p.SubsReqParams.ClientEndpoint = clientEndpoint
1107 p.SubsReqParams.Meid = meid
1108 var rANFunctionID int64 = 33
1109 p.SubsReqParams.RANFunctionID = &rANFunctionID
1111 // reqId := int64(1)
1113 actionId := int64(1)
1114 actionType := "policy"
1115 subsequestActioType := "continue"
1116 timeToWait := "w10ms"
1118 for requestCount := 0; requestCount < subReqCount; requestCount++ {
1119 reqId := int64(requestCount) + 1
1120 subscriptionDetail := &clientmodel.SubscriptionDetail{
1121 XappEventInstanceID: &reqId,
1122 EventTriggers: clientmodel.EventTriggerDefinition{
1123 int64(1234 + requestCount),
1125 ActionToBeSetupList: clientmodel.ActionsToBeSetup{
1126 &clientmodel.ActionToBeSetup{
1127 ActionID: &actionId,
1128 ActionType: &actionType,
1129 ActionDefinition: clientmodel.ActionDefinition{
1130 int64(5678 + requestCount),
1132 SubsequentAction: &clientmodel.SubsequentAction{
1133 SubsequentActionType: &subsequestActioType,
1134 TimeToWait: &timeToWait,
1139 p.SubsReqParams.SubscriptionDetails = append(p.SubsReqParams.SubscriptionDetails, subscriptionDetail)