Commit 98cbf6c0 authored by Robert Schmidt's avatar Robert Schmidt

Basic start/stop of nr-softmodem

parent e1640d89
......@@ -548,6 +548,119 @@ void terminate_task(task_id_t task_id, module_id_t mod_id) {
//extern void free_transport(PHY_VARS_gNB *);
extern void nr_phy_free_RU(RU_t *);
#include "openair2/LAYER2/NR_MAC_gNB/mac_proto.h"
#include "openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h"
int stop_L1L2(module_id_t gnb_id)
{
LOG_W(GNB_APP, "stopping nr-softmodem\n");
oai_exit = 1;
if (!RC.ru) {
LOG_F(GNB_APP, "no RU configured\n");
return -1;
}
/* stop trx devices, multiple carrier currently not supported by RU */
if (RC.ru[gnb_id]) {
AssertFatal(RC.ru[gnb_id]->rfdevice.trx_stop_func != NULL, "cannot call rfdevice.trx_stop_func(), is NULL\n");
RC.ru[gnb_id]->rfdevice.trx_stop_func(&RC.ru[gnb_id]->rfdevice);
LOG_I(GNB_APP, "turned off RU rfdevice\n");
/*
AssertFatal(RC.ru[gnb_id]->ifdevice.trx_stop_func != NULL, "cannot call ifdevice.trx_stop_func(), is NULL\n");
RC.ru[gnb_id]->ifdevice.trx_stop_func(&RC.ru[gnb_id]->ifdevice);
LOG_I(GNB_APP, "turned off RU ifdevice\n");
*/
}
/* these tasks need to pick up new configuration */
/*
terminate_task(TASK_RRC_GNB, gnb_id);
*/
gNB_MAC_INST *mac = RC.nrmac[0];
mac->f1_config.setup_resp = NULL;
MessageDef *msg = itti_alloc_new_message (TASK_GNB_APP, 0, F1AP_LOST_CONNECTION);
itti_send_msg_to_task (TASK_RRC_GNB, 0, msg);
if (RC.nb_nr_L1_inst > 0)
stop_gNB(RC.nb_nr_L1_inst);
if (RC.nb_RU > 0)
stop_RU(RC.nb_RU);
/* release memory used by the RU/gNB threads (incomplete), after all
* threads have been stopped (they partially use the same memory) */
for (int inst = 0; inst < RC.nb_RU; inst++) {
nr_phy_free_RU(RC.ru[inst]);
}
for (int inst = 0; inst < RC.nb_nr_L1_inst; inst++) {
phy_free_nr_gNB(RC.gNB[inst]);
}
oai_exit = 0;
return 0;
}
/*
* Restart the nr-softmodem after it has been soft-stopped with stop_L1L2()
*/
int start_L1L2(module_id_t gnb_id)
{
//RU_t *ru = RC.ru[gnb_id];
//MessageDef *msg_p = NULL;
LOG_W(GNB_APP, "restarting nr-softmodem\n");
/* block threads */
sync_var = -1;
RC.gNB[gnb_id]->configured = 0;
extern void init_sched_response(void);
init_sched_response();
/*
RC.ru_mask |= (1 << ru->idx);
set_function_spec_param(RC.ru[gnb_id]);
LOG_I(GNB_APP, "attempting to create ITTI tasks\n");
*/
// No more rrc thread, as many race conditions are hidden behind
//int rc = itti_create_task (TASK_RRC_GNB, rrc_gnb_task, NULL);
//AssertFatal(rc == 0, "could not create RRC task\n");
/* pass a reconfiguration request which will configure everything down to
* RC.eNB[i][j]->frame_parms, too */
/*
msg_p = itti_alloc_new_message(TASK_GNB_APP, 0, NRRRC_CONFIGURATION_REQ);
NRRRC_CONFIGURATION_REQ(msg_p) = RC.nrrrc[gnb_id]->configuration;
itti_send_msg_to_task(TASK_RRC_GNB, 0, msg_p);
*/
gNB_MAC_INST *mac = RC.nrmac[0];
NR_ServingCellConfigCommon_t *scc = mac->common_channels[0].ServingCellConfigCommon;
nr_mac_config_scc(mac, scc, &mac->radio_config);
/* send new F1 Setup Request to RRC */
NR_BCCH_BCH_Message_t *mib = mac->common_channels[0].mib;
NR_BCCH_DL_SCH_Message_t *sib1 = mac->common_channels[0].sib1;
f1ap_setup_req_t *old = mac->f1_config.setup_req;
const f1ap_served_cell_info_t *info = &old->cell[0].info;
f1ap_setup_req_t *req = RC_read_F1Setup(old->gNB_DU_id, old->gNB_DU_name, info, scc, mib, sib1);
AssertFatal(req != NULL, "could not read F1 Setup information\n");
RC.nrmac[0]->f1_config.setup_req = req;
nr_mac_send_f1_setup_req();
//wait_gNBs();
init_NR_RU(config_get_if(), NULL);
wait_f1_setup_response();
start_NR_RU();
//ru->rf_map.carD = 0;
//ru->rf_map.chain = 0; /* CC_id + chain_offset;*/
wait_RUs();
// TODO eNB->RU_list[ru_id]->common.rxdataF
init_eNB_afterRU();
printf("Sending sync to all threads\n");
pthread_mutex_lock(&sync_mutex);
sync_var=0;
pthread_cond_broadcast(&sync_cond);
pthread_mutex_unlock(&sync_mutex);
return 0;
}
static void wait_nfapi_init(char *thread_name) {
printf( "waiting for NFAPI PNF connection and population of global structure (%s)\n",thread_name);
pthread_mutex_lock( &nfapi_sync_mutex );
......
......@@ -550,11 +550,6 @@ void nr_phy_config_request(NR_PHY_Config_t *phy_config)
nr_init_frame_parms(gNB_config, fp);
if (RC.gNB[Mod_id]->configured == 1) {
LOG_E(PHY,"Already gNB already configured, do nothing\n");
return;
}
fd_occasion = 0;
nfapi_nr_prach_config_t *prach_config = &gNB_config->prach_config;
short_sequence = prach_config->prach_sequence_length.value;
......
......@@ -217,4 +217,8 @@ void nr_phy_free_RU(RU_t *ru)
}
}
free_and_zero(ru->common.sync_corr);
PHY_VARS_gNB *gNB0= ru->gNB_list[0];
gNB0->num_RU--;
DevAssert(gNB0->num_RU >= 0);
}
......@@ -37,7 +37,7 @@ static pthread_mutex_t cu2du_mutex = PTHREAD_MUTEX_INITIALIZER;
void cu_init_f1_ue_data(void)
{
pthread_mutex_lock(&cu2du_mutex);
DevAssert(cu2du_ue_mapping == NULL);
if (cu2du_ue_mapping == NULL) // hack: there is nothing to free this properly
cu2du_ue_mapping = hashtable_create(1319, NULL, free); // 1319 is prime, default hash func (unit), free()
DevAssert(cu2du_ue_mapping != NULL);
pthread_mutex_unlock(&cu2du_mutex);
......
......@@ -55,17 +55,7 @@ static bool resp_freelist_inited = false;
void init_sched_response(void)
{
/* init only once */
if (pthread_mutex_lock(&resp_mutex))
AssertFatal(0, "pthread_mutex_lock failed\n");
if (resp_freelist_inited) {
if (pthread_mutex_unlock(&resp_mutex))
AssertFatal(0, "pthread_mutex_unlock failed\n");
return;
}
resp_freelist_inited = true;
if (pthread_mutex_unlock(&resp_mutex))
AssertFatal(0, "pthread_mutex_unlock failed\n");
int i;
for (i = 0; i < N_RESP - 1; i++)
......
......@@ -2305,6 +2305,7 @@ void *rrc_gnb_task(void *args_p) {
switch (ITTI_MSG_ID(msg_p)) {
case TERMINATE_MESSAGE:
LOG_W(NR_RRC, " *** Exiting NR_RRC thread\n");
timer_remove(stats_timer_id);
itti_exit_task();
break;
......
......@@ -670,6 +670,15 @@ static int startServer(openair0_device *device) {
return 0;
}
static void rfsimulator_end(openair0_device *device);
static void stopServer(openair0_device *device)
{
rfsimulator_state_t *t = (rfsimulator_state_t *) device->priv;
DevAssert(t != NULL);
rfsimulator_end(device);
close(t->listen_sock);
}
static int startClient(openair0_device *device) {
rfsimulator_state_t *t = device->priv;
t->role = SIMU_ROLE_CLIENT;
......@@ -1047,10 +1056,11 @@ static void rfsimulator_end(openair0_device *device) {
rfsimulator_state_t* s = device->priv;
for (int i = 0; i < MAX_FD_RFSIMU; i++) {
buffer_t *b = &s->buf[i];
if (b->conn_sock >= 0 )
close(b->conn_sock);
if (b->conn_sock >= 0 ) {
removeCirBuf(s, b->conn_sock);
}
}
close(s->epollfd);
//close(s->epollfd); // don't close as we cannot restart with startServer()/startClient()
}
static int rfsimulator_stop(openair0_device *device) {
return 0;
......@@ -1084,7 +1094,7 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
device->trx_start_func = rfsimulator->role == SIMU_ROLE_SERVER ? startServer : startClient;
device->trx_get_stats_func = rfsimulator_get_stats;
device->trx_reset_stats_func = rfsimulator_reset_stats;
device->trx_end_func = rfsimulator_end;
device->trx_end_func = rfsimulator->role == SIMU_ROLE_SERVER ? stopServer : rfsimulator_end;
device->trx_stop_func = rfsimulator_stop;
device->trx_set_freq_func = rfsimulator_set_freq;
device->trx_set_gains_func = rfsimulator_set_gains;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment