oaisim.c 63.2 KB
Newer Older
1
/*******************************************************************************
2 3
    OpenAirInterface 
    Copyright(c) 1999 - 2014 Eurecom
4

5 6 7 8
    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
9 10


11 12 13 14
    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
15

16 17 18 19
    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is 
    included in this distribution in the file called "COPYING". If not, 
    see <http://www.gnu.org/licenses/>.
20

21 22 23 24 25
   Contact Information
   OpenAirInterface Admin: openair_admin@eurecom.fr
   OpenAirInterface Tech : openair_tech@eurecom.fr
   OpenAirInterface Dev  : openair4g-devel@eurecom.fr
  
ghaddab's avatar
ghaddab committed
26
   Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
27

Raymond Knopp's avatar
 
Raymond Knopp committed
28
*******************************************************************************/
29

30 31 32 33 34 35 36 37 38 39
#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>

40
#include "event_handler.h"
41 42 43 44 45 46 47
#include "SIMULATION/RF/defs.h"
#include "PHY/types.h"
#include "PHY/defs.h"
#include "PHY/LTE_TRANSPORT/proto.h"
#include "PHY/vars.h"
#include "MAC_INTERFACE/vars.h"

Cedric Roux's avatar
Cedric Roux committed
48 49
#include "SIMULATION/ETH_TRANSPORT/proto.h"

50 51
//#ifdef OPENAIR2
#include "LAYER2/MAC/defs.h"
52
#include "LAYER2/MAC/proto.h"
53
#include "LAYER2/MAC/vars.h"
54
#include "pdcp.h"
55 56 57 58 59
#ifndef CELLULAR
#include "RRC/LITE/vars.h"
#endif
#include "PHY_INTERFACE/vars.h"
//#endif
60
#include "RRC/NAS/nas_config.h"
61 62 63 64 65 66 67 68 69 70 71 72 73

#ifdef IFFT_FPGA
//#include "PHY/LTE_REFSIG/mod_table.h"
#endif //IFFT_FPGA
#include "SCHED/defs.h"
#include "SCHED/vars.h"

#ifdef XFORMS
#include "PHY/TOOLS/lte_phy_scope.h"
#endif

#ifdef SMBV
#include "PHY/TOOLS/smbv.h"
74
char           smbv_fname[] = "smbv_config_file.smbv";
75 76
unsigned short smbv_nframes = 4; // how many frames to configure 1,..,4
unsigned short config_frames[4] = {2,9,11,13};
77
unsigned char  smbv_frame_cnt = 0;
78
uint8_t             config_smbv = 0;
79
char           smbv_ip[16];
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
#endif

#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"

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

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

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

107 108 109
#define RF                    1
#define MCS_COUNT             24 /*added for PHY abstraction */
#define N_TRIALS              1
110 111

/*
Raymond Knopp's avatar
 
Raymond Knopp committed
112 113 114 115 116
  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;
*/
117

118 119 120 121
#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
122

123 124
#define DECOR_DIST             100
#define SF_VAR                 10
125 126

//constant for OAISIM soft realtime calibration
127 128 129 130
//#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 */
131 132 133

frame_t                frame = 0;
char                   stats_buffer[16384];
Raymond Knopp's avatar
 
Raymond Knopp committed
134 135
channel_desc_t        *eNB2UE[NUMBER_OF_eNB_MAX][NUMBER_OF_UE_MAX][MAX_NUM_CCs];
channel_desc_t        *UE2eNB[NUMBER_OF_UE_MAX][NUMBER_OF_eNB_MAX][MAX_NUM_CCs];
136
//Added for PHY abstraction
137 138
node_desc_t           *enb_data[NUMBER_OF_eNB_MAX];
node_desc_t           *ue_data[NUMBER_OF_UE_MAX];
139
// Added for PHY abstraction
140 141
extern node_list*       ue_node_list;
extern node_list*       enb_node_list;
142 143 144 145 146 147 148
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;
149 150 151 152 153 154 155 156 157 158
extern uint8_t              set_sinr;
extern uint8_t              ue_connection_test;
extern uint8_t              set_seed;
uint8_t                     cooperation_flag; // for cooperative communication
extern uint8_t              target_dl_mcs;
extern uint8_t              target_ul_mcs;
uint8_t                     rate_adaptation_flag;
extern uint8_t              abstraction_flag;
extern uint8_t              ethernet_flag;
extern uint16_t             Nid_cell;
159

Raymond Knopp's avatar
 
Raymond Knopp committed
160
extern LTE_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs];
161 162 163 164 165

#ifdef XFORMS
int otg_enabled;
#endif

166 167 168 169 170
time_stats_t oaisim_stats;
time_stats_t oaisim_stats_f;
time_stats_t dl_chan_stats;
time_stats_t ul_chan_stats;

171
// this should reflect the channel models in openair1/SIMULATION/TOOLS/defs.h
172
mapping small_scale_names[] = {
Raymond Knopp's avatar
 
Raymond Knopp committed
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
  {"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}
193
};
194 195 196 197
#if !defined(ENABLE_ITTI)
static void *sigh(void *arg);
#endif
void oai_shutdown(void);
198

199
void help(void) {
200
  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");
201 202 203

  printf ("-h provides this help message!\n");
  printf ("-a Activates PHY abstraction mode\n");
204
  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");
205 206
  printf ("-b Set the number of local eNB\n");
  printf ("-B Set the mobility model for eNB, options are: STATIC, RWP, RWALK, \n");
207
  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");
208 209
  printf ("-C [0-6] Sets TDD configuration\n");
  printf ("-e Activates extended prefix mode\n");
210
  printf ("-E Random number generator seed\n");
211 212 213 214
  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");
215
  printf ("-H Enable handover operation (default disabled) \n");
216 217
  printf ("-I Enable CLI interface (to connect use telnet localhost 1352)\n");
  printf ("-k Set the Ricean factor (linear)\n");
218
  printf ("-K [log_file] Enable ITTI logging into log_file\n");
219 220
  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");
221
  printf ("-m Gives a fixed DL mcs for eNB scheduler\n");
222 223
  printf ("-M Set the machine ID for Ethernet-based emulation\n");
  printf ("-n Set the number of frames for the simulation\n");
224
  printf ("-O [enb_conf_file] eNB configuration file name\n");
225 226 227 228 229
  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");
230
  printf ("-q Enable Openair performance profiler \n");
231
  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");
232 233 234 235
  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");
236
  printf ("-t Gives a fixed UL mcs for eNB scheduler\n");
237
  printf ("-T activate the traffic generator: cbr, scbr, mcbr, bcbr, mscbr\n");
238
  printf ("-u Set the number of local UE\n");
239 240
  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");
241
  printf ("-w number of CBA groups, if not specified or zero, CBA is inactive\n");
242
  printf ("-W IP address to connect to SMBV and configure SMBV from config file. Requires compilation with SMBV=1, -W0 uses default IP 192.168.12.201\n");
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
  printf ("-x Set the transmission mode (1,2,5,6 supported for now)\n");
  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");
}

pthread_t log_thread;

void log_thread_init() {
  //create log_list
  //log_list_init(&log_list);
#ifndef LOG_NO_THREAD

  log_shutdown = 0;

258
  if ((pthread_mutex_init (&log_lock, NULL) != 0) || (pthread_cond_init (&log_notify, NULL) != 0)) {
Raymond Knopp's avatar
 
Raymond Knopp committed
259
    return;
260 261
  }

262
  if (pthread_create (&log_thread, NULL, log_thread_function, (void*) NULL) != 0) {
Raymond Knopp's avatar
 
Raymond Knopp committed
263 264
    log_thread_finalize ();
    return;
265 266 267 268 269 270 271 272 273 274 275
  }
#endif

}

//Call it after the last LOG call
int log_thread_finalize() {
  int err = 0;

#ifndef LOG_NO_THREAD

276
  if (pthread_mutex_lock (&log_lock) != 0) {
Raymond Knopp's avatar
 
Raymond Knopp committed
277
    return -1;
278 279 280 281 282
  }

  log_shutdown = 1;

  /* Wake up LOG thread */
283
  if ((pthread_cond_broadcast (&log_notify) != 0) || (pthread_mutex_unlock (&log_lock) != 0)) {
Raymond Knopp's avatar
 
Raymond Knopp committed
284
    err = -1;
285
  }
286
  if (pthread_join (log_thread, NULL) != 0) {
Raymond Knopp's avatar
 
Raymond Knopp committed
287
    err = -1;
288
  }
289
  if (pthread_mutex_unlock (&log_lock) != 0) {
Raymond Knopp's avatar
 
Raymond Knopp committed
290
    err = -1;
291 292
  }

293
  if (!err) {
Raymond Knopp's avatar
 
Raymond Knopp committed
294 295 296 297
    //log_list_free(&log_list);
    pthread_mutex_lock (&log_lock);
    pthread_mutex_destroy (&log_lock);
    pthread_cond_destroy (&log_notify);
298
  }
Cedric Roux's avatar
Cedric Roux committed
299 300
#endif

301 302 303
  return err;
}

304
#if defined(ENABLE_ITTI)
305 306
static void set_cli_start(module_id_t module_idP, uint8_t start) {
  if (module_idP < NB_eNB_INST) {
Raymond Knopp's avatar
 
Raymond Knopp committed
307
    oai_emulation.info.cli_start_enb[module_idP] = start;
308
  } else {
Raymond Knopp's avatar
 
Raymond Knopp committed
309
    oai_emulation.info.cli_start_ue[module_idP - NB_eNB_INST] = start;
310 311 312 313
  }
}
#endif

314
#ifdef OPENAIR2
315
int omv_write(int pfd, node_list* enb_node_list, node_list* ue_node_list, Data_Flow_Unit omv_data) {
316
  module_id_t i, j;
317
  omv_data.end = 0;
318
  //omv_data.total_num_nodes = NB_UE_INST + NB_eNB_INST;
319
  for (i = 0; i < NB_eNB_INST; i++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
    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;
      for (j = NB_eNB_INST; j < NB_UE_INST + NB_eNB_INST; j++) {
	if (is_UE_active (i, j - NB_eNB_INST) == 1) {
	  omv_data.geo[i].Neighbor[omv_data.geo[i].Neighbors] = j;
	  omv_data.geo[i].Neighbors++;
	  LOG_D(
		OMG,
		"[eNB %d][UE %d] is_UE_active(i,j) %d geo (x%d, y%d) num neighbors %d\n", i, j-NB_eNB_INST, is_UE_active(i,j-NB_eNB_INST), omv_data.geo[i].x, omv_data.geo[i].y, omv_data.geo[i].Neighbors);
	}
336
      }
Raymond Knopp's avatar
 
Raymond Knopp committed
337
    }
338
  }
339
  for (i = NB_eNB_INST; i < NB_UE_INST + NB_eNB_INST; i++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
    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;
      for (j = 0; j < NB_eNB_INST; j++) {
	if (is_UE_active (j, i - NB_eNB_INST) == 1) {
	  omv_data.geo[i].Neighbor[omv_data.geo[i].Neighbors] = j;
	  omv_data.geo[i].Neighbors++;
	  LOG_D(
		OMG,
		"[UE %d][eNB %d] is_UE_active  %d geo (x%d, y%d) num neighbors %d\n", i-NB_eNB_INST, j, is_UE_active(j,i-NB_eNB_INST), omv_data.geo[i].x, omv_data.geo[i].y, omv_data.geo[i].Neighbors);
	}
370
      }
Raymond Knopp's avatar
 
Raymond Knopp committed
371
    }
372
  }
