First commit

This commit is contained in:
Leonardo Bonati
2021-12-08 20:17:46 +00:00
commit 60dffad583
2923 changed files with 463894 additions and 0 deletions

View File

@@ -0,0 +1,113 @@
/*******************************************************************************
*
* Copyright (c) 2019 AT&T Intellectual Property.
*
* 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.
*
*******************************************************************************/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
package e2pdus
// #cgo CFLAGS: -I../asn1codec/inc/ -I../asn1codec/e2ap_engine/
// #cgo LDFLAGS: -L ../asn1codec/lib/ -L../asn1codec/e2ap_engine/ -le2ap_codec -lasncodec
// #include <configuration_update_wrapper.h>
import "C"
import (
"fmt"
"unsafe"
)
var PackedEndcConfigurationUpdateFailure []byte
var PackedEndcConfigurationUpdateAck []byte
var PackedX2EnbConfigurationUpdateFailure []byte
var PackedX2EnbConfigurationUpdateAck []byte
func prepareEndcConfigurationUpdateFailurePDU(maxAsn1PackedBufferSize int, maxAsn1CodecMessageBufferSize int) error {
packedBuffer := make([]C.uchar, maxAsn1PackedBufferSize)
errorBuffer := make([]C.char, maxAsn1CodecMessageBufferSize)
var payloadSize = C.ulong(maxAsn1PackedBufferSize)
if status := C.build_pack_endc_configuration_update_failure(&payloadSize, &packedBuffer[0], C.ulong(maxAsn1CodecMessageBufferSize), &errorBuffer[0]); !status {
return fmt.Errorf("#configuration_update.prepareEndcConfigurationUpdateFailurePDU - failed to build and pack the endc configuration update failure message %s ", C.GoString(&errorBuffer[0]))
}
PackedEndcConfigurationUpdateFailure = C.GoBytes(unsafe.Pointer(&packedBuffer[0]), C.int(payloadSize))
return nil
}
func prepareX2EnbConfigurationUpdateFailurePDU(maxAsn1PackedBufferSize int, maxAsn1CodecMessageBufferSize int) error {
packedBuffer := make([]C.uchar, maxAsn1PackedBufferSize)
errorBuffer := make([]C.char, maxAsn1CodecMessageBufferSize)
var payloadSize = C.ulong(maxAsn1PackedBufferSize)
if status := C.build_pack_x2enb_configuration_update_failure(&payloadSize, &packedBuffer[0], C.ulong(maxAsn1CodecMessageBufferSize), &errorBuffer[0]); !status {
return fmt.Errorf("#configuration_update.prepareX2EnbConfigurationUpdateFailurePDU - failed to build and pack the x2 configuration update failure message %s ", C.GoString(&errorBuffer[0]))
}
PackedX2EnbConfigurationUpdateFailure = C.GoBytes(unsafe.Pointer(&packedBuffer[0]), C.int(payloadSize))
return nil
}
func prepareEndcConfigurationUpdateAckPDU(maxAsn1PackedBufferSize int, maxAsn1CodecMessageBufferSize int) error {
packedBuffer := make([]C.uchar, maxAsn1PackedBufferSize)
errorBuffer := make([]C.char, maxAsn1CodecMessageBufferSize)
var payloadSize = C.ulong(maxAsn1PackedBufferSize)
if status := C.build_pack_endc_configuration_update_ack(&payloadSize, &packedBuffer[0], C.ulong(maxAsn1CodecMessageBufferSize), &errorBuffer[0]); !status {
return fmt.Errorf("#configuration_update.prepareEndcConfigurationUpdateAckPDU - failed to build and pack the endc configuration update ack message %s ", C.GoString(&errorBuffer[0]))
}
PackedEndcConfigurationUpdateAck = C.GoBytes(unsafe.Pointer(&packedBuffer[0]), C.int(payloadSize))
return nil
}
func prepareX2EnbConfigurationUpdateAckPDU(maxAsn1PackedBufferSize int, maxAsn1CodecMessageBufferSize int) error {
packedBuffer := make([]C.uchar, maxAsn1PackedBufferSize)
errorBuffer := make([]C.char, maxAsn1CodecMessageBufferSize)
var payloadSize = C.ulong(maxAsn1PackedBufferSize)
if status := C.build_pack_x2enb_configuration_update_ack(&payloadSize, &packedBuffer[0], C.ulong(maxAsn1CodecMessageBufferSize), &errorBuffer[0]); !status {
return fmt.Errorf("#configuration_update.prepareX2EnbConfigurationUpdateAckPDU - failed to build and pack the x2 configuration update ack message %s ", C.GoString(&errorBuffer[0]))
}
PackedX2EnbConfigurationUpdateAck = C.GoBytes(unsafe.Pointer(&packedBuffer[0]), C.int(payloadSize))
return nil
}
func init() {
if err := prepareEndcConfigurationUpdateFailurePDU(MaxAsn1PackedBufferSize, MaxAsn1CodecMessageBufferSize); err != nil {
panic(err)
}
if err := prepareEndcConfigurationUpdateAckPDU(MaxAsn1PackedBufferSize, MaxAsn1CodecMessageBufferSize); err != nil {
panic(err)
}
if err := prepareX2EnbConfigurationUpdateFailurePDU(MaxAsn1PackedBufferSize, MaxAsn1CodecMessageBufferSize); err != nil {
panic(err)
}
if err := prepareX2EnbConfigurationUpdateAckPDU(MaxAsn1PackedBufferSize, MaxAsn1CodecMessageBufferSize); err != nil {
panic(err)
}
}

