oaisim_functions.c 53.1 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

28
 *******************************************************************************/
29
30


31
32
33
34
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
35
#include <execinfo.h>
36
#include <time.h>
gauthier's avatar
gauthier committed
37
#include <mcheck.h>
38
#include <sys/timerfd.h>
39

40
#include "assertions.h"
41
42
43
44
45
#include "oaisim_functions.h"

#include "PHY/extern.h"
#include "MAC_INTERFACE/extern.h"
#include "LAYER2/MAC/extern.h"
46
47
48
#ifdef OPENAIR2
#include "LAYER2/MAC/proto.h"
#endif 
49
50
51
#include "LAYER2/PDCP_v10.1.0/pdcp.h"
#include "LAYER2/PDCP_v10.1.0/pdcp_primitives.h"
#include "RRC/LITE/extern.h"
Cedric Roux's avatar
Cedric Roux committed
52
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
53
#include "PHY_INTERFACE/extern.h"
54
//#include "ARCH/CBMIMO1/DEVICE_DRIVER/extern.h"
55
#include "SCHED/extern.h"
Cedric Roux's avatar
Cedric Roux committed
56
#include "SIMULATION/ETH_TRANSPORT/proto.h"
57
58
59
#include "UTIL/OCG/OCG_extern.h"
#include "UTIL/LOG/vcd_signal_dumper.h"
#include "UTIL/OPT/opt.h"
60
#include "UTIL/OTG/otg_config.h"
winckel's avatar
winckel committed
61
#include "UTIL/OTG/otg_tx.h"
62
63
#include "lteRALenb.h"
#include "lteRALue.h"
64

Cedric Roux's avatar
Cedric Roux committed
65
#include "cor_SF_sim.h"
66
#include "enb_config.h"
Cedric Roux's avatar
Cedric Roux committed
67

68
69
70
71
#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
#endif

72
73
74
75
#if defined(ENABLE_USE_MME)
# include "s1ap_eNB.h"
#endif

76
#ifdef SMBV
gauthier's avatar
gauthier committed
77
extern uint8_t config_smbv;
78
79
80
81
82
83
84
85
86
extern char smbv_ip[16];
#endif

//constant for OAISIM soft realtime calibration
#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

gauthier's avatar
gauthier committed
87
88
89
90
int           otg_times             = 0;
int           if_times              = 0;
int           for_times             = 0;

gauthier's avatar
gauthier committed
91
uint16_t           Nid_cell              = 0; //needed by init_lte_vars
gauthier's avatar
gauthier committed
92
int           nb_antennas_rx        = 2; // //
93
uint8_t            target_dl_mcs         = 16; // max mcs used by MAC scheduler
gauthier's avatar
gauthier committed
94
uint8_t            rate_adaptation_flag  = 0;
95
uint8_t 		   set_snr				 = 0;
gauthier's avatar
gauthier committed
96
uint8_t            set_sinr              = 0;
97
double             snr_dB=0, sinr_dB=0;
gauthier's avatar
gauthier committed
98
99
100
101
uint8_t            set_seed              = 0;
uint8_t            cooperation_flag;          // for cooperative communication
uint8_t            abstraction_flag      = 0;
uint8_t            ethernet_flag         = 0;
gauthier's avatar
gauthier committed
102
double        snr_step              = 1.0;
gauthier's avatar
gauthier committed
103
uint8_t            ue_connection_test    = 0;
gauthier's avatar
gauthier committed
104
double        forgetting_factor     = 0.0;
gauthier's avatar
gauthier committed
105
106
107
uint8_t            beta_ACK              = 0;
uint8_t            beta_RI               = 0;
uint8_t            beta_CQI              = 2;
108
uint8_t            target_ul_mcs         = 16;
knopp's avatar
   
knopp committed
109
LTE_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs];
gauthier's avatar
gauthier committed
110
111
int           map1,map2;
double      **ShaF                  = NULL;
112
// pointers signal buffers (s = transmit, r,r0 = receive)
gauthier's avatar
gauthier committed
113
double      **s_re, **s_im, **r_re, **r_im, **r_re0, **r_im0;
114
115
node_list*     ue_node_list          = NULL;
node_list*     enb_node_list         = NULL;
gauthier's avatar
gauthier committed
116
int           omg_period            = 0;
117
int           pdcp_period           = 0;
118
int           cba_backoff           = 30;
119
120
// time calibration for soft realtime mode
struct timespec time_spec;
gauthier's avatar
gauthier committed
121
122
123
124
125
unsigned long   time_last           = 0;
unsigned long   time_now            = 0;
int             td                  = 0;
int             td_avg              = 0;
int             sleep_time_us       = 0;
126
127
128
129
130

#ifdef OPENAIR2
// omv related info
//pid_t omv_pid;
char full_name[200];
131
extern int pfd[2]; // fd for omv : fixme: this could be a local var
132
133
134
135
136
137
138
139
140
141
142
143
144
char fdstr[10];
char frames[10];
char num_enb[10];
char num_ue[10];
//area_x, area_y and area_z for omv
char x_area[20];
char y_area[20];
char z_area[20];
char nb_antenna[20];
char frame_type[10];
char tdd_config[10];
#endif

gauthier's avatar
gauthier committed
145
Packet_OTG_List_t *otg_pdcp_buffer = NULL;
146
147
148

extern node_desc_t *enb_data[NUMBER_OF_eNB_MAX];
extern node_desc_t *ue_data[NUMBER_OF_UE_MAX];
knopp's avatar
   
knopp committed
149
150
extern channel_desc_t *eNB2UE[NUMBER_OF_eNB_MAX][NUMBER_OF_UE_MAX][MAX_NUM_CCs];
extern channel_desc_t *UE2eNB[NUMBER_OF_UE_MAX][NUMBER_OF_eNB_MAX][MAX_NUM_CCs];
151
152

extern mapping small_scale_names[];
gauthier's avatar
gauthier committed
153
154
155
156
#if defined(Rel10)
extern pdcp_mbms_t pdcp_mbms_array_ue[NUMBER_OF_UE_MAX][maxServiceCount][maxSessionPerPMCH];
extern pdcp_mbms_t pdcp_mbms_array_eNB[NUMBER_OF_eNB_MAX][maxServiceCount][maxSessionPerPMCH];
#endif
157

158
159
extern time_stats_t dl_chan_stats;
extern time_stats_t ul_chan_stats;
160