373 374 375
  LOG_E(OMG, "pfd %d \n", pfd);
  if (write (pfd, &omv_data, sizeof(struct Data_Flow_Unit)) == -1)
    perror ("write omv failed");
376 377 378
  return 1;
}

379 380 381 382
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)
    perror ("write omv failed");
383 384 385
}
#endif 

386
#ifdef OPENAIR2
387 388
int pfd[2]; // fd for omv : fixme: this could be a local var
#endif
389

390 391 392
#ifdef OPENAIR2
static Data_Flow_Unit omv_data;
#endif //ALU
393 394
static module_id_t UE_inst  = 0;
static module_id_t eNB_inst = 0;
395
#ifdef Rel10
396
static module_id_t RN_id    = 0;
397
#endif
398

399
Packet_OTG_List_t *otg_pdcp_buffer;
400 401

typedef enum l2l1_task_state_e
Raymond Knopp's avatar
 
Raymond Knopp committed
402 403 404 405 406
  {
    L2L1_WAITTING,
    L2L1_RUNNING,
    L2L1_TERMINATED,
  } l2l1_task_state_t;
407

408 409
l2l1_task_state_t     l2l1_state = L2L1_WAITTING;

410
/*------------------------------------------------------------------------------*/
411
void *l2l1_task(void *args_p) {
412
  
413
  clock_t               t;
Raymond Knopp's avatar
 
Raymond Knopp committed
414
  int CC_id;
415

416
  // Framing variables
417
  int32_t                   slot, last_slot, next_slot;
418

419
#ifdef Rel10
420
  relaying_type_t       r_type = no_relay; // no relaying
421
#endif
422

423
  lte_subframe_t        direction;
424

425
  char                  fname[64], vname[64];
Raymond Knopp's avatar
 
Raymond Knopp committed
426
  int sf;
427 428 429 430

#ifdef XFORMS
  // 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 
431
  FD_lte_phy_scope_ue  *form_ue[NUMBER_OF_UE_MAX];
432
  FD_lte_phy_scope_enb *form_enb[NUMBER_OF_UE_MAX];
433 434 435 436
  char                  title[255];
  char                  xname[32]                  = "oaisim";
  int                   xargc                      = 1;
  char                 *xargv[1];
437 438 439
#endif

#ifdef PRINT_STATS
440 441 442 443 444 445 446 447 448 449
  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];
450 451
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
452 453 454 455 456 457 458 459 460 461
  for (CC_id = 0;CC_id<MAX_NUM_CCs;CC_id++)
    for (eNB_inst=0;eNB_inst<NB_eNB_INST;eNB_inst++) {
      for (sf=0;sf<10;sf++) {
	PHY_vars_eNB_g[eNB_inst][CC_id]->proc[sf].frame_tx = 0;
	PHY_vars_eNB_g[eNB_inst][CC_id]->proc[sf].frame_rx = 0;
	PHY_vars_eNB_g[eNB_inst][CC_id]->proc[sf].subframe_tx = (sf+1)%10;
	PHY_vars_eNB_g[eNB_inst][CC_id]->proc[sf].subframe_rx = (sf+9)%10;
      }
      PHY_vars_eNB_g[eNB_inst][CC_id]->proc[0].frame_rx = 1023;
      PHY_vars_eNB_g[eNB_inst][CC_id]->proc[9].frame_tx = 1;
Raymond Knopp's avatar
 
Raymond Knopp committed
462
    }
463 464 465
#ifdef XFORMS
  xargv[0] = xname;
  fl_initialize (&xargc, xargv, NULL, 0, 0);
466 467
  eNB_inst = 0;
  for (UE_inst = 0; UE_inst < NB_UE_INST; UE_inst++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
    // DL scope at UEs
    form_ue[UE_inst] = create_lte_phy_scope_ue();
    sprintf (title, "LTE DL SCOPE eNB %d to UE %d", eNB_inst, UE_inst);
    fl_show_form (form_ue[UE_inst]->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);

    // UL scope at eNB 0
    form_enb[UE_inst] = create_lte_phy_scope_enb();
    sprintf (title, "LTE UL SCOPE UE %d to eNB %d", UE_inst, eNB_inst);
    fl_show_form (form_enb[UE_inst]->lte_phy_scope_enb, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);

    if (openair_daq_vars.use_ia_receiver == 1) {
      fl_set_button(form_ue[UE_inst]->button_0,1);
      fl_set_object_label(form_ue[UE_inst]->button_0, "IA Receiver ON");
      fl_set_object_color(form_ue[UE_inst]->button_0, FL_GREEN, FL_GREEN);
    }
483 484 485 486 487

  }
#endif

#ifdef PRINT_STATS
488
  for (UE_inst=0;UE_inst<NB_UE_INST;UE_inst++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
489 490
    sprintf(UE_stats_filename,"UE_stats%d.txt",UE_inst);
    UE_stats[UE_inst] = fopen (UE_stats_filename, "w");
491
  }
492
  for (eNB_inst=0;eNB_inst<NB_eNB_INST;eNB_inst++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
493 494
    sprintf(eNB_stats_filename,"eNB_stats%d.txt",eNB_inst);
    eNB_stats[eNB_inst] = fopen (eNB_stats_filename, "w");
495 496 497
  }

  if(abstraction_flag==0) {
Raymond Knopp's avatar
 
Raymond Knopp committed
498 499 500 501 502 503
    for (UE_inst=0;UE_inst<NB_UE_INST;UE_inst++) {
      sprintf(UE_stats_th_filename,"UE_stats_th%d_tx%d.txt",UE_inst,oai_emulation.info.transmission_mode);
      UE_stats_th[UE_inst] = fopen (UE_stats_th_filename, "w");
    }
    sprintf(eNB_stats_th_filename,"eNB_stats_th_tx%d.txt",oai_emulation.info.transmission_mode);
    eNB_avg_thr = fopen (eNB_stats_th_filename, "w");
504 505
  }
  else {
Raymond Knopp's avatar
 
Raymond Knopp committed
506 507 508 509 510 511
    for (UE_inst=0;UE_inst<NB_UE_INST;UE_inst++) {
      sprintf(UE_stats_th_filename,"UE_stats_abs_th%d_tx%d.txt",UE_inst,oai_emulation.info.transmission_mode);
      UE_stats_th[UE_inst] = fopen (UE_stats_th_filename, "w");
    }
    sprintf(eNB_stats_th_filename,"eNB_stats_abs_th_tx%d.txt",oai_emulation.info.transmission_mode);
    eNB_avg_thr = fopen (eNB_stats_th_filename, "w");
512 513 514 515 516 517 518 519
  }
#ifdef OPENAIR2
  eNB_l2_stats = fopen ("eNB_l2_stats.txt", "w");
  LOG_I(EMU,"eNB_l2_stats=%p\n", eNB_l2_stats);
