From 4edb52e022fe23b8951488c959458ad68b644d47 Mon Sep 17 00:00:00 2001 From: sjana Date: Mon, 26 Oct 2020 11:33:43 -0700 Subject: [PATCH] Control Message Encode/Decode Issue-ID: RICAPP-119 Signed-off-by: sjana Change-Id: I1a219561ae22faca6f886b8b296baa531378e6f2 --- src/xapp-asn/e2ap/e2ap_action.hpp | 17 +- src/xapp-asn/e2ap/e2ap_consts.hpp | 38 +++ src/xapp-asn/e2ap/e2ap_control_ack.cc | 265 +++++++++++++++++++ src/xapp-asn/e2ap/e2ap_control_ack.hpp | 141 +++++++++++ src/xapp-asn/e2ap/e2ap_control_failure.cc | 313 +++++++++++++++++++++++ src/xapp-asn/e2ap/e2ap_control_failure.hpp | 151 +++++++++++ src/xapp-asn/e2ap/e2ap_control_request.hpp | 321 ++++++++++++++++++++++++ src/xapp-asn/e2ap/e2ap_indication.hpp | 50 ++-- src/xapp-asn/e2ap/e2ap_subscription_request.hpp | 33 ++- src/xapp-asn/e2ap/e2ap_subsdel_request.cc | 148 +++++++++++ src/xapp-asn/e2ap/e2ap_subsdel_request.hpp | 99 ++++++++ src/xapp-asn/e2sm/e2sm_control.cc | 2 +- src/xapp-asn/e2sm/e2sm_control.hpp | 2 +- src/xapp-asn/e2sm/e2sm_indication.cc | 2 +- src/xapp-asn/e2sm/e2sm_subscription.cc | 2 +- src/xapp-asn/e2sm/e2sm_subscription.hpp | 2 +- test/test_e2ap.h | 168 +++++++++++++ test/test_e2sm.h | 19 +- test/test_subs.h | 37 +++ 19 files changed, 1746 insertions(+), 64 deletions(-) create mode 100644 src/xapp-asn/e2ap/e2ap_consts.hpp create mode 100644 src/xapp-asn/e2ap/e2ap_control_ack.cc create mode 100644 src/xapp-asn/e2ap/e2ap_control_ack.hpp create mode 100644 src/xapp-asn/e2ap/e2ap_control_failure.cc create mode 100644 src/xapp-asn/e2ap/e2ap_control_failure.hpp create mode 100644 src/xapp-asn/e2ap/e2ap_control_request.hpp create mode 100644 src/xapp-asn/e2ap/e2ap_subsdel_request.cc create mode 100644 src/xapp-asn/e2ap/e2ap_subsdel_request.hpp create mode 100644 test/test_e2ap.h diff --git a/src/xapp-asn/e2ap/e2ap_action.hpp b/src/xapp-asn/e2ap/e2ap_action.hpp index b3eb4f0..d5fad65 100644 --- a/src/xapp-asn/e2ap/e2ap_action.hpp +++ b/src/xapp-asn/e2ap/e2ap_action.hpp @@ -17,15 +17,14 @@ ================================================================================== */ /* - * action_e2ap.hpp + * e2ap_action.hpp * * Created on: Jun 30, 2020 - * Author: sjana + * Author: Shraboni Jana */ #ifndef XAPP_ASN_REFACTOR_E2AP_ACTION_HPP_ #define XAPP_ASN_REFACTOR_E2AP_ACTION_HPP_ -#define E2SM_SIZE ((int)128) #include @@ -33,6 +32,8 @@ #include #include #include + +#include "e2ap_consts.hpp" /* RICaction-ToBeSetup-Item ::= SEQUENCE { ricActionID RICactionID, @@ -56,12 +57,12 @@ class E2APAction{ public: class ActionIEs{ private: - bool is_ricSubsequentAction; + bool is_ricSubsequentAction, is_ricActionDefinition; unsigned int ricActionType, ricActionID,ricSubsequentActionType,ricTimeToWait; - unsigned char ricActionDefinition[E2SM_SIZE]; - size_t ricActionDefinition_size = E2SM_SIZE; + unsigned char ricActionDefinition[IE_SIZE]; + size_t ricActionDefinition_size = IE_SIZE; public: - ActionIEs():ricActionType(0),ricActionID(0),ricSubsequentActionType(0),ricTimeToWait(0),is_ricSubsequentAction(false){ }; + ActionIEs():ricActionType(0),ricActionID(0),ricSubsequentActionType(0),ricTimeToWait(0),is_ricSubsequentAction(false),is_ricActionDefinition(false){ }; ActionIEs& set_ricSubsequentAction(int subsequentActionType, int timeToWait){ is_ricSubsequentAction = true; ricSubsequentActionType = subsequentActionType; @@ -78,6 +79,7 @@ public: } else { mdclog_write(MDCLOG_INFO, "Successfully encoded: %s","RIC Action Definition"); } + this->is_ricActionDefinition = true; return *this; }; ActionIEs& set_ricActionID(int actionID){ricActionID = actionID; return *this;}; @@ -88,6 +90,7 @@ public: bool get_is_ricSubsequentAction() { return this->is_ricSubsequentAction; }; int get_ricSubsequentActionType(){return this->ricSubsequentActionType; } int get_ricTimeToWait(){ return this->ricTimeToWait; } + bool get_is_ricActionDefinition(){return this->is_ricActionDefinition;}; void* get_ricActionDefinition(){ return this->ricActionDefinition; }; size_t get_ricActionDefinition_size(){return this->ricActionDefinition_size; }; diff --git a/src/xapp-asn/e2ap/e2ap_consts.hpp b/src/xapp-asn/e2ap/e2ap_consts.hpp new file mode 100644 index 0000000..fc18dde --- /dev/null +++ b/src/xapp-asn/e2ap/e2ap_consts.hpp @@ -0,0 +1,38 @@ +/* +================================================================================== + + Copyright (c) 2019-2020 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. +================================================================================== +*/ + +/* + * e2ap_consts.hpp + * + * Created on: Oct 24, 2020 + * Author: Shraboni Jana + */ + +#ifndef SRC_XAPP_ASN_E2AP_CONSTS_HPP_ +#define SRC_XAPP_ASN_E2AP_CONSTS_HPP_ + +#define IE_SIZE ((int)128) +#define RIC_CONTROL_ACK_IES_COUNT 5 +#define RIC_CONTROL_FAILURE_IES_COUNT 5 +#define RIC_CONTROL_REQUEST_IES_COUNT 6 +#define RIC_INDICATION_IES_COUNT 8 +#define RIC_SUBDEL_REQUEST_IES_COUNT 2 +#define RIC_SUB_REQUEST_IES_COUNT 3 + +#endif /* SRC_XAPP_ASN_E2AP_CONSTS_HPP_ */ diff --git a/src/xapp-asn/e2ap/e2ap_control_ack.cc b/src/xapp-asn/e2ap/e2ap_control_ack.cc new file mode 100644 index 0000000..9768cec --- /dev/null +++ b/src/xapp-asn/e2ap/e2ap_control_ack.cc @@ -0,0 +1,265 @@ +/* +================================================================================== + + Copyright (c) 2019-2020 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. +================================================================================== + */ +/* + * e2ap_control_ack.cc + * + * Author: SJana, Ashwin Sridharan + */ + +#include "e2ap_control_ack.hpp" + + +E2APControlAcknowledge::E2APControlAcknowledge(ControlAcknowledgeIEs &cntrlObj){ + _cntrlIEs = std::make_unique(); + *_cntrlIEs = cntrlObj; + + _e2ap_pdu_obj = 0; + _e2ap_pdu_obj = (E2AP_PDU_t * )calloc(1, sizeof(E2AP_PDU_t)); + assert(_e2ap_pdu_obj != 0); + + _successMsg = 0; + _successMsg = (SuccessfulOutcome_t * )calloc(1, sizeof(SuccessfulOutcome_t)); + assert(_successMsg != 0); + + _successMsg->procedureCode = ProcedureCode_id_RICcontrol; + _successMsg->criticality = Criticality_reject; + _successMsg->value.present = SuccessfulOutcome__value_PR_RICcontrolAcknowledge; + + + IE_array = 0; + IE_array = (RICcontrolAcknowledge_IEs_t *)calloc(RIC_CONTROL_ACK_IES_COUNT, sizeof(RICcontrolAcknowledge_IEs_t)); + assert(IE_array != 0); + + RICcontrolAcknowledge_t * ric_acknowledge = &(_successMsg->value.choice.RICcontrolAcknowledge); + for(int i = 0; i < RIC_CONTROL_ACK_IES_COUNT; i++){ + ASN_SEQUENCE_ADD(&(ric_acknowledge->protocolIEs), &(IE_array[i])); + } + +}; + +E2APControlAcknowledge::E2APControlAcknowledge(unsigned char *buf, size_t *size){ + _e2ap_pdu_obj = 0; + _successMsg = 0; + IE_array = 0; + + _cntrlIEs = std::make_unique(); + bool status = this->decode(buf, size); + if(!status) + throw "E2AP Control Acknowledge Decode Failed: "+this->get_error(); +} + + +// Clear assigned protocolIE list from RIC control_request IE container +E2APControlAcknowledge::~E2APControlAcknowledge(void){ + + mdclog_write(MDCLOG_DEBUG, "Freeing E2AP Control Response object memory"); + + RICcontrolAcknowledge_t * ric_acknowledge = &(_successMsg->value.choice.RICcontrolAcknowledge); + for(int i = 0; i < ric_acknowledge->protocolIEs.list.size; i++){ + ric_acknowledge->protocolIEs.list.array[i] = 0; + } + if (ric_acknowledge->protocolIEs.list.size > 0){ + free(ric_acknowledge->protocolIEs.list.array); + ric_acknowledge->protocolIEs.list.array = 0; + ric_acknowledge->protocolIEs.list.count = 0; + } + + + free(IE_array); + free(_successMsg); + + _e2ap_pdu_obj->choice.successfulOutcome = 0; + _e2ap_pdu_obj->present = E2AP_PDU_PR_successfulOutcome; + + ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, _e2ap_pdu_obj); + mdclog_write(MDCLOG_DEBUG, "Freed E2AP Control Response object memory"); +} + + +bool E2APControlAcknowledge::encode(unsigned char *buf, size_t *size){ + + bool res; + res = setfields(_successMsg); + if (!res){ + return false; + } + _e2ap_pdu_obj->choice.successfulOutcome = _successMsg; + _e2ap_pdu_obj->present = E2AP_PDU_PR_successfulOutcome ; + + xer_fprint(stdout, &asn_DEF_E2AP_PDU, _e2ap_pdu_obj); + + int ret_constr = asn_check_constraints(&asn_DEF_E2AP_PDU, (void *) _e2ap_pdu_obj, _errbuf, &_errbuf_len); + if(ret_constr){ + _error_string.assign(_errbuf, _errbuf_len); + _error_string = "Constraints failed for encoding control response. Reason = " + _error_string; + return false; + } + + asn_enc_rval_t retval = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, _e2ap_pdu_obj, buf, *size); + + if(retval.encoded == -1){ + _error_string.assign(strerror(errno)); + return false; + } + else { + if(*size < retval.encoded){ + std::stringstream ss; + ss <<"Error encoding E2AP Control response . Reason = encoded pdu size " << retval.encoded << " exceeds buffer size " << *size << std::endl; + _error_string = ss.str(); + return false; + } + } + + *size = retval.encoded; + return true; + +} + +bool E2APControlAcknowledge::setfields(SuccessfulOutcome_t *successMsg){ + unsigned int ie_index; + + if (successMsg == 0){ + _error_string = "Invalid reference for E2AP Control Acknowledge in set_fields"; + return false; + } + + RICcontrolAcknowledge_t * ric_acknowledge = &(successMsg->value.choice.RICcontrolAcknowledge); + ric_acknowledge->protocolIEs.list.count = 0; + + ie_index = 0; + RICcontrolAcknowledge_IEs_t *ies_ricreq = &IE_array[ie_index]; + ies_ricreq->criticality = Criticality_reject; + ies_ricreq->id = ProtocolIE_ID_id_RICrequestID; + ies_ricreq->value.present = RICcontrolAcknowledge_IEs__value_PR_RICrequestID; + + RICrequestID_t *ricrequest_ie = &ies_ricreq->value.choice.RICrequestID; + ricrequest_ie->ricRequestorID = this->getIEs().get_ricRequestorID(); + ricrequest_ie->ricInstanceID = this->getIEs().get_ricInstanceID(); + ASN_SEQUENCE_ADD(&(ric_acknowledge->protocolIEs), ies_ricreq); + + ie_index = 1; + RICcontrolAcknowledge_IEs_t *ies_ranfunc = &IE_array[ie_index]; + ies_ranfunc->criticality = Criticality_reject; + ies_ranfunc->id = ProtocolIE_ID_id_RANfunctionID; + ies_ranfunc->value.present = RICcontrolAcknowledge_IEs__value_PR_RANfunctionID; + + RANfunctionID_t *ranfunction_ie = &ies_ranfunc->value.choice.RANfunctionID; + *ranfunction_ie = this->getIEs().get_ranFunctionID(); + ASN_SEQUENCE_ADD(&(ric_acknowledge->protocolIEs), ies_ranfunc); + + ie_index = 2; + RICcontrolAcknowledge_IEs_t *ies_cntrlstatus = &IE_array[ie_index]; + ies_cntrlstatus->criticality = Criticality_reject; + ies_cntrlstatus->id = ProtocolIE_ID_id_RICcontrolStatus; + ies_cntrlstatus->value.present = RICcontrolAcknowledge_IEs__value_PR_RICcontrolStatus; + RICcontrolStatus_t *ricstatus_ie = &ies_cntrlstatus->value.choice.RICcontrolStatus; + *ricstatus_ie = this->getIEs().get_ricControlStatus(); + + ASN_SEQUENCE_ADD(&(ric_acknowledge->protocolIEs), ies_cntrlstatus); + + if(this->getIEs().get_is_ricCallProcessId()){ + ie_index++; + RICcontrolAcknowledge_IEs_t *ies_riccallprocessid = &IE_array[ie_index]; + ies_riccallprocessid->criticality = Criticality_reject; + ies_riccallprocessid->id = ProtocolIE_ID_id_RICcallProcessID; + ies_riccallprocessid->value.present = RICcontrolAcknowledge_IEs__value_PR_RICcallProcessID; + RICcallProcessID_t *riccallprocessid_ie = &ies_riccallprocessid->value.choice.RICcallProcessID; + riccallprocessid_ie->buf = (uint8_t*)this->getIEs().get_ricCallProcessId(); + riccallprocessid_ie->size = this->getIEs().get_ricCallProcessId_size(); + ASN_SEQUENCE_ADD(&(ric_acknowledge->protocolIEs), ies_riccallprocessid); + + } + if(this->getIEs().get_is_ricControlOutcome()){ + ie_index++; + RICcontrolAcknowledge_IEs_t *ies_ricControlOutcome = &IE_array[ie_index]; + ies_ricControlOutcome->criticality = Criticality_reject; + ies_ricControlOutcome->id = ProtocolIE_ID_id_RICcallProcessID; + ies_ricControlOutcome->value.present = RICcontrolAcknowledge_IEs__value_PR_RICcontrolOutcome; + RICcontrolOutcome_t *ricControlOutcome_ie = &ies_ricControlOutcome->value.choice.RICcallProcessID; + ricControlOutcome_ie->buf = (uint8_t*)this->getIEs().get_ricControlOutcome(); + ricControlOutcome_ie->size = this->getIEs().get_ricControlOutcome_size(); + ASN_SEQUENCE_ADD(&(ric_acknowledge->protocolIEs), ies_ricControlOutcome); + + } + + + + return true; + +}; + + +bool E2APControlAcknowledge::decode(unsigned char *buf, size_t *size) +{ + asn_dec_rval_t dec_res = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void**)&(_e2ap_pdu_obj), buf, *size); + if(dec_res.code != RC_OK){ + mdclog_write(MDCLOG_ERR, "Failed to decode: %s","RIC Control Ack Message"); + return false; + } else { + mdclog_write(MDCLOG_INFO, "Successfully decoded: %s","RIC Control Ack Message"); + } + + xer_fprint(stdout, &asn_DEF_E2AP_PDU, _e2ap_pdu_obj); + + _successMsg = _e2ap_pdu_obj->choice.successfulOutcome; + //write the decoding code. + + + if (_successMsg == 0){ + _error_string = "Invalid reference for E2AP Control Acknowledge message in get_fields"; + return false; + } + + + for(int edx = 0; edx < _successMsg->value.choice.RICcontrolAcknowledge.protocolIEs.list.count; edx++) { + RICcontrolAcknowledge_IEs_t *memb_ptr = _successMsg->value.choice.RICcontrolAcknowledge.protocolIEs.list.array[edx]; + + switch(memb_ptr->id) + { + + case (ProtocolIE_ID_id_RICcallProcessID): + _cntrlIEs->set_ricCallProcessID(memb_ptr->value.choice.RICcallProcessID.buf, memb_ptr->value.choice.RICcallProcessID.size); + break; + + case (ProtocolIE_ID_id_RICrequestID): + _cntrlIEs->set_ricRequestorID(memb_ptr->value.choice.RICrequestID.ricRequestorID); + _cntrlIEs->set_ricInstanceID(memb_ptr->value.choice.RICrequestID.ricInstanceID); + break; + + case (ProtocolIE_ID_id_RANfunctionID): + _cntrlIEs->set_ranFunctionID(memb_ptr->value.choice.RANfunctionID); + break; + + case (ProtocolIE_ID_id_RICcontrolStatus): + _cntrlIEs->set_ricControlStatus(memb_ptr->value.choice.RICcontrolStatus); + break; + + case (ProtocolIE_ID_id_RICcontrolOutcome): + _cntrlIEs->set_ricControlOutcome(memb_ptr->value.choice.RICcontrolOutcome.buf, memb_ptr->value.choice.RICcontrolOutcome.size); + break; + + } + + } + + return true; + +} + + diff --git a/src/xapp-asn/e2ap/e2ap_control_ack.hpp b/src/xapp-asn/e2ap/e2ap_control_ack.hpp new file mode 100644 index 0000000..4963642 --- /dev/null +++ b/src/xapp-asn/e2ap/e2ap_control_ack.hpp @@ -0,0 +1,141 @@ +/* +================================================================================== + + Copyright (c) 2019-2020 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. +================================================================================== +*/ +/* + * e2ap_control_ack.hpp + * + * Author: Shraboni Jana + */ + +/*-- ************************************************************** +-- +-- RIC CONTROL ACKNOWLEDGE +-- +-- ************************************************************** +RICcontrolAcknowledge ::= SEQUENCE { + protocolIEs ProtocolIE-Container {{RICcontrolAcknowledge-IEs}}, + ... +} + +RICcontrolAcknowledge-IEs E2AP-PROTOCOL-IES ::= { + { ID id-RICrequestID CRITICALITY reject TYPE RICrequestID PRESENCE mandatory }| + { ID id-RANfunctionID CRITICALITY reject TYPE RANfunctionID PRESENCE mandatory }| + { ID id-RICcallProcessID CRITICALITY reject TYPE RICcallProcessID PRESENCE optional }| + { ID id-RICcontrolStatus CRITICALITY reject TYPE RICcontrolStatus PRESENCE mandatory } | + { ID id-RICcontrolOutcome CRITICALITY reject TYPE RICcontrolOutcome PRESENCE optional }, + ... +}*/ + +#ifndef SRC_XAPP_ASN_E2AP_E2AP_CONTROL_ACK_HPP_ +#define SRC_XAPP_ASN_E2AP_E2AP_CONTROL_ACK_HPP_ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "e2ap_consts.hpp" + +class E2APControlAcknowledge{ + +public: + class ControlAcknowledgeIEs{ + private: + long int ricRequestorID , ricInstanceID, ranFunctionID, ricCallProcessID, ricControlStatus; + + unsigned char ricCallProcessId[IE_SIZE]; + size_t ricCallProcessId_size = IE_SIZE; + bool is_ricCallProcessId; + unsigned char ricControlOutcome[IE_SIZE]; + size_t ricControlOutcome_size = IE_SIZE; + bool is_ricControlOutcome; + + public: + ControlAcknowledgeIEs(void):ricRequestorID(1), ricInstanceID(1),ranFunctionID(1), ricCallProcessID(0),ricControlStatus(1),is_ricControlOutcome(false),is_ricCallProcessId(false){}; + void* get_ricCallProcessId(){return this->ricCallProcessId;}; + size_t get_ricCallProcessId_size(){return this->ricCallProcessId_size;}; + + void* get_ricControlOutcome(){return this->ricControlOutcome;}; + size_t get_ricControlOutcome_size(){return this->ricControlOutcome_size;}; + + long int get_ricRequestorID(){return this->ricRequestorID;}; + long int get_ricInstanceID(){return this->ricInstanceID;}; + long int get_ranFunctionID(){return this->ranFunctionID;}; + long int get_ricControlStatus(){return this->ricControlStatus;}; + + bool get_is_ricCallProcessId(){return is_ricCallProcessId;}; + bool get_is_ricControlOutcome(){return is_ricControlOutcome;}; + + + ControlAcknowledgeIEs& set_ricCallProcessID(std::string strCallProcID){ + is_ricCallProcessId = true; ricCallProcessId_size = strlen(strCallProcID.c_str()); + memcpy((char*)ricCallProcessId, strCallProcID.c_str(), ricCallProcessId_size); + return *this; + } + ControlAcknowledgeIEs& set_ricCallProcessID(unsigned char* callproc, size_t callproc_size){ + is_ricCallProcessId = true; + memcpy(ricCallProcessId, callproc, callproc_size); ricCallProcessId_size = callproc_size; + return *this; + } + + + ControlAcknowledgeIEs& set_ricControlOutcome(std::string strOutcome){ + is_ricControlOutcome = true; ricControlOutcome_size = strlen(strOutcome.c_str()); + memcpy((char*)ricControlOutcome, strOutcome.c_str(), ricControlOutcome_size); + return *this; + } + ControlAcknowledgeIEs& set_ricControlOutcome(unsigned char* callproc, size_t callproc_size){ + is_ricControlOutcome = true; + memcpy(ricControlOutcome, callproc, callproc_size); ricControlOutcome_size = callproc_size; + return *this; + } + + + ControlAcknowledgeIEs& set_ricRequestorID(long int reqID){this->ricRequestorID = reqID; return *this;} + ControlAcknowledgeIEs& set_ricControlStatus(long int stat){this->ricControlStatus = stat; return *this;} + ControlAcknowledgeIEs& set_ricInstanceID(long int reqID){this->ricInstanceID = reqID; return *this;} + ControlAcknowledgeIEs& set_ranFunctionID(long int funcID){this->ranFunctionID = funcID; return *this;} + + }; + E2APControlAcknowledge(ControlAcknowledgeIEs &); + E2APControlAcknowledge(unsigned char *, size_t *); + ~E2APControlAcknowledge(void); + bool encode(unsigned char *, size_t *); + bool decode(unsigned char *, size_t *); + ControlAcknowledgeIEs& getIEs(){ return *_cntrlIEs.get();}; + std::string get_error(void) const {return _error_string ; }; +private: + + E2AP_PDU_t * _e2ap_pdu_obj; + SuccessfulOutcome_t * _successMsg; + RICcontrolAcknowledge_IEs_t *IE_array; + std::string _error_string; + bool setfields(SuccessfulOutcome_t *); + bool getfields(SuccessfulOutcome_t *); + std::unique_ptr _cntrlIEs; + char _errbuf[128]; + size_t _errbuf_len = IE_SIZE; +}; + + + + +#endif /* SRC_XAPP_ASN_E2AP_E2AP_CONTROL_ACK_HPP_ */ diff --git a/src/xapp-asn/e2ap/e2ap_control_failure.cc b/src/xapp-asn/e2ap/e2ap_control_failure.cc new file mode 100644 index 0000000..099233c --- /dev/null +++ b/src/xapp-asn/e2ap/e2ap_control_failure.cc @@ -0,0 +1,313 @@ +/* +================================================================================== + + Copyright (c) 2019-2020 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. +================================================================================== + */ +/* + * e2ap_control_failure.cc + * + * Author: SJana, Ashwin Sridharan + */ + +#include "e2ap_control_failure.hpp" + + +E2APControlFailure::E2APControlFailure(ControlFailureIEs &cntrlObj){ + _cntrlIEs = std::make_unique(); + *_cntrlIEs = cntrlObj; + + _e2ap_pdu_obj = 0; + _e2ap_pdu_obj = (E2AP_PDU_t * )calloc(1, sizeof(E2AP_PDU_t)); + assert(_e2ap_pdu_obj != 0); + + _unsuccessMsg = 0; + _unsuccessMsg = (UnsuccessfulOutcome_t * )calloc(1, sizeof(UnsuccessfulOutcome_t)); + assert(_unsuccessMsg != 0); + + _unsuccessMsg->procedureCode = ProcedureCode_id_RICcontrol; + _unsuccessMsg->criticality = Criticality_reject; + _unsuccessMsg->value.present = UnsuccessfulOutcome__value_PR_RICcontrolFailure; + + + IE_array = 0; + IE_array = (RICcontrolFailure_IEs_t *)calloc(RIC_CONTROL_FAILURE_IES_COUNT, sizeof(RICcontrolFailure_IEs_t)); + assert(IE_array != 0); + + RICcontrolFailure_t * ric_failure = &(_unsuccessMsg->value.choice.RICcontrolFailure); + for(int i = 0; i < RIC_CONTROL_FAILURE_IES_COUNT; i++){ + ASN_SEQUENCE_ADD(&(ric_failure->protocolIEs), &(IE_array[i])); + } + +}; + +E2APControlFailure::E2APControlFailure(unsigned char *buf, size_t *size){ + _e2ap_pdu_obj = 0; + _unsuccessMsg = 0; + IE_array = 0; + + _cntrlIEs = std::make_unique(); + bool status = this->decode(buf, size); + if(!status) + throw "E2AP Control Failure Decode Failed: "+this->get_error(); +} + + +// Clear assigned protocolIE list from RIC control_request IE container +E2APControlFailure::~E2APControlFailure(void){ + + mdclog_write(MDCLOG_DEBUG, "Freeing E2AP Control Response object memory"); + + RICcontrolFailure_t * ric_failure = &(_unsuccessMsg->value.choice.RICcontrolFailure); + for(int i = 0; i < ric_failure->protocolIEs.list.size; i++){ + ric_failure->protocolIEs.list.array[i] = 0; + } + if (ric_failure->protocolIEs.list.size > 0){ + free(ric_failure->protocolIEs.list.array); + ric_failure->protocolIEs.list.array = 0; + ric_failure->protocolIEs.list.count = 0; + } + + + free(IE_array); + free(_unsuccessMsg); + + _e2ap_pdu_obj->choice.unsuccessfulOutcome = 0; + _e2ap_pdu_obj->present = E2AP_PDU_PR_unsuccessfulOutcome; + + ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, _e2ap_pdu_obj); + mdclog_write(MDCLOG_DEBUG, "Freed E2AP Control Response object memory"); +} + + +bool E2APControlFailure::encode(unsigned char *buf, size_t *size){ + + bool res; + res = setfields(_unsuccessMsg); + if (!res){ + return false; + } + _e2ap_pdu_obj->choice.unsuccessfulOutcome = _unsuccessMsg; + _e2ap_pdu_obj->present = E2AP_PDU_PR_unsuccessfulOutcome ; + + xer_fprint(stdout, &asn_DEF_E2AP_PDU, _e2ap_pdu_obj); + + int ret_constr = asn_check_constraints(&asn_DEF_E2AP_PDU, (void *) _e2ap_pdu_obj, _errbuf, &_errbuf_len); + if(ret_constr){ + _error_string.assign(_errbuf, _errbuf_len); + _error_string = "Constraints failed for encoding control response. Reason = " + _error_string; + return false; + } + + asn_enc_rval_t retval = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, _e2ap_pdu_obj, buf, *size); + + if(retval.encoded == -1){ + _error_string.assign(strerror(errno)); + return false; + } + else { + if(*size < retval.encoded){ + std::stringstream ss; + ss <<"Error encoding E2AP Control response . Reason = encoded pdu size " << retval.encoded << " exceeds buffer size " << *size << std::endl; + _error_string = ss.str(); + return false; + } + } + + *size = retval.encoded; + return true; + +} + +bool E2APControlFailure::setfields(UnsuccessfulOutcome_t *successMsg){ + unsigned int ie_index; + + if (successMsg == 0){ + _error_string = "Invalid reference for E2AP Control Failure in set_fields"; + return false; + } + + RICcontrolFailure_t * ric_failure = &(successMsg->value.choice.RICcontrolFailure); + ric_failure->protocolIEs.list.count = 0; + + ie_index = 0; + RICcontrolFailure_IEs_t *ies_ricreq = &IE_array[ie_index]; + ies_ricreq->criticality = Criticality_reject; + ies_ricreq->id = ProtocolIE_ID_id_RICrequestID; + ies_ricreq->value.present = RICcontrolFailure_IEs__value_PR_RICrequestID; + + RICrequestID_t *ricrequest_ie = &ies_ricreq->value.choice.RICrequestID; + ricrequest_ie->ricRequestorID = this->getIEs().get_ricRequestorID(); + ricrequest_ie->ricInstanceID = this->getIEs().get_ricInstanceID(); + ASN_SEQUENCE_ADD(&(ric_failure->protocolIEs), ies_ricreq); + + ie_index = 1; + RICcontrolFailure_IEs_t *ies_ranfunc = &IE_array[ie_index]; + ies_ranfunc->criticality = Criticality_reject; + ies_ranfunc->id = ProtocolIE_ID_id_RANfunctionID; + ies_ranfunc->value.present = RICcontrolFailure_IEs__value_PR_RANfunctionID; + + RANfunctionID_t *ranfunction_ie = &ies_ranfunc->value.choice.RANfunctionID; + *ranfunction_ie = this->getIEs().get_ranFunctionID(); + ASN_SEQUENCE_ADD(&(ric_failure->protocolIEs), ies_ranfunc); + + ie_index = 2; + RICcontrolFailure_IEs_t *ies_ric_cause = &IE_array[ie_index]; + ies_ric_cause->criticality = Criticality_ignore; + ies_ric_cause->id = ProtocolIE_ID_id_Cause; + ies_ric_cause->value.present = RICcontrolFailure_IEs__value_PR_Cause; + Cause_t * ric_cause = &(ies_ric_cause->value.choice.Cause); + ric_cause->present = (Cause_PR)this->getIEs().get_ricCause(); + switch(this->getIEs().get_ricCause()){ + case Cause_PR_ricService: + ric_cause->choice.ricService = this->getIEs().get_ricSubCause(); + break; + case Cause_PR_transport: + ric_cause->choice.transport = this->getIEs().get_ricSubCause(); + break; + case Cause_PR_protocol: + ric_cause->choice.protocol= this->getIEs().get_ricSubCause(); + break; + case Cause_PR_misc: + ric_cause->choice.misc = this->getIEs().get_ricSubCause(); + break; + case Cause_PR_ricRequest: + ric_cause->choice.ricRequest = this->getIEs().get_ricSubCause(); + break; + default: + std::cout <<"Error ! Illegal cause enum" << this->getIEs().get_ricCause() << std::endl; + return false; + } + ASN_SEQUENCE_ADD(&(ric_failure->protocolIEs), ies_ric_cause); + + if(this->getIEs().get_is_ricCallProcessId()){ + ie_index++; + RICcontrolFailure_IEs_t *ies_riccallprocessid = &IE_array[ie_index]; + ies_riccallprocessid->criticality = Criticality_reject; + ies_riccallprocessid->id = ProtocolIE_ID_id_RICcallProcessID; + ies_riccallprocessid->value.present = RICcontrolFailure_IEs__value_PR_RICcallProcessID; + RICcallProcessID_t *riccallprocessid_ie = &ies_riccallprocessid->value.choice.RICcallProcessID; + riccallprocessid_ie->buf = (uint8_t*)this->getIEs().get_ricCallProcessId(); + riccallprocessid_ie->size = this->getIEs().get_ricCallProcessId_size(); + ASN_SEQUENCE_ADD(&(ric_failure->protocolIEs), ies_riccallprocessid); + + } + if(this->getIEs().get_is_ricControlOutcome()){ + ie_index++; + RICcontrolFailure_IEs_t *ies_ricControlOutcome = &IE_array[ie_index]; + ies_ricControlOutcome->criticality = Criticality_reject; + ies_ricControlOutcome->id = ProtocolIE_ID_id_RICcallProcessID; + ies_ricControlOutcome->value.present = RICcontrolFailure_IEs__value_PR_RICcontrolOutcome; + RICcontrolOutcome_t *ricControlOutcome_ie = &ies_ricControlOutcome->value.choice.RICcallProcessID; + ricControlOutcome_ie->buf = (uint8_t*)this->getIEs().get_ricControlOutcome(); + ricControlOutcome_ie->size = this->getIEs().get_ricControlOutcome_size(); + ASN_SEQUENCE_ADD(&(ric_failure->protocolIEs), ies_ricControlOutcome); + + } + + + + return true; + +}; + + +bool E2APControlFailure::decode(unsigned char *buf, size_t *size) +{ + asn_dec_rval_t dec_res = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void**)&(_e2ap_pdu_obj), buf, *size); + if(dec_res.code != RC_OK){ + mdclog_write(MDCLOG_ERR, "Failed to decode: %s","RIC Control Ack Message"); + return false; + } else { + mdclog_write(MDCLOG_INFO, "Successfully decoded: %s","RIC Control Ack Message"); + } + + xer_fprint(stdout, &asn_DEF_E2AP_PDU, _e2ap_pdu_obj); + + _unsuccessMsg = _e2ap_pdu_obj->choice.unsuccessfulOutcome; + //write the decoding code. + + + if (_unsuccessMsg == 0){ + _error_string = "Invalid reference for E2AP Control Failure message in get_fields"; + return false; + } + + + for(int edx = 0; edx < _unsuccessMsg->value.choice.RICcontrolFailure.protocolIEs.list.count; edx++) { + RICcontrolFailure_IEs_t *memb_ptr = _unsuccessMsg->value.choice.RICcontrolFailure.protocolIEs.list.array[edx]; + + switch(memb_ptr->id) + { + + case (ProtocolIE_ID_id_RICcallProcessID): + _cntrlIEs->set_ricCallProcessID(memb_ptr->value.choice.RICcallProcessID.buf, memb_ptr->value.choice.RICcallProcessID.size); + break; + + case (ProtocolIE_ID_id_RICrequestID): + _cntrlIEs->set_ricRequestorID(memb_ptr->value.choice.RICrequestID.ricRequestorID); + _cntrlIEs->set_ricInstanceID(memb_ptr->value.choice.RICrequestID.ricInstanceID); + break; + + case (ProtocolIE_ID_id_RANfunctionID): + _cntrlIEs->set_ranFunctionID(memb_ptr->value.choice.RANfunctionID); + break; + + case (ProtocolIE_ID_id_Cause): + + _cntrlIEs->set_ricCause(memb_ptr->value.choice.Cause.present); + switch(memb_ptr->value.choice.Cause.present){ + case Cause_PR_ricService : + _cntrlIEs->set_ricSubCause(memb_ptr->value.choice.Cause.choice.ricService); + break; + + case Cause_PR_transport : + _cntrlIEs->set_ricSubCause(memb_ptr->value.choice.Cause.choice.transport); + break; + + case Cause_PR_protocol : + _cntrlIEs->set_ricSubCause(memb_ptr->value.choice.Cause.choice.protocol); + break; + + case Cause_PR_misc : + _cntrlIEs->set_ricSubCause(memb_ptr->value.choice.Cause.choice.misc); + break; + + case Cause_PR_ricRequest : + _cntrlIEs->set_ricSubCause(memb_ptr->value.choice.Cause.choice.ricRequest); + break; + + default: + _cntrlIEs->set_ricSubCause(-1); + break; + } + + + break; + + case (ProtocolIE_ID_id_RICcontrolOutcome): + _cntrlIEs->set_ricControlOutcome(memb_ptr->value.choice.RICcontrolOutcome.buf, memb_ptr->value.choice.RICcontrolOutcome.size); + break; + + } + + } + + return true; + +} + + + diff --git a/src/xapp-asn/e2ap/e2ap_control_failure.hpp b/src/xapp-asn/e2ap/e2ap_control_failure.hpp new file mode 100644 index 0000000..2566b87 --- /dev/null +++ b/src/xapp-asn/e2ap/e2ap_control_failure.hpp @@ -0,0 +1,151 @@ +/* +================================================================================== + + Copyright (c) 2019-2020 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. +================================================================================== +*/ +/* + * e2ap_control_failure.hpp + * + * Author: Shraboni Jana + */ +/* + -- ************************************************************** +-- +-- RIC CONTROL FAILURE +-- +-- ************************************************************** +RICcontrolFailure ::= SEQUENCE { + protocolIEs ProtocolIE-Container {{RICcontrolFailure-IEs}}, + ... +} + +RICcontrolFailure-IEs E2AP-PROTOCOL-IES ::= { + { ID id-RICrequestID CRITICALITY reject TYPE RICrequestID PRESENCE mandatory }| + { ID id-RANfunctionID CRITICALITY reject TYPE RANfunctionID PRESENCE mandatory }| + { ID id-RICcallProcessID CRITICALITY reject TYPE RICcallProcessID PRESENCE optional }| + { ID id-Cause CRITICALITY ignore TYPE Cause PRESENCE mandatory } | + { ID id-RICcontrolOutcome CRITICALITY reject TYPE RICcontrolOutcome PRESENCE optional }, + ... +} + + + */ +#ifndef SRC_XAPP_ASN_E2AP_E2AP_CONTROL_FAILURE_HPP_ +#define SRC_XAPP_ASN_E2AP_E2AP_CONTROL_FAILURE_HPP_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "e2ap_consts.hpp" + + +class E2APControlFailure{ + +public: + class ControlFailureIEs{ + private: + long int ricRequestorID , ricInstanceID, ranFunctionID, ricCallProcessID, ricCause, ricSubCause; + + unsigned char ricCallProcessId[IE_SIZE]; + size_t ricCallProcessId_size = IE_SIZE; + bool is_ricCallProcessId; + unsigned char ricControlOutcome[IE_SIZE]; + size_t ricControlOutcome_size = IE_SIZE; + bool is_ricControlOutcome; + + public: + ControlFailureIEs(void):ricRequestorID(1), ricInstanceID(1),ranFunctionID(1), ricCallProcessID(0),ricCause(1),ricSubCause(1),is_ricControlOutcome(false),is_ricCallProcessId(false){}; + void* get_ricCallProcessId(){return this->ricCallProcessId;}; + size_t get_ricCallProcessId_size(){return this->ricCallProcessId_size;}; + + void* get_ricControlOutcome(){return this->ricControlOutcome;}; + size_t get_ricControlOutcome_size(){return this->ricControlOutcome_size;}; + + long int get_ricRequestorID(){return this->ricRequestorID;}; + long int get_ricInstanceID(){return this->ricInstanceID;}; + long int get_ranFunctionID(){return this->ranFunctionID;}; + long int get_ricCause(){return this->ricCause;}; + long int get_ricSubCause(){return this->ricCause;}; + + + bool get_is_ricCallProcessId(){return is_ricCallProcessId;}; + bool get_is_ricControlOutcome(){return is_ricControlOutcome;}; + + + ControlFailureIEs& set_ricCallProcessID(std::string strCallProcID){ + is_ricCallProcessId = true; ricCallProcessId_size = strlen(strCallProcID.c_str()); + memcpy((char*)ricCallProcessId, strCallProcID.c_str(), ricCallProcessId_size); + return *this; + } + ControlFailureIEs& set_ricCallProcessID(unsigned char* callproc, size_t callproc_size){ + is_ricCallProcessId = true; + memcpy(ricCallProcessId, callproc, callproc_size); ricCallProcessId_size = callproc_size; + return *this; + } + + + ControlFailureIEs& set_ricControlOutcome(std::string strOutcome){ + is_ricControlOutcome = true; ricControlOutcome_size = strlen(strOutcome.c_str()); + memcpy((char*)ricControlOutcome, strOutcome.c_str(), ricControlOutcome_size); + return *this; + } + ControlFailureIEs& set_ricControlOutcome(unsigned char* callproc, size_t callproc_size){ + is_ricControlOutcome = true; + memcpy(ricControlOutcome, callproc, callproc_size); ricControlOutcome_size = callproc_size; + return *this; + } + + + ControlFailureIEs& set_ricRequestorID(long int reqID){this->ricRequestorID = reqID; return *this;} + ControlFailureIEs& set_ricCause(long int cause){this->ricCause = cause; return *this;} + ControlFailureIEs& set_ricSubCause(long int cause){this->ricCause = cause; return *this;} + + ControlFailureIEs& set_ricInstanceID(long int reqID){this->ricInstanceID = reqID; return *this;} + ControlFailureIEs& set_ranFunctionID(long int funcID){this->ranFunctionID = funcID; return *this;} + + }; + E2APControlFailure(ControlFailureIEs &); + E2APControlFailure(unsigned char *, size_t *); + ~E2APControlFailure(void); + bool encode(unsigned char *, size_t *); + bool decode(unsigned char *, size_t *); + ControlFailureIEs& getIEs(){ return *_cntrlIEs.get();}; + std::string get_error(void) const {return _error_string ; }; +private: + + E2AP_PDU_t * _e2ap_pdu_obj; + UnsuccessfulOutcome_t * _unsuccessMsg; + RICcontrolFailure_IEs_t *IE_array; + std::string _error_string; + bool setfields(UnsuccessfulOutcome_t *); + std::unique_ptr _cntrlIEs; + char _errbuf[128]; + size_t _errbuf_len = IE_SIZE; +}; + + + + + + + +#endif /* SRC_XAPP_ASN_E2AP_E2AP_CONTROL_FAILURE_HPP_ */ diff --git a/src/xapp-asn/e2ap/e2ap_control_request.hpp b/src/xapp-asn/e2ap/e2ap_control_request.hpp new file mode 100644 index 0000000..d3b0c61 --- /dev/null +++ b/src/xapp-asn/e2ap/e2ap_control_request.hpp @@ -0,0 +1,321 @@ +/* +================================================================================== + + Copyright (c) 2019-2020 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. +================================================================================== +*/ + +/* + * e2ap_control_request.hpp + * + * Created on: Oct 10, 2020 + * Author: Shraboni Jana + */ +/*RICcontrolRequest ::= SEQUENCE { + protocolIEs ProtocolIE-Container {{RICcontrolRequest-IEs}}, + ... +} + +RICcontrolRequest-IEs E2AP-PROTOCOL-IES ::= { + { ID id-RICrequestID CRITICALITY reject TYPE RICrequestID PRESENCE mandatory }| + { ID id-RANfunctionID CRITICALITY reject TYPE RANfunctionID PRESENCE mandatory }| + { ID id-RICcallProcessID CRITICALITY reject TYPE RICcallProcessID PRESENCE optional }| + { ID id-RICcontrolHeader CRITICALITY reject TYPE RICcontrolHeader PRESENCE mandatory }| + { ID id-RICcontrolMessage CRITICALITY reject TYPE RICcontrolMessage PRESENCE mandatory }| + { ID id-RICcontrolAckRequest CRITICALITY reject TYPE RICcontrolAckRequest PRESENCE optional }, + ... +} +*/ + +#ifndef SRC_XAPP_ASN_E2AP_E2AP_CONTROL_REQUEST_HPP_ +#define SRC_XAPP_ASN_E2AP_E2AP_CONTROL_REQUEST_HPP_ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "e2ap_consts.hpp" + + +template +class E2APControlMessage{ + +public: + class ControlRequestIEs{ + private: + long int ricRequestorID , ricInstanceID, ranFunctionID, ricCallProcessID, ricControlAckRequest; + unsigned char ricControlHeader[IE_SIZE]; + size_t ricControlHeader_size=IE_SIZE; + unsigned char ricControlMessage[IE_SIZE]; + size_t ricControlMessage_size=IE_SIZE; + unsigned char ricCallProcessId[IE_SIZE]; + size_t ricCallProcessId_size = IE_SIZE; + bool is_ricCallProcessId; + + public: + ControlRequestIEs(void):ricRequestorID(1), ricInstanceID(1),ranFunctionID(1), ricCallProcessID(0), ricControlAckRequest(-1),is_ricCallProcessId(false){}; + void* get_ricControlMessage(){return this->ricControlMessage; }; + void* get_ricControlHeader(){return this->ricControlHeader; }; + void* get_ricCallProcessId(){return this->ricCallProcessId;}; + + size_t get_ricControlMessageSize(){return this->ricControlMessage_size; }; + size_t get_ricControlHeaderSize(){return this->ricControlHeader_size; }; + size_t get_ricCallProcessIdSize(){return this->ricCallProcessId_size;}; + + long int get_ricRequestorID(){return this->ricRequestorID;}; + long int get_ricInstanceID(){return this->ricInstanceID;}; + long int get_ranFunctionID(){return this->ranFunctionID;}; + long int get_ricControlAckRequest(){return this->ricControlAckRequest;}; + bool get_is_ricCallProcessId(){return is_ricCallProcessId;}; + ControlRequestIEs& set_ricControlHeader(E2SMControlHeader headerObj){ + bool res = headerObj.encode(&(this->ricControlHeader)[0],&this->ricControlHeader_size); + if(!res){ + mdclog_write(MDCLOG_ERR, "Failed to encode: %s","RIC Control Header"); + mdclog_write(MDCLOG_ERR, "Error during encode: %s",headerObj.get_error()); + } else { + mdclog_write(MDCLOG_INFO, "Successfully encoded: %s","RIC Control Header"); + } + + return *this; + } + ControlRequestIEs& set_ricControlMessage(E2SMControlMessage msgObj){ + bool res = msgObj.encode(&(this->ricControlMessage)[0],&this->ricControlMessage_size); + if(!res){ + mdclog_write(MDCLOG_ERR, "Failed to encode: %s","RIC Control Message"); + mdclog_write(MDCLOG_ERR, "Error during encode: %s",msgObj.get_error()); + } else { + mdclog_write(MDCLOG_INFO, "Successfully encoded: %s","RIC Control Message"); + } + return *this; + } + + ControlRequestIEs& set_ricCallProcessID(std::string strCallProcID){ + is_ricCallProcessId = true; ricCallProcessId_size = strlen(strCallProcID.c_str()); + memcpy((char*)ricCallProcessId, strCallProcID.c_str(), ricCallProcessId_size); + return *this; + } + ControlRequestIEs& set_ricCallProcessID(unsigned char* callproc, size_t callproc_size){ + is_ricCallProcessId = true; + memcpy(ricCallProcessId, callproc, callproc_size); ricCallProcessId_size = callproc_size; + return *this; + } + + ControlRequestIEs& set_ricRequestorID(long int reqID){this->ricRequestorID = reqID; return *this;} + ControlRequestIEs& set_ricInstanceID(long int reqID){this->ricInstanceID = reqID; return *this;} + ControlRequestIEs& set_ranFunctionID(long int funcID){this->ranFunctionID = funcID; return *this;} + + }; + E2APControlMessage(ControlRequestIEs &); + ~E2APControlMessage(void); + bool encode(unsigned char *, size_t *); + ControlRequestIEs& getIEs(){ return *_cntrlIEs.get();}; + std::string get_error(void) const {return _error_string ; }; +private: + + E2AP_PDU_t * _e2ap_pdu_obj; + InitiatingMessage_t *_initMsg; + RICcontrolRequest_IEs_t *IE_array; + std::string _error_string; + bool setfields(InitiatingMessage_t *); + std::unique_ptr _cntrlIEs; + char _errbuf[128]; + size_t _errbuf_len = IE_SIZE; +}; + +template +E2APControlMessage::E2APControlMessage(ControlRequestIEs &controlObj){ + + _cntrlIEs = std::make_unique(); + *_cntrlIEs = controlObj; + + _e2ap_pdu_obj = 0; + _e2ap_pdu_obj = (E2AP_PDU_t * )calloc(1, sizeof(E2AP_PDU_t)); + assert(_e2ap_pdu_obj != 0); + + _initMsg = 0; + _initMsg = (InitiatingMessage_t * )calloc(1, sizeof(InitiatingMessage_t)); + assert(_initMsg != 0); + + IE_array = 0; + IE_array = (RICcontrolRequest_IEs_t *)calloc(RIC_CONTROL_REQUEST_IES_COUNT, sizeof(RICcontrolRequest_IEs_t)); + assert(IE_array != 0); + + _e2ap_pdu_obj->present = E2AP_PDU_PR_initiatingMessage; + _e2ap_pdu_obj->choice.initiatingMessage = _initMsg; + + +}; + + +// Clear assigned protocolIE list from RIC control_request IE container +template +E2APControlMessage::~E2APControlMessage(void){ + + mdclog_write(MDCLOG_DEBUG, "Freeing E2AP Control Request object memory"); + + RICcontrolRequest_t *ricControl_Request = &(_initMsg->value.choice.RICcontrolRequest); + for(int i = 0; i < ricControl_Request->protocolIEs.list.size; i++){ + ricControl_Request->protocolIEs.list.array[i] = 0; + } + + if (ricControl_Request->protocolIEs.list.size > 0){ + free(ricControl_Request->protocolIEs.list.array); + ricControl_Request->protocolIEs.list.size = 0; + ricControl_Request->protocolIEs.list.count = 0; + } + + free(IE_array); + free(_initMsg); + _e2ap_pdu_obj->choice.initiatingMessage = 0; + + ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, _e2ap_pdu_obj); + mdclog_write(MDCLOG_DEBUG, "Freed E2AP Control Request object memory"); + +} + +template +bool E2APControlMessage::encode(unsigned char *buf, size_t *size){ + + _initMsg->procedureCode = ProcedureCode_id_RICcontrol; + _initMsg->criticality = Criticality_ignore; + _initMsg->value.present = InitiatingMessage__value_PR_RICcontrolRequest; + + bool res; + + res = setfields(_initMsg); + if (!res){ + return false; + } + + int ret_constr = asn_check_constraints(&asn_DEF_E2AP_PDU, (void *) _e2ap_pdu_obj, _errbuf, &_errbuf_len); + if(ret_constr){ + _error_string.assign(_errbuf, _errbuf_len); + _error_string = "Constraints failed for encoding control . Reason = " + _error_string; + return false; + } + + xer_fprint(stdout, &asn_DEF_E2AP_PDU, _e2ap_pdu_obj); + + asn_enc_rval_t retval = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, _e2ap_pdu_obj, buf, *size); + + if(retval.encoded == -1){ + _error_string.assign(strerror(errno)); + return false; + } + else { + if(*size < retval.encoded){ + std::stringstream ss; + ss <<"Error encoding event trigger definition. Reason = encoded pdu size " << retval.encoded << " exceeds buffer size " << *size << std::endl; + _error_string = ss.str(); + return false; + } + } + + *size = retval.encoded; + return true; + +} + +template +bool E2APControlMessage::setfields(InitiatingMessage_t *_initMsg){ + unsigned int ie_index; + + if (_initMsg == 0){ + _error_string = "Invalid reference for E2AP Control_Request message in set_fields"; + return false; + } + + RICcontrolRequest_t * E2APControlMessage = &(_initMsg->value.choice.RICcontrolRequest); + E2APControlMessage->protocolIEs.list.count = 0; + + + // Mandatory IE + ie_index = 0; + RICcontrolRequest_IEs_t *ies_ricreq = &IE_array[ie_index]; + ies_ricreq->criticality = Criticality_reject; + ies_ricreq->id = ProtocolIE_ID_id_RICrequestID; + ies_ricreq->value.present = RICcontrolRequest_IEs__value_PR_RICrequestID; + RICrequestID_t *ricrequest_ie = &ies_ricreq->value.choice.RICrequestID; + ricrequest_ie->ricRequestorID = this->getIEs().get_ricRequestorID(); + ricrequest_ie->ricInstanceID = this->getIEs().get_ricInstanceID(); + ASN_SEQUENCE_ADD(&(E2APControlMessage->protocolIEs), &(IE_array[ie_index])); + + // Mandatory IE + ie_index = 1; + RICcontrolRequest_IEs_t *ies_ranfunc = &IE_array[ie_index]; + ies_ranfunc->criticality = Criticality_reject; + ies_ranfunc->id = ProtocolIE_ID_id_RANfunctionID; + ies_ranfunc->value.present = RICcontrolRequest_IEs__value_PR_RANfunctionID; + RANfunctionID_t *ranfunction_ie = &ies_ranfunc->value.choice.RANfunctionID; + *ranfunction_ie = this->getIEs().get_ranFunctionID(); + ASN_SEQUENCE_ADD(&(E2APControlMessage->protocolIEs), &(IE_array[ie_index])); + + + // Mandatory IE + ie_index = 2; + RICcontrolRequest_IEs_t *ies_richead = &IE_array[ie_index]; + ies_richead->criticality = Criticality_reject; + ies_richead->id = ProtocolIE_ID_id_RICcontrolHeader; + ies_richead->value.present = RICcontrolRequest_IEs__value_PR_RICcontrolHeader; + RICcontrolHeader_t *richeader_ie = &ies_richead->value.choice.RICcontrolHeader; + richeader_ie->buf = (uint8_t*)this->getIEs().get_ricControlHeader(); + richeader_ie->size = this->getIEs().get_ricControlHeaderSize(); + ASN_SEQUENCE_ADD(&(E2APControlMessage->protocolIEs), &(IE_array[ie_index])); + + // Mandatory IE + ie_index = 3; + RICcontrolRequest_IEs_t *ies_indmsg = &IE_array[ie_index]; + ies_indmsg->criticality = Criticality_reject; + ies_indmsg->id = ProtocolIE_ID_id_RICcontrolMessage; + ies_indmsg->value.present = RICcontrolRequest_IEs__value_PR_RICcontrolMessage; + RICcontrolMessage_t *ricmsg_ie = &ies_indmsg->value.choice.RICcontrolMessage; + ricmsg_ie->buf = (uint8_t*)this->getIEs().get_ricControlMessage(); + ricmsg_ie->size = this->getIEs().get_ricControlMessageSize(); + ASN_SEQUENCE_ADD(&(E2APControlMessage->protocolIEs), &(IE_array[ie_index])); + + // Optional IE + ie_index = 4; + if (this->getIEs().get_ricControlAckRequest()>= 0){ + RICcontrolRequest_IEs_t *ies_indtyp = &IE_array[ie_index]; + ies_indtyp->criticality = Criticality_reject; + ies_indtyp->id = ProtocolIE_ID_id_RICcontrolAckRequest; + ies_indtyp->value.present = RICcontrolRequest_IEs__value_PR_RICcontrolAckRequest; + RICcontrolAckRequest_t *ricackreq_ie = &ies_indtyp->value.choice.RICcontrolAckRequest; + *ricackreq_ie = this->getIEs().get_ricControlAckRequest(); + ASN_SEQUENCE_ADD(&(E2APControlMessage->protocolIEs), &(IE_array[ie_index])); + } + + // Optional IE + ie_index = 5; + if(this->getIEs().get_is_ricCallProcessId()){ + RICcontrolRequest_IEs_t *ies_callprocid = &IE_array[ie_index]; + ies_callprocid->criticality = Criticality_reject; + ies_callprocid->id = ProtocolIE_ID_id_RICcallProcessID; + ies_callprocid->value.present = RICcontrolRequest_IEs__value_PR_RICcallProcessID; + RICcallProcessID_t *riccallprocessid_ie = &ies_callprocid->value.choice.RICcallProcessID; + riccallprocessid_ie->buf = (uint8_t*)this->getIEs().get_ricCallProcessId(); + riccallprocessid_ie->size = this->getIEs().get_ricCallProcessIdSize(); + ASN_SEQUENCE_ADD(&(E2APControlMessage->protocolIEs), &(IE_array[ie_index])); + + } + return true; + +}; + +#endif /* SRC_XAPP_ASN_E2AP_E2AP_CONTROL_REQUEST_HPP_ */ diff --git a/src/xapp-asn/e2ap/e2ap_indication.hpp b/src/xapp-asn/e2ap/e2ap_indication.hpp index 87f08dc..48051db 100644 --- a/src/xapp-asn/e2ap/e2ap_indication.hpp +++ b/src/xapp-asn/e2ap/e2ap_indication.hpp @@ -19,7 +19,7 @@ */ /* - * indication.hpp + * e2ap_indication.hpp * * Created on: Sep 18, 2020 * Author: Shraboni Jana @@ -66,7 +66,7 @@ RICindication-IEs E2AP-PROTOCOL-IES ::= { #include #include -#define IE_SIZE ((int)128) +#include "e2ap_consts.hpp" template class E2APIndication{ @@ -85,10 +85,10 @@ public: unsigned char ricCallProcessId[IE_SIZE]; size_t ricCallProcessId_size = IE_SIZE; - bool is_callProcessID; + bool is_callProcessID, is_ricIndicationSN; public: - IndicationIEs(void) : ricRequestorID(0), ranFunctionID(0), ricActionID(0),ricIndicationSN(0), ricIndicationType(0),is_callProcessID(false){}; + IndicationIEs(void) : ricRequestorID(0), ranFunctionID(0), ricActionID(0),ricIndicationSN(0), ricIndicationType(0),is_callProcessID(false),is_ricIndicationSN(false){}; void* get_ricIndicationMessage(){return this->ricIndicationMessage; }; void* get_ricIndicationHeader(){return this->ricIndicationHeader; }; void* get_ricCallProcessId(){return this->ricCallProcessId;}; @@ -102,7 +102,7 @@ public: long int get_ricActionID(){return this->ricActionID;}; long int get_ricIndicationType(){return this->ricIndicationType;} long int get_ricIndicationSN(){return this->ricIndicationSN;}; - + bool get_is_ricIndicationSN(){return this->is_ricIndicationSN;}; bool get_is_callProcessID(){return this->is_callProcessID;}; IndicationIEs& set_ricIndicationHeader(E2SMIndicationHeader e2smObj){ @@ -145,7 +145,7 @@ public: IndicationIEs& set_ranFunctionID(long int funcID){this->ranFunctionID = funcID; return *this;} IndicationIEs& set_ricActionID(long int actID){ this->ricActionID = actID; return *this;} IndicationIEs& set_ricIndicationType(long int typ){ this->ricIndicationType = typ; return *this;} - IndicationIEs& set_ricIndicationSN(long int sn){ this->ricIndicationSN = sn; return *this;} + IndicationIEs& set_ricIndicationSN(long int sn){ this->ricIndicationSN = sn; is_ricIndicationSN=true; return *this;} }; @@ -166,8 +166,6 @@ private: RICindication_IEs_t *IE_array; std::unique_ptr _indicationIEs; - unsigned int ricIndicationIEs_Count; - std::string _error_string; char _errbuf[128]; size_t _errbuf_len = 128; @@ -178,8 +176,6 @@ private: template E2APIndication::E2APIndication(IndicationIEs& ieObj){ - ricIndicationIEs_Count = 8; - e2ap_pdu_obj = 0; e2ap_pdu_obj = (E2AP_PDU_t * )calloc(1, sizeof(E2AP_PDU_t)); assert(e2ap_pdu_obj != 0); @@ -189,7 +185,7 @@ E2APIndication::E2APIndication(IndicationIEs& ieObj){ assert(initMsg != 0); IE_array = 0; - IE_array = (RICindication_IEs_t *)calloc(ricIndicationIEs_Count, sizeof(RICindication_IEs_t)); + IE_array = (RICindication_IEs_t *)calloc(RIC_INDICATION_IES_COUNT, sizeof(RICindication_IEs_t)); assert(IE_array != 0); e2ap_pdu_obj->present = E2AP_PDU_PR_initiatingMessage; @@ -367,7 +363,7 @@ bool E2APIndication::setfields(InitiatingMessage_t *initMsg){ ricrequest_ie->ricRequestorID = _indicationIEs->get_ricRequestorID(); ASN_SEQUENCE_ADD(&(ric_indication->protocolIEs), &(IE_array[ie_index])); - ie_index = 1; + ie_index++; RICindication_IEs_t *ies_ranfunc = &IE_array[ie_index]; ies_ranfunc->criticality = Criticality_reject; ies_ranfunc->id = ProtocolIE_ID_id_RANfunctionID; @@ -376,7 +372,7 @@ bool E2APIndication::setfields(InitiatingMessage_t *initMsg){ *ranfunction_ie = _indicationIEs->get_ranFunctionID(); ASN_SEQUENCE_ADD(&(ric_indication->protocolIEs), &(IE_array[ie_index])); - ie_index = 2; + ie_index++; RICindication_IEs_t *ies_actid = &IE_array[ie_index]; ies_actid->criticality = Criticality_reject; ies_actid->id = ProtocolIE_ID_id_RICactionID; @@ -385,17 +381,19 @@ bool E2APIndication::setfields(InitiatingMessage_t *initMsg){ *ricaction_ie = _indicationIEs->get_ricActionID(); ASN_SEQUENCE_ADD(&(ric_indication->protocolIEs), &(IE_array[ie_index])); - ie_index = 3; - RICindication_IEs_t *ies_ricsn = &IE_array[ie_index]; - ies_ricsn->criticality = Criticality_reject; - ies_ricsn->id = ProtocolIE_ID_id_RICindicationSN; - ies_ricsn->value.present = RICindication_IEs__value_PR_RICindicationSN; - RICindicationSN_t *ricsn_ie = &ies_ricsn->value.choice.RICindicationSN; - *ricsn_ie = _indicationIEs->get_ricIndicationSN(); - ASN_SEQUENCE_ADD(&(ric_indication->protocolIEs), &(IE_array[ie_index])); - + if(_indicationIEs->get_is_ricIndicationSN()) + { + ie_index++; + RICindication_IEs_t *ies_ricsn = &IE_array[ie_index]; + ies_ricsn->criticality = Criticality_reject; + ies_ricsn->id = ProtocolIE_ID_id_RICindicationSN; + ies_ricsn->value.present = RICindication_IEs__value_PR_RICindicationSN; + RICindicationSN_t *ricsn_ie = &ies_ricsn->value.choice.RICindicationSN; + *ricsn_ie = _indicationIEs->get_ricIndicationSN(); + ASN_SEQUENCE_ADD(&(ric_indication->protocolIEs), &(IE_array[ie_index])); + } - ie_index = 4; + ie_index++; RICindication_IEs_t *ies_indtyp = &IE_array[ie_index]; ies_indtyp->criticality = Criticality_reject; ies_indtyp->id = ProtocolIE_ID_id_RICindicationType; @@ -404,7 +402,7 @@ bool E2APIndication::setfields(InitiatingMessage_t *initMsg){ *rictype_ie = _indicationIEs->get_ricIndicationType(); ASN_SEQUENCE_ADD(&(ric_indication->protocolIEs), &(IE_array[ie_index])); - ie_index = 5; + ie_index++; RICindication_IEs_t *ies_richead = &IE_array[ie_index]; ies_richead->criticality = Criticality_reject; ies_richead->id = ProtocolIE_ID_id_RICindicationHeader; @@ -414,7 +412,7 @@ bool E2APIndication::setfields(InitiatingMessage_t *initMsg){ richeader_ie->size = _indicationIEs->get_ricIndicationHeader_size(); ASN_SEQUENCE_ADD(&(ric_indication->protocolIEs), &(IE_array[ie_index])); - ie_index = 6; + ie_index++; RICindication_IEs_t *ies_indmsg = &IE_array[ie_index]; ies_indmsg->criticality = Criticality_reject; ies_indmsg->id = ProtocolIE_ID_id_RICindicationMessage; @@ -427,7 +425,7 @@ bool E2APIndication::setfields(InitiatingMessage_t *initMsg){ // optional call process id .. if (_indicationIEs->get_is_callProcessID()){ - ie_index = 7; + ie_index++; RICindication_IEs_t *ies_ind_callprocessid = &IE_array[ie_index]; ies_ind_callprocessid->criticality = Criticality_reject; ies_ind_callprocessid->id = ProtocolIE_ID_id_RICcallProcessID; diff --git a/src/xapp-asn/e2ap/e2ap_subscription_request.hpp b/src/xapp-asn/e2ap/e2ap_subscription_request.hpp index d7e618a..51eb209 100644 --- a/src/xapp-asn/e2ap/e2ap_subscription_request.hpp +++ b/src/xapp-asn/e2ap/e2ap_subscription_request.hpp @@ -17,10 +17,10 @@ ================================================================================== */ /* - * e2ap_subscription.hpp + * e2ap_subscription_request.hpp * * Created on: Jun 30, 2020 - * Author: sjana + * Author: Shraboni Jana */ #ifndef XAPP_ASN_REFACTOR_E2AP_SUBSCRIPTION_HPP_ @@ -63,8 +63,8 @@ public: class SubscriptionRequestIEs{ private: long int ricRequestorID, ricInstanceID, ranFunctionID; - size_t ricEventTriggerDefinition_size = E2SM_SIZE; - unsigned char ricEventTriggerDefinition[E2SM_SIZE]; + size_t ricEventTriggerDefinition_size = IE_SIZE; + unsigned char ricEventTriggerDefinition[IE_SIZE]; int ricAction_ToBeSetup_List_Count; std::vector::ActionIEs> *ricAction_ToBeSetup_List; @@ -112,7 +112,6 @@ public: SubscriptionRequestIEs& getIEs(){ return *_requestIEs.get();}; private: - unsigned int ricSubscriptionRequestIEs_Count; InitiatingMessage_t *initMsg; E2AP_PDU_t * e2ap_pdu_obj; RICsubscriptionRequest_IEs_t * IE_array; @@ -130,8 +129,6 @@ private: template E2APSubscriptionRequest::E2APSubscriptionRequest(SubscriptionRequestIEs &subRequestObj){ - ricSubscriptionRequestIEs_Count = 3; - _requestIEs = std::make_unique(); *_requestIEs = subRequestObj; @@ -145,10 +142,10 @@ E2APSubscriptionRequest::E2APSubscriptionRequest(SubscriptionRequestIEs & IE_array = 0; - if(this->ricSubscriptionRequestIEs_Count == 0) { + if(RIC_SUB_REQUEST_IES_COUNT == 0) { mdclog_write(MDCLOG_ERR, "E2AP Subscription Request IEs = 0."); } - IE_array = (RICsubscriptionRequest_IEs_t *)calloc(this->ricSubscriptionRequestIEs_Count, sizeof(RICsubscriptionRequest_IEs_t)); + IE_array = (RICsubscriptionRequest_IEs_t *)calloc(RIC_SUB_REQUEST_IES_COUNT, sizeof(RICsubscriptionRequest_IEs_t)); assert(IE_array != 0); @@ -282,7 +279,7 @@ bool E2APSubscriptionRequest::setfields( InitiatingMessage_t * init_msg){ result = ASN_SEQUENCE_ADD(&(ric_subscription->protocolIEs), &IE_array[ie_index]); assert(result == 0); - ie_index = 1; + ie_index++; RICsubscriptionRequest_IEs_t *ies_ranfunc = &IE_array[ie_index]; ies_ranfunc->criticality = Criticality_reject; ies_ranfunc->id = ProtocolIE_ID_id_RANfunctionID; @@ -293,7 +290,7 @@ bool E2APSubscriptionRequest::setfields( InitiatingMessage_t * init_msg){ assert(result == 0); - ie_index = 2; + ie_index++; RICsubscriptionRequest_IEs_t *ies_actid = &IE_array[ie_index]; ies_actid->criticality = Criticality_reject; ies_actid->id = ProtocolIE_ID_id_RICsubscriptionDetails; @@ -323,15 +320,17 @@ bool E2APSubscriptionRequest::setfields( InitiatingMessage_t * init_msg){ action_array[i].value.choice.RICaction_ToBeSetup_Item.ricSubsequentAction->ricSubsequentActionType = (*ref_action_array)[i].get_ricSubsequentActionType(); action_array[i].value.choice.RICaction_ToBeSetup_Item.ricSubsequentAction->ricTimeToWait = (*ref_action_array)[i].get_ricTimeToWait(); } - action_array[i].value.choice.RICaction_ToBeSetup_Item.ricActionDefinition = (RICactionDefinition_t*)calloc(1, sizeof(RICactionDefinition_t)); - auto actionSize = (*ref_action_array)[i].get_ricActionDefinition_size(); - action_array[i].value.choice.RICaction_ToBeSetup_Item.ricActionDefinition->size = actionSize; - action_array[i].value.choice.RICaction_ToBeSetup_Item.ricActionDefinition->buf = (uint8_t *)calloc(1,actionSize); - memcpy(action_array[i].value.choice.RICaction_ToBeSetup_Item.ricActionDefinition->buf, (uint8_t*)(*ref_action_array)[i].get_ricActionDefinition(), actionSize); + if((*ref_action_array)[i].get_is_ricActionDefinition()){ + action_array[i].value.choice.RICaction_ToBeSetup_Item.ricActionDefinition = (RICactionDefinition_t*)calloc(1, sizeof(RICactionDefinition_t)); - action_array[i].value.choice.RICaction_ToBeSetup_Item.ricActionDefinition->size = actionSize; + auto actionSize = (*ref_action_array)[i].get_ricActionDefinition_size(); + action_array[i].value.choice.RICaction_ToBeSetup_Item.ricActionDefinition->size = actionSize; + action_array[i].value.choice.RICaction_ToBeSetup_Item.ricActionDefinition->buf = (uint8_t *)calloc(1,actionSize); + memcpy(action_array[i].value.choice.RICaction_ToBeSetup_Item.ricActionDefinition->buf, (uint8_t*)(*ref_action_array)[i].get_ricActionDefinition(), actionSize); + action_array[i].value.choice.RICaction_ToBeSetup_Item.ricActionDefinition->size = actionSize; + } result = ASN_SEQUENCE_ADD(&ricsubscription_ie->ricAction_ToBeSetup_List, &(action_array[i])); if (result == -1){ diff --git a/src/xapp-asn/e2ap/e2ap_subsdel_request.cc b/src/xapp-asn/e2ap/e2ap_subsdel_request.cc new file mode 100644 index 0000000..fa40ce9 --- /dev/null +++ b/src/xapp-asn/e2ap/e2ap_subsdel_request.cc @@ -0,0 +1,148 @@ + + +/* +================================================================================== + Copyright (c) 2019-2020 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. +================================================================================== +*/ +/* + * e2ap_subsdel_request.cc + * + * Author: SJana, Ashwin Sridharan + */ + + +#include "e2ap_subsdel_request.hpp" + +E2APSubscriptionDeleteRequest::E2APSubscriptionDeleteRequest(SubscriptionDeleteRequestIEs& ieObj){ + + + + _requestIEs = std::make_unique(); + *_requestIEs = ieObj; + + e2ap_pdu_obj = (E2AP_PDU_t * )calloc(1, sizeof(E2AP_PDU_t)); + assert(e2ap_pdu_obj != 0); + + initMsg = (InitiatingMessage_t * )calloc(1, sizeof(InitiatingMessage_t)); + assert(initMsg != 0); + + IE_array = (RICsubscriptionDeleteRequest_IEs_t *)calloc(RIC_SUBDEL_REQUEST_IES_COUNT, sizeof(RICsubscriptionDeleteRequest_IEs_t)); + assert(IE_array != 0); + + RICsubscriptionDeleteRequest_t * subDelrequest = &(initMsg->value.choice.RICsubscriptionDeleteRequest); + for(int i = 0; i < RIC_SUBDEL_REQUEST_IES_COUNT; i++){ + ASN_SEQUENCE_ADD(&subDelrequest->protocolIEs, &(IE_array[i])); + } + +}; + + + +// Clear assigned protocolIE list from RIC indication IE container +E2APSubscriptionDeleteRequest::~E2APSubscriptionDeleteRequest(void){ + + mdclog_write(MDCLOG_DEBUG, "Freeing subscription delete request object memory"); + RICsubscriptionDeleteRequest_t * E2APSubscriptionDeleteRequest = &(initMsg->value.choice.RICsubscriptionDeleteRequest); + + for(int i = 0; i < E2APSubscriptionDeleteRequest->protocolIEs.list.size; i++){ + E2APSubscriptionDeleteRequest->protocolIEs.list.array[i] = 0; + } + + if (E2APSubscriptionDeleteRequest->protocolIEs.list.size > 0){ + free(E2APSubscriptionDeleteRequest->protocolIEs.list.array); + E2APSubscriptionDeleteRequest->protocolIEs.list.count = 0; + E2APSubscriptionDeleteRequest->protocolIEs.list.size = 0; + E2APSubscriptionDeleteRequest->protocolIEs.list.array = 0; + } + + free(IE_array); + free(initMsg); + e2ap_pdu_obj->choice.initiatingMessage = 0; + + ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, e2ap_pdu_obj); + mdclog_write(MDCLOG_DEBUG, "Freed subscription delete request object memory"); + + +}; + + +bool E2APSubscriptionDeleteRequest::encode(unsigned char *buf, size_t *size){ + + e2ap_pdu_obj->choice.initiatingMessage = initMsg; + e2ap_pdu_obj->present = E2AP_PDU_PR_initiatingMessage; + setfields( initMsg); + + initMsg->procedureCode = ProcedureCode_id_RICsubscriptionDelete; + initMsg->criticality = Criticality_reject; + initMsg->value.present = InitiatingMessage__value_PR_RICsubscriptionDeleteRequest; + + xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2ap_pdu_obj); + + int ret_constr = asn_check_constraints(&asn_DEF_E2AP_PDU, (void *) e2ap_pdu_obj, _errbuf, &_errbuf_len); + if(ret_constr){ + _error_string.assign(_errbuf, _errbuf_len); + _error_string = "Constraints failed for encoding subscription delete request. Reason = " + _error_string; + return false; + } + + asn_enc_rval_t res = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, e2ap_pdu_obj, buf, *size); + + if(res.encoded == -1){ + _error_string.assign(strerror(errno)); + _error_string = "Error encoding Subscription Delete Request. Reason = " + _error_string; + return false; + } + else { + if(*size < res.encoded){ + std::stringstream ss; + ss <<"Error encoding Subscription Delete Request . Reason = encoded pdu size " << res.encoded << " exceeds buffer size " << *size << std::endl; + _error_string = ss.str(); + res.encoded = -1; + return false; + } + } + + *size = res.encoded; + return true; + +} + + +bool E2APSubscriptionDeleteRequest::setfields( InitiatingMessage_t *initMsg){ + unsigned int ie_index; + + ie_index = 0; + RICsubscriptionDeleteRequest_IEs_t *ies_ricreq = &IE_array[ie_index]; + ies_ricreq->criticality = Criticality_reject; + ies_ricreq->id = ProtocolIE_ID_id_RICrequestID; + ies_ricreq->value.present = RICsubscriptionDeleteRequest_IEs__value_PR_RICrequestID; + RICrequestID_t *ricrequest_ie = &ies_ricreq->value.choice.RICrequestID; + ricrequest_ie->ricRequestorID = this->getIEs().get_ricRequestorID(); + ricrequest_ie->ricInstanceID = this->getIEs().get_ricInstanceID(); + + + ie_index = 1; + RICsubscriptionDeleteRequest_IEs_t *ies_ranfunc = &IE_array[ie_index]; + ies_ranfunc->criticality = Criticality_reject; + ies_ranfunc->id = ProtocolIE_ID_id_RANfunctionID; + ies_ranfunc->value.present = RICsubscriptionDeleteRequest_IEs__value_PR_RANfunctionID; + RANfunctionID_t *ranfunction_ie = &ies_ranfunc->value.choice.RANfunctionID; + *ranfunction_ie = this->getIEs().get_ranFunctionID(); + + + return true; +}; + diff --git a/src/xapp-asn/e2ap/e2ap_subsdel_request.hpp b/src/xapp-asn/e2ap/e2ap_subsdel_request.hpp new file mode 100644 index 0000000..9243403 --- /dev/null +++ b/src/xapp-asn/e2ap/e2ap_subsdel_request.hpp @@ -0,0 +1,99 @@ +/* +================================================================================== + + Copyright (c) 2019-2020 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. +================================================================================== +*/ +/* + * e2ap_subsdel_request.hpp + * + * Created on: Oct 23, 2020 + * Author: Shraboni Jana + */ + +/*-- ************************************************************** +-- +-- RIC SUBSCRIPTION DELETE REQUEST +-- +-- ************************************************************** +RICsubscriptionDeleteRequest ::= SEQUENCE { + protocolIEs ProtocolIE-Container {{RICsubscriptionDeleteRequest-IEs}}, + ... +} + +RICsubscriptionDeleteRequest-IEs E2AP-PROTOCOL-IES ::= { + { ID id-RICrequestID CRITICALITY reject TYPE RICrequestID PRESENCE mandatory }| + { ID id-RANfunctionID CRITICALITY reject TYPE RANfunctionID PRESENCE mandatory }, + ... +}*/ +#ifndef SRC_XAPP_ASN_E2AP_E2AP_SUBSDEL_REQUEST_HPP_ +#define SRC_XAPP_ASN_E2AP_E2AP_SUBSDEL_REQUEST_HPP_ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "e2ap_consts.hpp" +class E2APSubscriptionDeleteRequest { +public: + + class SubscriptionDeleteRequestIEs{ + private: + long int ricRequestorID, ricInstanceID, ranFunctionID; + + public: + SubscriptionDeleteRequestIEs(void):ricRequestorID(0), ricInstanceID(0),ranFunctionID(0){}; + SubscriptionDeleteRequestIEs& set_ricRequestorID(long int req_id){ricRequestorID = req_id; return *this;}; + SubscriptionDeleteRequestIEs& set_ranFunctionID(long int func_id){ranFunctionID = func_id; return *this;}; + SubscriptionDeleteRequestIEs& set_ricInstanceID(long int inst_id){ricInstanceID = inst_id; return *this;}; + + long int get_ricInstanceID(){return this->ricInstanceID;}; + long int get_ricRequestorID(){return this->ricRequestorID;}; + long int get_ranFunctionID(){return this->ranFunctionID;}; + + + }; + + E2APSubscriptionDeleteRequest(SubscriptionDeleteRequestIEs&); + ~E2APSubscriptionDeleteRequest(); + bool encode(unsigned char *, size_t * ); + std::string get_error (void) const {return _error_string ;}; + SubscriptionDeleteRequestIEs& getIEs(){ return *_requestIEs.get();}; +private: + + InitiatingMessage_t *initMsg; + E2AP_PDU_t * e2ap_pdu_obj; + RICsubscriptionDeleteRequest_IEs_t * IE_array; + + std::unique_ptr _requestIEs; + std::string _error_string; + char _errbuf[128]; + size_t _errbuf_len = 128; + + bool setfields(InitiatingMessage_t *); + +}; + + + + +#endif /* SRC_XAPP_ASN_E2AP_E2AP_SUBSDEL_REQUEST_HPP_ */ diff --git a/src/xapp-asn/e2sm/e2sm_control.cc b/src/xapp-asn/e2sm/e2sm_control.cc index 7e1be7d..ce74f98 100644 --- a/src/xapp-asn/e2sm/e2sm_control.cc +++ b/src/xapp-asn/e2sm/e2sm_control.cc @@ -17,7 +17,7 @@ ================================================================================== */ /* - * HWControlMessage.cc + * e2sm_control.cc * * Created on: Apr, 2020 * Author: Shraboni Jana diff --git a/src/xapp-asn/e2sm/e2sm_control.hpp b/src/xapp-asn/e2sm/e2sm_control.hpp index a93064e..ee8c7c6 100644 --- a/src/xapp-asn/e2sm/e2sm_control.hpp +++ b/src/xapp-asn/e2sm/e2sm_control.hpp @@ -17,7 +17,7 @@ ================================================================================== */ /* - * e2sm_indication.hpp + * e2sm_control.hpp * * Created on: Apr, 2020 * Author: Shraboni Jana diff --git a/src/xapp-asn/e2sm/e2sm_indication.cc b/src/xapp-asn/e2sm/e2sm_indication.cc index 1201068..286c62e 100644 --- a/src/xapp-asn/e2sm/e2sm_indication.cc +++ b/src/xapp-asn/e2sm/e2sm_indication.cc @@ -17,7 +17,7 @@ ================================================================================== */ /* - * HWIndicationMessage.cc + * e2sm_indication.cc * * Created on: Apr, 2020 * Author: Shraboni Jana diff --git a/src/xapp-asn/e2sm/e2sm_subscription.cc b/src/xapp-asn/e2sm/e2sm_subscription.cc index 1739b04..7f575a1 100644 --- a/src/xapp-asn/e2sm/e2sm_subscription.cc +++ b/src/xapp-asn/e2sm/e2sm_subscription.cc @@ -20,7 +20,7 @@ * e2sm_subscription.cc * * Created on: Jun 30, 2020 - * Author: sjana + * Author: Shraboni Jana */ #include "e2sm_subscription.hpp" diff --git a/src/xapp-asn/e2sm/e2sm_subscription.hpp b/src/xapp-asn/e2sm/e2sm_subscription.hpp index 8e56c73..a03eb30 100644 --- a/src/xapp-asn/e2sm/e2sm_subscription.hpp +++ b/src/xapp-asn/e2sm/e2sm_subscription.hpp @@ -20,7 +20,7 @@ * e2sm_subscription.hpp * * Created on: Jun 30, 2020 - * Author: sjana + * Author: Shraboni Jana */ #ifndef XAPP_ASN_REFACTOR_E2SM_SUBSCRIPTION_HPP_ diff --git a/test/test_e2ap.h b/test/test_e2ap.h new file mode 100644 index 0000000..427d840 --- /dev/null +++ b/test/test_e2ap.h @@ -0,0 +1,168 @@ +/* +================================================================================== + + Copyright (c) 2019-2020 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. +================================================================================== +*/ +/* + * test_e2ap.h + * + * Created on: Oct 23, 2020 + * Author: Shraboni Jana + */ + +#ifndef TEST_TEST_E2AP_H_ +#define TEST_TEST_E2AP_H_ +#include +#include + +#include "e2ap_control_failure.hpp" +#include "xapp.hpp" +#include "e2ap_control_ack.hpp" +TEST(E2AP, ControlAcknowledgementEncode) +{ + + unsigned char buff[1024]; + size_t buf_len = 1024; + + E2APControlAcknowledge::ControlAcknowledgeIEs infoObj; + infoObj.set_ranFunctionID(1); + infoObj.set_ricRequestorID(1); + infoObj.set_ricInstanceID(1); + infoObj.set_ricControlStatus(1); + infoObj.set_ricCallProcessID("CallProcessID"); + infoObj.set_ricControlOutcome("ControlOutcome"); + + + E2APControlAcknowledge cntrlObj(infoObj); + + bool res = cntrlObj.encode(buff, &buf_len); + if(!res) + { + std::cout << cntrlObj.get_error() << std::endl; + } + ASSERT_TRUE(res); + FILE * pFile; + pFile = fopen ("controlack1.per","w"); + if (pFile!=NULL) + { + fwrite (buff , sizeof(char), buf_len, pFile); + sleep(2); + fclose (pFile); + } + +} +TEST(E2SM, ControlAcknowledgementDecode) +{ + unsigned char e2ap_buff[4096]; + char filename[100] = "controlack1.per"; + FILE *fp; + fp = fopen(filename,"rb"); + if(!fp) { + perror(filename); + exit(1); } + + size_t e2ap_buff_size = fread(e2ap_buff, 1, 4096, fp); + fclose(fp); + if(!e2ap_buff_size){ + fprintf(stderr, "%s: Empty or broken\n", filename); + exit(1); + } else { + fprintf(stderr, "e2ap buffer size: %ld \n", e2ap_buff_size); + } + + bool decode_status = true; + try{ + E2APControlAcknowledge e2obj(&e2ap_buff[0],&e2ap_buff_size); + + + } catch(const char* e){ + decode_status = false; + std::cout << "Error Message: " << e << std::endl; + } + + + ASSERT_TRUE(decode_status); + +} +TEST(E2AP, ControlFailureEncode) +{ + + unsigned char buff[1024]; + size_t buf_len = 1024; + + E2APControlFailure::ControlFailureIEs infoObj; + infoObj.set_ranFunctionID(1); + infoObj.set_ricRequestorID(1); + infoObj.set_ricInstanceID(1); + infoObj.set_ricCause(1); + infoObj.set_ricSubCause(1); + infoObj.set_ricCallProcessID("CallProcessID"); + infoObj.set_ricControlOutcome("ControlOutcome"); + + + E2APControlFailure cntrlObj(infoObj); + + bool res = cntrlObj.encode(buff, &buf_len); + if(!res) + { + std::cout << cntrlObj.get_error() << std::endl; + } + ASSERT_TRUE(res); + FILE * pFile; + pFile = fopen ("controlfail1.per","w"); + if (pFile!=NULL) + { + fwrite (buff , sizeof(char), buf_len, pFile); + sleep(2); + fclose (pFile); + } + +} +TEST(E2SM, ControlFailureDecode) +{ + unsigned char e2ap_buff[1024]; + char filename[100] = "controlfail1.per"; + FILE *fp; + fp = fopen(filename,"rb"); + if(!fp) { + perror(filename); + exit(1); } + + size_t e2ap_buff_size = fread(e2ap_buff, 1, 1024, fp); + fclose(fp); + if(!e2ap_buff_size){ + fprintf(stderr, "%s: Empty or broken\n", filename); + exit(1); + } else { + fprintf(stderr, "e2ap buffer size: %ld \n", e2ap_buff_size); + } + + bool decode_status = true; + try{ + E2APControlFailure e2obj(&e2ap_buff[0],&e2ap_buff_size); + + + } catch(const char* e){ + decode_status = false; + std::cout << "Error Message: " << e << std::endl; + } + + + ASSERT_TRUE(decode_status); + +} + +#endif /* TEST_TEST_E2AP_H_ */ diff --git a/test/test_e2sm.h b/test/test_e2sm.h index 82b0bfb..a973df2 100644 --- a/test/test_e2sm.h +++ b/test/test_e2sm.h @@ -16,7 +16,7 @@ limitations under the License. ================================================================================== /* - * test_asn.h + * test_e2sm.h * * Created on: Apr, 2020 * Author: Shraboni Jana @@ -27,11 +27,11 @@ #include #include +#include "e2ap_control_request.hpp" #include "xapp.hpp" #include "e2sm_control.hpp" #include "e2ap_indication.hpp" #include "e2sm_indication.hpp" -#include "e2ap_control.hpp" using namespace std; TEST(E2SM, IndicationMessageEncode) @@ -58,18 +58,19 @@ TEST(E2SM, IndicationMessageEncode) E2APIndication e2obj(infoObj); bool res = e2obj.encode(buff, &buf_len); - if(!res) - { - std::cout << e2obj.get_error() << std::endl; - } - ASSERT_TRUE(res); + if(!res) + { + std::cout << e2obj.get_error() << std::endl; + } + ASSERT_TRUE(res); FILE * pFile; pFile = fopen ("indication2.per","w"); if (pFile!=NULL) { - fputs ((const char*)buff,pFile); + fwrite (buff , sizeof(char), buf_len, pFile); + sleep(2); fclose (pFile); } @@ -136,7 +137,7 @@ TEST(E2SM, ControlMessage) infoObj.set_ricRequestorID(1); infoObj.set_ricControlHeader(headObj); infoObj.set_ricControlMessage(msgObj); - + infoObj.set_ricCallProcessID("ProcessID"); E2APControlMessage cntrlObj(infoObj); diff --git a/test/test_subs.h b/test/test_subs.h index e50a473..ea540bf 100644 --- a/test/test_subs.h +++ b/test/test_subs.h @@ -16,11 +16,21 @@ limitations under the License. ================================================================================== */ +/* + * test_subs.h + * + * Created on: Apr, 2020 + * Author: Shraboni Jana + */ + #ifndef TEST_TEST_SUBS_H_ #define TEST_TEST_SUBS_H_ #include #include + +#include "e2ap_subscription_request.hpp" +#include "e2ap_subsdel_request.hpp" #include "xapp.hpp" #define BUFFER_SIZE 1024 @@ -152,7 +162,33 @@ TEST(SubscriptionRequest, MultipleActions) } +TEST(E2AP, SubscriptionDeleteRequest){ + + unsigned char buff[1024]; + size_t buff_size = 1024; + + + E2APSubscriptionDeleteRequest::SubscriptionDeleteRequestIEs dataObj; + + dataObj.set_ranFunctionID(1); + dataObj.set_ricInstanceID(1); + dataObj.set_ricRequestorID(3); + + E2APSubscriptionDeleteRequest requestObj(dataObj); + bool res = requestObj.encode(buff, &buff_size); + if(!res) + { + std::cout << requestObj.get_error() << std::endl; + } + ASSERT_TRUE(res); + + +} + + + //create a MOck e2term + TEST (MOCK, E2TERM){ const char* meid = "test1"; @@ -185,4 +221,5 @@ TEST (MOCK, E2TERM){ } } + #endif /* TEST_TEST_SUBS_H_ */ -- 2.16.6