winckel's avatar
winckel committed
161
162
163
void get_simulation_options(int argc, char *argv[]) {
  int                           option;
  const Enb_properties_array_t *enb_properties;
164
  char  *conf_config_file_name = NULL;
winckel's avatar
winckel committed
165

winckel's avatar
winckel committed
166
  enum long_option_e {
gauthier's avatar
gauthier committed
167
    LONG_OPTION_START = 0x100, /* Start after regular single char options */
winckel's avatar
winckel committed
168

gauthier's avatar
gauthier committed
169
    LONG_OPTION_ENB_CONF,
winckel's avatar
winckel committed
170

gauthier's avatar
gauthier committed
171
172
    LONG_OPTION_PDNC_PERIOD,
    LONG_OPTION_OMG_PERIOD,
173
    LONG_OPTION_OEH_ENABLED,
winckel's avatar
winckel committed
174

gauthier's avatar
gauthier committed
175
176
177
178
    LONG_OPTION_ENB_RAL_LISTENING_PORT,
    LONG_OPTION_ENB_RAL_IP_ADDRESS,
    LONG_OPTION_ENB_RAL_LINK_ID,
    LONG_OPTION_ENB_RAL_LINK_ADDRESS,
winckel's avatar
winckel committed
179

gauthier's avatar
gauthier committed
180
181
182
    LONG_OPTION_ENB_MIHF_REMOTE_PORT,
    LONG_OPTION_ENB_MIHF_IP_ADDRESS,
    LONG_OPTION_ENB_MIHF_ID,
winckel's avatar
winckel committed
183

gauthier's avatar
gauthier committed
184
185
186
187
    LONG_OPTION_UE_RAL_LISTENING_PORT,
    LONG_OPTION_UE_RAL_IP_ADDRESS,
    LONG_OPTION_UE_RAL_LINK_ID,
    LONG_OPTION_UE_RAL_LINK_ADDRESS,
winckel's avatar
winckel committed
188

gauthier's avatar
gauthier committed
189
190
191
    LONG_OPTION_UE_MIHF_REMOTE_PORT,
    LONG_OPTION_UE_MIHF_IP_ADDRESS,
    LONG_OPTION_UE_MIHF_ID,
gauthier's avatar
gauthier committed
192
193

    LONG_OPTION_MALLOC_TRACE_ENABLED,
194
195

    LONG_OPTION_CBA_BACKOFF_TIMER,
winckel's avatar
winckel committed
196
  };
winckel's avatar
winckel committed
197

winckel's avatar
winckel committed
198
  static struct option long_options[] = {
gauthier's avatar
gauthier committed
199
      {"enb-conf",               required_argument, 0, LONG_OPTION_ENB_CONF},
winckel's avatar
winckel committed
200

201
202
203
      {"pdcp-period",            required_argument, 0, LONG_OPTION_PDNC_PERIOD},
      {"omg-period",             required_argument, 0, LONG_OPTION_OMG_PERIOD},
      {"oeh-enabled",            no_argument, 0, LONG_OPTION_OEH_ENABLED},
winckel's avatar
winckel committed
204

gauthier's avatar
gauthier committed
205
206
207
208
      {"enb-ral-listening-port", required_argument, 0, LONG_OPTION_ENB_RAL_LISTENING_PORT},
      {"enb-ral-ip-address",     required_argument, 0, LONG_OPTION_ENB_RAL_IP_ADDRESS},
      {"enb-ral-link-id",        required_argument, 0, LONG_OPTION_ENB_RAL_LINK_ID},
      {"enb-ral-link-address",   required_argument, 0, LONG_OPTION_ENB_RAL_LINK_ADDRESS},
winckel's avatar
winckel committed
209

gauthier's avatar
gauthier committed
210
211
212
      {"enb-mihf-remote-port",   required_argument, 0, LONG_OPTION_ENB_MIHF_REMOTE_PORT},
      {"enb-mihf-ip-address",    required_argument, 0, LONG_OPTION_ENB_MIHF_IP_ADDRESS},
      {"enb-mihf-id",            required_argument, 0, LONG_OPTION_ENB_MIHF_ID},
winckel's avatar
winckel committed
213

gauthier's avatar
gauthier committed
214
215
216
217
      {"ue-ral-listening-port",  required_argument, 0, LONG_OPTION_UE_RAL_LISTENING_PORT},
      {"ue-ral-ip-address",      required_argument, 0, LONG_OPTION_UE_RAL_IP_ADDRESS},
      {"ue-ral-link-id",         required_argument, 0, LONG_OPTION_UE_RAL_LINK_ID},
      {"ue-ral-link-address",    required_argument, 0, LONG_OPTION_UE_RAL_LINK_ADDRESS},
winckel's avatar
winckel committed
218

gauthier's avatar
gauthier committed
219
220
221
      {"ue-mihf-remote-port",    required_argument, 0, LONG_OPTION_UE_MIHF_REMOTE_PORT},
      {"ue-mihf-ip-address",     required_argument, 0, LONG_OPTION_UE_MIHF_IP_ADDRESS},
      {"ue-mihf-id",             required_argument, 0, LONG_OPTION_UE_MIHF_ID},
222

gauthier's avatar
gauthier committed
223
      {"malloc-trace-enabled",   no_argument,       0, LONG_OPTION_MALLOC_TRACE_ENABLED},
224
225
226

      {"cba-backoff",            required_argument, 0, LONG_OPTION_CBA_BACKOFF_TIMER},

gauthier's avatar
gauthier committed
227
      {NULL, 0, NULL, 0}
winckel's avatar
winckel committed
228
  };
winckel's avatar
winckel committed
229

230
  while ((option = getopt_long (argc, argv, "aA:b:B:c:C:D:d:eE:f:FGg:hHi:IJ:j:k:K:l:L:m:M:n:N:oO:p:P:qQ:rR:s:S:t:T:u:U:vV:w:W:x:X:y:Y:z:Z:", long_options, NULL)) != -1) {
gauthier's avatar
gauthier committed
231
232
233
      switch (option) {
      case LONG_OPTION_ENB_CONF:
        if (optarg) {
234
            free(conf_config_file_name); // prevent memory leak if option is used multiple times
gauthier's avatar
gauthier committed
235
236
237
238
            conf_config_file_name = strdup(optarg);
            printf("eNB configuration file is %s\n", conf_config_file_name);
        }
        break;
winckel's avatar
winckel committed
239

gauthier's avatar
gauthier committed
240
241
242
243
244
245
      case LONG_OPTION_PDNC_PERIOD:
        if (optarg) {
            pdcp_period = atoi(optarg);
            printf("PDCP period is %d\n", pdcp_period);
        }
        break;
winckel's avatar
winckel committed
246

gauthier's avatar
gauthier committed
247
248
      case LONG_OPTION_OMG_PERIOD:
        if (optarg) {
249
	  omg_period = atoi(optarg);
gauthier's avatar
gauthier committed
250
251
252
            printf("OMG period is %d\n", omg_period);
        }
        break;
253
254
      
      case LONG_OPTION_OEH_ENABLED:
255
256
	oai_emulation.info.oeh_enabled = 1;
	break;
gauthier's avatar
gauthier committed
257
258
259

      case LONG_OPTION_MALLOC_TRACE_ENABLED:
    	 mtrace();
260
261
262
263
264
265
266
	 break;

      case LONG_OPTION_CBA_BACKOFF_TIMER:
	oai_emulation.info.cba_backoff=atoi(optarg);
	cba_backoff=atoi(optarg);
	printf("setting CBA backoff to %d\n", cba_backoff);
	break;
gauthier's avatar
gauthier committed
267

268
#if defined(ENABLE_RAL)
gauthier's avatar
gauthier committed
269
270
      case LONG_OPTION_ENB_RAL_LISTENING_PORT:
        if (optarg) {
271
272
	  g_conf_enb_ral_listening_port = strdup(optarg);
	  printf("eNB RAL listening port is %s\n", g_conf_enb_ral_listening_port);
gauthier's avatar
gauthier committed
273
274
        }
        break;
275
	
gauthier's avatar
gauthier committed
276
277
      case LONG_OPTION_ENB_RAL_IP_ADDRESS:
        if (optarg) {
278
279
	  g_conf_enb_ral_ip_address = strdup(optarg);
	  printf("eNB RAL IP address is %s\n", g_conf_enb_ral_ip_address);
gauthier's avatar
gauthier committed
280
281
        }
        break;
282
	
gauthier's avatar
gauthier committed
283
284
      case LONG_OPTION_ENB_RAL_LINK_ADDRESS:
        if (optarg) {
285
286
	  g_conf_enb_ral_link_address = strdup(optarg);
	  printf("eNB RAL link address is %s\n", g_conf_enb_ral_link_address);
gauthier's avatar
gauthier committed
287
288
        }
        break;
289
	
gauthier's avatar
gauthier committed
290
291
      case LONG_OPTION_ENB_RAL_LINK_ID:
        if (optarg) {
292
293
	  g_conf_enb_ral_link_id = strdup(optarg);
	  printf("eNB RAL link id is %s\n", g_conf_enb_ral_link_id);
gauthier's avatar
gauthier committed
294
295
        }
        break;
296
	
gauthier's avatar
gauthier committed
297
298
      case LONG_OPTION_ENB_MIHF_REMOTE_PORT:
        if (optarg) {
299
300
	  g_conf_enb_mihf_remote_port = strdup(optarg);
	  printf("eNB MIH-F remote port is %s\n", g_conf_enb_mihf_remote_port);
gauthier's avatar
gauthier committed
301
302
        }
        break;
303
	
gauthier's avatar
gauthier committed
304
305
      case LONG_OPTION_ENB_MIHF_IP_ADDRESS:
        if (optarg) {
306
307
	  g_conf_enb_mihf_ip_address = strdup(optarg);
	  printf("eNB MIH-F IP address is %s\n", g_conf_enb_mihf_ip_address);
gauthier's avatar
gauthier committed
308
309
        }
        break;
310
	
gauthier's avatar
gauthier committed
311
312
      case LONG_OPTION_ENB_MIHF_ID:
        if (optarg) {
313
314
	  g_conf_enb_mihf_id = strdup(optarg);
	  printf("eNB MIH-F id is %s\n", g_conf_enb_mihf_id);
gauthier's avatar
gauthier committed
315
316
        }
        break;
317
	
gauthier's avatar
gauthier committed
318
319
      case LONG_OPTION_UE_RAL_LISTENING_PORT:
        if (optarg) {
320
321
	  g_conf_ue_ral_listening_port = strdup(optarg);
	  printf("UE RAL listening port is %s\n", g_conf_ue_ral_listening_port);
gauthier's avatar
gauthier committed
322
323
        }
        break;
324
	
gauthier's avatar
gauthier committed
325
326
      case LONG_OPTION_UE_RAL_IP_ADDRESS:
        if (optarg) {
327
328
	  g_conf_ue_ral_ip_address = strdup(optarg);
	  printf("UE RAL IP address is %s\n", g_conf_ue_ral_ip_address);
gauthier's avatar
gauthier committed
329
330
        }
        break;
331
	
gauthier's avatar
gauthier committed
332
333
      case LONG_OPTION_UE_RAL_LINK_ID:
        if (optarg) {
334
335
	  g_conf_ue_ral_link_id = strdup(optarg);
	  printf("UE RAL link id is %s\n", g_conf_ue_ral_link_id);
gauthier's avatar
gauthier committed
336
337
        }
        break;
338
	
gauthier's avatar
gauthier committed
339
340
      case LONG_OPTION_UE_RAL_LINK_ADDRESS:
        if (optarg) {
341
342
	  g_conf_ue_ral_link_address = strdup(optarg);
	  printf("UE RAL link address is %s\n", g_conf_ue_ral_link_address);
gauthier's avatar
gauthier committed
343
344
        }
        break;
345
	
gauthier's avatar
gauthier committed
346
347
      case LONG_OPTION_UE_MIHF_REMOTE_PORT:
        if (optarg) {
348
349
	  g_conf_ue_mihf_remote_port = strdup(optarg);
	  printf("UE MIH-F remote port is %s\n", g_conf_ue_mihf_remote_port);
gauthier's avatar
gauthier committed
350
351
        }
        break;
352
	
gauthier's avatar
gauthier committed
353
354
      case LONG_OPTION_UE_MIHF_IP_ADDRESS:
        if (optarg) {
355
356
	  g_conf_ue_mihf_ip_address = strdup(optarg);
	  printf("UE MIH-F IP address is %s\n", g_conf_ue_mihf_ip_address);
gauthier's avatar
gauthier committed
357
358
        }
        break;
winckel's avatar
winckel committed
359

gauthier's avatar
gauthier committed
360
361
      case LONG_OPTION_UE_MIHF_ID:
        if (optarg) {
362
363
	  g_conf_ue_mihf_id = strdup(optarg);
	  printf("UE MIH-F id is %s\n", g_conf_ue_mihf_id);
gauthier's avatar
gauthier committed
364
365
        }
        break;
366
#endif
367
	
gauthier's avatar
gauthier committed
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
      case 'a':
        abstraction_flag = 1;
        break;

      case 'A':
        //oai_emulation.info.ocm_enabled=1;
        if (optarg == NULL)
          oai_emulation.environment_system_config.fading.small_scale.selected_option="AWGN";
        else
          oai_emulation.environment_system_config.fading.small_scale.selected_option= optarg;
        //awgn_flag = 1;
        break;

      case 'b':
        oai_emulation.info.nb_enb_local = atoi (optarg);
        break;

      case 'B':
        oai_emulation.topology_config.mobility.eNB_mobility.eNB_mobility_type.selected_option = optarg;
        //oai_emulation.info.omg_model_enb = atoi (optarg);
        break;

      case 'c':
nikaeinn's avatar
nikaeinn committed
391
392
393
394
        //strcpy(oai_emulation.info.local_server, optarg);
	strncpy(oai_emulation.info.local_server, optarg, sizeof(oai_emulation.info.local_server));
	oai_emulation.info.local_server[sizeof(oai_emulation.info.local_server) - 1] = 0; // terminate string
	oai_emulation.info.ocg_enabled=1;
gauthier's avatar
gauthier committed
395
396
397
        break;

      case 'C':
knopp's avatar
   
knopp committed
398
399
400
        oai_emulation.info.tdd_config[0] = atoi (optarg);
        AssertFatal (oai_emulation.info.tdd_config[0] <= TDD_Config__subframeAssignment_sa6, "Illegal tdd_config %d (should be 0-%d)!",
            oai_emulation.info.tdd_config[0], TDD_Config__subframeAssignment_sa6);
gauthier's avatar
gauthier committed
401
402
403
404
405
406
407
        break;

      case 'D':
        oai_emulation.info.multicast_ifname = strdup(optarg);
        break;

      case 'e':
knopp's avatar
   
knopp committed
408
        oai_emulation.info.extended_prefix_flag[0] = 1;
gauthier's avatar
gauthier committed
409
410
411
412
413
414
415
416
417
418
419
420
421
        break;

      case 'E':
        set_seed = 1;
        oai_emulation.info.seed = atoi (optarg);
        break;

      case 'f':
        forgetting_factor = atof (optarg);
        break;

      case 'F':                   // set FDD
        printf("Setting Frame to FDD\n");
knopp's avatar
   
knopp committed
422
        oai_emulation.info.frame_type[0] = 0;
423
	oai_emulation.info.frame_type_name[0] = "FDD";
gauthier's avatar
gauthier committed
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
        break;

      case 'g':
        oai_emulation.info.multicast_group = atoi (optarg);
        break;

      case 'G' :
        oai_emulation.info.otg_bg_traffic_enabled = 1;
        break;

      case 'h':
        help ();
        exit (1);
        break;

      case 'H':
        oai_emulation.info.handover_active=1;
        printf("Activate the handover procedure at RRC\n");
        break;

      case 'i':
winckel's avatar
winckel committed
445
#ifdef PROC
gauthier's avatar
gauthier committed
446
447
448
        Process_Flag=1;
        node_id = wgt+atoi(optarg);
        port+=atoi(optarg);
winckel's avatar
winckel committed
449
#endif
gauthier's avatar
gauthier committed
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
        break;

      case 'I':
        oai_emulation.info.cli_enabled = 1;
        break;

      case 'j' :
        // number of relay nodes: currently only applicable to eMBMS
        oai_emulation.info.nb_rn_local = atoi (optarg);
        break;

      case 'J':
        ue_connection_test=1;
        oai_emulation.info.ocm_enabled=0;
        snr_step = atof(optarg);
        break;

      case 'k':
        //ricean_factor = atof (optarg);
        printf("[SIM] Option k is no longer supported on the command line. Please specify your channel model in the xml template\n");
winckel's avatar
winckel committed
470
        exit(-1);
gauthier's avatar
gauthier committed
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
        break;

      case 'K':
        oai_emulation.info.itti_dump_file = optarg;
        break;

      case 'l':
        oai_emulation.info.g_log_level = atoi(optarg);
        break;

      case 'L':                   // set FDD
        flag_LA = atoi(optarg);
        break;

      case 'm':
        target_dl_mcs = atoi (optarg);
487
	printf("Max target downlink MCS used by MAC scheduler is set to %d\n", target_dl_mcs);
gauthier's avatar
gauthier committed
488
489
490
491
492
493
494
495
496
497
498
499
        break;

      case 'M':
        abstraction_flag = 1;
        ethernet_flag = 1;
        oai_emulation.info.ethernet_id = atoi (optarg);
        oai_emulation.info.master_id = oai_emulation.info.ethernet_id;
        oai_emulation.info.ethernet_flag = 1;
        break;

      case 'n':
        oai_emulation.info.n_frames = atoi (optarg);
500
	oai_emulation.emulation_config.emulation_time_ms= oai_emulation.info.n_frames * 10; // 10 ms frame
gauthier's avatar
gauthier committed
501
502
503
504
505
506
507
508
509
510
511
512
513
        //n_frames = (n_frames >1024) ? 1024: n_frames; // adjust the n_frames if higher that 1024
        oai_emulation.info.n_frames_flag = 1;
        break;

      case 'N':
        Nid_cell = atoi (optarg);
        if (Nid_cell > 503) {
            printf("Illegal Nid_cell %d (should be 0 ... 503)\n", Nid_cell);
            exit(-1);
        }
        break;

      case 'O':
514
515
516
517
        if (optarg) {
            free(conf_config_file_name); // prevent memory leak if option is used multiple times
            conf_config_file_name = strdup(optarg);
        }
gauthier's avatar
gauthier committed
518
519
520
521
522
523
524
525
526
527
528
529
        break;

      case 'o':
        oai_emulation.info.slot_isr = 1;
        break;

      case 'p':
        oai_emulation.info.nb_master = atoi (optarg);
        break;

      case 'P':
        oai_emulation.info.opt_enabled = 1;
530
	opt_enabled = 1;
gauthier's avatar
gauthier committed
531
532
533
534
535
536
537
538
539
540
541
        if (strcmp(optarg, "wireshark") == 0) {
            opt_type = OPT_WIRESHARK;
            printf("Enabling OPT for wireshark\n");
        } else if (strcmp(optarg, "pcap") == 0) {
            opt_type = OPT_PCAP;
            printf("Enabling OPT for pcap\n");
        } else {
            printf("Unrecognized option for OPT module. -> Disabling it\n");
            printf("Possible values are either wireshark or pcap\n");
            opt_type = OPT_NONE;
            oai_emulation.info.opt_enabled = 0;
542
	    opt_enabled = 0;
gauthier's avatar
gauthier committed
543
544
545
        }
        oai_emulation.info.opt_mode = opt_type;
        break;
546
547
548
549
550
      case 'q':
        // openair performane profiler 
        oai_emulation.info.opp_enabled = 1; // this var is used for OCG
        opp_enabled = 1; // this is the global var used by oaisim 
        break;
gauthier's avatar
gauthier committed
551
552
553
554
555
556
557
558
559
560
561
      case 'Q':
        //eMBMS_active=1;
        // 0 : not used (default), 1: eMBMS and RRC enabled, 2: eMBMS relaying and RRC enabled, 3: eMBMS enabled, RRC disabled, 4: eMBMS relaying enabled, RRC disabled
        oai_emulation.info.eMBMS_active_state = atoi (optarg);
        break;

      case 'r':
        rate_adaptation_flag = 1;
        break;

      case 'R':
knopp's avatar
   
knopp committed
562
563
564
565
        oai_emulation.info.N_RB_DL[0] = atoi (optarg);
        if ((oai_emulation.info.N_RB_DL[0] != 6) && (oai_emulation.info.N_RB_DL[0] != 15) && (oai_emulation.info.N_RB_DL[0] != 25)
            && (oai_emulation.info.N_RB_DL[0] != 50) && (oai_emulation.info.N_RB_DL[0] != 75) && (oai_emulation.info.N_RB_DL[0] != 100)) {
            printf("Illegal N_RB_DL %d (should be one of 6,15,25,50,75,100)\n", oai_emulation.info.N_RB_DL[0]);
gauthier's avatar
gauthier committed
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
            exit (-1);
        }
        break;

      case 's':
        snr_dB = atoi (optarg);
        //      set_snr = 1;
        oai_emulation.info.ocm_enabled=0;
        break;

      case 'S':
        sinr_dB = atoi (optarg);
        set_sinr = 1;
        oai_emulation.info.ocm_enabled=0;
        break;

      case 't':
583
        target_ul_mcs = atoi (optarg);
584
585
	printf("Max target uplink MCS used by MAC scheduler is set to %d\n", target_ul_mcs);
	break;
gauthier's avatar
gauthier committed
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614

      case 'T':
        oai_emulation.info.otg_enabled = 1;
        oai_emulation.info.otg_traffic = optarg;
        break;

      case 'u':
        oai_emulation.info.nb_ue_local = atoi (optarg);
        break;

      case 'U':
        oai_emulation.topology_config.mobility.UE_mobility.UE_mobility_type.selected_option = optarg;
        break;

      case 'v':
        oai_emulation.info.omv_enabled = 1;
        break;

      case 'V':
        ouput_vcd = 1;
        oai_emulation.info.vcd_enabled = 1;
        oai_emulation.info.vcd_file = optarg;
        break;

      case 'w':
        oai_emulation.info.cba_group_active = atoi (optarg);
        break;

      case 'W':
615
#ifdef SMBV
gauthier's avatar
gauthier committed
616
617
618
        config_smbv = 1;
        if(atoi(optarg)!=0)
          strcpy(smbv_ip,optarg);
619
#endif
gauthier's avatar
gauthier committed
620
        break;
winckel's avatar
winckel committed
621

gauthier's avatar
gauthier committed
622
      case 'x':
knopp's avatar
   
knopp committed
623
        oai_emulation.info.transmission_mode[0] = atoi (optarg);
624
        if ((oai_emulation.info.transmission_mode[0] != 1) &&  (oai_emulation.info.transmission_mode[0] != 2) && (oai_emulation.info.transmission_mode[0] != 3) && (oai_emulation.info.transmission_mode[0] != 5) && (oai_emulation.info.transmission_mode[0] != 6)) {
thomasl's avatar
thomasl committed
625
            printf("Unsupported transmission mode %d\n",oai_emulation.info.transmission_mode[0]);
gauthier's avatar
gauthier committed
626
627
628
            exit(-1);
        }
        break;
winckel's avatar
winckel committed
629

gauthier's avatar
gauthier committed
630
      case 'X':
winckel's avatar
winckel committed
631
#ifdef PROC
gauthier's avatar
gauthier committed
632
633
634
635
636
637
638
639
640
641
        temp=atoi(optarg);
        if(temp==0){
            port=CHANNEL_PORT; Channel_Flag=1; Process_Flag=0; wgt=0;
        }
        else if(temp==1){
            port=eNB_PORT; wgt=0;
        }
        else {
            port=UE_PORT; wgt=MAX_eNB;
        }
winckel's avatar
winckel committed
642
#endif
gauthier's avatar
gauthier committed
643
        break;
winckel's avatar
winckel committed
644

gauthier's avatar
gauthier committed
645
646
647
648
649
650
651
      case 'y':
        nb_antennas_rx=atoi(optarg);
        if (nb_antennas_rx>4) {
            printf("Cannot have more than 4 antennas\n");
            exit(-1);
        }
        break;
winckel's avatar
winckel committed
652

gauthier's avatar
gauthier committed
653
654
655
      case 'Y':
        oai_emulation.info.g_log_verbosity_option = strdup(optarg);
        break;
winckel's avatar
winckel committed
656

gauthier's avatar
gauthier committed
657
658
659
      case 'z':
        cooperation_flag = atoi (optarg);
        break;
winckel's avatar
winckel committed
660

gauthier's avatar
gauthier committed
661
662
663
      case 'Z':
        /* Sebastien ROUX: Reserved for future use (currently used in ltenow branch) */
        break;
winckel's avatar
winckel committed
664

gauthier's avatar
gauthier committed
665
666
667
668
669
      default:
        help ();
        exit (-1);
        break;
      }
winckel's avatar
winckel committed
670
  }
671
672

  if ((oai_emulation.info.nb_enb_local > 0) && (conf_config_file_name != NULL))
gauthier's avatar
gauthier committed
673
    {
674
675
676
677
      /* Read eNB configuration file */
      enb_properties = enb_config_init(conf_config_file_name);

      AssertFatal (oai_emulation.info.nb_enb_local <= enb_properties->number,
gauthier's avatar
gauthier committed
678
679
          "Number of eNB is greater than eNB defined in configuration file %s (%d/%d)!",
          conf_config_file_name, oai_emulation.info.nb_enb_local, enb_properties->number);
680
681

      /* Update some simulation parameters */
knopp's avatar
   
knopp committed
682
683
684
685
      oai_emulation.info.frame_type[0] =           enb_properties->properties[0]->frame_type[0];
      oai_emulation.info.tdd_config[0] =           enb_properties->properties[0]->tdd_config[0];
      oai_emulation.info.tdd_config_S[0] =         enb_properties->properties[0]->tdd_config_s[0];
      oai_emulation.info.extended_prefix_flag[0] = enb_properties->properties[0]->prefix_type[0];
gauthier's avatar
gauthier committed
686
    }
687
688
689

    free(conf_config_file_name);
    conf_config_file_name = 0;
690
691
}