#endif 

#endif

520
#if defined(ENABLE_ITTI)
521
  MessageDef   *message_p = NULL;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
522
  const char   *msg_name  = NULL;
523
  int           result;
524

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

528
  if (oai_emulation.info.nb_enb_local > 0) {
Raymond Knopp's avatar
 
Raymond Knopp committed
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
    /* Wait for the initialize message */
    do {
      if (message_p != NULL) {
	result = itti_free (ITTI_MSG_ORIGIN_ID(message_p), message_p);
	AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
      }
      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;
	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);
563 564
  }
#endif
565
  start_meas(&oaisim_stats);
566 567
  for (frame = 0; (l2l1_state != L2L1_TERMINATED) && (frame < oai_emulation.info.n_frames); frame++) {

568
 
569
#if defined(ENABLE_ITTI)
Raymond Knopp's avatar
 
Raymond Knopp committed
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
    do {
      // Checks if a message has been sent to L2L1 task
      itti_poll_msg (TASK_L2L1, &message_p);

      if (message_p != NULL) {
	msg_name = ITTI_MSG_NAME (message_p);
	LOG_I(EMU, "TASK_L2L1 received %s\n", msg_name);
	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;

	case MESSAGE_TEST:
	  break;


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

	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);
603
#endif
604
      
Raymond Knopp's avatar
 
Raymond Knopp committed
605 606 607
    //Run the aperiodic user-defined events
    if (oai_emulation.info.oeh_enabled == 1)
      execute_events(frame);
608
           
Raymond Knopp's avatar
 
Raymond Knopp committed
609 610 611 612 613 614 615 616 617 618 619 620
    /*
    // Handling the cooperation Flag
    if (cooperation_flag == 2)
    {
    if ((PHY_vars_eNB_g[0]->eNB_UE_stats[0].mode == PUSCH) && (PHY_vars_eNB_g[0]->eNB_UE_stats[1].mode == PUSCH))
    PHY_vars_eNB_g[0]->cooperation_flag = 2;
    }
    */
    if (ue_connection_test == 1) {
      if ((frame % 20) == 0) {
	snr_dB += snr_direction;
	sinr_dB -= snr_direction;
621
      }
Raymond Knopp's avatar
 
Raymond Knopp committed
622 623
      if (snr_dB == -20) {
	snr_direction = snr_step;
624
      }
Raymond Knopp's avatar
 
Raymond Knopp committed
625 626 627 628 629
      else
	if (snr_dB == 20) {
	  snr_direction = -snr_step;
	}
    }
630

Raymond Knopp's avatar
 
Raymond Knopp committed
631 632 633 634 635 636 637 638 639
    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)
    // if n_frames not set by the user or is greater than max num frame then set adjust the frame counter
    if ((oai_emulation.info.n_frames_flag == 0) || (oai_emulation.info.n_frames >= 0xffff)) {
      frame %= (oai_emulation.info.n_frames - 1);
    }

    update_omg (frame); // frequency is defined in the omg_global params configurable by the user
640

Raymond Knopp's avatar
 
Raymond Knopp committed
641
    update_omg_ocm ();
642 643

#ifdef OPENAIR2
Raymond Knopp's avatar
 
Raymond Knopp committed
644 645 646 647
    // 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);
    }
648
#endif
649
#ifdef DEBUG_OMG
Raymond Knopp's avatar
 
Raymond Knopp committed
650
    /*
651
      if ((((int) oai_emulation.info.time_s) % 100) == 0) {
Raymond Knopp's avatar
 
Raymond Knopp committed
652 653
      for (UE_inst = oai_emulation.info.first_ue_local; UE_inst < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_inst++) {
      get_node_position (UE, UE_inst);
654
      }
Raymond Knopp's avatar
 
Raymond Knopp committed
655 656
      }
    */
657 658
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
659
    update_ocm ();
660

Raymond Knopp's avatar
 
Raymond Knopp committed
661
    for (slot = 0; slot < 20; slot++) {
662 663 664
      if (slot%2==0)
	start_meas(&oaisim_stats_f);

Raymond Knopp's avatar
 
Raymond Knopp committed
665
      wait_for_slot_isr ();
666

667
#if defined(ENABLE_ITTI)
Raymond Knopp's avatar
 
Raymond Knopp committed
668
      itti_update_lte_time(frame, slot);
669
#endif
670

Raymond Knopp's avatar
 
Raymond Knopp committed
671 672 673 674
      last_slot = (slot - 1) % 20;
      if (last_slot < 0)
	last_slot += 20;
      next_slot = (slot + 1) % 20;
675

Raymond Knopp's avatar
 
Raymond Knopp committed
676
      oai_emulation.info.time_ms = frame * 10 + (slot >> 1);
677

Raymond Knopp's avatar
 
Raymond Knopp committed
678
      direction = subframe_select (frame_parms[0], next_slot >> 1);
679

680
#ifdef PROC
Raymond Knopp's avatar
 
Raymond Knopp committed
681 682
      if(Channel_Flag==1)
	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,eNB2UE,UE2eNB,enb_data,ue_data,abstraction_flag,frame_parms,slot);
683

Raymond Knopp's avatar
 
Raymond Knopp committed
684
      if(Channel_Flag==0)
685
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
686
	{
687
#if defined(ENABLE_ITTI)
Raymond Knopp's avatar
 
Raymond Knopp committed
688
	  log_set_instance_type (LOG_INSTANCE_ENB);
689 690
#endif

691 692
	  //	  if ((next_slot % 2) == 0)  
	  if ((slot&1) == 0) 
Raymond Knopp's avatar
 
Raymond Knopp committed
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
	    clear_eNB_transport_info (oai_emulation.info.nb_enb_local);

	  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) {
	      if ((slot&1) == 0) 
		LOG_D(
		      EMU,
		      "PHY procedures eNB %d for frame %d, slot %d (subframe TX %d, RX %d) TDD %d/%d Nid_cell %d\n",
		      eNB_inst,
		      frame,
		      slot,
		      PHY_vars_eNB_g[eNB_inst][0]->proc[slot >> 1].subframe_tx,
		      PHY_vars_eNB_g[eNB_inst][0]->proc[slot >> 1].subframe_rx,
		      PHY_vars_eNB_g[eNB_inst][0]->lte_frame_parms.frame_type,
		      PHY_vars_eNB_g[eNB_inst][0]->lte_frame_parms.tdd_config,
		      PHY_vars_eNB_g[eNB_inst][0]->lte_frame_parms.Nid_cell);
		  
710
#ifdef OPENAIR2
Raymond Knopp's avatar
 
Raymond Knopp committed
711 712
	      //Appliation: traffic gen
	      update_otg_eNB (eNB_inst, oai_emulation.info.time_ms);
713

Raymond Knopp's avatar
 
Raymond Knopp committed
714
	      //IP/OTG to PDCP and PDCP to IP operation
Raymond Knopp's avatar
 
Raymond Knopp committed
715
	      //	      pdcp_run (frame, 1, 0, eNB_inst); //PHY_vars_eNB_g[eNB_id]->Mod_id
716
#endif
717

Raymond Knopp's avatar
 
Raymond Knopp committed
718 719 720
	      // PHY_vars_eNB_g[eNB_id]->frame = frame;
	      if ((slot&1) == 0) 
		phy_procedures_eNB_lte (slot>>1,PHY_vars_eNB_g[eNB_inst], abstraction_flag, no_relay, NULL);
721
#ifdef PRINT_STATS
Raymond Knopp's avatar
 
Raymond Knopp committed
722 723 724 725 726 727 728 729 730 731
	      if(last_slot==9 && frame%10==0)
		if(eNB_avg_thr) 
		  fprintf(eNB_avg_thr,"%d %d\n",PHY_vars_eNB_g[eNB_inst]->proc[slot>>1].frame_tx,
			  (PHY_vars_eNB_g[eNB_inst]->total_system_throughput)/((PHY_vars_eNB_g[eNB_inst]->proc[slot>>1].frame_tx+1)*10));
	      if (eNB_stats[eNB_inst]) {
		len = dump_eNB_stats(PHY_vars_eNB_g[eNB_inst][0], stats_buffer, 0);
		rewind (eNB_stats[eNB_inst]);
		fwrite (stats_buffer, 1, len, eNB_stats[eNB_inst]);
		fflush(eNB_stats[eNB_inst]);
	      }
732
#ifdef OPENAIR2
Raymond Knopp's avatar
 
Raymond Knopp committed
733 734 735 736 737 738
	      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);
	      }
739
#endif
740
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
741 742
	    }
	  }
Raymond Knopp's avatar
 
Raymond Knopp committed
743
	    	    
Raymond Knopp's avatar
 
Raymond Knopp committed
744 745
	  // Call ETHERNET emulation here
	  //emu_transport (frame, last_slot, next_slot, direction, oai_emulation.info.frame_type, ethernet_flag);
746

747
#if defined(ENABLE_ITTI)
Raymond Knopp's avatar
 
Raymond Knopp committed
748
	  log_set_instance_type (LOG_INSTANCE_UE);
749 750
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
751
	  if ((next_slot % 2) == 0)
752
	  // if ((slot&1) == 0) 
Raymond Knopp's avatar
 
