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)
119 p.Req.ActionSetups[0].ActionId = 0
120 p.Req.ActionSetups[0].ActionType = e2ap.E2AP_ActionTypeReport
121 p.Req.ActionSetups[0].ActionDefinition.Present = false
122 //p.Req.ActionSetups[index].ActionDefinition.StyleId = 255
123 //p.Req.ActionSetups[index].ActionDefinition.ParamId = 222
124 p.Req.ActionSetups[0].SubsequentAction.Present = true
125 p.Req.ActionSetups[0].SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeContinue
126 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.Meid = trans.meid
202 params.Xid = trans.xid
205 tc.Logger.Info("SEND SUB REQ: %s", params.String())
206 snderr := tc.RmrSend(params)
208 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
214 //-----------------------------------------------------------------------------
216 //-----------------------------------------------------------------------------
217 func (tc *E2Stub) RecvSubsReq(t *testing.T) (*e2ap.E2APSubscriptionRequest, *xapptweaks.RMRParams) {
218 tc.Logger.Info("RecvSubsReq")
219 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
221 //---------------------------------
222 // e2term activity: Recv Subs Req
223 //---------------------------------
224 msg := tc.WaitMsg(15)
226 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] {
227 tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_REQ", xapp.RicMessageTypeToName[msg.Mtype])
229 tc.Logger.Info("Recv Subs Req")
230 packedData := &e2ap.PackedData{}
231 packedData.Buf = msg.Payload
232 unpackerr, req := e2SubsReq.UnPack(packedData)
233 if unpackerr != nil {
234 tc.TestError(t, "RIC_SUB_REQ unpack failed err: %s", unpackerr.Error())
239 tc.TestError(t, "Not Received msg within %d secs", 15)
245 //-----------------------------------------------------------------------------
247 //-----------------------------------------------------------------------------
248 func (tc *E2Stub) SendSubsResp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *xapptweaks.RMRParams) {
249 tc.Logger.Info("SendSubsResp")
250 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
252 //---------------------------------
253 // e2term activity: Send Subs Resp
254 //---------------------------------
255 resp := &e2ap.E2APSubscriptionResponse{}
257 resp.RequestId.Id = req.RequestId.Id
258 resp.RequestId.Seq = req.RequestId.Seq
259 resp.FunctionId = req.FunctionId
261 resp.ActionAdmittedList.Items = make([]e2ap.ActionAdmittedItem, len(req.ActionSetups))
262 for index := int(0); index < len(req.ActionSetups); index++ {
263 resp.ActionAdmittedList.Items[index].ActionId = req.ActionSetups[index].ActionId
266 for index := uint64(0); index < 1; index++ {
267 item := e2ap.ActionNotAdmittedItem{}
268 item.ActionId = index
269 item.Cause.Content = 1
270 item.Cause.CauseVal = 1
271 resp.ActionNotAdmittedList.Items = append(resp.ActionNotAdmittedList.Items, item)
274 packerr, packedMsg := e2SubsResp.Pack(resp)
276 tc.TestError(t, "pack NOK %s", packerr.Error())
278 tc.Logger.Debug("%s", e2SubsResp.String())
280 params := xapptweaks.NewParams(nil)
281 params.Mtype = xapp.RIC_SUB_RESP
282 //params.SubId = msg.SubId
284 params.Payload = packedMsg.Buf
285 params.Meid = msg.Meid
286 //params.Xid = msg.Xid
289 tc.Logger.Info("SEND SUB RESP: %s", params.String())
290 snderr := tc.RmrSend(params)
292 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
296 //-----------------------------------------------------------------------------
298 //-----------------------------------------------------------------------------
299 func (tc *E2Stub) RecvSubsResp(t *testing.T, trans *RmrTransactionId) uint32 {
300 tc.Logger.Info("RecvSubsResp")
301 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
304 //---------------------------------
305 // xapp activity: Recv Subs Resp
306 //---------------------------------
307 msg := tc.WaitMsg(15)
309 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
310 tc.TestError(t, "Received RIC_SUB_RESP wrong mtype expected %s got %s, error", "RIC_SUB_RESP", xapp.RicMessageTypeToName[msg.Mtype])
312 } else if msg.Xid != trans.xid {
313 tc.TestError(t, "Received RIC_SUB_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
316 packedData := &e2ap.PackedData{}
317 packedData.Buf = msg.Payload
319 e2SubsId = uint32(msg.SubId)
323 unpackerr, resp := e2SubsResp.UnPack(packedData)
324 if unpackerr != nil {
325 tc.TestError(t, "RIC_SUB_RESP unpack failed err: %s", unpackerr.Error())
327 tc.Logger.Info("Recv Subs Resp rmr: xid=%s subid=%d, asn: seqnro=%d", msg.Xid, msg.SubId, resp.RequestId.Seq)
331 tc.TestError(t, "Not Received msg within %d secs", 15)
336 //-----------------------------------------------------------------------------
338 //-----------------------------------------------------------------------------
340 func (tc *E2Stub) SendSubsFail(t *testing.T, fparams *E2StubSubsFailParams, msg *xapptweaks.RMRParams) {
341 tc.Logger.Info("SendSubsFail")
342 e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
344 //---------------------------------
345 // e2term activity: Send Subs Fail
346 //---------------------------------
347 packerr, packedMsg := e2SubsFail.Pack(fparams.Fail)
349 tc.TestError(t, "pack NOK %s", packerr.Error())
351 tc.Logger.Debug("%s", e2SubsFail.String())
353 params := xapptweaks.NewParams(nil)
354 params.Mtype = xapp.RIC_SUB_FAILURE
355 params.SubId = msg.SubId
356 params.Payload = packedMsg.Buf
357 params.Meid = msg.Meid
361 tc.Logger.Info("SEND SUB FAIL: %s", params.String())
362 snderr := tc.RmrSend(params)
364 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
368 //-----------------------------------------------------------------------------
370 //-----------------------------------------------------------------------------
371 func (tc *E2Stub) RecvSubsFail(t *testing.T, trans *RmrTransactionId) uint32 {
372 tc.Logger.Info("RecvSubsFail")
373 e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
376 //-------------------------------
377 // xapp activity: Recv Subs Fail
378 //-------------------------------
379 msg := tc.WaitMsg(15)
381 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_FAILURE"] {
382 tc.TestError(t, "Received RIC_SUB_FAILURE wrong mtype expected %s got %s, error", "RIC_SUB_FAILURE", xapp.RicMessageTypeToName[msg.Mtype])
384 } else if msg.Xid != trans.xid {
385 tc.TestError(t, "Received RIC_SUB_FAILURE wrong xid expected %s got %s, error", trans.xid, msg.Xid)
388 packedData := &e2ap.PackedData{}
389 packedData.Buf = msg.Payload
391 e2SubsId = uint32(msg.SubId)
395 unpackerr, resp := e2SubsFail.UnPack(packedData)
396 if unpackerr != nil {
397 tc.TestError(t, "RIC_SUB_FAILURE unpack failed err: %s", unpackerr.Error())
399 tc.Logger.Info("Recv Subs Fail rmr: xid=%s subid=%d, asn: seqnro=%d", msg.Xid, msg.SubId, resp.RequestId.Seq)
403 tc.TestError(t, "Not Received msg within %d secs", 15)
408 //-----------------------------------------------------------------------------
410 //-----------------------------------------------------------------------------
411 func (tc *E2Stub) SendSubsDelReq(t *testing.T, oldTrans *RmrTransactionId, e2SubsId uint32) *RmrTransactionId {
415 trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
418 tc.Logger.Info("SendSubsDelReq %s", trans.String())
419 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
420 //---------------------------------
421 // xapp activity: Send Subs Del Req
422 //---------------------------------
423 req := &e2ap.E2APSubscriptionDeleteRequest{}
425 req.RequestId.Seq = e2SubsId
428 err, packedMsg := e2SubsDelReq.Pack(req)
430 tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
433 tc.Logger.Debug("%s %s", trans.String(), e2SubsDelReq.String())
435 params := xapptweaks.NewParams(nil)
436 params.Mtype = xapp.RIC_SUB_DEL_REQ
437 params.SubId = int(e2SubsId)
438 params.Payload = packedMsg.Buf
439 params.Meid = trans.meid
440 params.Xid = trans.xid
443 tc.Logger.Info("SEND SUB DEL REQ: %s", params.String())
444 snderr := tc.RmrSend(params)
446 tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
452 //-----------------------------------------------------------------------------
454 //-----------------------------------------------------------------------------
455 func (tc *E2Stub) RecvSubsDelReq(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *xapptweaks.RMRParams) {
456 tc.Logger.Info("RecvSubsDelReq")
457 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
459 //---------------------------------
460 // e2term activity: Recv Subs Del Req
461 //---------------------------------
462 msg := tc.WaitMsg(15)
464 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] {
465 tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_DEL_REQ", xapp.RicMessageTypeToName[msg.Mtype])
467 tc.Logger.Info("Recv Subs Del Req")
469 packedData := &e2ap.PackedData{}
470 packedData.Buf = msg.Payload
471 unpackerr, req := e2SubsDelReq.UnPack(packedData)
472 if unpackerr != nil {
473 tc.TestError(t, "RIC_SUB_DEL_REQ unpack failed err: %s", unpackerr.Error())
478 tc.TestError(t, "Not Received msg within %d secs", 15)
483 //-----------------------------------------------------------------------------
485 //-----------------------------------------------------------------------------
486 func (tc *E2Stub) SendSubsDelResp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapptweaks.RMRParams) {
487 tc.Logger.Info("SendSubsDelResp")
488 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
490 //---------------------------------
491 // e2term activity: Send Subs Del Resp
492 //---------------------------------
493 resp := &e2ap.E2APSubscriptionDeleteResponse{}
494 resp.RequestId.Id = req.RequestId.Id
495 resp.RequestId.Seq = req.RequestId.Seq
496 resp.FunctionId = req.FunctionId
498 packerr, packedMsg := e2SubsDelResp.Pack(resp)
500 tc.TestError(t, "pack NOK %s", packerr.Error())
502 tc.Logger.Debug("%s", e2SubsDelResp.String())
504 params := xapptweaks.NewParams(nil)
505 params.Mtype = xapp.RIC_SUB_DEL_RESP
506 params.SubId = msg.SubId
507 params.Payload = packedMsg.Buf
508 params.Meid = msg.Meid
512 tc.Logger.Info("SEND SUB DEL RESP: %s", params.String())
513 snderr := tc.RmrSend(params)
515 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
519 //-----------------------------------------------------------------------------
521 //-----------------------------------------------------------------------------
522 func (tc *E2Stub) RecvSubsDelResp(t *testing.T, trans *RmrTransactionId) {
523 tc.Logger.Info("RecvSubsDelResp")
524 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
526 //---------------------------------
527 // xapp activity: Recv Subs Del Resp
528 //---------------------------------
529 msg := tc.WaitMsg(15)
531 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
532 tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong mtype expected %s got %s, error", "RIC_SUB_DEL_RESP", xapp.RicMessageTypeToName[msg.Mtype])
534 } else if trans != nil && msg.Xid != trans.xid {
535 tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
538 packedData := &e2ap.PackedData{}
539 packedData.Buf = msg.Payload
540 unpackerr, resp := e2SubsDelResp.UnPack(packedData)
541 if unpackerr != nil {
542 tc.TestError(t, "RIC_SUB_DEL_RESP unpack failed err: %s", unpackerr.Error())
544 tc.Logger.Info("Recv Subs Del Resp rmr: xid=%s subid=%d, asn: seqnro=%d", msg.Xid, msg.SubId, resp.RequestId.Seq)
548 tc.TestError(t, "Not Received msg within %d secs", 15)
552 //-----------------------------------------------------------------------------
554 //-----------------------------------------------------------------------------
555 func (tc *E2Stub) SendSubsDelFail(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapptweaks.RMRParams) {
556 tc.Logger.Info("SendSubsDelFail")
557 e2SubsDelFail := e2asnpacker.NewPackerSubscriptionDeleteFailure()
559 //---------------------------------
560 // e2term activity: Send Subs Del Fail
561 //---------------------------------
562 resp := &e2ap.E2APSubscriptionDeleteFailure{}
563 resp.RequestId.Id = req.RequestId.Id
564 resp.RequestId.Seq = req.RequestId.Seq
565 resp.FunctionId = req.FunctionId
566 resp.Cause.Content = 3 // CauseMisc
567 resp.Cause.CauseVal = 4 // unspecified
569 packerr, packedMsg := e2SubsDelFail.Pack(resp)
571 tc.TestError(t, "pack NOK %s", packerr.Error())
573 tc.Logger.Debug("%s", e2SubsDelFail.String())
575 params := xapptweaks.NewParams(nil)
576 params.Mtype = xapp.RIC_SUB_DEL_FAILURE
577 params.SubId = msg.SubId
578 params.Payload = packedMsg.Buf
579 params.Meid = msg.Meid
583 tc.Logger.Info("SEND SUB DEL FAIL: %s", params.String())
584 snderr := tc.RmrSend(params)
586 tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())