gauthier's avatar
gauthier committed
692
void check_and_adjust_params(void) {
693

gauthier's avatar
gauthier committed
694
  int32_t ret;
695
696
  int i,j;

697
  if (oai_emulation.info.nb_ue_local  + oai_emulation.info.nb_rn_local > NUMBER_OF_UE_MAX) {
gauthier's avatar
gauthier committed
698
699
      LOG_E(EMU,"Enter fewer than %d UEs/RNs for the moment or change the NUMBER_OF_UE_MAX\n", NUMBER_OF_UE_MAX);
      exit(EXIT_FAILURE);
700
701
  }

702
  if (oai_emulation.info.nb_enb_local + oai_emulation.info.nb_rn_local > NUMBER_OF_eNB_MAX) {
gauthier's avatar
gauthier committed
703
704
      LOG_E(EMU,"Enter fewer than %d eNBs/RNs for the moment or change the NUMBER_OF_UE_MAX\n", NUMBER_OF_eNB_MAX);
      exit(EXIT_FAILURE);
705
  }
706

707
  if (oai_emulation.info.nb_rn_local > NUMBER_OF_RN_MAX) {
gauthier's avatar
gauthier committed
708
709
      LOG_E(EMU,"Enter fewer than %d RNs for the moment or change the NUMBER_OF_RN_MAX\n", NUMBER_OF_RN_MAX);
      exit(EXIT_FAILURE);
710
  }
711
712
713
714
715
716
717
718
719
720
721
  // fix ethernet and abstraction with RRC_CELLULAR Flag
#ifdef RRC_CELLULAR
  abstraction_flag = 1;
  ethernet_flag = 1;
#endif

  if (set_sinr == 0)
    sinr_dB = snr_dB - 20;

  // setup netdevice interface (netlink socket)
  LOG_I(EMU,"[INIT] Starting NAS netlink interface\n");
Cedric Roux's avatar
Cedric Roux committed
722
  ret = netlink_init();
723
  if (ret < 0)
724
    LOG_W(EMU,"[INIT] Netlink not available, careful ...\n");
725
726

  if (ethernet_flag == 1) {
gauthier's avatar
gauthier committed
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
      oai_emulation.info.master[oai_emulation.info.master_id].nb_ue = oai_emulation.info.nb_ue_local + oai_emulation.info.nb_rn_local;
      oai_emulation.info.master[oai_emulation.info.master_id].nb_enb = oai_emulation.info.nb_enb_local + oai_emulation.info.nb_rn_local;
      if (oai_emulation.info.nb_rn_local>0)
        LOG_N(EMU,"Ethernet emulation is not yet tested with the relay nodes\n");
      if (!oai_emulation.info.master_id)
        oai_emulation.info.is_primary_master = 1;
      j = 1;
      for (i = 0; i < oai_emulation.info.nb_master; i++) {
          if (i != oai_emulation.info.master_id)
            oai_emulation.info.master_list = oai_emulation.info.master_list + j;
          LOG_I (EMU, "Index of master id i=%d  MASTER_LIST %d\n", i, oai_emulation.info.master_list);
          j *= 2;
      }
      LOG_I (EMU, " Total number of master %d my master id %d\n", oai_emulation.info.nb_master, oai_emulation.info.master_id);
      init_bypass ();
742

gauthier's avatar
gauthier committed
743
744
745
746
      while (emu_tx_status != SYNCED_TRANSPORT) {
          LOG_I (EMU, " Waiting for EMU Transport to be synced\n");
          emu_transport_sync ();    //emulation_tx_rx();
      }
747
748
  } // ethernet flag

749
  //
750
751
  NB_UE_INST = oai_emulation.info.nb_ue_local + oai_emulation.info.nb_ue_remote;
  NB_eNB_INST = oai_emulation.info.nb_enb_local + oai_emulation.info.nb_enb_remote;
752
753
  NB_RN_INST = oai_emulation.info.nb_rn_local + oai_emulation.info.nb_rn_remote;

754
#if defined(ENABLE_PDCP_NETLINK_FIFO) && defined(OPENAIR2)
755
756
757
  pdcp_netlink_init();
#endif

758
  if (NB_RN_INST > 0 ) {
gauthier's avatar
gauthier committed
759
      LOG_N(EMU,"Total number of RN %d (local %d, remote %d) mobility (the same as eNB) %s  \n", NB_RN_INST,oai_emulation.info.nb_rn_local,oai_emulation.info.nb_rn_remote, oai_emulation.topology_config.mobility.eNB_mobility.eNB_mobility_type.selected_option);
760

gauthier's avatar
gauthier committed
761
762
763
764
765
      LOG_N(EMU,"Adjust the number of eNB inst (%d->%d) and UE inst (%d->%d)\n ",
          NB_eNB_INST, NB_eNB_INST+NB_RN_INST,
          NB_UE_INST, NB_UE_INST+NB_RN_INST);
      NB_eNB_INST+=NB_RN_INST;
      NB_UE_INST+=NB_RN_INST;
766
  }
767
  LOG_I(EMU,"Total number of UE %d (first local %d , num local %d, remote %d, relay %d) mobility %s \n",
gauthier's avatar
gauthier committed
768
769
770
      NB_UE_INST,oai_emulation.info.first_ue_local, oai_emulation.info.nb_ue_local,oai_emulation.info.nb_ue_remote,
      NB_RN_INST,
      oai_emulation.topology_config.mobility.UE_mobility.UE_mobility_type.selected_option);
771
772

  LOG_I(EMU,"Total number of eNB %d (local %d, remote %d, relay %d) mobility %s \n",
gauthier's avatar
gauthier committed
773
774
775
      NB_eNB_INST,oai_emulation.info.nb_enb_local,oai_emulation.info.nb_enb_remote,
      NB_RN_INST,
      oai_emulation.topology_config.mobility.eNB_mobility.eNB_mobility_type.selected_option);
776

777
778
}