Raymond Knopp committed
753 754 755 756
	    clear_UE_transport_info (oai_emulation.info.nb_ue_local);
	  for (UE_inst = oai_emulation.info.first_ue_local;
	       (UE_inst < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local)); UE_inst++) {
	    if (oai_emulation.info.cli_start_ue[UE_inst] != 0) {
757
#if defined(ENABLE_ITTI) && defined(ENABLE_USE_MME)
758

759
#else
Raymond Knopp's avatar
 
Raymond Knopp committed
760
	      if (frame >= (UE_inst * 20))  // activate UE only after 20*UE_id frames so that different UEs turn on separately
761
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
762 763 764 765 766 767 768 769 770 771
		{
		  LOG_D(EMU, "PHY procedures UE %d for frame %d, slot %d (subframe TX %d, RX %d)\n",
			UE_inst,
			frame,
			slot,
			next_slot >> 1,
			last_slot>>1);

		  if (PHY_vars_UE_g[UE_inst][0]->UE_mode[0] != NOT_SYNCHED) {
		    if (frame > 0) {
Raymond Knopp's avatar
 
Raymond Knopp committed
772 773 774 775 776 777 778
		      PHY_vars_UE_g[UE_inst][0]->frame_rx = frame;
		      PHY_vars_UE_g[UE_inst][0]->slot_rx = last_slot;
		      PHY_vars_UE_g[UE_inst][0]->slot_tx = next_slot;
		      if (next_slot > 1)
			PHY_vars_UE_g[UE_inst][0]->frame_tx = frame;
		      else
			PHY_vars_UE_g[UE_inst][0]->frame_tx = frame+1;
779
#ifdef OPENAIR2
Raymond Knopp's avatar
 
Raymond Knopp committed
780 781
		      //Application
		      update_otg_UE (UE_inst, oai_emulation.info.time_ms);
782

Raymond Knopp's avatar
 
Raymond Knopp committed
783 784
		      //Access layer
		      pdcp_run (frame, 0, UE_inst, 0);
785
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
786
		      for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
787
			phy_procedures_UE_lte (PHY_vars_UE_g[UE_inst][CC_id], 0, abstraction_flag, normal_txrx,
Raymond Knopp's avatar
 
Raymond Knopp committed
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
					       no_relay, NULL);
		      }
		      ue_data[UE_inst]->tx_power_dBm = PHY_vars_UE_g[UE_inst][0]->tx_power_dBm;
		    }
		  }
		  else {
		    if (abstraction_flag == 1) {
		      LOG_E(
			    EMU,
			    "sync not supported in abstraction mode (UE%d,mode%d)\n", UE_inst, PHY_vars_UE_g[UE_inst][0]->UE_mode[0]);
		      exit (-1);
		    }
		    if ((frame > 0) && (last_slot == (LTE_SLOTS_PER_FRAME - 2))) {
		      initial_sync (PHY_vars_UE_g[UE_inst][0], normal_txrx);

		      /*
			write_output("dlchan00.m","dlch00",&(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][0][0]),(6*(PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)),1,1);
			if (PHY_vars_UE_g[0]->lte_frame_parms.nb_antennas_rx>1)
			write_output("dlchan01.m","dlch01",&(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][1][0]),(6*(PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)),1,1);
			write_output("dlchan10.m","dlch10",&(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][2][0]),(6*(PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)),1,1);
			if (PHY_vars_UE_g[0]->lte_frame_parms.nb_antennas_rx>1)
			write_output("dlchan11.m","dlch11",&(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][3][0]),(6*(PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)),1,1);
			write_output("rxsig.m","rxs",PHY_vars_UE_g[0]->lte_ue_common_vars.rxdata[0],PHY_vars_UE_g[0]->lte_frame_parms.samples_per_tti*10,1,1);
			write_output("rxsigF.m","rxsF",PHY_vars_UE_g[0]->lte_ue_common_vars.rxdataF[0],2*PHY_vars_UE_g[0]->lte_frame_parms.symbols_per_tti*PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size,2,1);
			write_output("pbch_rxF_ext0.m","pbch_ext0",PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->rxdataF_ext[0],6*12*4,1,1);
			write_output("pbch_rxF_comp0.m","pbch_comp0",PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->rxdataF_comp[0],6*12*4,1,1);
			write_output("pbch_rxF_llr.m","pbch_llr",PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->llr,(frame_parms->Ncp==0) ? 1920 : 1728,1,4);
		      */
		    }
		  }
818
#ifdef PRINT_STATS
Raymond Knopp's avatar
 
Raymond Knopp committed
819 820 821 822 823 824 825 826 827 828 829
		  if(last_slot==2 && frame%10==0) {
		    if (UE_stats_th[UE_inst]) {
		      fprintf(UE_stats_th[UE_inst],"%d %d\n",frame, PHY_vars_UE_g[UE_inst][0]->bitrate[0]/1000);
		    }
		  }
		  if (UE_stats[UE_inst]) {
		    len = dump_ue_stats (PHY_vars_UE_g[UE_inst][0], stats_buffer, 0, normal_txrx, 0);
		    rewind (UE_stats[UE_inst]);
		    fwrite (stats_buffer, 1, len, UE_stats[UE_inst]);
		    fflush(UE_stats[UE_inst]);
		  }
830
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
831 832 833 834
		}
	    }
	  }	       
    
835
#ifdef Rel10
Raymond Knopp's avatar
 
Raymond Knopp committed
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857
	  for (RN_id=oai_emulation.info.first_rn_local;
	       RN_id<oai_emulation.info.first_rn_local+oai_emulation.info.nb_rn_local;
	       RN_id++) {
	    // UE id and eNB id of the RN
	    UE_inst= oai_emulation.info.first_ue_local+oai_emulation.info.nb_ue_local + RN_id;// NB_UE_INST + RN_id
	    eNB_inst= oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local + RN_id;// NB_eNB_INST + RN_id
	    // currently only works in FDD
	    if (oai_emulation.info.eMBMS_active_state == 4) {
	      r_type = multicast_relay;
	      //LOG_I(EMU,"Activating the multicast relaying\n");
	    }
	    else {
	      LOG_E(EMU,"Not supported eMBMS option when relaying is enabled %d\n", r_type);
	      exit(-1);
	    }
	    PHY_vars_RN_g[RN_id]->frame = frame;
	    if ( oai_emulation.info.frame_type == 0) {
	      // RN == UE
	      if (frame>0) {
		if (PHY_vars_UE_g[UE_inst][0]->UE_mode[0] != NOT_SYNCHED) {
		  LOG_D(EMU,"[RN %d] PHY procedures UE %d for frame %d, slot %d (subframe TX %d, RX %d)\n",
			RN_id, UE_inst, frame, slot, next_slot >> 1,last_slot>>1);
Raymond Knopp's avatar
 
Raymond Knopp committed
858 859 860 861 862 863
		  PHY_vars_UE_g[UE_inst][0]->frame_rx = frame;
		  PHY_vars_UE_g[UE_inst][0]->slot_rx =  last_slot;
		  PHY_vars_UE_g[UE_inst][0]->slot_tx =  next_slot;
		  if (next_slot>1) PHY_vars_UE_g[UE_inst][0]->frame_tx = frame;
		  else PHY_vars_UE_g[UE_inst][0]->frame_tx = frame+1;
		  phy_procedures_UE_lte (PHY_vars_UE_g[UE_inst][0], 0, abstraction_flag,normal_txrx,
Raymond Knopp's avatar
 
Raymond Knopp committed
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880
					 r_type, PHY_vars_RN_g[RN_id]);
		}
		else if (last_slot == (LTE_SLOTS_PER_FRAME-2)) {
		  initial_sync(PHY_vars_UE_g[UE_inst][0],normal_txrx);
		}
	      }
	      // RN == eNB
	      LOG_D(EMU,"[RN %d] PHY procedures eNB %d for frame %d, slot %d (subframe TX %d, RX %d)\n",
		    RN_id, eNB_inst, frame, slot, next_slot >> 1,last_slot>>1);
	      phy_procedures_eNB_lte(slot>>1, PHY_vars_eNB_g[eNB_inst][0], abstraction_flag,
				     r_type, PHY_vars_RN_g[RN_id]);
	    }
	    else {
	      LOG_E(EMU,"TDD is not supported for multicast relaying %d\n", r_type);
	      exit(-1);
	    }
	  }
881
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
882
	  emu_transport (frame, last_slot, next_slot, direction, oai_emulation.info.frame_type[0], ethernet_flag);
Raymond Knopp's avatar
 
