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 {
53 func (trans *RmrTransactionId) String() string {
55 if trans.meid != nil {
56 meidstr = trans.meid.String()
58 return "trans(" + trans.xid + "/" + meidstr + ")"
62 teststub.RmrStubControl
66 CallBackNotification chan int64
67 RESTNotification chan uint32
68 CallBackListedNotifications chan E2RestIds
69 ListedRESTNotifications chan E2RestIds
70 clientEndpoint clientmodel.SubscriptionParamsClientEndpoint
72 restSubsIdList []string
75 //-----------------------------------------------------------------------------
77 //-----------------------------------------------------------------------------
78 func CreateNewE2Stub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int, ranName string, host string, RMRPort int64, HTTPPort int64) *E2Stub {
80 tc.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed)
83 tc.CallBackNotification = make(chan int64)
84 tc.RESTNotification = make(chan uint32)
85 tc.CallBackListedNotifications = make(chan E2RestIds)
86 tc.ListedRESTNotifications = make(chan E2RestIds, 2)
87 var endPoint clientmodel.SubscriptionParamsClientEndpoint
89 endPoint.HTTPPort = &HTTPPort
90 endPoint.RMRPort = &RMRPort
91 tc.clientEndpoint = endPoint
96 //-----------------------------------------------------------------------------
98 //-----------------------------------------------------------------------------
99 func CreateNewE2termStub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int) *E2Stub {
101 tc.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed)
103 tc.SetCheckXid(false)
107 //-----------------------------------------------------------------------------
109 //-----------------------------------------------------------------------------
110 func (tc *E2Stub) NewRmrTransactionId(xid string, ranname string) *RmrTransactionId {
111 trans := &RmrTransactionId{}
113 trans.xid = tc.GetDesc() + "_XID_" + strconv.FormatUint(uint64(tc.xid_seq), 10)
118 trans.meid = &xapp.RMRMeid{RanName: ranname}
119 tc.Info("New test %s", trans.String())
123 //-----------------------------------------------------------------------------
125 //-----------------------------------------------------------------------------
126 type E2StubSubsReqParams struct {
127 Req *e2ap.E2APSubscriptionRequest
130 func (p *E2StubSubsReqParams) Init() {
131 p.Req = &e2ap.E2APSubscriptionRequest{}
133 p.Req.RequestId.Id = 1
134 p.Req.RequestId.InstanceId = 0
137 // gnb -> enb outgoing
138 // enb -> gnb incoming
140 p.Req.EventTriggerDefinition.Data.Length = 1
141 p.Req.EventTriggerDefinition.Data.Data = make([]uint8, p.Req.EventTriggerDefinition.Data.Length)
142 p.Req.EventTriggerDefinition.Data.Data[0] = 1
144 p.Req.ActionSetups = make([]e2ap.ActionToBeSetupItem, 1)
146 p.Req.ActionSetups[0].ActionId = 0
147 p.Req.ActionSetups[0].ActionType = e2ap.E2AP_ActionTypeReport
148 p.Req.ActionSetups[0].RicActionDefinitionPresent = true
150 p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Length = 1
151 p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Data = make([]uint8, p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Length)
152 p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Data[0] = 1
154 p.Req.ActionSetups[0].SubsequentAction.Present = true
155 p.Req.ActionSetups[0].SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeContinue
156 p.Req.ActionSetups[0].SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitZero
159 //-----------------------------------------------------------------------------
161 //-----------------------------------------------------------------------------
163 type E2StubSubsFailParams struct {
164 Req *e2ap.E2APSubscriptionRequest
165 Fail *e2ap.E2APSubscriptionFailure
168 func (p *E2StubSubsFailParams) Set(req *e2ap.E2APSubscriptionRequest) {
171 p.Fail = &e2ap.E2APSubscriptionFailure{}
172 p.Fail.RequestId.Id = p.Req.RequestId.Id
173 p.Fail.RequestId.InstanceId = p.Req.RequestId.InstanceId
174 p.Fail.FunctionId = p.Req.FunctionId
175 p.Fail.ActionNotAdmittedList.Items = make([]e2ap.ActionNotAdmittedItem, len(p.Req.ActionSetups))
176 for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ {
177 p.Fail.ActionNotAdmittedList.Items[index].ActionId = p.Req.ActionSetups[index].ActionId
178 p.SetCauseVal(index, 5, 1)
182 func (p *E2StubSubsFailParams) SetCauseVal(ind int, content uint8, causeval uint8) {
185 for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ {
186 p.Fail.ActionNotAdmittedList.Items[index].Cause.Content = content
187 p.Fail.ActionNotAdmittedList.Items[index].Cause.Value = causeval
191 p.Fail.ActionNotAdmittedList.Items[ind].Cause.Content = content
192 p.Fail.ActionNotAdmittedList.Items[ind].Cause.Value = causeval
195 //-----------------------------------------------------------------------------
197 //-----------------------------------------------------------------------------
199 func (tc *E2Stub) SendSubsReq(t *testing.T, rparams *E2StubSubsReqParams, oldTrans *RmrTransactionId) *RmrTransactionId {
203 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
206 tc.Info("SendSubsReq %s", trans.String())
207 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
209 //---------------------------------
210 // xapp activity: Send Subs Req
211 //---------------------------------
215 myparams = &E2StubSubsReqParams{}
219 err, packedMsg := e2SubsReq.Pack(myparams.Req)
221 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
224 tc.Debug("%s %s", trans.String(), e2SubsReq.String())
226 params := &xapp.RMRParams{}
227 params.Mtype = xapp.RIC_SUB_REQ
229 params.Payload = packedMsg.Buf
230 params.PayloadLen = len(packedMsg.Buf)
231 params.Meid = trans.meid
232 params.Xid = trans.xid
235 tc.Info("SEND SUB REQ: %s", params.String())
236 snderr := tc.SendWithRetry(params, false, 5)
238 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
244 //-----------------------------------------------------------------------------
246 //-----------------------------------------------------------------------------
247 func (tc *E2Stub) RecvSubsReq(t *testing.T) (*e2ap.E2APSubscriptionRequest, *xapp.RMRParams) {
248 tc.Info("RecvSubsReq")
249 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
251 //---------------------------------
252 // e2term activity: Recv Subs Req
253 //---------------------------------
254 msg := tc.WaitMsg(15)
256 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] {
257 tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_REQ", xapp.RicMessageTypeToName[msg.Mtype])
259 tc.Info("Recv Subs Req")
260 packedData := &e2ap.PackedData{}
261 packedData.Buf = msg.Payload
262 unpackerr, req := e2SubsReq.UnPack(packedData)
263 if unpackerr != nil {
264 tc.TestError(t, "RIC_SUB_REQ unpack failed err: %s", unpackerr.Error())
269 tc.TestError(t, "Not Received msg within %d secs", 15)
275 //-----------------------------------------------------------------------------
277 //-----------------------------------------------------------------------------
278 func (tc *E2Stub) SendSubsResp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *xapp.RMRParams) {
279 tc.Info("SendSubsResp")
280 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
282 //---------------------------------
283 // e2term activity: Send Subs Resp
284 //---------------------------------
285 resp := &e2ap.E2APSubscriptionResponse{}
287 resp.RequestId.Id = req.RequestId.Id
288 resp.RequestId.InstanceId = req.RequestId.InstanceId
289 resp.FunctionId = req.FunctionId
291 resp.ActionAdmittedList.Items = make([]e2ap.ActionAdmittedItem, len(req.ActionSetups))
292 for index := int(0); index < len(req.ActionSetups); index++ {
293 resp.ActionAdmittedList.Items[index].ActionId = req.ActionSetups[index].ActionId
296 for index := uint64(0); index < 1; index++ {
297 item := e2ap.ActionNotAdmittedItem{}
298 item.ActionId = index
299 item.Cause.Content = 1
301 resp.ActionNotAdmittedList.Items = append(resp.ActionNotAdmittedList.Items, item)
304 packerr, packedMsg := e2SubsResp.Pack(resp)
306 tc.TestError(t, "pack NOK %s", packerr.Error())
308 tc.Debug("%s", e2SubsResp.String())
310 params := &xapp.RMRParams{}
311 params.Mtype = xapp.RIC_SUB_RESP
312 //params.SubId = msg.SubId
314 params.Payload = packedMsg.Buf
315 params.PayloadLen = len(packedMsg.Buf)
316 params.Meid = msg.Meid
317 //params.Xid = msg.Xid
320 tc.Info("SEND SUB RESP: %s", params.String())
321 snderr := tc.SendWithRetry(params, false, 5)
323 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
327 //-----------------------------------------------------------------------------
329 //-----------------------------------------------------------------------------
330 func (tc *E2Stub) RecvSubsResp(t *testing.T, trans *RmrTransactionId) uint32 {
331 tc.Info("RecvSubsResp")
332 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
335 //---------------------------------
336 // xapp activity: Recv Subs Resp
337 //---------------------------------
338 msg := tc.WaitMsg(15)
340 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
341 tc.TestError(t, "Received RIC_SUB_RESP wrong mtype expected %s got %s, error", "RIC_SUB_RESP", xapp.RicMessageTypeToName[msg.Mtype])
343 } else if msg.Xid != trans.xid {
344 tc.TestError(t, "Received RIC_SUB_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
347 packedData := &e2ap.PackedData{}
348 packedData.Buf = msg.Payload
350 e2SubsId = uint32(msg.SubId)
354 unpackerr, resp := e2SubsResp.UnPack(packedData)
355 if unpackerr != nil {
356 tc.TestError(t, "RIC_SUB_RESP unpack failed err: %s", unpackerr.Error())
358 tc.Info("Recv Subs Resp rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
362 tc.TestError(t, "Not Received msg within %d secs", 15)
367 //-----------------------------------------------------------------------------
369 //-----------------------------------------------------------------------------
371 func (tc *E2Stub) SendSubsFail(t *testing.T, fparams *E2StubSubsFailParams, msg *xapp.RMRParams) {
372 tc.Info("SendSubsFail")
373 e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
375 //---------------------------------
376 // e2term activity: Send Subs Fail
377 //---------------------------------
378 packerr, packedMsg := e2SubsFail.Pack(fparams.Fail)
380 tc.TestError(t, "pack NOK %s", packerr.Error())
382 tc.Debug("%s", e2SubsFail.String())
384 params := &xapp.RMRParams{}
385 params.Mtype = xapp.RIC_SUB_FAILURE
386 params.SubId = msg.SubId
387 params.Payload = packedMsg.Buf
388 params.PayloadLen = len(packedMsg.Buf)
389 params.Meid = msg.Meid
393 tc.Info("SEND SUB FAIL: %s", params.String())
394 snderr := tc.SendWithRetry(params, false, 5)
396 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
400 //-----------------------------------------------------------------------------
402 //-----------------------------------------------------------------------------
403 func (tc *E2Stub) RecvSubsFail(t *testing.T, trans *RmrTransactionId) uint32 {
404 tc.Info("RecvSubsFail")
405 e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
408 //-------------------------------
409 // xapp activity: Recv Subs Fail
410 //-------------------------------
411 msg := tc.WaitMsg(15)
413 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_FAILURE"] {
414 tc.TestError(t, "Received RIC_SUB_FAILURE wrong mtype expected %s got %s, error", "RIC_SUB_FAILURE", xapp.RicMessageTypeToName[msg.Mtype])
416 } else if msg.Xid != trans.xid {
417 tc.TestError(t, "Received RIC_SUB_FAILURE wrong xid expected %s got %s, error", trans.xid, msg.Xid)
420 packedData := &e2ap.PackedData{}
421 packedData.Buf = msg.Payload
423 e2SubsId = uint32(msg.SubId)
427 unpackerr, resp := e2SubsFail.UnPack(packedData)
428 if unpackerr != nil {
429 tc.TestError(t, "RIC_SUB_FAILURE unpack failed err: %s", unpackerr.Error())
431 tc.Info("Recv Subs Fail rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
435 tc.TestError(t, "Not Received msg within %d secs", 15)
440 //-----------------------------------------------------------------------------
442 //-----------------------------------------------------------------------------
443 func (tc *E2Stub) SendSubsDelReq(t *testing.T, oldTrans *RmrTransactionId, e2SubsId uint32) *RmrTransactionId {
447 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
450 tc.Info("SendSubsDelReq %s", trans.String())
451 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
452 //---------------------------------
453 // xapp activity: Send Subs Del Req
454 //---------------------------------
455 req := &e2ap.E2APSubscriptionDeleteRequest{}
457 req.RequestId.InstanceId = e2SubsId
460 err, packedMsg := e2SubsDelReq.Pack(req)
462 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
465 tc.Debug("%s %s", trans.String(), e2SubsDelReq.String())
467 params := &xapp.RMRParams{}
468 params.Mtype = xapp.RIC_SUB_DEL_REQ
469 params.SubId = int(e2SubsId)
470 params.Payload = packedMsg.Buf
471 params.PayloadLen = len(packedMsg.Buf)
472 params.Meid = trans.meid
473 params.Xid = trans.xid
476 tc.Info("SEND SUB DEL REQ: %s", params.String())
477 snderr := tc.SendWithRetry(params, false, 5)
479 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
485 //-----------------------------------------------------------------------------
487 //-----------------------------------------------------------------------------
488 func (tc *E2Stub) RecvSubsDelReq(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *xapp.RMRParams) {
489 tc.Info("RecvSubsDelReq")
490 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
492 //---------------------------------
493 // e2term activity: Recv Subs Del Req
494 //---------------------------------
495 msg := tc.WaitMsg(15)
497 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] {
498 tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_DEL_REQ", xapp.RicMessageTypeToName[msg.Mtype])
500 tc.Info("Recv Subs Del Req")
502 packedData := &e2ap.PackedData{}
503 packedData.Buf = msg.Payload
504 unpackerr, req := e2SubsDelReq.UnPack(packedData)
505 if unpackerr != nil {
506 tc.TestError(t, "RIC_SUB_DEL_REQ unpack failed err: %s", unpackerr.Error())
511 tc.TestError(t, "Not Received msg within %d secs", 15)
516 //-----------------------------------------------------------------------------
518 //-----------------------------------------------------------------------------
519 func (tc *E2Stub) SendSubsDelResp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapp.RMRParams) {
520 tc.Info("SendSubsDelResp")
521 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
523 //---------------------------------
524 // e2term activity: Send Subs Del Resp
525 //---------------------------------
526 resp := &e2ap.E2APSubscriptionDeleteResponse{}
527 resp.RequestId.Id = req.RequestId.Id
528 resp.RequestId.InstanceId = req.RequestId.InstanceId
529 resp.FunctionId = req.FunctionId
531 packerr, packedMsg := e2SubsDelResp.Pack(resp)
533 tc.TestError(t, "pack NOK %s", packerr.Error())
535 tc.Debug("%s", e2SubsDelResp.String())
537 params := &xapp.RMRParams{}
538 params.Mtype = xapp.RIC_SUB_DEL_RESP
539 params.SubId = msg.SubId
540 params.Payload = packedMsg.Buf
541 params.PayloadLen = len(packedMsg.Buf)
542 params.Meid = msg.Meid
546 tc.Info("SEND SUB DEL RESP: %s", params.String())
547 snderr := tc.SendWithRetry(params, false, 5)
549 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
553 //-----------------------------------------------------------------------------
555 //-----------------------------------------------------------------------------
556 func (tc *E2Stub) RecvSubsDelResp(t *testing.T, trans *RmrTransactionId) {
557 tc.Info("RecvSubsDelResp")
558 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
560 //---------------------------------
561 // xapp activity: Recv Subs Del Resp
562 //---------------------------------
563 msg := tc.WaitMsg(15)
565 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
566 tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong mtype expected %s got %s, error", "RIC_SUB_DEL_RESP", xapp.RicMessageTypeToName[msg.Mtype])
568 } else if trans != nil && msg.Xid != trans.xid {
569 tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
572 packedData := &e2ap.PackedData{}
573 packedData.Buf = msg.Payload
574 unpackerr, resp := e2SubsDelResp.UnPack(packedData)
575 if unpackerr != nil {
576 tc.TestError(t, "RIC_SUB_DEL_RESP unpack failed err: %s", unpackerr.Error())
578 tc.Info("Recv Subs Del Resp rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
582 tc.TestError(t, "Not Received msg within %d secs", 15)
586 //-----------------------------------------------------------------------------
588 //-----------------------------------------------------------------------------
589 func (tc *E2Stub) SendSubsDelFail(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapp.RMRParams) {
590 tc.Info("SendSubsDelFail")
591 e2SubsDelFail := e2asnpacker.NewPackerSubscriptionDeleteFailure()
593 //---------------------------------
594 // e2term activity: Send Subs Del Fail
595 //---------------------------------
596 resp := &e2ap.E2APSubscriptionDeleteFailure{}
597 resp.RequestId.Id = req.RequestId.Id
598 resp.RequestId.InstanceId = req.RequestId.InstanceId
599 resp.FunctionId = req.FunctionId
600 resp.Cause.Content = 4 // CauseMisc
601 resp.Cause.Value = 3 // unspecified
603 packerr, packedMsg := e2SubsDelFail.Pack(resp)
605 tc.TestError(t, "pack NOK %s", packerr.Error())
607 tc.Debug("%s", e2SubsDelFail.String())
609 params := &xapp.RMRParams{}
610 params.Mtype = xapp.RIC_SUB_DEL_FAILURE
611 params.SubId = msg.SubId
612 params.Payload = packedMsg.Buf
613 params.PayloadLen = len(packedMsg.Buf)
614 params.Meid = msg.Meid
618 tc.Info("SEND SUB DEL FAIL: %s", params.String())
619 snderr := tc.SendWithRetry(params, false, 5)
621 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
625 // REST code below all
627 /*****************************************************************************/
628 // REST interface specific functions are below
630 //-----------------------------------------------------------------------------
631 // Callback handler for subscription response notifications
632 //-----------------------------------------------------------------------------
633 func (tc *E2Stub) SubscriptionRespHandler(resp *clientmodel.SubscriptionResponse) {
634 if tc.subscriptionId == "SUBSCRIPTIONID NOT SET" {
635 tc.Info("REST notification received for %v while no SubscriptionID was not set for InstanceID=%v, RequestorID=%v (%v)",
636 *resp.SubscriptionID, *resp.SubscriptionInstances[0].InstanceID, *resp.SubscriptionInstances[0].RequestorID, tc)
637 tc.CallBackNotification <- *resp.SubscriptionInstances[0].InstanceID
638 } else if tc.subscriptionId == *resp.SubscriptionID {
639 tc.Info("REST notification received SubscriptionID=%s, InstanceID=%v, RequestorID=%v (%v)",
640 *resp.SubscriptionID, *resp.SubscriptionInstances[0].InstanceID, *resp.SubscriptionInstances[0].RequestorID, tc)
641 tc.CallBackNotification <- *resp.SubscriptionInstances[0].InstanceID
643 tc.Info("MISMATCHING REST notification received SubscriptionID=%s<>%s, InstanceID=%v, RequestorID=%v (%v)",
644 tc.subscriptionId, *resp.SubscriptionID, *resp.SubscriptionInstances[0].InstanceID, *resp.SubscriptionInstances[0].RequestorID, tc)
648 //-----------------------------------------------------------------------------
650 //-----------------------------------------------------------------------------
651 func (tc *E2Stub) ExpectRESTNotification(t *testing.T, restSubsId string) {
653 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)
654 tc.restSubsIdList = []string{restSubsId}
655 xapp.Subscription.SetResponseCB(tc.ListedRestNotifHandler)
656 if tc.requestCount == 0 {
657 tc.TestError(t, "### NO REST notifications SET received for endpoint=%s, request zount ZERO! (%v)", tc.clientEndpoint, tc)
661 case e2Ids := <-tc.CallBackListedNotifications:
662 if tc.requestCount == 0 {
663 tc.TestError(t, "### REST notification count unexpectedly ZERO for %s (%v)", restSubsId, tc)
664 } else if e2Ids.RestSubsId != restSubsId {
665 tc.TestError(t, "### Unexpected REST notifications received |%s:%s| (%v)", e2Ids.RestSubsId, restSubsId, tc)
668 if tc.requestCount == 0 {
669 tc.Info("### All expected REST notifications received for %s (%v)", e2Ids.RestSubsId, tc)
671 tc.Info("### Expected REST notifications received for %s, (%v)", e2Ids.RestSubsId, tc)
673 tc.Info("### REST Notification received Notif for %s : %v", e2Ids.RestSubsId, e2Ids.E2SubsId)
674 tc.ListedRESTNotifications <- e2Ids
676 case <-time.After(15 * time.Second):
677 err := fmt.Errorf("### Timeout 15s expired while expecting REST notification for subsId: %v", restSubsId)
678 tc.TestError(t, "%s", err.Error())
683 func (tc *E2Stub) WaitRESTNotification(t *testing.T, restSubsId string) uint32 {
685 case e2SubsId := <-tc.ListedRESTNotifications:
686 if e2SubsId.RestSubsId == restSubsId {
687 tc.Info("### Expected REST notifications received %s, e2SubsId %v for endpoint=%s, (%v)", e2SubsId.RestSubsId, e2SubsId.E2SubsId, tc.clientEndpoint, tc)
688 return e2SubsId.E2SubsId
690 tc.TestError(t, "### Unexpected REST notifications received %s, expected %s for endpoint=%s, (%v)", e2SubsId.RestSubsId, restSubsId, tc.clientEndpoint, tc)
693 case <-time.After(15 * time.Second):
694 err := fmt.Errorf("### Timeout 15s expired while waiting REST notification for subsId: %v", restSubsId)
695 tc.TestError(t, "%s", err.Error())
696 panic("WaitRESTNotification - timeout error")
701 func (tc *E2Stub) WaitRESTNotificationForAnySubscriptionId(t *testing.T) {
703 tc.Info("### REST notifications received for endpoint=%s, (%v)", tc.clientEndpoint, tc)
705 case e2SubsId := <-tc.CallBackNotification:
706 tc.Info("### REST notifications received e2SubsId %v for endpoint=%s, (%v)", e2SubsId, tc.clientEndpoint, tc)
707 tc.RESTNotification <- (uint32)(e2SubsId)
708 case <-time.After(15 * time.Second):
709 err := fmt.Errorf("### Timeout 15s expired while waiting REST notification")
710 tc.TestError(t, "%s", err.Error())
711 tc.RESTNotification <- 0
716 func (tc *E2Stub) ListedRestNotifHandler(resp *clientmodel.SubscriptionResponse) {
718 if len(tc.restSubsIdList) == 0 {
719 tc.Error("Unexpected listed REST notifications received for endpoint=%s, expected restSubsId list size was ZERO!", tc.clientEndpoint)
721 for i, subsId := range tc.restSubsIdList {
722 if *resp.SubscriptionID == subsId {
723 //tc.Info("Listed REST notifications received SubscriptionID=%s, InstanceID=%v, RequestorID=%v",
724 // *resp.SubscriptionID, *resp.SubscriptionInstances[0].InstanceID, *resp.SubscriptionInstances[0].RequestorID)
726 tc.restSubsIdList = append(tc.restSubsIdList[:i], tc.restSubsIdList[i+1:]...)
727 //tc.Info("Removed %s from Listed REST notifications, %v entries left", *resp.SubscriptionID, len(tc.restSubsIdList))
729 tc.CallBackListedNotifications <- E2RestIds{*resp.SubscriptionID, uint32(*resp.SubscriptionInstances[0].InstanceID)}
731 if len(tc.restSubsIdList) == 0 {
732 //tc.Info("All listed REST notifications received for endpoint=%s", tc.clientEndpoint)
738 tc.Error("UNKONWN REST notification received SubscriptionID=%s<>%s, InstanceID=%v, RequestorID=%v (%v)",
739 tc.subscriptionId, *resp.SubscriptionID, *resp.SubscriptionInstances[0].InstanceID, *resp.SubscriptionInstances[0].RequestorID, tc)
743 //-----------------------------------------------------------------------------
745 //-----------------------------------------------------------------------------
746 func (tc *E2Stub) WaitListedRestNotifications(t *testing.T, restSubsIds []string) {
747 tc.Info("Started to wait REST notifications %v on port %v f(RMR port %v)", restSubsIds, *tc.clientEndpoint.HTTPPort, *tc.clientEndpoint.RMRPort)
749 tc.restSubsIdList = restSubsIds
750 xapp.Subscription.SetResponseCB(tc.ListedRestNotifHandler)
752 for i := 0; i < len(restSubsIds); i++ {
755 case e2Ids := <-tc.CallBackListedNotifications:
756 tc.Info("Listed Notification waiter received Notif for %s : %v", e2Ids.RestSubsId, e2Ids.E2SubsId)
757 tc.ListedRESTNotifications <- e2Ids
758 case <-time.After(15 * time.Second):
759 err := fmt.Errorf("Timeout 15s expired while waiting Listed REST notification")
760 tc.TestError(t, "%s", err.Error())
761 tc.RESTNotification <- 0
767 //-----------------------------------------------------------------------------
769 //-----------------------------------------------------------------------------
770 func (tc *E2Stub) SendRESTSubsReq(t *testing.T, params *RESTSubsReqParams) string { // This need to be edited according to new specification
771 tc.Info("======== Posting REST Report subscriptions to Submgr ======")
774 tc.Info("SendRESTReportSubsReq: params == nil")
778 tc.subscriptionId = "SUBSCIPTIONID NOT SET"
780 resp, err := xapp.Subscription.Subscribe(¶ms.SubsReqParams)
782 // Swagger generated code makes checks for the values that are inserted the subscription function
783 // If error cause is unknown and POST is not done, the problem is in the inserted values
784 tc.Error("======== REST report subscriptions failed %s ========", err.Error())
787 tc.subscriptionId = *resp.SubscriptionID
788 tc.Info("======== REST report subscriptions posted successfully. SubscriptionID = %s, RequestCount = %v ========", *resp.SubscriptionID, tc.requestCount)
789 return *resp.SubscriptionID
792 //-----------------------------------------------------------------------------
794 //-----------------------------------------------------------------------------
795 func (tc *E2Stub) GetRESTSubsReqReportParams(subReqCount int, parameterSet int, actionDefinitionPresent bool, actionParamCount int) *RESTSubsReqParams {
797 reportParams := RESTSubsReqParams{}
798 if parameterSet == 1 {
799 reportParams.GetRESTSubsReqReportParams1(subReqCount, actionDefinitionPresent, actionParamCount, &tc.clientEndpoint, &tc.meid)
800 } else if parameterSet == 2 {
803 tc.Error("Invalid parameterSet=%v", parameterSet)
805 tc.requestCount = subReqCount
809 //-----------------------------------------------------------------------------
811 //-----------------------------------------------------------------------------
812 func (tc *E2Stub) GetRESTSubsReqReportParams1(subReqCount int, actionDefinitionPresent bool, actionParamCount int) *RESTSubsReqParams {
814 reportParams := RESTSubsReqParams{}
815 reportParams.GetRESTSubsReqReportParams1(subReqCount, actionDefinitionPresent, actionParamCount, &tc.clientEndpoint, &tc.meid)
816 tc.requestCount = subReqCount
820 //-----------------------------------------------------------------------------
822 //-----------------------------------------------------------------------------
823 type RESTSubsReqParams struct {
824 SubsReqParams clientmodel.SubscriptionParams
827 func (p *RESTSubsReqParams) GetRESTSubsReqReportParams1(subReqCount int, actionDefinitionPresent bool, actionParamCount int, clientEndpoint *clientmodel.SubscriptionParamsClientEndpoint, meid *string) {
830 p.SubsReqParams.ClientEndpoint = clientEndpoint
831 p.SubsReqParams.Meid = meid
832 var rANFunctionID int64 = 33
833 p.SubsReqParams.RANFunctionID = &rANFunctionID
838 actionType := "report"
839 subsequestActioType := "continue"
840 timeToWait := "w10ms"
842 for requestCount := 0; requestCount < subReqCount; requestCount++ {
843 reqId := int64(requestCount) + 1
844 seqId := int64(requestCount) + 1
845 subscriptionDetail := &clientmodel.SubscriptionDetail{
848 EventTriggers: &clientmodel.EventTriggerDefinition{
849 OctetString: "1234" + strconv.Itoa(requestCount),
851 ActionToBeSetupList: clientmodel.ActionsToBeSetup{
852 &clientmodel.ActionToBeSetup{
854 ActionType: &actionType,
855 ActionDefinition: &clientmodel.ActionDefinition{
856 OctetString: "5678" + strconv.Itoa(requestCount),
858 SubsequentAction: &clientmodel.SubsequentAction{
859 SubsequentActionType: &subsequestActioType,
860 TimeToWait: &timeToWait,
865 p.SubsReqParams.SubscriptionDetails = append(p.SubsReqParams.SubscriptionDetails, subscriptionDetail)
870 func (p *RESTSubsReqParams) SetMeid(MEID string) {
871 p.SubsReqParams.Meid = &MEID
874 func (p *RESTSubsReqParams) SetEndpoint(HTTP_port int64, RMR_port int64, host string) {
875 var endpoint clientmodel.SubscriptionParamsClientEndpoint
876 endpoint.HTTPPort = &HTTP_port
877 endpoint.RMRPort = &RMR_port
879 p.SubsReqParams.ClientEndpoint = &endpoint
882 func (p *RESTSubsReqParams) SetEndpointHost(host string) {
884 if p.SubsReqParams.ClientEndpoint.Host != "" {
885 if p.SubsReqParams.ClientEndpoint.Host != host {
886 // Renaming toto, print something tc.Info("Posting REST subscription request to Submgr")
887 err := fmt.Errorf("hostname change attempt: %s -> %s", p.SubsReqParams.ClientEndpoint.Host, host)
891 p.SubsReqParams.ClientEndpoint.Host = host
894 func (p *RESTSubsReqParams) SetHTTPEndpoint(HTTP_port int64, host string) {
896 p.SubsReqParams.ClientEndpoint.HTTPPort = &HTTP_port
898 p.SetEndpointHost(host)
900 if p.SubsReqParams.ClientEndpoint.RMRPort == nil {
902 p.SubsReqParams.ClientEndpoint.RMRPort = &RMR_port
906 func (p *RESTSubsReqParams) SetSubActionTypes(actionType string) {
908 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
909 for _, action := range subDetail.ActionToBeSetupList {
911 action.ActionType = &actionType
917 func (p *RESTSubsReqParams) SetSubActionIDs(actionId int64) {
919 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
920 for _, action := range subDetail.ActionToBeSetupList {
922 action.ActionID = &actionId
928 func (p *RESTSubsReqParams) SetSubActionDefinition(actionDefinition string) {
930 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
931 for _, action := range subDetail.ActionToBeSetupList {
933 action.ActionDefinition.OctetString = actionDefinition
939 func (p *RESTSubsReqParams) SetSubEventTriggerDefinition(eventTriggerDefinition string) {
941 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
942 if subDetail != nil {
943 subDetail.EventTriggers.OctetString = eventTriggerDefinition
948 func (p *RESTSubsReqParams) AppendActionToActionToBeSetupList(actionId int64, actionType string, actionDefinition string, subsequentActionType string, timeToWait string) {
950 actionToBeSetup := &clientmodel.ActionToBeSetup{
952 ActionType: &actionType,
953 ActionDefinition: &clientmodel.ActionDefinition{
954 OctetString: actionDefinition,
956 SubsequentAction: &clientmodel.SubsequentAction{
957 SubsequentActionType: &subsequentActionType,
958 TimeToWait: &timeToWait,
962 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
963 if subDetail != nil {
964 subDetail.ActionToBeSetupList = append(subDetail.ActionToBeSetupList, actionToBeSetup)
969 func (p *RESTSubsReqParams) SetRMREndpoint(RMR_port int64, host string) {
971 p.SubsReqParams.ClientEndpoint.RMRPort = &RMR_port
973 p.SetEndpointHost(host)
975 if p.SubsReqParams.ClientEndpoint.HTTPPort == nil {
977 p.SubsReqParams.ClientEndpoint.HTTPPort = &HTTP_port
981 func (p *RESTSubsReqParams) SetTimeToWait(timeToWait string) {
983 for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
984 for _, action := range subDetail.ActionToBeSetupList {
985 if action != nil && action.SubsequentAction != nil {
986 action.SubsequentAction.TimeToWait = &timeToWait
992 //-----------------------------------------------------------------------------
994 //-----------------------------------------------------------------------------
995 func (tc *E2Stub) SendRESTSubsDelReq(t *testing.T, subscriptionID *string) {
997 if *subscriptionID == "" {
998 tc.Error("REST error in deleting subscriptions. Empty SubscriptionID = %s", *subscriptionID)
1000 tc.Info("REST deleting E2 subscriptions. SubscriptionID = %s", *subscriptionID)
1002 err := xapp.Subscription.Unsubscribe(*subscriptionID)
1004 tc.Error("REST Delete subscription failed %s", err.Error())
1006 tc.Info("REST delete subscription pushed to submgr successfully. SubscriptionID = %s", *subscriptionID)
1009 //-----------------------------------------------------------------------------
1011 //-----------------------------------------------------------------------------
1012 func (tc *E2Stub) GetRESTSubsReqPolicyParams(subReqCount int, actionDefinitionPresent bool, policyParamCount int) *RESTSubsReqParams {
1014 policyParams := RESTSubsReqParams{}
1015 policyParams.GetRESTSubsReqPolicyParams(subReqCount, actionDefinitionPresent, policyParamCount, &tc.clientEndpoint, &tc.meid)
1016 tc.requestCount = subReqCount
1017 return &policyParams
1020 //-----------------------------------------------------------------------------
1022 //-----------------------------------------------------------------------------
1023 func (p *RESTSubsReqParams) GetRESTSubsReqPolicyParams(subReqCount int, actionDefinitionPresent bool, policyParamCount int, clientEndpoint *clientmodel.SubscriptionParamsClientEndpoint, meid *string) {
1025 p.SubsReqParams.ClientEndpoint = clientEndpoint
1026 p.SubsReqParams.Meid = meid
1027 var rANFunctionID int64 = 33
1028 p.SubsReqParams.RANFunctionID = &rANFunctionID
1030 // reqId := int64(1)
1032 actionId := int64(1)
1033 actionType := "policy"
1034 subsequestActioType := "continue"
1035 timeToWait := "w10ms"
1037 for requestCount := 0; requestCount < subReqCount; requestCount++ {
1038 reqId := int64(requestCount) + 1
1040 subscriptionDetail := &clientmodel.SubscriptionDetail{
1041 RequestorID: &reqId,
1043 EventTriggers: &clientmodel.EventTriggerDefinition{
1044 OctetString: "1234" + strconv.Itoa(requestCount),
1046 ActionToBeSetupList: clientmodel.ActionsToBeSetup{
1047 &clientmodel.ActionToBeSetup{
1048 ActionID: &actionId,
1049 ActionType: &actionType,
1050 ActionDefinition: &clientmodel.ActionDefinition{
1051 OctetString: "5678" + strconv.Itoa(requestCount),
1053 SubsequentAction: &clientmodel.SubsequentAction{
1054 SubsequentActionType: &subsequestActioType,
1055 TimeToWait: &timeToWait,
1060 p.SubsReqParams.SubscriptionDetails = append(p.SubsReqParams.SubscriptionDetails, subscriptionDetail)