oaisim.c 61.1 KB
Newer Older
1 2 3 4 5
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * 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.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

22
/*! \file oaisim.c
23 24 25 26 27 28 29 30 31
 * \brief oaisim top level
 * \author Navid Nikaein 
 * \date 2013-2015
 * \version 1.0
 * \company Eurecom
 * \email: openair_tech@eurecom.fr
 * \note
 * \warning
 */
32

33 34 35 36 37 38 39 40 41 42
#include <string.h>
#include <math.h>
#include <unistd.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <cblas.h>
#include <execinfo.h>

43
#include "event_handler.h"
44 45 46 47 48 49
#include "SIMULATION/RF/defs.h"
#include "PHY/types.h"
#include "PHY/defs.h"
#include "PHY/LTE_TRANSPORT/proto.h"
#include "PHY/vars.h"

Cedric Roux's avatar
Cedric Roux committed
50 51
#include "SIMULATION/ETH_TRANSPORT/proto.h"

52 53
//#ifdef OPENAIR2
#include "LAYER2/MAC/defs.h"
54
#include "LAYER2/MAC/proto.h"
55
#include "LAYER2/MAC/vars.h"
56
#include "pdcp.h"
57
#include "RRC/LITE/vars.h"
58
#include "RRC/NAS/nas_config.h"
59 60 61

#include "SCHED/defs.h"
#include "SCHED/vars.h"
62
#include "system.h"
63

Raymond Knopp's avatar
Raymond Knopp committed
64

65
#include "PHY/TOOLS/lte_phy_scope.h"
Raymond Knopp's avatar
Raymond Knopp committed
66

67 68

#ifdef SMBV
69
// Rohde&Schwarz SMBV100A vector signal generator
70
#include "PHY/TOOLS/smbv.h"
Lionel Gauthier's avatar
Lionel Gauthier committed
71
char smbv_fname[] = "smbv_config_file.smbv";
72 73
unsigned short smbv_nframes = 4; // how many frames to configure 1,..,4
unsigned short config_frames[4] = {2,9,11,13};
Lionel Gauthier's avatar
Lionel Gauthier committed
74 75 76
unsigned char smbv_frame_cnt = 0;
uint8_t config_smbv = 0;
char smbv_ip[16];
77 78
#endif

79
#include "flexran_agent.h"
80 81


82 83 84 85 86 87 88 89
#include "oaisim_functions.h"

#include "oaisim.h"
#include "oaisim_config.h"
#include "UTIL/OCG/OCG_extern.h"
#include "cor_SF_sim.h"
#include "UTIL/OMG/omg_constants.h"
#include "UTIL/FIFO/pad_list.h"
90
#include "enb_app.h"
91 92 93 94 95 96 97

#include "../PROC/interface.h"
#include "../PROC/channel_sim_proc.h"
#include "../PROC/Tsync.h"
#include "../PROC/Process.h"

#include "UTIL/LOG/vcd_signal_dumper.h"
98
#include "UTIL/OTG/otg_kpi.h"
99
#include "assertions.h"
100 101

#if defined(ENABLE_ITTI)
102
# include "intertask_interface.h"
103
# include "create_tasks.h"
104
#endif
105

106 107
#include "T.h"

108
/*
109 110 111 112 113
  DCI0_5MHz_TDD0_t          UL_alloc_pdu;
  DCI1A_5MHz_TDD_1_6_t      CCCH_alloc_pdu;
  DCI2_5MHz_2A_L10PRB_TDD_t DLSCH_alloc_pdu1;
  DCI2_5MHz_2A_M10PRB_TDD_t DLSCH_alloc_pdu2;
*/
114

115 116 117 118
#define UL_RB_ALLOC            computeRIV(lte_frame_parms->N_RB_UL,0,24)
#define CCCH_RB_ALLOC          computeRIV(lte_frame_parms->N_RB_UL,0,3)
#define RA_RB_ALLOC            computeRIV(lte_frame_parms->N_RB_UL,0,3)
#define DLSCH_RB_ALLOC         0x1fff
119

120 121
#define DECOR_DIST             100
#define SF_VAR                 10
122 123

//constant for OAISIM soft realtime calibration
124 125 126 127
//#define SF_DEVIATION_OFFSET_NS 100000        /*= 0.1ms : should be as a number of UE */
//#define SLEEP_STEP_US          100           /*  = 0.01ms could be adaptive, should be as a number of UE */
//#define K                      2             /* averaging coefficient */
//#define TARGET_SF_TIME_NS      1000000       /* 1ms = 1000000 ns */
128

fnabet's avatar
fnabet committed
129 130
uint8_t usim_test = 0;

Lionel Gauthier's avatar
Lionel Gauthier committed
131 132
frame_t frame = 0;
char stats_buffer[16384];
133 134
channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM_CCs];
channel_desc_t *UE2RU[NUMBER_OF_UE_MAX][NUMBER_OF_RU_MAX][MAX_NUM_CCs];
135
//Added for PHY abstraction
136
node_desc_t *enb_data[NUMBER_OF_RU_MAX];
Lionel Gauthier's avatar
Lionel Gauthier committed
137
node_desc_t *ue_data[NUMBER_OF_UE_MAX];
Raymond Knopp's avatar
Raymond Knopp committed
138 139 140

pthread_cond_t sync_cond;
pthread_mutex_t sync_mutex;
141
int sync_var=-1;
Raymond Knopp's avatar
Raymond Knopp committed
142

143
pthread_mutex_t subframe_mutex;
144
int subframe_ru_mask=0,subframe_UE_mask=0;
Raymond Knopp's avatar
Raymond Knopp committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160

openair0_config_t openair0_cfg[MAX_CARDS];
uint32_t          downlink_frequency[MAX_NUM_CCs][4];
int32_t           uplink_frequency_offset[MAX_NUM_CCs][4];
openair0_rf_map rf_map[MAX_NUM_CCs];

#if defined(ENABLE_ITTI)
volatile int             start_eNB = 0;
volatile int             start_UE = 0;
#endif
volatile int                    oai_exit = 0;


//int32_t **rxdata;
//int32_t **txdata;

161 162
uint16_t sf_ahead=4;
uint8_t nfapi_mode = 0;
Raymond Knopp's avatar
Raymond Knopp committed
163

164
// Added for PHY abstraction
Lionel Gauthier's avatar
Lionel Gauthier committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
extern node_list* ue_node_list;
extern node_list* enb_node_list;
extern int pdcp_period, omg_period;

extern double **s_re, **s_im, **r_re, **r_im, **r_re0, **r_im0;
int map1, map2;
extern double **ShaF;
double snr_dB, sinr_dB, snr_direction; //,sinr_direction;
extern double snr_step;
extern uint8_t set_sinr;
extern uint8_t ue_connection_test;
extern uint8_t set_seed;
extern uint8_t target_dl_mcs;
extern uint8_t target_ul_mcs;
extern uint8_t abstraction_flag;
extern uint8_t ethernet_flag;
extern uint16_t Nid_cell;
182

Raymond Knopp's avatar
Raymond Knopp committed
183

184 185
double cpuf;
#include "threads_t.h"
186
threads_t threads= {-1,-1,-1,-1,-1,-1,-1};
Raymond Knopp's avatar
Raymond Knopp committed
187

188
//#ifdef XFORMS
189
int otg_enabled;
190 191
int xforms=0;
//#endif
192

193 194 195 196 197
time_stats_t oaisim_stats;
time_stats_t oaisim_stats_f;
time_stats_t dl_chan_stats;
time_stats_t ul_chan_stats;

198
// this should reflect the channel models in openair1/SIMULATION/TOOLS/defs.h
199 200 201 202 203 204 205 206 207 208
mapping small_scale_names[] = { 
  { "custom", custom }, { "SCM_A", SCM_A },
  { "SCM_B", SCM_B   }, { "SCM_C", SCM_C },
  { "SCM_D", SCM_D   }, { "EPA",   EPA   },
  { "EVA",   EVA     }, { "ETU",   ETU   },
  { "MBSFN", MBSFN },   { "Rayleigh8", Rayleigh8 },
  { "Rayleigh1", Rayleigh1 }, { "Rayleigh1_800", Rayleigh1_800 },
  { "Rayleigh1_corr", Rayleigh1_corr }, { "Rayleigh1_anticorr", Rayleigh1_anticorr },
  { "Rice8", Rice8 }, { "Rice1", Rice1 }, { "Rice1_corr", Rice1_corr },
  { "Rice1_anticorr", Rice1_anticorr }, { "AWGN", AWGN }, { NULL,-1 }
209
};
210
#if !defined(ENABLE_ITTI)
Lionel Gauthier's avatar
Lionel Gauthier committed
211 212
static void *
sigh (void *arg);
213
#endif
Lionel Gauthier's avatar
Lionel Gauthier committed
214 215 216
void
oai_shutdown (void);

Rohit Gupta's avatar
Rohit Gupta committed
217 218
void reset_opp_meas_oaisim (void);

219 220 221 222
void wait_eNBs() {
  return;
}

Lionel Gauthier's avatar
Lionel Gauthier committed
223
void
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
help (void)
{
  printf ("Usage: oaisim -h -a -F -C tdd_config -K [log_file] -V [vcd_file] -R N_RB_DL -e -x transmission_mode -m target_dl_mcs -r(ate_adaptation) -n n_frames -s snr_dB -k ricean_factor -t max_delay -f forgetting factor -A channel_model -z cooperation_flag -u nb_local_ue -U UE mobility -b nb_local_enb -B eNB_mobility -M ethernet_flag -p nb_master -g multicast_group -l log_level -c ocg_enable -T traffic model -D multicast network device\n");

  printf ("-h provides this help message!\n");
  printf ("-a Activates PHY abstraction mode\n");
  printf ("-A set the multipath channel simulation,  options are: SCM_A, SCM_B, SCM_C, SCM_D, EPA, EVA, ETU, Rayleigh8, Rayleigh1, Rayleigh1_corr,Rayleigh1_anticorr, Rice8,, Rice1, AWGN \n");
  printf ("-b Set the number of local eNB\n");
  printf ("-B Set the mobility model for eNB, options are: STATIC, RWP, RWALK, \n");
  printf ("-c [1,2,3,4] Activate the config generator (OCG) to process the scenario descriptor, or give the scenario manually: -c template_1.xml \n");
  printf ("-C [0-6] Sets TDD configuration\n");
  printf ("-e Activates extended prefix mode\n");
  printf ("-E Random number generator seed\n");
  printf ("-f Set the forgetting factor for time-variation\n");
  printf ("-F Activates FDD transmission (TDD is default)\n");
  printf ("-g Set multicast group ID (0,1,2,3) - valid if M is set\n");
  printf ("-G Enable background traffic \n");
  printf ("-H Enable handover operation (default disabled) \n");
  printf ("-I Enable CLI interface (to connect use telnet localhost 1352)\n");
  printf ("-k Set the Ricean factor (linear)\n");
  printf ("-K [log_file] Enable ITTI logging into log_file\n");
  printf ("-l Set the global log level (8:trace, 7:debug, 6:info, 4:warn, 3:error) \n");
  printf ("-L [0-1] 0 to disable new link adaptation, 1 to enable new link adapatation\n");
  printf ("-m Gives a fixed DL mcs for eNB scheduler\n");
  printf ("-M Set the machine ID for Ethernet-based emulation\n");
249
  printf ("-n Set the number of frames for the simulation. 0 for no limit\n");
250 251 252 253 254 255 256 257 258 259 260 261 262
  printf ("-O [enb_conf_file] eNB configuration file name\n");
  printf ("-p Set the total number of machine in emulation - valid if M is set\n");
  printf ("-P [trace type] Enable protocol analyzer. Possible values for OPT:\n");
  printf ("    - wireshark: Enable tracing of layers above PHY using an UDP socket\n");
  printf ("    - pcap:      Enable tracing of layers above PHY to a pcap file\n");
  printf ("    - tshark:    Not implemented yet\n");
  printf ("-q Enable Openair performance profiler \n");
  printf ("-Q Activate and set the MBMS service: 0 : not used (default eMBMS disabled), 1: eMBMS and RRC Connection enabled, 2: eMBMS relaying and RRC Connection enabled, 3: eMBMS enabled, RRC Connection disabled, 4: eMBMS relaying enabled, RRC Connection disabled\n");
  printf ("-R [6,15,25,50,75,100] Sets N_RB_DL\n");
  printf ("-r Activates rate adaptation (DL for now)\n");
  printf ("-s snr_dB set a fixed (average) SNR, this deactivates the openair channel model generator (OCM)\n");
  printf ("-S snir_dB set a fixed (average) SNIR, this deactivates the openair channel model generator (OCM)\n");
  printf ("-t Gives a fixed UL mcs for eNB scheduler\n");
263
  printf ("-T activate the traffic generator. Valide options are m2m,scbr,mcbr,bcbr,auto_pilot,bicycle_race,open_arena,team_fortress,m2m_traffic,auto_pilot_l,auto_pilot_m,auto_pilot_h,auto_pilot_e,virtual_game_l,virtual_game_m,virtual_game_h,virtual_game_f,alarm_humidity,alarm_smoke,alarm_temperature,openarena_dl,openarena_ul,voip_g711,voip_g729,video_vbr_10mbps,video_vbr_4mbps,video_vbr_2mbp,video_vbr_768kbps,video_vbr_384kbps,video_vbr_192kpbs,background_users\n");
264 265 266 267
  printf ("-u Set the number of local UE\n");
  printf ("-U Set the mobility model for UE, options are: STATIC, RWP, RWALK\n");
  printf ("-V [vcd_file] Enable VCD dump into vcd_file\n");
  printf ("-w number of CBA groups, if not specified or zero, CBA is inactive\n");
268
#ifdef SMBV
269
  printf ("-W IP address to connect to Rohde&Schwarz SMBV100A and configure SMBV from config file. -W0 uses default IP 192.168.12.201\n");
270
#else
271
  printf ("-W [Rohde&Schwarz SMBV100A functions disabled. Recompile with SMBV=1]\n");
272
#endif
273 274
  printf ("-x deprecated. Set the transmission mode in config file!\n");
  printf ("-y Set the number of receive antennas at the UE (1 or 2)\n");
275 276 277
  printf ("-Y Set the global log verbosity (none, low, medium, high, full) \n");
  printf ("-z Set the cooperation flag (0 for no cooperation, 1 for delay diversity and 2 for distributed alamouti\n");
  printf ("-Z Reserved\n");
278 279
  printf ("--xforms Activate the grapical scope\n");

Cedric Roux's avatar
Cedric Roux committed
280 281 282
#if T_TRACER
  printf ("--T_port [port]    use given port\n");
  printf ("--T_nowait         don't wait for tracer, start immediately\n");
283
  printf ("--T_dont_fork      to ease debugging with gdb\n");
Cedric Roux's avatar
Cedric Roux committed
284
#endif
285 286 287 288
}

pthread_t log_thread;

Lionel Gauthier's avatar
Lionel Gauthier committed
289
void
290 291 292 293
log_thread_init (void)
{
  //create log_list
  //log_list_init(&log_list);
294 295
#ifndef LOG_NO_THREAD

296
  log_shutdown = 0;
297

298 299 300 301 302 303 304 305 306 307
  if ((pthread_mutex_init (&log_lock, NULL) != 0)
      || (pthread_cond_init (&log_notify, NULL) != 0)) {
    return;
  }

  if (pthread_create (&log_thread, NULL, log_thread_function, (void*) NULL)
      != 0) {
    log_thread_finalize ();
    return;
  }
308 309 310 311 312 313

#endif

}

//Call it after the last LOG call
Lionel Gauthier's avatar
Lionel Gauthier committed
314
int
315 316 317
log_thread_finalize (void)
{
  int err = 0;
318 319 320

#ifndef LOG_NO_THREAD

321 322 323
  if (pthread_mutex_lock (&log_lock) != 0) {
    return -1;
  }
Lionel Gauthier's avatar
Lionel Gauthier committed
324

325
  log_shutdown = 1;
Lionel Gauthier's avatar
Lionel Gauthier committed
326

327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
  /* Wake up LOG thread */
  if ((pthread_cond_broadcast (&log_notify) != 0)
      || (pthread_mutex_unlock (&log_lock) != 0)) {
    err = -1;
  }

  if (pthread_join (log_thread, NULL) != 0) {
    err = -1;
  }

  if (pthread_mutex_unlock (&log_lock) != 0) {
    err = -1;
  }

  if (!err) {
    //log_list_free(&log_list);
    pthread_mutex_lock (&log_lock);
    pthread_mutex_destroy (&log_lock);
    pthread_cond_destroy (&log_notify);
  }
Lionel Gauthier's avatar
Lionel Gauthier committed
347

Cedric Roux's avatar
Cedric Roux committed
348 349
#endif

350
  return err;
351 352
}

353
#if defined(ENABLE_ITTI)
354 355 356 357 358 359 360
static void set_cli_start(module_id_t module_idP, uint8_t start)
{
  if (module_idP < NB_eNB_INST) {
    oai_emulation.info.cli_start_enb[module_idP] = start;
  } else {
    oai_emulation.info.cli_start_ue[module_idP - NB_eNB_INST] = start;
  }
361 362 363
}
#endif

364
#ifdef OPENAIR2
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
int omv_write(int pfd, node_list* enb_node_list, node_list* ue_node_list, Data_Flow_Unit omv_data)
{
  module_id_t i, j;
  omv_data.end = 0;

  //omv_data.total_num_nodes = NB_UE_INST + NB_eNB_INST;
  for (i = 0; i < NB_eNB_INST; i++) {
    if (enb_node_list != NULL) {
      omv_data.geo[i].x = (enb_node_list->node->x_pos < 0.0) ? 0.0 : enb_node_list->node->x_pos;
      omv_data.geo[i].y = (enb_node_list->node->y_pos < 0.0) ? 0.0 : enb_node_list->node->y_pos;
      omv_data.geo[i].z = 1.0;
      omv_data.geo[i].mobility_type = oai_emulation.info.omg_model_enb;
      omv_data.geo[i].node_type = 0; //eNB
      enb_node_list = enb_node_list->next;
      omv_data.geo[i].Neighbors = 0;
380
/*
381 382
      for (j = NB_RU; j < NB_UE_INST + NB_RU; j++) {
        if (is_UE_active (i, j - NB_RU) == 1) {
383 384 385
          omv_data.geo[i].Neighbor[omv_data.geo[i].Neighbors] = j;
          omv_data.geo[i].Neighbors++;
          LOG_D(
386
		OMG,
387
		"[RU %d][UE %d] is_UE_active(i,j) %d geo (x%d, y%d) num neighbors %d\n", i, j-NB_RU, is_UE_active(i,j-NB_RU), omv_data.geo[i].x, omv_data.geo[i].y, omv_data.geo[i].Neighbors);
Lionel Gauthier's avatar
Lionel Gauthier committed
388
        }
389
      }
390
*/
Raymond Knopp's avatar
 
Raymond Knopp committed
391
    }
392 393
  }

394
  for (i = NB_RU; i < NB_UE_INST + NB_RU; i++) {
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
    if (ue_node_list != NULL) {
      omv_data.geo[i].x = (ue_node_list->node->x_pos < 0.0) ? 0.0 : ue_node_list->node->x_pos;
      omv_data.geo[i].y = (ue_node_list->node->y_pos < 0.0) ? 0.0 : ue_node_list->node->y_pos;
      omv_data.geo[i].z = 1.0;
      omv_data.geo[i].mobility_type = oai_emulation.info.omg_model_ue;
      omv_data.geo[i].node_type = 1; //UE
      //trial
      omv_data.geo[i].state = 1;
      omv_data.geo[i].rnti = 88;
      omv_data.geo[i].connected_eNB = 0;
      omv_data.geo[i].RSRP = 66;
      omv_data.geo[i].RSRQ = 55;
      omv_data.geo[i].Pathloss = 44;
      omv_data.geo[i].RSSI[0] = 33;
      omv_data.geo[i].RSSI[1] = 22;

      if ((sizeof(omv_data.geo[0].RSSI) / sizeof(omv_data.geo[0].RSSI[0])) > 2) {
        omv_data.geo[i].RSSI[2] = 11;
      }

      ue_node_list = ue_node_list->next;
      omv_data.geo[i].Neighbors = 0;
417
/*
418 419
      for (j = 0; j < NB_RU; j++) {
        if (is_UE_active (j, i - NB_RU) == 1) {
420 421 422
          omv_data.geo[i].Neighbor[omv_data.geo[i].Neighbors] = j;
          omv_data.geo[i].Neighbors++;
          LOG_D(
423
		OMG,
424
		"[UE %d][RU %d] is_UE_active  %d geo (x%d, y%d) num neighbors %d\n", i-NB_RU, j, is_UE_active(j,i-NB_RU), omv_data.geo[i].x, omv_data.geo[i].y, omv_data.geo[i].Neighbors);
Lionel Gauthier's avatar
Lionel Gauthier committed
425
        }
426
      }
427
*/
Raymond Knopp's avatar
 
Raymond Knopp committed
428
    }
429 430 431 432 433
  }

  LOG_E(OMG, "pfd %d \n", pfd);

  if (write (pfd, &omv_data, sizeof(struct Data_Flow_Unit)) == -1)
434
    perror ("write omv failed");
435 436

  return 1;
437 438
}

439 440 441 442 443
void omv_end(int pfd, Data_Flow_Unit omv_data)
{
  omv_data.end = 1;

  if (write (pfd, &omv_data, sizeof(struct Data_Flow_Unit)) == -1)
444
    perror ("write omv failed");
445
}
446
#endif
447

448
#ifdef OPENAIR2
449 450
int pfd[2]; // fd for omv : fixme: this could be a local var
#endif
451

452 453 454
#ifdef OPENAIR2
static Data_Flow_Unit omv_data;
#endif //ALU
Lionel Gauthier's avatar
Lionel Gauthier committed
455
static module_id_t UE_inst = 0;
456
static module_id_t eNB_inst = 0;
457
static module_id_t ru_id;
458

459
Packet_OTG_List_t *otg_pdcp_buffer;
460

Lionel Gauthier's avatar
Lionel Gauthier committed
461
typedef enum l2l1_task_state_e {
462
  L2L1_WAITTING, L2L1_RUNNING, L2L1_TERMINATED,
Lionel Gauthier's avatar
Lionel Gauthier committed
463
} l2l1_task_state_t;
464

Lionel Gauthier's avatar
Lionel Gauthier committed
465
l2l1_task_state_t l2l1_state = L2L1_WAITTING;
466

467
extern openair0_timestamp current_ru_rx_timestamp[NUMBER_OF_RU_MAX][MAX_NUM_CCs];
468
extern openair0_timestamp current_UE_rx_timestamp[NUMBER_OF_UE_MAX][MAX_NUM_CCs];
469 470
extern openair0_timestamp last_eNB_rx_timestamp[NUMBER_OF_eNB_MAX][MAX_NUM_CCs];
extern openair0_timestamp last_UE_rx_timestamp[NUMBER_OF_UE_MAX][MAX_NUM_CCs];
471

472
/*------------------------------------------------------------------------------*/
Lionel Gauthier's avatar
Lionel Gauthier committed
473
void *
474 475
l2l1_task (void *args_p)
{
Lionel Gauthier's avatar
Lionel Gauthier committed
476

477
  int CC_id;
478

479
  // Framing variables
480
  int32_t sf;
481

Cedric Roux's avatar
Cedric Roux committed
482
  //char fname[64], vname[64];
483

484
  //#ifdef XFORMS
485 486
  // current status is that every UE has a DL scope for a SINGLE eNB (eNB_id=0)
  // at eNB 0, an UL scope for every UE
487
  FD_lte_phy_scope_ue *form_ue[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
488 489 490 491 492
  FD_lte_phy_scope_enb *form_enb[NUMBER_OF_UE_MAX];
  char title[255];
  char xname[32] = "oaisim";
  int xargc = 1;
  char *xargv[1];
493
  //#endif
494

Cedric Roux's avatar
Cedric Roux committed
495
#undef PRINT_STATS /* this undef is to avoid gcc warnings */
496
#define PRINT_STATS
497
#ifdef PRINT_STATS
498 499 500 501 502 503 504 505 506 507
  int len;
  FILE *UE_stats[NUMBER_OF_UE_MAX];
  FILE *UE_stats_th[NUMBER_OF_UE_MAX];
  FILE *eNB_stats[NUMBER_OF_eNB_MAX];
  FILE *eNB_avg_thr;
  FILE *eNB_l2_stats;
  char UE_stats_filename[255];
  char eNB_stats_filename[255];
  char UE_stats_th_filename[255];
  char eNB_stats_th_filename[255];
508 509 510
#endif


511 512 513 514 515 516 517 518 519 520 521
  if (xforms==1) {
    xargv[0] = xname;
    fl_initialize (&xargc, xargv, NULL, 0, 0);
    eNB_inst = 0;
    for (UE_inst = 0; UE_inst < NB_UE_INST; UE_inst++) {
      for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
	// DL scope at UEs
	form_ue[CC_id][UE_inst] = create_lte_phy_scope_ue();
	sprintf (title, "LTE DL SCOPE eNB %d to UE %d CC_id %d", eNB_inst, UE_inst, CC_id);
	fl_show_form (form_ue[CC_id][UE_inst]->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);

522
	if (PHY_vars_UE_g[UE_inst][CC_id]->use_ia_receiver == 1) {
523 524 525 526 527 528
	  fl_set_button(form_ue[CC_id][UE_inst]->button_0,1);
	  fl_set_object_label(form_ue[CC_id][UE_inst]->button_0, "IA Receiver ON");
	  fl_set_object_color(form_ue[CC_id][UE_inst]->button_0, FL_GREEN, FL_GREEN);
	}
	
      }
Lionel Gauthier's avatar
Lionel Gauthier committed
529
    }
530
  }
531

532 533

#ifdef PRINT_STATS
Lionel Gauthier's avatar
Lionel Gauthier committed
534

535 536 537 538 539 540 541 542 543 544 545 546
  for (UE_inst=0; UE_inst<NB_UE_INST; UE_inst++) {
    sprintf(UE_stats_filename,"UE_stats%d.txt",UE_inst);
    UE_stats[UE_inst] = fopen (UE_stats_filename, "w");
  }

  for (eNB_inst=0; eNB_inst<NB_eNB_INST; eNB_inst++) {
    sprintf(eNB_stats_filename,"eNB_stats%d.txt",eNB_inst);
    eNB_stats[eNB_inst] = fopen (eNB_stats_filename, "w");
  }

  if(abstraction_flag==0) {
    for (UE_inst=0; UE_inst<NB_UE_INST; UE_inst++) {
Cedric Roux's avatar
Cedric Roux committed
547 548
      /* TODO: transmission_mode is defined per CC, we set 0 for now */
      sprintf(UE_stats_th_filename,"UE_stats_th%d_tx%d.txt",UE_inst,oai_emulation.info.transmission_mode[0]);
549
      UE_stats_th[UE_inst] = fopen (UE_stats_th_filename, "w");
Lionel Gauthier's avatar
Lionel Gauthier committed
550
    }
551

Cedric Roux's avatar
Cedric Roux committed
552 553
    /* TODO: transmission_mode is defined per CC, we set 0 for now */
    sprintf(eNB_stats_th_filename,"eNB_stats_th_tx%d.txt",oai_emulation.info.transmission_mode[0]);
554 555 556
    eNB_avg_thr = fopen (eNB_stats_th_filename, "w");
  } else {
    for (UE_inst=0; UE_inst<NB_UE_INST; UE_inst++) {
Cedric Roux's avatar
Cedric Roux committed
557 558
      /* TODO: transmission_mode is defined per CC, we set 0 for now */
      sprintf(UE_stats_th_filename,"UE_stats_abs_th%d_tx%d.txt",UE_inst,oai_emulation.info.transmission_mode[0]);
559
      UE_stats_th[UE_inst] = fopen (UE_stats_th_filename, "w");
Raymond Knopp's avatar
 
Raymond Knopp committed
560
    }
561

Cedric Roux's avatar
Cedric Roux committed
562 563
    /* TODO: transmission_mode is defined per CC, we set 0 for now */
    sprintf(eNB_stats_th_filename,"eNB_stats_abs_th_tx%d.txt",oai_emulation.info.transmission_mode[0]);
564 565 566
    eNB_avg_thr = fopen (eNB_stats_th_filename, "w");
  }

567
#ifdef OPENAIR2
568 569 570
  eNB_l2_stats = fopen ("eNB_l2_stats.txt", "w");
  LOG_I(EMU,"eNB_l2_stats=%p\n", eNB_l2_stats);
#endif
571 572 573

#endif

574
#if defined(ENABLE_ITTI)
575 576 577 578 579 580 581
  MessageDef *message_p = NULL;
  const char *msg_name = NULL;
  int result;

  itti_mark_task_ready (TASK_L2L1);
  LOG_I(EMU, "TASK_L2L1 is READY\n");

582 583
  if ((oai_emulation.info.nb_enb_local > 0) && 
      (oai_emulation.info.node_function[0] < NGFI_RAU_IF4p5)) {
584 585 586
    /* Wait for the initialize message */
    do {
      if (message_p != NULL) {
Lionel Gauthier's avatar
Lionel Gauthier committed
587 588
        result = itti_free (ITTI_MSG_ORIGIN_ID(message_p), message_p);
        AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
589 590 591 592 593 594 595 596 597
      }

      itti_receive_msg (TASK_L2L1, &message_p);
      msg_name = ITTI_MSG_NAME (message_p);
      LOG_I(EMU, "TASK_L2L1 received %s in state L2L1_WAITTING\n", msg_name);

      switch (ITTI_MSG_ID(message_p)) {
      case INITIALIZE_MESSAGE:
        l2l1_state = L2L1_RUNNING;
598
        start_eNB = 1;
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
        break;

      case ACTIVATE_MESSAGE:
        set_cli_start(ITTI_MSG_INSTANCE (message_p), 1);
        break;

      case DEACTIVATE_MESSAGE:
        set_cli_start(ITTI_MSG_INSTANCE (message_p), 0);
        break;

      case TERMINATE_MESSAGE:
        l2l1_state = L2L1_TERMINATED;
        break;

      default:
        LOG_E(EMU, "Received unexpected message %s\n", ITTI_MSG_NAME(message_p));
        break;
      }
    } while (l2l1_state == L2L1_WAITTING);

    result = itti_free (ITTI_MSG_ORIGIN_ID(message_p), message_p);
    AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
  }

Lionel Gauthier's avatar
Lionel Gauthier committed
623
#endif
624 625
  module_id_t enb_id;
  module_id_t UE_id;
626

627 628
  if (abstraction_flag == 1) {
    for (UE_id = 0; UE_id < NB_UE_INST; UE_id++)
629
      dl_phy_sync_success (UE_id, 0, 0,1);   //UE_id%NB_eNB_INST);
630 631
  }
  
632 633 634
  start_meas (&oaisim_stats);

  for (frame = 0;
635
       (l2l1_state != L2L1_TERMINATED) && 
636 637
	 ((oai_emulation.info.n_frames_flag == 0) ||
	  (frame < oai_emulation.info.n_frames));
638
       frame++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
639

Lionel Gauthier's avatar
Lionel Gauthier committed
640 641
#if defined(ENABLE_ITTI)

642 643 644
    do {
      // Checks if a message has been sent to L2L1 task
      itti_poll_msg (TASK_L2L1, &message_p);
645

646 647 648
      if (message_p != NULL) {
        msg_name = ITTI_MSG_NAME (message_p);
        LOG_I(EMU, "TASK_L2L1 received %s\n", msg_name);
Lionel Gauthier's avatar
Lionel Gauthier committed
649

650 651 652 653 654 655 656 657 658 659 660 661
        switch (ITTI_MSG_ID(message_p)) {
        case ACTIVATE_MESSAGE:
          set_cli_start(ITTI_MSG_INSTANCE (message_p), 1);
          break;

        case DEACTIVATE_MESSAGE:
          set_cli_start(ITTI_MSG_INSTANCE (message_p), 0);
          break;

        case TERMINATE_MESSAGE:
          l2l1_state = L2L1_TERMINATED;
          break;
Lionel Gauthier's avatar
Lionel Gauthier committed
662

663 664 665 666 667 668
        case MESSAGE_TEST:
          break;

        default:
          LOG_E(EMU, "Received unexpected message %s\n", ITTI_MSG_NAME(message_p));
          break;
Lionel Gauthier's avatar
Lionel Gauthier committed
669 670
        }

671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
        result = itti_free (ITTI_MSG_ORIGIN_ID(message_p), message_p);
        AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
      }
    } while(message_p != NULL);

#endif

    //Run the aperiodic user-defined events
    if (oai_emulation.info.oeh_enabled == 1)
      execute_events (frame);

    if (ue_connection_test == 1) {
      if ((frame % 20) == 0) {
        snr_dB += snr_direction;
        sinr_dB -= snr_direction;
      }

      if (snr_dB == -20) {
        snr_direction = snr_step;
      } else if (snr_dB == 20) {
        snr_direction = -snr_step;
      }
    }

    oai_emulation.info.frame = frame;
    //oai_emulation.info.time_ms += 1;
    oai_emulation.info.time_s += 0.01; // emu time in s, each frame lasts for 10 ms // JNote: TODO check the coherency of the time and frame (I corrected it to 10 (instead of 0.01)
Lionel Gauthier's avatar
Lionel Gauthier committed
698

699
    update_omg (frame); // frequency is defined in the omg_global params configurable by the user
700
    update_omg_ocm ();
701 702

#ifdef OPENAIR2
703 704 705 706 707 708

    // check if pipe is still open
    if ((oai_emulation.info.omv_enabled == 1)) {
      omv_write (pfd[1], enb_node_list, ue_node_list, omv_data);
    }

709 710
#endif

711

Lionel Gauthier's avatar
Lionel Gauthier committed
712

713
    for (sf = 0; sf < 10; sf++) {
714
      LOG_D(EMU,"************************* Subframe %d\n",sf);
715
      start_meas (&oaisim_stats_f);
716

717
      wait_for_slot_isr ();
718

719
#if defined(ENABLE_ITTI)
720
      itti_update_lte_time(frame % MAX_FRAME_NUMBER, sf<<1);
721
#endif
722

723
      oai_emulation.info.time_ms = frame * 10 + sf;
724

725
#ifdef PROC
726

727
    if(Channel_Flag==1)
728
      Channel_Func(s_re2,s_im2,r_re2,r_im2,r_re02,r_im02,r_re0_d,r_im0_d,r_re0_u,r_im0_u,RU2UE,UE2RU,enb_data,ue_data,abstraction_flag,frame_parms,sf<<1);
729

730
    if(Channel_Flag==0)
731
#endif
732
      { // SUBFRAME INNER PART
733
#if defined(ENABLE_ITTI)
734
        log_set_instance_type (LOG_INSTANCE_ENB);
735 736
#endif

737

738
	CC_id=0;
739
        int all_done=0;
740

741
        while (all_done==0) {
742

743
          pthread_mutex_lock(&subframe_mutex);
744
          int subframe_ru_mask_local = subframe_ru_mask;
745 746
          int subframe_UE_mask_local  = subframe_UE_mask;
          pthread_mutex_unlock(&subframe_mutex);
Wolfgang A. Mozart's avatar
Wolfgang A. Mozart committed
747
          LOG_D(EMU,"Frame %d, Subframe %d, NB_RU %d, NB_UE %d: Checking masks %x,%x\n",frame,sf,NB_RU,NB_UE_INST,subframe_ru_mask_local,subframe_UE_mask_local);
748
          if ((subframe_ru_mask_local == ((1<<NB_RU)-1)) &&
749 750 751
              (subframe_UE_mask_local == ((1<<NB_UE_INST)-1)))
             all_done=1;
          else
752
	    usleep(1500);
753 754
        }

755

756 757
        //clear subframe masks for next round
        pthread_mutex_lock(&subframe_mutex);
758
        subframe_ru_mask=0;
759 760
        subframe_UE_mask=0;
        pthread_mutex_unlock(&subframe_mutex);
761

762
        // increment timestamps
763 764 765
	/*
        for (ru_id = oai_emulation.info.first_enb_local;
             (ru_id
766 767
              < (oai_emulation.info.first_enb_local
                 + oai_emulation.info.nb_enb_local));
768 769 770 771
             ru_id++) {
	*/
	for (ru_id=0;ru_id<NB_RU;ru_id++) {
	  current_ru_rx_timestamp[ru_id][CC_id] += RC.ru[ru_id]->frame_parms.samples_per_tti;
772
	  LOG_D(EMU,"RU %d/%d: TS %llu\n",ru_id,CC_id,current_ru_rx_timestamp[ru_id][CC_id]);
773 774
        }
        for (UE_inst = 0; UE_inst<NB_UE_INST;UE_inst++) {
775
	  current_UE_rx_timestamp[UE_inst][CC_id] += PHY_vars_UE_g[UE_inst][CC_id]->frame_parms.samples_per_tti;
776
	  LOG_D(EMU,"UE %d/%d: TS %llu\n",UE_id,CC_id,current_UE_rx_timestamp[UE_inst][CC_id]);
777 778
        }

779 780 781 782 783 784
        for (eNB_inst = oai_emulation.info.first_enb_local;
             (eNB_inst
              < (oai_emulation.info.first_enb_local
                 + oai_emulation.info.nb_enb_local));
             eNB_inst++) {
          if (oai_emulation.info.cli_start_enb[eNB_inst] != 0) {
785
        
786
	    /*
787 788 789 790 791 792 793 794 795
	    LOG_D(EMU,
		  "PHY procedures eNB %d for frame %d, subframe %d TDD %d/%d Nid_cell %d\n",
		  eNB_inst,
		  frame % MAX_FRAME_NUMBER,
		  sf,
		  PHY_vars_eNB_g[eNB_inst][0]->frame_parms.frame_type,
		  PHY_vars_eNB_g[eNB_inst][0]->frame_parms.tdd_config,
		  PHY_vars_eNB_g[eNB_inst][0]->frame_parms.Nid_cell);
            
796
	    */
797
#ifdef OPENAIR2
798
	    //Application: traffic gen
799
            update_otg_eNB (eNB_inst, oai_emulation.info.time_ms);
800

801 802
            //IP/OTG to PDCP and PDCP to IP operation
            //        pdcp_run (frame, 1, 0, eNB_inst); //PHY_vars_eNB_g[eNB_id]->Mod_id
803
#endif
804
           
805

806
#ifdef PRINT_STATS
807

808
            if((sf==9) && frame%10==0)
809
              if(eNB_avg_thr)
810 811
                fprintf(eNB_avg_thr,"%d %d\n",RC.eNB[eNB_inst][0]->proc.proc_rxtx[sf&1].frame_tx,
                        (RC.eNB[eNB_inst][0]->total_system_throughput)/((RC.eNB[eNB_inst][0]->proc.proc_rxtx[sf&1].frame_tx+1)*10));
812
	    /*
813
            if (eNB_stats[eNB_inst]) {
814
              len = dump_eNB_stats(RC.eNB[eNB_inst][0], stats_buffer, 0);
815 816 817 818
              rewind (eNB_stats[eNB_inst]);
              fwrite (stats_buffer, 1, len, eNB_stats[eNB_inst]);
              fflush(eNB_stats[eNB_inst]);
            }
819
#ifdef OPENAIR2
820 821 822 823 824 825 826 827

            if (eNB_l2_stats) {
              len = dump_eNB_l2_stats (stats_buffer, 0);
              rewind (eNB_l2_stats);
              fwrite (stats_buffer, 1, len, eNB_l2_stats);
              fflush(eNB_l2_stats);
            }

828
#endif
829
*/
830
#endif
831
          }
832
        }// eNB_inst loop
Lionel Gauthier's avatar
Lionel Gauthier committed
833

834

835
#if defined(ENABLE_ITTI)
836
        log_set_instance_type (LOG_INSTANCE_UE);
837 838
#endif

839

840 841 842 843 844
	if ((sf == 0) && ((frame % MAX_FRAME_NUMBER) == 0) && (abstraction_flag == 0)
	    && (oai_emulation.info.n_frames == 1)) {
	  
	  write_output ("dlchan0.m",
			"dlch0",
845
			&(PHY_vars_UE_g[0][0]->common_vars.common_vars_rx_data_per_thread[0].dl_ch_estimates[0][0][0]),
846 847 848 849 850
			(6
			 * (PHY_vars_UE_g[0][0]->frame_parms.ofdm_symbol_size)),
			1, 1);
	  write_output ("dlchan1.m",
			"dlch1",
851
			&(PHY_vars_UE_g[0][0]->common_vars.common_vars_rx_data_per_thread[0].dl_ch_estimates[1][0][0]),
852 853 854 855 856
			(6
			 * (PHY_vars_UE_g[0][0]->frame_parms.ofdm_symbol_size)),
			1, 1);
	  write_output ("dlchan2.m",
			"dlch2",
857
			&(PHY_vars_UE_g[0][0]->common_vars.common_vars_rx_data_per_thread[0].dl_ch_estimates[2][0][0]),
858 859 860 861 862 863 864 865 866
			(6
			 * (PHY_vars_UE_g[0][0]->frame_parms.ofdm_symbol_size)),
			1, 1);
	  write_output ("pbch_rxF_comp0.m",
			"pbch_comp0",
			PHY_vars_UE_g[0][0]->pbch_vars[0]->rxdataF_comp[0],
			6 * 12 * 4, 1, 1);
	  write_output ("pbch_rxF_llr.m", "pbch_llr",
			PHY_vars_UE_g[0][0]->pbch_vars[0]->llr,
867
			(PHY_vars_UE_g[0][0]->frame_parms.Ncp == 0) ? 1920 : 1728, 1,
868 869 870 871 872
			4);
	}
    
	stop_meas (&oaisim_stats_f);
      } // SUBFRAME INNER PART
873 874


875
    }
876
    update_ocm ();
877
    /*
878
    if ((frame >= 10) && (frame <= 11) && (abstraction_flag == 0)
879
#ifdef PROC
880
	&&(Channel_Flag==0)
881
#endif
882
	) {
883 884
      sprintf (fname, "UEtxsig%d.m", frame % MAX_FRAME_NUMBER);
      sprintf (vname, "txs%d", frame % MAX_FRAME_NUMBER);
885
      write_output (fname,
886 887 888 889 890
		    vname,
		    PHY_vars_UE_g[0][0]->common_vars.txdata[0],
		    PHY_vars_UE_g[0][0]->frame_parms.samples_per_tti
		    * 10,
		    1, 1);
891 892
      sprintf (fname, "eNBtxsig%d.m", frame % MAX_FRAME_NUMBER);
      sprintf (vname, "txs%d", frame % MAX_FRAME_NUMBER);
893
      write_output (fname,
894 895 896 897 898
		    vname,
		    PHY_vars_eNB_g[0][0]->common_vars.txdata[0][0],
		    PHY_vars_UE_g[0][0]->frame_parms.samples_per_tti
		    * 10,
		    1, 1);
899 900
      sprintf (fname, "eNBtxsigF%d.m", frame % MAX_FRAME_NUMBER);
      sprintf (vname, "txsF%d", frame % MAX_FRAME_NUMBER);
901
      write_output (fname,
902 903 904 905 906
		    vname,
		    PHY_vars_eNB_g[0][0]->common_vars.txdataF[0][0],
		    PHY_vars_eNB_g[0][0]->frame_parms.symbols_per_tti
		    * PHY_vars_eNB_g[0][0]->frame_parms.ofdm_symbol_size,
		    1, 1);
907 908
      sprintf (fname, "UErxsig%d.m", frame % MAX_FRAME_NUMBER);
      sprintf (vname, "rxs%d", frame % MAX_FRAME_NUMBER);
909
      write_output (fname,
910 911 912 913 914
		    vname,
		    PHY_vars_UE_g[0][0]->common_vars.rxdata[0],
		    PHY_vars_UE_g[0][0]->frame_parms.samples_per_tti
		    * 10,
		    1, 1);
915 916
      sprintf (fname, "eNBrxsig%d.m", frame % MAX_FRAME_NUMBER);
      sprintf (vname, "rxs%d", frame % MAX_FRAME_NUMBER);
917
      write_output (fname,
918 919 920 921 922
		    vname,
		    PHY_vars_eNB_g[0][0]->common_vars.rxdata[0][0],
		    PHY_vars_UE_g[0][0]->frame_parms.samples_per_tti
		    * 10,
		    1, 1);
923
    }
924
    */
925
    
926 927
    //#ifdef XFORMS
    if (xforms==1) {
928 929 930 931 932 933 934 935 936 937
      eNB_inst = 0;
      
      for (UE_inst = 0; UE_inst < NB_UE_INST; UE_inst++) {
	for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
	  phy_scope_UE(form_ue[CC_id][UE_inst],
		   PHY_vars_UE_g[UE_inst][CC_id],
		   eNB_inst,
		   UE_inst,
		   7);
	}
938 939 940 941
	if (RC.eNB && RC.eNB[eNB_inst] && RC.eNB[eNB_inst][0] )
	  phy_scope_eNB(form_enb[UE_inst],
			RC.eNB[eNB_inst][0],
			UE_inst);
942
	
943 944 945
      }
    }
    //#endif
946
    
947
#ifdef SMBV
948
    
949
    // Rohde&Schwarz SMBV100A vector signal generator
950
    if ((frame % MAX_FRAME_NUMBER == config_frames[0]) || (frame % MAX_FRAME_NUMBER == config_frames[1]) || (frame % MAX_FRAME_NUMBER == config_frames[2]) || (frame % MAX_FRAME_NUMBER == config_frames[3])) {
951
      smbv_frame_cnt++;
Lionel Gauthier's avatar
Lionel Gauthier committed
952
    }
953
    
954
#endif
955 956
    
  } // frame loop