Raymond Knopp committed
883
	  if ((direction == SF_DL) || (frame_parms[0]->frame_type == FDD)) {
Raymond Knopp's avatar
 
Raymond Knopp committed
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
	    // consider only sec id 0
	    /*  for (eNB_id=0;eNB_id<NB_eNB_INST;eNB_id++) {
		if (abstraction_flag == 0) {
		do_OFDM_mod(PHY_vars_eNB_g[eNB_id]->lte_eNB_common_vars.txdataF[0],
		PHY_vars_eNB_g[eNB_id]->lte_eNB_common_vars.txdata[0],
		frame,next_slot,
		frame_parms);
		}
		}*/
	    start_meas(&dl_chan_stats);
	    for (UE_inst = 0; UE_inst < NB_UE_INST; UE_inst++) 
	      for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
#warning figure out what to do with UE frame_parms during initial_sync
		do_DL_sig (r_re0, r_im0, r_re, r_im, s_re, s_im, eNB2UE, enb_data, ue_data, next_slot, abstraction_flag,&PHY_vars_eNB_g[0][CC_id]->lte_frame_parms,UE_inst,CC_id);
	      }
	    stop_meas(&dl_chan_stats);
	  }
	  if ((direction == SF_UL) || (frame_parms[0]->frame_type == 0)) { //if ((subframe<2) || (subframe>4))
	    start_meas(&ul_chan_stats);
	    for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
#warning figure out what to do with UE frame_parms during initial_sync
	      do_UL_sig (r_re0, r_im0, r_re, r_im, s_re, s_im, UE2eNB, enb_data, ue_data, next_slot, abstraction_flag,&PHY_vars_eNB_g[0][CC_id]->lte_frame_parms, frame,CC_id); 
	    }
	    stop_meas(&ul_chan_stats);
	    /*
	      int ccc;
	      fprintf(SINRpost,"SINRdb For eNB New Subframe : \n ");
	      for(ccc = 0 ; ccc<301; ccc++)
	      {
	      fprintf(SINRpost,"_ %f ", SINRpost_eff[ccc]);
	      }
	      fprintf(SINRpost,"SINRdb For eNB : %f \n ", SINRpost_eff[ccc]);
	    */
	  }
	  if ((direction == SF_S)) { //it must be a special subframe
	    if (next_slot % 2 == 0) { //DL part
	      /*  for (eNB_id=0;eNB_id<NB_eNB_INST;eNB_id++) {
		  if (abstraction_flag == 0) {
		  do_OFDM_mod(PHY_vars_eNB_g[eNB_id]->lte_eNB_common_vars.txdataF[0],
		  PHY_vars_eNB_g[eNB_id]->lte_eNB_common_vars.txdata[0],
		  frame,next_slot,
		  frame_parms);
		  }
		  }*/ 
	      start_meas(&dl_chan_stats);
	      for (UE_inst = 0; UE_inst < NB_UE_INST; UE_inst++) 
		for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
#warning	check dimensions of r_reN,r_imN for multiple CCs
		  do_DL_sig (r_re0, r_im0, r_re, r_im, s_re, s_im, eNB2UE, enb_data, ue_data, next_slot, abstraction_flag,&PHY_vars_eNB_g[0][CC_id]->lte_frame_parms, UE_inst,CC_id);
		}
	      stop_meas(&dl_chan_stats);
	      /*
		for (aarx=0;aarx<UE2eNB[1][0]->nb_rx;aarx++)
		for (aatx=0;aatx<UE2eNB[1][0]->nb_tx;aatx++)
		for (k=0;k<UE2eNB[1][0]->channel_length;k++)
		printf("SB(%d,%d,%d)->(%f,%f)\n",k,aarx,aatx,UE2eNB[1][0]->ch[aarx+(aatx*UE2eNB[1][0]->nb_rx)][k].r,UE2eNB[1][0]->ch[aarx+(aatx*UE2eNB[1][0]->nb_rx)][k].i);
	      */
	    }
	    else { // UL part
	      start_meas(&ul_chan_stats);
	      for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
#warning	check dimensions of r_reN,r_imN for multiple CCs
		do_UL_sig (r_re0, r_im0, r_re, r_im, s_re, s_im, UE2eNB, enb_data, ue_data, next_slot, abstraction_flag,&PHY_vars_eNB_g[0][CC_id]->lte_frame_parms, frame,CC_id);
	      }
	      stop_meas(&ul_chan_stats);

	      /*        int ccc;
			fprintf(SINRpost,"SINRdb For eNB New Subframe : \n ");
			for(ccc = 0 ; ccc<301; ccc++)
			{
			fprintf(SINRpost,"_ %f ", SINRpost_eff[ccc]);
			}
			fprintf(SINRpost,"SINRdb For eNB : %f \n ", SINRpost_eff[ccc]);
			}
	      */
	    }
	  }
	  if ((last_slot == 1) && (frame == 0) && (abstraction_flag == 0) && (oai_emulation.info.n_frames == 1)) {

	    write_output ("dlchan0.m", "dlch0", &(PHY_vars_UE_g[0][0]->lte_ue_common_vars.dl_ch_estimates[0][0][0]),
			  (6 * (PHY_vars_UE_g[0][0]->lte_frame_parms.ofdm_symbol_size)), 1, 1);
	    write_output ("dlchan1.m", "dlch1", &(PHY_vars_UE_g[0][0]->lte_ue_common_vars.dl_ch_estimates[1][0][0]),
			  (6 * (PHY_vars_UE_g[0][0]->lte_frame_parms.ofdm_symbol_size)), 1, 1);
	    write_output ("dlchan2.m", "dlch2", &(PHY_vars_UE_g[0][0]->lte_ue_common_vars.dl_ch_estimates[2][0][0]),
			  (6 * (PHY_vars_UE_g[0][0]->lte_frame_parms.ofdm_symbol_size)), 1, 1);
	    write_output ("pbch_rxF_comp0.m", "pbch_comp0", PHY_vars_UE_g[0][0]->lte_ue_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]->lte_ue_pbch_vars[0]->llr,
			  (frame_parms[0]->Ncp == 0) ? 1920 : 1728, 1, 4);
	  }
	  /*
	    if ((last_slot==1) && (frame==1)) {
	    write_output("dlsch_rxF_comp0.m","dlsch0_rxF_comp0",PHY_vars_UE->lte_ue_pdsch_vars[eNB_id]->rxdataF_comp[0],300*(-(PHY_vars_UE->lte_frame_parms.Ncp*2)+14),1,1);
	    write_output("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",PHY_vars_UE->lte_ue_pdcch_vars[eNB_id]->rxdataF_comp[0],4*300,1,1);
	    }
	  */
	} // if Channel_Flag==0
981 982
      if (slot%2==1)
	stop_meas(&oaisim_stats_f);
Raymond Knopp's avatar
 
Raymond Knopp committed
983 984
    }//end of slot

985
    if ((frame >= 10) && (frame <= 11) && (abstraction_flag == 0)
986
#ifdef PROC
Raymond Knopp's avatar
 
Raymond Knopp committed
987
	&&(Channel_Flag==0)
988
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
989
	) {
990 991 992 993
      sprintf (fname, "UEtxsig%d.m", frame);
      sprintf (vname, "txs%d", frame);
      write_output (fname, vname, PHY_vars_UE_g[0][0]->lte_ue_common_vars.txdata[0], 
		    PHY_vars_UE_g[0][0]->lte_frame_parms.samples_per_tti*10,1,1);
Raymond Knopp's avatar
 
Raymond Knopp committed
994 995
      sprintf (fname, "eNBtxsig%d.m", frame);
      sprintf (vname, "txs%d", frame);
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
      write_output (fname, vname, PHY_vars_eNB_g[0][0]->lte_eNB_common_vars.txdata[0][0], 
		    PHY_vars_UE_g[0][0]->lte_frame_parms.samples_per_tti*10,1,1);
      sprintf (fname, "eNBtxsigF%d.m", frame);
      sprintf (vname, "txsF%d", frame);
      write_output (fname, vname, PHY_vars_eNB_g[0][0]->lte_eNB_common_vars.txdataF[0][0],
		    PHY_vars_eNB_g[0][0]->lte_frame_parms.symbols_per_tti * PHY_vars_eNB_g[0][0]->lte_frame_parms.ofdm_symbol_size,1,1);
      sprintf (fname, "UErxsig%d.m", frame);
      sprintf (vname, "rxs%d", frame);
      write_output (fname, vname, PHY_vars_UE_g[0][0]->lte_ue_common_vars.rxdata[0], 
		    PHY_vars_UE_g[0][0]->lte_frame_parms.samples_per_tti*10,1,1);
      sprintf (fname, "eNBrxsig%d.m", frame);
      sprintf (vname, "rxs%d", frame);
      write_output (fname, vname, PHY_vars_eNB_g[0][0]->lte_eNB_common_vars.rxdata[0][0], 
		    PHY_vars_UE_g[0][0]->lte_frame_parms.samples_per_tti*10,1,1);
Raymond Knopp's avatar
 
Raymond Knopp committed
1010 1011
    }
    
1012
#ifdef XFORMS
Raymond Knopp's avatar
 
Raymond Knopp committed
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
    eNB_inst = 0;
    for (UE_inst = 0; UE_inst < NB_UE_INST; UE_inst++) {
      phy_scope_UE(form_ue[UE_inst],
		   PHY_vars_UE_g[UE_inst][0],
		   eNB_inst,
		   UE_inst,
		   7);
      
      phy_scope_eNB(form_enb[UE_inst],
		    PHY_vars_eNB_g[eNB_inst][0],
		    UE_inst);
      
    }
1026
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1027
    
1028
#ifdef SMBV
Raymond Knopp's avatar
 
Raymond Knopp committed
1029 1030 1031
    if ((frame == config_frames[0]) || (frame == config_frames[1]) || (frame == config_frames[2]) || (frame == config_frames[3])) {
      smbv_frame_cnt++;
    }
