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 func createSubsReq() *e2ap.E2APSubscriptionRequest {
41 req := &e2ap.E2APSubscriptionRequest{}
47 req.EventTriggerDefinition.InterfaceId.GlobalEnbId.Present = true
48 req.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.StringPut("310150")
49 req.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId.Id = 123
50 req.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId.Bits = e2ap.E2AP_ENBIDHomeBits28
52 // gnb -> enb outgoing
53 // enb -> gnb incoming
55 req.EventTriggerDefinition.InterfaceDirection = e2ap.E2AP_InterfaceDirectionIncoming
56 req.EventTriggerDefinition.ProcedureCode = 5 //28 35
57 req.EventTriggerDefinition.TypeOfMessage = e2ap.E2AP_InitiatingMessage
59 req.ActionSetups = make([]e2ap.ActionToBeSetupItem, 1)
60 req.ActionSetups[0].ActionId = 0
61 req.ActionSetups[0].ActionType = e2ap.E2AP_ActionTypeReport
62 req.ActionSetups[0].ActionDefinition.Present = false
63 //req.ActionSetups[index].ActionDefinition.StyleId = 255
64 //req.ActionSetups[index].ActionDefinition.ParamId = 222
65 req.ActionSetups[0].SubsequentAction.Present = true
66 req.ActionSetups[0].SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeContinue
67 req.ActionSetups[0].SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitZero
72 //-----------------------------------------------------------------------------
74 //-----------------------------------------------------------------------------
75 func createSubsResp(req *e2ap.E2APSubscriptionRequest) *e2ap.E2APSubscriptionResponse {
77 resp := &e2ap.E2APSubscriptionResponse{}
79 resp.RequestId.Id = req.RequestId.Id
80 resp.RequestId.Seq = req.RequestId.Seq
81 resp.FunctionId = req.FunctionId
83 resp.ActionAdmittedList.Items = make([]e2ap.ActionAdmittedItem, len(req.ActionSetups))
84 for index := int(0); index < len(req.ActionSetups); index++ {
85 resp.ActionAdmittedList.Items[index].ActionId = req.ActionSetups[index].ActionId
88 for index := uint64(0); index < 1; index++ {
89 item := e2ap.ActionNotAdmittedItem{}
91 item.Cause.Content = 1
92 item.Cause.CauseVal = 1
93 resp.ActionNotAdmittedList.Items = append(resp.ActionNotAdmittedList.Items, item)
99 //-----------------------------------------------------------------------------
101 //-----------------------------------------------------------------------------
102 func createSubsDelReq(e2SubsId uint32) *e2ap.E2APSubscriptionDeleteRequest {
103 req := &e2ap.E2APSubscriptionDeleteRequest{}
105 req.RequestId.Seq = e2SubsId
110 //-----------------------------------------------------------------------------
112 //-----------------------------------------------------------------------------
113 func createSubsDelResp(req *e2ap.E2APSubscriptionDeleteRequest) *e2ap.E2APSubscriptionDeleteResponse {
114 resp := &e2ap.E2APSubscriptionDeleteResponse{}
115 resp.RequestId.Id = req.RequestId.Id
116 resp.RequestId.Seq = req.RequestId.Seq
117 resp.FunctionId = req.FunctionId
121 //-----------------------------------------------------------------------------
123 //-----------------------------------------------------------------------------
124 func handle_xapp_subs_req(t *testing.T) {
125 xapp.Logger.Info("handle_xapp_subs_req start")
126 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
128 //---------------------------------
129 // xapp activity: Send Subs Req
130 //---------------------------------
132 //case <-time.After(1 * time.Second):
133 xapp.Logger.Info("(xappConn) Send Subs Req")
134 req := createSubsReq()
136 xapp.Logger.Debug("%s", e2SubsReq.String())
137 err, packedMsg := e2SubsReq.Pack(nil)
139 testError(t, "(xappConn) pack NOK %s", err.Error())
142 params := &xapp.RMRParams{}
143 params.Mtype = xapp.RIC_SUB_REQ
145 params.Payload = packedMsg.Buf
146 params.Meid = &xapp.RMRMeid{RanName: "RAN_NAME_1"}
150 snderr := xappConn.RmrSend(params)
152 testError(t, "(xappConn) RMR SEND FAILED: %s", snderr.Error())
157 //-----------------------------------------------------------------------------
159 //-----------------------------------------------------------------------------
160 func handle_e2term_subs_req(t *testing.T) (*e2ap.E2APSubscriptionRequest, *xapp.RMRParams) {
161 xapp.Logger.Info("handle_e2term_subs_req start")
162 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
164 //---------------------------------
165 // e2term activity: Recv Subs Req
166 //---------------------------------
168 case msg := <-e2termConn.rmrConChan:
169 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] {
170 testError(t, "(e2termConn) Received non RIC_SUB_REQ message")
172 xapp.Logger.Info("(e2termConn) Recv Subs Req")
173 packedData := &packer.PackedData{}
174 packedData.Buf = msg.Payload
175 unpackerr := e2SubsReq.UnPack(packedData)
176 if unpackerr != nil {
177 testError(t, "(e2termConn) RIC_SUB_REQ unpack failed err: %s", unpackerr.Error())
179 geterr, req := e2SubsReq.Get()
181 testError(t, "(e2termConn) RIC_SUB_REQ get failed err: %s", geterr.Error())
185 case <-time.After(15 * time.Second):
186 testError(t, "(e2termConn) Not Received RIC_SUB_REQ within 15 secs")
191 func handle_e2term_subs_resp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *xapp.RMRParams) {
192 xapp.Logger.Info("handle_e2term_subs_resp start")
193 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
195 //---------------------------------
196 // e2term activity: Send Subs Resp
197 //---------------------------------
198 xapp.Logger.Info("(e2termConn) Send Subs Resp")
199 resp := createSubsResp(req)
201 xapp.Logger.Debug("%s", e2SubsResp.String())
202 packerr, packedMsg := e2SubsResp.Pack(nil)
204 testError(t, "(e2termConn) pack NOK %s", packerr.Error())
207 params := &xapp.RMRParams{}
208 params.Mtype = xapp.RIC_SUB_RESP
209 params.SubId = msg.SubId
210 params.Payload = packedMsg.Buf
211 params.Meid = msg.Meid
215 snderr := e2termConn.RmrSend(params)
217 testError(t, "(e2termConn) RMR SEND FAILED: %s", snderr.Error())
221 func handle_e2term_subs_reqandresp(t *testing.T) {
222 req, msg := handle_e2term_subs_req(t)
223 handle_e2term_subs_resp(t, req, msg)
226 //-----------------------------------------------------------------------------
228 //-----------------------------------------------------------------------------
229 func handle_xapp_subs_resp(t *testing.T) int {
230 xapp.Logger.Info("handle_xapp_subs_resp start")
231 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
234 //---------------------------------
235 // xapp activity: Recv Subs Resp
236 //---------------------------------
238 case msg := <-xappConn.rmrConChan:
239 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
240 testError(t, "(xappConn) Received non RIC_SUB_RESP message")
242 xapp.Logger.Info("(xappConn) Recv Subs Resp")
244 packedData := &packer.PackedData{}
245 packedData.Buf = msg.Payload
247 unpackerr := e2SubsResp.UnPack(packedData)
249 if unpackerr != nil {
250 testError(t, "(xappConn) RIC_SUB_RESP unpack failed err: %s", unpackerr.Error())
252 geterr, _ := e2SubsResp.Get()
254 testError(t, "(xappConn) RIC_SUB_RESP get failed err: %s", geterr.Error())
258 case <-time.After(15 * time.Second):
259 testError(t, "(xappConn) Not Received RIC_SUB_RESP within 15 secs")
264 //-----------------------------------------------------------------------------
266 //-----------------------------------------------------------------------------
267 func handle_xapp_subs_del_req(t *testing.T, e2SubsId int) {
268 xapp.Logger.Info("handle_xapp_subs_del_req start")
269 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
271 //---------------------------------
272 // xapp activity: Send Subs Del Req
273 //---------------------------------
275 //case <-time.After(1 * time.Second):
276 xapp.Logger.Info("(xappConn) Send Subs Del Req")
277 req := createSubsDelReq(uint32(e2SubsId))
278 e2SubsDelReq.Set(req)
279 xapp.Logger.Debug("%s", e2SubsDelReq.String())
280 err, packedMsg := e2SubsDelReq.Pack(nil)
282 testError(t, "(xappConn) pack NOK %s", err.Error())
285 params := &xapp.RMRParams{}
286 params.Mtype = xapp.RIC_SUB_DEL_REQ
287 params.SubId = e2SubsId
288 params.Payload = packedMsg.Buf
289 params.Meid = &xapp.RMRMeid{RanName: "RAN_NAME_1"}
293 snderr := xappConn.RmrSend(params)
295 testError(t, "(xappConn) RMR SEND FAILED: %s", snderr.Error())
300 //-----------------------------------------------------------------------------
302 //-----------------------------------------------------------------------------
303 func handle_e2term_subs_del_req(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *xapp.RMRParams) {
304 xapp.Logger.Info("handle_e2term_subs_del_req start")
305 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
307 //---------------------------------
308 // e2term activity: Recv Subs Del Req
309 //---------------------------------
311 case msg := <-e2termConn.rmrConChan:
312 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] {
313 testError(t, "(e2termConn) Received non RIC_SUB_DEL_REQ message")
315 xapp.Logger.Info("(e2termConn) Recv Subs Del Req")
317 packedData := &packer.PackedData{}
318 packedData.Buf = msg.Payload
319 unpackerr := e2SubsDelReq.UnPack(packedData)
320 if unpackerr != nil {
321 testError(t, "(e2termConn) RIC_SUB_DEL_REQ unpack failed err: %s", unpackerr.Error())
323 geterr, req := e2SubsDelReq.Get()
325 testError(t, "(e2termConn) RIC_SUB_DEL_REQ get failed err: %s", geterr.Error())
329 case <-time.After(15 * time.Second):
330 testError(t, "(e2termConn) Not Received RIC_SUB_DEL_REQ within 15 secs")
335 func handle_e2term_subs_del_resp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapp.RMRParams) {
336 xapp.Logger.Info("handle_e2term_subs_del_resp start")
337 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
339 //---------------------------------
340 // e2term activity: Send Subs Del Resp
341 //---------------------------------
342 xapp.Logger.Info("(e2termConn) Send Subs Del Resp")
343 resp := createSubsDelResp(req)
344 e2SubsDelResp.Set(resp)
345 xapp.Logger.Debug("%s", e2SubsDelResp.String())
346 packerr, packedMsg := e2SubsDelResp.Pack(nil)
348 testError(t, "(e2termConn) pack NOK %s", packerr.Error())
351 params := &xapp.RMRParams{}
352 params.Mtype = xapp.RIC_SUB_DEL_RESP
353 params.SubId = msg.SubId
354 params.Payload = packedMsg.Buf
355 params.Meid = msg.Meid
359 snderr := e2termConn.RmrSend(params)
361 testError(t, "(e2termConn) RMR SEND FAILED: %s", snderr.Error())
366 func handle_e2term_subs_del_reqandresp(t *testing.T) {
367 req, msg := handle_e2term_subs_del_req(t)
368 handle_e2term_subs_del_resp(t, req, msg)
371 //-----------------------------------------------------------------------------
373 //-----------------------------------------------------------------------------
374 func handle_xapp_subs_del_resp(t *testing.T) {
375 xapp.Logger.Info("handle_xapp_subs_del_resp start")
376 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
378 //---------------------------------
379 // xapp activity: Recv Subs Del Resp
380 //---------------------------------
382 case msg := <-xappConn.rmrConChan:
383 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
384 testError(t, "(xappConn) Received non RIC_SUB_DEL_RESP message")
386 xapp.Logger.Info("(xappConn) Recv Subs Del Resp")
388 packedData := &packer.PackedData{}
389 packedData.Buf = msg.Payload
390 unpackerr := e2SubsDelResp.UnPack(packedData)
391 if unpackerr != nil {
392 testError(t, "(xappConn) RIC_SUB_DEL_RESP unpack failed err: %s", unpackerr.Error())
394 geterr, _ := e2SubsDelResp.Get()
396 testError(t, "(xappConn) RIC_SUB_DEL_RESP get failed err: %s", geterr.Error())
400 case <-time.After(15 * time.Second):
401 testError(t, "(xappConn) Not Received RIC_SUB_DEL_RESP within 15 secs")
405 //-----------------------------------------------------------------------------
407 //-----------------------------------------------------------------------------
408 func handle_wait_subs_clean(t *testing.T, e2SubsId int) bool {
409 xapp.Logger.Info("handle_wait_subs_clean start")
410 if mainCtrl.wait_subs_clean(e2SubsId, 10) == false {
411 testError(t, "(general) no clean within 10 secs")
417 //-----------------------------------------------------------------------------
418 // TestSubReqAndSubDelOk
421 // +-------+ +---------+ +---------+
422 // | xapp | | submgr | | e2term |
423 // +-------+ +---------+ +---------+
426 // |------------->| |
429 // | |------------->|
432 // | |<-------------|
435 // |<-------------| |
439 // |------------->| |
442 // | |------------->|
445 // | |<-------------|
448 // |<-------------| |
450 //-----------------------------------------------------------------------------
451 func TestSubReqAndSubDelOk(t *testing.T) {
452 xapp.Logger.Info("TestSubReqAndSubDelOk start")
454 handle_xapp_subs_req(t)
455 handle_e2term_subs_reqandresp(t)
456 e2SubsId := handle_xapp_subs_resp(t)
458 handle_xapp_subs_del_req(t, e2SubsId)
459 handle_e2term_subs_del_reqandresp(t)
460 handle_xapp_subs_del_resp(t)
462 //Wait that subs is cleaned
463 handle_wait_subs_clean(t, e2SubsId)
466 //-----------------------------------------------------------------------------
467 // TestSubReqRetransmission
470 // +-------+ +---------+ +---------+
471 // | xapp | | submgr | | e2term |
472 // +-------+ +---------+ +---------+
475 // |------------->| |
478 // | |------------->|
482 // |------------->| |
485 // | |<-------------|
488 // |<-------------| |
493 //-----------------------------------------------------------------------------
494 func TestSubReqRetransmission(t *testing.T) {
495 xapp.Logger.Info("TestSubReqRetransmission start")
498 handle_xapp_subs_req(t)
499 req, msg := handle_e2term_subs_req(t)
500 handle_xapp_subs_req(t)
502 handle_e2term_subs_resp(t, req, msg)
504 e2SubsId := handle_xapp_subs_resp(t)
507 handle_xapp_subs_del_req(t, e2SubsId)
508 handle_e2term_subs_del_reqandresp(t)
509 handle_xapp_subs_del_resp(t)
511 //Wait that subs is cleaned
512 handle_wait_subs_clean(t, e2SubsId)
515 //-----------------------------------------------------------------------------
516 // TestSubDelReqRetransmission
519 // +-------+ +---------+ +---------+
520 // | xapp | | submgr | | e2term |
521 // +-------+ +---------+ +---------+
527 // |------------->| |
530 // | |------------->|
533 // |------------->| |
536 // | |<-------------|
539 // |<-------------| |
541 //-----------------------------------------------------------------------------
542 func TestSubDelReqRetransmission(t *testing.T) {
543 xapp.Logger.Info("TestSubDelReqRetransmission start")
546 handle_xapp_subs_req(t)
547 handle_e2term_subs_reqandresp(t)
548 e2SubsId := handle_xapp_subs_resp(t)
551 handle_xapp_subs_del_req(t, e2SubsId)
552 req, msg := handle_e2term_subs_del_req(t)
554 <-time.After(2 * time.Second)
556 handle_xapp_subs_del_req(t, e2SubsId)
558 handle_e2term_subs_del_resp(t, req, msg)
560 //Wait that subs is cleaned
561 handle_wait_subs_clean(t, e2SubsId)