Lionel Gauthier's avatar
Lionel Gauthier committed
957

958
  stop_meas (&oaisim_stats);
959
  oai_shutdown ();
960
  
961
#ifdef PRINT_STATS
962
  
963 964 965
  for (UE_inst=0; UE_inst<NB_UE_INST; UE_inst++) {
    if (UE_stats[UE_inst])
      fclose (UE_stats[UE_inst]);
966
    
967 968 969
    if(UE_stats_th[UE_inst])
      fclose (UE_stats_th[UE_inst]);
  }
970
  
971 972 973 974
  for (eNB_inst=0; eNB_inst<NB_eNB_INST; eNB_inst++) {
    if (eNB_stats[eNB_inst])
      fclose (eNB_stats[eNB_inst]);
  }
975
  
976
  if (eNB_avg_thr)
977
    fclose (eNB_avg_thr);
978
  
979
  if (eNB_l2_stats)
980
    fclose (eNB_l2_stats);
981
  
982
#endif
983
  
984 985 986
#if defined(ENABLE_ITTI)
  itti_terminate_tasks(TASK_L2L1);
#endif
987
  
988
  return NULL;
989
}
Lionel Gauthier's avatar
Lionel Gauthier committed
990

991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007
/*
 * The following two functions are meant to restart *the lte-softmodem* and are
 * here to make oaisim compile. A restart command from the controller will be
 * ignored in oaisim.
 */