1032
#endif
1033
 
Raymond Knopp's avatar
 
Raymond Knopp committed
1034
  }
1035
  
Raymond Knopp's avatar
 
Raymond Knopp committed
1036 1037
    //end of frame
      
1038 1039
  stop_meas(&oaisim_stats);

1040 1041 1042 1043
#if defined(ENABLE_ITTI)
  itti_terminate_tasks(TASK_L2L1);
#endif

1044
#ifdef PRINT_STATS
1045
  for (UE_inst=0;UE_inst<NB_UE_INST;UE_inst++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
1046 1047 1048 1049
    if (UE_stats[UE_inst])
      fclose (UE_stats[UE_inst]);
    if(UE_stats_th[UE_inst])
      fclose (UE_stats_th[UE_inst]);
1050
  }
1051
  for (eNB_inst=0;eNB_inst<NB_eNB_INST;eNB_inst++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
1052 1053
    if (eNB_stats[eNB_inst])
      fclose (eNB_stats[eNB_inst]);
1054 1055
  }
  if (eNB_avg_thr)
1056
    fclose (eNB_avg_thr);
1057
  if (eNB_l2_stats)
1058
    fclose (eNB_l2_stats);
Raymond Knopp's avatar
 
Raymond Knopp committed
1059
  
1060
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1061
  
1062 1063
  return NULL;
}
Raymond Knopp's avatar
 
Raymond Knopp committed
1064 1065 1066
  
  /*------------------------------------------------------------------------------*/
  int main(int argc, char **argv) {
1067

Raymond Knopp's avatar
 
Raymond Knopp committed
1068 1069 1070
    int32_t i;
    // pointers signal buffers (s = transmit, r,r0 = receive)
    clock_t t;
1071

Raymond Knopp's avatar
 
Raymond Knopp committed
1072 1073 1074 1075 1076
    //FILE *SINRpost;
    //char SINRpost_fname[512];
    // sprintf(SINRpost_fname,"postprocSINR.m");
    //SINRpost = fopen(SINRpost_fname,"w");
    // variables/flags which are set by user on command-line
1077 1078

#ifdef SMBV
Raymond Knopp's avatar
 
Raymond Knopp committed
1079
    strcpy(smbv_ip,DEFAULT_SMBV_IP);
1080 1081
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
1082 1083 1084
    // time calibration for soft realtime mode  
    char pbch_file_path[512];
    FILE *pbch_file_fd;
1085 1086

#ifdef PROC
Raymond Knopp's avatar
 
Raymond Knopp committed
1087 1088
    int node_id;
    int port,Process_Flag=0,wgt,Channel_Flag=0,temp;
1089
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1090 1091 1092 1093 1094 1095 1096 1097
    //double **s_re2[MAX_eNB+MAX_UE], **s_im2[MAX_eNB+MAX_UE], **r_re2[MAX_eNB+MAX_UE], **r_im2[MAX_eNB+MAX_UE], **r_re02, **r_im02;
    //double **r_re0_d[MAX_UE][MAX_eNB], **r_im0_d[MAX_UE][MAX_eNB], **r_re0_u[MAX_eNB][MAX_UE],**r_im0_u[MAX_eNB][MAX_UE];
    //default parameters
    rate_adaptation_flag = 0;
    oai_emulation.info.n_frames = 0xffff; //1024;          //10;
    oai_emulation.info.n_frames_flag = 0; //fixme
    snr_dB = 30;
    cooperation_flag = 0; // default value 0 for no cooperation, 1 for Delay diversity, 2 for Distributed Alamouti
1098

Raymond Knopp's avatar
 
Raymond Knopp committed
1099 1100 1101 1102 1103
    //Default values if not changed by the user in get_simulation_options();
    pdcp_period = 1;
    omg_period = 1;
    // start thread for log gen
    log_thread_init ();
1104

Raymond Knopp's avatar
 
Raymond Knopp committed
1105
    init_oai_emulation (); // to initialize everything !!!
1106

Raymond Knopp's avatar
 
Raymond Knopp committed
1107 1108
    // get command-line options
    get_simulation_options (argc, argv); //Command-line options
1109

Raymond Knopp's avatar
 
Raymond Knopp committed
1110 1111
    // Initialize VCD LOG module
    vcd_signal_dumper_init (oai_emulation.info.vcd_file);
1112

1113
#if !defined(ENABLE_ITTI)
Raymond Knopp's avatar
 
Raymond Knopp committed
1114 1115 1116 1117 1118 1119 1120 1121 1122
    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);
1123
 
Raymond Knopp's avatar
 
Raymond Knopp committed
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
    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");
    }
1134
#endif 
Raymond Knopp's avatar
 
Raymond Knopp committed
1135 1136
    // configure oaisim with OCG
    oaisim_config (); // config OMG and OCG, OPT, OTG, OLG
1137

Raymond Knopp's avatar
 
Raymond Knopp committed
1138
    if (ue_connection_test == 1) {
1139 1140 1141
      snr_direction = -snr_step;
      snr_dB = 20;
      sinr_dB = -20;
Raymond Knopp's avatar
 
Raymond Knopp committed
1142
    }
1143 1144

#ifdef OPENAIR2
Raymond Knopp's avatar
 
Raymond Knopp committed
1145
    init_omv ();
1146
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1147 1148
    //Before this call, NB_UE_INST and NB_eNB_INST are not set correctly
    check_and_adjust_params ();
1149

Raymond Knopp's avatar
 
Raymond Knopp committed
1150
    set_seed = oai_emulation.emulation_config.seed.value;
1151

Raymond Knopp's avatar
 
Raymond Knopp committed
1152
    init_otg_pdcp_buffer ();
1153

Raymond Knopp's avatar
 
Raymond Knopp committed
1154
    init_seed (set_seed);
1155

Raymond Knopp's avatar
 
Raymond Knopp committed
1156
    init_openair1 ();
1157

Raymond Knopp's avatar
 
Raymond Knopp committed
1158
    init_openair2 ();
1159

Raymond Knopp's avatar
 
Raymond Knopp committed
1160
    init_ocm ();
1161 1162

#ifdef SMBV
Raymond Knopp's avatar
 
Raymond Knopp committed
1163 1164
    smbv_init_config(smbv_fname, smbv_nframes);
    smbv_write_config_from_frame_parms(smbv_fname, &PHY_vars_eNB_g[0][0]->lte_frame_parms);
1165
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1166 1167 1168 1169 1170 1171 1172 1173
    // 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)
      reset_opp_meas();
1174
  
Raymond Knopp's avatar
 
Raymond Knopp committed
1175
    init_time ();
1176

Raymond Knopp's avatar
 
Raymond Knopp committed
1177
    init_slot_isr ();
1178

Raymond Knopp's avatar
 
Raymond Knopp committed
1179
    t = clock ();
1180

Raymond Knopp's avatar
 
Raymond Knopp committed
1181
    LOG_N(EMU, ">>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU initialization done <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
1182 1183

#if defined(ENABLE_ITTI)
Raymond Knopp's avatar
 
Raymond Knopp committed
1184 1185
    // Handle signals until all tasks are terminated
    if (create_tasks(oai_emulation.info.nb_enb_local, oai_emulation.info.nb_ue_local) >= 0) {
1186
      itti_wait_tasks_end();
Raymond Knopp's avatar
 
Raymond Knopp committed
1187
    } else {
1188
      exit(-1); // need a softer mode
Raymond Knopp's avatar
 
Raymond Knopp committed
1189
    }
1190
#else
Raymond Knopp's avatar
 
Raymond Knopp committed
1191
    if (oai_emulation.info.nb_enb_local > 0) {
1192
      eNB_app_task(NULL); // do nothing for the moment
Raymond Knopp's avatar
 
Raymond Knopp committed
1193 1194
    }
    l2l1_task (NULL);
1195
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1196 1197
    t = clock () - t;
    LOG_I (EMU,"Duration of the simulation: %f seconds\n", ((float) t) / CLOCKS_PER_SEC);
1198

Raymond Knopp's avatar
 
Raymond Knopp committed
1199 1200
    //  fclose(SINRpost);
    LOG_N(EMU, ">>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU Ending <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
1201 1202


Raymond Knopp's avatar
 
Raymond Knopp committed
1203 1204
    raise(SIGINT);
    oai_shutdown();
1205

Raymond Knopp's avatar
 
Raymond Knopp committed
1206 1207
    return (0);
  }
1208

Raymond Knopp's avatar
 
Raymond Knopp committed
1209 1210
  void reset_opp_meas(void){
    uint8_t eNB_id=0,UE_id=0;
1211
 
Raymond Knopp's avatar
 
Raymond Knopp committed
1212 1213
    reset_meas(&oaisim_stats);
    reset_meas(&oaisim_stats_f); // frame 
1214
  
Raymond Knopp's avatar
 
Raymond Knopp committed
1215 1216 1217
    // init time stats here (including channel)
    reset_meas(&dl_chan_stats);
    reset_meas(&ul_chan_stats);
1218
  
Raymond Knopp's avatar
 
Raymond Knopp committed
1219 1220 1221 1222
    for (UE_id=0; UE_id<NB_UE_INST; UE_id++) {
      reset_meas(&PHY_vars_UE_g[UE_id][0]->phy_proc);
      reset_meas(&PHY_vars_UE_g[UE_id][0]->phy_proc_rx);
      reset_meas(&PHY_vars_UE_g[UE_id][0]->phy_proc_tx);
1223
    
Raymond Knopp's avatar
 
Raymond Knopp committed
1224 1225 1226 1227 1228 1229 1230 1231 1232 1233
      reset_meas(&PHY_vars_UE_g[UE_id][0]->ofdm_demod_stats);
      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);
      reset_meas(&PHY_vars_UE_g[UE_id][0]->dlsch_decoding_stats);
      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);
1234
    
Raymond Knopp's avatar
 
Raymond Knopp committed
1235 1236 1237 1238 1239 1240 1241
      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);