779
#ifdef OPENAIR2
gauthier's avatar
gauthier committed
780
void init_omv(void) {
781
782
  if (oai_emulation.info.omv_enabled == 1) {

gauthier's avatar
gauthier committed
783
784
      if(pipe(pfd) == -1)
        perror("pipe error \n");
785

786
      snprintf( full_name, sizeof(full_name), "%s/UTIL/OMV/OMV",getenv("OPENAIR2_DIR") );
gauthier's avatar
gauthier committed
787
      LOG_I(EMU,"Stating the OMV path %s pfd[0] %d pfd[1] %d \n", full_name, pfd[0],pfd[1]);
788

gauthier's avatar
gauthier committed
789
790
791
792
      switch(fork()) {
      case -1 :
        perror("fork failed \n");
        break;
793
      case 0 : // child is going to be the omv, it is the reader
gauthier's avatar
gauthier committed
794
795
796
797
798
799
800
801
802
803
        if(close(pfd[1]) == -1 ) // we close the write desc.
          perror("close on write\n" );
        sprintf(fdstr, "%d", pfd[0] );
        sprintf(num_enb, "%d", NB_eNB_INST);
        sprintf(num_ue, "%d", NB_UE_INST);
        sprintf(x_area, "%f", oai_emulation.topology_config.area.x_m );
        sprintf(y_area, "%f", oai_emulation.topology_config.area.y_m );
        sprintf(z_area, "%f", 200.0 );
        sprintf(frames, "%d", oai_emulation.info.n_frames);
        sprintf(nb_antenna, "%d", 4);
knopp's avatar
   
knopp committed
804
805
        sprintf(frame_type, "%s", (oai_emulation.info.frame_type[0] == 0) ? "FDD" : "TDD");
        sprintf(tdd_config, "%d", oai_emulation.info.tdd_config[0]);
gauthier's avatar
gauthier committed
806
807
808
809
810
811
812
        // execl is used to launch the visualisor
        execl(full_name,"OMV", fdstr, frames, num_enb, num_ue, x_area, y_area, z_area, nb_antenna, frame_type, tdd_config,NULL );
        perror( "error in execl the OMV" );
      }
      //parent
      if(close( pfd[0] ) == -1 ) // we close the write desc.
        perror("close on read\n" );
813
814
  }
}
815
#endif
816