int stop_L1L2(int enb_id)
{
  LOG_W(FLEXRAN_AGENT, "stop_L1L2() not supported in oaisim\n");
  return 0;
}

int restart_L1L2(int enb_id)
{
  LOG_W(FLEXRAN_AGENT, "restart_L1L2() not supported in oaisim\n");
  return 0;
}

Cedric Roux's avatar
Cedric Roux committed
1008 1009 1010
#if T_TRACER
int T_wait = 1;       /* by default we wait for the tracer */
int T_port = 2021;    /* default port to listen to to wait for the tracer */
1011
int T_dont_fork = 0;  /* default is to fork, see 'T_init' to understand */
Cedric Roux's avatar
Cedric Roux committed
1012 1013
#endif

1014

1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
void wait_RUs() {

  int i;

  // wait for all RUs to be configured over fronthaul
  pthread_mutex_lock(&RC.ru_mutex);



  while (RC.ru_mask>0) {
    pthread_cond_wait(&RC.ru_cond,&RC.ru_mutex);
  }

  // copy frame parameters from RU to UEs
  for (i=0;i<NB_UE_INST;i++) {
    PHY_vars_UE_g[i][0]->frame_parms.N_RB_DL              = RC.ru[0]->frame_parms.N_RB_DL;
1031
    PHY_vars_UE_g[i][0]->frame_parms.N_RB_UL              = RC.ru[0]->frame_parms.N_RB_UL;
1032 1033
    PHY_vars_UE_g[i][0]->frame_parms.nb_antennas_tx       = 1;
    PHY_vars_UE_g[i][0]->frame_parms.nb_antennas_rx       = 1;
1034 1035
    // set initially to 2, it will be revised after initial synchronization
    PHY_vars_UE_g[i][0]->frame_parms.nb_antenna_ports_eNB = 2;
1036
    PHY_vars_UE_g[i][0]->frame_parms.tdd_config = 1;
1037 1038 1039
    PHY_vars_UE_g[i][0]->frame_parms.dl_CarrierFreq       = RC.ru[0]->frame_parms.dl_CarrierFreq;
    PHY_vars_UE_g[i][0]->frame_parms.ul_CarrierFreq       = RC.ru[0]->frame_parms.ul_CarrierFreq;
    PHY_vars_UE_g[i][0]->frame_parms.eutra_band           = RC.ru[0]->frame_parms.eutra_band;
1040 1041 1042 1043 1044 1045 1046 1047
    LOG_I(PHY,"Initializing UE %d frame parameters from RU information: N_RB_DL %d, p %d, dl_Carrierfreq %u, ul_CarrierFreq %u, eutra_band %d\n",
	  i,
	  PHY_vars_UE_g[i][0]->frame_parms.N_RB_DL,
	  PHY_vars_UE_g[i][0]->frame_parms.nb_antenna_ports_eNB,
	  PHY_vars_UE_g[i][0]->frame_parms.dl_CarrierFreq,
	  PHY_vars_UE_g[i][0]->frame_parms.ul_CarrierFreq,
	  PHY_vars_UE_g[i][0]->frame_parms.eutra_band);

1048
    current_UE_rx_timestamp[i][0] = RC.ru[0]->frame_parms.samples_per_tti + RC.ru[0]->frame_parms.ofdm_symbol_size + RC.ru[0]->frame_parms.nb_prefix_samples0;
1049 1050 1051

  }
  
1052 1053 1054
  


1055 1056 1057 1058 1059
  for (ru_id=0;ru_id<RC.nb_RU;ru_id++) current_ru_rx_timestamp[ru_id][0] = RC.ru[ru_id]->frame_parms.samples_per_tti;

  printf("RUs are ready, let's go\n");
}

1060
void init_UE(int,int,int,int);
1061 1062
void init_RU(const char*);

1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
void set_UE_defaults(int nb_ue) {

  for (int UE_id = 0;UE_id<nb_ue;UE_id++) {
    for (int CC_id = 0;CC_id<MAX_NUM_CCs;CC_id++) {
      for (uint8_t i=0; i<RX_NB_TH_MAX; i++) {
	PHY_vars_UE_g[UE_id][CC_id]->pdcch_vars[i][0]->dciFormat      = 0;
	PHY_vars_UE_g[UE_id][CC_id]->pdcch_vars[i][0]->agregationLevel      = 0xFF;
      }
      PHY_vars_UE_g[UE_id][CC_id]->current_dlsch_cqi[0] = 10;
    }
  }
}

1076

Cedric Roux's avatar
Cedric Roux committed
1077 1078 1079 1080 1081 1082 1083 1084 1085
static void print_current_directory(void)
{
  char dir[8192]; /* arbitrary size (should be big enough) */
  if (getcwd(dir, 8192) == NULL)
    printf("ERROR getting working directory\n");
  else
    printf("working directory: %s\n", dir);
}

Lionel Gauthier's avatar
Lionel Gauthier committed
1086 1087
/*------------------------------------------------------------------------------*/
int
1088 1089
main (int argc, char **argv)
{
1090

1091
  clock_t t;
1092

Cedric Roux's avatar
Cedric Roux committed
1093 1094
  print_current_directory();

1095 1096
  start_background_system();

1097
#ifdef SMBV
1098 1099
  // Rohde&Schwarz SMBV100A vector signal generator
  strcpy(smbv_ip,DEFAULT_SMBV_IP);
1100 1101 1102
#endif

#ifdef PROC
1103 1104
  int node_id;
  int port,Process_Flag=0,wgt,Channel_Flag=0,temp;
1105
#endif
1106
  int i;
1107

1108
  //default parameters
1109
  oai_emulation.info.n_frames = MAX_FRAME_NUMBER; //1024;          //10;
1110 1111
  oai_emulation.info.n_frames_flag = 0; //fixme
  snr_dB = 30;
1112

1113 1114 1115
  //Default values if not changed by the user in get_simulation_options();
  pdcp_period = 1;
  omg_period = 1;
1116 1117 1118 1119
  //Clean ip rule table
  for(int i =0; i<NUMBER_OF_UE_MAX; i++){
      char command_line[100];
      sprintf(command_line, "while ip rule del table %d; do true; done",i+201);
Cedric Roux's avatar
Cedric Roux committed
1120 1121 1122 1123
      /* we don't care about return value from system(), but let's the
       * compiler be silent, so let's do "if (XX);"
       */
      if (system(command_line)) /* nothing */;
1124
  }
1125 1126
  // start thread for log gen
  log_thread_init ();
1127

1128
  init_oai_emulation (); // to initialize everything !!!
1129

1130 1131
  // get command-line options
  get_simulation_options (argc, argv); //Command-line options
1132

Cedric Roux's avatar
Cedric Roux committed
1133
#if T_TRACER
1134
  T_init(T_port, T_wait, T_dont_fork);
Cedric Roux's avatar
Cedric Roux committed
1135 1136
#endif

1137
  // Initialize VCD LOG module
1138
  VCD_SIGNAL_DUMPER_INIT (oai_emulation.info.vcd_file);
1139

1140
#if !defined(ENABLE_ITTI)
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161
  pthread_t tid;
  int err;
  sigset_t sigblock;
  sigemptyset (&sigblock);
  sigaddset (&sigblock, SIGHUP);
  sigaddset (&sigblock, SIGINT);
  sigaddset (&sigblock, SIGTERM);
  sigaddset (&sigblock, SIGQUIT);
  //sigaddset(&sigblock, SIGKILL);

  if ((err = pthread_sigmask (SIG_BLOCK, &sigblock, NULL)) != 0) {
    printf ("SIG_BLOCK error\n");
    return -1;
  }

  if (pthread_create (&tid, NULL, sigh, NULL)) {
    printf ("Pthread for tracing Signals is not created!\n");
    return -1;
  } else {
    printf ("Pthread for tracing Signals is created!\n");
  }
1162

1163 1164 1165 1166 1167 1168 1169 1170 1171
#endif
  // configure oaisim with OCG
  oaisim_config (); // config OMG and OCG, OPT, OTG, OLG

  if (ue_connection_test == 1) {
    snr_direction = -snr_step;
    snr_dB = 20;
    sinr_dB = -20;
  }
1172

1173 1174 1175 1176
  pthread_cond_init(&sync_cond,NULL);
  pthread_mutex_init(&sync_mutex, NULL);
  pthread_mutex_init(&subframe_mutex, NULL);

1177
#ifdef OPENAIR2
1178
  init_omv ();
1179
#endif
1180 1181
  //Before this call, NB_UE_INST and NB_eNB_INST are not set correctly
  check_and_adjust_params ();
1182

1183
  set_seed = oai_emulation.emulation_config.seed.value;
1184

1185
  init_otg_pdcp_buffer ();
1186

1187
  init_seed (set_seed);
1188

1189

1190
  init_RU(NULL);
1191

1192
  init_devices ();
1193

1194
  //  init_openair2 ();
1195
  //  init_openair0();
1196 1197 1198



1199

1200
  if (create_tasks_ue(oai_emulation.info.nb_ue_local) < 0) 
1201
      exit(-1); // need a softer mode
1202 1203 1204 1205


  printf("Waiting for RUs to get set up\n"); 
  wait_RUs();
1206

1207 1208 1209 1210
  init_UE(NB_UE_INST,0,0,1);

  set_UE_defaults(NB_UE_INST);

1211

1212
  init_ocm ();
1213 1214
  printf("Sending sync to all threads\n");

1215

1216 1217 1218 1219
  pthread_mutex_lock(&sync_mutex);
  sync_var=0;
  pthread_cond_broadcast(&sync_cond);
  pthread_mutex_unlock(&sync_mutex);
1220 1221

#ifdef SMBV
1222 1223
  // Rohde&Schwarz SMBV100A vector signal generator
  smbv_init_config(smbv_fname, smbv_nframes);
1224
  smbv_write_config_from_frame_parms(smbv_fname, &PHY_vars_eNB_g[0][0]->frame_parms);
1225
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1226

1227 1228
  /* #if defined (FLEXRAN_AGENT_SB_IF)
  flexran_agent_start();
1229
  #endif */ 
1230

1231 1232 1233 1234 1235 1236 1237
  // add events to future event list: Currently not used
  //oai_emulation.info.oeh_enabled = 1;
  if (oai_emulation.info.oeh_enabled == 1)
    schedule_events ();

  // oai performance profiler is enabled
  if (oai_emulation.info.opp_enabled == 1)
Raymond Knopp's avatar
Raymond Knopp committed
1238
    reset_opp_meas_oaisim ();
Lionel Gauthier's avatar
Lionel Gauthier committed
1239

Cedric Roux's avatar
Cedric Roux committed
1240 1241
  cpuf=get_cpu_freq_GHz();

1242
  init_time ();
1243

1244
  init_slot_isr ();
1245

1246
  t = clock ();
1247

1248 1249
  LOG_N(EMU,
        ">>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU initialization done <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
1250

Cedric Roux's avatar
Cedric Roux committed
1251 1252 1253 1254 1255
#ifndef PACKAGE_VERSION
#  define PACKAGE_VERSION "UNKNOWN-EXPERIMENTAL"
#endif
  LOG_I(EMU, "Version: %s\n", PACKAGE_VERSION);

1256
#if defined(ENABLE_ITTI)
1257 1258

  // Handle signals until all tasks are terminated
1259 1260
  itti_wait_tasks_end();

1261
#else
1262 1263 1264 1265 1266 1267

  if (oai_emulation.info.nb_enb_local > 0) {
    eNB_app_task (NULL); // do nothing for the moment
  }

  l2l1_task (NULL);
1268
#endif
1269 1270 1271
  t = clock () - t;
  LOG_I(EMU, "Duration of the simulation: %f seconds\n",
        ((float) t) / CLOCKS_PER_SEC);
1272

1273 1274
  LOG_N(EMU,
        ">>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU Ending <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
1275

1276
  raise (SIGINT);
1277
  //  oai_shutdown ();
1278

1279
  return (0);
Lionel Gauthier's avatar
Lionel Gauthier committed
1280 1281 1282
}

void
Raymond Knopp's avatar
Raymond Knopp committed
1283
reset_opp_meas_oaisim (void)
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294
{
  uint8_t eNB_id = 0, UE_id = 0;

  reset_meas (&oaisim_stats);
  reset_meas (&oaisim_stats_f); // frame

  // init time stats here (including channel)
  reset_meas (&dl_chan_stats);
  reset_meas (&ul_chan_stats);

  for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
1295 1296
    reset_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc[0]);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc[1]);
Cedric Roux's avatar
Cedric Roux committed
1297 1298
    reset_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc_rx[0]);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc_rx[1]);