View File

@@ -0,0 +1,171 @@
/*******************************************************************************
*
* Copyright (c) 2019 AT&T Intellectual Property.
*
* 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.
*
*******************************************************************************/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
package e2pdus
import (
"e2mgr/logger"
"fmt"
"strings"
"testing"
)
func TestPrepareEndcConfigurationUpdateFailurePDU(t *testing.T) {
_,err := logger.InitLogger(logger.InfoLevel)
if err!=nil{
t.Errorf("failed to initialize logger, error: %s", err)
}
packedPdu := "402500080000010005400142"
packedEndcConfigurationUpdateFailure := PackedEndcConfigurationUpdateFailure
tmp := fmt.Sprintf("%x", packedEndcConfigurationUpdateFailure)
if len(tmp) != len(packedPdu) {
t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcConfigurationUpdateFailure)/2)
}
if strings.Compare(tmp, packedPdu) != 0 {
t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
}
}
func TestPrepareEndcConfigurationUpdateFailurePDUFailure(t *testing.T) {
_, err := logger.InitLogger(logger.InfoLevel)
if err != nil {
t.Errorf("failed to initialize logger, error: %s", err)
}
err = prepareEndcConfigurationUpdateFailurePDU(1, 4096)
if err == nil {
t.Errorf("want: error, got: success.\n")
}
expected:= "#configuration_update.prepareEndcConfigurationUpdateFailurePDU - failed to build and pack the endc configuration update failure message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
if !strings.Contains(err.Error(), expected) {
t.Errorf("want :[%s], got: [%s]\n", expected, err)
}
}
func TestPrepareX2EnbConfigurationUpdateFailurePDU(t *testing.T) {
_,err := logger.InitLogger(logger.InfoLevel)
if err!=nil{
t.Errorf("failed to initialize logger, error: %s", err)
}
packedPdu := "400800080000010005400142"
packedEndcX2ConfigurationUpdateFailure := PackedX2EnbConfigurationUpdateFailure
tmp := fmt.Sprintf("%x", packedEndcX2ConfigurationUpdateFailure)
if len(tmp) != len(packedPdu) {
t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcX2ConfigurationUpdateFailure)/2)
}
if strings.Compare(tmp, packedPdu) != 0 {
t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
}
}
func TestPrepareX2EnbConfigurationUpdateFailurePDUFailure(t *testing.T) {
_, err := logger.InitLogger(logger.InfoLevel)
if err != nil {
t.Errorf("failed to initialize logger, error: %s", err)
}
err = prepareX2EnbConfigurationUpdateFailurePDU(1, 4096)
if err == nil {
t.Errorf("want: error, got: success.\n")
}
expected:= "#configuration_update.prepareX2EnbConfigurationUpdateFailurePDU - failed to build and pack the x2 configuration update failure message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
if !strings.Contains(err.Error(), expected) {
t.Errorf("want :[%s], got: [%s]\n", expected, err)
}
}
func TestPrepareEndcConfigurationUpdateAckPDU(t *testing.T) {
_,err := logger.InitLogger(logger.InfoLevel)
if err!=nil{
t.Errorf("failed to initialize logger, error: %s", err)
}
packedPdu := "2025000a00000100f70003000000"
packedEndcConfigurationUpdateAck := PackedEndcConfigurationUpdateAck
tmp := fmt.Sprintf("%x", packedEndcConfigurationUpdateAck)
if len(tmp) != len(packedPdu) {
t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcConfigurationUpdateAck)/2)
}
if strings.Compare(tmp, packedPdu) != 0 {
t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
}
}
func TestPrepareEndcConfigurationUpdateAckPDUFailure(t *testing.T) {
_, err := logger.InitLogger(logger.InfoLevel)
if err != nil {
t.Errorf("failed to initialize logger, error: %s", err)
}
err = prepareEndcConfigurationUpdateAckPDU(1, 4096)
if err == nil {
t.Errorf("want: error, got: success.\n")
}
expected:= "#configuration_update.prepareEndcConfigurationUpdateAckPDU - failed to build and pack the endc configuration update ack message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
if !strings.Contains(err.Error(), expected) {
t.Errorf("want :[%s], got: [%s]\n", expected, err)
}
}
func TestPrepareX2EnbConfigurationUpdateAckPDU(t *testing.T) {
_,err := logger.InitLogger(logger.InfoLevel)
if err!=nil{
t.Errorf("failed to initialize logger, error: %s", err)
}
packedPdu := "200800080000010011400100"
packedEndcX2ConfigurationUpdateAck := PackedX2EnbConfigurationUpdateAck
tmp := fmt.Sprintf("%x", packedEndcX2ConfigurationUpdateAck)
if len(tmp) != len(packedPdu) {
t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcX2ConfigurationUpdateAck)/2)
}
if strings.Compare(tmp, packedPdu) != 0 {
t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
}
}
func TestPrepareX2EnbConfigurationUpdateAckPDUFailure(t *testing.T) {
_, err := logger.InitLogger(logger.InfoLevel)
if err != nil {
t.Errorf("failed to initialize logger, error: %s", err)
}
err = prepareX2EnbConfigurationUpdateAckPDU(1, 4096)
if err == nil {
t.Errorf("want: error, got: success.\n")
}
expected:= "#configuration_update.prepareX2EnbConfigurationUpdateAckPDU - failed to build and pack the x2 configuration update ack message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
if !strings.Contains(err.Error(), expected) {
t.Errorf("want :[%s], got: [%s]\n", expected, err)
}
}

