Merge newe2 into master
[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         "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
24         "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap_wrapper"
25         "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub"
26         "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/xapptweaks"
27         "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
28         "strconv"
29         "testing"
30 )
31
32 //-----------------------------------------------------------------------------
33 //
34 //-----------------------------------------------------------------------------
35 var e2asnpacker e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
36
37 //-----------------------------------------------------------------------------
38 //
39 //-----------------------------------------------------------------------------
40 type RmrTransactionId struct {
41         xid  string
42         meid *xapp.RMRMeid
43 }
44
45 func (trans *RmrTransactionId) String() string {
46         return "trans(" + trans.xid + "/" + (&xapptweaks.RMRMeid{trans.meid}).String() + ")"
47 }
48
49 type E2Stub struct {
50         teststub.RmrStubControl
51         xid_seq uint64
52 }
53
54 //-----------------------------------------------------------------------------
55 //
56 //-----------------------------------------------------------------------------
57 func CreateNewE2Stub(desc string, rtfile string, port uint16, rtport uint16, stat string, mtypeseed int) *E2Stub {
58         tc := &E2Stub{}
59         tc.RmrStubControl.Init(desc, rtfile, port, rtport, stat, mtypeseed)
60         tc.xid_seq = 1
61         tc.SetCheckXid(true)
62         return tc
63 }
64
65 //-----------------------------------------------------------------------------
66 //
67 //-----------------------------------------------------------------------------
68 func CreateNewE2termStub(desc string, rtfile string, port uint16, rtport uint16, stat string, mtypeseed int) *E2Stub {
69         tc := &E2Stub{}
70         tc.RmrStubControl.Init(desc, rtfile, port, rtport, stat, mtypeseed)
71         tc.xid_seq = 1
72         tc.SetCheckXid(false)
73         return tc
74 }
75
76 //-----------------------------------------------------------------------------
77 //
78 //-----------------------------------------------------------------------------
79 func (tc *E2Stub) NewRmrTransactionId(xid string, ranname string) *RmrTransactionId {
80         trans := &RmrTransactionId{}
81         if len(xid) == 0 {
82                 trans.xid = tc.GetDesc() + "_XID_" + strconv.FormatUint(uint64(tc.xid_seq), 10)
83                 tc.xid_seq++
84         } else {
85                 trans.xid = xid
86         }
87         trans.meid = &xapp.RMRMeid{RanName: ranname}
88         tc.Logger.Info("New test %s", trans.String())
89         return trans
90 }
91
92 //-----------------------------------------------------------------------------
93 //
94 //-----------------------------------------------------------------------------
95 type E2StubSubsReqParams struct {
96         Req *e2ap.E2APSubscriptionRequest
97 }
98
99 func (p *E2StubSubsReqParams) Init() {
100         p.Req = &e2ap.E2APSubscriptionRequest{}
101
102         p.Req.RequestId.Id = 1
103         p.Req.RequestId.InstanceId = 0
104         p.Req.FunctionId = 1
105
106         // gnb -> enb outgoing
107         // enb -> gnb incoming
108         // X2 36423-f40.doc
109         p.Req.EventTriggerDefinition.NBX2EventTriggerDefinitionPresent = true
110         p.Req.EventTriggerDefinition.NBNRTEventTriggerDefinitionPresent = false
111         if p.Req.EventTriggerDefinition.NBX2EventTriggerDefinitionPresent == true {
112                 p.Req.EventTriggerDefinition.InterfaceId.GlobalEnbId.Present = true
113                 p.Req.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.Set("310150")
114                 p.Req.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId.Id = 123
115                 p.Req.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId.Bits = e2ap.E2AP_ENBIDHomeBits28
116
117                 p.Req.EventTriggerDefinition.InterfaceDirection = e2ap.E2AP_InterfaceDirectionIncoming
118                 p.Req.EventTriggerDefinition.ProcedureCode = 5 //28 35
119                 p.Req.EventTriggerDefinition.TypeOfMessage = e2ap.E2AP_InitiatingMessage
120         } else if p.Req.EventTriggerDefinition.NBNRTEventTriggerDefinitionPresent == true {
121                 p.Req.EventTriggerDefinition.NBNRTEventTriggerDefinition.TriggerNature = e2ap.NRTTriggerNature_now
122         }
123
124         p.Req.ActionSetups = make([]e2ap.ActionToBeSetupItem, 1)
125
126         p.Req.ActionSetups[0].ActionId = 0
127         p.Req.ActionSetups[0].ActionType = e2ap.E2AP_ActionTypeReport
128         p.Req.ActionSetups[0].RicActionDefinitionPresent = true
129         p.Req.ActionSetups[0].ActionDefinitionChoice.ActionDefinitionX2Format1Present = false
130         p.Req.ActionSetups[0].ActionDefinitionChoice.ActionDefinitionX2Format2Present = true
131         p.Req.ActionSetups[0].ActionDefinitionChoice.ActionDefinitionNRTFormat1Present = false
132
133         if p.Req.ActionSetups[0].ActionDefinitionChoice.ActionDefinitionX2Format1Present {
134                 p.Req.ActionSetups[0].ActionDefinitionChoice.ActionDefinitionX2Format1.StyleID = 99
135                 // 1..255
136                 for index := 0; index < 1; index++ {
137                         actionParameterItem := e2ap.ActionParameterItem{}
138                         actionParameterItem.ParameterID = 11
139                         actionParameterItem.ActionParameterValue.ValueIntPresent = true
140                         actionParameterItem.ActionParameterValue.ValueInt = 100
141                         p.Req.ActionSetups[0].ActionDefinitionChoice.ActionDefinitionX2Format1.ActionParameterItems =
142                                 append(p.Req.ActionSetups[0].ActionDefinitionChoice.ActionDefinitionX2Format1.ActionParameterItems, actionParameterItem)
143                 }
144         } else if p.Req.ActionSetups[0].ActionDefinitionChoice.ActionDefinitionX2Format2Present {
145                 // 1..15
146                 for index := 0; index < 1; index++ {
147                         ranUEgroupItem := e2ap.RANueGroupItem{}
148                         // 1..255
149                         for index2 := 0; index2 < 1; index2++ {
150                                 ranUEGroupDefItem := e2ap.RANueGroupDefItem{}
151                                 ranUEGroupDefItem.RanParameterID = 22
152                                 ranUEGroupDefItem.RanParameterTest = e2ap.RANParameterTest_equal
153                                 ranUEGroupDefItem.RanParameterValue.ValueIntPresent = true
154                                 ranUEGroupDefItem.RanParameterValue.ValueInt = 100
155                                 ranUEgroupItem.RanUEgroupDefinition.RanUEGroupDefItems = append(ranUEgroupItem.RanUEgroupDefinition.RanUEGroupDefItems, ranUEGroupDefItem)
156                         }
157                         // 1..255
158                         for index3 := 0; index3 < 1; index3++ {
159                                 ranParameterItem := e2ap.RANParameterItem{}
160                                 ranParameterItem.RanParameterID = 33
161                                 ranParameterItem.RanParameterValue.ValueIntPresent = true
162                                 ranParameterItem.RanParameterValue.ValueInt = 100
163                                 ranUEgroupItem.RanPolicy.RanParameterItems = append(ranUEgroupItem.RanPolicy.RanParameterItems, ranParameterItem)
164                         }
165                         ranUEgroupItem.RanUEgroupID = 2
166                         p.Req.ActionSetups[0].ActionDefinitionChoice.ActionDefinitionX2Format2.RanUEgroupItems =
167                                 append(p.Req.ActionSetups[0].ActionDefinitionChoice.ActionDefinitionX2Format2.RanUEgroupItems, ranUEgroupItem)
168                 }
169         } else if p.Req.ActionSetups[0].ActionDefinitionChoice.ActionDefinitionNRTFormat1Present {
170                 // 1..255
171                 for index := 0; index < 1; index++ {
172                         ranParameterItem := e2ap.RANParameterItem{}
173                         ranParameterItem.RanParameterID = 33
174                         ranParameterItem.RanParameterValue.ValueIntPresent = true
175                         ranParameterItem.RanParameterValue.ValueInt = 100
176                         p.Req.ActionSetups[0].ActionDefinitionChoice.ActionDefinitionNRTFormat1.RanParameterList =
177                                 append(p.Req.ActionSetups[0].ActionDefinitionChoice.ActionDefinitionNRTFormat1.RanParameterList, ranParameterItem)
178                 }
179         }
180         p.Req.ActionSetups[0].SubsequentAction.Present = true
181         p.Req.ActionSetups[0].SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeContinue
182         p.Req.ActionSetups[0].SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitZero
183 }
184
185 //-----------------------------------------------------------------------------
186 //
187 //-----------------------------------------------------------------------------
188
189 type E2StubSubsFailParams struct {
190         Req  *e2ap.E2APSubscriptionRequest
191         Fail *e2ap.E2APSubscriptionFailure
192 }
193
194 func (p *E2StubSubsFailParams) Set(req *e2ap.E2APSubscriptionRequest) {
195         p.Req = req
196
197         p.Fail = &e2ap.E2APSubscriptionFailure{}
198         p.Fail.RequestId.Id = p.Req.RequestId.Id
199         p.Fail.RequestId.InstanceId = p.Req.RequestId.InstanceId
200         p.Fail.FunctionId = p.Req.FunctionId
201         p.Fail.ActionNotAdmittedList.Items = make([]e2ap.ActionNotAdmittedItem, len(p.Req.ActionSetups))
202         for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ {
203                 p.Fail.ActionNotAdmittedList.Items[index].ActionId = p.Req.ActionSetups[index].ActionId
204                 p.SetCauseVal(index, 5, 1)
205         }
206 }
207
208 func (p *E2StubSubsFailParams) SetCauseVal(ind int, content uint8, causeval uint8) {
209
210         if ind < 0 {
211                 for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ {
212                         p.Fail.ActionNotAdmittedList.Items[index].Cause.Content = content
213                         p.Fail.ActionNotAdmittedList.Items[index].Cause.Value = causeval
214                 }
215                 return
216         }
217         p.Fail.ActionNotAdmittedList.Items[ind].Cause.Content = content
218         p.Fail.ActionNotAdmittedList.Items[ind].Cause.Value = causeval
219 }
220
221 //-----------------------------------------------------------------------------
222 //
223 //-----------------------------------------------------------------------------
224
225 func (tc *E2Stub) SendSubsReq(t *testing.T, rparams *E2StubSubsReqParams, oldTrans *RmrTransactionId) *RmrTransactionId {
226
227         trans := oldTrans
228         if oldTrans == nil {
229                 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
230         }
231
232         tc.Logger.Info("SendSubsReq %s", trans.String())
233         e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
234
235         //---------------------------------
236         // xapp activity: Send Subs Req
237         //---------------------------------
238         myparams := rparams
239
240         if myparams == nil {
241                 myparams = &E2StubSubsReqParams{}
242                 myparams.Init()
243         }
244
245         err, packedMsg := e2SubsReq.Pack(myparams.Req)
246         if err != nil {
247                 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
248                 return nil
249         }
250         tc.Logger.Debug("%s %s", trans.String(), e2SubsReq.String())
251
252         params := xapptweaks.NewParams(nil)
253         params.Mtype = xapp.RIC_SUB_REQ
254         params.SubId = -1
255         params.Payload = packedMsg.Buf
256         params.PayloadLen = len(packedMsg.Buf)
257         params.Meid = trans.meid
258         params.Xid = trans.xid
259         params.Mbuf = nil
260
261         tc.Logger.Info("SEND SUB REQ: %s", params.String())
262         snderr := tc.RmrSend(params, 5)
263         if snderr != nil {
264                 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
265                 return nil
266         }
267         return trans
268 }
269
270 //-----------------------------------------------------------------------------
271 //
272 //-----------------------------------------------------------------------------
273 func (tc *E2Stub) RecvSubsReq(t *testing.T) (*e2ap.E2APSubscriptionRequest, *xapptweaks.RMRParams) {
274         tc.Logger.Info("RecvSubsReq")
275         e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
276
277         //---------------------------------
278         // e2term activity: Recv Subs Req
279         //---------------------------------
280         msg := tc.WaitMsg(15)
281         if msg != nil {
282                 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] {
283                         tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_REQ", xapp.RicMessageTypeToName[msg.Mtype])
284                 } else {
285                         tc.Logger.Info("Recv Subs Req")
286                         packedData := &e2ap.PackedData{}
287                         packedData.Buf = msg.Payload
288                         unpackerr, req := e2SubsReq.UnPack(packedData)
289                         if unpackerr != nil {
290                                 tc.TestError(t, "RIC_SUB_REQ unpack failed err: %s", unpackerr.Error())
291                         }
292                         return req, msg
293                 }
294         } else {
295                 tc.TestError(t, "Not Received msg within %d secs", 15)
296         }
297
298         return nil, nil
299 }
300
301 //-----------------------------------------------------------------------------
302 //
303 //-----------------------------------------------------------------------------
304 func (tc *E2Stub) SendSubsResp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *xapptweaks.RMRParams) {
305         tc.Logger.Info("SendSubsResp")
306         e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
307
308         //---------------------------------
309         // e2term activity: Send Subs Resp
310         //---------------------------------
311         resp := &e2ap.E2APSubscriptionResponse{}
312
313         resp.RequestId.Id = req.RequestId.Id
314         resp.RequestId.InstanceId = req.RequestId.InstanceId
315         resp.FunctionId = req.FunctionId
316
317         resp.ActionAdmittedList.Items = make([]e2ap.ActionAdmittedItem, len(req.ActionSetups))
318         for index := int(0); index < len(req.ActionSetups); index++ {
319                 resp.ActionAdmittedList.Items[index].ActionId = req.ActionSetups[index].ActionId
320         }
321
322         for index := uint64(0); index < 1; index++ {
323                 item := e2ap.ActionNotAdmittedItem{}
324                 item.ActionId = index
325                 item.Cause.Content = 1
326                 item.Cause.Value = 1
327                 resp.ActionNotAdmittedList.Items = append(resp.ActionNotAdmittedList.Items, item)
328         }
329
330         packerr, packedMsg := e2SubsResp.Pack(resp)
331         if packerr != nil {
332                 tc.TestError(t, "pack NOK %s", packerr.Error())
333         }
334         tc.Logger.Debug("%s", e2SubsResp.String())
335
336         params := xapptweaks.NewParams(nil)
337         params.Mtype = xapp.RIC_SUB_RESP
338         //params.SubId = msg.SubId
339         params.SubId = -1
340         params.Payload = packedMsg.Buf
341         params.PayloadLen = len(packedMsg.Buf)
342         params.Meid = msg.Meid
343         //params.Xid = msg.Xid
344         params.Mbuf = nil
345
346         tc.Logger.Info("SEND SUB RESP: %s", params.String())
347         snderr := tc.RmrSend(params, 5)
348         if snderr != nil {
349                 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
350         }
351 }
352
353 //-----------------------------------------------------------------------------
354 //
355 //-----------------------------------------------------------------------------
356 func (tc *E2Stub) RecvSubsResp(t *testing.T, trans *RmrTransactionId) uint32 {
357         tc.Logger.Info("RecvSubsResp")
358         e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
359         var e2SubsId uint32
360
361         //---------------------------------
362         // xapp activity: Recv Subs Resp
363         //---------------------------------
364         msg := tc.WaitMsg(15)
365         if msg != nil {
366                 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
367                         tc.TestError(t, "Received RIC_SUB_RESP wrong mtype expected %s got %s, error", "RIC_SUB_RESP", xapp.RicMessageTypeToName[msg.Mtype])
368                         return 0
369                 } else if msg.Xid != trans.xid {
370                         tc.TestError(t, "Received RIC_SUB_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
371                         return 0
372                 } else {
373                         packedData := &e2ap.PackedData{}
374                         packedData.Buf = msg.Payload
375                         if msg.SubId > 0 {
376                                 e2SubsId = uint32(msg.SubId)
377                         } else {
378                                 e2SubsId = 0
379                         }
380                         unpackerr, resp := e2SubsResp.UnPack(packedData)
381                         if unpackerr != nil {
382                                 tc.TestError(t, "RIC_SUB_RESP unpack failed err: %s", unpackerr.Error())
383                         }
384                         tc.Logger.Info("Recv Subs Resp rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
385                         return e2SubsId
386                 }
387         } else {
388                 tc.TestError(t, "Not Received msg within %d secs", 15)
389         }
390         return 0
391 }
392
393 //-----------------------------------------------------------------------------
394 //
395 //-----------------------------------------------------------------------------
396
397 func (tc *E2Stub) SendSubsFail(t *testing.T, fparams *E2StubSubsFailParams, msg *xapptweaks.RMRParams) {
398         tc.Logger.Info("SendSubsFail")
399         e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
400
401         //---------------------------------
402         // e2term activity: Send Subs Fail
403         //---------------------------------
404         packerr, packedMsg := e2SubsFail.Pack(fparams.Fail)
405         if packerr != nil {
406                 tc.TestError(t, "pack NOK %s", packerr.Error())
407         }
408         tc.Logger.Debug("%s", e2SubsFail.String())
409
410         params := xapptweaks.NewParams(nil)
411         params.Mtype = xapp.RIC_SUB_FAILURE
412         params.SubId = msg.SubId
413         params.Payload = packedMsg.Buf
414         params.PayloadLen = len(packedMsg.Buf)
415         params.Meid = msg.Meid
416         params.Xid = msg.Xid
417         params.Mbuf = nil
418
419         tc.Logger.Info("SEND SUB FAIL: %s", params.String())
420         snderr := tc.RmrSend(params, 5)
421         if snderr != nil {
422                 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
423         }
424 }
425
426 //-----------------------------------------------------------------------------
427 //
428 //-----------------------------------------------------------------------------
429 func (tc *E2Stub) RecvSubsFail(t *testing.T, trans *RmrTransactionId) uint32 {
430         tc.Logger.Info("RecvSubsFail")
431         e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
432         var e2SubsId uint32
433
434         //-------------------------------
435         // xapp activity: Recv Subs Fail
436         //-------------------------------
437         msg := tc.WaitMsg(15)
438         if msg != nil {
439                 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_FAILURE"] {
440                         tc.TestError(t, "Received RIC_SUB_FAILURE wrong mtype expected %s got %s, error", "RIC_SUB_FAILURE", xapp.RicMessageTypeToName[msg.Mtype])
441                         return 0
442                 } else if msg.Xid != trans.xid {
443                         tc.TestError(t, "Received RIC_SUB_FAILURE wrong xid expected %s got %s, error", trans.xid, msg.Xid)
444                         return 0
445                 } else {
446                         packedData := &e2ap.PackedData{}
447                         packedData.Buf = msg.Payload
448                         if msg.SubId > 0 {
449                                 e2SubsId = uint32(msg.SubId)
450                         } else {
451                                 e2SubsId = 0
452                         }
453                         unpackerr, resp := e2SubsFail.UnPack(packedData)
454                         if unpackerr != nil {
455                                 tc.TestError(t, "RIC_SUB_FAILURE unpack failed err: %s", unpackerr.Error())
456                         }
457                         tc.Logger.Info("Recv Subs Fail rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
458                         return e2SubsId
459                 }
460         } else {
461                 tc.TestError(t, "Not Received msg within %d secs", 15)
462         }
463         return 0
464 }
465
466 //-----------------------------------------------------------------------------
467 //
468 //-----------------------------------------------------------------------------
469 func (tc *E2Stub) SendSubsDelReq(t *testing.T, oldTrans *RmrTransactionId, e2SubsId uint32) *RmrTransactionId {
470
471         trans := oldTrans
472         if oldTrans == nil {
473                 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
474         }
475
476         tc.Logger.Info("SendSubsDelReq %s", trans.String())
477         e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
478         //---------------------------------
479         // xapp activity: Send Subs Del Req
480         //---------------------------------
481         req := &e2ap.E2APSubscriptionDeleteRequest{}
482         req.RequestId.Id = 1
483         req.RequestId.InstanceId = e2SubsId
484         req.FunctionId = 1
485
486         err, packedMsg := e2SubsDelReq.Pack(req)
487         if err != nil {
488                 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
489                 return nil
490         }
491         tc.Logger.Debug("%s %s", trans.String(), e2SubsDelReq.String())
492
493         params := xapptweaks.NewParams(nil)
494         params.Mtype = xapp.RIC_SUB_DEL_REQ
495         params.SubId = int(e2SubsId)
496         params.Payload = packedMsg.Buf
497         params.PayloadLen = len(packedMsg.Buf)
498         params.Meid = trans.meid
499         params.Xid = trans.xid
500         params.Mbuf = nil
501
502         tc.Logger.Info("SEND SUB DEL REQ: %s", params.String())
503         snderr := tc.RmrSend(params, 5)
504         if snderr != nil {
505                 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
506                 return nil
507         }
508         return trans
509 }
510
511 //-----------------------------------------------------------------------------
512 //
513 //-----------------------------------------------------------------------------
514 func (tc *E2Stub) RecvSubsDelReq(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *xapptweaks.RMRParams) {
515         tc.Logger.Info("RecvSubsDelReq")
516         e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
517
518         //---------------------------------
519         // e2term activity: Recv Subs Del Req
520         //---------------------------------
521         msg := tc.WaitMsg(15)
522         if msg != nil {
523                 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] {
524                         tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_DEL_REQ", xapp.RicMessageTypeToName[msg.Mtype])
525                 } else {
526                         tc.Logger.Info("Recv Subs Del Req")
527
528                         packedData := &e2ap.PackedData{}
529                         packedData.Buf = msg.Payload
530                         unpackerr, req := e2SubsDelReq.UnPack(packedData)
531                         if unpackerr != nil {
532                                 tc.TestError(t, "RIC_SUB_DEL_REQ unpack failed err: %s", unpackerr.Error())
533                         }
534                         return req, msg
535                 }
536         } else {
537                 tc.TestError(t, "Not Received msg within %d secs", 15)
538         }
539         return nil, nil
540 }
541
542 //-----------------------------------------------------------------------------
543 //
544 //-----------------------------------------------------------------------------
545 func (tc *E2Stub) SendSubsDelResp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapptweaks.RMRParams) {
546         tc.Logger.Info("SendSubsDelResp")
547         e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
548
549         //---------------------------------
550         // e2term activity: Send Subs Del Resp
551         //---------------------------------
552         resp := &e2ap.E2APSubscriptionDeleteResponse{}
553         resp.RequestId.Id = req.RequestId.Id
554         resp.RequestId.InstanceId = req.RequestId.InstanceId
555         resp.FunctionId = req.FunctionId
556
557         packerr, packedMsg := e2SubsDelResp.Pack(resp)
558         if packerr != nil {
559                 tc.TestError(t, "pack NOK %s", packerr.Error())
560         }
561         tc.Logger.Debug("%s", e2SubsDelResp.String())
562
563         params := xapptweaks.NewParams(nil)
564         params.Mtype = xapp.RIC_SUB_DEL_RESP
565         params.SubId = msg.SubId
566         params.Payload = packedMsg.Buf
567         params.PayloadLen = len(packedMsg.Buf)
568         params.Meid = msg.Meid
569         params.Xid = msg.Xid
570         params.Mbuf = nil
571
572         tc.Logger.Info("SEND SUB DEL RESP: %s", params.String())
573         snderr := tc.RmrSend(params, 5)
574         if snderr != nil {
575                 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
576         }
577 }
578
579 //-----------------------------------------------------------------------------
580 //
581 //-----------------------------------------------------------------------------
582 func (tc *E2Stub) RecvSubsDelResp(t *testing.T, trans *RmrTransactionId) {
583         tc.Logger.Info("RecvSubsDelResp")
584         e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
585
586         //---------------------------------
587         // xapp activity: Recv Subs Del Resp
588         //---------------------------------
589         msg := tc.WaitMsg(15)
590         if msg != nil {
591                 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
592                         tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong mtype expected %s got %s, error", "RIC_SUB_DEL_RESP", xapp.RicMessageTypeToName[msg.Mtype])
593                         return
594                 } else if trans != nil && msg.Xid != trans.xid {
595                         tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
596                         return
597                 } else {
598                         packedData := &e2ap.PackedData{}
599                         packedData.Buf = msg.Payload
600                         unpackerr, resp := e2SubsDelResp.UnPack(packedData)
601                         if unpackerr != nil {
602                                 tc.TestError(t, "RIC_SUB_DEL_RESP unpack failed err: %s", unpackerr.Error())
603                         }
604                         tc.Logger.Info("Recv Subs Del Resp rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
605                         return
606                 }
607         } else {
608                 tc.TestError(t, "Not Received msg within %d secs", 15)
609         }
610 }
611
612 //-----------------------------------------------------------------------------
613 //
614 //-----------------------------------------------------------------------------
615 func (tc *E2Stub) SendSubsDelFail(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapptweaks.RMRParams) {
616         tc.Logger.Info("SendSubsDelFail")
617         e2SubsDelFail := e2asnpacker.NewPackerSubscriptionDeleteFailure()
618
619         //---------------------------------
620         // e2term activity: Send Subs Del Fail
621         //---------------------------------
622         resp := &e2ap.E2APSubscriptionDeleteFailure{}
623         resp.RequestId.Id = req.RequestId.Id
624         resp.RequestId.InstanceId = req.RequestId.InstanceId
625         resp.FunctionId = req.FunctionId
626         resp.Cause.Content = 4 // CauseMisc
627         resp.Cause.Value = 3   // unspecified
628
629         packerr, packedMsg := e2SubsDelFail.Pack(resp)
630         if packerr != nil {
631                 tc.TestError(t, "pack NOK %s", packerr.Error())
632         }
633         tc.Logger.Debug("%s", e2SubsDelFail.String())
634
635         params := xapptweaks.NewParams(nil)
636         params.Mtype = xapp.RIC_SUB_DEL_FAILURE
637         params.SubId = msg.SubId
638         params.Payload = packedMsg.Buf
639         params.PayloadLen = len(packedMsg.Buf)
640         params.Meid = msg.Meid
641         params.Xid = msg.Xid
642         params.Mbuf = nil
643
644         tc.Logger.Info("SEND SUB DEL FAIL: %s", params.String())
645         snderr := tc.RmrSend(params, 5)
646         if snderr != nil {
647                 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
648         }
649 }