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/e2ap/pkg/packer"
26 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 var e2asnpacker e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
40 type xappTransaction struct {
41 xappConn *testingXappControl
45 func newXappTransaction(xappConn *testingXappControl) {
46 trans := &xappTransaction{}
47 trans.xappConn = xappConn
48 trans.xid = xappConn.newXid()
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
54 func (xappConn *testingXappControl) handle_xapp_subs_req(t *testing.T, updseq bool) {
55 xapp.Logger.Info("handle_xapp_subs_req")
56 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
58 //---------------------------------
59 // xapp activity: Send Subs Req
60 //---------------------------------
61 xapp.Logger.Info("(%s) Send Subs Req", xappConn.desc)
63 req := &e2ap.E2APSubscriptionRequest{}
69 req.EventTriggerDefinition.InterfaceId.GlobalEnbId.Present = true
70 req.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.StringPut("310150")
71 req.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId.Id = 123
72 req.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId.Bits = e2ap.E2AP_ENBIDHomeBits28
74 // gnb -> enb outgoing
75 // enb -> gnb incoming
77 req.EventTriggerDefinition.InterfaceDirection = e2ap.E2AP_InterfaceDirectionIncoming
78 req.EventTriggerDefinition.ProcedureCode = 5 //28 35
79 req.EventTriggerDefinition.TypeOfMessage = e2ap.E2AP_InitiatingMessage
81 req.ActionSetups = make([]e2ap.ActionToBeSetupItem, 1)
82 req.ActionSetups[0].ActionId = 0
83 req.ActionSetups[0].ActionType = e2ap.E2AP_ActionTypeReport
84 req.ActionSetups[0].ActionDefinition.Present = false
85 //req.ActionSetups[index].ActionDefinition.StyleId = 255
86 //req.ActionSetups[index].ActionDefinition.ParamId = 222
87 req.ActionSetups[0].SubsequentAction.Present = true
88 req.ActionSetups[0].SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeContinue
89 req.ActionSetups[0].SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitZero
92 xapp.Logger.Debug("%s", e2SubsReq.String())
93 err, packedMsg := e2SubsReq.Pack(nil)
95 testError(t, "(%s) pack NOK %s", xappConn.desc, err.Error())
98 params := &xapp.RMRParams{}
99 params.Mtype = xapp.RIC_SUB_REQ
101 params.Payload = packedMsg.Buf
102 params.Meid = xappConn.meid
106 params.Xid = xappConn.xid
109 snderr := xappConn.RmrSend(params)
111 testError(t, "(%s) RMR SEND FAILED: %s", xappConn.desc, snderr.Error())
115 //-----------------------------------------------------------------------------
117 //-----------------------------------------------------------------------------
118 func (xappConn *testingXappControl) handle_xapp_subs_resp(t *testing.T) int {
119 xapp.Logger.Info("handle_xapp_subs_resp")
120 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
123 //---------------------------------
124 // xapp activity: Recv Subs Resp
125 //---------------------------------
127 case msg := <-xappConn.rmrConChan:
128 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
129 testError(t, "(%s) Received wrong mtype expected %s got %s, error", xappConn.desc, "RIC_SUB_RESP", xapp.RicMessageTypeToName[msg.Mtype])
132 packedData := &packer.PackedData{}
133 packedData.Buf = msg.Payload
135 unpackerr := e2SubsResp.UnPack(packedData)
137 if unpackerr != nil {
138 testError(t, "(%s) RIC_SUB_RESP unpack failed err: %s", xappConn.desc, unpackerr.Error())
140 geterr, resp := e2SubsResp.Get()
142 testError(t, "(%s) RIC_SUB_RESP get failed err: %s", xappConn.desc, geterr.Error())
145 xapp.Logger.Info("(%s) Recv Subs Resp rmr: xid=%s subid=%d, asn: seqnro=%d", xappConn.desc, msg.Xid, msg.SubId, resp.RequestId.Seq)
148 case <-time.After(15 * time.Second):
149 testError(t, "(%s) Not Received RIC_SUB_RESP within 15 secs", xappConn.desc)
155 //-----------------------------------------------------------------------------
157 //-----------------------------------------------------------------------------
158 func (xappConn *testingXappControl) handle_xapp_subs_del_req(t *testing.T, updseq bool, e2SubsId int) {
159 xapp.Logger.Info("handle_xapp_subs_del_req")
160 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
162 //---------------------------------
163 // xapp activity: Send Subs Del Req
164 //---------------------------------
165 xapp.Logger.Info("(%s) Send Subs Del Req", xappConn.desc)
167 req := &e2ap.E2APSubscriptionDeleteRequest{}
169 req.RequestId.Seq = uint32(e2SubsId)
172 e2SubsDelReq.Set(req)
173 xapp.Logger.Debug("%s", e2SubsDelReq.String())
174 err, packedMsg := e2SubsDelReq.Pack(nil)
176 testError(t, "(%s) pack NOK %s", xappConn.desc, err.Error())
179 params := &xapp.RMRParams{}
180 params.Mtype = xapp.RIC_SUB_DEL_REQ
181 params.SubId = e2SubsId
182 params.Payload = packedMsg.Buf
183 params.Meid = xappConn.meid
187 params.Xid = xappConn.xid
190 snderr := xappConn.RmrSend(params)
192 testError(t, "(%s) RMR SEND FAILED: %s", xappConn.desc, snderr.Error())
196 //-----------------------------------------------------------------------------
198 //-----------------------------------------------------------------------------
199 func (xappConn *testingXappControl) handle_xapp_subs_del_resp(t *testing.T) {
200 xapp.Logger.Info("handle_xapp_subs_del_resp")
201 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
203 //---------------------------------
204 // xapp activity: Recv Subs Del Resp
205 //---------------------------------
207 case msg := <-xappConn.rmrConChan:
208 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
209 testError(t, "(%s) Received wrong mtype expected %s got %s, error", xappConn.desc, "RIC_SUB_DEL_RESP", xapp.RicMessageTypeToName[msg.Mtype])
212 packedData := &packer.PackedData{}
213 packedData.Buf = msg.Payload
214 unpackerr := e2SubsDelResp.UnPack(packedData)
215 if unpackerr != nil {
216 testError(t, "(%s) RIC_SUB_DEL_RESP unpack failed err: %s", xappConn.desc, unpackerr.Error())
218 geterr, resp := e2SubsDelResp.Get()
220 testError(t, "(%s) RIC_SUB_DEL_RESP get failed err: %s", xappConn.desc, geterr.Error())
222 xapp.Logger.Info("(%s) Recv Subs Del Resp rmr: xid=%s subid=%d, asn: seqnro=%d", xappConn.desc, msg.Xid, msg.SubId, resp.RequestId.Seq)
225 case <-time.After(15 * time.Second):
226 testError(t, "(%s) Not Received RIC_SUB_DEL_RESP within 15 secs", xappConn.desc)
230 //-----------------------------------------------------------------------------
232 //-----------------------------------------------------------------------------
233 func (e2termConn *testingE2termControl) handle_e2term_subs_req(t *testing.T) (*e2ap.E2APSubscriptionRequest, *xapp.RMRParams) {
234 xapp.Logger.Info("handle_e2term_subs_req")
235 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
237 //---------------------------------
238 // e2term activity: Recv Subs Req
239 //---------------------------------
241 case msg := <-e2termConn.rmrConChan:
242 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] {
243 testError(t, "(%s) Received wrong mtype expected %s got %s, error", e2termConn.desc, "RIC_SUB_REQ", xapp.RicMessageTypeToName[msg.Mtype])
245 xapp.Logger.Info("(%s) Recv Subs Req", e2termConn.desc)
246 packedData := &packer.PackedData{}
247 packedData.Buf = msg.Payload
248 unpackerr := e2SubsReq.UnPack(packedData)
249 if unpackerr != nil {
250 testError(t, "(%s) RIC_SUB_REQ unpack failed err: %s", e2termConn.desc, unpackerr.Error())
252 geterr, req := e2SubsReq.Get()
254 testError(t, "(%s) RIC_SUB_REQ get failed err: %s", e2termConn.desc, geterr.Error())
258 case <-time.After(15 * time.Second):
259 testError(t, "(%s) Not Received RIC_SUB_REQ within 15 secs", e2termConn.desc)
264 func (e2termConn *testingE2termControl) handle_e2term_subs_resp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *xapp.RMRParams) {
265 xapp.Logger.Info("handle_e2term_subs_resp")
266 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
268 //---------------------------------
269 // e2term activity: Send Subs Resp
270 //---------------------------------
271 xapp.Logger.Info("(%s) Send Subs Resp", e2termConn.desc)
273 resp := &e2ap.E2APSubscriptionResponse{}
275 resp.RequestId.Id = req.RequestId.Id
276 resp.RequestId.Seq = req.RequestId.Seq
277 resp.FunctionId = req.FunctionId
279 resp.ActionAdmittedList.Items = make([]e2ap.ActionAdmittedItem, len(req.ActionSetups))
280 for index := int(0); index < len(req.ActionSetups); index++ {
281 resp.ActionAdmittedList.Items[index].ActionId = req.ActionSetups[index].ActionId
284 for index := uint64(0); index < 1; index++ {
285 item := e2ap.ActionNotAdmittedItem{}
286 item.ActionId = index
287 item.Cause.Content = 1
288 item.Cause.CauseVal = 1
289 resp.ActionNotAdmittedList.Items = append(resp.ActionNotAdmittedList.Items, item)
293 xapp.Logger.Debug("%s", e2SubsResp.String())
294 packerr, packedMsg := e2SubsResp.Pack(nil)
296 testError(t, "(%s) pack NOK %s", e2termConn.desc, packerr.Error())
299 params := &xapp.RMRParams{}
300 params.Mtype = xapp.RIC_SUB_RESP
301 params.SubId = msg.SubId
302 params.Payload = packedMsg.Buf
303 params.Meid = msg.Meid
307 snderr := e2termConn.RmrSend(params)
309 testError(t, "(%s) RMR SEND FAILED: %s", e2termConn.desc, snderr.Error())
313 //-----------------------------------------------------------------------------
315 //-----------------------------------------------------------------------------
316 func (e2termConn *testingE2termControl) handle_e2term_subs_del_req(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *xapp.RMRParams) {
317 xapp.Logger.Info("handle_e2term_subs_del_req")
318 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
320 //---------------------------------
321 // e2term activity: Recv Subs Del Req
322 //---------------------------------
324 case msg := <-e2termConn.rmrConChan:
325 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] {
326 testError(t, "(%s) Received wrong mtype expected %s got %s, error", e2termConn.desc, "RIC_SUB_DEL_REQ", xapp.RicMessageTypeToName[msg.Mtype])
328 xapp.Logger.Info("(%s) Recv Subs Del Req", e2termConn.desc)
330 packedData := &packer.PackedData{}
331 packedData.Buf = msg.Payload
332 unpackerr := e2SubsDelReq.UnPack(packedData)
333 if unpackerr != nil {
334 testError(t, "(%s) RIC_SUB_DEL_REQ unpack failed err: %s", e2termConn.desc, unpackerr.Error())
336 geterr, req := e2SubsDelReq.Get()
338 testError(t, "(%s) RIC_SUB_DEL_REQ get failed err: %s", e2termConn.desc, geterr.Error())
342 case <-time.After(15 * time.Second):
343 testError(t, "(%s) Not Received RIC_SUB_DEL_REQ within 15 secs", e2termConn.desc)
348 func handle_e2term_recv_empty() bool {
349 if len(e2termConn.rmrConChan) > 0 {
355 func (e2termConn *testingE2termControl) handle_e2term_subs_del_resp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapp.RMRParams) {
356 xapp.Logger.Info("handle_e2term_subs_del_resp")
357 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
359 //---------------------------------
360 // e2term activity: Send Subs Del Resp
361 //---------------------------------
362 xapp.Logger.Info("(%s) Send Subs Del Resp", e2termConn.desc)
364 resp := &e2ap.E2APSubscriptionDeleteResponse{}
365 resp.RequestId.Id = req.RequestId.Id
366 resp.RequestId.Seq = req.RequestId.Seq
367 resp.FunctionId = req.FunctionId
369 e2SubsDelResp.Set(resp)
370 xapp.Logger.Debug("%s", e2SubsDelResp.String())
371 packerr, packedMsg := e2SubsDelResp.Pack(nil)
373 testError(t, "(%s) pack NOK %s", e2termConn.desc, packerr.Error())
376 params := &xapp.RMRParams{}
377 params.Mtype = xapp.RIC_SUB_DEL_RESP
378 params.SubId = msg.SubId
379 params.Payload = packedMsg.Buf
380 params.Meid = msg.Meid
384 snderr := e2termConn.RmrSend(params)
386 testError(t, "(%s) RMR SEND FAILED: %s", e2termConn.desc, snderr.Error())
391 //-----------------------------------------------------------------------------
393 //-----------------------------------------------------------------------------
394 func (mc *testingMainControl) wait_subs_clean(t *testing.T, e2SubsId int, secs int) bool {
396 for ; i <= secs*2; i++ {
397 if mc.c.registry.IsValidSequenceNumber(uint16(e2SubsId)) == false {
400 time.Sleep(500 * time.Millisecond)
402 testError(t, "(general) no clean within %d secs", secs)
406 //-----------------------------------------------------------------------------
407 // TestSubReqAndSubDelOk
410 // +-------+ +---------+ +---------+
411 // | xapp | | submgr | | e2term |
412 // +-------+ +---------+ +---------+
415 // |------------->| |
418 // | |------------->|
421 // | |<-------------|
424 // |<-------------| |
428 // |------------->| |
431 // | |------------->|
434 // | |<-------------|
437 // |<-------------| |
439 //-----------------------------------------------------------------------------
440 func TestSubReqAndSubDelOk(t *testing.T) {
441 xapp.Logger.Info("TestSubReqAndSubDelOk")
443 xappConn1.handle_xapp_subs_req(t, true)
444 crereq, cremsg := e2termConn.handle_e2term_subs_req(t)
445 e2termConn.handle_e2term_subs_resp(t, crereq, cremsg)
446 e2SubsId := xappConn1.handle_xapp_subs_resp(t)
448 xappConn1.handle_xapp_subs_del_req(t, true, e2SubsId)
449 delreq, delmsg := e2termConn.handle_e2term_subs_del_req(t)
450 e2termConn.handle_e2term_subs_del_resp(t, delreq, delmsg)
451 xappConn1.handle_xapp_subs_del_resp(t)
453 //Wait that subs is cleaned
454 mainCtrl.wait_subs_clean(t, e2SubsId, 10)
457 //-----------------------------------------------------------------------------
458 // TestSubReqRetransmission
461 // +-------+ +---------+ +---------+
462 // | xapp | | submgr | | e2term |
463 // +-------+ +---------+ +---------+
466 // |------------->| |
469 // | |------------->|
473 // |------------->| |
476 // | |<-------------|
479 // |<-------------| |
484 //-----------------------------------------------------------------------------
485 func TestSubReqRetransmission(t *testing.T) {
486 xapp.Logger.Info("TestSubReqRetransmission")
489 xappConn1.handle_xapp_subs_req(t, true)
490 crereq, cremsg := e2termConn.handle_e2term_subs_req(t)
491 xappConn1.handle_xapp_subs_req(t, false)
493 e2termConn.handle_e2term_subs_resp(t, crereq, cremsg)
495 e2SubsId := xappConn1.handle_xapp_subs_resp(t)
498 xappConn1.handle_xapp_subs_del_req(t, true, e2SubsId)
499 delreq, delmsg := e2termConn.handle_e2term_subs_del_req(t)
500 e2termConn.handle_e2term_subs_del_resp(t, delreq, delmsg)
501 xappConn1.handle_xapp_subs_del_resp(t)
503 //Wait that subs is cleaned
504 mainCtrl.wait_subs_clean(t, e2SubsId, 10)
507 //-----------------------------------------------------------------------------
508 // TestSubDelReqRetransmission
511 // +-------+ +---------+ +---------+
512 // | xapp | | submgr | | e2term |
513 // +-------+ +---------+ +---------+
519 // |------------->| |
522 // | |------------->|
525 // |------------->| |
528 // | |<-------------|
531 // |<-------------| |
533 //-----------------------------------------------------------------------------
534 func TestSubDelReqRetransmission(t *testing.T) {
535 xapp.Logger.Info("TestSubDelReqRetransmission")
538 xappConn1.handle_xapp_subs_req(t, true)
539 crereq, cremsg := e2termConn.handle_e2term_subs_req(t)
540 e2termConn.handle_e2term_subs_resp(t, crereq, cremsg)
541 e2SubsId := xappConn1.handle_xapp_subs_resp(t)
544 xappConn1.handle_xapp_subs_del_req(t, true, e2SubsId)
545 delreq, delmsg := e2termConn.handle_e2term_subs_del_req(t)
547 <-time.After(2 * time.Second)
548 xappConn1.handle_xapp_subs_del_req(t, false, e2SubsId)
550 e2termConn.handle_e2term_subs_del_resp(t, delreq, delmsg)
551 xappConn1.handle_xapp_subs_del_resp(t)
553 //Wait that subs is cleaned
554 mainCtrl.wait_subs_clean(t, e2SubsId, 10)
557 //-----------------------------------------------------------------------------
558 // TestSubReqAndSubDelOkTwoParallel
561 // +-------+ +---------+ +---------+
562 // | xapp | | submgr | | e2term |
563 // +-------+ +---------+ +---------+
568 // |------------->| |
571 // | |------------->|
574 // |------------->| |
577 // | |------------->|
580 // | |<-------------|
582 // | |<-------------|
585 // |<-------------| |
587 // |<-------------| |
589 // | [SUBS 1 DELETE] |
591 // | [SUBS 2 DELETE] |
594 //-----------------------------------------------------------------------------
595 func TestSubReqAndSubDelOkTwoParallel(t *testing.T) {
596 xapp.Logger.Info("TestSubReqAndSubDelOkTwoParallel")
599 xappConn1.handle_xapp_subs_req(t, true)
600 crereq1, cremsg1 := e2termConn.handle_e2term_subs_req(t)
603 xappConn2.handle_xapp_subs_req(t, true)
604 crereq2, cremsg2 := e2termConn.handle_e2term_subs_req(t)
607 e2termConn.handle_e2term_subs_resp(t, crereq1, cremsg1)
608 e2SubsId1 := xappConn1.handle_xapp_subs_resp(t)
611 e2termConn.handle_e2term_subs_resp(t, crereq2, cremsg2)
612 e2SubsId2 := xappConn2.handle_xapp_subs_resp(t)
615 xappConn1.handle_xapp_subs_del_req(t, true, e2SubsId1)
616 delreq1, delmsg1 := e2termConn.handle_e2term_subs_del_req(t)
617 e2termConn.handle_e2term_subs_del_resp(t, delreq1, delmsg1)
618 xappConn1.handle_xapp_subs_del_resp(t)
619 //Wait that subs is cleaned
620 mainCtrl.wait_subs_clean(t, e2SubsId1, 10)
623 xappConn2.handle_xapp_subs_del_req(t, true, e2SubsId2)
624 delreq2, delmsg2 := e2termConn.handle_e2term_subs_del_req(t)
625 e2termConn.handle_e2term_subs_del_resp(t, delreq2, delmsg2)
626 xappConn2.handle_xapp_subs_del_resp(t)
627 //Wait that subs is cleaned
628 mainCtrl.wait_subs_clean(t, e2SubsId2, 10)