View File

@@ -0,0 +1,106 @@
/*
* Copyright (c) 2019 AT&T Intellectual Property.
*
* 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
package e2pdus
import (
"fmt"
"strings"
"testing"
)
/*
* Create and pack an x2ap setup request.
* Verify the packed representation matches the want value.
*/
func TestPackEndcX2apSetupRequest(t *testing.T) {
pLMNId := []byte{0xbb, 0xbc, 0xcc}
ricFlag := []byte{0xbb, 0xbc, 0xcc} /*pLMNId [3]bytes*/
var testCases = []struct {
eNBId []byte
eNBIdBitqty uint
packedPdu string
}{
{
eNBId: []byte{0xab, 0xcd, 0x2}, /*00000010 -> 10000000*/
eNBIdBitqty: ShortMacro_eNB_ID,
packedPdu: "0024003200000100f4002b0000020015000900bbbccc8003abcd8000fa0017000001f700bbbcccabcd80000000bbbccc000000000001",
},
{
eNBId: []byte{0xab, 0xcd, 0xe},
eNBIdBitqty: Macro_eNB_ID,
packedPdu: "0024003100000100f4002a0000020015000800bbbccc00abcde000fa0017000001f700bbbcccabcde0000000bbbccc000000000001",
},
{
eNBId: []byte{0xab, 0xcd, 0x7}, /*00000111 -> 00111000*/
eNBIdBitqty: LongMacro_eNB_ID,
//packedPdu: "0024003200000100f4002b0000020015000900bbbccc8103abcd3800fa0017000001f700bbbcccabcd38000000bbbccc000000000001",
packedPdu: "0024003200000100f4002b0000020015000900bbbcccc003abcd3800fa0017000001f700bbbcccabcd38000000bbbccc000000000001",
},
{
eNBId: []byte{0xab, 0xcd, 0xef, 0x8},
eNBIdBitqty: Home_eNB_ID,
packedPdu: "0024003200000100f4002b0000020015000900bbbccc40abcdef8000fa0017000001f700bbbcccabcdef800000bbbccc000000000001",
},
}
for _, tc := range testCases {
t.Run(tc.packedPdu, func(t *testing.T) {
payload, _, err := preparePackedEndcX2SetupRequest(MaxAsn1PackedBufferSize /*max packed buffer*/, MaxAsn1CodecMessageBufferSize /*max message buffer*/, pLMNId, tc.eNBId, tc.eNBIdBitqty, ricFlag)
if err != nil {
t.Errorf("want: success, got: pack failed. Error: %v\n", err)
} else {
t.Logf("packed X2AP setup request(size=%d): %x\n", len(payload), payload)
tmp := fmt.Sprintf("%x", payload)
if len(tmp) != len(tc.packedPdu) {
t.Errorf("want packed len:%d, got: %d\n", len(tc.packedPdu)/2, len(payload)/2)
}
if strings.Compare(tmp, tc.packedPdu) != 0 {
t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", tc.packedPdu, tmp)
}
}
})
}
}
/*Packing error*/
func TestPackEndcX2apSetupRequestPackError(t *testing.T) {
pLMNId := []byte{0xbb, 0xbc, 0xcc}
ricFlag := []byte{0xbb, 0xbc, 0xcc} /*pLMNId [3]bytes*/
eNBId := []byte{0xab, 0xcd, 0x2}
eNBIdBitqty := uint(Macro_eNB_ID)
wantError := "packing error: #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big:53"
_, _, err := preparePackedEndcX2SetupRequest(40 /*max packed buffer*/, MaxAsn1CodecMessageBufferSize /*max message buffer*/, pLMNId, eNBId, eNBIdBitqty, ricFlag)
if err != nil {
if 0 != strings.Compare(fmt.Sprintf("%s", err), wantError) {
t.Errorf("want failure: %s, got: %s", wantError, err)
}
} else {
t.Errorf("want failure: %s, got: success", wantError)
}
}

View File