gauthier's avatar
gauthier committed
817
void init_seed(uint8_t set_seed) {
818
819
820

  if(set_seed) {

gauthier's avatar
gauthier committed
821
822
      randominit (oai_emulation.info.seed);
      set_taus_seed (oai_emulation.info.seed);
823
824

  } else {
gauthier's avatar
gauthier committed
825
826
      randominit (0);
      set_taus_seed (0);
827
828
829
  }
}

gauthier's avatar
gauthier committed
830
void init_openair1(void) {
gauthier's avatar
gauthier committed
831
  module_id_t UE_id, eNB_id;
knopp's avatar
   
knopp committed
832
  uint8_t CC_id;
833
834
835
#if defined(ENABLE_RAL)
  int list_index;
#endif
836
  // change the nb_connected_eNB
knopp's avatar
   
knopp committed
837
  for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
838
    init_lte_vars (&frame_parms[CC_id], oai_emulation.info.frame_type[CC_id], oai_emulation.info.tdd_config[CC_id], oai_emulation.info.tdd_config_S[CC_id],oai_emulation.info.extended_prefix_flag[CC_id],oai_emulation.info.N_RB_DL[CC_id], Nid_cell, cooperation_flag, oai_emulation.info.transmission_mode[CC_id], abstraction_flag,nb_antennas_rx, oai_emulation.info.eMBMS_active_state);
knopp's avatar
   
knopp committed
839
  }
