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/xapp-frame/pkg/xapp"
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
35 var xapp_e2asnpacker e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
40 type xappTransaction struct {
45 func (trans *xappTransaction) String() string {
46 return "trans(" + trans.xid + "/" + trans.meid.RanName + ")"
49 type testingXappStub struct {
54 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
57 func createNewXappStub(desc string, rtfile string, port string, stat string) *testingXappStub {
58 xappCtrl := &testingXappStub{}
59 xappCtrl.testingRmrStubControl.init(desc, rtfile, port, stat, xappCtrl)
64 //-----------------------------------------------------------------------------
66 //-----------------------------------------------------------------------------
67 func (tc *testingXappStub) newXappTransaction(xid string, ranname string) *xappTransaction {
68 trans := &xappTransaction{}
70 trans.xid = tc.GetDesc() + "_XID_" + strconv.FormatUint(uint64(tc.xid_seq), 10)
75 trans.meid = &xapp.RMRMeid{RanName: ranname}
76 xapp.Logger.Info("(%s) New test %s", tc.GetDesc(), trans.String())
80 //-----------------------------------------------------------------------------
82 //-----------------------------------------------------------------------------
83 func (tc *testingXappStub) Consume(params *xapp.RMRParams) (err error) {
84 xapp.Rmr.Free(params.Mbuf)
86 msg := &RMRParams{params}
88 if params.Mtype == 55555 {
89 xapp.Logger.Info("(%s) Testing message ignore %s", tc.GetDesc(), msg.String())
94 if strings.Contains(msg.Xid, tc.GetDesc()) {
95 xapp.Logger.Info("(%s) Consume %s", tc.GetDesc(), msg.String())
99 xapp.Logger.Info("(%s) Ignore %s", tc.GetDesc(), msg.String())
104 //-----------------------------------------------------------------------------
106 //-----------------------------------------------------------------------------
107 type test_subs_req_params struct {
108 req *e2ap.E2APSubscriptionRequest
111 func (p *test_subs_req_params) Init() {
112 p.req = &e2ap.E2APSubscriptionRequest{}
114 p.req.RequestId.Id = 1
115 p.req.RequestId.Seq = 0
118 p.req.EventTriggerDefinition.InterfaceId.GlobalEnbId.Present = true
119 p.req.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.StringPut("310150")
120 p.req.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId.Id = 123
121 p.req.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId.Bits = e2ap.E2AP_ENBIDHomeBits28
123 // gnb -> enb outgoing
124 // enb -> gnb incoming
126 p.req.EventTriggerDefinition.InterfaceDirection = e2ap.E2AP_InterfaceDirectionIncoming
127 p.req.EventTriggerDefinition.ProcedureCode = 5 //28 35
128 p.req.EventTriggerDefinition.TypeOfMessage = e2ap.E2AP_InitiatingMessage
130 p.req.ActionSetups = make([]e2ap.ActionToBeSetupItem, 1)
131 p.req.ActionSetups[0].ActionId = 0
132 p.req.ActionSetups[0].ActionType = e2ap.E2AP_ActionTypeReport
133 p.req.ActionSetups[0].ActionDefinition.Present = false
134 //p.req.ActionSetups[index].ActionDefinition.StyleId = 255
135 //p.req.ActionSetups[index].ActionDefinition.ParamId = 222
136 p.req.ActionSetups[0].SubsequentAction.Present = true
137 p.req.ActionSetups[0].SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeContinue
138 p.req.ActionSetups[0].SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitZero
142 func (xappConn *testingXappStub) handle_xapp_subs_req(t *testing.T, rparams *test_subs_req_params, oldTrans *xappTransaction) *xappTransaction {
146 trans = xappConn.newXappTransaction("", "RAN_NAME_1")
149 xapp.Logger.Info("(%s) handle_xapp_subs_req %s", xappConn.GetDesc(), trans.String())
150 e2SubsReq := xapp_e2asnpacker.NewPackerSubscriptionRequest()
152 //---------------------------------
153 // xapp activity: Send Subs Req
154 //---------------------------------
155 xapp.Logger.Info("(%s) Send Subs Req %s", xappConn.GetDesc(), trans.String())
160 myparams = &test_subs_req_params{}
164 err, packedMsg := e2SubsReq.Pack(myparams.req)
166 testError(t, "(%s) pack NOK %s %s", xappConn.GetDesc(), trans.String(), err.Error())
169 xapp.Logger.Debug("(%s) %s %s", xappConn.GetDesc(), trans.String(), e2SubsReq.String())
171 params := &RMRParams{&xapp.RMRParams{}}
172 params.Mtype = xapp.RIC_SUB_REQ
174 params.Payload = packedMsg.Buf
175 params.Meid = trans.meid
176 params.Xid = trans.xid
179 snderr := xappConn.RmrSend(params)
181 testError(t, "(%s) RMR SEND FAILED: %s %s", xappConn.GetDesc(), trans.String(), snderr.Error())
187 //-----------------------------------------------------------------------------
189 //-----------------------------------------------------------------------------
190 func (xappConn *testingXappStub) handle_xapp_subs_resp(t *testing.T, trans *xappTransaction) uint32 {
191 xapp.Logger.Info("(%s) handle_xapp_subs_resp", xappConn.GetDesc())
192 e2SubsResp := xapp_e2asnpacker.NewPackerSubscriptionResponse()
195 //---------------------------------
196 // xapp activity: Recv Subs Resp
197 //---------------------------------
199 case msg := <-xappConn.rmrConChan:
201 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
202 testError(t, "(%s) Received RIC_SUB_RESP wrong mtype expected %s got %s, error", xappConn.GetDesc(), "RIC_SUB_RESP", xapp.RicMessageTypeToName[msg.Mtype])
204 } else if msg.Xid != trans.xid {
205 testError(t, "(%s) Received RIC_SUB_RESP wrong xid expected %s got %s, error", xappConn.GetDesc(), trans.xid, msg.Xid)
208 packedData := &e2ap.PackedData{}
209 packedData.Buf = msg.Payload
211 e2SubsId = uint32(msg.SubId)
215 unpackerr, resp := e2SubsResp.UnPack(packedData)
216 if unpackerr != nil {
217 testError(t, "(%s) RIC_SUB_RESP unpack failed err: %s", xappConn.GetDesc(), unpackerr.Error())
219 xapp.Logger.Info("(%s) Recv Subs Resp rmr: xid=%s subid=%d, asn: seqnro=%d", xappConn.GetDesc(), msg.Xid, msg.SubId, resp.RequestId.Seq)
222 case <-time.After(15 * time.Second):
223 testError(t, "(%s) Not Received RIC_SUB_RESP within 15 secs", xappConn.GetDesc())
229 //-----------------------------------------------------------------------------
231 //-----------------------------------------------------------------------------
232 func (xappConn *testingXappStub) handle_xapp_subs_fail(t *testing.T, trans *xappTransaction) uint32 {
233 xapp.Logger.Info("(%s) handle_xapp_subs_fail", xappConn.GetDesc())
234 e2SubsFail := xapp_e2asnpacker.NewPackerSubscriptionFailure()
237 //-------------------------------
238 // xapp activity: Recv Subs Fail
239 //-------------------------------
241 case msg := <-xappConn.rmrConChan:
243 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_FAILURE"] {
244 testError(t, "(%s) Received RIC_SUB_FAILURE wrong mtype expected %s got %s, error", xappConn.GetDesc(), "RIC_SUB_FAILURE", xapp.RicMessageTypeToName[msg.Mtype])
246 } else if msg.Xid != trans.xid {
247 testError(t, "(%s) Received RIC_SUB_FAILURE wrong xid expected %s got %s, error", xappConn.GetDesc(), trans.xid, msg.Xid)
250 packedData := &e2ap.PackedData{}
251 packedData.Buf = msg.Payload
253 e2SubsId = uint32(msg.SubId)
257 unpackerr, resp := e2SubsFail.UnPack(packedData)
258 if unpackerr != nil {
259 testError(t, "(%s) RIC_SUB_FAILURE unpack failed err: %s", xappConn.GetDesc(), unpackerr.Error())
261 xapp.Logger.Info("(%s) Recv Subs Fail rmr: xid=%s subid=%d, asn: seqnro=%d", xappConn.GetDesc(), msg.Xid, msg.SubId, resp.RequestId.Seq)
264 case <-time.After(15 * time.Second):
265 testError(t, "(%s) Not Received RIC_SUB_FAILURE within 15 secs", xappConn.GetDesc())
271 //-----------------------------------------------------------------------------
273 //-----------------------------------------------------------------------------
274 func (xappConn *testingXappStub) handle_xapp_subs_del_req(t *testing.T, oldTrans *xappTransaction, e2SubsId uint32) *xappTransaction {
278 trans = xappConn.newXappTransaction("", "RAN_NAME_1")
281 xapp.Logger.Info("(%s) handle_xapp_subs_del_req %s", xappConn.GetDesc(), trans.String())
282 e2SubsDelReq := xapp_e2asnpacker.NewPackerSubscriptionDeleteRequest()
283 //---------------------------------
284 // xapp activity: Send Subs Del Req
285 //---------------------------------
286 xapp.Logger.Info("(%s) Send Subs Del Req %s", xappConn.GetDesc(), trans.String())
288 req := &e2ap.E2APSubscriptionDeleteRequest{}
290 req.RequestId.Seq = e2SubsId
293 err, packedMsg := e2SubsDelReq.Pack(req)
295 testError(t, "(%s) pack NOK %s %s", xappConn.GetDesc(), trans.String(), err.Error())
298 xapp.Logger.Debug("(%s) %s %s", xappConn.GetDesc(), trans.String(), e2SubsDelReq.String())
300 params := &RMRParams{&xapp.RMRParams{}}
301 params.Mtype = xapp.RIC_SUB_DEL_REQ
302 params.SubId = int(e2SubsId)
303 params.Payload = packedMsg.Buf
304 params.Meid = trans.meid
305 params.Xid = trans.xid
308 snderr := xappConn.RmrSend(params)
311 testError(t, "(%s) RMR SEND FAILED: %s %s", xappConn.GetDesc(), trans.String(), snderr.Error())
317 //-----------------------------------------------------------------------------
319 //-----------------------------------------------------------------------------
320 func (xappConn *testingXappStub) handle_xapp_subs_del_resp(t *testing.T, trans *xappTransaction) {
321 xapp.Logger.Info("(%s) handle_xapp_subs_del_resp", xappConn.GetDesc())
322 e2SubsDelResp := xapp_e2asnpacker.NewPackerSubscriptionDeleteResponse()
324 //---------------------------------
325 // xapp activity: Recv Subs Del Resp
326 //---------------------------------
328 case msg := <-xappConn.rmrConChan:
330 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
331 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])
333 } else if trans != nil && msg.Xid != trans.xid {
334 testError(t, "(%s) Received RIC_SUB_DEL_RESP wrong xid expected %s got %s, error", xappConn.GetDesc(), trans.xid, msg.Xid)
337 packedData := &e2ap.PackedData{}
338 packedData.Buf = msg.Payload
339 unpackerr, resp := e2SubsDelResp.UnPack(packedData)
340 if unpackerr != nil {
341 testError(t, "(%s) RIC_SUB_DEL_RESP unpack failed err: %s", xappConn.GetDesc(), unpackerr.Error())
343 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)
346 case <-time.After(15 * time.Second):
347 testError(t, "(%s) Not Received RIC_SUB_DEL_RESP within 15 secs", xappConn.GetDesc())