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 + "/" + trans.meid.RanName + ")"
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.StringPut("310150")
108 p.Req.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId.Id = 123
109 p.Req.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId.Bits = e2ap.E2AP_ENBIDHomeBits28
111 // gnb -> enb outgoing
112 // enb -> gnb incoming
114 p.Req.EventTriggerDefinition.InterfaceDirection = e2ap.E2AP_InterfaceDirectionIncoming
115 p.Req.EventTriggerDefinition.ProcedureCode = 5 //28 35
116 p.Req.EventTriggerDefinition.TypeOfMessage = e2ap.E2AP_InitiatingMessage
118 p.Req.ActionSetups = make([]e2ap.ActionToBeSetupItem, 1)
120 p.Req.ActionSetups[0].ActionId = 0
121 p.Req.ActionSetups[0].ActionType = e2ap.E2AP_ActionTypeReport
122 p.Req.ActionSetups[0].ActionDefinition.Present = false // Not supported
123 //p.Req.ActionSetups[index].ActionDefinition.StyleId = 255
124 //p.Req.ActionSetups[index].ActionDefinition.ParamId = 222
125 p.Req.ActionSetups[0].SubsequentAction.Present = true
126 p.Req.ActionSetups[0].SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeContinue
127 p.Req.ActionSetups[0].SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitZero
130 //-----------------------------------------------------------------------------
132 //-----------------------------------------------------------------------------
134 type E2StubSubsFailParams struct {
135 Req *e2ap.E2APSubscriptionRequest
136 Fail *e2ap.E2APSubscriptionFailure
139 func (p *E2StubSubsFailParams) Set(req *e2ap.E2APSubscriptionRequest) {
142 p.Fail = &e2ap.E2APSubscriptionFailure{}
143 p.Fail.RequestId.Id = p.Req.RequestId.Id
144 p.Fail.RequestId.Seq = p.Req.RequestId.Seq
145 p.Fail.FunctionId = p.Req.FunctionId
146 p.Fail.ActionNotAdmittedList.Items = make([]e2ap.ActionNotAdmittedItem, len(p.Req.ActionSetups))
147 for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ {
148 p.Fail.ActionNotAdmittedList.Items[index].ActionId = p.Req.ActionSetups[index].ActionId
149 p.SetCauseVal(index, 5, 1)
153 func (p *E2StubSubsFailParams) SetCauseVal(ind int, content uint8, causeval uint8) {
156 for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ {
157 p.Fail.ActionNotAdmittedList.Items[index].Cause.Content = content
158 p.Fail.ActionNotAdmittedList.Items[index].Cause.CauseVal = causeval
162 p.Fail.ActionNotAdmittedList.Items[ind].Cause.Content = content
163 p.Fail.ActionNotAdmittedList.Items[ind].Cause.CauseVal = causeval
166 //-----------------------------------------------------------------------------
168 //-----------------------------------------------------------------------------
170 func (tc *E2Stub) SendSubsReq(t *testing.T, rparams *E2StubSubsReqParams, oldTrans *RmrTransactionId) *RmrTransactionId {
174 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
177 tc.Logger.Info("SendSubsReq %s", trans.String())
178 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
180 //---------------------------------
181 // xapp activity: Send Subs Req
182 //---------------------------------
186 myparams = &E2StubSubsReqParams{}
190 err, packedMsg := e2SubsReq.Pack(myparams.Req)
192 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
195 tc.Logger.Debug("%s %s", trans.String(), e2SubsReq.String())
197 params := xapptweaks.NewParams(nil)
198 params.Mtype = xapp.RIC_SUB_REQ
200 params.Payload = packedMsg.Buf
201 params.PayloadLen = len(packedMsg.Buf)
202 params.Meid = trans.meid
203 params.Xid = trans.xid
206 tc.Logger.Info("SEND SUB REQ: %s", params.String())
207 snderr := tc.RmrSend(params)
209 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
215 //-----------------------------------------------------------------------------
217 //-----------------------------------------------------------------------------
218 func (tc *E2Stub) RecvSubsReq(t *testing.T) (*e2ap.E2APSubscriptionRequest, *xapptweaks.RMRParams) {
219 tc.Logger.Info("RecvSubsReq")
220 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
222 //---------------------------------
223 // e2term activity: Recv Subs Req
224 //---------------------------------
225 msg := tc.WaitMsg(15)
227 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] {
228 tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_REQ", xapp.RicMessageTypeToName[msg.Mtype])
230 tc.Logger.Info("Recv Subs Req")
231 packedData := &e2ap.PackedData{}
232 packedData.Buf = msg.Payload
233 unpackerr, req := e2SubsReq.UnPack(packedData)
234 if unpackerr != nil {
235 tc.TestError(t, "RIC_SUB_REQ unpack failed err: %s", unpackerr.Error())
240 tc.TestError(t, "Not Received msg within %d secs", 15)
246 //-----------------------------------------------------------------------------
248 //-----------------------------------------------------------------------------
249 func (tc *E2Stub) SendSubsResp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *xapptweaks.RMRParams) {
250 tc.Logger.Info("SendSubsResp")
251 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
253 //---------------------------------
254 // e2term activity: Send Subs Resp
255 //---------------------------------
256 resp := &e2ap.E2APSubscriptionResponse{}
258 resp.RequestId.Id = req.RequestId.Id
259 resp.RequestId.Seq = req.RequestId.Seq
260 resp.FunctionId = req.FunctionId
262 resp.ActionAdmittedList.Items = make([]e2ap.ActionAdmittedItem, len(req.ActionSetups))
263 for index := int(0); index < len(req.ActionSetups); index++ {
264 resp.ActionAdmittedList.Items[index].ActionId = req.ActionSetups[index].ActionId
267 for index := uint64(0); index < 1; index++ {
268 item := e2ap.ActionNotAdmittedItem{}
269 item.ActionId = index
270 item.Cause.Content = 1
271 item.Cause.CauseVal = 1
272 resp.ActionNotAdmittedList.Items = append(resp.ActionNotAdmittedList.Items, item)
275 packerr, packedMsg := e2SubsResp.Pack(resp)
277 tc.TestError(t, "pack NOK %s", packerr.Error())
279 tc.Logger.Debug("%s", e2SubsResp.String())
281 params := xapptweaks.NewParams(nil)
282 params.Mtype = xapp.RIC_SUB_RESP
283 //params.SubId = msg.SubId
285 params.Payload = packedMsg.Buf
286 params.PayloadLen = len(packedMsg.Buf)
287 params.Meid = msg.Meid
288 //params.Xid = msg.Xid
291 tc.Logger.Info("SEND SUB RESP: %s", params.String())
292 snderr := tc.RmrSend(params)
294 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
298 //-----------------------------------------------------------------------------
300 //-----------------------------------------------------------------------------
301 func (tc *E2Stub) RecvSubsResp(t *testing.T, trans *RmrTransactionId) uint32 {
302 tc.Logger.Info("RecvSubsResp")
303 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
306 //---------------------------------
307 // xapp activity: Recv Subs Resp
308 //---------------------------------
309 msg := tc.WaitMsg(15)
311 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
312 tc.TestError(t, "Received RIC_SUB_RESP wrong mtype expected %s got %s, error", "RIC_SUB_RESP", xapp.RicMessageTypeToName[msg.Mtype])
314 } else if msg.Xid != trans.xid {
315 tc.TestError(t, "Received RIC_SUB_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
318 packedData := &e2ap.PackedData{}
319 packedData.Buf = msg.Payload
321 e2SubsId = uint32(msg.SubId)
325 unpackerr, resp := e2SubsResp.UnPack(packedData)
326 if unpackerr != nil {
327 tc.TestError(t, "RIC_SUB_RESP unpack failed err: %s", unpackerr.Error())
329 tc.Logger.Info("Recv Subs Resp rmr: xid=%s subid=%d, asn: seqnro=%d", msg.Xid, msg.SubId, resp.RequestId.Seq)
333 tc.TestError(t, "Not Received msg within %d secs", 15)
338 //-----------------------------------------------------------------------------
340 //-----------------------------------------------------------------------------
342 func (tc *E2Stub) SendSubsFail(t *testing.T, fparams *E2StubSubsFailParams, msg *xapptweaks.RMRParams) {
343 tc.Logger.Info("SendSubsFail")
344 e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
346 //---------------------------------
347 // e2term activity: Send Subs Fail
348 //---------------------------------
349 packerr, packedMsg := e2SubsFail.Pack(fparams.Fail)
351 tc.TestError(t, "pack NOK %s", packerr.Error())
353 tc.Logger.Debug("%s", e2SubsFail.String())
355 params := xapptweaks.NewParams(nil)
356 params.Mtype = xapp.RIC_SUB_FAILURE
357 params.SubId = msg.SubId
358 params.Payload = packedMsg.Buf
359 params.PayloadLen = len(packedMsg.Buf)
360 params.Meid = msg.Meid
364 tc.Logger.Info("SEND SUB FAIL: %s", params.String())
365 snderr := tc.RmrSend(params)
367 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
371 //-----------------------------------------------------------------------------
373 //-----------------------------------------------------------------------------
374 func (tc *E2Stub) RecvSubsFail(t *testing.T, trans *RmrTransactionId) uint32 {
375 tc.Logger.Info("RecvSubsFail")
376 e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
379 //-------------------------------
380 // xapp activity: Recv Subs Fail
381 //-------------------------------
382 msg := tc.WaitMsg(15)
384 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_FAILURE"] {
385 tc.TestError(t, "Received RIC_SUB_FAILURE wrong mtype expected %s got %s, error", "RIC_SUB_FAILURE", xapp.RicMessageTypeToName[msg.Mtype])
387 } else if msg.Xid != trans.xid {
388 tc.TestError(t, "Received RIC_SUB_FAILURE wrong xid expected %s got %s, error", trans.xid, msg.Xid)
391 packedData := &e2ap.PackedData{}
392 packedData.Buf = msg.Payload
394 e2SubsId = uint32(msg.SubId)
398 unpackerr, resp := e2SubsFail.UnPack(packedData)
399 if unpackerr != nil {
400 tc.TestError(t, "RIC_SUB_FAILURE unpack failed err: %s", unpackerr.Error())
402 tc.Logger.Info("Recv Subs Fail rmr: xid=%s subid=%d, asn: seqnro=%d", msg.Xid, msg.SubId, resp.RequestId.Seq)
406 tc.TestError(t, "Not Received msg within %d secs", 15)
411 //-----------------------------------------------------------------------------
413 //-----------------------------------------------------------------------------
414 func (tc *E2Stub) SendSubsDelReq(t *testing.T, oldTrans *RmrTransactionId, e2SubsId uint32) *RmrTransactionId {
418 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
421 tc.Logger.Info("SendSubsDelReq %s", trans.String())
422 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
423 //---------------------------------
424 // xapp activity: Send Subs Del Req
425 //---------------------------------
426 req := &e2ap.E2APSubscriptionDeleteRequest{}
428 req.RequestId.Seq = e2SubsId
431 err, packedMsg := e2SubsDelReq.Pack(req)
433 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
436 tc.Logger.Debug("%s %s", trans.String(), e2SubsDelReq.String())
438 params := xapptweaks.NewParams(nil)
439 params.Mtype = xapp.RIC_SUB_DEL_REQ
440 params.SubId = int(e2SubsId)
441 params.Payload = packedMsg.Buf
442 params.PayloadLen = len(packedMsg.Buf)
443 params.Meid = trans.meid
444 params.Xid = trans.xid
447 tc.Logger.Info("SEND SUB DEL REQ: %s", params.String())
448 snderr := tc.RmrSend(params)
450 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
456 //-----------------------------------------------------------------------------
458 //-----------------------------------------------------------------------------
459 func (tc *E2Stub) RecvSubsDelReq(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *xapptweaks.RMRParams) {
460 tc.Logger.Info("RecvSubsDelReq")
461 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
463 //---------------------------------
464 // e2term activity: Recv Subs Del Req
465 //---------------------------------
466 msg := tc.WaitMsg(15)
468 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] {
469 tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_DEL_REQ", xapp.RicMessageTypeToName[msg.Mtype])
471 tc.Logger.Info("Recv Subs Del Req")
473 packedData := &e2ap.PackedData{}
474 packedData.Buf = msg.Payload
475 unpackerr, req := e2SubsDelReq.UnPack(packedData)
476 if unpackerr != nil {
477 tc.TestError(t, "RIC_SUB_DEL_REQ unpack failed err: %s", unpackerr.Error())
482 tc.TestError(t, "Not Received msg within %d secs", 15)
487 //-----------------------------------------------------------------------------
489 //-----------------------------------------------------------------------------
490 func (tc *E2Stub) SendSubsDelResp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapptweaks.RMRParams) {
491 tc.Logger.Info("SendSubsDelResp")
492 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
494 //---------------------------------
495 // e2term activity: Send Subs Del Resp
496 //---------------------------------
497 resp := &e2ap.E2APSubscriptionDeleteResponse{}
498 resp.RequestId.Id = req.RequestId.Id
499 resp.RequestId.Seq = req.RequestId.Seq
500 resp.FunctionId = req.FunctionId
502 packerr, packedMsg := e2SubsDelResp.Pack(resp)
504 tc.TestError(t, "pack NOK %s", packerr.Error())
506 tc.Logger.Debug("%s", e2SubsDelResp.String())
508 params := xapptweaks.NewParams(nil)
509 params.Mtype = xapp.RIC_SUB_DEL_RESP
510 params.SubId = msg.SubId
511 params.Payload = packedMsg.Buf
512 params.PayloadLen = len(packedMsg.Buf)
513 params.Meid = msg.Meid
517 tc.Logger.Info("SEND SUB DEL RESP: %s", params.String())
518 snderr := tc.RmrSend(params)
520 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
524 //-----------------------------------------------------------------------------
526 //-----------------------------------------------------------------------------
527 func (tc *E2Stub) RecvSubsDelResp(t *testing.T, trans *RmrTransactionId) {
528 tc.Logger.Info("RecvSubsDelResp")
529 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
531 //---------------------------------
532 // xapp activity: Recv Subs Del Resp
533 //---------------------------------
534 msg := tc.WaitMsg(15)
536 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
537 tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong mtype expected %s got %s, error", "RIC_SUB_DEL_RESP", xapp.RicMessageTypeToName[msg.Mtype])
539 } else if trans != nil && msg.Xid != trans.xid {
540 tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
543 packedData := &e2ap.PackedData{}
544 packedData.Buf = msg.Payload
545 unpackerr, resp := e2SubsDelResp.UnPack(packedData)
546 if unpackerr != nil {
547 tc.TestError(t, "RIC_SUB_DEL_RESP unpack failed err: %s", unpackerr.Error())
549 tc.Logger.Info("Recv Subs Del Resp rmr: xid=%s subid=%d, asn: seqnro=%d", msg.Xid, msg.SubId, resp.RequestId.Seq)
553 tc.TestError(t, "Not Received msg within %d secs", 15)
557 //-----------------------------------------------------------------------------
559 //-----------------------------------------------------------------------------
560 func (tc *E2Stub) SendSubsDelFail(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapptweaks.RMRParams) {
561 tc.Logger.Info("SendSubsDelFail")
562 e2SubsDelFail := e2asnpacker.NewPackerSubscriptionDeleteFailure()
564 //---------------------------------
565 // e2term activity: Send Subs Del Fail
566 //---------------------------------
567 resp := &e2ap.E2APSubscriptionDeleteFailure{}
568 resp.RequestId.Id = req.RequestId.Id
569 resp.RequestId.Seq = req.RequestId.Seq
570 resp.FunctionId = req.FunctionId
571 resp.Cause.Content = 3 // CauseMisc
572 resp.Cause.CauseVal = 4 // unspecified
574 packerr, packedMsg := e2SubsDelFail.Pack(resp)
576 tc.TestError(t, "pack NOK %s", packerr.Error())
578 tc.Logger.Debug("%s", e2SubsDelFail.String())
580 params := xapptweaks.NewParams(nil)
581 params.Mtype = xapp.RIC_SUB_DEL_FAILURE
582 params.SubId = msg.SubId
583 params.Payload = packedMsg.Buf
584 params.PayloadLen = len(packedMsg.Buf)
585 params.Meid = msg.Meid
589 tc.Logger.Info("SEND SUB DEL FAIL: %s", params.String())
590 snderr := tc.RmrSend(params)
592 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())