@@ -0,0 +1,147 @@
/*
* Copyright (c) 2019 AT&T Intellectual Property.
*
* 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
package e2pdus
// #cgo CFLAGS: -I../3rdparty/asn1codec/inc/ -I../3rdparty/asn1codec/e2ap_engine/
// #cgo LDFLAGS: -L ../3rdparty/asn1codec/lib/ -L../3rdparty/asn1codec/e2ap_engine/ -le2ap_codec -lasncodec
// #include <x2reset_request_wrapper.h>
import "C"
import (
"fmt"
"strings"
"unsafe"
)
const (
MaxAsn1PackedBufferSize = 4096
MaxAsn1CodecMessageBufferSize = 4096
MaxAsn1CodecAllocationBufferSize = 4096 // TODO: remove later
)
// Used as default by the x2_reset_request
const (
OmInterventionCause = "misc:om-intervention"
)
type cause struct {
causeGroup uint32
cause int
}
var knownCauses = map[string]cause{
"misc:control-processing-overload": {causeGroup: C.Cause_PR_misc, cause: C.CauseMisc_control_processing_overload},
"misc:hardware-failure": {causeGroup: C.Cause_PR_misc, cause: C.CauseMisc_hardware_failure},
OmInterventionCause: {causeGroup: C.Cause_PR_misc, cause: C.CauseMisc_om_intervention},
"misc:not-enough-user-plane-processing-resources": {causeGroup: C.Cause_PR_misc, cause: C.CauseMisc_not_enough_user_plane_processing_resources},
"misc:unspecified": {causeGroup: C.Cause_PR_misc, cause: C.CauseMisc_unspecified},
"protocol:transfer-syntax-error": {causeGroup: C.Cause_PR_protocol, cause: C.CauseProtocol_transfer_syntax_error},
"protocol:abstract-syntax-error-reject": {causeGroup: C.Cause_PR_protocol, cause: C.CauseProtocol_abstract_syntax_error_reject},
"protocol:abstract-syntax-error-ignore-and-notify": {causeGroup: C.Cause_PR_protocol, cause: C.CauseProtocol_abstract_syntax_error_ignore_and_notify},
"protocol:message-not-compatible-with-receiver-state": {causeGroup: C.Cause_PR_protocol, cause: C.CauseProtocol_message_not_compatible_with_receiver_state},
"protocol:semantic-error": {causeGroup: C.Cause_PR_protocol, cause: C.CauseProtocol_semantic_error},
"protocol:unspecified": {causeGroup: C.Cause_PR_protocol, cause: C.CauseProtocol_unspecified},
"protocol:abstract-syntax-error-falsely-constructed-message": {causeGroup: C.Cause_PR_protocol, cause: C.CauseProtocol_abstract_syntax_error_falsely_constructed_message},
"transport:transport-resource-unavailable": {causeGroup: C.Cause_PR_transport, cause: C.CauseTransport_transport_resource_unavailable},
"transport:unspecified": {causeGroup: C.Cause_PR_transport, cause: C.CauseTransport_unspecified},
"radioNetwork:handover-desirable-for-radio-reasons": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_handover_desirable_for_radio_reasons},
"radioNetwork:time-critical-handover": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_time_critical_handover},
"radioNetwork:resource-optimisation-handover": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_resource_optimisation_handover},
"radioNetwork:reduce-load-in-serving-cell": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_reduce_load_in_serving_cell},
"radioNetwork:partial-handover": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_partial_handover},
"radioNetwork:unknown-new-enb-ue-x2ap-id": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_unknown_new_eNB_UE_X2AP_ID},
"radioNetwork:unknown-old-enb-ue-x2ap-id": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_unknown_old_eNB_UE_X2AP_ID},
"radioNetwork:unknown-pair-of-ue-x2ap-id": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_unknown_pair_of_UE_X2AP_ID},
"radioNetwork:ho-target-not-allowed": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_ho_target_not_allowed},
"radioNetwork:tx2relocoverall-expiry": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_tx2relocoverall_expiry},
"radioNetwork:trelocprep-expiry": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_trelocprep_expiry},
"radioNetwork:cell-not-available": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_cell_not_available},
"radioNetwork:no-radio-resources-available-in-target-cell": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_no_radio_resources_available_in_target_cell},
"radioNetwork:invalid-mme-groupid": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_invalid_MME_GroupID},
"radioNetwork:unknown-mme-code": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_unknown_MME_Code},
"radioNetwork:encryption-and-or-integrity-protection-algorithms-not-supported": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_encryption_and_or_integrity_protection_algorithms_not_supported},
"radioNetwork:reportcharacteristicsempty": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_reportCharacteristicsEmpty},
"radioNetwork:noreportperiodicity": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_noReportPeriodicity},
"radioNetwork:existingMeasurementID": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_existingMeasurementID},
"radioNetwork:unknown-enb-measurement-id": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_unknown_eNB_Measurement_ID},
"radioNetwork:measurement-temporarily-not-available": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_measurement_temporarily_not_available},
"radioNetwork:unspecified": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_unspecified},
"radioNetwork:load-balancing": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_load_balancing},
"radioNetwork:handover-optimisation": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_handover_optimisation},
"radioNetwork:value-out-of-allowed-range": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_value_out_of_allowed_range},
"radioNetwork:multiple-E-RAB-ID-instances": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_multiple_E_RAB_ID_instances},
"radioNetwork:switch-off-ongoing": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_switch_off_ongoing},
"radioNetwork:not-supported-qci-value": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_not_supported_QCI_value},
"radioNetwork:measurement-not-supported-for-the-object": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_measurement_not_supported_for_the_object},
"radioNetwork:tdcoverall-expiry": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_tDCoverall_expiry},
"radioNetwork:tdcprep-expiry": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_tDCprep_expiry},
"radioNetwork:action-desirable-for-radio-reasons": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_action_desirable_for_radio_reasons},
"radioNetwork:reduce-load": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_reduce_load},
"radioNetwork:resource-optimisation": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_resource_optimisation},
"radioNetwork:time-critical-action": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_time_critical_action},
"radioNetwork:target-not-allowed": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_target_not_allowed},
"radioNetwork:no-radio-resources-available": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_no_radio_resources_available},
"radioNetwork:invalid-qos-combination": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_invalid_QoS_combination},
"radioNetwork:encryption-algorithms-not-aupported": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_encryption_algorithms_not_aupported},
"radioNetwork:procedure-cancelled": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_procedure_cancelled},
"radioNetwork:rrm-purpose": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_rRM_purpose},
"radioNetwork:improve-user-bit-rate": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_improve_user_bit_rate},
"radioNetwork:user-inactivity": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_user_inactivity},
"radioNetwork:radio-connection-with-ue-lost": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_radio_connection_with_UE_lost},
"radioNetwork:failure-in-the-radio-interface-procedure": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_failure_in_the_radio_interface_procedure},
"radioNetwork:bearer-option-not-supported": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_bearer_option_not_supported},
"radioNetwork:mcg-mobility": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_mCG_Mobility},
"radioNetwork:scg-mobility": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_sCG_Mobility},
"radioNetwork:count-reaches-max-value": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_count_reaches_max_value},
"radioNetwork:unknown-old-en-gnb-ue-x2ap-id": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_unknown_old_en_gNB_UE_X2AP_ID},
"radioNetwork:pdcp-Overload": {causeGroup: C.Cause_PR_radioNetwork, cause: C.CauseRadioNetwork_pDCP_Overload},
}
var knownCausesToX2ResetPDUs = map[string][]byte{}
func prepareX2ResetPDUs(maxAsn1PackedBufferSize int, maxAsn1CodecMessageBufferSize int) error {
packedBuffer := make([]C.uchar, maxAsn1PackedBufferSize)
errorBuffer := make([]C.char, maxAsn1CodecMessageBufferSize)
for k, cause := range knownCauses {
var payloadSize = C.ulong(maxAsn1PackedBufferSize)
if status := C.build_pack_x2reset_request(cause.causeGroup, C.int(cause.cause), &payloadSize, &packedBuffer[0], C.ulong(maxAsn1CodecMessageBufferSize), &errorBuffer[0]); !status {
return fmt.Errorf("#x2_reset_known_causes.prepareX2ResetPDUs - failed to build and pack the reset message %s ", C.GoString(&errorBuffer[0]))
}
knownCausesToX2ResetPDUs[strings.ToLower(k)] = C.GoBytes(unsafe.Pointer(&packedBuffer[0]), C.int(payloadSize))
}
return nil
}
// KnownCausesToX2ResetPDU returns a packed x2 reset pdu with the specified cause (case insensitive match).
func KnownCausesToX2ResetPDU(cause string) ([]byte, bool) {
v, ok := knownCausesToX2ResetPDUs[strings.ToLower(cause)]
return v, ok
}
func init() {
if err := prepareX2ResetPDUs(MaxAsn1PackedBufferSize, MaxAsn1CodecMessageBufferSize); err != nil {
panic(err)
}
}

View File

@@ -0,0 +1,106 @@
/*
* Copyright (c) 2019 AT&T Intellectual Property.
*
* 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
package e2pdus
import (
"e2mgr/logger"
"fmt"
"strings"
"testing"
)
func TestKnownCausesToX2ResetPDU(t *testing.T) {
_, err := logger.InitLogger(logger.InfoLevel)
if err != nil {
t.Errorf("failed to initialize logger, error: %s", err)
}
var testCases = []struct {
cause string
packedPdu string
}{
{
cause: OmInterventionCause,
packedPdu: "000700080000010005400164",
},
{
cause: "PROTOCOL:transfer-syntax-error",
packedPdu: "000700080000010005400140",
},
{
cause: "transport:transport-RESOURCE-unavailable",
packedPdu: "000700080000010005400120",
},
{
cause: "radioNetwork:invalid-MME-groupid",
packedPdu: "00070009000001000540020680",
},
}
for _, tc := range testCases {
t.Run(tc.packedPdu, func(t *testing.T) {
payload, ok := KnownCausesToX2ResetPDU(tc.cause)
if !ok {
t.Errorf("want: success, got: not found.\n")
} else {
tmp := fmt.Sprintf("%x", payload)
if len(tmp) != len(tc.packedPdu) {
t.Errorf("want packed len:%d, got: %d\n", len(tc.packedPdu)/2, len(payload)/2)
}
if strings.Compare(tmp, tc.packedPdu) != 0 {
t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", tc.packedPdu, tmp)
}
}
})
}
}
func TestKnownCausesToX2ResetPDUFailure(t *testing.T) {
_, err := logger.InitLogger(logger.InfoLevel)
if err != nil {
t.Errorf("failed to initialize logger, error: %s", err)
}
_, ok := KnownCausesToX2ResetPDU("xxxx")
if ok {
t.Errorf("want: not found, got: success.\n")
}
}
func TestPrepareX2ResetPDUsFailure(t *testing.T) {
_, err := logger.InitLogger(logger.InfoLevel)
if err != nil {
t.Errorf("failed to initialize logger, error: %s", err)
}
err = prepareX2ResetPDUs(1, 4096)
if err == nil {
t.Errorf("want: error, got: success.\n")
}
expected := "failed to build and pack the reset message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big:"
if !strings.Contains(err.Error(), expected) {
t.Errorf("want :[%s], got: [%s]\n", expected, err)
}
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 2019 AT&T Intellectual Property.
*
* 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
package e2pdus
// #cgo CFLAGS: -I../3rdparty/asn1codec/inc/ -I../3rdparty/asn1codec/e2ap_engine/
// #cgo LDFLAGS: -L ../3rdparty/asn1codec/lib/ -L../3rdparty/asn1codec/e2ap_engine/ -le2ap_codec -lasncodec
// #include <x2reset_response_wrapper.h>
import "C"
import (
"fmt"
"unsafe"
)
var PackedX2ResetResponse []byte
func prepareX2ResetResponsePDU(maxAsn1PackedBufferSize int, maxAsn1CodecMessageBufferSize int) error {
packedBuffer := make([]C.uchar, maxAsn1PackedBufferSize)
errorBuffer := make([]C.char, maxAsn1CodecMessageBufferSize)
var payloadSize = C.ulong(maxAsn1PackedBufferSize)
if status := C.build_pack_x2reset_response(&payloadSize, &packedBuffer[0], C.ulong(maxAsn1CodecMessageBufferSize), &errorBuffer[0]); !status {
return fmt.Errorf("#x2_reset_response.prepareX2ResetResponsePDU - failed to build and pack the reset response message %s ", C.GoString(&errorBuffer[0]))
}
PackedX2ResetResponse = C.GoBytes(unsafe.Pointer(&packedBuffer[0]), C.int(payloadSize))
return nil
}
func init() {
if err := prepareX2ResetResponsePDU(MaxAsn1PackedBufferSize, MaxAsn1CodecMessageBufferSize); err != nil {
panic(err)
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 2019 AT&T Intellectual Property.
*
* 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
package e2pdus
import (
"e2mgr/logger"
"fmt"
"strings"
"testing"
)
func TestPrepareX2ResetResponsePDU(t *testing.T) {
_,err := logger.InitLogger(logger.InfoLevel)
if err!=nil{
t.Errorf("failed to initialize logger, error: %s", err)
}
packedPdu := "200700080000010011400100"
packedX2ResetResponse := PackedX2ResetResponse
tmp := fmt.Sprintf("%x", packedX2ResetResponse)
if len(tmp) != len(packedPdu) {
t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedX2ResetResponse)/2)
}
if strings.Compare(tmp, packedPdu) != 0 {
t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
}
}
func TestPrepareX2ResetResponsePDUFailure(t *testing.T) {
_, err := logger.InitLogger(logger.InfoLevel)
if err != nil {
t.Errorf("failed to initialize logger, error: %s", err)
}
err = prepareX2ResetResponsePDU(1, 4096)
if err == nil {
t.Errorf("want: error, got: success.\n")
}
expected:= "#x2_reset_response.prepareX2ResetResponsePDU - failed to build and pack the reset response message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
if !strings.Contains(err.Error(), expected) {
t.Errorf("want :[%s], got: [%s]\n", expected, err)
}
}

View File

@@ -0,0 +1,108 @@
/*
* Copyright (c) 2019 AT&T Intellectual Property.
*
* 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
package e2pdus
import (
"fmt"
"strings"
"testing"
)
/*
* Create and pack an x2ap setup request.
* Verify the packed representation matches the want value.
*/
func TestPackX2apSetupRequest(t *testing.T) {
pLMNId := []byte{0xbb, 0xbc, 0xcc}
ricFlag := []byte{0xbb, 0xbc, 0xcc} /*pLMNId [3]bytes*/
var testCases = []struct {
eNBId []byte
eNBIdBitqty uint
packedPdu string
}{
{
eNBId: []byte{0xab, 0xcd, 0x2}, /*00000010 -> 10000000*/
eNBIdBitqty: ShortMacro_eNB_ID,
packedPdu: "0006002b0000020015000900bbbccc8003abcd8000140017000001f700bbbcccabcd80000000bbbccc000000000001",
},
{
eNBId: []byte{0xab, 0xcd, 0xe},
eNBIdBitqty: Macro_eNB_ID,
packedPdu: "0006002a0000020015000800bbbccc00abcde000140017000001f700bbbcccabcde0000000bbbccc000000000001",
},
{
eNBId: []byte{0xab, 0xcd, 0x7}, /*00000111 -> 00111000*/
eNBIdBitqty: LongMacro_eNB_ID,
//packedPdu: "0006002b0000020015000900bbbccc8103abcd3800140017000001f700bbbcccabcd38000000bbbccc000000000001",
packedPdu: "0006002b0000020015000900bbbcccc003abcd3800140017000001f700bbbcccabcd38000000bbbccc000000000001",
},
{
eNBId: []byte{0xab, 0xcd, 0xef, 0x8},
eNBIdBitqty: Home_eNB_ID,
packedPdu: "0006002b0000020015000900bbbccc40abcdef8000140017000001f700bbbcccabcdef800000bbbccc000000000001",
},
}
// TODO: Consider using testify's assert/require
// testing/quick to input random value
for _, tc := range testCases {
t.Run(tc.packedPdu, func(t *testing.T) {
payload, _, err := preparePackedX2SetupRequest(MaxAsn1PackedBufferSize /*max packed buffer*/, MaxAsn1CodecMessageBufferSize /*max message buffer*/, pLMNId, tc.eNBId, tc.eNBIdBitqty,ricFlag)
if err != nil {
t.Errorf("want: success, got: pack failed. Error: %v\n", err)
} else {
t.Logf("packed X2AP setup request(size=%d): %x\n", len(payload), payload)
tmp := fmt.Sprintf("%x", payload)
if len(tmp) != len(tc.packedPdu) {
t.Errorf("want packed len:%d, got: %d\n", len(tc.packedPdu)/2, len(payload)/2)
}
if strings.Compare(tmp, tc.packedPdu) != 0 {
t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", tc.packedPdu, tmp)
}
}
})
}
}
/*Packing error*/
func TestPackX2apSetupRequestPackError(t *testing.T) {
wantError := "packing error: #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big:46"
pLMNId := []byte{0xbb, 0xbc, 0xcc}
ricFlag := []byte{0xbb, 0xbc, 0xcc} /*pLMNId [3]bytes*/
eNBId := []byte{0xab, 0xcd, 0xe}
eNBIdBitqty := uint(Macro_eNB_ID)
_, _, err := preparePackedX2SetupRequest(40 /*max packed buffer*/, MaxAsn1CodecMessageBufferSize /*max message buffer*/, pLMNId, eNBId, eNBIdBitqty, ricFlag)
if err != nil {
if 0 != strings.Compare(fmt.Sprintf("%s", err), wantError) {
t.Errorf("want failure: %s, got: %s", wantError, err)
}
} else {
t.Errorf("want failure: %s, got: success", wantError)
}
}

