From: Markku Virtanen Date: Tue, 25 May 2021 08:18:43 +0000 (+0000) Subject: Added E2AP interface wrapper for UT X-Git-Tag: 0.7.1~22^2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=fa39fedbbd1c2e6bfea4b952184936f393ff2690;p=ric-plt%2Fsubmgr.git Added E2AP interface wrapper for UT Signed-off-by: Markku Virtanen Change-Id: Ic1fa3cf7e16baffe357cfd1f93e639cbc0ef560d --- diff --git a/e2ap/pkg/e2ap_wrapper/ut_packer_e2ap.go b/e2ap/pkg/e2ap_wrapper/ut_packer_e2ap.go new file mode 100644 index 0000000..3449a91 --- /dev/null +++ b/e2ap/pkg/e2ap_wrapper/ut_packer_e2ap.go @@ -0,0 +1,266 @@ +/* +================================================================================== + Copyright (c) 2021 Nokia + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +================================================================================== +*/ + +package e2ap_wrapper + +import ( + "fmt" + + "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap" +) + +const ( + SUB_REQ int = 1 + SUB_RESP int = 2 + SUB_FAILURE int = 3 + SUB_DEL_REQ int = 4 + SUB_DEL_RESP int = 5 + SUB_DEL_FAILURE int = 6 +) + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- + +var origPackerif e2ap.E2APPackerIf = NewAsn1E2Packer() + +var allowAction = map[int]bool{ + SUB_REQ: true, + SUB_RESP: true, + SUB_FAILURE: true, + SUB_DEL_REQ: true, + SUB_DEL_RESP: true, + SUB_DEL_FAILURE: true, +} + +func AllowE2apToProcess(mtype int, actionFail bool) { + fmt.Printf("INFO: AllowE2apToProcess setting %d : %t -> %t", mtype, allowAction[mtype], actionFail) + allowAction[mtype] = actionFail +} + +type utMsgPackerSubscriptionRequest struct { + e2apMsgPackerSubscriptionRequest +} + +func (e2apMsg *utMsgPackerSubscriptionRequest) init() { +} + +func (e2apMsg *utMsgPackerSubscriptionRequest) Pack(data *e2ap.E2APSubscriptionRequest) (error, *e2ap.PackedData) { + if allowAction[SUB_REQ] { + e2sub := origPackerif.NewPackerSubscriptionRequest() + return e2sub.Pack(data) + } + return fmt.Errorf("Error: Set to be fail by UT (%v)", allowAction[SUB_REQ]), nil +} + +func (e2apMsg *utMsgPackerSubscriptionRequest) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionRequest) { + if allowAction[SUB_REQ] { + e2sub := origPackerif.NewPackerSubscriptionRequest() + return e2sub.UnPack(msg) + } + return fmt.Errorf("Error: Set to be fail by UT (%v)", allowAction[SUB_REQ]), nil +} + +func (e2apMsg *utMsgPackerSubscriptionRequest) String() string { + return "utMsgPackerSubscriptionRequest" +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +type utMsgPackerSubscriptionResponse struct { + e2apMsgPackerSubscriptionResponse +} + +func (e2apMsg *utMsgPackerSubscriptionResponse) init() { +} + +func (e2apMsg *utMsgPackerSubscriptionResponse) Pack(data *e2ap.E2APSubscriptionResponse) (error, *e2ap.PackedData) { + if allowAction[SUB_RESP] { + e2sub := origPackerif.NewPackerSubscriptionResponse() + return e2sub.Pack(data) + } + return fmt.Errorf("Error: Set to be fail by UT"), nil +} + +func (e2apMsg *utMsgPackerSubscriptionResponse) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionResponse) { + if allowAction[SUB_RESP] { + e2sub := origPackerif.NewPackerSubscriptionResponse() + return e2sub.UnPack(msg) + } + return fmt.Errorf("Error: Set to be fail by UT"), nil +} + +func (e2apMsg *utMsgPackerSubscriptionResponse) String() string { + return "utMsgPackerSubscriptionResponse" +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +type utMsgPackerSubscriptionFailure struct { + e2apMsgPackerSubscriptionFailure +} + +func (e2apMsg *utMsgPackerSubscriptionFailure) init() { +} + +func (e2apMsg *utMsgPackerSubscriptionFailure) Pack(data *e2ap.E2APSubscriptionFailure) (error, *e2ap.PackedData) { + if allowAction[SUB_FAILURE] { + e2sub := origPackerif.NewPackerSubscriptionFailure() + return e2sub.Pack(data) + } + return fmt.Errorf("Error: Set to be fail by UT"), nil +} + +func (e2apMsg *utMsgPackerSubscriptionFailure) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionFailure) { + if allowAction[SUB_FAILURE] { + e2sub := origPackerif.NewPackerSubscriptionFailure() + return e2sub.UnPack(msg) + } + return fmt.Errorf("Error: Set to be fail by UT"), nil +} + +func (e2apMsg *utMsgPackerSubscriptionFailure) String() string { + return "utMsgPackerSubscriptionFailure" +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +type utMsgPackerSubscriptionDeleteRequest struct { + e2apMsgPackerSubscriptionDeleteRequest +} + +func (e2apMsg *utMsgPackerSubscriptionDeleteRequest) init() { +} + +func (e2apMsg *utMsgPackerSubscriptionDeleteRequest) Pack(data *e2ap.E2APSubscriptionDeleteRequest) (error, *e2ap.PackedData) { + if allowAction[SUB_DEL_REQ] { + e2sub := origPackerif.NewPackerSubscriptionDeleteRequest() + return e2sub.Pack(data) + } + return fmt.Errorf("Error: Set to be fail by UT (%v)", allowAction[SUB_DEL_REQ]), nil +} + +func (e2apMsg *utMsgPackerSubscriptionDeleteRequest) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionDeleteRequest) { + if allowAction[SUB_DEL_REQ] { + e2sub := origPackerif.NewPackerSubscriptionDeleteRequest() + return e2sub.UnPack(msg) + } + return fmt.Errorf("Error: Set to be fail by UT (%v)", allowAction[SUB_DEL_REQ]), nil +} + +func (e2apMsg *utMsgPackerSubscriptionDeleteRequest) String() string { + return "utMsgPackerSubscriptionDeleteRequest" +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +type utMsgPackerSubscriptionDeleteResponse struct { + e2apMsgPackerSubscriptionDeleteResponse +} + +func (e2apMsg *utMsgPackerSubscriptionDeleteResponse) init() { + +} + +func (e2apMsg *utMsgPackerSubscriptionDeleteResponse) Pack(data *e2ap.E2APSubscriptionDeleteResponse) (error, *e2ap.PackedData) { + if allowAction[SUB_DEL_RESP] { + e2sub := origPackerif.NewPackerSubscriptionDeleteResponse() + return e2sub.Pack(data) + } + return fmt.Errorf("Error: Set to be fail by UT"), nil +} + +func (e2apMsg *utMsgPackerSubscriptionDeleteResponse) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionDeleteResponse) { + if allowAction[SUB_DEL_RESP] { + e2sub := origPackerif.NewPackerSubscriptionDeleteResponse() + return e2sub.UnPack(msg) + } + return fmt.Errorf("Error: Set to be fail by UT"), nil +} + +func (e2apMsg *utMsgPackerSubscriptionDeleteResponse) String() string { + return "utMsgPackerSubscriptionDeleteResponse" +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +type utMsgPackerSubscriptionDeleteFailure struct { + e2apMsgPackerSubscriptionDeleteFailure +} + +func (e2apMsg *utMsgPackerSubscriptionDeleteFailure) init() { +} + +func (e2apMsg *utMsgPackerSubscriptionDeleteFailure) Pack(data *e2ap.E2APSubscriptionDeleteFailure) (error, *e2ap.PackedData) { + if allowAction[SUB_DEL_FAILURE] { + e2sub := origPackerif.NewPackerSubscriptionDeleteFailure() + return e2sub.Pack(data) + } + return fmt.Errorf("Error: Set to be fail by UT"), nil +} + +func (e2apMsg *utMsgPackerSubscriptionDeleteFailure) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionDeleteFailure) { + if allowAction[SUB_DEL_FAILURE] { + e2sub := origPackerif.NewPackerSubscriptionDeleteFailure() + return e2sub.UnPack(msg) + } + return fmt.Errorf("Error: Set to be fail by UT"), nil +} + +func (e2apMsg *utMsgPackerSubscriptionDeleteFailure) String() string { + return "utMsgPackerSubscriptionDeleteFailure" +} + +//----------------------------------------------------------------------------- +// Public E2AP packer creators +//----------------------------------------------------------------------------- + +type utAsn1E2APPacker struct{} + +func (*utAsn1E2APPacker) NewPackerSubscriptionRequest() e2ap.E2APMsgPackerSubscriptionRequestIf { + return &utMsgPackerSubscriptionRequest{} +} + +func (*utAsn1E2APPacker) NewPackerSubscriptionResponse() e2ap.E2APMsgPackerSubscriptionResponseIf { + return &utMsgPackerSubscriptionResponse{} +} + +func (*utAsn1E2APPacker) NewPackerSubscriptionFailure() e2ap.E2APMsgPackerSubscriptionFailureIf { + return &utMsgPackerSubscriptionFailure{} +} + +func (*utAsn1E2APPacker) NewPackerSubscriptionDeleteRequest() e2ap.E2APMsgPackerSubscriptionDeleteRequestIf { + return &utMsgPackerSubscriptionDeleteRequest{} +} + +func (*utAsn1E2APPacker) NewPackerSubscriptionDeleteResponse() e2ap.E2APMsgPackerSubscriptionDeleteResponseIf { + return &utMsgPackerSubscriptionDeleteResponse{} +} + +func (*utAsn1E2APPacker) NewPackerSubscriptionDeleteFailure() e2ap.E2APMsgPackerSubscriptionDeleteFailureIf { + return &utMsgPackerSubscriptionDeleteFailure{} +} + +func NewUtAsn1E2APPacker() e2ap.E2APPackerIf { + return &utAsn1E2APPacker{} +} diff --git a/pkg/control/e2ap.go b/pkg/control/e2ap.go index c547567..9f19ba7 100644 --- a/pkg/control/e2ap.go +++ b/pkg/control/e2ap.go @@ -27,6 +27,7 @@ import "C" import ( "encoding/hex" "fmt" + "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap" "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap_wrapper" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/models" @@ -35,6 +36,14 @@ import ( var packerif e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer() +func GetPackerIf() e2ap.E2APPackerIf { + return packerif +} + +func SetPackerIf(iface e2ap.E2APPackerIf) { + packerif = iface +} + type E2ap struct { } diff --git a/pkg/control/ut_messaging_test.go b/pkg/control/ut_messaging_test.go index 20f8709..d20b872 100644 --- a/pkg/control/ut_messaging_test.go +++ b/pkg/control/ut_messaging_test.go @@ -24,11 +24,28 @@ import ( "time" "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap" + "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap_wrapper" "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststube2ap" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" "github.com/stretchr/testify/assert" ) +func TestRESTSubReqAndDeleteOkWithE2apUtWrapper(t *testing.T) { + + // The effect of this call shall endure thgough the UT suite! + // If this causes any issues, the previout interface can be restored + // like this: + // SetPackerIf(e2ap_wrapper.NewAsn1E2APPacker()) + + SetPackerIf(e2ap_wrapper.NewUtAsn1E2APPacker()) + + restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, nil) + + deleteSubscription(t, xappConn1, e2termConn1, &restSubId) + + waitSubsCleanup(t, e2SubsId, 10) +} + //----------------------------------------------------------------------------- // TestSubReqAndRouteNok //