1242
    
Raymond Knopp's avatar
 
Raymond Knopp committed
1243
      reset_meas(&PHY_vars_UE_g[UE_id][0]->tx_prach);
1244
    
Raymond Knopp's avatar
 
Raymond Knopp committed
1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
      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);
      /*
       * L2 functions
       */ 
1256
    
Raymond Knopp's avatar
 
Raymond Knopp committed
1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271
      // 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);
1272 1273
    
      
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285
    }
    for (eNB_id=0; eNB_id<NB_eNB_INST; eNB_id++) {
      
      for (UE_id=0; UE_id<NB_UE_INST; UE_id++) {
	  reset_meas(&eNB2UE[eNB_id][UE_id][0]->random_channel);
	  reset_meas(&eNB2UE[eNB_id][UE_id][0]->interp_time);
	  reset_meas(&eNB2UE[eNB_id][UE_id][0]->interp_freq);
	  reset_meas(&eNB2UE[eNB_id][UE_id][0]->convolution);
	  reset_meas(&UE2eNB[UE_id][eNB_id][0]->random_channel);
	  reset_meas(&UE2eNB[UE_id][eNB_id][0]->interp_time);
	  reset_meas(&UE2eNB[UE_id][eNB_id][0]->interp_freq);
	  reset_meas(&UE2eNB[UE_id][eNB_id][0]->convolution);
Raymond Knopp's avatar
 
Raymond Knopp committed
1286
      }
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341

      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->phy_proc);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->phy_proc_rx);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->phy_proc_tx);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->rx_prach);
      
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->ofdm_mod_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->dlsch_encoding_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->dlsch_modulation_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->dlsch_scrambling_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->dlsch_rate_matching_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->dlsch_turbo_encoding_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->dlsch_interleaving_stats);
      
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->ofdm_demod_stats);
      //reset_meas(&PHY_vars_eNB_g[eNB_id]->rx_dft_stats);
      //reset_meas(&PHY_vars_eNB_g[eNB_id]->ulsch_channel_estimation_stats);
      //reset_meas(&PHY_vars_eNB_g[eNB_id]->ulsch_freq_offset_estimation_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_decoding_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_demodulation_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_rate_unmatching_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_turbo_decoding_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_deinterleaving_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_demultiplexing_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_llr_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_tc_init_stats);    
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_tc_alpha_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_tc_beta_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_tc_gamma_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_tc_ext_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_tc_intl1_stats);
      reset_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_tc_intl2_stats);
      
      /* 
       * L2 functions 
       */
      // eNB MAC
      reset_meas(&eNB_mac_inst[eNB_id].eNB_scheduler); // total 
      reset_meas(&eNB_mac_inst[eNB_id].schedule_si); // only schedule + tx
      reset_meas(&eNB_mac_inst[eNB_id].schedule_ra); // only ra
      reset_meas(&eNB_mac_inst[eNB_id].schedule_ulsch); // onlu ulsch
      reset_meas(&eNB_mac_inst[eNB_id].fill_DLSCH_dci);// only dci
      reset_meas(&eNB_mac_inst[eNB_id].schedule_dlsch_preprocessor); // include rlc_data_req + MAC header gen
      reset_meas(&eNB_mac_inst[eNB_id].schedule_dlsch); // include rlc_data_req + MAC header gen + pre-processor
      reset_meas(&eNB_mac_inst[eNB_id].schedule_mch); // only embms 
      reset_meas(&eNB_mac_inst[eNB_id].rx_ulsch_sdu); // include rlc_data_ind + mac header parser
      
      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);
      
1342 1343 1344
    }
  }

1345 1346 1347
void print_opp_meas(void){
  
  uint8_t eNB_id=0,UE_id=0;
1348

Raymond Knopp's avatar
 
Raymond Knopp committed
1349 1350
    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);
1351
  
Raymond Knopp's avatar
 
Raymond Knopp committed
1352 1353
    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);
1354
  
Raymond Knopp's avatar
 
Raymond Knopp committed
1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366
    for (UE_id=0; UE_id<NB_UE_INST;UE_id++) {
      for (eNB_id=0; eNB_id<NB_eNB_INST; eNB_id++) {
	print_meas(&eNB2UE[eNB_id][UE_id][0]->random_channel,"[DL][random_channel]",&oaisim_stats,&oaisim_stats_f);
	print_meas(&eNB2UE[eNB_id][UE_id][0]->interp_time,"[DL][interp_time]",&oaisim_stats,&oaisim_stats_f);
	print_meas(&eNB2UE[eNB_id][UE_id][0]->interp_freq,"[DL][interp_freq]",&oaisim_stats,&oaisim_stats_f);
	print_meas(&eNB2UE[eNB_id][UE_id][0]->convolution,"[DL][convolution]",&oaisim_stats,&oaisim_stats_f);

	print_meas(&UE2eNB[UE_id][eNB_id][0]->random_channel,"[UL][random_channel]",&oaisim_stats,&oaisim_stats_f);
	print_meas(&UE2eNB[UE_id][eNB_id][0]->interp_time,"[UL][interp_time]",&oaisim_stats,&oaisim_stats_f);
	print_meas(&UE2eNB[UE_id][eNB_id][0]->interp_freq,"[UL][interp_freq]",&oaisim_stats,&oaisim_stats_f);
	print_meas(&UE2eNB[UE_id][eNB_id][0]->convolution,"[UL][convolution]",&oaisim_stats,&oaisim_stats_f);
      }
1367 1368
    }

Raymond Knopp's avatar
 
Raymond Knopp committed
1369 1370
    for (UE_id=0; UE_id<NB_UE_INST;UE_id++) {
      print_meas(&PHY_vars_UE_g[UE_id][0]->phy_proc,"[UE][total_phy_proc]",&oaisim_stats,&oaisim_stats_f);
1371
    
Raymond Knopp's avatar
 
Raymond Knopp committed
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389
      print_meas(&PHY_vars_UE_g[UE_id][0]->phy_proc_rx,"[UE][total_phy_proc_rx]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_UE_g[UE_id][0]->ofdm_demod_stats,"[UE][ofdm_demod]",&oaisim_stats,&oaisim_stats_f);
      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);
      print_meas(&PHY_vars_UE_g[UE_id][0]->dlsch_decoding_stats,"[UE][decoding]",&oaisim_stats,&oaisim_stats_f);
      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);
1390
    
Raymond Knopp's avatar
 
Raymond Knopp committed
1391 1392 1393 1394 1395 1396 1397 1398 1399
      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);
1400

Raymond Knopp's avatar
 
Raymond Knopp committed
1401
    }
1402
  
Raymond Knopp's avatar
 
Raymond Knopp committed
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413
    for (eNB_id=0; eNB_id<NB_eNB_INST; eNB_id++) {
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->phy_proc,"[eNB][total_phy_proc]",&oaisim_stats,&oaisim_stats_f);

      print_meas(&PHY_vars_eNB_g[eNB_id][0]->phy_proc_tx,"[eNB][total_phy_proc_tx]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->ofdm_mod_stats,"[eNB][ofdm_mod]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->dlsch_modulation_stats,"[eNB][modulation]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->dlsch_scrambling_stats,"[eNB][scrambling]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->dlsch_encoding_stats,"[eNB][encoding]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->dlsch_interleaving_stats,"[eNB][|_interleaving]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->dlsch_rate_matching_stats,"[eNB][|_rate_matching]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->dlsch_turbo_encoding_stats,"[eNB][|_turbo_encoding]",&oaisim_stats,&oaisim_stats_f);
1414 1415
    
    
Raymond Knopp's avatar
 
Raymond Knopp committed
1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->phy_proc_rx,"[eNB][total_phy_proc_rx]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->ofdm_demod_stats,"[eNB][ofdm_demod]",&oaisim_stats,&oaisim_stats_f);
      //print_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_channel_estimation_stats,"[eNB][channel_est]");
      //print_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_freq_offset_estimation_stats,"[eNB][freq_offset]");
      //print_meas(&PHY_vars_eNB_g[eNB_id][0]->rx_dft_stats,"[eNB][rx_dft]");
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_demodulation_stats,"[eNB][demodulation]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_decoding_stats,"[eNB][decoding]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_deinterleaving_stats,"[eNB][|_deinterleaving]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_demultiplexing_stats,"[eNB][|_demultiplexing]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_rate_unmatching_stats,"[eNB][|_rate_unmatching]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_turbo_decoding_stats,"[eNB][|_turbo_decoding]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_tc_init_stats,"[eNB][ |_tc_init]",&oaisim_stats,&oaisim_stats_f);    
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_tc_alpha_stats,"[eNB][ |_tc_alpha]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_tc_beta_stats,"[eNB][ |_tc_beta]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_tc_gamma_stats,"[eNB][ |_tc_gamma]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_tc_ext_stats,"[eNB][ |_tc_ext]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_tc_intl1_stats,"[eNB][ |_tc_intl1]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->ulsch_tc_intl2_stats,"[eNB][ |_tc_intl2]",&oaisim_stats,&oaisim_stats_f);
1434
    