View File

@@ -0,0 +1,148 @@
/*
* Copyright (c) 2019 AT&T Intellectual Property.
*
* 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
package e2pdus
// #cgo CFLAGS: -I../3rdparty/asn1codec/inc/ -I../3rdparty/asn1codec/e2ap_engine/
// #cgo LDFLAGS: -L ../3rdparty/asn1codec/lib/ -L../3rdparty/asn1codec/e2ap_engine/ -le2ap_codec -lasncodec
// #include <asn1codec_utils.h>
// #include <x2setup_request_wrapper.h>
import "C"
import (
"fmt"
"github.com/pkg/errors"
"unsafe"
)
const (
EnvRicId = "RIC_ID"
ShortMacro_eNB_ID = 18
Macro_eNB_ID = 20
LongMacro_eNB_ID = 21
Home_eNB_ID = 28
)
var PackedEndcX2setupRequest []byte
var PackedX2setupRequest []byte
var PackedEndcX2setupRequestAsString string
var PackedX2setupRequestAsString string
/*The Ric Id is the combination of pLMNId and ENBId*/
var pLMNId []byte
var eNBId []byte
var eNBIdBitqty uint
var ricFlag = []byte{0xbb, 0xbc, 0xcc} /*pLMNId [3]bytes*/
func preparePackedEndcX2SetupRequest(maxAsn1PackedBufferSize int, maxAsn1CodecMessageBufferSize int, pLMNId []byte, eNB_Id []byte /*18, 20, 21, 28 bits length*/, bitqty uint, ricFlag []byte) ([]byte, string, error) {
packedBuf := make([]byte, maxAsn1PackedBufferSize)
errBuf := make([]C.char, maxAsn1CodecMessageBufferSize)
packedBufSize := C.ulong(len(packedBuf))
pduAsString := ""
if !C.build_pack_endc_x2setup_request(
(*C.uchar)(unsafe.Pointer(&pLMNId[0])) /*pLMN_Identity*/,
(*C.uchar)(unsafe.Pointer(&eNB_Id[0])),
C.uint(bitqty),
(*C.uchar)(unsafe.Pointer(&ricFlag[0])) /*pLMN_Identity*/,
&packedBufSize,
(*C.uchar)(unsafe.Pointer(&packedBuf[0])),
C.ulong(len(errBuf)),
&errBuf[0]) {
return nil, "", errors.New(fmt.Sprintf("packing error: %s", C.GoString(&errBuf[0])))
}
pdu := C.new_pdu(C.size_t(1)) //TODO: change signature
defer C.delete_pdu(pdu)
if C.per_unpack_pdu(pdu, packedBufSize, (*C.uchar)(unsafe.Pointer(&packedBuf[0])), C.size_t(len(errBuf)), &errBuf[0]) {
C.asn1_pdu_printer(pdu, C.size_t(len(errBuf)), &errBuf[0])
pduAsString = C.GoString(&errBuf[0])
}
return packedBuf[:packedBufSize], pduAsString, nil
}
func preparePackedX2SetupRequest(maxAsn1PackedBufferSize int, maxAsn1CodecMessageBufferSize int, pLMNId []byte, eNB_Id []byte /*18, 20, 21, 28 bits length*/, bitqty uint, ricFlag []byte) ([]byte, string, error) {
packedBuf := make([]byte, maxAsn1PackedBufferSize)
errBuf := make([]C.char, maxAsn1CodecMessageBufferSize)
packedBufSize := C.ulong(len(packedBuf))
pduAsString := ""
if !C.build_pack_x2setup_request(
(*C.uchar)(unsafe.Pointer(&pLMNId[0])) /*pLMN_Identity*/,
(*C.uchar)(unsafe.Pointer(&eNB_Id[0])),
C.uint(bitqty),
(*C.uchar)(unsafe.Pointer(&ricFlag[0])) /*pLMN_Identity*/,
&packedBufSize,
(*C.uchar)(unsafe.Pointer(&packedBuf[0])),
C.ulong(len(errBuf)),
&errBuf[0]) {
return nil, "", errors.New(fmt.Sprintf("packing error: %s", C.GoString(&errBuf[0])))
}
pdu := C.new_pdu(C.size_t(1)) //TODO: change signature
defer C.delete_pdu(pdu)
if C.per_unpack_pdu(pdu, packedBufSize, (*C.uchar)(unsafe.Pointer(&packedBuf[0])), C.size_t(len(errBuf)), &errBuf[0]) {
C.asn1_pdu_printer(pdu, C.size_t(len(errBuf)), &errBuf[0])
pduAsString = C.GoString(&errBuf[0])
}
return packedBuf[:packedBufSize], pduAsString, nil
}
//Expected value in RIC_ID = pLMN_Identity-eNB_ID/<eNB_ID size in bits>
//<6 hex digits>-<6 or 8 hex digits>/<18|20|21|28>
//Each byte is represented by two hex digits, the value in the lowest byte of the eNB_ID must be assigned to the lowest bits
//For example, to get the value of ffffeab/28 the last byte must be 0x0b, not 0xb0 (-ffffea0b/28).
func parseRicID(ricId string) error {
if _, err := fmt.Sscanf(ricId, "%6x-%8x/%2d", &pLMNId, &eNBId, &eNBIdBitqty); err != nil {
return fmt.Errorf("unable to extract the value of %s: %s", EnvRicId, err)
}
if len(pLMNId) < 3 {
return fmt.Errorf("invalid value for %s, len(pLMNId:%v) != 3", EnvRicId, pLMNId)
}
if len(eNBId) < 3 {
return fmt.Errorf("invalid value for %s, len(eNBId:%v) != 3 or 4", EnvRicId, eNBId)
}
if eNBIdBitqty != ShortMacro_eNB_ID && eNBIdBitqty != Macro_eNB_ID && eNBIdBitqty != LongMacro_eNB_ID && eNBIdBitqty != Home_eNB_ID {
return fmt.Errorf("invalid value for %s, eNBIdBitqty: %d", EnvRicId, eNBIdBitqty)
}
return nil
}
func init() {
var err error
ricId := "bbbccc-abcd0e/20"
if err = parseRicID(ricId); err != nil {
panic(err)
}
PackedEndcX2setupRequest, PackedEndcX2setupRequestAsString, err = preparePackedEndcX2SetupRequest(MaxAsn1PackedBufferSize, MaxAsn1CodecMessageBufferSize, pLMNId, eNBId, eNBIdBitqty, ricFlag)
if err != nil {
panic(err)
}
PackedX2setupRequest, PackedX2setupRequestAsString, err = preparePackedX2SetupRequest(MaxAsn1PackedBufferSize, MaxAsn1CodecMessageBufferSize, pLMNId, eNBId, eNBIdBitqty, ricFlag)
if err != nil {
panic(err)
}
}