1299 1300
    reset_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc_tx);

1301
    //    reset_meas (&PHY_vars_UE_g[UE_id][0]->ofdm_demod_stats);
1302 1303 1304
    reset_meas (&PHY_vars_UE_g[UE_id][0]->rx_dft_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_channel_estimation_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_freq_offset_estimation_stats);
Cedric Roux's avatar
Cedric Roux committed
1305 1306
    reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_decoding_stats[0]);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_decoding_stats[1]);
1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330
    reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_rate_unmatching_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_turbo_decoding_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_deinterleaving_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_llr_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_unscrambling_stats);

    reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_init_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_alpha_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_beta_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_gamma_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_ext_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_intl1_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_intl2_stats);

    reset_meas (&PHY_vars_UE_g[UE_id][0]->tx_prach);

    reset_meas (&PHY_vars_UE_g[UE_id][0]->ofdm_mod_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_encoding_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_modulation_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_segmentation_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_rate_matching_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_turbo_encoding_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_interleaving_stats);
    reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_multiplexing_stats);
1331 1332


1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352
    /*
     * L2 functions
     */

    // UE MAC
    reset_meas (&UE_mac_inst[UE_id].ue_scheduler); // total
    reset_meas (&UE_mac_inst[UE_id].tx_ulsch_sdu); // inlcude rlc_data_req + mac header gen
    reset_meas (&UE_mac_inst[UE_id].rx_dlsch_sdu); // include mac_rrc_data_ind or mac_rlc_status_ind+mac_rlc_data_ind and  mac header parser
    reset_meas (&UE_mac_inst[UE_id].ue_query_mch);
    reset_meas (&UE_mac_inst[UE_id].rx_mch_sdu); // include rld_data_ind+ parse mch header
    reset_meas (&UE_mac_inst[UE_id].rx_si); // include rlc_data_ind + mac header parser

    reset_meas (&UE_pdcp_stats[UE_id].pdcp_run);
    reset_meas (&UE_pdcp_stats[UE_id].data_req);
    reset_meas (&UE_pdcp_stats[UE_id].data_ind);
    reset_meas (&UE_pdcp_stats[UE_id].apply_security);
    reset_meas (&UE_pdcp_stats[UE_id].validate_security);
    reset_meas (&UE_pdcp_stats[UE_id].pdcp_ip);
    reset_meas (&UE_pdcp_stats[UE_id].ip_pdcp);

1353
    
1354 1355 1356
  }

  for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) {
Lionel Gauthier's avatar
Lionel Gauthier committed
1357 1358

    for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
1359 1360 1361 1362 1363 1364 1365 1366
      reset_meas (&RU2UE[eNB_id][UE_id][0]->random_channel);
      reset_meas (&RU2UE[eNB_id][UE_id][0]->interp_time);
      reset_meas (&RU2UE[eNB_id][UE_id][0]->interp_freq);
      reset_meas (&RU2UE[eNB_id][UE_id][0]->convolution);
      reset_meas (&UE2RU[UE_id][eNB_id][0]->random_channel);
      reset_meas (&UE2RU[UE_id][eNB_id][0]->interp_time);
      reset_meas (&UE2RU[UE_id][eNB_id][0]->interp_freq);
      reset_meas (&UE2RU[UE_id][eNB_id][0]->convolution);
1367
    }
Lionel Gauthier's avatar
Lionel Gauthier committed
1368

1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399
    reset_meas (&RC.eNB[eNB_id][0]->phy_proc);
    reset_meas (&RC.eNB[eNB_id][0]->phy_proc_rx);
    reset_meas (&RC.eNB[eNB_id][0]->phy_proc_tx);
    reset_meas (&RC.eNB[eNB_id][0]->rx_prach);

    reset_meas (&RC.eNB[eNB_id][0]->ofdm_mod_stats);
    reset_meas (&RC.eNB[eNB_id][0]->dlsch_encoding_stats);
    reset_meas (&RC.eNB[eNB_id][0]->dlsch_modulation_stats);
    reset_meas (&RC.eNB[eNB_id][0]->dlsch_scrambling_stats);
    reset_meas (&RC.eNB[eNB_id][0]->dlsch_rate_matching_stats);
    reset_meas (&RC.eNB[eNB_id][0]->dlsch_turbo_encoding_stats);
    reset_meas (&RC.eNB[eNB_id][0]->dlsch_interleaving_stats);

    //    reset_meas (&RC.eNB[eNB_id][0]->ofdm_demod_stats);
    //reset_meas(&RC.eNB[eNB_id]->rx_dft_stats);
    //reset_meas(&RC.eNB[eNB_id]->ulsch_channel_estimation_stats);
    //reset_meas(&RC.eNB[eNB_id]->ulsch_freq_offset_estimation_stats);
    reset_meas (&RC.eNB[eNB_id][0]->ulsch_decoding_stats);
    reset_meas (&RC.eNB[eNB_id][0]->ulsch_demodulation_stats);
    reset_meas (&RC.eNB[eNB_id][0]->ulsch_rate_unmatching_stats);
    reset_meas (&RC.eNB[eNB_id][0]->ulsch_turbo_decoding_stats);
    reset_meas (&RC.eNB[eNB_id][0]->ulsch_deinterleaving_stats);
    reset_meas (&RC.eNB[eNB_id][0]->ulsch_demultiplexing_stats);
    reset_meas (&RC.eNB[eNB_id][0]->ulsch_llr_stats);
    reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_init_stats);
    reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_alpha_stats);
    reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_beta_stats);
    reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_gamma_stats);
    reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_ext_stats);
    reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_intl1_stats);
    reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_intl2_stats);
1400
#ifdef LOCALIZATION
1401
    reset_meas(&RC.eNB[eNB_id][0]->localization_stats);
1402
#endif
Lionel Gauthier's avatar
Lionel Gauthier committed
1403

1404 1405 1406 1407
    /*
     * L2 functions
     */
    // eNB MAC
1408 1409 1410 1411 1412 1413 1414 1415 1416
    reset_meas (&RC.mac[eNB_id]->eNB_scheduler); // total
    reset_meas (&RC.mac[eNB_id]->schedule_si); // only schedule + tx
    reset_meas (&RC.mac[eNB_id]->schedule_ra); // only ra
    reset_meas (&RC.mac[eNB_id]->schedule_ulsch); // onlu ulsch
    reset_meas (&RC.mac[eNB_id]->fill_DLSCH_dci); // only dci
    reset_meas (&RC.mac[eNB_id]->schedule_dlsch_preprocessor); // include rlc_data_req + MAC header gen
    reset_meas (&RC.mac[eNB_id]->schedule_dlsch); // include rlc_data_req + MAC header gen + pre-processor
    reset_meas (&RC.mac[eNB_id]->schedule_mch); // only embms
    reset_meas (&RC.mac[eNB_id]->rx_ulsch_sdu); // include rlc_data_ind + mac header parser
1417 1418 1419 1420 1421 1422 1423 1424 1425 1426

    reset_meas (&eNB_pdcp_stats[eNB_id].pdcp_run);
    reset_meas (&eNB_pdcp_stats[eNB_id].data_req);
    reset_meas (&eNB_pdcp_stats[eNB_id].data_ind);
    reset_meas (&eNB_pdcp_stats[eNB_id].apply_security);
    reset_meas (&eNB_pdcp_stats[eNB_id].validate_security);
    reset_meas (&eNB_pdcp_stats[eNB_id].pdcp_ip);
    reset_meas (&eNB_pdcp_stats[eNB_id].ip_pdcp);

  }
