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"
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
36 var xapp_e2asnpacker e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
41 type xappTransaction struct {
47 type testingXappStub struct {
52 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
55 func createNewXappStub(desc string, rtfile string, port string, stat string) *testingXappStub {
56 xappCtrl := &testingXappStub{}
57 xappCtrl.testingRmrStubControl.init(desc, rtfile, port, stat, xappCtrl)
62 //-----------------------------------------------------------------------------
64 //-----------------------------------------------------------------------------
65 func (tc *testingXappStub) newXid() string {
67 xid = tc.desc + "_XID_" + strconv.FormatUint(uint64(tc.xid_seq), 10)
72 //-----------------------------------------------------------------------------
74 //-----------------------------------------------------------------------------
75 func (tc *testingXappStub) newXappTransaction(xid *string, ranname string) *xappTransaction {
76 trans := &xappTransaction{}
79 trans.xid = tc.newXid()
83 trans.meid = &xapp.RMRMeid{RanName: ranname}
87 //-----------------------------------------------------------------------------
89 //-----------------------------------------------------------------------------
90 func (tc *testingXappStub) Consume(params *xapp.RMRParams) (err error) {
91 xapp.Rmr.Free(params.Mbuf)
93 msg := &RMRParams{params}
95 if params.Mtype == 55555 {
96 xapp.Logger.Info("(%s) Testing message ignore %s", tc.desc, msg.String())
101 if strings.Contains(msg.Xid, tc.desc) {
102 xapp.Logger.Info("(%s) Consume %s", tc.desc, msg.String())
106 xapp.Logger.Info("(%s) Ignore %s", tc.desc, msg.String())
111 //-----------------------------------------------------------------------------
113 //-----------------------------------------------------------------------------
114 type test_subs_req_params struct {
115 req *e2ap.E2APSubscriptionRequest
118 func (p *test_subs_req_params) Init() {
119 p.req = &e2ap.E2APSubscriptionRequest{}
121 p.req.RequestId.Id = 1
122 p.req.RequestId.Seq = 0
125 p.req.EventTriggerDefinition.InterfaceId.GlobalEnbId.Present = true
126 p.req.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.StringPut("310150")
127 p.req.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId.Id = 123
128 p.req.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId.Bits = e2ap.E2AP_ENBIDHomeBits28
130 // gnb -> enb outgoing
131 // enb -> gnb incoming
133 p.req.EventTriggerDefinition.InterfaceDirection = e2ap.E2AP_InterfaceDirectionIncoming
134 p.req.EventTriggerDefinition.ProcedureCode = 5 //28 35
135 p.req.EventTriggerDefinition.TypeOfMessage = e2ap.E2AP_InitiatingMessage
137 p.req.ActionSetups = make([]e2ap.ActionToBeSetupItem, 1)
138 p.req.ActionSetups[0].ActionId = 0
139 p.req.ActionSetups[0].ActionType = e2ap.E2AP_ActionTypeReport
140 p.req.ActionSetups[0].ActionDefinition.Present = false
141 //p.req.ActionSetups[index].ActionDefinition.StyleId = 255
142 //p.req.ActionSetups[index].ActionDefinition.ParamId = 222
143 p.req.ActionSetups[0].SubsequentAction.Present = true
144 p.req.ActionSetups[0].SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeContinue
145 p.req.ActionSetups[0].SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitZero
149 func (xappConn *testingXappStub) handle_xapp_subs_req(t *testing.T, rparams *test_subs_req_params, oldTrans *xappTransaction) *xappTransaction {
150 xapp.Logger.Info("(%s) handle_xapp_subs_req", xappConn.desc)
151 e2SubsReq := xapp_e2asnpacker.NewPackerSubscriptionRequest()
153 //---------------------------------
154 // xapp activity: Send Subs Req
155 //---------------------------------
156 xapp.Logger.Info("(%s) Send Subs Req", xappConn.desc)
161 myparams = &test_subs_req_params{}
165 e2SubsReq.Set(myparams.req)
166 xapp.Logger.Debug("%s", e2SubsReq.String())
167 err, packedMsg := e2SubsReq.Pack(nil)
169 testError(t, "(%s) pack NOK %s", xappConn.desc, err.Error())
173 var trans *xappTransaction = oldTrans
175 trans = xappConn.newXappTransaction(nil, "RAN_NAME_1")
178 params := &RMRParams{&xapp.RMRParams{}}
179 params.Mtype = xapp.RIC_SUB_REQ
181 params.Payload = packedMsg.Buf
182 params.Meid = trans.meid
183 params.Xid = trans.xid
186 snderr := xappConn.RmrSend(params)
188 testError(t, "(%s) RMR SEND FAILED: %s", xappConn.desc, snderr.Error())
194 //-----------------------------------------------------------------------------
196 //-----------------------------------------------------------------------------
197 func (xappConn *testingXappStub) handle_xapp_subs_resp(t *testing.T, trans *xappTransaction) int {
198 xapp.Logger.Info("(%s) handle_xapp_subs_resp", xappConn.desc)
199 e2SubsResp := xapp_e2asnpacker.NewPackerSubscriptionResponse()
202 //---------------------------------
203 // xapp activity: Recv Subs Resp
204 //---------------------------------
206 case msg := <-xappConn.rmrConChan:
208 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
209 testError(t, "(%s) Received RIC_SUB_RESP wrong mtype expected %s got %s, error", xappConn.desc, "RIC_SUB_RESP", xapp.RicMessageTypeToName[msg.Mtype])
211 } else if msg.Xid != trans.xid {
212 testError(t, "(%s) Received RIC_SUB_RESP wrong xid expected %s got %s, error", xappConn.desc, trans.xid, msg.Xid)
215 packedData := &packer.PackedData{}
216 packedData.Buf = msg.Payload
218 unpackerr := e2SubsResp.UnPack(packedData)
220 if unpackerr != nil {
221 testError(t, "(%s) RIC_SUB_RESP unpack failed err: %s", xappConn.desc, unpackerr.Error())
223 geterr, resp := e2SubsResp.Get()
225 testError(t, "(%s) RIC_SUB_RESP get failed err: %s", xappConn.desc, geterr.Error())
228 xapp.Logger.Info("(%s) Recv Subs Resp rmr: xid=%s subid=%d, asn: seqnro=%d", xappConn.desc, msg.Xid, msg.SubId, resp.RequestId.Seq)
231 case <-time.After(15 * time.Second):
232 testError(t, "(%s) Not Received RIC_SUB_RESP within 15 secs", xappConn.desc)
238 //-----------------------------------------------------------------------------
240 //-----------------------------------------------------------------------------
241 func (xappConn *testingXappStub) handle_xapp_subs_fail(t *testing.T, trans *xappTransaction) int {
242 xapp.Logger.Info("(%s) handle_xapp_subs_fail", xappConn.desc)
243 e2SubsFail := xapp_e2asnpacker.NewPackerSubscriptionFailure()
246 //-------------------------------
247 // xapp activity: Recv Subs Fail
248 //-------------------------------
250 case msg := <-xappConn.rmrConChan:
252 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_FAILURE"] {
253 testError(t, "(%s) Received RIC_SUB_FAILURE wrong mtype expected %s got %s, error", xappConn.desc, "RIC_SUB_FAILURE", xapp.RicMessageTypeToName[msg.Mtype])
255 } else if msg.Xid != trans.xid {
256 testError(t, "(%s) Received RIC_SUB_FAILURE wrong xid expected %s got %s, error", xappConn.desc, trans.xid, msg.Xid)
259 packedData := &packer.PackedData{}
260 packedData.Buf = msg.Payload
262 unpackerr := e2SubsFail.UnPack(packedData)
264 if unpackerr != nil {
265 testError(t, "(%s) RIC_SUB_FAILURE unpack failed err: %s", xappConn.desc, unpackerr.Error())
267 geterr, resp := e2SubsFail.Get()
269 testError(t, "(%s) RIC_SUB_FAILURE get failed err: %s", xappConn.desc, geterr.Error())
272 xapp.Logger.Info("(%s) Recv Subs Fail rmr: xid=%s subid=%d, asn: seqnro=%d", xappConn.desc, msg.Xid, msg.SubId, resp.RequestId.Seq)
275 case <-time.After(15 * time.Second):
276 testError(t, "(%s) Not Received RIC_SUB_FAILURE within 15 secs", xappConn.desc)
282 //-----------------------------------------------------------------------------
284 //-----------------------------------------------------------------------------
285 func (xappConn *testingXappStub) handle_xapp_subs_del_req(t *testing.T, oldTrans *xappTransaction, e2SubsId int) *xappTransaction {
286 xapp.Logger.Info("(%s) handle_xapp_subs_del_req", xappConn.desc)
287 e2SubsDelReq := xapp_e2asnpacker.NewPackerSubscriptionDeleteRequest()
289 //---------------------------------
290 // xapp activity: Send Subs Del Req
291 //---------------------------------
292 xapp.Logger.Info("(%s) Send Subs Del Req", xappConn.desc)
294 req := &e2ap.E2APSubscriptionDeleteRequest{}
296 req.RequestId.Seq = uint32(e2SubsId)
299 e2SubsDelReq.Set(req)
300 xapp.Logger.Debug("%s", e2SubsDelReq.String())
301 err, packedMsg := e2SubsDelReq.Pack(nil)
303 testError(t, "(%s) pack NOK %s", xappConn.desc, err.Error())
307 var trans *xappTransaction = oldTrans
309 trans = xappConn.newXappTransaction(nil, "RAN_NAME_1")
312 params := &RMRParams{&xapp.RMRParams{}}
313 params.Mtype = xapp.RIC_SUB_DEL_REQ
314 params.SubId = e2SubsId
315 params.Payload = packedMsg.Buf
316 params.Meid = trans.meid
317 params.Xid = trans.xid
320 snderr := xappConn.RmrSend(params)
322 testError(t, "(%s) RMR SEND FAILED: %s", xappConn.desc, snderr.Error())
328 //-----------------------------------------------------------------------------
330 //-----------------------------------------------------------------------------
331 func (xappConn *testingXappStub) handle_xapp_subs_del_resp(t *testing.T, trans *xappTransaction) {
332 xapp.Logger.Info("(%s) handle_xapp_subs_del_resp", xappConn.desc)
333 e2SubsDelResp := xapp_e2asnpacker.NewPackerSubscriptionDeleteResponse()
335 //---------------------------------
336 // xapp activity: Recv Subs Del Resp
337 //---------------------------------
339 case msg := <-xappConn.rmrConChan:
341 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
342 testError(t, "(%s) Received RIC_SUB_DEL_RESP wrong mtype expected %s got %s, error", xappConn.desc, "RIC_SUB_DEL_RESP", xapp.RicMessageTypeToName[msg.Mtype])
344 } else if trans != nil && msg.Xid != trans.xid {
345 testError(t, "(%s) Received RIC_SUB_DEL_RESP wrong xid expected %s got %s, error", xappConn.desc, trans.xid, msg.Xid)
348 packedData := &packer.PackedData{}
349 packedData.Buf = msg.Payload
350 unpackerr := e2SubsDelResp.UnPack(packedData)
351 if unpackerr != nil {
352 testError(t, "(%s) RIC_SUB_DEL_RESP unpack failed err: %s", xappConn.desc, unpackerr.Error())
354 geterr, resp := e2SubsDelResp.Get()
356 testError(t, "(%s) RIC_SUB_DEL_RESP get failed err: %s", xappConn.desc, geterr.Error())
358 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)
361 case <-time.After(15 * time.Second):
362 testError(t, "(%s) Not Received RIC_SUB_DEL_RESP within 15 secs", xappConn.desc)