View File

@@ -0,0 +1,135 @@
/*
* Copyright (c) 2019 AT&T Intellectual Property.
*
* 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.
*/
/*
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
* platform project (RICP).
*/
package e2pdus
import (
"bytes"
"fmt"
"strings"
"testing"
)
func TestParseRicId(t *testing.T) {
var testCases = []struct {
ricId string
pLMNId []byte
eNBId []byte
eNBIdBitqty uint
failure error
}{
{
ricId: "bbbccc-abcd02/18",
pLMNId: []byte{0xbb, 0xbc, 0xcc},
eNBId: []byte{0xab, 0xcd, 0x2}, /*00000010 -> 10000000*/
eNBIdBitqty: ShortMacro_eNB_ID,
},
{
ricId: "bbbccc-abcd0e/20",
pLMNId: []byte{0xbb, 0xbc, 0xcc},
eNBId: []byte{0xab, 0xcd, 0xe},
eNBIdBitqty: Macro_eNB_ID,
},
{
ricId: "bbbccc-abcd07/21",
pLMNId: []byte{0xbb, 0xbc, 0xcc},
eNBId: []byte{0xab, 0xcd, 0x7}, /*00000111 -> 00111000*/
eNBIdBitqty: LongMacro_eNB_ID,
},
{
ricId: "bbbccc-abcdef08/28",
pLMNId: []byte{0xbb, 0xbc, 0xcc},
eNBId: []byte{0xab, 0xcd, 0xef, 0x8},
eNBIdBitqty: Home_eNB_ID,
},
{
ricId: "",
failure: fmt.Errorf("unable to extract the value of RIC_ID: EOF"),
},
{
ricId: "bbbccc",
failure: fmt.Errorf("unable to extract the value of RIC_ID: unexpected EOF"),
},
{
ricId: "bbbccc-",
failure: fmt.Errorf("unable to extract the value of RIC_ID: EOF"),
},
{
ricId: "-bbbccc",
failure: fmt.Errorf("%s", "unable to extract the value of RIC_ID: no hex data for %x string"),
},
{
ricId: "/20",
failure: fmt.Errorf("%s", "unable to extract the value of RIC_ID: no hex data for %x string"),
},
{
ricId: "bbbcccdd-abcdef08/28", // pLMNId too long
failure: fmt.Errorf("unable to extract the value of RIC_ID: input does not match format"),
},
{
ricId: "bbbccc-abcdef0809/28", // eNBId too long
failure: fmt.Errorf("unable to extract the value of RIC_ID: input does not match format"),
},
{
ricId: "bbbc-abcdef08/28", // pLMNId too short
failure: fmt.Errorf("invalid value for RIC_ID, len(pLMNId:[187 188]) != 3"),
},
{
ricId: "bbbccc-abcd/28", // eNBId too short
failure: fmt.Errorf("invalid value for RIC_ID, len(eNBId:[171 205]) != 3 or 4"),
},
{
ricId: "bbbccc-abcdef08/239", // bit quantity too long - no error, will return 23 (which is invalid)
failure: fmt.Errorf("invalid value for RIC_ID, eNBIdBitqty: 23"),
},
}
for _, tc := range testCases {
t.Run(tc.ricId, func(t *testing.T) {
err := parseRicID(tc.ricId)
if err != nil {
if tc.failure == nil {
t.Errorf("want: success, got: parse failed. Error: %v\n", err)
} else {
if strings.Compare(err.Error(), tc.failure.Error()) != 0 {
t.Errorf("want: %s, got: %s\n", err, tc.failure)
}
}
} else {
if bytes.Compare(tc.pLMNId, pLMNId) != 0 {
t.Errorf("want: pLMNId = %v, got: pLMNId = %v", tc.pLMNId, pLMNId)
}
if bytes.Compare(tc.eNBId, eNBId) != 0 {
t.Errorf("want: eNBId = %v, got: eNBId = %v", tc.eNBId, eNBId)
}
if tc.eNBIdBitqty != eNBIdBitqty {
t.Errorf("want: eNBIdBitqty = %d, got: eNBIdBitqty = %d", tc.eNBIdBitqty, eNBIdBitqty)
}
}
})
}
}