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 {
46 func (trans *xappTransaction) String() string {
47 return "trans(" + trans.xid + "/" + trans.meid.RanName + ")"
50 type testingXappStub struct {
55 //-----------------------------------------------------------------------------
57 //-----------------------------------------------------------------------------
58 func createNewXappStub(desc string, rtfile string, port string, stat string) *testingXappStub {
59 xappCtrl := &testingXappStub{}
60 xappCtrl.testingRmrStubControl.init(desc, rtfile, port, stat, xappCtrl)
65 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
68 func (tc *testingXappStub) newXappTransaction(xid string, ranname string) *xappTransaction {
69 trans := &xappTransaction{}
71 trans.xid = tc.GetDesc() + "_XID_" + strconv.FormatUint(uint64(tc.xid_seq), 10)
76 trans.meid = &xapp.RMRMeid{RanName: ranname}
77 xapp.Logger.Info("(%s) New test %s", tc.GetDesc(), trans.String())
81 //-----------------------------------------------------------------------------
83 //-----------------------------------------------------------------------------
84 func (tc *testingXappStub) Consume(params *xapp.RMRParams) (err error) {
85 xapp.Rmr.Free(params.Mbuf)
87 msg := &RMRParams{params}
89 if params.Mtype == 55555 {
90 xapp.Logger.Info("(%s) Testing message ignore %s", tc.GetDesc(), msg.String())
95 if strings.Contains(msg.Xid, tc.GetDesc()) {
96 xapp.Logger.Info("(%s) Consume %s", tc.GetDesc(), msg.String())
100 xapp.Logger.Info("(%s) Ignore %s", tc.GetDesc(), msg.String())
105 //-----------------------------------------------------------------------------
107 //-----------------------------------------------------------------------------
108 type test_subs_req_params struct {
109 req *e2ap.E2APSubscriptionRequest
112 func (p *test_subs_req_params) Init() {
113 p.req = &e2ap.E2APSubscriptionRequest{}
115 p.req.RequestId.Id = 1
116 p.req.RequestId.Seq = 0
119 p.req.EventTriggerDefinition.InterfaceId.GlobalEnbId.Present = true
120 p.req.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.StringPut("310150")
121 p.req.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId.Id = 123
122 p.req.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId.Bits = e2ap.E2AP_ENBIDHomeBits28
124 // gnb -> enb outgoing
125 // enb -> gnb incoming
127 p.req.EventTriggerDefinition.InterfaceDirection = e2ap.E2AP_InterfaceDirectionIncoming
128 p.req.EventTriggerDefinition.ProcedureCode = 5 //28 35
129 p.req.EventTriggerDefinition.TypeOfMessage = e2ap.E2AP_InitiatingMessage
131 p.req.ActionSetups = make([]e2ap.ActionToBeSetupItem, 1)
132 p.req.ActionSetups[0].ActionId = 0
133 p.req.ActionSetups[0].ActionType = e2ap.E2AP_ActionTypeReport
134 p.req.ActionSetups[0].ActionDefinition.Present = false
135 //p.req.ActionSetups[index].ActionDefinition.StyleId = 255
136 //p.req.ActionSetups[index].ActionDefinition.ParamId = 222
137 p.req.ActionSetups[0].SubsequentAction.Present = true
138 p.req.ActionSetups[0].SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeContinue
139 p.req.ActionSetups[0].SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitZero
143 func (xappConn *testingXappStub) handle_xapp_subs_req(t *testing.T, rparams *test_subs_req_params, oldTrans *xappTransaction) *xappTransaction {
147 trans = xappConn.newXappTransaction("", "RAN_NAME_1")
150 xapp.Logger.Info("(%s) handle_xapp_subs_req %s", xappConn.GetDesc(), trans.String())
151 e2SubsReq := xapp_e2asnpacker.NewPackerSubscriptionRequest()
153 //---------------------------------
154 // xapp activity: Send Subs Req
155 //---------------------------------
156 xapp.Logger.Info("(%s) Send Subs Req %s", xappConn.GetDesc(), trans.String())
161 myparams = &test_subs_req_params{}
165 err, packedMsg := e2SubsReq.Pack(myparams.req)
167 testError(t, "(%s) pack NOK %s %s", xappConn.GetDesc(), trans.String(), err.Error())
170 xapp.Logger.Debug("(%s) %s %s", xappConn.GetDesc(), trans.String(), e2SubsReq.String())
172 params := &RMRParams{&xapp.RMRParams{}}
173 params.Mtype = xapp.RIC_SUB_REQ
175 params.Payload = packedMsg.Buf
176 params.Meid = trans.meid
177 params.Xid = trans.xid
180 snderr := xappConn.RmrSend(params)
182 testError(t, "(%s) RMR SEND FAILED: %s %s", xappConn.GetDesc(), trans.String(), snderr.Error())
188 //-----------------------------------------------------------------------------
190 //-----------------------------------------------------------------------------
191 func (xappConn *testingXappStub) handle_xapp_subs_resp(t *testing.T, trans *xappTransaction) uint32 {
192 xapp.Logger.Info("(%s) handle_xapp_subs_resp", xappConn.GetDesc())
193 e2SubsResp := xapp_e2asnpacker.NewPackerSubscriptionResponse()
196 //---------------------------------
197 // xapp activity: Recv Subs Resp
198 //---------------------------------
200 case msg := <-xappConn.rmrConChan:
202 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
203 testError(t, "(%s) Received RIC_SUB_RESP wrong mtype expected %s got %s, error", xappConn.GetDesc(), "RIC_SUB_RESP", xapp.RicMessageTypeToName[msg.Mtype])
205 } else if msg.Xid != trans.xid {
206 testError(t, "(%s) Received RIC_SUB_RESP wrong xid expected %s got %s, error", xappConn.GetDesc(), trans.xid, msg.Xid)
209 packedData := &packer.PackedData{}
210 packedData.Buf = msg.Payload
212 e2SubsId = uint32(msg.SubId)
216 unpackerr, resp := e2SubsResp.UnPack(packedData)
217 if unpackerr != nil {
218 testError(t, "(%s) RIC_SUB_RESP unpack failed err: %s", xappConn.GetDesc(), unpackerr.Error())
220 xapp.Logger.Info("(%s) Recv Subs Resp rmr: xid=%s subid=%d, asn: seqnro=%d", xappConn.GetDesc(), msg.Xid, msg.SubId, resp.RequestId.Seq)
223 case <-time.After(15 * time.Second):
224 testError(t, "(%s) Not Received RIC_SUB_RESP within 15 secs", xappConn.GetDesc())
230 //-----------------------------------------------------------------------------
232 //-----------------------------------------------------------------------------
233 func (xappConn *testingXappStub) handle_xapp_subs_fail(t *testing.T, trans *xappTransaction) uint32 {
234 xapp.Logger.Info("(%s) handle_xapp_subs_fail", xappConn.GetDesc())
235 e2SubsFail := xapp_e2asnpacker.NewPackerSubscriptionFailure()
238 //-------------------------------
239 // xapp activity: Recv Subs Fail
240 //-------------------------------
242 case msg := <-xappConn.rmrConChan:
244 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_FAILURE"] {
245 testError(t, "(%s) Received RIC_SUB_FAILURE wrong mtype expected %s got %s, error", xappConn.GetDesc(), "RIC_SUB_FAILURE", xapp.RicMessageTypeToName[msg.Mtype])
247 } else if msg.Xid != trans.xid {
248 testError(t, "(%s) Received RIC_SUB_FAILURE wrong xid expected %s got %s, error", xappConn.GetDesc(), trans.xid, msg.Xid)
251 packedData := &packer.PackedData{}
252 packedData.Buf = msg.Payload
254 e2SubsId = uint32(msg.SubId)
258 unpackerr, resp := e2SubsFail.UnPack(packedData)
259 if unpackerr != nil {
260 testError(t, "(%s) RIC_SUB_FAILURE unpack failed err: %s", xappConn.GetDesc(), unpackerr.Error())
262 xapp.Logger.Info("(%s) Recv Subs Fail rmr: xid=%s subid=%d, asn: seqnro=%d", xappConn.GetDesc(), msg.Xid, msg.SubId, resp.RequestId.Seq)
265 case <-time.After(15 * time.Second):
266 testError(t, "(%s) Not Received RIC_SUB_FAILURE within 15 secs", xappConn.GetDesc())
272 //-----------------------------------------------------------------------------
274 //-----------------------------------------------------------------------------
275 func (xappConn *testingXappStub) handle_xapp_subs_del_req(t *testing.T, oldTrans *xappTransaction, e2SubsId uint32) *xappTransaction {
279 trans = xappConn.newXappTransaction("", "RAN_NAME_1")
282 xapp.Logger.Info("(%s) handle_xapp_subs_del_req %s", xappConn.GetDesc(), trans.String())
283 e2SubsDelReq := xapp_e2asnpacker.NewPackerSubscriptionDeleteRequest()
284 //---------------------------------
285 // xapp activity: Send Subs Del Req
286 //---------------------------------
287 xapp.Logger.Info("(%s) Send Subs Del Req %s", xappConn.GetDesc(), trans.String())
289 req := &e2ap.E2APSubscriptionDeleteRequest{}
291 req.RequestId.Seq = e2SubsId
294 err, packedMsg := e2SubsDelReq.Pack(req)
296 testError(t, "(%s) pack NOK %s %s", xappConn.GetDesc(), trans.String(), err.Error())
299 xapp.Logger.Debug("(%s) %s %s", xappConn.GetDesc(), trans.String(), e2SubsDelReq.String())
301 params := &RMRParams{&xapp.RMRParams{}}
302 params.Mtype = xapp.RIC_SUB_DEL_REQ
303 params.SubId = int(e2SubsId)
304 params.Payload = packedMsg.Buf
305 params.Meid = trans.meid
306 params.Xid = trans.xid
309 snderr := xappConn.RmrSend(params)
312 testError(t, "(%s) RMR SEND FAILED: %s %s", xappConn.GetDesc(), trans.String(), snderr.Error())
318 //-----------------------------------------------------------------------------
320 //-----------------------------------------------------------------------------
321 func (xappConn *testingXappStub) handle_xapp_subs_del_resp(t *testing.T, trans *xappTransaction) {
322 xapp.Logger.Info("(%s) handle_xapp_subs_del_resp", xappConn.GetDesc())
323 e2SubsDelResp := xapp_e2asnpacker.NewPackerSubscriptionDeleteResponse()
325 //---------------------------------
326 // xapp activity: Recv Subs Del Resp
327 //---------------------------------
329 case msg := <-xappConn.rmrConChan:
331 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
332 testError(t, "(%s) Received RIC_SUB_DEL_RESP wrong mtype expected %s got %s, error", xappConn.GetDesc(), "RIC_SUB_DEL_RESP", xapp.RicMessageTypeToName[msg.Mtype])
334 } else if trans != nil && msg.Xid != trans.xid {
335 testError(t, "(%s) Received RIC_SUB_DEL_RESP wrong xid expected %s got %s, error", xappConn.GetDesc(), trans.xid, msg.Xid)
338 packedData := &packer.PackedData{}
339 packedData.Buf = msg.Payload
340 unpackerr, resp := e2SubsDelResp.UnPack(packedData)
341 if unpackerr != nil {
342 testError(t, "(%s) RIC_SUB_DEL_RESP unpack failed err: %s", xappConn.GetDesc(), unpackerr.Error())
344 xapp.Logger.Info("(%s) Recv Subs Del Resp rmr: xid=%s subid=%d, asn: seqnro=%d", xappConn.GetDesc(), msg.Xid, msg.SubId, resp.RequestId.Seq)
347 case <-time.After(15 * time.Second):
348 testError(t, "(%s) Not Received RIC_SUB_DEL_RESP within 15 secs", xappConn.GetDesc())