From 4b7683efa5ee46870e550ee6fa55f765a0a1f70c Mon Sep 17 00:00:00 2001 From: subhash kumar singh Date: Wed, 7 Oct 2020 01:28:58 +0530 Subject: [PATCH] Support for service update E2 Message Implement support for E2 service update message. Issue-ID: SIM-43 Signed-off-by: subhash kumar singh Change-Id: Ifc3e3e0cf0638c36efc2edb98afc51e4392b3abc --- e2sim/src/base/e2sim.cpp | 5 ++ e2sim/src/base/e2sim.hpp | 3 + e2sim/src/encoding/encode_e2apv1.cpp | 61 ++++++++++++++++ e2sim/src/encoding/encode_e2apv1.hpp | 2 + e2sim/src/messagerouting/e2ap_message_handler.cpp | 89 ++++++++++++++++++++++- e2sim/src/messagerouting/e2ap_message_handler.hpp | 3 + 6 files changed, 162 insertions(+), 1 deletion(-) diff --git a/e2sim/src/base/e2sim.cpp b/e2sim/src/base/e2sim.cpp index fa62bed..372cc9d 100644 --- a/e2sim/src/base/e2sim.cpp +++ b/e2sim/src/base/e2sim.cpp @@ -1,6 +1,7 @@ /***************************************************************************** # * # Copyright 2020 AT&T Intellectual Property * +# Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved. * # * # Licensed under the Apache License, Version 2.0 (the "License"); * # you may not use this file except in compliance with the License. * @@ -33,6 +34,10 @@ using namespace std; int client_fd = 0; +std::unordered_map E2Sim::getRegistered_ran_functions() { + return ran_functions_registered; +} + void E2Sim::register_subscription_callback(long func_id, SubscriptionCallback cb) { fprintf(stderr,"%%%%about to register callback for subscription for func_id %d\n", func_id); subscription_callbacks[func_id] = cb; diff --git a/e2sim/src/base/e2sim.hpp b/e2sim/src/base/e2sim.hpp index 16015ea..eace5a8 100644 --- a/e2sim/src/base/e2sim.hpp +++ b/e2sim/src/base/e2sim.hpp @@ -1,6 +1,7 @@ /***************************************************************************** # * # Copyright 2020 AT&T Intellectual Property * +# Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved. * # * # Licensed under the Apache License, Version 2.0 (the "License"); * # you may not use this file except in compliance with the License. * @@ -40,6 +41,8 @@ private: public: + std::unordered_map getRegistered_ran_functions(); + void generate_e2apv1_subscription_response_success(E2AP_PDU *e2ap_pdu, long reqActionIdsAccepted[], long reqActionIdsRejected[], int accept_size, int reject_size, long reqRequestorId, long reqInstanceId); void generate_e2apv1_indication_request_parameterized(E2AP_PDU *e2ap_pdu, long requestorId, long instanceId, long ranFunctionId, long actionId, long seqNum, uint8_t *ind_header_buf, int header_length, uint8_t *ind_message_buf, int message_length); diff --git a/e2sim/src/encoding/encode_e2apv1.cpp b/e2sim/src/encoding/encode_e2apv1.cpp index d1c2c06..6f8c589 100644 --- a/e2sim/src/encoding/encode_e2apv1.cpp +++ b/e2sim/src/encoding/encode_e2apv1.cpp @@ -3,6 +3,7 @@ /***************************************************************************** # * # Copyright 2020 AT&T Intellectual Property * +# Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved. * # * # Licensed under the Apache License, Version 2.0 (the "License"); * # you may not use this file except in compliance with the License. * @@ -95,6 +96,66 @@ long encoding::get_function_id_from_subscription(E2AP_PDU_t *e2ap_pdu) { } +void encoding::generate_e2apv1_service_update(E2AP_PDU_t *e2ap_pdu, std::vector all_funcs) { + char* ran_function_op_type = getenv("RAN_FUNCTION_OP_TYPE"); + LOG_D("Ran funciton : %s", ran_function_op_type); + ProtocolIE_ID_t prID; + if (ran_function_op_type != NULL) + { + if (strcmp(ran_function_op_type, "ADD") == 0) + { + prID = ProtocolIE_ID_id_RANfunctionsAdded; + } + else if (strcmp(ran_function_op_type, "DELETE")) + { + prID = ProtocolIE_ID_id_RANfunctionsDeleted; + } + } + else + { + prID = ProtocolIE_ID_id_RANfunctionsModified; + } + + + RICserviceUpdate_IEs_t *e2serviceUpdateList = (RICserviceUpdate_IEs_t *)calloc(1, sizeof(RICserviceUpdate_IEs_t)); + e2serviceUpdateList->id = prID; + e2serviceUpdateList->criticality = Criticality_reject; + e2serviceUpdateList->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List; + + + for (int i=0; iid = ProtocolIE_ID_id_RANfunction_Item; + itemIes->criticality = Criticality_reject; + itemIes->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item; + itemIes->value.choice.RANfunction_Item.ranFunctionID = 1; + + itemIes->value.choice.RANfunction_Item.ranFunctionDefinition = *nextRanFuncDesc; + itemIes->value.choice.RANfunction_Item.ranFunctionRevision = nextRanFuncRev + 1; + + ASN_SEQUENCE_ADD(&e2serviceUpdateList->value.choice.RANfunctions_List.list, itemIes); + } + + RICserviceUpdate_t *ricServiceUpdate = (RICserviceUpdate_t *)calloc(1, sizeof(RICserviceUpdate_t)); + ASN_SEQUENCE_ADD(&ricServiceUpdate->protocolIEs.list, e2serviceUpdateList); + + InitiatingMessage_t *initiatingMessage = (InitiatingMessage_t *)calloc(1, sizeof(InitiatingMessage_t)); + initiatingMessage->criticality = Criticality_reject; + initiatingMessage->procedureCode = ProcedureCode_id_RICserviceUpdate; + initiatingMessage->value.present = InitiatingMessage__value_PR_RICserviceUpdate; + initiatingMessage->value.choice.RICserviceUpdate = *ricServiceUpdate; + + E2AP_PDU_PR pres6 = E2AP_PDU_PR_initiatingMessage; + e2ap_pdu->present = pres6; + e2ap_pdu->choice.initiatingMessage = initiatingMessage; +} + void encoding::generate_e2apv1_setup_request_parameterized(E2AP_PDU_t *e2ap_pdu, std::vector all_funcs) { // long ranFunctionId, uint8_t *ranFuncDescEncoded, int ranFuncLength) { diff --git a/e2sim/src/encoding/encode_e2apv1.hpp b/e2sim/src/encoding/encode_e2apv1.hpp index b7747d4..6bbbe56 100644 --- a/e2sim/src/encoding/encode_e2apv1.hpp +++ b/e2sim/src/encoding/encode_e2apv1.hpp @@ -2,6 +2,7 @@ /***************************************************************************** # * # Copyright 2020 AT&T Intellectual Property * +# Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved. * # * # Licensed under the Apache License, Version 2.0 (the "License"); * # you may not use this file except in compliance with the License. * @@ -54,6 +55,7 @@ namespace encoding { void generate_e2apv1_indication_request_parameterized(E2AP_PDU *e2ap_pdu, long requestorId, long instanceId, long ranFunctionId, long actionId, long seqNum, uint8_t *ind_header_buf, int header_length, uint8_t *ind_message_buf, int message_length); + void generate_e2apv1_service_update(E2AP_PDU_t *e2ap_pdu, std::vector all_funcs); } #endif diff --git a/e2sim/src/messagerouting/e2ap_message_handler.cpp b/e2sim/src/messagerouting/e2ap_message_handler.cpp index 0e23c8d..3ecc2f0 100644 --- a/e2sim/src/messagerouting/e2ap_message_handler.cpp +++ b/e2sim/src/messagerouting/e2ap_message_handler.cpp @@ -3,6 +3,7 @@ /***************************************************************************** # * # Copyright 2020 AT&T Intellectual Property * +# Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved. * # * # Licensed under the Apache License, Version 2.0 (the "License"); * # you may not use this file except in compliance with the License. * @@ -172,7 +173,40 @@ void e2ap_handle_sctp_data(int &socket_fd, sctp_buffer_t &data, bool xmlenc, E2S break; } break; - + + case ProcedureCode_id_RICserviceQuery: + switch (index) + { + case E2AP_PDU_PR_initiatingMessage: + LOG_I("[E2AP] Received RIC-Service-Query") + e2ap_handle_E2SeviceRequest(pdu, socket_fd, e2sim); + break; + + default: + LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU %d", index, + (int)ProcedureCode_id_RICserviceQuery); + break; + } + break; + + case ProcedureCode_id_RICserviceUpdate: + switch (index) + { + case E2AP_PDU_PR_successfulOutcome: + LOG_I("[E2AP] Received RIC-SERVICE-UPDATE-SUCCESS") + break; + + case E2AP_PDU_PR_unsuccessfulOutcome: + LOG_I("[E2AP] Received RIC-SERVICE-UPDATE-FAILURE") + break; + + default: + LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU %d", index, + (int)ProcedureCode_id_RICserviceUpdate); + break; + } + break; + default: LOG_E("[E2AP] No available handler for procedureCode=%d", procedureCode); @@ -181,6 +215,59 @@ void e2ap_handle_sctp_data(int &socket_fd, sctp_buffer_t &data, bool xmlenc, E2S } } +void e2ap_handle_E2SeviceRequest(E2AP_PDU_t* pdu, int &socket_fd, E2Sim *e2sim) { + + auto buffer_size = MAX_SCTP_BUFFER; + unsigned char buffer[MAX_SCTP_BUFFER]; + E2AP_PDU_t* res_pdu = (E2AP_PDU_t*)calloc(1,sizeof(E2AP_PDU)); + + // prepare ran function defination + std::vector all_funcs; + + //Loop through RAN function definitions that are registered + + for (std::pair elem : e2sim->getRegistered_ran_functions()) { + printf("looping through ran func\n"); + encoding::ran_func_info next_func; + + next_func.ranFunctionId = elem.first; + next_func.ranFunctionDesc = elem.second; + next_func.ranFunctionRev = (long)3; + all_funcs.push_back(next_func); + } + + printf("about to call service update encode\n"); + + encoding::generate_e2apv1_service_update(res_pdu, all_funcs); + + LOG_D("[E2AP] Created E2-SERVICE-UPDATE"); + + e2ap_asn1c_print_pdu(res_pdu); + + sctp_buffer_t data; + + char *error_buf = (char*)calloc(300, sizeof(char)); + size_t errlen; + + asn_check_constraints(&asn_DEF_E2AP_PDU, res_pdu, error_buf, &errlen); + printf("error length %d\n", errlen); + printf("error buf %s\n", error_buf); + + auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, res_pdu, buffer, buffer_size); + + data.len = er.encoded; + fprintf(stderr, "er encoded is %d\n", er.encoded); + + memcpy(data.buffer, buffer, er.encoded); + + //send response data over sctp + if(sctp_send_data(socket_fd, data) > 0) { + LOG_I("[SCTP] Sent E2-SERVICE-UPDATE"); + } else { + LOG_E("[SCTP] Unable to send E2-SERVICE-UPDATE to peer"); + } +} + void e2ap_handle_E2SetupRequest(E2AP_PDU_t* pdu, int &socket_fd) { diff --git a/e2sim/src/messagerouting/e2ap_message_handler.hpp b/e2sim/src/messagerouting/e2ap_message_handler.hpp index 5ec288b..f937745 100644 --- a/e2sim/src/messagerouting/e2ap_message_handler.hpp +++ b/e2sim/src/messagerouting/e2ap_message_handler.hpp @@ -2,6 +2,7 @@ # * # Copyright 2019 AT&T Intellectual Property * # Copyright 2019 Nokia * +# Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved. * # * # Licensed under the Apache License, Version 2.0 (the "License"); * # you may not use this file except in compliance with the License. * @@ -44,4 +45,6 @@ void e2ap_handle_RICSubscriptionRequest_securityDemo(E2AP_PDU_t* pdu, int &socke void e2ap_handle_ResourceStatusRequest(E2AP_PDU_t* pdu, int &socket_fd); +void e2ap_handle_E2SeviceRequest(E2AP_PDU_t* pdu, int &socket_fd, E2Sim *e2sim); + #endif -- 2.16.6