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()
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
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)
102 func createSubsDelReq(e2SubsId uint32) *e2ap.E2APSubscriptionDeleteRequest {
103 req := &e2ap.E2APSubscriptionDeleteRequest{}
105 req.RequestId.Seq = e2SubsId
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 //-----------------------------------------------------------------------------
122 // TestSubRequestSubResponseOk
125 // +-------+ +---------+ +---------+
126 // | xapp | | submgr | | e2term |
127 // +-------+ +---------+ +---------+
130 // |------------->| |
133 // | |------------->|
136 // | |<-------------|
139 // |<-------------| |
143 // |------------->| |
146 // | |------------->|
149 // | |<-------------|
152 // |<-------------| |
154 //-----------------------------------------------------------------------------
155 func TestSubReqAndSubDelOk(t *testing.T) {
157 xapp.Logger.Info("TestSubReqAndSubDelOk start")
158 e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
159 e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
160 e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
161 e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
164 //---------------------------------
165 // xapp activity: Send Subs Req
166 //---------------------------------
168 case <-time.After(5 * time.Second):
169 xapp.Logger.Info("(xappConn) Send Subs Req")
170 req := createSubsReq()
172 xapp.Logger.Debug("%s", e2SubsReq.String())
173 err, packedMsg := e2SubsReq.Pack(nil)
175 testError(t, "(xappConn) pack NOK %s", err.Error())
178 params := &xapp.RMRParams{}
179 params.Mtype = xapp.RIC_SUB_REQ
181 params.Payload = packedMsg.Buf
182 params.Meid = &xapp.RMRMeid{RanName: "RAN_NAME_1"}
186 snderr := xappConn.RmrSend(params)
188 testError(t, "(xappConn) RMR SEND FAILED: %s", snderr.Error())
192 //---------------------------------
193 // e2term activity: Recv Subs Req & Send Subs Resp
194 //---------------------------------
196 case msg := <-e2termConn.rmrConChan:
197 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] {
198 testError(t, "(e2termConn) Received non RIC_SUB_REQ message")
200 xapp.Logger.Info("(e2termConn) Recv Subs Req & Send Subs Resp")
201 packedData := &packer.PackedData{}
202 packedData.Buf = msg.Payload
203 unpackerr := e2SubsReq.UnPack(packedData)
204 if unpackerr != nil {
205 testError(t, "(e2termConn) RIC_SUB_REQ unpack failed err: %s", unpackerr.Error())
207 geterr, req := e2SubsReq.Get()
209 testError(t, "(e2termConn) RIC_SUB_REQ get failed err: %s", geterr.Error())
212 resp := createSubsResp(req)
214 xapp.Logger.Debug("%s", e2SubsResp.String())
215 packerr, packedMsg := e2SubsResp.Pack(nil)
217 testError(t, "(e2termConn) pack NOK %s", packerr.Error())
220 params := &xapp.RMRParams{}
221 params.Mtype = xapp.RIC_SUB_RESP
222 params.SubId = msg.SubId
223 params.Payload = packedMsg.Buf
224 params.Meid = msg.Meid
228 snderr := e2termConn.RmrSend(params)
230 testError(t, "(e2termConn) RMR SEND FAILED: %s", snderr.Error())
234 case <-time.After(15 * time.Second):
235 testError(t, "(e2termConn) Not Received RIC_SUB_REQ within 15 secs")
238 //---------------------------------
239 // xapp activity: Recv Subs Resp
240 //---------------------------------
242 case msg := <-xappConn.rmrConChan:
243 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
244 testError(t, "(xappConn) Received non RIC_SUB_RESP message")
246 xapp.Logger.Info("(xappConn) Recv Subs Resp")
248 packedData := &packer.PackedData{}
249 packedData.Buf = msg.Payload
251 unpackerr := e2SubsResp.UnPack(packedData)
253 if unpackerr != nil {
254 testError(t, "(xappConn) RIC_SUB_RESP unpack failed err: %s", unpackerr.Error())
256 geterr, _ := e2SubsResp.Get()
258 testError(t, "(xappConn) RIC_SUB_RESP get failed err: %s", geterr.Error())
262 case <-time.After(15 * time.Second):
263 testError(t, "(xappConn) Not Received RIC_SUB_RESP within 15 secs")
266 //---------------------------------
267 // xapp activity: Send Subs Del Req
268 //---------------------------------
270 case <-time.After(2 * time.Second):
271 xapp.Logger.Info("(xappConn) Send Subs Del Req")
272 req := createSubsDelReq(uint32(e2SubsId))
273 e2SubsDelReq.Set(req)
274 xapp.Logger.Debug("%s", e2SubsDelReq.String())
275 err, packedMsg := e2SubsDelReq.Pack(nil)
277 testError(t, "(xappConn) pack NOK %s", err.Error())
280 params := &xapp.RMRParams{}
281 params.Mtype = xapp.RIC_SUB_DEL_REQ
282 params.SubId = e2SubsId
283 params.Payload = packedMsg.Buf
284 params.Meid = &xapp.RMRMeid{RanName: "RAN_NAME_1"}
288 snderr := xappConn.RmrSend(params)
290 testError(t, "(xappConn) RMR SEND FAILED: %s", snderr.Error())
294 //---------------------------------
295 // e2term activity: Recv Subs Del Req & Send Subs Del Resp
296 //---------------------------------
298 case msg := <-e2termConn.rmrConChan:
299 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] {
300 testError(t, "(e2termConn) Received non RIC_SUB_DEL_REQ message")
302 xapp.Logger.Info("(e2termConn) Recv Subs Del Req & Send Subs Del Resp")
304 packedData := &packer.PackedData{}
305 packedData.Buf = msg.Payload
306 unpackerr := e2SubsDelReq.UnPack(packedData)
307 if unpackerr != nil {
308 testError(t, "(e2termConn) RIC_SUB_DEL_REQ unpack failed err: %s", unpackerr.Error())
310 geterr, req := e2SubsDelReq.Get()
312 testError(t, "(e2termConn) RIC_SUB_DEL_REQ get failed err: %s", geterr.Error())
315 resp := createSubsDelResp(req)
316 e2SubsDelResp.Set(resp)
317 xapp.Logger.Debug("%s", e2SubsDelResp.String())
318 packerr, packedMsg := e2SubsDelResp.Pack(nil)
320 testError(t, "(e2termConn) pack NOK %s", packerr.Error())
323 params := &xapp.RMRParams{}
324 params.Mtype = xapp.RIC_SUB_DEL_RESP
325 params.SubId = msg.SubId
326 params.Payload = packedMsg.Buf
327 params.Meid = msg.Meid
331 snderr := e2termConn.RmrSend(params)
333 testError(t, "(e2termConn) RMR SEND FAILED: %s", snderr.Error())
337 case <-time.After(15 * time.Second):
338 testError(t, "(e2termConn) Not Received RIC_SUB_DEL_REQ within 15 secs")
341 //---------------------------------
342 // xapp activity: Recv Subs Del Resp
343 //---------------------------------
345 case msg := <-xappConn.rmrConChan:
346 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
347 testError(t, "(xappConn) Received non RIC_SUB_DEL_RESP message")
349 xapp.Logger.Info("(xappConn) Recv Subs Del Resp")
351 packedData := &packer.PackedData{}
352 packedData.Buf = msg.Payload
353 unpackerr := e2SubsDelResp.UnPack(packedData)
354 if unpackerr != nil {
355 testError(t, "(xappConn) RIC_SUB_DEL_RESP unpack failed err: %s", unpackerr.Error())
357 geterr, _ := e2SubsDelResp.Get()
359 testError(t, "(xappConn) RIC_SUB_DEL_RESP get failed err: %s", geterr.Error())
363 case <-time.After(15 * time.Second):
364 testError(t, "(xappConn) Not Received RIC_SUB_DEL_RESP within 15 secs")