840
841
842

  for (eNB_id=0; eNB_id<NB_eNB_INST;eNB_id++){
      for (UE_id=0; UE_id<NB_UE_INST;UE_id++){
knopp's avatar
   
knopp committed
843
844
845
846
	for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
          PHY_vars_eNB_g[eNB_id][CC_id]->pusch_config_dedicated[UE_id].betaOffset_ACK_Index = beta_ACK;
          PHY_vars_eNB_g[eNB_id][CC_id]->pusch_config_dedicated[UE_id].betaOffset_RI_Index  = beta_RI;
          PHY_vars_eNB_g[eNB_id][CC_id]->pusch_config_dedicated[UE_id].betaOffset_CQI_Index = beta_CQI;
847
          PHY_vars_eNB_g[eNB_id][CC_id]->lte_frame_parms.pdsch_config_common.p_b = (frame_parms[CC_id]->nb_antennas_tx_eNB>1) ? 1 : 0; // rho_A = rho_B
848
849
850
851
	
	  PHY_vars_UE_g[UE_id][CC_id]->pusch_config_dedicated[eNB_id].betaOffset_ACK_Index = beta_ACK;
	  PHY_vars_UE_g[UE_id][CC_id]->pusch_config_dedicated[eNB_id].betaOffset_RI_Index  = beta_RI;
	  PHY_vars_UE_g[UE_id][CC_id]->pusch_config_dedicated[eNB_id].betaOffset_CQI_Index = beta_CQI;
852
          PHY_vars_UE_g[UE_id][CC_id]->lte_frame_parms.pdsch_config_common.p_b = (frame_parms[CC_id]->nb_antennas_tx_eNB>1) ? 1 : 0; // rho_A = rho_B
knopp's avatar
   
knopp committed
853
	}
854
855
856
      }
  }