Lionel Gauthier's avatar
Lionel Gauthier committed
1427
}
1428

Lionel Gauthier's avatar
Lionel Gauthier committed
1429
void
Raymond Knopp's avatar
Raymond Knopp committed
1430
print_opp_meas_oaisim (void)
1431
{
Lionel Gauthier's avatar
Lionel Gauthier committed
1432

1433
  uint8_t eNB_id = 0, UE_id = 0;
1434

1435 1436 1437 1438
  print_meas (&oaisim_stats, "[OAI][total_exec_time]", &oaisim_stats,
              &oaisim_stats);
  print_meas (&oaisim_stats_f, "[OAI][SF_exec_time]", &oaisim_stats,
              &oaisim_stats_f);
1439

1440 1441 1442 1443
  print_meas (&dl_chan_stats, "[DL][chan_stats]", &oaisim_stats,
              &oaisim_stats_f);
  print_meas (&ul_chan_stats, "[UL][chan_stats]", &oaisim_stats,
              &oaisim_stats_f);
Lionel Gauthier's avatar
Lionel Gauthier committed
1444

1445
  for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
1446 1447
    for (ru_id = 0; ru_id < NB_RU; ru_id++) {
      print_meas (&RU2UE[ru_id][UE_id][0]->random_channel,
1448
                  "[DL][random_channel]", &oaisim_stats, &oaisim_stats_f);
1449
      print_meas (&RU2UE[ru_id][UE_id][0]->interp_time,
1450
                  "[DL][interp_time]", &oaisim_stats, &oaisim_stats_f);
1451
      print_meas (&RU2UE[ru_id][UE_id][0]->interp_freq,
1452
                  "[DL][interp_freq]", &oaisim_stats, &oaisim_stats_f);
1453
      print_meas (&RU2UE[ru_id][UE_id][0]->convolution,
1454 1455
                  "[DL][convolution]", &oaisim_stats, &oaisim_stats_f);

1456
      print_meas (&UE2RU[UE_id][ru_id][0]->random_channel,
1457
                  "[UL][random_channel]", &oaisim_stats, &oaisim_stats_f);
1458
      print_meas (&UE2RU[UE_id][ru_id][0]->interp_time,
1459
                  "[UL][interp_time]", &oaisim_stats, &oaisim_stats_f);
1460
      print_meas (&UE2RU[UE_id][ru_id][0]->interp_freq,
1461
                  "[UL][interp_freq]", &oaisim_stats, &oaisim_stats_f);
1462
      print_meas (&UE2RU[UE_id][ru_id][0]->convolution,
1463
                  "[UL][convolution]", &oaisim_stats, &oaisim_stats_f);
Raymond Knopp's avatar
 
Raymond Knopp committed
1464
    }
1465 1466 1467
  }

  for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
1468 1469 1470
    print_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc[0], "[UE][total_phy_proc[0]]",
                &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc[1], "[UE][total_phy_proc[1]]",
1471 1472
                &oaisim_stats, &oaisim_stats_f);

1473

1474 1475
    print_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc_rx,
                "[UE][total_phy_proc_rx]", &oaisim_stats, &oaisim_stats_f);
1476 1477
    //    print_meas (&PHY_vars_UE_g[UE_id][0]->ofdm_demod_stats,
    //                "[UE][ofdm_demod]", &oaisim_stats, &oaisim_stats_f);
1478 1479 1480 1481 1482 1483 1484 1485 1486 1487
    print_meas (&PHY_vars_UE_g[UE_id][0]->rx_dft_stats, "[UE][rx_dft]",
                &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_channel_estimation_stats,
                "[UE][channel_est]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_freq_offset_estimation_stats,
                "[UE][freq_offset]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_llr_stats, "[UE][llr]",
                &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_unscrambling_stats,
                "[UE][unscrambling]", &oaisim_stats, &oaisim_stats_f);
Cedric Roux's avatar
Cedric Roux committed
1488 1489 1490 1491
    print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_decoding_stats[0],
                "[UE][decoding[0]]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_decoding_stats[1],
                "[UE][decoding[1]]", &oaisim_stats, &oaisim_stats_f);
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534
    print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_rate_unmatching_stats,
                "[UE][rate_unmatching]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_deinterleaving_stats,
                "[UE][deinterleaving]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_turbo_decoding_stats,
                "[UE][turbo_decoding]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_init_stats,
                "[UE][ |_tc_init]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_alpha_stats,
                "[UE][ |_tc_alpha]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_beta_stats,
                "[UE][ |_tc_beta]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_gamma_stats,
                "[UE][ |_tc_gamma]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_ext_stats,
                "[UE][ |_tc_ext]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_intl1_stats,
                "[UE][ |_tc_intl1]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_intl2_stats,
                "[UE][ |_tc_intl2]", &oaisim_stats, &oaisim_stats_f);

    print_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc_tx,
                "[UE][total_phy_proc_tx]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->ofdm_mod_stats, "[UE][ofdm_mod]",
                &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_modulation_stats,
                "[UE][modulation]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_encoding_stats,
                "[UE][encoding]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_segmentation_stats,
                "[UE][segmentation]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_rate_matching_stats,
                "[UE][rate_matching]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_turbo_encoding_stats,
                "[UE][turbo_encoding]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_interleaving_stats,
                "[UE][interleaving]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_multiplexing_stats,
                "[UE][multiplexing]", &oaisim_stats, &oaisim_stats_f);

  }

  for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) {
1535
    print_meas (&RC.eNB[eNB_id][0]->phy_proc,
1536 1537
                "[eNB][total_phy_proc]", &oaisim_stats, &oaisim_stats_f);

1538
    print_meas (&RC.eNB[eNB_id][0]->phy_proc_tx,
1539
                "[eNB][total_phy_proc_tx]", &oaisim_stats, &oaisim_stats_f);
1540
    print_meas (&RC.eNB[eNB_id][0]->ofdm_mod_stats,
1541
                "[eNB][ofdm_mod]", &oaisim_stats, &oaisim_stats_f);
1542
    print_meas (&RC.eNB[eNB_id][0]->dlsch_modulation_stats,
1543
                "[eNB][modulation]", &oaisim_stats, &oaisim_stats_f);
1544
    print_meas (&RC.eNB[eNB_id][0]->dlsch_scrambling_stats,
1545
                "[eNB][scrambling]", &oaisim_stats, &oaisim_stats_f);
1546
    print_meas (&RC.eNB[eNB_id][0]->dlsch_encoding_stats,
1547
                "[eNB][encoding]", &oaisim_stats, &oaisim_stats_f);
1548
    print_meas (&RC.eNB[eNB_id][0]->dlsch_interleaving_stats,
1549
                "[eNB][|_interleaving]", &oaisim_stats, &oaisim_stats_f);
1550
    print_meas (&RC.eNB[eNB_id][0]->dlsch_rate_matching_stats,
1551
                "[eNB][|_rate_matching]", &oaisim_stats, &oaisim_stats_f);
1552
    print_meas (&RC.eNB[eNB_id][0]->dlsch_turbo_encoding_stats,
1553 1554
                "[eNB][|_turbo_encoding]", &oaisim_stats, &oaisim_stats_f);

1555
    print_meas (&RC.eNB[eNB_id][0]->phy_proc_rx,
1556
                "[eNB][total_phy_proc_rx]", &oaisim_stats, &oaisim_stats_f);
1557 1558 1559 1560 1561 1562
    //    print_meas (&RC.eNB[eNB_id][0]->ofdm_demod_stats,
    //                "[eNB][ofdm_demod]", &oaisim_stats, &oaisim_stats_f);
    //print_meas(&RC.eNB[eNB_id][0]->ulsch_channel_estimation_stats,"[eNB][channel_est]");
    //print_meas(&RC.eNB[eNB_id][0]->ulsch_freq_offset_estimation_stats,"[eNB][freq_offset]");
    //print_meas(&RC.eNB[eNB_id][0]->rx_dft_stats,"[eNB][rx_dft]");
    print_meas (&RC.eNB[eNB_id][0]->ulsch_demodulation_stats,
1563
                "[eNB][demodulation]", &oaisim_stats, &oaisim_stats_f);
1564
    print_meas (&RC.eNB[eNB_id][0]->ulsch_decoding_stats,
1565
                "[eNB][decoding]", &oaisim_stats, &oaisim_stats_f);
1566
    print_meas (&RC.eNB[eNB_id][0]->ulsch_deinterleaving_stats,
1567
                "[eNB][|_deinterleaving]", &oaisim_stats, &oaisim_stats_f);
1568
    print_meas (&RC.eNB[eNB_id][0]->ulsch_demultiplexing_stats,
1569
                "[eNB][|_demultiplexing]", &oaisim_stats, &oaisim_stats_f);
1570
    print_meas (&RC.eNB[eNB_id][0]->ulsch_rate_unmatching_stats,
1571
                "[eNB][|_rate_unmatching]", &oaisim_stats, &oaisim_stats_f);
1572
    print_meas (&RC.eNB[eNB_id][0]->ulsch_turbo_decoding_stats,
1573
                "[eNB][|_turbo_decoding]", &oaisim_stats, &oaisim_stats_f);
1574
    print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_init_stats,
1575
                "[eNB][ |_tc_init]", &oaisim_stats, &oaisim_stats_f);
1576
    print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_alpha_stats,
1577
                "[eNB][ |_tc_alpha]", &oaisim_stats, &oaisim_stats_f);
1578
    print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_beta_stats,
1579
                "[eNB][ |_tc_beta]", &oaisim_stats, &oaisim_stats_f);
1580
    print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_gamma_stats,
1581
                "[eNB][ |_tc_gamma]", &oaisim_stats, &oaisim_stats_f);
1582
    print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_ext_stats,
1583
                "[eNB][ |_tc_ext]", &oaisim_stats, &oaisim_stats_f);
1584
    print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_intl1_stats,
1585
                "[eNB][ |_tc_intl1]", &oaisim_stats, &oaisim_stats_f);
1586
    print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_intl2_stats,
1587 1588
                "[eNB][ |_tc_intl2]", &oaisim_stats, &oaisim_stats_f);

1589
    print_meas (&RC.eNB[eNB_id][0]->rx_prach, "[eNB][rx_prach]",
1590
                &oaisim_stats, &oaisim_stats_f);
1591

1592
#ifdef LOCALIZATION
1593
    print_meas(&RC.eNB[eNB_id][0]->localization_stats, "[eNB][LOCALIZATION]",&oaisim_stats,&oaisim_stats_f);
