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 //-----------------------------------------------------------------------------
34 var e2t_e2asnpacker e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
39 type testingE2termStub struct {
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
46 func createNewE2termStub(desc string, rtfile string, port string, stat string) *testingE2termStub {
47 e2termCtrl := &testingE2termStub{}
48 e2termCtrl.testingRmrStubControl.init(desc, rtfile, port, stat, e2termCtrl)
52 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
55 func (tc *testingE2termStub) Consume(params *xapp.RMRParams) (err error) {
56 xapp.Rmr.Free(params.Mbuf)
58 msg := &RMRParams{params}
60 if params.Mtype == 55555 {
61 xapp.Logger.Info("(%s) Testing message ignore %s", tc.GetDesc(), msg.String())
66 xapp.Logger.Info("(%s) Consume %s", tc.GetDesc(), msg.String())
71 //-----------------------------------------------------------------------------
73 //-----------------------------------------------------------------------------
74 func (e2termConn *testingE2termStub) handle_e2term_subs_req(t *testing.T) (*e2ap.E2APSubscriptionRequest, *RMRParams) {
75 xapp.Logger.Info("(%s) handle_e2term_subs_req", e2termConn.GetDesc())
76 e2SubsReq := e2t_e2asnpacker.NewPackerSubscriptionRequest()
78 //---------------------------------
79 // e2term activity: Recv Subs Req
80 //---------------------------------
82 case msg := <-e2termConn.rmrConChan:
83 e2termConn.DecMsgCnt()
84 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] {
85 testError(t, "(%s) Received wrong mtype expected %s got %s, error", e2termConn.GetDesc(), "RIC_SUB_REQ", xapp.RicMessageTypeToName[msg.Mtype])
87 xapp.Logger.Info("(%s) Recv Subs Req", e2termConn.GetDesc())
88 packedData := &packer.PackedData{}
89 packedData.Buf = msg.Payload
90 unpackerr, req := e2SubsReq.UnPack(packedData)
92 testError(t, "(%s) RIC_SUB_REQ unpack failed err: %s", e2termConn.GetDesc(), unpackerr.Error())
96 case <-time.After(15 * time.Second):
97 testError(t, "(%s) Not Received RIC_SUB_REQ within 15 secs", e2termConn.GetDesc())
102 func (e2termConn *testingE2termStub) handle_e2term_subs_resp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *RMRParams) {
103 xapp.Logger.Info("(%s) handle_e2term_subs_resp", e2termConn.GetDesc())
104 e2SubsResp := e2t_e2asnpacker.NewPackerSubscriptionResponse()
106 //---------------------------------
107 // e2term activity: Send Subs Resp
108 //---------------------------------
109 xapp.Logger.Info("(%s) Send Subs Resp", e2termConn.GetDesc())
111 resp := &e2ap.E2APSubscriptionResponse{}
113 resp.RequestId.Id = req.RequestId.Id
114 resp.RequestId.Seq = req.RequestId.Seq
115 resp.FunctionId = req.FunctionId
117 resp.ActionAdmittedList.Items = make([]e2ap.ActionAdmittedItem, len(req.ActionSetups))
118 for index := int(0); index < len(req.ActionSetups); index++ {
119 resp.ActionAdmittedList.Items[index].ActionId = req.ActionSetups[index].ActionId
122 for index := uint64(0); index < 1; index++ {
123 item := e2ap.ActionNotAdmittedItem{}
124 item.ActionId = index
125 item.Cause.Content = 1
126 item.Cause.CauseVal = 1
127 resp.ActionNotAdmittedList.Items = append(resp.ActionNotAdmittedList.Items, item)
130 packerr, packedMsg := e2SubsResp.Pack(resp)
132 testError(t, "(%s) pack NOK %s", e2termConn.GetDesc(), packerr.Error())
134 xapp.Logger.Debug("(%s) %s", e2termConn.GetDesc(), e2SubsResp.String())
136 params := &RMRParams{&xapp.RMRParams{}}
137 params.Mtype = xapp.RIC_SUB_RESP
138 //params.SubId = msg.SubId
140 params.Payload = packedMsg.Buf
141 params.Meid = msg.Meid
142 //params.Xid = msg.Xid
145 snderr := e2termConn.RmrSend(params)
147 testError(t, "(%s) RMR SEND FAILED: %s", e2termConn.GetDesc(), snderr.Error())
151 //-----------------------------------------------------------------------------
153 //-----------------------------------------------------------------------------
154 type test_subs_fail_params struct {
155 req *e2ap.E2APSubscriptionRequest
156 fail *e2ap.E2APSubscriptionFailure
159 func (p *test_subs_fail_params) Set(req *e2ap.E2APSubscriptionRequest) {
162 p.fail = &e2ap.E2APSubscriptionFailure{}
163 p.fail.RequestId.Id = p.req.RequestId.Id
164 p.fail.RequestId.Seq = p.req.RequestId.Seq
165 p.fail.FunctionId = p.req.FunctionId
166 p.fail.ActionNotAdmittedList.Items = make([]e2ap.ActionNotAdmittedItem, len(p.req.ActionSetups))
167 for index := int(0); index < len(p.fail.ActionNotAdmittedList.Items); index++ {
168 p.fail.ActionNotAdmittedList.Items[index].ActionId = p.req.ActionSetups[index].ActionId
169 p.SetCauseVal(index, 5, 1)
173 func (p *test_subs_fail_params) SetCauseVal(ind int, content uint8, causeval uint8) {
176 for index := int(0); index < len(p.fail.ActionNotAdmittedList.Items); index++ {
177 p.fail.ActionNotAdmittedList.Items[index].Cause.Content = content
178 p.fail.ActionNotAdmittedList.Items[index].Cause.CauseVal = causeval
182 p.fail.ActionNotAdmittedList.Items[ind].Cause.Content = content
183 p.fail.ActionNotAdmittedList.Items[ind].Cause.CauseVal = causeval
186 func (e2termConn *testingE2termStub) handle_e2term_subs_fail(t *testing.T, fparams *test_subs_fail_params, msg *RMRParams) {
187 xapp.Logger.Info("(%s) handle_e2term_subs_fail", e2termConn.GetDesc())
188 e2SubsFail := e2t_e2asnpacker.NewPackerSubscriptionFailure()
190 //---------------------------------
191 // e2term activity: Send Subs Fail
192 //---------------------------------
193 xapp.Logger.Info("(%s) Send Subs Fail", e2termConn.GetDesc())
195 packerr, packedMsg := e2SubsFail.Pack(fparams.fail)
197 testError(t, "(%s) pack NOK %s", e2termConn.GetDesc(), packerr.Error())
199 xapp.Logger.Debug("(%s) %s", e2termConn.GetDesc(), e2SubsFail.String())
201 params := &RMRParams{&xapp.RMRParams{}}
202 params.Mtype = xapp.RIC_SUB_FAILURE
203 params.SubId = msg.SubId
204 params.Payload = packedMsg.Buf
205 params.Meid = msg.Meid
209 snderr := e2termConn.RmrSend(params)
211 testError(t, "(%s) RMR SEND FAILED: %s", e2termConn.GetDesc(), snderr.Error())
215 //-----------------------------------------------------------------------------
217 //-----------------------------------------------------------------------------
218 func (e2termConn *testingE2termStub) handle_e2term_subs_del_req(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *RMRParams) {
219 xapp.Logger.Info("(%s) handle_e2term_subs_del_req", e2termConn.GetDesc())
220 e2SubsDelReq := e2t_e2asnpacker.NewPackerSubscriptionDeleteRequest()
222 //---------------------------------
223 // e2term activity: Recv Subs Del Req
224 //---------------------------------
226 case msg := <-e2termConn.rmrConChan:
227 e2termConn.DecMsgCnt()
228 if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] {
229 testError(t, "(%s) Received wrong mtype expected %s got %s, error", e2termConn.GetDesc(), "RIC_SUB_DEL_REQ", xapp.RicMessageTypeToName[msg.Mtype])
231 xapp.Logger.Info("(%s) Recv Subs Del Req", e2termConn.GetDesc())
233 packedData := &packer.PackedData{}
234 packedData.Buf = msg.Payload
235 unpackerr, req := e2SubsDelReq.UnPack(packedData)
236 if unpackerr != nil {
237 testError(t, "(%s) RIC_SUB_DEL_REQ unpack failed err: %s", e2termConn.GetDesc(), unpackerr.Error())
241 case <-time.After(15 * time.Second):
242 testError(t, "(%s) Not Received RIC_SUB_DEL_REQ within 15 secs", e2termConn.GetDesc())
247 func handle_e2term_recv_empty() bool {
248 if len(e2termConn.rmrConChan) > 0 {
254 func (e2termConn *testingE2termStub) handle_e2term_subs_del_resp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *RMRParams) {
255 xapp.Logger.Info("(%s) handle_e2term_subs_del_resp", e2termConn.GetDesc())
256 e2SubsDelResp := e2t_e2asnpacker.NewPackerSubscriptionDeleteResponse()
258 //---------------------------------
259 // e2term activity: Send Subs Del Resp
260 //---------------------------------
261 xapp.Logger.Info("(%s) Send Subs Del Resp", e2termConn.GetDesc())
263 resp := &e2ap.E2APSubscriptionDeleteResponse{}
264 resp.RequestId.Id = req.RequestId.Id
265 resp.RequestId.Seq = req.RequestId.Seq
266 resp.FunctionId = req.FunctionId
268 packerr, packedMsg := e2SubsDelResp.Pack(resp)
270 testError(t, "(%s) pack NOK %s", e2termConn.GetDesc(), packerr.Error())
272 xapp.Logger.Debug("(%s) %s", e2termConn.GetDesc(), e2SubsDelResp.String())
274 params := &RMRParams{&xapp.RMRParams{}}
275 params.Mtype = xapp.RIC_SUB_DEL_RESP
276 params.SubId = msg.SubId
277 params.Payload = packedMsg.Buf
278 params.Meid = msg.Meid
282 snderr := e2termConn.RmrSend(params)
284 testError(t, "(%s) RMR SEND FAILED: %s", e2termConn.GetDesc(), snderr.Error())
288 //-----------------------------------------------------------------------------
290 //-----------------------------------------------------------------------------
291 func (e2termConn *testingE2termStub) handle_e2term_subs_del_fail(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *RMRParams) {
292 xapp.Logger.Info("(%s) handle_e2term_del_subs_fail", e2termConn.GetDesc())
293 e2SubsDelFail := e2t_e2asnpacker.NewPackerSubscriptionDeleteFailure()
295 //---------------------------------
296 // e2term activity: Send Subs Del Fail
297 //---------------------------------
298 xapp.Logger.Info("(%s) Send Subs Del Fail", e2termConn.GetDesc())
300 resp := &e2ap.E2APSubscriptionDeleteFailure{}
301 resp.RequestId.Id = req.RequestId.Id
302 resp.RequestId.Seq = req.RequestId.Seq
303 resp.FunctionId = req.FunctionId
304 resp.Cause.Content = 3 // CauseMisc
305 resp.Cause.CauseVal = 4 // unspecified
307 packerr, packedMsg := e2SubsDelFail.Pack(resp)
309 testError(t, "(%s) pack NOK %s", e2termConn.GetDesc(), packerr.Error())
311 xapp.Logger.Debug("(%s) %s", e2termConn.GetDesc(), e2SubsDelFail.String())
313 params := &RMRParams{&xapp.RMRParams{}}
314 params.Mtype = xapp.RIC_SUB_DEL_FAILURE
315 params.SubId = msg.SubId
316 params.Payload = packedMsg.Buf
317 params.Meid = msg.Meid
321 snderr := e2termConn.RmrSend(params)
323 testError(t, "(%s) RMR SEND FAILED: %s", e2termConn.GetDesc(), snderr.Error())