72baf27c869603ffc3e75e63d7a6bd3d48939aa0
[ric-plt/submgr.git] / pkg / teststube2ap / stubE2.go
1 /*
2 ==================================================================================
3   Copyright (c) 2019 AT&T Intellectual Property.
4   Copyright (c) 2019 Nokia
5
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
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
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 ==================================================================================
18 */
19
20 package teststube2ap
21
22 import (
23         "fmt"
24         "runtime/debug"
25         "strconv"
26         "testing"
27         "time"
28
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"
34 )
35
36 //-----------------------------------------------------------------------------
37 //
38 //-----------------------------------------------------------------------------
39 var e2asnpacker e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
40
41 //-----------------------------------------------------------------------------
42 //
43 //-----------------------------------------------------------------------------
44 type RmrTransactionId struct {
45         xid  string
46         meid *xapp.RMRMeid
47 }
48
49 type E2RestIds struct {
50         RestSubsId string
51         E2SubsId   uint32
52         ErrorCause string
53 }
54
55 func (trans *RmrTransactionId) String() string {
56         meidstr := "N/A"
57         if trans.meid != nil {
58                 meidstr = trans.meid.String()
59         }
60         return "trans(" + trans.xid + "/" + meidstr + ")"
61 }
62
63 type E2Stub struct {
64         teststub.RmrStubControl
65         xid_seq                     uint64
66         subscriptionId              string
67         requestCount                int
68         CallBackNotification        chan int64
69         RESTNotification            chan uint32
70         CallBackListedNotifications chan E2RestIds
71         ListedRESTNotifications     chan E2RestIds
72         clientEndpoint              clientmodel.SubscriptionParamsClientEndpoint
73         meid                        string
74         restSubsIdList              []string
75 }
76
77 //-----------------------------------------------------------------------------
78 //
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 {
81         tc := &E2Stub{}
82         tc.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed)
83         tc.xid_seq = 1
84         tc.SetCheckXid(true)
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
90         endPoint.Host = host
91         endPoint.HTTPPort = &HTTPPort
92         endPoint.RMRPort = &RMRPort
93         tc.clientEndpoint = endPoint
94         tc.meid = ranName
95         return tc
96 }
97
98 //-----------------------------------------------------------------------------
99 //
100 //-----------------------------------------------------------------------------
101 func CreateNewE2termStub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int) *E2Stub {
102         tc := &E2Stub{}
103         tc.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed)
104         tc.xid_seq = 1
105         tc.SetCheckXid(false)
106         return tc
107 }
108
109 //-----------------------------------------------------------------------------
110 //
111 //-----------------------------------------------------------------------------
112 func (tc *E2Stub) NewRmrTransactionId(xid string, ranname string) *RmrTransactionId {
113         trans := &RmrTransactionId{}
114         if len(xid) == 0 {
115                 trans.xid = tc.GetDesc() + "_XID_" + strconv.FormatUint(uint64(tc.xid_seq), 10)
116                 tc.xid_seq++
117         } else {
118                 trans.xid = xid
119         }
120         trans.meid = &xapp.RMRMeid{RanName: ranname}
121         tc.Info("New test %s", trans.String())
122         return trans
123 }
124
125 //-----------------------------------------------------------------------------
126 //
127 //-----------------------------------------------------------------------------
128 type E2StubSubsReqParams struct {
129         Req *e2ap.E2APSubscriptionRequest
130 }
131
132 func (p *E2StubSubsReqParams) Init() {
133         p.Req = &e2ap.E2APSubscriptionRequest{}
134
135         p.Req.RequestId.Id = 1
136         p.Req.RequestId.InstanceId = 0
137         p.Req.FunctionId = 1
138
139         // gnb -> enb outgoing
140         // enb -> gnb incoming
141         // X2 36423-f40.doc
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
145
146         p.Req.ActionSetups = make([]e2ap.ActionToBeSetupItem, 1)
147
148         p.Req.ActionSetups[0].ActionId = 0
149         p.Req.ActionSetups[0].ActionType = e2ap.E2AP_ActionTypeReport
150         p.Req.ActionSetups[0].RicActionDefinitionPresent = true
151
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
155
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
159 }
160
161 //-----------------------------------------------------------------------------
162 //
163 //-----------------------------------------------------------------------------
164
165 type E2StubSubsFailParams struct {
166         Req  *e2ap.E2APSubscriptionRequest
167         Fail *e2ap.E2APSubscriptionFailure
168 }
169
170 func (p *E2StubSubsFailParams) Set(req *e2ap.E2APSubscriptionRequest) {
171         p.Req = req
172
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)
181         }
182 }
183
184 func (p *E2StubSubsFailParams) SetCauseVal(ind int, content uint8, causeval uint8) {
185
186         if ind < 0 {
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
190                 }
191                 return
192         }
193         p.Fail.ActionNotAdmittedList.Items[ind].Cause.Content = content
194         p.Fail.ActionNotAdmittedList.Items[ind].Cause.Value = causeval
195 }
196
197 //-----------------------------------------------------------------------------
198 //
199 //-----------------------------------------------------------------------------
200
201 func (tc *E2Stub) SendSubsReq(t *testing.T, rparams *E2StubSubsReqParams, oldTrans *RmrTransactionId) *RmrTransactionId {
202
203         trans := oldTrans
204         if oldTrans == nil {
205                 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
206         }
207
208         tc.Info("SendSubsReq %s", trans.String())
209         e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
210
211         //---------------------------------
212         // xapp activity: Send Subs Req
213         //---------------------------------
214         myparams := rparams
215
216         if myparams == nil {
217                 myparams = &E2StubSubsReqParams{}
218                 myparams.Init()
219         }
220
221         err, packedMsg := e2SubsReq.Pack(myparams.Req)
222         if err != nil {
223                 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
224                 return nil
225         }
226         tc.Debug("%s %s", trans.String(), e2SubsReq.String())
227
228         params := &xapp.RMRParams{}
229         params.Mtype = xapp.RIC_SUB_REQ
230         params.SubId = -1
231         params.Payload = packedMsg.Buf
232         params.PayloadLen = len(packedMsg.Buf)
233         params.Meid = trans.meid
234         params.Xid = trans.xid
235         params.Mbuf = nil
236
237         tc.Info("SEND SUB REQ: %s", params.String())
238         snderr := tc.SendWithRetry(params, false, 5)
239         if snderr != nil {
240                 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
241                 return nil
242         }
243         return trans
244 }
245
246 //-----------------------------------------------------------------------------
247 //
248 //-----------------------------------------------------------------------------
249 func (tc *E2Stub) RecvSubsReq(t *testing.T) (*e2ap.E2APSubscriptionRequest, *xapp.RMRParams) {
250         tc.Info("RecvSubsReq")
251         e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
252
253         //---------------------------------
254         // e2term activity: Recv Subs Req
255         //---------------------------------
256         msg := tc.WaitMsg(15)
257         if msg != nil {
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])
260                 } else {
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())
267                         }
268                         return req, msg
269                 }
270         } else {
271                 tc.TestError(t, "Not Received msg within %d secs", 15)
272         }
273
274         return nil, nil
275 }
276
277 //-----------------------------------------------------------------------------
278 //
279 //-----------------------------------------------------------------------------
280 func (tc *E2Stub) SendSubsResp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *xapp.RMRParams) {
281         tc.Info("SendSubsResp")
282         e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
283
284         //---------------------------------
285         // e2term activity: Send Subs Resp
286         //---------------------------------
287         resp := &e2ap.E2APSubscriptionResponse{}
288
289         resp.RequestId.Id = req.RequestId.Id
290         resp.RequestId.InstanceId = req.RequestId.InstanceId
291         resp.FunctionId = req.FunctionId
292
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
296         }
297
298         for index := uint64(0); index < 1; index++ {
299                 item := e2ap.ActionNotAdmittedItem{}
300                 item.ActionId = index
301                 item.Cause.Content = 1
302                 item.Cause.Value = 1
303                 resp.ActionNotAdmittedList.Items = append(resp.ActionNotAdmittedList.Items, item)
304         }
305
306         packerr, packedMsg := e2SubsResp.Pack(resp)
307         if packerr != nil {
308                 tc.TestError(t, "pack NOK %s", packerr.Error())
309         }
310         tc.Debug("%s", e2SubsResp.String())
311
312         params := &xapp.RMRParams{}
313         params.Mtype = xapp.RIC_SUB_RESP
314         //params.SubId = msg.SubId
315         params.SubId = -1
316         params.Payload = packedMsg.Buf
317         params.PayloadLen = len(packedMsg.Buf)
318         params.Meid = msg.Meid
319         //params.Xid = msg.Xid
320         params.Mbuf = nil
321
322         tc.Info("SEND SUB RESP: %s", params.String())
323         snderr := tc.SendWithRetry(params, false, 5)
324         if snderr != nil {
325                 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
326         }
327 }
328
329 //-----------------------------------------------------------------------------
330 //
331 //-----------------------------------------------------------------------------
332 func (tc *E2Stub) SendInvalidE2Asn1Resp(t *testing.T, msg *xapp.RMRParams, msgType int) {
333
334         params := &xapp.RMRParams{}
335         params.Mtype = msgType
336         params.SubId = -1
337         params.Payload = []byte{1, 2, 3, 4, 5}
338         params.PayloadLen = 5
339         params.Meid = msg.Meid
340         params.Xid = ""
341         params.Mbuf = nil
342
343         if params.Mtype == xapp.RIC_SUB_RESP {
344                 tc.Info("SEND INVALID ASN.1 SUB RESP")
345
346         } else if params.Mtype == xapp.RIC_SUB_FAILURE {
347                 tc.Info("SEND INVALID ASN.1 SUB FAILURE")
348
349         } else if params.Mtype == xapp.RIC_SUB_DEL_RESP {
350                 tc.Info("SEND INVALID ASN.1 SUB DEL RESP")
351
352         } else if params.Mtype == xapp.RIC_SUB_DEL_FAILURE {
353                 tc.Info("SEND INVALID ASN.1 SUB DEL FAILURE")
354         }
355         snderr := tc.SendWithRetry(params, false, 5)
356         if snderr != nil {
357                 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
358         }
359 }
360
361 //-----------------------------------------------------------------------------
362 //
363 //-----------------------------------------------------------------------------
364 func (tc *E2Stub) RecvSubsResp(t *testing.T, trans *RmrTransactionId) uint32 {
365         tc.Info("RecvSubsResp")
366         e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
367         var e2SubsId uint32
368
369         //---------------------------------
370         // xapp activity: Recv Subs Resp
371         //---------------------------------
372         msg := tc.WaitMsg(15)
373         if msg != nil {
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])
376                         return 0
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)
379                         return 0
380                 } else {
381                         packedData := &e2ap.PackedData{}
382                         packedData.Buf = msg.Payload
383                         if msg.SubId > 0 {
384                                 e2SubsId = uint32(msg.SubId)
385                         } else {
386                                 e2SubsId = 0
387                         }
388                         unpackerr, resp := e2SubsResp.UnPack(packedData)
389                         if unpackerr != nil {
390                                 tc.TestError(t, "RIC_SUB_RESP unpack failed err: %s", unpackerr.Error())
391                         }
392                         tc.Info("Recv Subs Resp rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
393                         return e2SubsId
394                 }
395         } else {
396                 tc.TestError(t, "Not Received msg within %d secs", 15)
397         }
398         return 0
399 }
400
401 //-----------------------------------------------------------------------------
402 //
403 //-----------------------------------------------------------------------------
404
405 func (tc *E2Stub) SendSubsFail(t *testing.T, fparams *E2StubSubsFailParams, msg *xapp.RMRParams) {
406         tc.Info("SendSubsFail")
407         e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
408
409         //---------------------------------
410         // e2term activity: Send Subs Fail
411         //---------------------------------
412         packerr, packedMsg := e2SubsFail.Pack(fparams.Fail)
413         if packerr != nil {
414                 tc.TestError(t, "pack NOK %s", packerr.Error())
415         }
416         tc.Debug("%s", e2SubsFail.String())
417
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
424         params.Xid = msg.Xid
425         params.Mbuf = nil
426
427         tc.Info("SEND SUB FAIL: %s", params.String())
428         snderr := tc.SendWithRetry(params, false, 5)
429         if snderr != nil {
430                 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
431         }
432 }
433
434 //-----------------------------------------------------------------------------
435 //
436 //-----------------------------------------------------------------------------
437 func (tc *E2Stub) RecvSubsFail(t *testing.T, trans *RmrTransactionId) uint32 {
438         tc.Info("RecvSubsFail")
439         e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
440         var e2SubsId uint32
441
442         //-------------------------------
443         // xapp activity: Recv Subs Fail
444         //-------------------------------
445         msg := tc.WaitMsg(15)
446         if msg != nil {
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])
449                         return 0
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)
452                         return 0
453                 } else {
454                         packedData := &e2ap.PackedData{}
455                         packedData.Buf = msg.Payload
456                         if msg.SubId > 0 {
457                                 e2SubsId = uint32(msg.SubId)
458                         } else {
459                                 e2SubsId = 0
460                         }
461                         unpackerr, resp := e2SubsFail.UnPack(packedData)
462                         if unpackerr != nil {
463                                 tc.TestError(t, "RIC_SUB_FAILURE unpack failed err: %s", unpackerr.Error())
464                         }
465                         tc.Info("Recv Subs Fail rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
466                         return e2SubsId
467                 }
468         } else {
469                 tc.TestError(t, "Not Received msg within %d secs", 15)
470         }
471         return 0
472 }
473
474 //-----------------------------------------------------------------------------
475 //
476 //-----------------------------------------------------------------------------
477 func (tc *E2Stub) SendSubsDelReq(t *testing.T, oldTrans *RmrTransactionId, e2SubsId uint32) *RmrTransactionId {
478
479         trans := oldTrans
480         if oldTrans == nil {
481                 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
482         }
483
484         tc.Info("SendSubsDelReq %s", trans.String())
485         e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
486         //---------------------------------
487         // xapp activity: Send Subs Del Req
488         //---------------------------------
489         req := &e2ap.E2APSubscriptionDeleteRequest{}
490         req.RequestId.Id = 1
491         req.RequestId.InstanceId = e2SubsId
492         req.FunctionId = 1
493
494         err, packedMsg := e2SubsDelReq.Pack(req)
495         if err != nil {
496                 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
497                 return nil
498         }
499         tc.Debug("%s %s", trans.String(), e2SubsDelReq.String())
500
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
508         params.Mbuf = nil
509
510         tc.Info("SEND SUB DEL REQ: %s", params.String())
511         snderr := tc.SendWithRetry(params, false, 5)
512         if snderr != nil {
513                 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
514                 return nil
515         }
516         return trans
517 }
518
519 //-----------------------------------------------------------------------------
520 //
521 //-----------------------------------------------------------------------------
522 func (tc *E2Stub) RecvSubsDelReq(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *xapp.RMRParams) {
523         tc.Info("RecvSubsDelReq")
524         e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
525
526         //---------------------------------
527         // e2term activity: Recv Subs Del Req
528         //---------------------------------
529         msg := tc.WaitMsg(15)
530         if msg != nil {
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])
533                 } else {
534                         tc.Info("Recv Subs Del Req")
535
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())
541                         }
542                         return req, msg
543                 }
544         } else {
545                 tc.TestError(t, "Not Received msg within %d secs", 15)
546         }
547         return nil, nil
548 }
549
550 //-----------------------------------------------------------------------------
551 //
552 //-----------------------------------------------------------------------------
553 func (tc *E2Stub) SendSubsDelResp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapp.RMRParams) {
554         tc.Info("SendSubsDelResp")
555         e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
556
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
564
565         packerr, packedMsg := e2SubsDelResp.Pack(resp)
566         if packerr != nil {
567                 tc.TestError(t, "pack NOK %s", packerr.Error())
568         }
569         tc.Debug("%s", e2SubsDelResp.String())
570
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
577         params.Xid = msg.Xid
578         params.Mbuf = nil
579
580         tc.Info("SEND SUB DEL RESP: %s", params.String())
581         snderr := tc.SendWithRetry(params, false, 5)
582         if snderr != nil {
583                 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
584         }
585 }
586
587 //-----------------------------------------------------------------------------
588 //
589 //-----------------------------------------------------------------------------
590 func (tc *E2Stub) RecvSubsDelResp(t *testing.T, trans *RmrTransactionId) {
591         tc.Info("RecvSubsDelResp")
592         e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
593
594         //---------------------------------
595         // xapp activity: Recv Subs Del Resp
596         //---------------------------------
597         msg := tc.WaitMsg(15)
598         if msg != nil {
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])
601                         return
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)
604                         return
605                 } else {
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())
611                         }
612                         tc.Info("Recv Subs Del Resp rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
613                         return
614                 }
615         } else {
616                 tc.TestError(t, "Not Received msg within %d secs", 15)
617         }
618 }
619
620 //-----------------------------------------------------------------------------
621 //
622 //-----------------------------------------------------------------------------
623 func (tc *E2Stub) SendSubsDelFail(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapp.RMRParams) {
624         tc.Info("SendSubsDelFail")
625         e2SubsDelFail := e2asnpacker.NewPackerSubscriptionDeleteFailure()
626
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
636
637         packerr, packedMsg := e2SubsDelFail.Pack(resp)
638         if packerr != nil {
639                 tc.TestError(t, "pack NOK %s", packerr.Error())
640         }
641         tc.Debug("%s", e2SubsDelFail.String())
642
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
649         params.Xid = msg.Xid
650         params.Mbuf = nil
651
652         tc.Info("SEND SUB DEL FAIL: %s", params.String())
653         snderr := tc.SendWithRetry(params, false, 5)
654         if snderr != nil {
655                 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
656         }
657 }
658
659 // REST code below all
660
661 /*****************************************************************************/
662 // REST interface specific functions are below
663
664 //-----------------------------------------------------------------------------
665 // Callback handler for subscription response notifications
666 //-----------------------------------------------------------------------------
667 func (tc *E2Stub) SubscriptionRespHandler(resp *clientmodel.SubscriptionResponse) {
668
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
677         } else {
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)
680         }
681 }
682
683 //-----------------------------------------------------------------------------
684 //
685 //-----------------------------------------------------------------------------
686
687 func (tc *E2Stub) ExpectRESTNotification(t *testing.T, restSubsId string) {
688         tc.expectNotification(t, restSubsId, "")
689 }
690
691 func (tc *E2Stub) ExpectRESTNotificationOk(t *testing.T, restSubsId string) {
692         tc.expectNotification(t, restSubsId, "allOk")
693 }
694
695 func (tc *E2Stub) ExpectRESTNotificationNok(t *testing.T, restSubsId string, expectError string) {
696         tc.expectNotification(t, restSubsId, expectError)
697 }
698
699 func (tc *E2Stub) expectNotification(t *testing.T, restSubsId string, expectError string) {
700
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)
706         }
707         go func() {
708                 select {
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)
718                         } else {
719                                 tc.requestCount--
720                                 if tc.requestCount == 0 {
721                                         tc.Info("### All expected REST notifications received for %s (%v)", e2Ids.RestSubsId, tc)
722                                 } else {
723                                         tc.Info("### Expected REST notifications received for %s, (%v)", e2Ids.RestSubsId, tc)
724                                 }
725                                 if e2Ids.ErrorCause != "" && expectError == "allFail" {
726                                         tc.Info("### REST Notification: %s, ErrorCause: %v", e2Ids.RestSubsId, e2Ids.ErrorCause)
727                                 }
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")
732                                 }
733                         }
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())
737                 }
738         }()
739 }
740
741 func (tc *E2Stub) WaitRESTNotification(t *testing.T, restSubsId string) uint32 {
742
743         stack := string(debug.Stack())
744
745         select {
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
750                 } else {
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)
753                         return 0
754                 }
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")
760         }
761 }
762
763 // Note, this function should be followed by a handling of <-xappConn1.RESTNotification.
764 func (tc *E2Stub) ExpectAnyNotification(t *testing.T) {
765         go func() {
766                 tc.Info("### Started waiting ANY REST notifications received for endpoint=%s, (%v)", tc.clientEndpoint, tc)
767                 select {
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
775                 }
776         }()
777 }
778
779 func (tc *E2Stub) WaitAnyRESTNotification(t *testing.T) uint32 {
780
781         select {
782         case e2SubsId := <-tc.RESTNotification:
783                 tc.Info("### Expected ANY REST notification received - e2SubsId %v for endpoint=%s, (%v)", e2SubsId, tc.clientEndpoint, tc)
784                 return e2SubsId
785
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")
790         }
791 }
792
793 func (tc *E2Stub) ListedRestNotifHandler(resp *clientmodel.SubscriptionResponse) {
794
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)
797         } else {
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)
802
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))
805
806                                 if resp.SubscriptionInstances[0].ErrorCause != nil {
807                                         tc.CallBackListedNotifications <- E2RestIds{*resp.SubscriptionID, uint32(*resp.SubscriptionInstances[0].E2EventInstanceID), *resp.SubscriptionInstances[0].ErrorCause}
808                                 } else {
809                                         tc.CallBackListedNotifications <- E2RestIds{*resp.SubscriptionID, uint32(*resp.SubscriptionInstances[0].E2EventInstanceID), ""}
810                                 }
811
812                                 if len(tc.restSubsIdList) == 0 {
813                                         tc.Info("All listed REST notifications received for endpoint=%s", tc.clientEndpoint)
814                                 }
815
816                                 return
817                         }
818                 }
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)
821         }
822 }
823
824 //-----------------------------------------------------------------------------
825 //
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)
829
830         tc.restSubsIdList = restSubsIds
831         xapp.Subscription.SetResponseCB(tc.ListedRestNotifHandler)
832
833         for i := 0; i < len(restSubsIds); i++ {
834                 go func() {
835                         select {
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
843                         }
844                 }()
845         }
846 }
847
848 //-----------------------------------------------------------------------------
849 //
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 ======")
853
854         if params == nil {
855                 tc.Info("SendRESTReportSubsReq: params == nil")
856                 return ""
857         }
858
859         tc.subscriptionId = "SUBSCRIPTIONID NOT SET"
860
861         resp, err := xapp.Subscription.Subscribe(&params.SubsReqParams)
862         if err != nil {
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())
866                 return ""
867         }
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
871 }
872
873 //-----------------------------------------------------------------------------
874 //
875 //-----------------------------------------------------------------------------
876 func (tc *E2Stub) GetRESTSubsReqReportParams(subReqCount int) *RESTSubsReqParams {
877
878         reportParams := RESTSubsReqParams{}
879         reportParams.GetRESTSubsReqReportParams(subReqCount, &tc.clientEndpoint, &tc.meid)
880         tc.requestCount = subReqCount
881         return &reportParams
882 }
883
884 //-----------------------------------------------------------------------------
885 //
886 //-----------------------------------------------------------------------------
887 type RESTSubsReqParams struct {
888         SubsReqParams clientmodel.SubscriptionParams
889 }
890
891 func (p *RESTSubsReqParams) GetRESTSubsReqReportParams(subReqCount int, clientEndpoint *clientmodel.SubscriptionParamsClientEndpoint, meid *string) {
892
893         // E2SM-gNB-X2
894         p.SubsReqParams.ClientEndpoint = clientEndpoint
895         p.SubsReqParams.Meid = meid
896         var rANFunctionID int64 = 33
897         p.SubsReqParams.RANFunctionID = &rANFunctionID
898
899         //      reqId := int64(1)
900         //seqId := int64(1)
901         actionId := int64(1)
902         actionType := "report"
903         subsequestActioType := "continue"
904         timeToWait := "w10ms"
905
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),
912                         },
913                         ActionToBeSetupList: clientmodel.ActionsToBeSetup{
914                                 &clientmodel.ActionToBeSetup{
915                                         ActionID:   &actionId,
916                                         ActionType: &actionType,
917                                         ActionDefinition: clientmodel.ActionDefinition{
918                                                 int64(5678 + requestCount),
919                                         },
920                                         SubsequentAction: &clientmodel.SubsequentAction{
921                                                 SubsequentActionType: &subsequestActioType,
922                                                 TimeToWait:           &timeToWait,
923                                         },
924                                 },
925                         },
926                 }
927                 p.SubsReqParams.SubscriptionDetails = append(p.SubsReqParams.SubscriptionDetails, subscriptionDetail)
928         }
929
930 }
931
932 func (p *RESTSubsReqParams) SetMeid(MEID string) {
933         p.SubsReqParams.Meid = &MEID
934 }
935
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
940         endpoint.Host = host
941         p.SubsReqParams.ClientEndpoint = &endpoint
942 }
943
944 func (p *RESTSubsReqParams) SetEndpointHost(host string) {
945
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)
950                         panic(err)
951                 }
952         }
953         p.SubsReqParams.ClientEndpoint.Host = host
954 }
955
956 func (p *RESTSubsReqParams) SetHTTPEndpoint(HTTP_port int64, host string) {
957
958         p.SubsReqParams.ClientEndpoint.HTTPPort = &HTTP_port
959
960         p.SetEndpointHost(host)
961
962         if p.SubsReqParams.ClientEndpoint.RMRPort == nil {
963                 var RMR_port int64
964                 p.SubsReqParams.ClientEndpoint.RMRPort = &RMR_port
965         }
966 }
967
968 func (p *RESTSubsReqParams) SetSubActionTypes(actionType string) {
969
970         for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
971                 for _, action := range subDetail.ActionToBeSetupList {
972                         if action != nil {
973                                 action.ActionType = &actionType
974                         }
975                 }
976         }
977 }
978
979 func (p *RESTSubsReqParams) SetSubActionIDs(actionId int64) {
980
981         for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
982                 for _, action := range subDetail.ActionToBeSetupList {
983                         if action != nil {
984                                 action.ActionID = &actionId
985                         }
986                 }
987         }
988 }
989
990 func (p *RESTSubsReqParams) SetSubActionDefinition(actionDefinition []int64) {
991
992         for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
993                 for _, action := range subDetail.ActionToBeSetupList {
994                         if action != nil {
995                                 action.ActionDefinition = actionDefinition
996                         }
997                 }
998         }
999 }
1000
1001 func (p *RESTSubsReqParams) SetSubEventTriggerDefinition(eventTriggerDefinition []int64) {
1002
1003         for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1004                 if subDetail != nil {
1005                         subDetail.EventTriggers = eventTriggerDefinition
1006                 }
1007         }
1008 }
1009
1010 func (p *RESTSubsReqParams) AppendActionToActionToBeSetupList(actionId int64, actionType string, actionDefinition []int64, subsequentActionType string, timeToWait string) {
1011
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,
1019                 },
1020         }
1021
1022         for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
1023                 if subDetail != nil {
1024                         subDetail.ActionToBeSetupList = append(subDetail.ActionToBeSetupList, actionToBeSetup)
1025                 }
1026         }
1027 }
1028
1029 func (p *RESTSubsReqParams) SetRMREndpoint(RMR_port int64, host string) {
1030
1031         p.SubsReqParams.ClientEndpoint.RMRPort = &RMR_port
1032
1033         p.SetEndpointHost(host)
1034
1035         if p.SubsReqParams.ClientEndpoint.HTTPPort == nil {
1036                 var HTTP_port int64
1037                 p.SubsReqParams.ClientEndpoint.HTTPPort = &HTTP_port
1038         }
1039 }
1040
1041 func (p *RESTSubsReqParams) SetTimeToWait(timeToWait string) {
1042
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
1047                         }
1048                 }
1049         }
1050 }
1051
1052 func (p *RESTSubsReqParams) SetSubscriptionID(SubscriptionID *string) {
1053
1054         if *SubscriptionID == "" {
1055                 return
1056         }
1057         p.SubsReqParams.SubscriptionID = *SubscriptionID
1058 }
1059
1060 //-----------------------------------------------------------------------------
1061 //
1062 //-----------------------------------------------------------------------------
1063 func (tc *E2Stub) SendRESTSubsDelReq(t *testing.T, subscriptionID *string) {
1064
1065         tc.Info("======== Posting REST DELETE subscription(s) to Submgr ======")
1066
1067         if *subscriptionID == "" {
1068                 tc.Error("REST error in deleting subscriptions. Empty SubscriptionID = %s", *subscriptionID)
1069         }
1070         tc.Info("REST deleting E2 subscriptions. SubscriptionID = %s", *subscriptionID)
1071
1072         err := xapp.Subscription.Unsubscribe(*subscriptionID)
1073         if err != nil {
1074                 tc.Error("REST Delete subscription failed %s", err.Error())
1075         }
1076         tc.Info("REST delete subscription pushed to submgr successfully. SubscriptionID = %s", *subscriptionID)
1077 }
1078
1079 //-----------------------------------------------------------------------------
1080 //
1081 //-----------------------------------------------------------------------------
1082 func (tc *E2Stub) GetRESTSubsReqPolicyParams(subReqCount int) *RESTSubsReqParams {
1083
1084         policyParams := RESTSubsReqParams{}
1085         policyParams.GetRESTSubsReqPolicyParams(subReqCount, &tc.clientEndpoint, &tc.meid)
1086         tc.requestCount = subReqCount
1087         return &policyParams
1088 }
1089
1090 //-----------------------------------------------------------------------------
1091 //
1092 //-----------------------------------------------------------------------------
1093 func (tc *E2Stub) DecrementRequestCount() {
1094         if tc.requestCount > 0 {
1095                 tc.requestCount -= 1
1096         } else {
1097                 tc.Error("FAILED to decrement request count, count already ZERO")
1098         }
1099 }
1100
1101 //-----------------------------------------------------------------------------
1102 //
1103 //-----------------------------------------------------------------------------
1104 func (p *RESTSubsReqParams) GetRESTSubsReqPolicyParams(subReqCount int, clientEndpoint *clientmodel.SubscriptionParamsClientEndpoint, meid *string) {
1105
1106         p.SubsReqParams.ClientEndpoint = clientEndpoint
1107         p.SubsReqParams.Meid = meid
1108         var rANFunctionID int64 = 33
1109         p.SubsReqParams.RANFunctionID = &rANFunctionID
1110
1111         //      reqId := int64(1)
1112         //seqId := int64(1)
1113         actionId := int64(1)
1114         actionType := "policy"
1115         subsequestActioType := "continue"
1116         timeToWait := "w10ms"
1117
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),
1124                         },
1125                         ActionToBeSetupList: clientmodel.ActionsToBeSetup{
1126                                 &clientmodel.ActionToBeSetup{
1127                                         ActionID:   &actionId,
1128                                         ActionType: &actionType,
1129                                         ActionDefinition: clientmodel.ActionDefinition{
1130                                                 int64(5678 + requestCount),
1131                                         },
1132                                         SubsequentAction: &clientmodel.SubsequentAction{
1133                                                 SubsequentActionType: &subsequestActioType,
1134                                                 TimeToWait:           &timeToWait,
1135                                         },
1136                                 },
1137                         },
1138                 }
1139                 p.SubsReqParams.SubscriptionDetails = append(p.SubsReqParams.SubscriptionDetails, subscriptionDetail)
1140         }
1141
1142 }