857
858
859
   printf ("AFTER init: MAX_NUM_CCs %d, Nid_cell %d frame_type %d,tdd_config %d\n",
	  MAX_NUM_CCs,
	  PHY_vars_eNB_g[0][0]->lte_frame_parms.Nid_cell,
860
861
      PHY_vars_eNB_g[0][0]->lte_frame_parms.frame_type,
      PHY_vars_eNB_g[0][0]->lte_frame_parms.tdd_config);
862
863
864
865
866
867
868

  number_of_cards = 1;

  openair_daq_vars.rx_rf_mode = 1;
  openair_daq_vars.tdd = 1;
  openair_daq_vars.rx_gain_mode = DAQ_AGC_ON;

knopp's avatar
   
knopp committed
869
  openair_daq_vars.dlsch_transmission_mode = oai_emulation.info.transmission_mode[0];
870
871
#warning "NN->FK: OAI EMU channel abstraction does not work for MCS higher than"
  openair_daq_vars.target_ue_dl_mcs = cmin(target_dl_mcs,16);
872
873
874
875
876
877
  openair_daq_vars.target_ue_ul_mcs = target_ul_mcs;
  openair_daq_vars.ue_dl_rb_alloc=0x1fff;
  openair_daq_vars.ue_ul_nb_rb=6;
  openair_daq_vars.dlsch_rate_adaptation = rate_adaptation_flag;
  openair_daq_vars.use_ia_receiver = 0;

878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
  //N_TA_offset
  for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
    for (UE_id=0; UE_id<NB_UE_INST;UE_id++){
      if (PHY_vars_UE_g[UE_id][CC_id]->lte_frame_parms.frame_type == TDD) {
	if (PHY_vars_UE_g[UE_id][CC_id]->lte_frame_parms.N_RB_DL == 100)
	  PHY_vars_UE_g[UE_id][CC_id]->N_TA_offset = 624;
	else if (PHY_vars_UE_g[UE_id][CC_id]->lte_frame_parms.N_RB_DL == 50)
	  PHY_vars_UE_g[UE_id][CC_id]->N_TA_offset = 624/2;
	else if (PHY_vars_UE_g[UE_id][CC_id]->lte_frame_parms.N_RB_DL == 25)
	  PHY_vars_UE_g[UE_id][CC_id]->N_TA_offset = 624/4;
      }
      else {
	PHY_vars_UE_g[UE_id][CC_id]->N_TA_offset = 0;
      }
    }
    for (eNB_id=0; eNB_id<NB_eNB_INST;eNB_id++){
      if (PHY_vars_eNB_g[eNB_id][CC_id]->lte_frame_parms.frame_type == TDD) {
	if (PHY_vars_eNB_g[eNB_id][CC_id]->lte_frame_parms.N_RB_DL == 100)
	  PHY_vars_eNB_g[eNB_id][CC_id]->N_TA_offset = 624;
	else if (PHY_vars_eNB_g[eNB_id][CC_id]->lte_frame_parms.N_RB_DL == 50)
	  PHY_vars_eNB_g[eNB_id][CC_id]->N_TA_offset = 624/2;
	else if (PHY_vars_eNB_g[eNB_id][CC_id]->lte_frame_parms.N_RB_DL == 25)
	  PHY_vars_eNB_g[eNB_id][CC_id]->N_TA_offset = 624/4;
      }
      else {
	PHY_vars_eNB_g[eNB_id][CC_id]->N_TA_offset = 0;
      }
    }
  } 

908
  // init_ue_status();
knopp's avatar
   
knopp committed
909
910
  for (UE_id=0; UE_id<NB_UE_INST;UE_id++) 
    for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++){
911
912
913

      PHY_vars_UE_g[UE_id][CC_id]->tx_power_max_dBm=23;

knopp's avatar
   
knopp committed
914
      PHY_vars_UE_g[UE_id][CC_id]->rx_total_gain_dB=160;
gauthier's avatar
gauthier committed
915
916
      // update UE_mode for each eNB_id not just 0
      if (abstraction_flag == 0)
knopp's avatar
   
knopp committed
917
        PHY_vars_UE_g[UE_id][CC_id]->UE_mode[0] = NOT_SYNCHED;
gauthier's avatar
gauthier committed
918
919
      else {
          // 0 is the index of the connected eNB
knopp's avatar
   
knopp committed
920
          PHY_vars_UE_g[UE_id][CC_id]->UE_mode[0] = PRACH;
gauthier's avatar
gauthier committed
921
      }
knopp's avatar
   
knopp committed
922
923
      PHY_vars_UE_g[UE_id][CC_id]->lte_ue_pdcch_vars[0]->crnti = 0x1235 + UE_id;
      PHY_vars_UE_g[UE_id][CC_id]->current_dlsch_cqi[0] = 10;
924

knopp's avatar
   
knopp committed
925
      LOG_I(EMU, "UE %d mode is initialized to %d\n", UE_id, PHY_vars_UE_g[UE_id][CC_id]->UE_mode[0] );
926
#if defined(ENABLE_RAL)
knopp's avatar
   
knopp committed
927
      PHY_vars_UE_g[UE_id][CC_id]->ral_thresholds_timed = hashtable_create (64, NULL, NULL);
gauthier's avatar
gauthier committed
928
      for (list_index = 0; list_index < RAL_LINK_PARAM_GEN_MAX; list_index++) {
knopp's avatar
   
knopp committed
929
          SLIST_INIT(&PHY_vars_UE_g[UE_id][CC_id]->ral_thresholds_gen_polled[list_index]);
gauthier's avatar
gauthier committed
930
931
      }
      for (list_index = 0; list_index < RAL_LINK_PARAM_LTE_MAX; list_index++) {
knopp's avatar
   
knopp committed
932
          SLIST_INIT(&PHY_vars_UE_g[UE_id][CC_id]->ral_thresholds_lte_polled[list_index]);
gauthier's avatar
gauthier committed
933
      }
934
935
#endif

936
937
938
  }
}

gauthier's avatar
gauthier committed
939
void init_openair2(void) {
940
#ifdef OPENAIR2
gauthier's avatar
gauthier committed
941
942
  module_id_t enb_id;
  module_id_t UE_id;
knopp's avatar
   
knopp committed
943
  int CC_id;
944
#warning "eNB index is hard coded to zero"
knopp's avatar
   
knopp committed
945
946
947
  for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++)
    l2_init (&PHY_vars_eNB_g[0][CC_id]->lte_frame_parms,
	     oai_emulation.info.eMBMS_active_state,
knopp's avatar
   
knopp committed
948
	     NULL,
knopp's avatar
   
knopp committed
949
950
951
	     oai_emulation.info.cba_group_active,
	     oai_emulation.info.handover_active);
  
gauthier's avatar
gauthier committed
952
953
  for (enb_id = 0; enb_id < NB_eNB_INST; enb_id++)
    mac_xface->mrbch_phy_sync_failure (enb_id, 0, enb_id);
