/*****************************************************************************\r
# *\r
# Copyright 2020 AT&T Intellectual Property *\r
+# Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved. *\r
# *\r
# Licensed under the Apache License, Version 2.0 (the "License"); *\r
# you may not use this file except in compliance with the License. *\r
LOG_I("[E2AP] Received RIC-SUBSCRIPTION-REQUEST");\r
// e2ap_handle_RICSubscriptionRequest(pdu, socket_fd);\r
long func_id = encoding::get_function_id_from_subscription(pdu);\r
- SubscriptionCallback cb = e2sim->get_subscription_callback(func_id);\r
- cb(pdu);\r
+ fprintf(stderr, "Function Id of message is %d\n", func_id);\r
+ SubscriptionCallback cb;\r
+\r
+ bool func_exists = true;\r
+\r
+ try {\r
+ cb = e2sim->get_subscription_callback(func_id);\r
+ } catch(const std::out_of_range& e) {\r
+ func_exists = false;\r
+ }\r
+\r
+ if (func_exists) {\r
+ fprintf(stderr, "Calling callback function\n");\r
+ cb(pdu);\r
+ } else {\r
+ fprintf(stderr, "Error: No RAN Function with this ID exists\n");\r
+ }\r
// callback_kpm_subscription_request(pdu, socket_fd);\r
\r
}\r
break;\r
}\r
break;\r
- \r
+\r
+ case ProcedureCode_id_RICserviceQuery:\r
+ switch (index)\r
+ {\r
+ case E2AP_PDU_PR_initiatingMessage:\r
+ LOG_I("[E2AP] Received RIC-Service-Query")\r
+ e2ap_handle_E2SeviceRequest(pdu, socket_fd, e2sim);\r
+ break;\r
+\r
+ default:\r
+ LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU %d", index,\r
+ (int)ProcedureCode_id_RICserviceQuery);\r
+ break;\r
+ }\r
+ break;\r
+\r
+ case ProcedureCode_id_RICserviceUpdate:\r
+ switch (index)\r
+ {\r
+ case E2AP_PDU_PR_successfulOutcome:\r
+ LOG_I("[E2AP] Received RIC-SERVICE-UPDATE-SUCCESS")\r
+ break;\r
+\r
+ case E2AP_PDU_PR_unsuccessfulOutcome:\r
+ LOG_I("[E2AP] Received RIC-SERVICE-UPDATE-FAILURE")\r
+ break;\r
+\r
+ default:\r
+ LOG_E("[E2AP] Invalid message index=%d in E2AP-PDU %d", index,\r
+ (int)ProcedureCode_id_RICserviceUpdate);\r
+ break;\r
+ }\r
+ break;\r
+ \r
default:\r
\r
LOG_E("[E2AP] No available handler for procedureCode=%d", procedureCode);\r
}\r
}\r
\r
+void e2ap_handle_E2SeviceRequest(E2AP_PDU_t* pdu, int &socket_fd, E2Sim *e2sim) {\r
+\r
+ auto buffer_size = MAX_SCTP_BUFFER;\r
+ unsigned char buffer[MAX_SCTP_BUFFER];\r
+ E2AP_PDU_t* res_pdu = (E2AP_PDU_t*)calloc(1,sizeof(E2AP_PDU));\r
+\r
+ // prepare ran function defination\r
+ std::vector<encoding::ran_func_info> all_funcs;\r
+\r
+ //Loop through RAN function definitions that are registered\r
+\r
+ for (std::pair<long, OCTET_STRING_t*> elem : e2sim->getRegistered_ran_functions()) {\r
+ printf("looping through ran func\n");\r
+ encoding::ran_func_info next_func;\r
+\r
+ next_func.ranFunctionId = elem.first;\r
+ next_func.ranFunctionDesc = elem.second;\r
+ next_func.ranFunctionRev = (long)3;\r
+ all_funcs.push_back(next_func);\r
+ }\r
+ \r
+ printf("about to call service update encode\n");\r
+\r
+ encoding::generate_e2apv1_service_update(res_pdu, all_funcs);\r
+\r
+ LOG_D("[E2AP] Created E2-SERVICE-UPDATE");\r
+\r
+ e2ap_asn1c_print_pdu(res_pdu);\r
+\r
+ sctp_buffer_t data;\r
+\r
+ char *error_buf = (char*)calloc(300, sizeof(char));\r
+ size_t errlen;\r
+\r
+ asn_check_constraints(&asn_DEF_E2AP_PDU, res_pdu, error_buf, &errlen);\r
+ printf("error length %d\n", errlen);\r
+ printf("error buf %s\n", error_buf);\r
+\r
+ auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, res_pdu, buffer, buffer_size);\r
+\r
+ data.len = er.encoded;\r
+ fprintf(stderr, "er encoded is %d\n", er.encoded);\r
+\r
+ memcpy(data.buffer, buffer, er.encoded);\r
+\r
+ //send response data over sctp\r
+ if(sctp_send_data(socket_fd, data) > 0) {\r
+ LOG_I("[SCTP] Sent E2-SERVICE-UPDATE");\r
+ } else {\r
+ LOG_E("[SCTP] Unable to send E2-SERVICE-UPDATE to peer");\r
+ }\r
+}\r
+\r
void e2ap_handle_E2SetupRequest(E2AP_PDU_t* pdu, int &socket_fd) {\r
\r
\r