Raymond Knopp's avatar
 
Raymond Knopp committed
1435
      print_meas(&PHY_vars_eNB_g[eNB_id][0]->rx_prach,"[eNB][rx_prach]",&oaisim_stats,&oaisim_stats_f);
1436

Raymond Knopp's avatar
 
Raymond Knopp committed
1437
    }
1438

Raymond Knopp's avatar
 
Raymond Knopp committed
1439
    for (UE_id=0; UE_id<NB_UE_INST;UE_id++) {
1440
   
Raymond Knopp's avatar
 
Raymond Knopp committed
1441 1442 1443 1444 1445 1446
      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); 
1447
   
Raymond Knopp's avatar
 
Raymond Knopp committed
1448 1449 1450 1451 1452 1453 1454 1455
      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);
1456
  
Raymond Knopp's avatar
 
Raymond Knopp committed
1457
    }
1458
  
Raymond Knopp's avatar
 
Raymond Knopp committed
1459
    for (eNB_id=0; eNB_id<NB_eNB_INST; eNB_id++) {
1460
   
Raymond Knopp's avatar
 
Raymond Knopp committed
1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478
      print_meas(&eNB_mac_inst[eNB_id].eNB_scheduler,"[eNB][mac_scheduler]",&oaisim_stats,&oaisim_stats_f); 
      print_meas(&eNB_mac_inst[eNB_id].schedule_si,"[eNB][DL][SI]",&oaisim_stats,&oaisim_stats_f); 
      print_meas(&eNB_mac_inst[eNB_id].schedule_ra,"[eNB][DL][RA]",&oaisim_stats,&oaisim_stats_f); 
      print_meas(&eNB_mac_inst[eNB_id].fill_DLSCH_dci,"[eNB][DL/UL][fill_DCI]",&oaisim_stats,&oaisim_stats_f);
      print_meas(&eNB_mac_inst[eNB_id].schedule_dlsch_preprocessor,"[eNB][DL][preprocessor]",&oaisim_stats,&oaisim_stats_f); 
      print_meas(&eNB_mac_inst[eNB_id].schedule_dlsch,"[eNB][DL][schedule_tx_dlsch]",&oaisim_stats,&oaisim_stats_f); 
      print_meas(&eNB_mac_inst[eNB_id].schedule_mch,"[eNB][DL][mch]",&oaisim_stats,&oaisim_stats_f); 
      print_meas(&eNB_mac_inst[eNB_id].schedule_ulsch,"[eNB][UL][ULSCH]",&oaisim_stats,&oaisim_stats_f); 
      print_meas(&eNB_mac_inst[eNB_id].rx_ulsch_sdu,"[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);
1479
  
Raymond Knopp's avatar
 
Raymond Knopp committed
1480
    }
1481
  
Raymond Knopp's avatar
 
Raymond Knopp committed
1482
  }
1483 1484


1485

Raymond Knopp's avatar
 
Raymond Knopp committed
1486
  static void *sigh(void *arg) {
1487

Raymond Knopp's avatar
 
Raymond Knopp committed
1488 1489 1490 1491 1492 1493 1494
    int signum;
    sigset_t sigcatch;
    sigemptyset(&sigcatch);
    sigaddset(&sigcatch, SIGHUP);
    sigaddset(&sigcatch, SIGINT);
    sigaddset(&sigcatch, SIGTERM);
    sigaddset(&sigcatch, SIGQUIT);
1495
   
Raymond Knopp's avatar
 
Raymond Knopp committed
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
    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;
      }
    }
    pthread_exit(NULL);
  }


  void oai_shutdown(void) {
    static int done=0;
    int i;
    char interfaceName[8];
1522
  
Raymond Knopp's avatar
 
Raymond Knopp committed
1523 1524
    if (done)
      return;
1525

Raymond Knopp's avatar
 
Raymond Knopp committed
1526
    free (otg_pdcp_buffer);
1527 1528

#ifdef SMBV
Raymond Knopp's avatar
 
Raymond Knopp committed
1529 1530 1531
    if (config_smbv) {
      smbv_send_config (smbv_fname,smbv_ip);
    }
1532 1533
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
1534 1535 1536
    //Perform KPI measurements
    if (oai_emulation.info.otg_enabled == 1)
      kpi_gen ();
1537

Raymond Knopp's avatar
 
Raymond Knopp committed
1538 1539
    if (oai_emulation.info.opp_enabled == 1)
      print_opp_meas();
1540
  
Raymond Knopp's avatar
 
Raymond Knopp committed
1541 1542
    // relase all rx state
    if (ethernet_flag == 1) {
1543
      emu_transport_release ();
Raymond Knopp's avatar
 
Raymond Knopp committed
1544
    }
1545 1546

#ifdef PROC
Raymond Knopp's avatar
 
Raymond Knopp committed
1547
    if (abstraction_flag == 0 && Channel_Flag==0 && Process_Flag==0)
1548
#else
Raymond Knopp's avatar
 
Raymond Knopp committed
1549
      if (abstraction_flag == 0)
1550
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561
	{
	  /*
	    #ifdef IFFT_FPGA
	    free(txdataF2[0]);
	    free(txdataF2[1]);
	    free(txdataF2);
	    free(txdata[0]);
	    free(txdata[1]);
	    free(txdata);
	    #endif
	  */
1562
      
Raymond Knopp's avatar
 
Raymond Knopp committed
1563 1564 1565 1566 1567 1568 1569 1570 1571 1572
	  for (i = 0; i < 2; i++) {
	    free (s_re[i]);
	    free (s_im[i]);
	    free (r_re[i]);
	    free (r_im[i]);
	  }
	  free (s_re);
	  free (s_im);
	  free (r_re);
	  free (r_im);
1573
      
Raymond Knopp's avatar
 
Raymond Knopp committed
1574 1575
	  lte_sync_time_free ();
	}
1576
  
Raymond Knopp's avatar
 
Raymond Knopp committed
1577 1578 1579 1580 1581 1582 1583 1584 1585
    // 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]);
      }
      for (UE_inst = 0; UE_inst < NUMBER_OF_UE_MAX; UE_inst++) {
	free (ue_data[UE_inst]);
      }
    } //End of PHY abstraction changes
1586 1587
  
#ifdef OPENAIR2
Raymond Knopp's avatar
 
Raymond Knopp committed
1588
    mac_top_cleanup ();
1589 1590
#endif 

Raymond Knopp's avatar
 
Raymond Knopp committed
1591 1592
    // stop OMG
    stop_mobility_generator (omg_param_list); //omg_param_list.mobility_type
1593
#ifdef OPENAIR2
Raymond Knopp's avatar
 
Raymond Knopp committed
1594 1595
    if (oai_emulation.info.omv_enabled == 1)
      omv_end (pfd[1], omv_data);
1596
#endif
Raymond Knopp's avatar
 
Raymond Knopp committed
1597 1598
    if ((oai_emulation.info.ocm_enabled == 1) && (ethernet_flag == 0) && (ShaF != NULL))
      destroyMat (ShaF, map1, map2);
1599
  
Raymond Knopp's avatar
 
Raymond Knopp committed
1600 1601
    if ((oai_emulation.info.opt_enabled == 1))
      terminate_opt ();
1602

Raymond Knopp's avatar
 
Raymond Knopp committed
1603 1604
    if (oai_emulation.info.cli_enabled)
      cli_server_cleanup ();
1605

Raymond Knopp's avatar
 
Raymond Knopp committed
1606 1607 1608 1609 1610
    for (i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++)
      if (oai_emulation.info.oai_ifup[i] == 1) {
	sprintf (interfaceName, "oai%d", i);
	bringInterfaceUp (interfaceName, 0);
      }
1611
  
Raymond Knopp's avatar
 
Raymond Knopp committed
1612 1613 1614 1615
    log_thread_finalize ();
    logClean ();
    vcd_signal_dumper_close ();
    done =1;
1616
  
Raymond Knopp's avatar
 
Raymond Knopp committed
1617 1618
    LOG_N(EMU, ">>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU shutdown <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
  }
1619

Raymond Knopp's avatar
 
Raymond Knopp committed
1620 1621 1622 1623
  eNB_MAC_INST* get_eNB_mac_inst(module_id_t module_idP)
  {
    return (&eNB_mac_inst[module_idP]);
  }
1624

Raymond Knopp's avatar
 
Raymond Knopp committed
1625 1626 1627 1628
  OAI_Emulation* get_OAI_emulation()
  {
    return &oai_emulation;
  }