Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 1 | /* |
| 2 | ================================================================================== |
| 3 | Copyright (c) 2019 AT&T Intellectual Property. |
| 4 | Copyright (c) 2019 Nokia |
| 5 | |
| 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 |
| 9 | |
| 10 | http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | |
| 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 | ================================================================================== |
| 18 | */ |
| 19 | |
| 20 | package teststube2ap |
| 21 | |
| 22 | import ( |
| 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/submgr/pkg/teststub" |
| 26 | "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/xapptweaks" |
| 27 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" |
| 28 | "strconv" |
| 29 | "testing" |
| 30 | ) |
| 31 | |
| 32 | //----------------------------------------------------------------------------- |
| 33 | // |
| 34 | //----------------------------------------------------------------------------- |
| 35 | var e2asnpacker e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer() |
| 36 | |
| 37 | //----------------------------------------------------------------------------- |
| 38 | // |
| 39 | //----------------------------------------------------------------------------- |
| 40 | type RmrTransactionId struct { |
| 41 | xid string |
| 42 | meid *xapp.RMRMeid |
| 43 | } |
| 44 | |
| 45 | func (trans *RmrTransactionId) String() string { |
| 46 | return "trans(" + trans.xid + "/" + trans.meid.RanName + ")" |
| 47 | } |
| 48 | |
| 49 | type E2Stub struct { |
| 50 | teststub.RmrStubControl |
| 51 | xid_seq uint64 |
| 52 | } |
| 53 | |
| 54 | //----------------------------------------------------------------------------- |
| 55 | // |
| 56 | //----------------------------------------------------------------------------- |
| 57 | func CreateNewE2Stub(desc string, rtfile string, port string, stat string, mtypeseed int) *E2Stub { |
| 58 | tc := &E2Stub{} |
| 59 | tc.RmrStubControl.Init(desc, rtfile, port, stat, mtypeseed) |
| 60 | tc.xid_seq = 1 |
| 61 | tc.SetCheckXid(true) |
| 62 | return tc |
| 63 | } |
| 64 | |
| 65 | //----------------------------------------------------------------------------- |
| 66 | // |
| 67 | //----------------------------------------------------------------------------- |
| 68 | func CreateNewE2termStub(desc string, rtfile string, port string, stat string, mtypeseed int) *E2Stub { |
| 69 | tc := &E2Stub{} |
| 70 | tc.RmrStubControl.Init(desc, rtfile, port, stat, mtypeseed) |
| 71 | tc.xid_seq = 1 |
| 72 | tc.SetCheckXid(false) |
| 73 | return tc |
| 74 | } |
| 75 | |
| 76 | //----------------------------------------------------------------------------- |
| 77 | // |
| 78 | //----------------------------------------------------------------------------- |
| 79 | func (tc *E2Stub) NewRmrTransactionId(xid string, ranname string) *RmrTransactionId { |
| 80 | trans := &RmrTransactionId{} |
| 81 | if len(xid) == 0 { |
| 82 | trans.xid = tc.GetDesc() + "_XID_" + strconv.FormatUint(uint64(tc.xid_seq), 10) |
| 83 | tc.xid_seq++ |
| 84 | } else { |
| 85 | trans.xid = xid |
| 86 | } |
| 87 | trans.meid = &xapp.RMRMeid{RanName: ranname} |
| 88 | tc.Logger.Info("New test %s", trans.String()) |
| 89 | return trans |
| 90 | } |
| 91 | |
| 92 | //----------------------------------------------------------------------------- |
| 93 | // |
| 94 | //----------------------------------------------------------------------------- |
| 95 | type E2StubSubsReqParams struct { |
| 96 | Req *e2ap.E2APSubscriptionRequest |
| 97 | } |
| 98 | |
| 99 | func (p *E2StubSubsReqParams) Init() { |
| 100 | p.Req = &e2ap.E2APSubscriptionRequest{} |
| 101 | |
| 102 | p.Req.RequestId.Id = 1 |
| 103 | p.Req.RequestId.Seq = 0 |
| 104 | p.Req.FunctionId = 1 |
| 105 | |
| 106 | p.Req.EventTriggerDefinition.InterfaceId.GlobalEnbId.Present = true |
| 107 | p.Req.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.StringPut("310150") |
| 108 | p.Req.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId.Id = 123 |
| 109 | p.Req.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId.Bits = e2ap.E2AP_ENBIDHomeBits28 |
| 110 | |
| 111 | // gnb -> enb outgoing |
| 112 | // enb -> gnb incoming |
| 113 | // X2 36423-f40.doc |
| 114 | p.Req.EventTriggerDefinition.InterfaceDirection = e2ap.E2AP_InterfaceDirectionIncoming |
| 115 | p.Req.EventTriggerDefinition.ProcedureCode = 5 //28 35 |
| 116 | p.Req.EventTriggerDefinition.TypeOfMessage = e2ap.E2AP_InitiatingMessage |
| 117 | |
| 118 | p.Req.ActionSetups = make([]e2ap.ActionToBeSetupItem, 1) |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 119 | |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 120 | p.Req.ActionSetups[0].ActionId = 0 |
| 121 | p.Req.ActionSetups[0].ActionType = e2ap.E2AP_ActionTypeReport |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 122 | p.Req.ActionSetups[0].ActionDefinition.Present = false // Not supported |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 123 | //p.Req.ActionSetups[index].ActionDefinition.StyleId = 255 |
| 124 | //p.Req.ActionSetups[index].ActionDefinition.ParamId = 222 |
| 125 | p.Req.ActionSetups[0].SubsequentAction.Present = true |
| 126 | p.Req.ActionSetups[0].SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeContinue |
| 127 | p.Req.ActionSetups[0].SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitZero |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | //----------------------------------------------------------------------------- |
| 131 | // |
| 132 | //----------------------------------------------------------------------------- |
| 133 | |
| 134 | type E2StubSubsFailParams struct { |
| 135 | Req *e2ap.E2APSubscriptionRequest |
| 136 | Fail *e2ap.E2APSubscriptionFailure |
| 137 | } |
| 138 | |
| 139 | func (p *E2StubSubsFailParams) Set(req *e2ap.E2APSubscriptionRequest) { |
| 140 | p.Req = req |
| 141 | |
| 142 | p.Fail = &e2ap.E2APSubscriptionFailure{} |
| 143 | p.Fail.RequestId.Id = p.Req.RequestId.Id |
| 144 | p.Fail.RequestId.Seq = p.Req.RequestId.Seq |
| 145 | p.Fail.FunctionId = p.Req.FunctionId |
| 146 | p.Fail.ActionNotAdmittedList.Items = make([]e2ap.ActionNotAdmittedItem, len(p.Req.ActionSetups)) |
| 147 | for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ { |
| 148 | p.Fail.ActionNotAdmittedList.Items[index].ActionId = p.Req.ActionSetups[index].ActionId |
| 149 | p.SetCauseVal(index, 5, 1) |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | func (p *E2StubSubsFailParams) SetCauseVal(ind int, content uint8, causeval uint8) { |
| 154 | |
| 155 | if ind < 0 { |
| 156 | for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ { |
| 157 | p.Fail.ActionNotAdmittedList.Items[index].Cause.Content = content |
| 158 | p.Fail.ActionNotAdmittedList.Items[index].Cause.CauseVal = causeval |
| 159 | } |
| 160 | return |
| 161 | } |
| 162 | p.Fail.ActionNotAdmittedList.Items[ind].Cause.Content = content |
| 163 | p.Fail.ActionNotAdmittedList.Items[ind].Cause.CauseVal = causeval |
| 164 | } |
| 165 | |
| 166 | //----------------------------------------------------------------------------- |
| 167 | // |
| 168 | //----------------------------------------------------------------------------- |
| 169 | |
| 170 | func (tc *E2Stub) SendSubsReq(t *testing.T, rparams *E2StubSubsReqParams, oldTrans *RmrTransactionId) *RmrTransactionId { |
| 171 | |
| 172 | trans := oldTrans |
| 173 | if oldTrans == nil { |
| 174 | trans = tc.NewRmrTransactionId("", "RAN_NAME_1") |
| 175 | } |
| 176 | |
| 177 | tc.Logger.Info("SendSubsReq %s", trans.String()) |
| 178 | e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest() |
| 179 | |
| 180 | //--------------------------------- |
| 181 | // xapp activity: Send Subs Req |
| 182 | //--------------------------------- |
| 183 | myparams := rparams |
| 184 | |
| 185 | if myparams == nil { |
| 186 | myparams = &E2StubSubsReqParams{} |
| 187 | myparams.Init() |
| 188 | } |
| 189 | |
| 190 | err, packedMsg := e2SubsReq.Pack(myparams.Req) |
| 191 | if err != nil { |
| 192 | tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error()) |
| 193 | return nil |
| 194 | } |
| 195 | tc.Logger.Debug("%s %s", trans.String(), e2SubsReq.String()) |
| 196 | |
| 197 | params := xapptweaks.NewParams(nil) |
| 198 | params.Mtype = xapp.RIC_SUB_REQ |
| 199 | params.SubId = -1 |
| 200 | params.Payload = packedMsg.Buf |
| 201 | params.Meid = trans.meid |
| 202 | params.Xid = trans.xid |
| 203 | params.Mbuf = nil |
| 204 | |
| 205 | tc.Logger.Info("SEND SUB REQ: %s", params.String()) |
| 206 | snderr := tc.RmrSend(params) |
| 207 | if snderr != nil { |
| 208 | tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error()) |
| 209 | return nil |
| 210 | } |
| 211 | return trans |
| 212 | } |
| 213 | |
| 214 | //----------------------------------------------------------------------------- |
| 215 | // |
| 216 | //----------------------------------------------------------------------------- |
| 217 | func (tc *E2Stub) RecvSubsReq(t *testing.T) (*e2ap.E2APSubscriptionRequest, *xapptweaks.RMRParams) { |
| 218 | tc.Logger.Info("RecvSubsReq") |
| 219 | e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest() |
| 220 | |
| 221 | //--------------------------------- |
| 222 | // e2term activity: Recv Subs Req |
| 223 | //--------------------------------- |
| 224 | msg := tc.WaitMsg(15) |
| 225 | if msg != nil { |
| 226 | if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] { |
| 227 | tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_REQ", xapp.RicMessageTypeToName[msg.Mtype]) |
| 228 | } else { |
| 229 | tc.Logger.Info("Recv Subs Req") |
| 230 | packedData := &e2ap.PackedData{} |
| 231 | packedData.Buf = msg.Payload |
| 232 | unpackerr, req := e2SubsReq.UnPack(packedData) |
| 233 | if unpackerr != nil { |
| 234 | tc.TestError(t, "RIC_SUB_REQ unpack failed err: %s", unpackerr.Error()) |
| 235 | } |
| 236 | return req, msg |
| 237 | } |
| 238 | } else { |
| 239 | tc.TestError(t, "Not Received msg within %d secs", 15) |
| 240 | } |
| 241 | |
| 242 | return nil, nil |
| 243 | } |
| 244 | |
| 245 | //----------------------------------------------------------------------------- |
| 246 | // |
| 247 | //----------------------------------------------------------------------------- |
| 248 | func (tc *E2Stub) SendSubsResp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *xapptweaks.RMRParams) { |
| 249 | tc.Logger.Info("SendSubsResp") |
| 250 | e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse() |
| 251 | |
| 252 | //--------------------------------- |
| 253 | // e2term activity: Send Subs Resp |
| 254 | //--------------------------------- |
| 255 | resp := &e2ap.E2APSubscriptionResponse{} |
| 256 | |
| 257 | resp.RequestId.Id = req.RequestId.Id |
| 258 | resp.RequestId.Seq = req.RequestId.Seq |
| 259 | resp.FunctionId = req.FunctionId |
| 260 | |
| 261 | resp.ActionAdmittedList.Items = make([]e2ap.ActionAdmittedItem, len(req.ActionSetups)) |
| 262 | for index := int(0); index < len(req.ActionSetups); index++ { |
| 263 | resp.ActionAdmittedList.Items[index].ActionId = req.ActionSetups[index].ActionId |
| 264 | } |
| 265 | |
| 266 | for index := uint64(0); index < 1; index++ { |
| 267 | item := e2ap.ActionNotAdmittedItem{} |
| 268 | item.ActionId = index |
| 269 | item.Cause.Content = 1 |
| 270 | item.Cause.CauseVal = 1 |
| 271 | resp.ActionNotAdmittedList.Items = append(resp.ActionNotAdmittedList.Items, item) |
| 272 | } |
| 273 | |
| 274 | packerr, packedMsg := e2SubsResp.Pack(resp) |
| 275 | if packerr != nil { |
| 276 | tc.TestError(t, "pack NOK %s", packerr.Error()) |
| 277 | } |
| 278 | tc.Logger.Debug("%s", e2SubsResp.String()) |
| 279 | |
| 280 | params := xapptweaks.NewParams(nil) |
| 281 | params.Mtype = xapp.RIC_SUB_RESP |
| 282 | //params.SubId = msg.SubId |
| 283 | params.SubId = -1 |
| 284 | params.Payload = packedMsg.Buf |
| 285 | params.Meid = msg.Meid |
| 286 | //params.Xid = msg.Xid |
| 287 | params.Mbuf = nil |
| 288 | |
| 289 | tc.Logger.Info("SEND SUB RESP: %s", params.String()) |
| 290 | snderr := tc.RmrSend(params) |
| 291 | if snderr != nil { |
| 292 | tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error()) |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | //----------------------------------------------------------------------------- |
| 297 | // |
| 298 | //----------------------------------------------------------------------------- |
| 299 | func (tc *E2Stub) RecvSubsResp(t *testing.T, trans *RmrTransactionId) uint32 { |
| 300 | tc.Logger.Info("RecvSubsResp") |
| 301 | e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse() |
| 302 | var e2SubsId uint32 |
| 303 | |
| 304 | //--------------------------------- |
| 305 | // xapp activity: Recv Subs Resp |
| 306 | //--------------------------------- |
| 307 | msg := tc.WaitMsg(15) |
| 308 | if msg != nil { |
| 309 | if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] { |
| 310 | tc.TestError(t, "Received RIC_SUB_RESP wrong mtype expected %s got %s, error", "RIC_SUB_RESP", xapp.RicMessageTypeToName[msg.Mtype]) |
| 311 | return 0 |
| 312 | } else if msg.Xid != trans.xid { |
| 313 | tc.TestError(t, "Received RIC_SUB_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid) |
| 314 | return 0 |
| 315 | } else { |
| 316 | packedData := &e2ap.PackedData{} |
| 317 | packedData.Buf = msg.Payload |
| 318 | if msg.SubId > 0 { |
| 319 | e2SubsId = uint32(msg.SubId) |
| 320 | } else { |
| 321 | e2SubsId = 0 |
| 322 | } |
| 323 | unpackerr, resp := e2SubsResp.UnPack(packedData) |
| 324 | if unpackerr != nil { |
| 325 | tc.TestError(t, "RIC_SUB_RESP unpack failed err: %s", unpackerr.Error()) |
| 326 | } |
| 327 | tc.Logger.Info("Recv Subs Resp rmr: xid=%s subid=%d, asn: seqnro=%d", msg.Xid, msg.SubId, resp.RequestId.Seq) |
| 328 | return e2SubsId |
| 329 | } |
| 330 | } else { |
| 331 | tc.TestError(t, "Not Received msg within %d secs", 15) |
| 332 | } |
| 333 | return 0 |
| 334 | } |
| 335 | |
| 336 | //----------------------------------------------------------------------------- |
| 337 | // |
| 338 | //----------------------------------------------------------------------------- |
| 339 | |
| 340 | func (tc *E2Stub) SendSubsFail(t *testing.T, fparams *E2StubSubsFailParams, msg *xapptweaks.RMRParams) { |
| 341 | tc.Logger.Info("SendSubsFail") |
| 342 | e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure() |
| 343 | |
| 344 | //--------------------------------- |
| 345 | // e2term activity: Send Subs Fail |
| 346 | //--------------------------------- |
| 347 | packerr, packedMsg := e2SubsFail.Pack(fparams.Fail) |
| 348 | if packerr != nil { |
| 349 | tc.TestError(t, "pack NOK %s", packerr.Error()) |
| 350 | } |
| 351 | tc.Logger.Debug("%s", e2SubsFail.String()) |
| 352 | |
| 353 | params := xapptweaks.NewParams(nil) |
| 354 | params.Mtype = xapp.RIC_SUB_FAILURE |
| 355 | params.SubId = msg.SubId |
| 356 | params.Payload = packedMsg.Buf |
| 357 | params.Meid = msg.Meid |
| 358 | params.Xid = msg.Xid |
| 359 | params.Mbuf = nil |
| 360 | |
| 361 | tc.Logger.Info("SEND SUB FAIL: %s", params.String()) |
| 362 | snderr := tc.RmrSend(params) |
| 363 | if snderr != nil { |
| 364 | tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error()) |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | //----------------------------------------------------------------------------- |
| 369 | // |
| 370 | //----------------------------------------------------------------------------- |
| 371 | func (tc *E2Stub) RecvSubsFail(t *testing.T, trans *RmrTransactionId) uint32 { |
| 372 | tc.Logger.Info("RecvSubsFail") |
| 373 | e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure() |
| 374 | var e2SubsId uint32 |
| 375 | |
| 376 | //------------------------------- |
| 377 | // xapp activity: Recv Subs Fail |
| 378 | //------------------------------- |
| 379 | msg := tc.WaitMsg(15) |
| 380 | if msg != nil { |
| 381 | if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_FAILURE"] { |
| 382 | tc.TestError(t, "Received RIC_SUB_FAILURE wrong mtype expected %s got %s, error", "RIC_SUB_FAILURE", xapp.RicMessageTypeToName[msg.Mtype]) |
| 383 | return 0 |
| 384 | } else if msg.Xid != trans.xid { |
| 385 | tc.TestError(t, "Received RIC_SUB_FAILURE wrong xid expected %s got %s, error", trans.xid, msg.Xid) |
| 386 | return 0 |
| 387 | } else { |
| 388 | packedData := &e2ap.PackedData{} |
| 389 | packedData.Buf = msg.Payload |
| 390 | if msg.SubId > 0 { |
| 391 | e2SubsId = uint32(msg.SubId) |
| 392 | } else { |
| 393 | e2SubsId = 0 |
| 394 | } |
| 395 | unpackerr, resp := e2SubsFail.UnPack(packedData) |
| 396 | if unpackerr != nil { |
| 397 | tc.TestError(t, "RIC_SUB_FAILURE unpack failed err: %s", unpackerr.Error()) |
| 398 | } |
| 399 | tc.Logger.Info("Recv Subs Fail rmr: xid=%s subid=%d, asn: seqnro=%d", msg.Xid, msg.SubId, resp.RequestId.Seq) |
| 400 | return e2SubsId |
| 401 | } |
| 402 | } else { |
| 403 | tc.TestError(t, "Not Received msg within %d secs", 15) |
| 404 | } |
| 405 | return 0 |
| 406 | } |
| 407 | |
| 408 | //----------------------------------------------------------------------------- |
| 409 | // |
| 410 | //----------------------------------------------------------------------------- |
| 411 | func (tc *E2Stub) SendSubsDelReq(t *testing.T, oldTrans *RmrTransactionId, e2SubsId uint32) *RmrTransactionId { |
| 412 | |
| 413 | trans := oldTrans |
| 414 | if oldTrans == nil { |
| 415 | trans = tc.NewRmrTransactionId("", "RAN_NAME_1") |
| 416 | } |
| 417 | |
| 418 | tc.Logger.Info("SendSubsDelReq %s", trans.String()) |
| 419 | e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest() |
| 420 | //--------------------------------- |
| 421 | // xapp activity: Send Subs Del Req |
| 422 | //--------------------------------- |
| 423 | req := &e2ap.E2APSubscriptionDeleteRequest{} |
| 424 | req.RequestId.Id = 1 |
| 425 | req.RequestId.Seq = e2SubsId |
| 426 | req.FunctionId = 1 |
| 427 | |
| 428 | err, packedMsg := e2SubsDelReq.Pack(req) |
| 429 | if err != nil { |
| 430 | tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error()) |
| 431 | return nil |
| 432 | } |
| 433 | tc.Logger.Debug("%s %s", trans.String(), e2SubsDelReq.String()) |
| 434 | |
| 435 | params := xapptweaks.NewParams(nil) |
| 436 | params.Mtype = xapp.RIC_SUB_DEL_REQ |
| 437 | params.SubId = int(e2SubsId) |
| 438 | params.Payload = packedMsg.Buf |
| 439 | params.Meid = trans.meid |
| 440 | params.Xid = trans.xid |
| 441 | params.Mbuf = nil |
| 442 | |
| 443 | tc.Logger.Info("SEND SUB DEL REQ: %s", params.String()) |
| 444 | snderr := tc.RmrSend(params) |
| 445 | if snderr != nil { |
| 446 | tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error()) |
| 447 | return nil |
| 448 | } |
| 449 | return trans |
| 450 | } |
| 451 | |
| 452 | //----------------------------------------------------------------------------- |
| 453 | // |
| 454 | //----------------------------------------------------------------------------- |
| 455 | func (tc *E2Stub) RecvSubsDelReq(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *xapptweaks.RMRParams) { |
| 456 | tc.Logger.Info("RecvSubsDelReq") |
| 457 | e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest() |
| 458 | |
| 459 | //--------------------------------- |
| 460 | // e2term activity: Recv Subs Del Req |
| 461 | //--------------------------------- |
| 462 | msg := tc.WaitMsg(15) |
| 463 | if msg != nil { |
| 464 | if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] { |
| 465 | tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_DEL_REQ", xapp.RicMessageTypeToName[msg.Mtype]) |
| 466 | } else { |
| 467 | tc.Logger.Info("Recv Subs Del Req") |
| 468 | |
| 469 | packedData := &e2ap.PackedData{} |
| 470 | packedData.Buf = msg.Payload |
| 471 | unpackerr, req := e2SubsDelReq.UnPack(packedData) |
| 472 | if unpackerr != nil { |
| 473 | tc.TestError(t, "RIC_SUB_DEL_REQ unpack failed err: %s", unpackerr.Error()) |
| 474 | } |
| 475 | return req, msg |
| 476 | } |
| 477 | } else { |
| 478 | tc.TestError(t, "Not Received msg within %d secs", 15) |
| 479 | } |
| 480 | return nil, nil |
| 481 | } |
| 482 | |
| 483 | //----------------------------------------------------------------------------- |
| 484 | // |
| 485 | //----------------------------------------------------------------------------- |
| 486 | func (tc *E2Stub) SendSubsDelResp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapptweaks.RMRParams) { |
| 487 | tc.Logger.Info("SendSubsDelResp") |
| 488 | e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse() |
| 489 | |
| 490 | //--------------------------------- |
| 491 | // e2term activity: Send Subs Del Resp |
| 492 | //--------------------------------- |
| 493 | resp := &e2ap.E2APSubscriptionDeleteResponse{} |
| 494 | resp.RequestId.Id = req.RequestId.Id |
| 495 | resp.RequestId.Seq = req.RequestId.Seq |
| 496 | resp.FunctionId = req.FunctionId |
| 497 | |
| 498 | packerr, packedMsg := e2SubsDelResp.Pack(resp) |
| 499 | if packerr != nil { |
| 500 | tc.TestError(t, "pack NOK %s", packerr.Error()) |
| 501 | } |
| 502 | tc.Logger.Debug("%s", e2SubsDelResp.String()) |
| 503 | |
| 504 | params := xapptweaks.NewParams(nil) |
| 505 | params.Mtype = xapp.RIC_SUB_DEL_RESP |
| 506 | params.SubId = msg.SubId |
| 507 | params.Payload = packedMsg.Buf |
| 508 | params.Meid = msg.Meid |
| 509 | params.Xid = msg.Xid |
| 510 | params.Mbuf = nil |
| 511 | |
| 512 | tc.Logger.Info("SEND SUB DEL RESP: %s", params.String()) |
| 513 | snderr := tc.RmrSend(params) |
| 514 | if snderr != nil { |
| 515 | tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error()) |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | //----------------------------------------------------------------------------- |
| 520 | // |
| 521 | //----------------------------------------------------------------------------- |
| 522 | func (tc *E2Stub) RecvSubsDelResp(t *testing.T, trans *RmrTransactionId) { |
| 523 | tc.Logger.Info("RecvSubsDelResp") |
| 524 | e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse() |
| 525 | |
| 526 | //--------------------------------- |
| 527 | // xapp activity: Recv Subs Del Resp |
| 528 | //--------------------------------- |
| 529 | msg := tc.WaitMsg(15) |
| 530 | if msg != nil { |
| 531 | if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] { |
| 532 | tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong mtype expected %s got %s, error", "RIC_SUB_DEL_RESP", xapp.RicMessageTypeToName[msg.Mtype]) |
| 533 | return |
| 534 | } else if trans != nil && msg.Xid != trans.xid { |
| 535 | tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid) |
| 536 | return |
| 537 | } else { |
| 538 | packedData := &e2ap.PackedData{} |
| 539 | packedData.Buf = msg.Payload |
| 540 | unpackerr, resp := e2SubsDelResp.UnPack(packedData) |
| 541 | if unpackerr != nil { |
| 542 | tc.TestError(t, "RIC_SUB_DEL_RESP unpack failed err: %s", unpackerr.Error()) |
| 543 | } |
| 544 | tc.Logger.Info("Recv Subs Del Resp rmr: xid=%s subid=%d, asn: seqnro=%d", msg.Xid, msg.SubId, resp.RequestId.Seq) |
| 545 | return |
| 546 | } |
| 547 | } else { |
| 548 | tc.TestError(t, "Not Received msg within %d secs", 15) |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | //----------------------------------------------------------------------------- |
| 553 | // |
| 554 | //----------------------------------------------------------------------------- |
| 555 | func (tc *E2Stub) SendSubsDelFail(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapptweaks.RMRParams) { |
| 556 | tc.Logger.Info("SendSubsDelFail") |
| 557 | e2SubsDelFail := e2asnpacker.NewPackerSubscriptionDeleteFailure() |
| 558 | |
| 559 | //--------------------------------- |
| 560 | // e2term activity: Send Subs Del Fail |
| 561 | //--------------------------------- |
| 562 | resp := &e2ap.E2APSubscriptionDeleteFailure{} |
| 563 | resp.RequestId.Id = req.RequestId.Id |
| 564 | resp.RequestId.Seq = req.RequestId.Seq |
| 565 | resp.FunctionId = req.FunctionId |
| 566 | resp.Cause.Content = 3 // CauseMisc |
| 567 | resp.Cause.CauseVal = 4 // unspecified |
| 568 | |
| 569 | packerr, packedMsg := e2SubsDelFail.Pack(resp) |
| 570 | if packerr != nil { |
| 571 | tc.TestError(t, "pack NOK %s", packerr.Error()) |
| 572 | } |
| 573 | tc.Logger.Debug("%s", e2SubsDelFail.String()) |
| 574 | |
| 575 | params := xapptweaks.NewParams(nil) |
| 576 | params.Mtype = xapp.RIC_SUB_DEL_FAILURE |
| 577 | params.SubId = msg.SubId |
| 578 | params.Payload = packedMsg.Buf |
| 579 | params.Meid = msg.Meid |
| 580 | params.Xid = msg.Xid |
| 581 | params.Mbuf = nil |
| 582 | |
| 583 | tc.Logger.Info("SEND SUB DEL FAIL: %s", params.String()) |
| 584 | snderr := tc.RmrSend(params) |
| 585 | if snderr != nil { |
| 586 | tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error()) |
| 587 | } |
| 588 | } |