1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610
#endif
  }

  for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {

    print_meas (&UE_mac_inst[UE_id].ue_scheduler, "[UE][mac_scheduler]",
                &oaisim_stats, &oaisim_stats_f);
    print_meas (&UE_mac_inst[UE_id].tx_ulsch_sdu, "[UE][tx_ulsch_sdu]",
                &oaisim_stats, &oaisim_stats_f);
    print_meas (&UE_mac_inst[UE_id].rx_dlsch_sdu, "[UE][rx_dlsch_sdu]",
                &oaisim_stats, &oaisim_stats_f);
    print_meas (&UE_mac_inst[UE_id].ue_query_mch, "[UE][query_MCH]",
                &oaisim_stats, &oaisim_stats_f);
    print_meas (&UE_mac_inst[UE_id].rx_mch_sdu, "[UE][rx_mch_sdu]",
                &oaisim_stats, &oaisim_stats_f);
    print_meas (&UE_mac_inst[UE_id].rx_si, "[UE][rx_si]", &oaisim_stats,
                &oaisim_stats_f);
Lionel Gauthier's avatar
Lionel Gauthier committed
1611

1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632
    print_meas (&UE_pdcp_stats[UE_id].pdcp_run, "[UE][total_pdcp_run]",
                &oaisim_stats, &oaisim_stats_f);
    print_meas (&UE_pdcp_stats[UE_id].data_req, "[UE][DL][pdcp_data_req]",
                &oaisim_stats, &oaisim_stats_f);
    print_meas (&UE_pdcp_stats[UE_id].data_ind, "[UE][UL][pdcp_data_ind]",
                &oaisim_stats, &oaisim_stats_f);

    print_meas (&UE_pdcp_stats[UE_id].apply_security,
                "[UE][DL][apply_security]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&UE_pdcp_stats[UE_id].validate_security,
                "[UE][UL][validate_security]", &oaisim_stats,
                &oaisim_stats_f);
    print_meas (&UE_pdcp_stats[UE_id].ip_pdcp, "[UE][DL][ip_pdcp]",
                &oaisim_stats, &oaisim_stats_f);
    print_meas (&UE_pdcp_stats[UE_id].pdcp_ip, "[UE][UL][pdcp_ip]",
                &oaisim_stats, &oaisim_stats_f);

  }

  for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) {

1633
    print_meas (&RC.mac[eNB_id]->eNB_scheduler, "[eNB][mac_scheduler]",
1634
                &oaisim_stats, &oaisim_stats_f);
1635
    print_meas (&RC.mac[eNB_id]->schedule_si, "[eNB][DL][SI]",
1636
                &oaisim_stats, &oaisim_stats_f);
1637
    print_meas (&RC.mac[eNB_id]->schedule_ra, "[eNB][DL][RA]",
1638
                &oaisim_stats, &oaisim_stats_f);
1639
    print_meas (&RC.mac[eNB_id]->fill_DLSCH_dci,
1640
                "[eNB][DL/UL][fill_DCI]", &oaisim_stats, &oaisim_stats_f);
1641
    print_meas (&RC.mac[eNB_id]->schedule_dlsch_preprocessor,
1642
                "[eNB][DL][preprocessor]", &oaisim_stats, &oaisim_stats_f);
1643
    print_meas (&RC.mac[eNB_id]->schedule_dlsch,
1644 1645
                "[eNB][DL][schedule_tx_dlsch]", &oaisim_stats,
                &oaisim_stats_f);
1646
    print_meas (&RC.mac[eNB_id]->schedule_mch, "[eNB][DL][mch]",
1647
                &oaisim_stats, &oaisim_stats_f);
1648
    print_meas (&RC.mac[eNB_id]->schedule_ulsch, "[eNB][UL][ULSCH]",
1649
                &oaisim_stats, &oaisim_stats_f);
1650
    print_meas (&RC.mac[eNB_id]->rx_ulsch_sdu,
1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669
                "[eNB][UL][rx_ulsch_sdu]", &oaisim_stats, &oaisim_stats_f);

    print_meas (&eNB_pdcp_stats[eNB_id].pdcp_run, "[eNB][pdcp_run]",
                &oaisim_stats, &oaisim_stats_f);
    print_meas (&eNB_pdcp_stats[eNB_id].data_req,
                "[eNB][DL][pdcp_data_req]", &oaisim_stats, &oaisim_stats_f);
    print_meas (&eNB_pdcp_stats[eNB_id].data_ind,
                "[eNB][UL][pdcp_data_ind]", &oaisim_stats, &oaisim_stats_f);

    print_meas (&eNB_pdcp_stats[eNB_id].apply_security,
                "[eNB][DL][apply_security]", &oaisim_stats,
                &oaisim_stats_f);
    print_meas (&eNB_pdcp_stats[eNB_id].validate_security,
                "[eNB][UL][validate_security]", &oaisim_stats,
                &oaisim_stats_f);
    print_meas (&eNB_pdcp_stats[eNB_id].ip_pdcp, "[eNB][DL][ip_pdcp]",
                &oaisim_stats, &oaisim_stats_f);
    print_meas (&eNB_pdcp_stats[eNB_id].pdcp_ip, "[eNB][UL][pdcp_ip]",
                &oaisim_stats, &oaisim_stats_f);
Lionel Gauthier's avatar
Lionel Gauthier committed
1670

1671
  }
1672

Lionel Gauthier's avatar
Lionel Gauthier committed
1673
}
1674

Cedric Roux's avatar
Cedric Roux committed
1675
#if !defined(ENABLE_ITTI)
Lionel Gauthier's avatar
Lionel Gauthier committed
1676
static void *
1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705
sigh (void *arg)
{

  int signum;
  sigset_t sigcatch;
  sigemptyset (&sigcatch);
  sigaddset (&sigcatch, SIGHUP);
  sigaddset (&sigcatch, SIGINT);
  sigaddset (&sigcatch, SIGTERM);
  sigaddset (&sigcatch, SIGQUIT);

  for (;;) {
    sigwait (&sigcatch, &signum);

    //sigwait(&sigblock, &signum);
    switch (signum) {
    case SIGHUP:
    case SIGINT:
    case SIGTERM:
    case SIGQUIT:
      fprintf (stderr, "received signal %d \n", signum);
      // no need for mutx: when ITTI not used, this variable is only accessed by this function
      l2l1_state = L2L1_TERMINATED;
      break;

    default:
      fprintf (stderr, "Unexpected signal %d \n", signum);
      exit (-1);
      break;
Raymond Knopp's avatar
 
Raymond Knopp committed
1706
    }
1707 1708 1709
  }

  pthread_exit (NULL);
Lionel Gauthier's avatar
Lionel Gauthier committed
1710
}
Cedric Roux's avatar
Cedric Roux committed
1711
#endif /* !defined(ENABLE_ITTI) */
Raymond Knopp's avatar
 
Raymond Knopp committed
1712

Lionel Gauthier's avatar
Lionel Gauthier committed
1713
void
1714 1715 1716
oai_shutdown (void)
{
  static int done = 0;
Lionel Gauthier's avatar
Lionel Gauthier committed
1717

1718 1719
  if (done)
    return;
1720

1721 1722
  free (otg_pdcp_buffer);
  otg_pdcp_buffer = 0;
1723 1724

#ifdef SMBV
1725 1726 1727 1728 1729 1730

  // Rohde&Schwarz SMBV100A vector signal generator
  if (config_smbv) {
    smbv_send_config (smbv_fname,smbv_ip);
  }

1731 1732
#endif

1733
  //Perform KPI measurements
1734 1735
  if (oai_emulation.info.otg_enabled == 1){
    LOG_N(EMU,"calling OTG kpi gen .... \n");
1736
    kpi_gen ();
1737
  }
1738
  if (oai_emulation.info.opp_enabled == 1)
Raymond Knopp's avatar
Raymond Knopp committed
1739
    print_opp_meas_oaisim ();
Lionel Gauthier's avatar
Lionel Gauthier committed
1740

1741 1742

#ifdef PROC
1743 1744

  if (abstraction_flag == 0 && Channel_Flag==0 && Process_Flag==0)
1745
#else
1746
    if (abstraction_flag == 0)
1747
#endif
1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758
      {
	/*
	  #ifdef IFFT_FPGA
	  free(txdataF2[0]);
	  free(txdataF2[1]);
	  free(txdataF2);
	  free(txdata[0]);
	  free(txdata[1]);
	  free(txdata);
	  #endif
	*/
1759
	/*
1760 1761 1762 1763 1764 1765
	for (int i = 0; i < 2; i++) {
	  free (s_re[i]);
	  free (s_im[i]);
	  free (r_re[i]);
	  free (r_im[i]);
	}
Lionel Gauthier's avatar
Lionel Gauthier committed
1766

1767 1768 1769 1770 1771 1772 1773
	free (s_re);
	free (s_im);
	free (r_re);
	free (r_im);
	s_re = 0;
	s_im = 0;
	r_re = 0;
1774
	r_im = 0;*/
1775

1776 1777
	lte_sync_time_free ();
      }
1778 1779 1780 1781 1782 1783

  // added for PHY abstraction
  if (oai_emulation.info.ocm_enabled == 1) {
    for (eNB_inst = 0; eNB_inst < NUMBER_OF_eNB_MAX; eNB_inst++) {
      free (enb_data[eNB_inst]);
      enb_data[eNB_inst] = 0;
Lionel Gauthier's avatar
Lionel Gauthier committed
1784 1785
    }

1786 1787 1788 1789 1790
    for (UE_inst = 0; UE_inst < NUMBER_OF_UE_MAX; UE_inst++) {
      free (ue_data[UE_inst]);
      ue_data[UE_inst] = 0;
    }
  } //End of PHY abstraction changes
Lionel Gauthier's avatar
Lionel Gauthier committed
1791

1792

1793 1794
  // stop OMG
  stop_mobility_generator (omg_param_list); //omg_param_list.mobility_type
1795
#ifdef OPENAIR2
1796 1797 1798 1799

  if (oai_emulation.info.omv_enabled == 1)
    omv_end (pfd[1], omv_data);

1800
#endif
Lionel Gauthier's avatar
Lionel Gauthier committed
1801

1802 1803 1804 1805 1806
  if ((oai_emulation.info.ocm_enabled == 1) && (ethernet_flag == 0)
      && (ShaF != NULL)) {
    destroyMat (ShaF, map1, map2);
    ShaF = 0;
  }
1807

1808 1809
  if (opt_enabled == 1)
    terminate_opt ();
1810

1811 1812
  if (oai_emulation.info.cli_enabled)
    cli_server_cleanup ();
Lionel Gauthier's avatar
Lionel Gauthier committed
1813

1814 1815 1816 1817 1818 1819 1820 1821 1822
  for (int i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++)
    if (oai_emulation.info.oai_ifup[i] == 1) {
      char interfaceName[8];
      snprintf (interfaceName, sizeof(interfaceName), "oai%d", i);
      bringInterfaceUp (interfaceName, 0);
    }

  log_thread_finalize ();
  logClean ();
1823
  VCD_SIGNAL_DUMPER_CLOSE ();
1824

1825
  done = 1; // prevent next invokation of this function
Lionel Gauthier's avatar
Lionel Gauthier committed
1826

1827 1828
  LOG_N(EMU,
        ">>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU shutdown <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
Lionel Gauthier's avatar
Lionel Gauthier committed
1829
}
1830

Lionel Gauthier's avatar
Lionel Gauthier committed
1831
eNB_MAC_INST*
1832 1833
get_eNB_mac_inst (module_id_t module_idP)
{
1834
  return (RC.mac[module_idP]);
Lionel Gauthier's avatar
Lionel Gauthier committed
1835
}
1836

Lionel Gauthier's avatar
Lionel Gauthier committed
1837
OAI_Emulation*
1838 1839 1840
get_OAI_emulation ()
{
  return &oai_emulation;
Lionel Gauthier's avatar
Lionel Gauthier committed
1841
}
1842 1843


1844 1845 1846 1847 1848 1849 1850
// dummy function declarations

void *rrc_enb_task(void *args_p) {


}