diff --git a/openair2/ENB_APP/enb_agent_common.c b/openair2/ENB_APP/enb_agent_common.c index 1e7efe920ac21405182c31d899f1c4ae5e156d65..f4f8c333d0cfac1f2f0e751eeb1f20dd4170db01 100644 --- a/openair2/ENB_APP/enb_agent_common.c +++ b/openair2/ENB_APP/enb_agent_common.c @@ -34,8 +34,12 @@ * \version 0.1 */ +#include<stdio.h> +#include <dlfcn.h> +#include <time.h> #include "enb_agent_common.h" +#include "enb_agent_extern.h" #include "PHY/extern.h" #include "log.h" @@ -703,6 +707,76 @@ int enb_agent_destroy_lc_config_request(Protocol__ProgranMessage *msg) { return 0; } +// call this function to start a nanosecond-resolution timer +struct timespec timer_start(){ + struct timespec start_time; + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time); + return start_time; +} + +// call this function to end a timer, returning nanoseconds elapsed as a long +long timer_end(struct timespec start_time){ + struct timespec end_time; + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_time); + long diffInNanos = end_time.tv_nsec - start_time.tv_nsec; + return diffInNanos; +} + +int enb_agent_control_delegation(mid_t mod_id, const void *params, Protocol__ProgranMessage **msg) { + + Protocol__ProgranMessage *input = (Protocol__ProgranMessage *)params; + Protocol__PrpControlDelegation *control_delegation_msg = input->control_delegation_msg; + + uint32_t delegation_type = control_delegation_msg->delegation_type; + + void *lib; + int i; + + struct timespec vartime = timer_start(); + + //Write the payload lib into a file in the cache and load the lib + char lib_name[120]; + char target[512]; + snprintf(lib_name, sizeof(lib_name), "/delegation_lib_%d.so", control_delegation_msg->header->xid); + strcpy(target, local_cache); + strcat(target, lib_name); + + FILE *f; + f = fopen(target, "wb"); + fwrite(control_delegation_msg->payload.data, control_delegation_msg->payload.len, 1, f); + fclose(f); + lib = dlopen(target, RTLD_NOW); + if (lib == NULL) { + goto error; + } + + i = 0; + //Check functions that need to be delegated + + //DL UE scheduler delegation + if (delegation_type & PROTOCOL__PRP_CONTROL_DELEGATION_TYPE__PRCDT_MAC_DL_UE_SCHEDULER) { + void *loaded_scheduler = dlsym(lib, control_delegation_msg->name[i]); + i++; + if (loaded_scheduler) { + if (mac_agent_registered[mod_id]) { + agent_mac_xface[mod_id]->enb_agent_schedule_ue_spec = loaded_scheduler; + LOG_D(ENB_APP,"Delegated control for DL UE scheduler successfully\n"); + } + } + } + long time_elapsed_nanos = timer_end(vartime); + LOG_I(ENB_AGENT, "DID IT IN %lld\n", time_elapsed_nanos); + *msg = NULL; + return 0; + + error: + return -1; +} + +int enb_agent_destroy_control_delegation(Protocol__ProgranMessage *msg) { + /*TODO: Dealocate memory for a dynamically allocated control delegation message*/ +} + /* * get generic info from RAN */ diff --git a/openair2/ENB_APP/enb_agent_common.h b/openair2/ENB_APP/enb_agent_common.h index 6a310944176d55f57b91d5dab4a1faa0404bdd1f..73ce0ec788400fd7624ac6f29ffbdb42ae3fb103 100644 --- a/openair2/ENB_APP/enb_agent_common.h +++ b/openair2/ENB_APP/enb_agent_common.h @@ -111,6 +111,9 @@ int enb_agent_destroy_lc_config_request(Protocol__ProgranMessage *msg); int enb_agent_ue_state_change(mid_t mod_id, uint32_t rnti, uint8_t state_change); int enb_agent_destroy_ue_state_change(Protocol__ProgranMessage *msg); +int enb_agent_control_delegation(mid_t mod_id, const void *params, Protocol__ProgranMessage **msg); +int enb_agent_destroy_control_delegation(Protocol__ProgranMessage *msg); + Protocol__ProgranMessage* enb_agent_handle_message (mid_t mod_id, uint8_t *data, uint32_t size); diff --git a/openair2/ENB_APP/enb_agent_defs.h b/openair2/ENB_APP/enb_agent_defs.h index 9d1e3f75fc37684d1c0e6e7bf2b487fc6c5f6034..8d71aa2db3ad53cd4effb4261f4844377806f3e6 100644 --- a/openair2/ENB_APP/enb_agent_defs.h +++ b/openair2/ENB_APP/enb_agent_defs.h @@ -47,7 +47,7 @@ #define NUM_MAX_UE 2048 #define DEFAULT_ENB_AGENT_IPv4_ADDRESS "127.0.0.1" #define DEFAULT_ENB_AGENT_PORT 2210 -#define DEFAULT_ENB_AGENT_CACHE "/mnt/tmpfs" +#define DEFAULT_ENB_AGENT_CACHE "/mnt/oai_agent_cache" typedef enum { diff --git a/openair2/ENB_APP/enb_agent_handler.c b/openair2/ENB_APP/enb_agent_handler.c index 2162a29314cea01880f50484f96992484b20a766..d4e5706b1100d7a2cc34d51f2e89d4f26f41fd26 100644 --- a/openair2/ENB_APP/enb_agent_handler.c +++ b/openair2/ENB_APP/enb_agent_handler.c @@ -57,6 +57,7 @@ enb_agent_message_decoded_callback agent_messages_callback[][3] = { {0, 0, 0}, /*PROTOCOL__PROGRAN_MESSAGE__MSG_LC_CONFIG_REPLY_MSG*/ {0, 0, 0}, /*PROTOCOL__PROGRAN_MESSAGE__MSG_DL_MAC_CONFIG_MSG*/ {0, 0, 0}, /*PROTOCOL__PROGRAN_MESSAGE__MSG_UE_STATE_CHANGE_MSG*/ + {enb_agent_control_delegation, 0, 0}, /*PROTOCOL__PROGRAN_MESSAGE__MSG_CONTROL_DELEGATION_MSG*/ }; @@ -76,6 +77,7 @@ enb_agent_message_destruction_callback message_destruction_callback[] = { enb_agent_destroy_lc_config_reply, enb_agent_mac_destroy_dl_config, enb_agent_destroy_ue_state_change, + enb_agent_destroy_control_delegation, }; static const char *enb_agent_direction2String[] = { diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.agent.oaisim.local_no_mme.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.agent.oaisim.local_no_mme.conf index 578a2e3f2ce39d7603bdd7bc6fdfd2d467338bba..f95cfd9389acf4ca74991210372eae9d46bdac90 100644 --- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.agent.oaisim.local_no_mme.conf +++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.agent.oaisim.local_no_mme.conf @@ -123,7 +123,7 @@ eNBs = ENB_AGENT_INTERFACE_NAME = "eth0"; ENB_AGENT_IPV4_ADDRESS = "127.0.0.1/24"; ENB_AGENT_PORT = 2210; - ENB_AGENT_CACHE = "/mnt/tmpfs"; + ENB_AGENT_CACHE = "/mnt/oai_agent_cache"; }; log_config :