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 ==================================================================================
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"
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
35 var e2asnpacker e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
40 type RmrTransactionId struct {
45 func (trans *RmrTransactionId) String() string {
46 return "trans(" + trans.xid + "/" + (&xapptweaks.RMRMeid{trans.meid}).String() + ")"
50 teststub.RmrStubControl
54 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
57 func CreateNewE2Stub(desc string, rtfile string, port string, stat string, mtypeseed int) *E2Stub {
59 tc.RmrStubControl.Init(desc, rtfile, port, stat, mtypeseed)
65 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
68 func CreateNewE2termStub(desc string, rtfile string, port string, stat string, mtypeseed int) *E2Stub {
70 tc.RmrStubControl.Init(desc, rtfile, port, stat, mtypeseed)
76 //-----------------------------------------------------------------------------
78 //-----------------------------------------------------------------------------
79 func (tc *E2Stub) NewRmrTransactionId(xid string, ranname string) *RmrTransactionId {
80 trans := &RmrTransactionId{}
82 trans.xid = tc.GetDesc() + "_XID_" + strconv.FormatUint(uint64(tc.xid_seq), 10)
87 trans.meid = &xapp.RMRMeid{RanName: ranname}
88 tc.Logger.Info("New test %s", trans.String())
92 //-----------------------------------------------------------------------------
94 //-----------------------------------------------------------------------------
95 type E2StubSubsReqParams struct {
96 Req *e2ap.E2APSubscriptionRequest
99 func (p *E2StubSubsReqParams) Init() {
100 p.Req = &e2ap.E2APSubscriptionRequest{}
102 p.Req.RequestId.Id = 1
103 p.Req.RequestId.Seq = 0
106 p.Req.EventTriggerDefinition.InterfaceId.GlobalEnbId.Present = true
107 p.Req.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.Mcc = "310"
108 p.Req.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.Mnc = "150"
109 p.Req.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId.Id = 123
110 p.Req.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId.Bits = e2ap.E2AP_ENBIDHomeBits28
112 // gnb -> enb outgoing
113 // enb -> gnb incoming
115 p.Req.EventTriggerDefinition.InterfaceDirection = e2ap.E2AP_InterfaceDirectionIncoming
116 p.Req.EventTriggerDefinition.ProcedureCode = 5 //28 35
117 p.Req.EventTriggerDefinition.TypeOfMessage = e2ap.E2AP_InitiatingMessage
119 p.Req.ActionSetups = make([]e2ap.ActionToBeSetupItem, 1)
121 p.Req.ActionSetups[0].ActionId = 0
122 p.Req.ActionSetups[0].ActionType = e2ap.E2AP_ActionTypeReport
123 p.Req.ActionSetups[0].ActionDefinition.Present = false // Not supported
124 //p.Req.ActionSetups[index].ActionDefinition.StyleId = 255
125 //p.Req.ActionSetups[index].ActionDefinition.ParamId = 222
126 p.Req.ActionSetups[0].SubsequentAction.Present = true
127 p.Req.ActionSetups[0].SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeContinue
128 p.Req.ActionSetups[0].SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitZero
131 //-----------------------------------------------------------------------------
133 //-----------------------------------------------------------------------------
135 type E2StubSubsFailParams struct {
136 Req *e2ap.E2APSubscriptionRequest
137 Fail *e2ap.E2APSubscriptionFailure
140 func (p *E2StubSubsFailParams) Set(req *e2ap.E2APSubscriptionRequest) {
143 p.Fail = &e2ap.E2APSubscriptionFailure{}
144 p.Fail.RequestId.Id = p.Req.RequestId.Id
145 p.Fail.RequestId.Seq = p.Req.RequestId.Seq
146 p.Fail.FunctionId = p.Req.FunctionId
147 p.Fail.ActionNotAdmittedList.Items = make([]e2ap.ActionNotAdmittedItem, len(p.Req.ActionSetups))
148 for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ {
149 p.Fail.ActionNotAdmittedList.Items[index].ActionId = p.Req.ActionSetups[index].ActionId
150 p.SetCauseVal(index, 5, 1)
154 func (p *E2StubSubsFailParams) SetCauseVal(ind int, content uint8, causeval uint8) {
157 for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ {
158 p.Fail.ActionNotAdmittedList.Items[index].Cause.Content = content
159 p.Fail.ActionNotAdmittedList.Items[index].Cause.Value = causeval
163 p.Fail.ActionNotAdmittedList.Items[ind].Cause.Content = content
164 p.Fail.ActionNotAdmittedList.Items[ind].Cause.Value = causeval
167 //-----------------------------------------------------------------------------
169 //-----------------------------------------------------------------------------
171 func (tc *E2Stub) SendSubsReq(t *testing.T, rparams *E2StubSubsReqParams, oldTrans *RmrTransactionId) *RmrTransactionId {
175 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
178 tc.Logger.Info("SendSubsReq %s", trans.String())
179 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
181 //---------------------------------
182 // xapp activity: Send Subs Req
183 //---------------------------------
187 myparams = &E2StubSubsReqParams{}
191 err, packedMsg := e2SubsReq.Pack(myparams.Req)
193 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
196 tc.Logger.Debug("%s %s", trans.String(), e2SubsReq.String())
198 params := xapptweaks.NewParams(nil)
199 params.Mtype = xapp.RIC_SUB_REQ
201 params.Payload = packedMsg.Buf
202 params.PayloadLen = len(packedMsg.Buf)
203 params.Meid = trans.meid
204 params.Xid = trans.xid
207 tc.Logger.Info("SEND SUB REQ: %s", params.String())
208 snderr := tc.RmrSend(params, 5)
210 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
216 //-----------------------------------------------------------------------------
218 //-----------------------------------------------------------------------------
219 func (tc *E2Stub) RecvSubsReq(t *testing.T) (*e2ap.E2APSubscriptionRequest, *xapptweaks.RMRParams) {
220 tc.Logger.Info("RecvSubsReq")
221 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
223 //---------------------------------
224 // e2term activity: Recv Subs Req
225 //---------------------------------
226 msg := tc.WaitMsg(15)
228 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] {
229 tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_REQ", xapp.RicMessageTypeToName[msg.Mtype])
231 tc.Logger.Info("Recv Subs Req")
232 packedData := &e2ap.PackedData{}
233 packedData.Buf = msg.Payload
234 unpackerr, req := e2SubsReq.UnPack(packedData)
235 if unpackerr != nil {
236 tc.TestError(t, "RIC_SUB_REQ unpack failed err: %s", unpackerr.Error())
241 tc.TestError(t, "Not Received msg within %d secs", 15)
247 //-----------------------------------------------------------------------------
249 //-----------------------------------------------------------------------------
250 func (tc *E2Stub) SendSubsResp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *xapptweaks.RMRParams) {
251 tc.Logger.Info("SendSubsResp")
252 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
254 //---------------------------------
255 // e2term activity: Send Subs Resp
256 //---------------------------------
257 resp := &e2ap.E2APSubscriptionResponse{}
259 resp.RequestId.Id = req.RequestId.Id
260 resp.RequestId.Seq = req.RequestId.Seq
261 resp.FunctionId = req.FunctionId
263 resp.ActionAdmittedList.Items = make([]e2ap.ActionAdmittedItem, len(req.ActionSetups))
264 for index := int(0); index < len(req.ActionSetups); index++ {
265 resp.ActionAdmittedList.Items[index].ActionId = req.ActionSetups[index].ActionId
268 for index := uint64(0); index < 1; index++ {
269 item := e2ap.ActionNotAdmittedItem{}
270 item.ActionId = index
271 item.Cause.Content = 1
273 resp.ActionNotAdmittedList.Items = append(resp.ActionNotAdmittedList.Items, item)
276 packerr, packedMsg := e2SubsResp.Pack(resp)
278 tc.TestError(t, "pack NOK %s", packerr.Error())
280 tc.Logger.Debug("%s", e2SubsResp.String())
282 params := xapptweaks.NewParams(nil)
283 params.Mtype = xapp.RIC_SUB_RESP
284 //params.SubId = msg.SubId
286 params.Payload = packedMsg.Buf
287 params.PayloadLen = len(packedMsg.Buf)
288 params.Meid = msg.Meid
289 //params.Xid = msg.Xid
292 tc.Logger.Info("SEND SUB RESP: %s", params.String())
293 snderr := tc.RmrSend(params, 5)
295 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
299 //-----------------------------------------------------------------------------
301 //-----------------------------------------------------------------------------
302 func (tc *E2Stub) RecvSubsResp(t *testing.T, trans *RmrTransactionId) uint32 {
303 tc.Logger.Info("RecvSubsResp")
304 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
307 //---------------------------------
308 // xapp activity: Recv Subs Resp
309 //---------------------------------
310 msg := tc.WaitMsg(15)
312 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
313 tc.TestError(t, "Received RIC_SUB_RESP wrong mtype expected %s got %s, error", "RIC_SUB_RESP", xapp.RicMessageTypeToName[msg.Mtype])
315 } else if msg.Xid != trans.xid {
316 tc.TestError(t, "Received RIC_SUB_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
319 packedData := &e2ap.PackedData{}
320 packedData.Buf = msg.Payload
322 e2SubsId = uint32(msg.SubId)
326 unpackerr, resp := e2SubsResp.UnPack(packedData)
327 if unpackerr != nil {
328 tc.TestError(t, "RIC_SUB_RESP unpack failed err: %s", unpackerr.Error())
330 tc.Logger.Info("Recv Subs Resp rmr: xid=%s subid=%d, asn: seqnro=%d", msg.Xid, msg.SubId, resp.RequestId.Seq)
334 tc.TestError(t, "Not Received msg within %d secs", 15)
339 //-----------------------------------------------------------------------------
341 //-----------------------------------------------------------------------------
343 func (tc *E2Stub) SendSubsFail(t *testing.T, fparams *E2StubSubsFailParams, msg *xapptweaks.RMRParams) {
344 tc.Logger.Info("SendSubsFail")
345 e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
347 //---------------------------------
348 // e2term activity: Send Subs Fail
349 //---------------------------------
350 packerr, packedMsg := e2SubsFail.Pack(fparams.Fail)
352 tc.TestError(t, "pack NOK %s", packerr.Error())
354 tc.Logger.Debug("%s", e2SubsFail.String())
356 params := xapptweaks.NewParams(nil)
357 params.Mtype = xapp.RIC_SUB_FAILURE
358 params.SubId = msg.SubId
359 params.Payload = packedMsg.Buf
360 params.PayloadLen = len(packedMsg.Buf)
361 params.Meid = msg.Meid
365 tc.Logger.Info("SEND SUB FAIL: %s", params.String())
366 snderr := tc.RmrSend(params, 5)
368 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
372 //-----------------------------------------------------------------------------
374 //-----------------------------------------------------------------------------
375 func (tc *E2Stub) RecvSubsFail(t *testing.T, trans *RmrTransactionId) uint32 {
376 tc.Logger.Info("RecvSubsFail")
377 e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
380 //-------------------------------
381 // xapp activity: Recv Subs Fail
382 //-------------------------------
383 msg := tc.WaitMsg(15)
385 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_FAILURE"] {
386 tc.TestError(t, "Received RIC_SUB_FAILURE wrong mtype expected %s got %s, error", "RIC_SUB_FAILURE", xapp.RicMessageTypeToName[msg.Mtype])
388 } else if msg.Xid != trans.xid {
389 tc.TestError(t, "Received RIC_SUB_FAILURE wrong xid expected %s got %s, error", trans.xid, msg.Xid)
392 packedData := &e2ap.PackedData{}
393 packedData.Buf = msg.Payload
395 e2SubsId = uint32(msg.SubId)
399 unpackerr, resp := e2SubsFail.UnPack(packedData)
400 if unpackerr != nil {
401 tc.TestError(t, "RIC_SUB_FAILURE unpack failed err: %s", unpackerr.Error())
403 tc.Logger.Info("Recv Subs Fail rmr: xid=%s subid=%d, asn: seqnro=%d", msg.Xid, msg.SubId, resp.RequestId.Seq)
407 tc.TestError(t, "Not Received msg within %d secs", 15)
412 //-----------------------------------------------------------------------------
414 //-----------------------------------------------------------------------------
415 func (tc *E2Stub) SendSubsDelReq(t *testing.T, oldTrans *RmrTransactionId, e2SubsId uint32) *RmrTransactionId {
419 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
422 tc.Logger.Info("SendSubsDelReq %s", trans.String())
423 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
424 //---------------------------------
425 // xapp activity: Send Subs Del Req
426 //---------------------------------
427 req := &e2ap.E2APSubscriptionDeleteRequest{}
429 req.RequestId.Seq = e2SubsId
432 err, packedMsg := e2SubsDelReq.Pack(req)
434 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
437 tc.Logger.Debug("%s %s", trans.String(), e2SubsDelReq.String())
439 params := xapptweaks.NewParams(nil)
440 params.Mtype = xapp.RIC_SUB_DEL_REQ
441 params.SubId = int(e2SubsId)
442 params.Payload = packedMsg.Buf
443 params.PayloadLen = len(packedMsg.Buf)
444 params.Meid = trans.meid
445 params.Xid = trans.xid
448 tc.Logger.Info("SEND SUB DEL REQ: %s", params.String())
449 snderr := tc.RmrSend(params, 5)
451 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
457 //-----------------------------------------------------------------------------
459 //-----------------------------------------------------------------------------
460 func (tc *E2Stub) RecvSubsDelReq(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *xapptweaks.RMRParams) {
461 tc.Logger.Info("RecvSubsDelReq")
462 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
464 //---------------------------------
465 // e2term activity: Recv Subs Del Req
466 //---------------------------------
467 msg := tc.WaitMsg(15)
469 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] {
470 tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_DEL_REQ", xapp.RicMessageTypeToName[msg.Mtype])
472 tc.Logger.Info("Recv Subs Del Req")
474 packedData := &e2ap.PackedData{}
475 packedData.Buf = msg.Payload
476 unpackerr, req := e2SubsDelReq.UnPack(packedData)
477 if unpackerr != nil {
478 tc.TestError(t, "RIC_SUB_DEL_REQ unpack failed err: %s", unpackerr.Error())
483 tc.TestError(t, "Not Received msg within %d secs", 15)
488 //-----------------------------------------------------------------------------
490 //-----------------------------------------------------------------------------
491 func (tc *E2Stub) SendSubsDelResp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapptweaks.RMRParams) {
492 tc.Logger.Info("SendSubsDelResp")
493 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
495 //---------------------------------
496 // e2term activity: Send Subs Del Resp
497 //---------------------------------
498 resp := &e2ap.E2APSubscriptionDeleteResponse{}
499 resp.RequestId.Id = req.RequestId.Id
500 resp.RequestId.Seq = req.RequestId.Seq
501 resp.FunctionId = req.FunctionId
503 packerr, packedMsg := e2SubsDelResp.Pack(resp)
505 tc.TestError(t, "pack NOK %s", packerr.Error())
507 tc.Logger.Debug("%s", e2SubsDelResp.String())
509 params := xapptweaks.NewParams(nil)
510 params.Mtype = xapp.RIC_SUB_DEL_RESP
511 params.SubId = msg.SubId
512 params.Payload = packedMsg.Buf
513 params.PayloadLen = len(packedMsg.Buf)
514 params.Meid = msg.Meid
518 tc.Logger.Info("SEND SUB DEL RESP: %s", params.String())
519 snderr := tc.RmrSend(params, 5)
521 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
525 //-----------------------------------------------------------------------------
527 //-----------------------------------------------------------------------------
528 func (tc *E2Stub) RecvSubsDelResp(t *testing.T, trans *RmrTransactionId) {
529 tc.Logger.Info("RecvSubsDelResp")
530 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
532 //---------------------------------
533 // xapp activity: Recv Subs Del Resp
534 //---------------------------------
535 msg := tc.WaitMsg(15)
537 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
538 tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong mtype expected %s got %s, error", "RIC_SUB_DEL_RESP", xapp.RicMessageTypeToName[msg.Mtype])
540 } else if trans != nil && msg.Xid != trans.xid {
541 tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
544 packedData := &e2ap.PackedData{}
545 packedData.Buf = msg.Payload
546 unpackerr, resp := e2SubsDelResp.UnPack(packedData)
547 if unpackerr != nil {
548 tc.TestError(t, "RIC_SUB_DEL_RESP unpack failed err: %s", unpackerr.Error())
550 tc.Logger.Info("Recv Subs Del Resp rmr: xid=%s subid=%d, asn: seqnro=%d", msg.Xid, msg.SubId, resp.RequestId.Seq)
554 tc.TestError(t, "Not Received msg within %d secs", 15)
558 //-----------------------------------------------------------------------------
560 //-----------------------------------------------------------------------------
561 func (tc *E2Stub) SendSubsDelFail(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapptweaks.RMRParams) {
562 tc.Logger.Info("SendSubsDelFail")
563 e2SubsDelFail := e2asnpacker.NewPackerSubscriptionDeleteFailure()
565 //---------------------------------
566 // e2term activity: Send Subs Del Fail
567 //---------------------------------
568 resp := &e2ap.E2APSubscriptionDeleteFailure{}
569 resp.RequestId.Id = req.RequestId.Id
570 resp.RequestId.Seq = req.RequestId.Seq
571 resp.FunctionId = req.FunctionId
572 resp.Cause.Content = 3 // CauseMisc
573 resp.Cause.Value = 4 // unspecified
575 packerr, packedMsg := e2SubsDelFail.Pack(resp)
577 tc.TestError(t, "pack NOK %s", packerr.Error())
579 tc.Logger.Debug("%s", e2SubsDelFail.String())
581 params := xapptweaks.NewParams(nil)
582 params.Mtype = xapp.RIC_SUB_DEL_FAILURE
583 params.SubId = msg.SubId
584 params.Payload = packedMsg.Buf
585 params.PayloadLen = len(packedMsg.Buf)
586 params.Meid = msg.Meid
590 tc.Logger.Info("SEND SUB DEL FAIL: %s", params.String())
591 snderr := tc.RmrSend(params, 5)
593 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())