954
955

  if (abstraction_flag == 1) {
gauthier's avatar
gauthier committed
956
957
      for (UE_id = 0; UE_id < NB_UE_INST; UE_id++)
        mac_xface->dl_phy_sync_success (UE_id, 0, 0,1);   //UE_id%NB_eNB_INST);
958
959
960
  }

  mac_xface->macphy_exit = exit_fun;
961

962
963
964
#endif
}

gauthier's avatar
gauthier committed
965
void init_ocm(void) {
gauthier's avatar
gauthier committed
966
  module_id_t UE_id, eNB_id;
knopp's avatar
   
knopp committed
967
  int CC_id;
gauthier's avatar
gauthier committed
968

969
  /* Added for PHY abstraction */
gauthier's avatar
gauthier committed
970
971
972
973
974
975
976
977
978
979
980
981

  char* frame_type = "unknown";
  switch (oai_emulation.info.frame_type[0]) {
  case FDD:
    frame_type = "FDD";
    break;
  case TDD:
    frame_type = "FDD";
    break;
  }
  LOG_I(OCM,"Running with frame_type %d (%s), Nid_cell %d, N_RB_DL %d, EP %d, mode %d, target dl_mcs %d, rate adaptation %d, nframes %d, abstraction %d, channel %s\n",
        oai_emulation.info.frame_type[0], frame_type, Nid_cell, oai_emulation.info.N_RB_DL[0], oai_emulation.info.extended_prefix_flag[0], oai_emulation.info.transmission_mode[0],target_dl_mcs,rate_adaptation_flag,oai_emulation.info.n_frames,abstraction_flag,oai_emulation.environment_system_config.fading.small_scale.selected_option);
982

gauthier's avatar
gauthier committed
983
  if (abstraction_flag) {
984

gauthier's avatar
gauthier committed
985
      get_beta_map();
986
#ifdef PHY_ABSTRACTION_UL
gauthier's avatar
gauthier committed
987
      get_beta_map_up();
988
#endif
gauthier's avatar
gauthier committed
989
      get_MIESM_param();
990
991

      //load_pbch_desc();
992
  }
993
  
994
995

  for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) {
gauthier's avatar
gauthier committed
996
997
      enb_data[eNB_id] = (node_desc_t *)malloc(sizeof(node_desc_t));
      init_enb(enb_data[eNB_id],oai_emulation.environment_system_config.antenna.eNB_antenna);
998
999
1000
  }

  for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
gauthier's avatar
gauthier committed
1001
1002
      ue_data[UE_id] = (node_desc_t *)malloc(sizeof(node_desc_t));
      init_ue(ue_data[UE_id],oai_emulation.environment_system_config.antenna.UE_antenna);
1003
1004
1005
1006
1007
1008
  }

  if ((oai_emulation.info.ocm_enabled == 1)&& (ethernet_flag == 0 ) &&
      (oai_emulation.environment_system_config.fading.shadowing.decorrelation_distance_m>0) &&
      (oai_emulation.environment_system_config.fading.shadowing.variance_dB>0)) {

gauthier's avatar
gauthier committed
1009
1010
1011
1012
      // init SF map here!!!
      map1 =(int)oai_emulation.topology_config.area.x_m;
      map2 =(int)oai_emulation.topology_config.area.y_m;
      ShaF = init_SF(map1,map2,oai_emulation.environment_system_config.fading.shadowing.decorrelation_distance_m,oai_emulation.environment_system_config.fading.shadowing.variance_dB);
1013

gauthier's avatar
gauthier committed
1014
1015
      // size of area to generate shadow fading map
      LOG_D(EMU,"Simulation area x=%f, y=%f\n",
1016
1017
1018
1019
1020
          oai_emulation.topology_config.area.x_m,
          oai_emulation.topology_config.area.y_m);
  }

  if (abstraction_flag == 0)
knopp's avatar
   
knopp committed
1021
    init_channel_vars (frame_parms[0], &s_re, &s_im, &r_re, &r_im, &r_re0, &r_im0);
1022
1023
1024

  // initialize channel descriptors
  for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) {
knopp's avatar
   
knopp committed
1025
1026
1027
    for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
      for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
	LOG_D(OCM,"Initializing channel (%s, %d) from eNB %d to UE %d\n", oai_emulation.environment_system_config.fading.small_scale.selected_option,
gauthier's avatar
gauthier committed
1028
              map_str_to_int(small_scale_names,oai_emulation.environment_system_config.fading.small_scale.selected_option), eNB_id, UE_id);
1029

gauthier's avatar
gauthier committed
1030
          /* if (oai_emulation.info.transmission_mode == 5)
1031
1032
1033
1034
1035
1036
1037
1038
1039
                    eNB2UE[eNB_id][UE_id] = new_channel_desc_scm(PHY_vars_eNB_g[eNB_id]->lte_frame_parms.nb_antennas_tx,
                                                       PHY_vars_UE_g[UE_id]->lte_frame_parms.nb_antennas_rx,
                                                       (UE_id == 0)? Rice1_corr : Rice1_anticorr,
                                                       oai_emulation.environment_system_config.system_bandwidth_MB,
                                                       forgetting_factor,
                                                       0,
                                                       0);

                else
gauthier's avatar
gauthier committed
1040
1041
           */

knopp's avatar
   
knopp committed
1042
1043
1044
1045
1046
1047
1048
1049
1050
	eNB2UE[eNB_id][UE_id][CC_id] = new_channel_desc_scm(PHY_vars_eNB_g[eNB_id][CC_id]->lte_frame_parms.nb_antennas_tx,
							    PHY_vars_UE_g[UE_id][CC_id]->lte_frame_parms.nb_antennas_rx,
							    map_str_to_int(small_scale_names,oai_emulation.environment_system_config.fading.small_scale.selected_option),
							    oai_emulation.environment_system_config.system_bandwidth_MB,
							    forgetting_factor,
							    0,
							    0);
	random_channel(eNB2UE[eNB_id][UE_id][CC_id],abstraction_flag);
	LOG_D(OCM,"[SIM] Initializing channel (%s, %d) from UE %d to eNB %d\n", oai_emulation.environment_system_config.fading.small_scale.selected_option,
gauthier's avatar
gauthier committed
1051
              map_str_to_int(small_scale_names, oai_emulation.environment_system_config.fading.small_scale.selected_option),UE_id, eNB_id);
knopp's avatar
   
knopp committed
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
	
	UE2eNB[UE_id][eNB_id][CC_id] = new_channel_desc_scm(PHY_vars_UE_g[UE_id][CC_id]->lte_frame_parms.nb_antennas_tx,
							    PHY_vars_eNB_g[eNB_id][CC_id]->lte_frame_parms.nb_antennas_rx,
							    map_str_to_int(small_scale_names, oai_emulation.environment_system_config.fading.small_scale.selected_option),
							    oai_emulation.environment_system_config.system_bandwidth_MB,
							    forgetting_factor,
							    0,
							    0);
	
	random_channel(UE2eNB[UE_id][eNB_id][CC_id],abstraction_flag);
1062

1063
1064
      // to make channel reciprocal uncomment following line instead of previous. However this only works for SISO at the moment. For MIMO the channel would need to be transposed.
      //UE2eNB[UE_id][eNB_id] = eNB2UE[eNB_id][UE_id];
knopp's avatar
   
knopp committed
1065