Commit 230acb9e authored by Raymond Knopp's avatar Raymond Knopp

fixes to ulsim/dlsim and system simulator after merge

parent 494348e2
......@@ -38,7 +38,7 @@
#include "UTIL/LOG/vcd_signal_dumper.h"
#include "prach_extern.h"
#define PRACH_DEBUG 1
//#define PRACH_DEBUG 1
//#define PRACH_WRITE_OUTPUT_DEBUG 1
......
......@@ -41,7 +41,7 @@
#include "../LTE_TRANSPORT/prach_extern.h"
#define PRACH_DEBUG 1
//#define PRACH_DEBUG 1
int32_t generate_prach( PHY_VARS_UE *ue, uint8_t eNB_id, uint8_t subframe, uint16_t Nf )
{
......
......@@ -100,9 +100,9 @@ void generate_pucch1x(int32_t **txdataF,
printf("[PHY] PUCCH: cNcs1/deltaPUCCH_Shift %d, Nprime %d, n1_pucch %d\n",thres,Nprime,n1_pucch);
#endif
LOG_I(PHY,"[PHY] PUCCH: n1_pucch %d, thres %d Ncs1_div_deltaPUCCH_Shift %d (12/deltaPUCCH_Shift) %d Nprime_div_deltaPUCCH_Shift %d \n",
LOG_D(PHY,"[PHY] PUCCH: n1_pucch %d, thres %d Ncs1_div_deltaPUCCH_Shift %d (12/deltaPUCCH_Shift) %d Nprime_div_deltaPUCCH_Shift %d \n",
n1_pucch, thres, Ncs1_div_deltaPUCCH_Shift, (int)(12/deltaPUCCH_Shift), Nprime_div_deltaPUCCH_Shift);
LOG_I(PHY,"[PHY] PUCCH: deltaPUCCH_Shift %d, Nprime %d\n",deltaPUCCH_Shift,Nprime);
LOG_D(PHY,"[PHY] PUCCH: deltaPUCCH_Shift %d, Nprime %d\n",deltaPUCCH_Shift,Nprime);
N_UL_symb = (frame_parms->Ncp==0) ? 7 : 6;
......
......@@ -1270,7 +1270,7 @@ void pusch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
for (i=0; i<NUMBER_OF_UE_MAX; i++) {
ulsch = eNB->ulsch[i];
ulsch_harq = ulsch->harq_processes[harq_pid];
if (ulsch->rnti>0) LOG_I(PHY,"eNB->ulsch[%d]->harq_processes[harq_pid:%d] SFN/SF:%04d%d: PUSCH procedures, UE %d/%x ulsch_harq[status:%d SFN/SF:%04d%d handled:%d]\n",
if (ulsch->rnti>0) LOG_D(PHY,"eNB->ulsch[%d]->harq_processes[harq_pid:%d] SFN/SF:%04d%d: PUSCH procedures, UE %d/%x ulsch_harq[status:%d SFN/SF:%04d%d handled:%d]\n",
i, harq_pid, frame,subframe,i,ulsch->rnti,
ulsch_harq->status, ulsch_harq->frame, ulsch_harq->subframe, ulsch_harq->handled);
......@@ -1297,7 +1297,7 @@ void pusch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
fp->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift +
nPRS)%12;
AssertFatal(ulsch_harq->TBS>0,"illegal TBS %d\n",ulsch_harq->TBS);
LOG_I(PHY,
LOG_D(PHY,
"[eNB %d][PUSCH %d] Frame %d Subframe %d Demodulating PUSCH: dci_alloc %d, rar_alloc %d, round %d, first_rb %d, nb_rb %d, Qm %d, TBS %d, rv %d, cyclic_shift %d (n_DMRS2 %d, cyclicShift_common %d, ), O_ACK %d, beta_cqi %d \n",
eNB->Mod_id,harq_pid,frame,subframe,
ulsch_harq->dci_alloc,
......
......@@ -2167,7 +2167,7 @@ void ue_pucch_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uin
&len);
LOG_I(PHY,"PUCCH feedback AbsSubframe %d.%d SR %d NbCW %d (%d %d) AckNack %d.%d CQI %d RI %d format %d pucch_resource %d pucch_payload %d %d \n",
LOG_D(PHY,"PUCCH feedback AbsSubframe %d.%d SR %d NbCW %d (%d %d) AckNack %d.%d CQI %d RI %d format %d pucch_resource %d pucch_payload %d %d \n",
frame_tx%1024, subframe_tx, SR_payload, nb_cw, ack_status_cw0, ack_status_cw1, pucch_ack_payload[0], pucch_ack_payload[1], cqi_status, ri_status, format, pucch_resource,pucch_payload[0],pucch_payload[1]);
// Part - IV
......@@ -2229,7 +2229,7 @@ void ue_pucch_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uin
Po_PUCCH,
tx_amp);
} else {
LOG_I(PHY,"[UE %d][PDSCH %x] AbsSubFrame %d.%d rx_offset_diff: %d, Generating PUCCH %s, an_srs_simultanous %d, shorten_pucch %d, n1_pucch %d, b[0]=%d,b[1]=%d (SR_Payload %d), Po_PUCCH %d, amp %d\n",
LOG_D(PHY,"[UE %d][PDSCH %x] AbsSubFrame %d.%d rx_offset_diff: %d, Generating PUCCH %s, an_srs_simultanous %d, shorten_pucch %d, n1_pucch %d, b[0]=%d,b[1]=%d (SR_Payload %d), Po_PUCCH %d, amp %d\n",
Mod_id,
ue->dlsch[ue->current_thread_id[proc->subframe_rx]][eNB_id][0]->rnti,
frame_tx%1024, subframe_tx,ue->rx_offset_diff,
......
......@@ -39,7 +39,7 @@ eNBs =
downlink_frequency = 2685000000L;
uplink_frequency_offset = -120000000;
Nid_cell = 0;
N_RB_DL = 100;
N_RB_DL = 50;
Nid_cell_mbsfn = 0;
nb_antenna_ports = 1;
nb_antennas_tx = 1;
......
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include <string.h>
#include <math.h>
#include <unistd.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include "SIMULATION/TOOLS/sim.h"
#include "SIMULATION/RF/rf.h"
#include "PHY/types.h"
#include "PHY/defs_eNB.h"
#include "PHY/phy_extern.h"
#include "PHY/phy_extern_ue.h"
#include "LAYER2/MAC/mac.h"
#include "LAYER2/MAC/mac_extern.h"
#include "UTIL/LOG/log_if.h"
#include "UTIL/LOG/log_extern.h"
#include "RRC/LTE/rrc_extern.h"
#include "PHY_INTERFACE/phy_interface_extern.h"
#include "UTIL/OCG/OCG.h"
#include "UTIL/OPT/opt.h" // to test OPT
#include "UTIL/FIFO/types.h"
#ifdef XFORMS
#include "forms.h"
#include "phy_procedures_sim_form.h"
#endif
#include "oaisim.h"
#define RF
#define DEBUG_SIM
/*
#undef LOG_D
#define LOG_D(A,B,C...) printf(B,C)
*/
int number_rb_ul;
int first_rbUL ;
extern Signal_buffers_t *signal_buffers_g;
double r_re_DL[NUMBER_OF_UE_MAX][2][30720];
double r_im_DL[NUMBER_OF_UE_MAX][2][30720];
double r_re_UL[NUMBER_OF_eNB_MAX][2][30720];
double r_im_UL[NUMBER_OF_eNB_MAX][2][30720];
int RU_output_mask[NUMBER_OF_UE_MAX];
int UE_output_mask[NUMBER_OF_RU_MAX];
pthread_mutex_t RU_output_mutex[NUMBER_OF_UE_MAX];
pthread_mutex_t UE_output_mutex[NUMBER_OF_RU_MAX];
double ru_amp[NUMBER_OF_RU_MAX];
void do_DL_sig(channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM_CCs],
node_desc_t *enb_data[NUMBER_OF_RU_MAX],
node_desc_t *ue_data[NUMBER_OF_UE_MAX],
uint16_t subframe,
uint32_t offset,
uint32_t length,
uint8_t abstraction_flag,LTE_DL_FRAME_PARMS *ue_frame_parms,
uint8_t UE_id,
int CC_id)
{
int32_t att_eNB_id=-1;
int32_t **txdata,**rxdata;
uint32_t eNB_id,ru_id=0;
double tx_pwr;
double rx_pwr;
int32_t rx_pwr2;
uint32_t i,aa;
uint32_t sf_offset;
double min_path_loss=-200;
uint8_t hold_channel=0;
uint8_t nb_antennas_rx = RU2UE[0][0][CC_id]->nb_rx; // number of rx antennas at UE
uint8_t nb_antennas_tx = RU2UE[0][0][CC_id]->nb_tx; // number of tx antennas at eNB
double s_re0[30720];
double s_re1[30720];
double *s_re[2];
double s_im0[30720];
double s_im1[30720];
double *s_im[2];
double r_re00[30720];
double r_re01[30720];
double *r_re0[2];
double r_im00[30720];
double r_im01[30720];
double *r_im0[2];
LTE_DL_FRAME_PARMS *frame_parms;
s_re[0] = s_re0;
s_im[0] = s_im0;
s_re[1] = s_re1;
s_im[1] = s_im1;
r_re0[0] = r_re00;
r_im0[0] = r_im00;
r_re0[1] = r_re01;
r_im0[1] = r_im01;
if (subframe==0)
hold_channel = 0;
else
hold_channel = 1;
if (abstraction_flag != 0) {
//for (UE_id=0;UE_id<NB_UE_INST;UE_id++) {
if (!hold_channel) {
// calculate the random channel from each RU
for (ru_id=0; ru_id<RC.nb_RU; ru_id++) {
frame_parms = &RC.ru[ru_id]->frame_parms;
random_channel(RU2UE[ru_id][UE_id][CC_id],abstraction_flag);
/*
for (i=0;i<RU2UE[eNB_id][UE_id]->nb_taps;i++)
printf("RU2UE[%d][%d]->a[0][%d] = (%f,%f)\n",eNB_id,UE_id,i,RU2UE[eNB_id][UE_id]->a[0][i].x,RU2UE[eNB_id][UE_id]->a[0][i].y);
*/
freq_channel(RU2UE[ru_id][UE_id][CC_id], frame_parms->N_RB_DL,frame_parms->N_RB_DL*12+1);
}
// find out which eNB the UE is attached to
/*
for (eNB_id=0; eNB_id<RC.nb_inst; eNB_id++) {
if (find_ue(PHY_vars_UE_g[UE_id][CC_id]->pdcch_vars[0][0]->crnti,RC.eNB[eNB_id][CC_id])>=0) {
// UE with UE_id is connected to eNb with eNB_id
att_eNB_id=eNB_id;
LOG_D(OCM,"A: UE attached to eNB (UE%d->eNB%d)\n",UE_id,eNB_id);
}
}
*/
// if UE is not attached yet, find assume its the eNB with the smallest pathloss
if (att_eNB_id<0) {
for (eNB_id=0; eNB_id<NB_eNB_INST; eNB_id++) {
for (int ru=0;ru<RC.nb_RU;ru++) {
ru_id = RC.eNB[eNB_id][CC_id]->RU_list[ru]->idx;
if (min_path_loss<RU2UE[ru_id][UE_id][CC_id]->path_loss_dB) {
min_path_loss = RU2UE[ru_id][UE_id][CC_id]->path_loss_dB;
att_eNB_id=eNB_id;
LOG_D(OCM,"B: UE attached to eNB (UE%d->eNB%d)\n",UE_id,eNB_id);
}
}
}
}
if (att_eNB_id<0) {
LOG_E(OCM,"Cannot find eNB for UE %d, return\n",UE_id);
return; //exit(-1);
}
#ifdef DEBUG_SIM
rx_pwr = signal_energy_fp2(RU2UE[att_eNB_id][UE_id][CC_id]->ch[0],
RU2UE[att_eNB_id][UE_id][CC_id]->channel_length)*RU2UE[att_eNB_id][UE_id][CC_id]->channel_length;
LOG_D(OCM,"Channel (CCid %d) eNB %d => UE %d : tx_power %d dBm, path_loss %f dB\n",
CC_id,att_eNB_id,UE_id,
frame_parms->pdsch_config_common.referenceSignalPower,
RU2UE[att_eNB_id][UE_id][CC_id]->path_loss_dB);
#endif
//dlsch_abstraction(PHY_vars_UE_g[UE_id]->sinr_dB, rb_alloc, 8);
// fill in perfect channel estimates
channel_desc_t *desc1 = RU2UE[att_eNB_id][UE_id][CC_id];
int32_t **dl_channel_est = PHY_vars_UE_g[UE_id][CC_id]->common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[0];
// double scale = pow(10.0,(enb_data[att_eNB_id]->tx_power_dBm + RU2UE[att_eNB_id][UE_id]->path_loss_dB + (double) PHY_vars_UE_g[UE_id]->rx_total_gain_dB)/20.0);
double scale = pow(10.0,(frame_parms->pdsch_config_common.referenceSignalPower+RU2UE[att_eNB_id][UE_id][CC_id]->path_loss_dB + (double) PHY_vars_UE_g[UE_id][CC_id]->rx_total_gain_dB)/20.0);
LOG_D(OCM,"scale =%lf (%d dB)\n",scale,(int) (20*log10(scale)));
// freq_channel(desc1,frame_parms->N_RB_DL,nb_samples);
//LOG_M("channel.m","ch",desc1->ch[0],desc1->channel_length,1,8);
//LOG_M("channelF.m","chF",desc1->chF[0],nb_samples,1,8);
int count,count1,a_rx,a_tx;
for(a_tx=0; a_tx<nb_antennas_tx; a_tx++) {
for (a_rx=0; a_rx<nb_antennas_rx; a_rx++) {
//for (count=0;count<frame_parms->symbols_per_tti/2;count++)
for (count=0; count<1; count++) {
for (count1=0; count1<frame_parms->N_RB_DL*12; count1++) {
((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count1+(count*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(int16_t)(desc1->chF[a_rx+(a_tx*nb_antennas_rx)][count1].x*scale);
((int16_t *) dl_channel_est[(a_tx<<1)+a_rx])[2*count1+1+(count*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(int16_t)(desc1->chF[a_rx+(a_tx*nb_antennas_rx)][count1].y*scale) ;
}
}
}
}
// calculate the SNR for the attached eNB (this assumes eNB always uses PMI stored in eNB_UE_stats; to be improved)
init_snr(RU2UE[att_eNB_id][UE_id][CC_id], enb_data[att_eNB_id], ue_data[UE_id], PHY_vars_UE_g[UE_id][CC_id]->sinr_dB, &PHY_vars_UE_g[UE_id][CC_id]->N0,
PHY_vars_UE_g[UE_id][CC_id]->transmission_mode[att_eNB_id], RC.eNB[att_eNB_id][CC_id]->UE_stats[UE_id].DL_pmi_single,
RC.eNB[att_eNB_id][CC_id]->mu_mimo_mode[UE_id].dl_pow_off,RC.eNB[att_eNB_id][CC_id]->frame_parms.N_RB_DL);
// calculate sinr here
for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) {
if (att_eNB_id != eNB_id) {
calculate_sinr(RU2UE[eNB_id][UE_id][CC_id], enb_data[eNB_id], ue_data[UE_id], PHY_vars_UE_g[UE_id][CC_id]->sinr_dB,
RC.eNB[att_eNB_id][CC_id]->frame_parms.N_RB_DL);
}
}
} // hold channel
}
else { //abstraction_flag
pthread_mutex_lock(&RU_output_mutex[UE_id]);
if (RU_output_mask[UE_id] == 0) { // This is the first eNodeB for this UE, clear the buffer
for (aa=0; aa<nb_antennas_rx; aa++) {
memset((void*)r_re_DL[UE_id][aa],0,(RC.ru[0]->frame_parms.samples_per_tti)*sizeof(double));
memset((void*)r_im_DL[UE_id][aa],0,(RC.ru[0]->frame_parms.samples_per_tti)*sizeof(double));
}
}
pthread_mutex_unlock(&RU_output_mutex[UE_id]);
for (ru_id=0; ru_id<RC.nb_RU; ru_id++) {
txdata = RC.ru[ru_id]->common.txdata;
frame_parms = &RC.ru[ru_id]->frame_parms;
sf_offset = (subframe*frame_parms->samples_per_tti) + offset;
LOG_D(EMU,">>>>>>>>>>>>>>>>>TXPATH: RU %d : DL_sig reading TX for subframe %d (sf_offset %d, length %d) from %p\n",ru_id,subframe,sf_offset,length,txdata[0]+sf_offset);
int length_meas = frame_parms->ofdm_symbol_size;
if (sf_offset+length <= frame_parms->samples_per_tti*10) {
tx_pwr = dac_fixed_gain(s_re,
s_im,
txdata,
sf_offset,
nb_antennas_tx,
length,
sf_offset,
length_meas,
14,
frame_parms->pdsch_config_common.referenceSignalPower, // dBm/RE
0,
&ru_amp[ru_id],
frame_parms->N_RB_DL*12);
}
else {
tx_pwr = dac_fixed_gain(s_re,
s_im,
txdata,
sf_offset,
nb_antennas_tx,
(frame_parms->samples_per_tti*10)-sf_offset,
sf_offset,
length_meas,
14,
frame_parms->pdsch_config_common.referenceSignalPower, // dBm/RE
0,
&ru_amp[ru_id],
frame_parms->N_RB_DL*12);
tx_pwr = dac_fixed_gain(s_re,
s_im,
txdata,
sf_offset,
nb_antennas_tx,
length+sf_offset-(frame_parms->samples_per_tti*10),
sf_offset,
length_meas,
14,
frame_parms->pdsch_config_common.referenceSignalPower, // dBm/RE
0,
&ru_amp[ru_id],
frame_parms->N_RB_DL*12);
}
#ifdef DEBUG_SIM
LOG_D(PHY,"[SIM][DL] subframe %d: txp (time) %d dB\n",
subframe,dB_fixed(signal_energy(&txdata[0][sf_offset],length_meas)));
LOG_D(OCM,"[SIM][DL] RU %d (CCid %d): tx_pwr %.1f dBm/RE (target %d dBm/RE), for subframe %d\n",
ru_id,CC_id,
10*log10(tx_pwr),
frame_parms->pdsch_config_common.referenceSignalPower,
subframe);
#endif
tx_pwr = signal_energy_fp(s_re,s_im,nb_antennas_tx,
length<length_meas?length:length_meas,
0)/(12.0*frame_parms->N_RB_DL);
//RU2UE[eNB_id][UE_id]->path_loss_dB = 0;
multipath_channel(RU2UE[ru_id][UE_id][CC_id],s_re,s_im,r_re0,r_im0,
length,hold_channel);
#ifdef DEBUG_SIM
rx_pwr = signal_energy_fp2(RU2UE[ru_id][UE_id][CC_id]->ch[0],
RU2UE[ru_id][UE_id][CC_id]->channel_length)*RU2UE[ru_id][UE_id][CC_id]->channel_length;
LOG_D(OCM,"[SIM][DL] Channel RU %d => UE %d (CCid %d): Channel gain %f dB (%f)\n",ru_id,UE_id,CC_id,10*log10(rx_pwr),rx_pwr);
#endif
#ifdef DEBUG_SIM
for (i=0; i<RU2UE[ru_id][UE_id][CC_id]->channel_length; i++)
LOG_D(OCM,"channel(%d,%d)[%d] : (%f,%f)\n",ru_id,UE_id,i,RU2UE[ru_id][UE_id][CC_id]->ch[0][i].x,RU2UE[ru_id][UE_id][CC_id]->ch[0][i].y);
#endif
LOG_D(OCM,"[SIM][DL] Channel RU %d => UE %d (CCid %d): tx_power %.1f dBm/RE, path_loss %1.f dB\n",
ru_id,UE_id,CC_id,
(double)frame_parms->pdsch_config_common.referenceSignalPower,
// enb_data[eNB_id]->tx_power_dBm,
RU2UE[ru_id][UE_id][CC_id]->path_loss_dB);
#ifdef DEBUG_SIM
rx_pwr = signal_energy_fp(r_re0,r_im0,nb_antennas_rx,
length<length_meas?length:length_meas,
0)/(12.0*frame_parms->N_RB_DL);
LOG_D(OCM,"[SIM][DL] UE %d : rx_pwr %f dBm/RE (%f dBm RSSI,tx %f dB)for subframe %d (length %d)\n",UE_id,
10*log10(rx_pwr),
10*log10(rx_pwr*(double)frame_parms->N_RB_DL*12),
10*log10(tx_pwr),subframe,
length<length_meas?length:length_meas);
LOG_D(OCM,"[SIM][DL] UE %d : rx_pwr (noise) -132 dBm/RE (N0fs = %.1f dBm, N0B = %.1f dBm) for subframe %d\n",
UE_id,
10*log10(RU2UE[ru_id][UE_id][CC_id]->sampling_rate*1e6)-174,
10*log10(RU2UE[ru_id][UE_id][CC_id]->sampling_rate*1e6*12*frame_parms->N_RB_DL/(double)frame_parms->ofdm_symbol_size)-174,
subframe);
#endif
if (RU2UE[ru_id][UE_id][CC_id]->first_run == 1)
RU2UE[ru_id][UE_id][CC_id]->first_run = 0;
// RF model
#ifdef DEBUG_SIM
LOG_D(OCM,"[SIM][DL] UE %d (CCid %d): rx_gain %d dB (-ADC %f) for subframe %d\n",UE_id,CC_id,PHY_vars_UE_g[UE_id][CC_id]->rx_total_gain_dB,
PHY_vars_UE_g[UE_id][CC_id]->rx_total_gain_dB-66.227,subframe);
#endif
rf_rx_simple(r_re0,
r_im0,
nb_antennas_rx,
length,
1e3/RU2UE[ru_id][UE_id][CC_id]->sampling_rate, // sampling time (ns)
(double)PHY_vars_UE_g[UE_id][CC_id]->rx_total_gain_dB - 66.227); // rx_gain (dB) (66.227 = 20*log10(pow2(11)) = gain from the adc that will be applied later)
#ifdef DEBUG_SIM
rx_pwr = signal_energy_fp(r_re0,r_im0,
nb_antennas_rx,
length<length_meas?length:length_meas,
0)/(12.0*frame_parms->N_RB_DL);
LOG_D(OCM,"[SIM][DL] UE %d : ADC in (RU %d) %f dBm/RE for subframe %d\n",
UE_id,ru_id,
10*log10(rx_pwr),subframe);
#endif
pthread_mutex_lock(&RU_output_mutex[UE_id]);
for (i=0; i<frame_parms->samples_per_tti; i++) {
for (aa=0; aa<nb_antennas_rx; aa++) {
r_re_DL[UE_id][aa][i]+=r_re0[aa][i];
r_im_DL[UE_id][aa][i]+=r_im0[aa][i];
}
}
RU_output_mask[UE_id] |= (1<<ru_id);
if (RU_output_mask[UE_id] == (1<<RC.nb_RU)-1) {
RU_output_mask[UE_id]=0;
double *r_re_p[2] = {r_re_DL[UE_id][0],r_re_DL[UE_id][1]};
double *r_im_p[2] = {r_im_DL[UE_id][0],r_im_DL[UE_id][1]};
#ifdef DEBUG_SIM
rx_pwr = signal_energy_fp(r_re_p,r_im_p,nb_antennas_rx,length<length_meas?length:length_meas,0)/(12.0*frame_parms->N_RB_DL);
LOG_D(OCM,"[SIM][DL] UE %d : ADC in %f dBm/RE for subframe %d\n",UE_id,10*log10(rx_pwr),subframe);
#endif
rxdata = PHY_vars_UE_g[UE_id][CC_id]->common_vars.rxdata;
sf_offset = (subframe*frame_parms->samples_per_tti)+offset;
adc(r_re_p,
r_im_p,
0,
sf_offset,
rxdata,
nb_antennas_rx,
length,
12);
#ifdef DEBUG_SIM
rx_pwr2 = signal_energy(rxdata[0]+sf_offset,length<length_meas?length:length_meas)/(12.0*frame_parms->N_RB_DL);
LOG_D(OCM,"[SIM][DL] UE %d : rx_pwr (ADC out) %f dB/RE (%d) for subframe %d, writing to %p, length %d\n",UE_id, 10*log10((double)rx_pwr2),rx_pwr2,subframe,rxdata,length<length_meas?length:length_meas);
LOG_D(OCM,"[SIM][DL] UE %d : rx_pwr (ADC out) %f dB for subframe %d\n",UE_id,10*log10((double)rx_pwr2*12*frame_parms->N_RB_DL) ,subframe);
#else
UNUSED_VARIABLE(rx_pwr2);
UNUSED_VARIABLE(tx_pwr);
UNUSED_VARIABLE(rx_pwr);
#endif
} // RU_output_mask
pthread_mutex_unlock(&RU_output_mutex[UE_id]);
} // ru_id
}
}
void do_UL_sig(channel_desc_t *UE2RU[NUMBER_OF_UE_MAX][NUMBER_OF_RU_MAX][MAX_NUM_CCs],
node_desc_t *enb_data[NUMBER_OF_RU_MAX],node_desc_t *ue_data[NUMBER_OF_UE_MAX],
uint16_t subframe,uint8_t abstraction_flag,LTE_DL_FRAME_PARMS *frame_parms,
uint32_t frame,int ru_id,uint8_t CC_id)
{
int32_t **txdata,**rxdata;
uint8_t UE_id=0;
uint8_t nb_antennas_rx = UE2RU[0][0][CC_id]->nb_rx; // number of rx antennas at eNB
uint8_t nb_antennas_tx = UE2RU[0][0][CC_id]->nb_tx; // number of tx antennas at UE
double tx_pwr, rx_pwr;
int32_t rx_pwr2;
uint32_t i,aa;
uint32_t sf_offset;
uint8_t hold_channel=0;
double s_re0[30720];
double s_re1[30720];
double *s_re[2];
double s_im0[30720];
double s_im1[30720];
double *s_im[2];
double r_re00[30720];
double r_re01[30720];
double *r_re0[2];
double r_im00[30720];
double r_im01[30720];
double *r_im0[2];
s_re[0] = s_re0;
s_im[0] = s_im0;
s_re[1] = s_re1;
s_im[1] = s_im1;
r_re0[0] = r_re00;
r_im0[0] = r_im00;
r_re0[1] = r_re01;
r_im0[1] = r_im01;
if (abstraction_flag!=0) {
} else { //without abstraction
pthread_mutex_lock(&UE_output_mutex[ru_id]);
// Clear RX signal for eNB = eNB_id
for (i=0; i<frame_parms->samples_per_tti; i++) {
for (aa=0; aa<nb_antennas_rx; aa++) {
r_re_UL[ru_id][aa][i]=0.0;
r_im_UL[ru_id][aa][i]=0.0;
}
}
pthread_mutex_unlock(&UE_output_mutex[ru_id]);
// Compute RX signal for eNB = eNB_id
for (UE_id=0; UE_id<NB_UE_INST; UE_id++) {
txdata = PHY_vars_UE_g[UE_id][CC_id]->common_vars.txdata;
AssertFatal(txdata != NULL,"txdata is null\n");
sf_offset = subframe*frame_parms->samples_per_tti;
if (((double)PHY_vars_UE_g[UE_id][CC_id]->tx_power_dBm[subframe] +
UE2RU[UE_id][ru_id][CC_id]->path_loss_dB) <= -125.0) {
// don't simulate a UE that is too weak
LOG_D(OCM,"[SIM][UL] ULPOWERS UE %d tx_pwr %d dBm (num_RE %d) for subframe %d (sf_offset %d)\n",
UE_id,
PHY_vars_UE_g[UE_id][CC_id]->tx_power_dBm[subframe],
PHY_vars_UE_g[UE_id][CC_id]->tx_total_RE[subframe],
subframe,sf_offset);
} else {
tx_pwr = dac_fixed_gain((double**)s_re,
(double**)s_im,
txdata,
sf_offset,
nb_antennas_tx,
frame_parms->samples_per_tti,
sf_offset,
frame_parms->ofdm_symbol_size,
14,
(double)PHY_vars_UE_g[UE_id][CC_id]->tx_power_dBm[subframe]-10*log10((double)PHY_vars_UE_g[UE_id][CC_id]->tx_total_RE[subframe]),
1,
NULL,
PHY_vars_UE_g[UE_id][CC_id]->tx_total_RE[subframe]); // This make the previous argument the total power
LOG_D(OCM,"[SIM][UL] ULPOWERS UE %d tx_pwr %f dBm (target %d dBm, num_RE %d) for subframe %d (sf_offset %d)\n",
UE_id,
10*log10(tx_pwr*PHY_vars_UE_g[UE_id][CC_id]->tx_total_RE[subframe]),
PHY_vars_UE_g[UE_id][CC_id]->tx_power_dBm[subframe],
PHY_vars_UE_g[UE_id][CC_id]->tx_total_RE[subframe],
subframe,sf_offset);
multipath_channel(UE2RU[UE_id][ru_id][CC_id],s_re,s_im,r_re0,r_im0,
frame_parms->samples_per_tti,hold_channel);
rx_pwr = signal_energy_fp2(UE2RU[UE_id][ru_id][CC_id]->ch[0],
UE2RU[UE_id][ru_id][CC_id]->channel_length)*UE2RU[UE_id][ru_id][CC_id]->channel_length;
LOG_D(OCM,"[SIM][UL] subframe %d Channel UE %d => RU %d : %f dB (hold %d,length %d, PL %f)\n",subframe,UE_id,ru_id,10*log10(rx_pwr),
hold_channel,UE2RU[UE_id][ru_id][CC_id]->channel_length,
UE2RU[UE_id][ru_id][CC_id]->path_loss_dB);
rx_pwr = signal_energy_fp(r_re0,r_im0,nb_antennas_rx,frame_parms->samples_per_tti,0);
LOG_D(OCM,"[SIM][UL] RU %d (%d/%d rx antennas) : rx_pwr %f dBm (tx_pwr - PL %f) for subframe %d, sptti %d\n",
ru_id,nb_antennas_rx,UE2RU[UE_id][ru_id][CC_id]->nb_rx,10*log10(rx_pwr),10*log10(tx_pwr*PHY_vars_UE_g[UE_id][CC_id]->tx_total_RE[subframe])+UE2RU[UE_id][ru_id][CC_id]->path_loss_dB,subframe,frame_parms->samples_per_tti);
/*
if (abs(10*log10(rx_pwr)-10*log10(tx_pwr*PHY_vars_UE_g[UE_id][CC_id]->tx_total_RE[subframe])-UE2RU[UE_id][ru_id][CC_id]->path_loss_dB)>3) {
LOG_M("txsig_re.m","s_re",s_re[0],frame_parms->samples_per_tti,1,7);
LOG_M("txsig_im.m","s_im",s_im[0],frame_parms->samples_per_tti,1,7);
LOG_M("rxsig_re.m","r_re",r_re0[0],frame_parms->samples_per_tti,1,7);
LOG_M("rxsig_im.m","r_im",r_im0[0],frame_parms->samples_per_tti,1,7);
exit(-1);
}*/
if (UE2RU[UE_id][ru_id][CC_id]->first_run == 1)
UE2RU[UE_id][ru_id][CC_id]->first_run = 0;
pthread_mutex_lock(&UE_output_mutex[ru_id]);
for (aa=0; aa<nb_antennas_rx; aa++) {
for (i=0; i<frame_parms->samples_per_tti; i++) {
r_re_UL[ru_id][aa][i]+=r_re0[aa][i];
r_im_UL[ru_id][aa][i]+=r_im0[aa][i];
}
}
pthread_mutex_unlock(&UE_output_mutex[ru_id]);
}
} //UE_id
double *r_re_p[2] = {r_re_UL[ru_id][0],r_re_UL[ru_id][1]};
double *r_im_p[2] = {r_im_UL[ru_id][0],r_im_UL[ru_id][1]};
rx_pwr = signal_energy_fp(r_re_p,r_im_p,nb_antennas_rx,frame_parms->samples_per_tti,0);
LOG_D(OCM,"[SIM][UL] RU %d (%d/%d rx antennas) : rx_pwr %f dBm (before RF) for subframe %d, gain %f\n",
ru_id,nb_antennas_rx,nb_antennas_rx,10*log10(rx_pwr),subframe,
(double)RC.ru[ru_id]->max_rxgain-(double)RC.ru[ru_id]->att_rx - 66.227);
rf_rx_simple(r_re_p,
r_im_p,
nb_antennas_rx,
frame_parms->samples_per_tti,
1e3/UE2RU[0][ru_id][CC_id]->sampling_rate, // sampling time (ns)
(double)RC.ru[ru_id]->max_rxgain-(double)RC.ru[ru_id]->att_rx - 66.227); // rx_gain (dB) (66.227 = 20*log10(pow2(11)) = gain from the adc that will be applied later)
//#ifdef DEBUG_SIM
rx_pwr = signal_energy_fp(r_re_p,r_im_p,nb_antennas_rx,frame_parms->samples_per_tti,0);//*(double)frame_parms->ofdm_symbol_size/(12.0*frame_parms->N_RB_DL;
LOG_D(OCM,"[SIM][UL] rx_pwr (ADC in) %f dB for subframe %d (rx_gain %f)\n",10*log10(rx_pwr),subframe,
(double)RC.ru[ru_id]->max_rxgain-(double)RC.ru[ru_id]->att_rx);
//#endif
rxdata = RC.ru[ru_id]->common.rxdata;
sf_offset = subframe*frame_parms->samples_per_tti;
adc(r_re_p,
r_im_p,
0,
sf_offset,
rxdata,
nb_antennas_rx,
frame_parms->samples_per_tti,
12);
#ifdef DEBUG_SIM
rx_pwr2 = signal_energy(rxdata[0]+sf_offset,frame_parms->samples_per_tti)*(double)frame_parms->ofdm_symbol_size/(12.0*frame_parms->N_RB_DL);
LOG_D(OCM,"[SIM][UL] RU %d rx_pwr (ADC out) %f dB (%d) for subframe %d (offset %d) = %p\n",ru_id,10*log10((double)rx_pwr2),rx_pwr2,subframe,sf_offset,rxdata[0]+sf_offset);
#else
UNUSED_VARIABLE(tx_pwr);
UNUSED_VARIABLE(rx_pwr);
UNUSED_VARIABLE(rx_pwr2);
#endif
} // abstraction_flag==0
}
void init_channel_vars(LTE_DL_FRAME_PARMS *frame_parms, double ***s_re,double ***s_im,double ***r_re,double ***r_im,double ***r_re0,double ***r_im0)
{
int i;
memset(RU_output_mask,0,sizeof(int)*NUMBER_OF_UE_MAX);
for (i=0;i<NB_UE_INST;i++)
pthread_mutex_init(&RU_output_mutex[i],NULL);
memset(UE_output_mask,0,sizeof(int)*NUMBER_OF_RU_MAX);
for (i=0;i<NB_eNB_INST;i++)
pthread_mutex_init(&UE_output_mutex[i],NULL);
}
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file oaisim.c
* \brief oaisim top level
* \author Navid Nikaein
* \date 2013-2015
* \version 1.0
* \company Eurecom
* \email: openair_tech@eurecom.fr
* \note
* \warning
*/
#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>
#include "event_handler.h"
#include "SIMULATION/RF/rf.h"
#include "PHY/types.h"
#include "PHY/defs_eNB.h"
#include "PHY/defs_UE.h"
#include "PHY/LTE_TRANSPORT/transport_proto.h"
#include "PHY/LTE_UE_TRANSPORT/transport_proto_ue.h"
#include "PHY/phy_vars.h"
#include "PHY/phy_vars_ue.h"
#include "SCHED/sched_common_vars.h"
#include "LAYER2/MAC/mac.h"
#include "LAYER2/MAC/mac_proto.h"
#include "LAYER2/MAC/mac_vars.h"
#include "pdcp.h"
#include "RRC/LTE/rrc_vars.h"
#include "RRC/NAS/nas_config.h"
#include "system.h"
#include "PHY/TOOLS/lte_phy_scope.h"
#ifdef SMBV
// Rohde&Schwarz SMBV100A vector signal generator
#include "PHY/TOOLS/smbv.h"
char smbv_fname[] = "smbv_config_file.smbv";
unsigned short smbv_nframes = 4; // how many frames to configure 1,..,4
unsigned short config_frames[4] = {2,9,11,13};
unsigned char smbv_frame_cnt = 0;
uint8_t config_smbv = 0;
char smbv_ip[16];
#endif
#include "flexran_agent.h"
#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"
#include "enb_app.h"
#include "../PROC/interface.h"
#include "../PROC/channel_sim_proc.h"
#include "../PROC/Tsync.h"
#include "../PROC/Process.h"
#include "UTIL/LOG/vcd_signal_dumper.h"
#include "UTIL/OTG/otg_kpi.h"
#include "assertions.h"
#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
# include "create_tasks.h"
# include "intertask_interface_init.h"
#endif
#include "T.h"
/*
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;
*/
#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
#define DECOR_DIST 100
#define SF_VAR 10
//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 */
uint8_t usim_test = 0;
frame_t frame = 0;
char stats_buffer[16384];
channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM_CCs];
channel_desc_t *UE2RU[NUMBER_OF_UE_MAX][NUMBER_OF_RU_MAX][MAX_NUM_CCs];
//Added for PHY abstraction
node_desc_t *enb_data[NUMBER_OF_RU_MAX];
node_desc_t *ue_data[NUMBER_OF_UE_MAX];
pthread_cond_t sync_cond;
pthread_mutex_t sync_mutex;
int sync_var=-1;
pthread_mutex_t subframe_mutex;
int subframe_ru_mask=0,subframe_UE_mask=0;
openair0_config_t openair0_cfg[MAX_CARDS];
uint32_t downlink_frequency[MAX_NUM_CCs][4];
int32_t uplink_frequency_offset[MAX_NUM_CCs][4];
openair0_rf_map rf_map[MAX_NUM_CCs];
#if defined(ENABLE_ITTI)
volatile int start_eNB = 0;
volatile int start_UE = 0;
#endif
volatile int oai_exit = 0;
//int32_t **rxdata;
//int32_t **txdata;
uint16_t sf_ahead=4;
uint8_t nfapi_mode = 0;
// Added for PHY abstraction
extern node_list* ue_node_list;
extern node_list* enb_node_list;
extern int pdcp_period, omg_period;
extern double **s_re, **s_im, **r_re, **r_im, **r_re0, **r_im0;
int map1, map2;
extern double **ShaF;
double snr_dB, sinr_dB, snr_direction; //,sinr_direction;
extern double snr_step;
extern uint8_t set_sinr;
extern uint8_t ue_connection_test;
extern uint8_t set_seed;
extern uint8_t target_dl_mcs;
extern uint8_t target_ul_mcs;
extern uint8_t abstraction_flag;
extern uint8_t ethernet_flag;
extern uint16_t Nid_cell;
double cpuf;
#include "threads_t.h"
threads_t threads= {-1,-1,-1,-1,-1,-1,-1};
//#ifdef XFORMS
int otg_enabled;
int xforms=0;
//#endif
time_stats_t oaisim_stats;
time_stats_t oaisim_stats_f;
time_stats_t dl_chan_stats;
time_stats_t ul_chan_stats;
int emulate_rf = 0;
int numerology = 0;
int codingw = 0;
int fepw = 0;
// this should reflect the channel models in openair1/SIMULATION/TOOLS/defs.h
mapping small_scale_names[] = {
{ "custom", custom }, { "SCM_A", SCM_A },
{ "SCM_B", SCM_B }, { "SCM_C", SCM_C },
{ "SCM_D", SCM_D }, { "EPA", EPA },
{ "EVA", EVA }, { "ETU", ETU },
{ "MBSFN", MBSFN }, { "Rayleigh8", Rayleigh8 },
{ "Rayleigh1", Rayleigh1 }, { "Rayleigh1_800", Rayleigh1_800 },
{ "Rayleigh1_corr", Rayleigh1_corr }, { "Rayleigh1_anticorr", Rayleigh1_anticorr },
{ "Rice8", Rice8 }, { "Rice1", Rice1 }, { "Rice1_corr", Rice1_corr },
{ "Rice1_anticorr", Rice1_anticorr }, { "AWGN", AWGN }, { NULL,-1 }
};
#if !defined(ENABLE_ITTI)
static void *
sigh (void *arg);
#endif
void
oai_shutdown (void);
void reset_opp_meas_oaisim (void);
void wait_eNBs(void)
{
return;
}
void
help (void)
{
printf ("Usage: oaisim -h -a -F -C tdd_config -K [log_file] -V [vcd_file] -R N_RB_DL -e -x transmission_mode -m target_dl_mcs -r(ate_adaptation) -n n_frames -s snr_dB -k ricean_factor -t max_delay -f forgetting factor -A channel_model -z cooperation_flag -u nb_local_ue -U UE mobility -b nb_local_enb -B eNB_mobility -M ethernet_flag -p nb_master -g multicast_group -l log_level -c ocg_enable -T traffic model -D multicast network device\n");
printf ("-h provides this help message!\n");
printf ("-a Activates PHY abstraction mode\n");
printf ("-A set the multipath channel simulation, options are: SCM_A, SCM_B, SCM_C, SCM_D, EPA, EVA, ETU, Rayleigh8, Rayleigh1, Rayleigh1_corr,Rayleigh1_anticorr, Rice8,, Rice1, AWGN \n");
printf ("-b Set the number of local eNB\n");
printf ("-B Set the mobility model for eNB, options are: STATIC, RWP, RWALK, \n");
printf ("-c [1,2,3,4] Activate the config generator (OCG) to process the scenario descriptor, or give the scenario manually: -c template_1.xml \n");
printf ("-C [0-6] Sets TDD configuration\n");
printf ("-e Activates extended prefix mode\n");
printf ("-E Random number generator seed\n");
printf ("-f Set the forgetting factor for time-variation\n");
printf ("-F Activates FDD transmission (TDD is default)\n");
printf ("-g Set multicast group ID (0,1,2,3) - valid if M is set\n");
printf ("-G Enable background traffic \n");
printf ("-H Enable handover operation (default disabled) \n");
printf ("-I Enable CLI interface (to connect use telnet localhost 1352)\n");
printf ("-k Set the Ricean factor (linear)\n");
printf ("-K [log_file] Enable ITTI logging into log_file\n");
printf ("-l Set the global log level (8:trace, 7:debug, 6:info, 4:warn, 3:error) \n");
printf ("-L [0-1] 0 to disable new link adaptation, 1 to enable new link adapatation\n");
printf ("-m Gives a fixed DL mcs for eNB scheduler\n");
printf ("-M Set the machine ID for Ethernet-based emulation\n");
printf ("-n Set the number of frames for the simulation. 0 for no limit\n");
printf ("-O [enb_conf_file] eNB configuration file name\n");
printf ("-p Set the total number of machine in emulation - valid if M is set\n");
printf ("-P [trace type] Enable protocol analyzer. Possible values for OPT:\n");
printf (" - wireshark: Enable tracing of layers above PHY using an UDP socket\n");
printf (" - pcap: Enable tracing of layers above PHY to a pcap file\n");
printf (" - tshark: Not implemented yet\n");
printf ("-q Enable Openair performance profiler \n");
printf ("-Q Activate and set the MBMS service: 0 : not used (default eMBMS disabled), 1: eMBMS and RRC Connection enabled, 2: eMBMS relaying and RRC Connection enabled, 3: eMBMS enabled, RRC Connection disabled, 4: eMBMS relaying enabled, RRC Connection disabled\n");
printf ("-R [6,15,25,50,75,100] Sets N_RB_DL\n");
printf ("-r Activates rate adaptation (DL for now)\n");
printf ("-s snr_dB set a fixed (average) SNR, this deactivates the openair channel model generator (OCM)\n");
printf ("-S snir_dB set a fixed (average) SNIR, this deactivates the openair channel model generator (OCM)\n");
printf ("-t Gives a fixed UL mcs for eNB scheduler\n");
printf ("-T activate the traffic generator. Valide options are m2m,scbr,mcbr,bcbr,auto_pilot,bicycle_race,open_arena,team_fortress,m2m_traffic,auto_pilot_l,auto_pilot_m,auto_pilot_h,auto_pilot_e,virtual_game_l,virtual_game_m,virtual_game_h,virtual_game_f,alarm_humidity,alarm_smoke,alarm_temperature,openarena_dl,openarena_ul,voip_g711,voip_g729,video_vbr_10mbps,video_vbr_4mbps,video_vbr_2mbp,video_vbr_768kbps,video_vbr_384kbps,video_vbr_192kpbs,background_users\n");
printf ("-u Set the number of local UE\n");
printf ("-U Set the mobility model for UE, options are: STATIC, RWP, RWALK\n");
printf ("-V [vcd_file] Enable VCD dump into vcd_file\n");
printf ("-w number of CBA groups, if not specified or zero, CBA is inactive\n");
#ifdef SMBV
printf ("-W IP address to connect to Rohde&Schwarz SMBV100A and configure SMBV from config file. -W0 uses default IP 192.168.12.201\n");
#else
printf ("-W [Rohde&Schwarz SMBV100A functions disabled. Recompile with SMBV=1]\n");
#endif
printf ("-x deprecated. Set the transmission mode in config file!\n");
printf ("-y Set the number of receive antennas at the UE (1 or 2)\n");
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");
printf ("--xforms Activate the grapical scope\n");
#if T_TRACER
printf ("--T_port [port] use given port\n");
printf ("--T_nowait don't wait for tracer, start immediately\n");
printf ("--T_dont_fork to ease debugging with gdb\n");
#endif
}
pthread_t log_thread;
void
log_thread_init (void)
{
//create log_list
//log_list_init(&log_list);
#ifndef LOG_NO_THREAD
log_shutdown = 0;
if ((pthread_mutex_init (&log_lock, NULL) != 0)
|| (pthread_cond_init (&log_notify, NULL) != 0)) {
return;
}
if (pthread_create (&log_thread, NULL, log_thread_function, (void*) NULL)
!= 0) {
log_thread_finalize ();
return;
}
#endif
}
//Call it after the last LOG call
int
log_thread_finalize (void)
{
int err = 0;
#ifndef LOG_NO_THREAD
if (pthread_mutex_lock (&log_lock) != 0) {
return -1;
}
log_shutdown = 1;
/* Wake up LOG thread */
if ((pthread_cond_broadcast (&log_notify) != 0)
|| (pthread_mutex_unlock (&log_lock) != 0)) {
err = -1;
}
if (pthread_join (log_thread, NULL) != 0) {
err = -1;
}
if (pthread_mutex_unlock (&log_lock) != 0) {
err = -1;
}
if (!err) {
//log_list_free(&log_list);
pthread_mutex_lock (&log_lock);
pthread_mutex_destroy (&log_lock);
pthread_cond_destroy (&log_notify);
}
#endif
return err;
}
#if defined(ENABLE_ITTI)
static void set_cli_start(module_id_t module_idP, uint8_t start)
{
if (module_idP < NB_eNB_INST) {
oai_emulation.info.cli_start_enb[module_idP] = start;
} else {
oai_emulation.info.cli_start_ue[module_idP - NB_eNB_INST] = start;
}
}
#endif
#ifdef OPENAIR2
int omv_write(int pfd, node_list* enb_node_list, node_list* ue_node_list, Data_Flow_Unit omv_data)
{
module_id_t i;
omv_data.end = 0;
//omv_data.total_num_nodes = NB_UE_INST + NB_eNB_INST;
for (i = 0; i < NB_eNB_INST; i++) {
if (enb_node_list != NULL) {
omv_data.geo[i].x = (enb_node_list->node->x_pos < 0.0) ? 0.0 : enb_node_list->node->x_pos;
omv_data.geo[i].y = (enb_node_list->node->y_pos < 0.0) ? 0.0 : enb_node_list->node->y_pos;
omv_data.geo[i].z = 1.0;
omv_data.geo[i].mobility_type = oai_emulation.info.omg_model_enb;
omv_data.geo[i].node_type = 0; //eNB
enb_node_list = enb_node_list->next;
omv_data.geo[i].Neighbors = 0;
/*
for (j = NB_RU; j < NB_UE_INST + NB_RU; j++) {
if (is_UE_active (i, j - NB_RU) == 1) {
omv_data.geo[i].Neighbor[omv_data.geo[i].Neighbors] = j;
omv_data.geo[i].Neighbors++;
LOG_D(
OMG,
"[RU %d][UE %d] is_UE_active(i,j) %d geo (x%d, y%d) num neighbors %d\n", i, j-NB_RU, is_UE_active(i,j-NB_RU), omv_data.geo[i].x, omv_data.geo[i].y, omv_data.geo[i].Neighbors);
}
}
*/
}
}
for (i = NB_RU; i < NB_UE_INST + NB_RU; i++) {
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_RU; j++) {
if (is_UE_active (j, i - NB_RU) == 1) {
omv_data.geo[i].Neighbor[omv_data.geo[i].Neighbors] = j;
omv_data.geo[i].Neighbors++;
LOG_D(
OMG,
"[UE %d][RU %d] is_UE_active %d geo (x%d, y%d) num neighbors %d\n", i-NB_RU, j, is_UE_active(j,i-NB_RU), omv_data.geo[i].x, omv_data.geo[i].y, omv_data.geo[i].Neighbors);
}
}
*/
}
}
LOG_E(OMG, "pfd %d \n", pfd);
if (write (pfd, &omv_data, sizeof(struct Data_Flow_Unit)) == -1)
perror ("write omv failed");
return 1;
}
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");
}
#endif
#ifdef OPENAIR2
int pfd[2]; // fd for omv : fixme: this could be a local var
#endif
#ifdef OPENAIR2
static Data_Flow_Unit omv_data;
#endif //ALU
static module_id_t UE_inst = 0;
static module_id_t eNB_inst = 0;
static module_id_t ru_id;
Packet_OTG_List_t *otg_pdcp_buffer;
typedef enum l2l1_task_state_e {
L2L1_WAITTING, L2L1_RUNNING, L2L1_TERMINATED,
} l2l1_task_state_t;
l2l1_task_state_t l2l1_state = L2L1_WAITTING;
extern openair0_timestamp current_ru_rx_timestamp[NUMBER_OF_RU_MAX][MAX_NUM_CCs];
extern openair0_timestamp current_UE_rx_timestamp[NUMBER_OF_UE_MAX][MAX_NUM_CCs];
extern openair0_timestamp last_eNB_rx_timestamp[NUMBER_OF_eNB_MAX][MAX_NUM_CCs];
extern openair0_timestamp last_UE_rx_timestamp[NUMBER_OF_UE_MAX][MAX_NUM_CCs];
/*------------------------------------------------------------------------------*/
void *
l2l1_task (void *args_p)
{
int CC_id;
// Framing variables
int32_t sf;
//char fname[64], vname[64];
//#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
FD_lte_phy_scope_ue *form_ue[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
FD_lte_phy_scope_enb *form_enb[NUMBER_OF_UE_MAX];
char title[255];
char xname[32] = "oaisim";
int xargc = 1;
char *xargv[1];
//#endif
#undef PRINT_STATS /* this undef is to avoid gcc warnings */
#define PRINT_STATS
#ifdef PRINT_STATS
//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];
#endif
if (xforms==1) {
xargv[0] = xname;
fl_initialize (&xargc, xargv, NULL, 0, 0);
eNB_inst = 0;
for (UE_inst = 0; UE_inst < NB_UE_INST; UE_inst++) {
for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
// DL scope at UEs
form_ue[CC_id][UE_inst] = create_lte_phy_scope_ue();
sprintf (title, "LTE DL SCOPE eNB %d to UE %d CC_id %d", eNB_inst, UE_inst, CC_id);
fl_show_form (form_ue[CC_id][UE_inst]->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);
if (PHY_vars_UE_g[UE_inst][CC_id]->use_ia_receiver == 1) {
fl_set_button(form_ue[CC_id][UE_inst]->button_0,1);
fl_set_object_label(form_ue[CC_id][UE_inst]->button_0, "IA Receiver ON");
fl_set_object_color(form_ue[CC_id][UE_inst]->button_0, FL_GREEN, FL_GREEN);
}
}
}
}
#ifdef PRINT_STATS
for (UE_inst=0; UE_inst<NB_UE_INST; UE_inst++) {
sprintf(UE_stats_filename,"UE_stats%d.txt",UE_inst);
UE_stats[UE_inst] = fopen (UE_stats_filename, "w");
}
for (eNB_inst=0; eNB_inst<NB_eNB_INST; eNB_inst++) {
sprintf(eNB_stats_filename,"eNB_stats%d.txt",eNB_inst);
eNB_stats[eNB_inst] = fopen (eNB_stats_filename, "w");
}
if(abstraction_flag==0) {
for (UE_inst=0; UE_inst<NB_UE_INST; UE_inst++) {
/* TODO: transmission_mode is defined per CC, we set 0 for now */
sprintf(UE_stats_th_filename,"UE_stats_th%d_tx%d.txt",UE_inst,oai_emulation.info.transmission_mode[0]);
UE_stats_th[UE_inst] = fopen (UE_stats_th_filename, "w");
}
/* TODO: transmission_mode is defined per CC, we set 0 for now */
sprintf(eNB_stats_th_filename,"eNB_stats_th_tx%d.txt",oai_emulation.info.transmission_mode[0]);
eNB_avg_thr = fopen (eNB_stats_th_filename, "w");
} else {
for (UE_inst=0; UE_inst<NB_UE_INST; UE_inst++) {
/* TODO: transmission_mode is defined per CC, we set 0 for now */
sprintf(UE_stats_th_filename,"UE_stats_abs_th%d_tx%d.txt",UE_inst,oai_emulation.info.transmission_mode[0]);
UE_stats_th[UE_inst] = fopen (UE_stats_th_filename, "w");
}
/* TODO: transmission_mode is defined per CC, we set 0 for now */
sprintf(eNB_stats_th_filename,"eNB_stats_abs_th_tx%d.txt",oai_emulation.info.transmission_mode[0]);
eNB_avg_thr = fopen (eNB_stats_th_filename, "w");
}
#ifdef OPENAIR2
eNB_l2_stats = fopen ("eNB_l2_stats.txt", "w");
LOG_I(EMU,"eNB_l2_stats=%p\n", eNB_l2_stats);
#endif
#endif
#if defined(ENABLE_ITTI)
MessageDef *message_p = NULL;
const char *msg_name = NULL;
int result;
itti_mark_task_ready (TASK_L2L1);
LOG_I(EMU, "TASK_L2L1 is READY\n");
if ((oai_emulation.info.nb_enb_local > 0) &&
(oai_emulation.info.node_function[0] < NGFI_RAU_IF4p5)) {
/* 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;
start_eNB = 1;
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);
}
#endif
start_meas (&oaisim_stats);
for (frame = 0;
(l2l1_state != L2L1_TERMINATED) &&
((oai_emulation.info.n_frames_flag == 0) ||
(frame < oai_emulation.info.n_frames));
frame++) {
#if defined(ENABLE_ITTI)
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);
#endif
//Run the aperiodic user-defined events
if (oai_emulation.info.oeh_enabled == 1)
execute_events (frame);
if (ue_connection_test == 1) {
if ((frame % 20) == 0) {
snr_dB += snr_direction;
sinr_dB -= snr_direction;
}
if (snr_dB == -20) {
snr_direction = snr_step;
} else if (snr_dB == 20) {
snr_direction = -snr_step;
}
}
oai_emulation.info.frame = frame;
//oai_emulation.info.time_ms += 1;
oai_emulation.info.time_s += 0.01; // emu time in s, each frame lasts for 10 ms // JNote: TODO check the coherency of the time and frame (I corrected it to 10 (instead of 0.01)
//update_omg (frame); // frequency is defined in the omg_global params configurable by the user
//update_omg_ocm ();
#ifdef OPENAIR2
// 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);
}
#endif
for (sf = 0; sf < 10; sf++) {
LOG_D(EMU,"************************* Subframe %d\n",sf);
start_meas (&oaisim_stats_f);
wait_for_slot_isr ();
#if defined(ENABLE_ITTI)
itti_update_lte_time(frame % MAX_FRAME_NUMBER, sf<<1);
#endif
oai_emulation.info.time_ms = frame * 10 + sf;
#ifdef PROC
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,RU2UE,UE2RU,enb_data,ue_data,abstraction_flag,frame_parms,sf<<1);
if(Channel_Flag==0)
#endif
{ // SUBFRAME INNER PART
#if defined(ENABLE_ITTI)
log_set_instance_type (LOG_INSTANCE_ENB);
#endif
CC_id=0;
int all_done=0;
while (all_done==0) {
pthread_mutex_lock(&subframe_mutex);
int subframe_ru_mask_local = (subframe_select(&RC.ru[0]->frame_parms,(sf+4)%10)!=SF_UL) ? subframe_ru_mask : ((1<<NB_RU)-1);
int subframe_UE_mask_local = (RC.ru[0]->frame_parms.frame_type == FDD || subframe_select(&RC.ru[0]->frame_parms,(sf+4)%10)!=SF_DL) ? subframe_UE_mask : ((1<<NB_UE_INST)-1);
pthread_mutex_unlock(&subframe_mutex);
LOG_D(EMU,"Frame %d, Subframe %d, NB_RU %d, NB_UE %d: Checking masks %x,%x\n",frame,sf,NB_RU,NB_UE_INST,subframe_ru_mask_local,subframe_UE_mask_local);
if ((subframe_ru_mask_local == ((1<<NB_RU)-1)) &&
(subframe_UE_mask_local == ((1<<NB_UE_INST)-1))) all_done=1;
else usleep(1500);
}
//clear subframe masks for next round
pthread_mutex_lock(&subframe_mutex);
subframe_ru_mask=0;
subframe_UE_mask=0;
pthread_mutex_unlock(&subframe_mutex);
// increment timestamps
/*
for (ru_id = oai_emulation.info.first_enb_local;
(ru_id
< (oai_emulation.info.first_enb_local
+ oai_emulation.info.nb_enb_local));
ru_id++) {
*/
for (ru_id=0;ru_id<NB_RU;ru_id++) {
current_ru_rx_timestamp[ru_id][CC_id] += RC.ru[ru_id]->frame_parms.samples_per_tti;
LOG_D(EMU,"RU %d/%d: TS %"PRIi64"\n",ru_id,CC_id,current_ru_rx_timestamp[ru_id][CC_id]);
}
for (UE_inst = 0; UE_inst<NB_UE_INST;UE_inst++) {
current_UE_rx_timestamp[UE_inst][CC_id] += PHY_vars_UE_g[UE_inst][CC_id]->frame_parms.samples_per_tti;
LOG_D(EMU,"UE %d/%d: TS %"PRIi64"\n",UE_inst,CC_id,current_UE_rx_timestamp[UE_inst][CC_id]);
}
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) {
/*
LOG_D(EMU,
"PHY procedures eNB %d for frame %d, subframe %d TDD %d/%d Nid_cell %d\n",
eNB_inst,
frame % MAX_FRAME_NUMBER,
sf,
PHY_vars_eNB_g[eNB_inst][0]->frame_parms.frame_type,
PHY_vars_eNB_g[eNB_inst][0]->frame_parms.tdd_config,
PHY_vars_eNB_g[eNB_inst][0]->frame_parms.Nid_cell);
*/
#ifdef PRINT_STATS
if((sf==9) && frame%10==0)
if(eNB_avg_thr)
fprintf(eNB_avg_thr,"%d %d\n",RC.eNB[eNB_inst][0]->proc.proc_rxtx[sf&1].frame_tx,
(RC.eNB[eNB_inst][0]->total_system_throughput)/((RC.eNB[eNB_inst][0]->proc.proc_rxtx[sf&1].frame_tx+1)*10));
/*
if (eNB_stats[eNB_inst]) {
len = dump_eNB_stats(RC.eNB[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]);
}
#ifdef OPENAIR2
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);
}
#endif
*/
#endif
}
}// eNB_inst loop
#if defined(ENABLE_ITTI)
log_set_instance_type (LOG_INSTANCE_UE);
#endif
if ((sf == 0) && ((frame % MAX_FRAME_NUMBER) == 0) && (abstraction_flag == 0)
&& (oai_emulation.info.n_frames == 1)) {
LOG_M ("dlchan0.m",
"dlch0",
&(PHY_vars_UE_g[0][0]->common_vars.common_vars_rx_data_per_thread[0].dl_ch_estimates[0][0][0]),
(6
* (PHY_vars_UE_g[0][0]->frame_parms.ofdm_symbol_size)),
1, 1);
LOG_M ("dlchan1.m",
"dlch1",
&(PHY_vars_UE_g[0][0]->common_vars.common_vars_rx_data_per_thread[0].dl_ch_estimates[1][0][0]),
(6
* (PHY_vars_UE_g[0][0]->frame_parms.ofdm_symbol_size)),
1, 1);
LOG_M ("dlchan2.m",
"dlch2",
&(PHY_vars_UE_g[0][0]->common_vars.common_vars_rx_data_per_thread[0].dl_ch_estimates[2][0][0]),
(6
* (PHY_vars_UE_g[0][0]->frame_parms.ofdm_symbol_size)),
1, 1);
LOG_M ("pbch_rxF_comp0.m",
"pbch_comp0",
PHY_vars_UE_g[0][0]->pbch_vars[0]->rxdataF_comp[0],
6 * 12 * 4, 1, 1);
LOG_M ("pbch_rxF_llr.m", "pbch_llr",
PHY_vars_UE_g[0][0]->pbch_vars[0]->llr,
(PHY_vars_UE_g[0][0]->frame_parms.Ncp == 0) ? 1920 : 1728, 1,
4);
}
stop_meas (&oaisim_stats_f);
} // SUBFRAME INNER PART
}
//update_ocm ();
/*
if ((frame >= 10) && (frame <= 11) && (abstraction_flag == 0)
#ifdef PROC
&&(Channel_Flag==0)
#endif
) {
sprintf (fname, "UEtxsig%d.m", frame % MAX_FRAME_NUMBER);
sprintf (vname, "txs%d", frame % MAX_FRAME_NUMBER);
LOG_M (fname,
vname,
PHY_vars_UE_g[0][0]->common_vars.txdata[0],
PHY_vars_UE_g[0][0]->frame_parms.samples_per_tti
* 10,
1, 1);
sprintf (fname, "eNBtxsig%d.m", frame % MAX_FRAME_NUMBER);
sprintf (vname, "txs%d", frame % MAX_FRAME_NUMBER);
LOG_M (fname,
vname,
PHY_vars_eNB_g[0][0]->common_vars.txdata[0][0],
PHY_vars_UE_g[0][0]->frame_parms.samples_per_tti
* 10,
1, 1);
sprintf (fname, "eNBtxsigF%d.m", frame % MAX_FRAME_NUMBER);
sprintf (vname, "txsF%d", frame % MAX_FRAME_NUMBER);
LOG_M (fname,
vname,
PHY_vars_eNB_g[0][0]->common_vars.txdataF[0][0],
PHY_vars_eNB_g[0][0]->frame_parms.symbols_per_tti
* PHY_vars_eNB_g[0][0]->frame_parms.ofdm_symbol_size,
1, 1);
sprintf (fname, "UErxsig%d.m", frame % MAX_FRAME_NUMBER);
sprintf (vname, "rxs%d", frame % MAX_FRAME_NUMBER);
LOG_M (fname,
vname,
PHY_vars_UE_g[0][0]->common_vars.rxdata[0],
PHY_vars_UE_g[0][0]->frame_parms.samples_per_tti
* 10,
1, 1);
sprintf (fname, "eNBrxsig%d.m", frame % MAX_FRAME_NUMBER);
sprintf (vname, "rxs%d", frame % MAX_FRAME_NUMBER);
LOG_M (fname,
vname,
PHY_vars_eNB_g[0][0]->common_vars.rxdata[0][0],
PHY_vars_UE_g[0][0]->frame_parms.samples_per_tti
* 10,
1, 1);
}
*/
//#ifdef XFORMS
if (xforms==1) {
eNB_inst = 0;
for (UE_inst = 0; UE_inst < NB_UE_INST; UE_inst++) {
for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
phy_scope_UE(form_ue[CC_id][UE_inst],
PHY_vars_UE_g[UE_inst][CC_id],
eNB_inst,
UE_inst,
7);
}
if (RC.eNB && RC.eNB[eNB_inst] && RC.eNB[eNB_inst][0] )
phy_scope_eNB(form_enb[UE_inst],
RC.eNB[eNB_inst][0],
UE_inst);
}
}
//#endif
#ifdef SMBV
// Rohde&Schwarz SMBV100A vector signal generator
if ((frame % MAX_FRAME_NUMBER == config_frames[0]) || (frame % MAX_FRAME_NUMBER == config_frames[1]) || (frame % MAX_FRAME_NUMBER == config_frames[2]) || (frame % MAX_FRAME_NUMBER == config_frames[3])) {
smbv_frame_cnt++;
}
#endif
} // frame loop
stop_meas (&oaisim_stats);
oai_shutdown ();
#ifdef PRINT_STATS
for (UE_inst=0; UE_inst<NB_UE_INST; UE_inst++) {
if (UE_stats[UE_inst])
fclose (UE_stats[UE_inst]);
if(UE_stats_th[UE_inst])
fclose (UE_stats_th[UE_inst]);
}
for (eNB_inst=0; eNB_inst<NB_eNB_INST; eNB_inst++) {
if (eNB_stats[eNB_inst])
fclose (eNB_stats[eNB_inst]);
}
if (eNB_avg_thr)
fclose (eNB_avg_thr);
if (eNB_l2_stats)
fclose (eNB_l2_stats);
#endif
#if defined(ENABLE_ITTI)
itti_terminate_tasks(TASK_L2L1);
#endif
return NULL;
}
/*
* The following two functions are meant to restart *the lte-softmodem* and are
* here to make oaisim compile. A restart command from the controller will be
* ignored in oaisim.
*/
int stop_L1L2(int enb_id)
{
LOG_W(FLEXRAN_AGENT, "stop_L1L2() not supported in oaisim\n");
return 0;
}
int restart_L1L2(int enb_id)
{
LOG_W(FLEXRAN_AGENT, "restart_L1L2() not supported in oaisim\n");
return 0;
}
#if T_TRACER
int T_wait = 1; /* by default we wait for the tracer */
int T_port = 2021; /* default port to listen to to wait for the tracer */
int T_dont_fork = 0; /* default is to fork, see 'T_init' to understand */
#endif
void wait_RUs(void)
{
int i;
// wait for all RUs to be configured over fronthaul
pthread_mutex_lock(&RC.ru_mutex);
while (RC.ru_mask>0) {
pthread_cond_wait(&RC.ru_cond,&RC.ru_mutex);
}
// copy frame parameters from RU to UEs
for (i=0;i<NB_UE_INST;i++) {
PHY_vars_UE_g[i][0]->frame_parms.N_RB_DL = RC.ru[0]->frame_parms.N_RB_DL;
PHY_vars_UE_g[i][0]->frame_parms.N_RB_UL = RC.ru[0]->frame_parms.N_RB_UL;
PHY_vars_UE_g[i][0]->frame_parms.nb_antennas_tx = 1;
PHY_vars_UE_g[i][0]->frame_parms.nb_antennas_rx = 1;
// set initially to 2, it will be revised after initial synchronization
PHY_vars_UE_g[i][0]->frame_parms.nb_antenna_ports_eNB = 2;
PHY_vars_UE_g[i][0]->frame_parms.tdd_config = 1;
PHY_vars_UE_g[i][0]->frame_parms.dl_CarrierFreq = RC.ru[0]->frame_parms.dl_CarrierFreq;
PHY_vars_UE_g[i][0]->frame_parms.ul_CarrierFreq = RC.ru[0]->frame_parms.ul_CarrierFreq;
PHY_vars_UE_g[i][0]->frame_parms.eutra_band = RC.ru[0]->frame_parms.eutra_band;
LOG_I(PHY,"Initializing UE %d frame parameters from RU information: N_RB_DL %d, p %d, dl_Carrierfreq %u, ul_CarrierFreq %u, eutra_band %d\n",
i,
PHY_vars_UE_g[i][0]->frame_parms.N_RB_DL,
PHY_vars_UE_g[i][0]->frame_parms.nb_antenna_ports_eNB,
PHY_vars_UE_g[i][0]->frame_parms.dl_CarrierFreq,
PHY_vars_UE_g[i][0]->frame_parms.ul_CarrierFreq,
PHY_vars_UE_g[i][0]->frame_parms.eutra_band);
current_UE_rx_timestamp[i][0] = RC.ru[0]->frame_parms.samples_per_tti + RC.ru[0]->frame_parms.ofdm_symbol_size + RC.ru[0]->frame_parms.nb_prefix_samples0;
}
for (ru_id=0;ru_id<RC.nb_RU;ru_id++) current_ru_rx_timestamp[ru_id][0] = RC.ru[ru_id]->frame_parms.samples_per_tti;
printf("RUs are ready, let's go\n");
}
void init_UE(int,int,int,int);
void init_RU(const char*);
void set_UE_defaults(int nb_ue) {
for (int UE_id = 0;UE_id<nb_ue;UE_id++) {
for (int CC_id = 0;CC_id<MAX_NUM_CCs;CC_id++) {
for (uint8_t i=0; i<RX_NB_TH_MAX; i++) {
PHY_vars_UE_g[UE_id][CC_id]->pdcch_vars[i][0]->dciFormat = 0;
PHY_vars_UE_g[UE_id][CC_id]->pdcch_vars[i][0]->agregationLevel = 0xFF;
}
PHY_vars_UE_g[UE_id][CC_id]->current_dlsch_cqi[0] = 10;
PHY_vars_UE_g[UE_id][CC_id]->tx_power_max_dBm = 23;
}
}
}
static void print_current_directory(void)
{
char dir[8192]; /* arbitrary size (should be big enough) */
if (getcwd(dir, 8192) == NULL)
printf("ERROR getting working directory\n");
else
printf("working directory: %s\n", dir);
}
void init_devices(void);
int main (int argc, char **argv)
{
clock_t t;
print_current_directory();
start_background_system();
#ifdef SMBV
// Rohde&Schwarz SMBV100A vector signal generator
strcpy(smbv_ip,DEFAULT_SMBV_IP);
#endif
#ifdef PROC
int node_id;
int port,Process_Flag=0,wgt,Channel_Flag=0,temp;
#endif
//default parameters
oai_emulation.info.n_frames = MAX_FRAME_NUMBER; //1024; //10;
oai_emulation.info.n_frames_flag = 0; //fixme
snr_dB = 30;
NB_UE_INST = 1;
//Default values if not changed by the user in get_simulation_options();
pdcp_period = 1;
omg_period = 1;
//Clean ip rule table
for(int i =0; i<NUMBER_OF_UE_MAX; i++){
char command_line[100];
sprintf(command_line, "while ip rule del table %d; do true; done",i+201);
/* we don't care about return value from system(), but let's the
* compiler be silent, so let's do "if (XX);"
*/
if (system(command_line)) /* nothing */;
}
// start thread for log gen
log_thread_init ();
//init_oai_emulation (); // to initialize everything !!!
// get command-line options
get_simulation_options (argc, argv); //Command-line options
#if T_TRACER
T_init(T_port, T_wait, T_dont_fork);
#endif
// Initialize VCD LOG module
VCD_SIGNAL_DUMPER_INIT (oai_emulation.info.vcd_file);
#if !defined(ENABLE_ITTI)
pthread_t tid;
int err;
sigset_t sigblock;
sigemptyset (&sigblock);
sigaddset (&sigblock, SIGHUP);
sigaddset (&sigblock, SIGINT);
sigaddset (&sigblock, SIGTERM);
sigaddset (&sigblock, SIGQUIT);
//sigaddset(&sigblock, SIGKILL);
if ((err = pthread_sigmask (SIG_BLOCK, &sigblock, NULL)) != 0) {
printf ("SIG_BLOCK error\n");
return -1;
}
if (pthread_create (&tid, NULL, sigh, NULL)) {
printf ("Pthread for tracing Signals is not created!\n");
return -1;
} else {
printf ("Pthread for tracing Signals is created!\n");
}
#endif
// configure oaisim with OCG
//oaisim_config (); // config OMG and OCG, OPT, OTG, OLG
logInit();
#if defined(ENABLE_ITTI)
itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info, messages_definition_xml, oai_emulation.info.itti_dump_file);
MSC_INIT(MSC_E_UTRAN, THREAD_MAX+TASK_MAX);
#endif
set_glog(LOG_INFO, 0x15);
//set_log(OCG, LOG_DEBUG, 1);
//set_log(EMU, LOG_INFO, 20);
set_log(MAC, LOG_DEBUG, 1);
set_log(RLC, LOG_TRACE, 1);
//set_log(PHY, LOG_DEBUG, 1);
set_log(PDCP, LOG_TRACE, 1);
set_log(RRC, LOG_DEBUG, 1);
//set_log(OCM, LOG_INFO, 20);
//set_log(OTG, LOG_INFO, 1);
set_comp_log(OCG, LOG_ERR, 0x15,1);
set_comp_log(EMU, LOG_DEBUG, 0x15,20);
set_comp_log(MAC, LOG_TRACE, 0x15,1);
set_comp_log(RLC, LOG_TRACE, 0x15,1);
set_comp_log(PHY, LOG_TRACE, 0x15, 1);
set_comp_log(PDCP, LOG_DEBUG, 0x15,1);
set_comp_log(RRC, LOG_DEBUG, 0x15,1);
set_comp_log(OCM, LOG_DEBUG, 0x15,20);
set_comp_log(OTG, LOG_DEBUG, 0x15,1);
set_comp_log(OMG, LOG_NOTICE, 0x15,1);
set_comp_log(OPT, LOG_ERR, 0x15,1);
if (ue_connection_test == 1) {
snr_direction = -snr_step;
snr_dB = 20;
sinr_dB = -20;
}
pthread_cond_init(&sync_cond,NULL);
pthread_mutex_init(&sync_mutex, NULL);
pthread_mutex_init(&subframe_mutex, NULL);
//Before this call, NB_UE_INST and NB_eNB_INST are not set correctly
check_and_adjust_params ();
set_seed = oai_emulation.emulation_config.seed.value;
init_seed (set_seed);
init_RU(NULL);
init_devices ();
// init_openair2 ();
// init_openair0();
if (create_tasks_ue(NB_UE_INST) < 0)
exit(-1); // need a softer mode
printf("Waiting for RUs to get set up\n");
wait_RUs();
init_UE(NB_UE_INST,0,0,1);
set_UE_defaults(NB_UE_INST);
init_ocm ();
printf("Sending sync to all threads\n");
pthread_mutex_lock(&sync_mutex);
sync_var=0;
pthread_cond_broadcast(&sync_cond);
pthread_mutex_unlock(&sync_mutex);
/* #if defined (FLEXRAN_AGENT_SB_IF)
flexran_agent_start();
#endif */
// 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_oaisim ();
cpuf=get_cpu_freq_GHz();
init_time ();
init_slot_isr ();
t = clock ();
LOG_N(EMU,
">>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU initialization done <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
#ifndef PACKAGE_VERSION
# define PACKAGE_VERSION "UNKNOWN-EXPERIMENTAL"
#endif
LOG_I(EMU, "Version: %s\n", PACKAGE_VERSION);
#if defined(ENABLE_ITTI)
// Handle signals until all tasks are terminated
itti_wait_tasks_end();
#else
if (oai_emulation.info.nb_enb_local > 0) {
eNB_app_task (NULL); // do nothing for the moment
}
l2l1_task (NULL);
#endif
t = clock () - t;
LOG_I(EMU, "Duration of the simulation: %f seconds\n",
((float) t) / CLOCKS_PER_SEC);
LOG_N(EMU,
">>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU Ending <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
raise (SIGINT);
// oai_shutdown ();
return (0);
}
void
reset_opp_meas_oaisim (void)
{
uint8_t eNB_id = 0, UE_id = 0;
reset_meas (&oaisim_stats);
reset_meas (&oaisim_stats_f); // frame
// init time stats here (including channel)
reset_meas (&dl_chan_stats);
reset_meas (&ul_chan_stats);
for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
reset_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc[0]);
reset_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc[1]);
reset_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc_rx[0]);
reset_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc_rx[1]);
reset_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc_tx);
// 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[0]);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_decoding_stats[1]);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_rate_unmatching_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_turbo_decoding_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_deinterleaving_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_llr_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_unscrambling_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_init_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_alpha_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_beta_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_gamma_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_ext_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_intl1_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_intl2_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->tx_prach);
reset_meas (&PHY_vars_UE_g[UE_id][0]->ofdm_mod_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_encoding_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_modulation_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_segmentation_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_rate_matching_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_turbo_encoding_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_interleaving_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_multiplexing_stats);
/*
* L2 functions
*/
// UE MAC
reset_meas (&UE_mac_inst[UE_id].ue_scheduler); // total
reset_meas (&UE_mac_inst[UE_id].tx_ulsch_sdu); // inlcude rlc_data_req + mac header gen
reset_meas (&UE_mac_inst[UE_id].rx_dlsch_sdu); // include mac_rrc_data_ind or mac_rlc_status_ind+mac_rlc_data_ind and mac header parser
reset_meas (&UE_mac_inst[UE_id].ue_query_mch);
reset_meas (&UE_mac_inst[UE_id].rx_mch_sdu); // include rld_data_ind+ parse mch header
reset_meas (&UE_mac_inst[UE_id].rx_si); // include rlc_data_ind + mac header parser
reset_meas (&UE_pdcp_stats[UE_id].pdcp_run);
reset_meas (&UE_pdcp_stats[UE_id].data_req);
reset_meas (&UE_pdcp_stats[UE_id].data_ind);
reset_meas (&UE_pdcp_stats[UE_id].apply_security);
reset_meas (&UE_pdcp_stats[UE_id].validate_security);
reset_meas (&UE_pdcp_stats[UE_id].pdcp_ip);
reset_meas (&UE_pdcp_stats[UE_id].ip_pdcp);
}
for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) {
for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
reset_meas (&RU2UE[eNB_id][UE_id][0]->random_channel);
reset_meas (&RU2UE[eNB_id][UE_id][0]->interp_time);
reset_meas (&RU2UE[eNB_id][UE_id][0]->interp_freq);
reset_meas (&RU2UE[eNB_id][UE_id][0]->convolution);
reset_meas (&UE2RU[UE_id][eNB_id][0]->random_channel);
reset_meas (&UE2RU[UE_id][eNB_id][0]->interp_time);
reset_meas (&UE2RU[UE_id][eNB_id][0]->interp_freq);
reset_meas (&UE2RU[UE_id][eNB_id][0]->convolution);
}
reset_meas (&RC.eNB[eNB_id][0]->phy_proc);
reset_meas (&RC.eNB[eNB_id][0]->phy_proc_rx);
reset_meas (&RC.eNB[eNB_id][0]->phy_proc_tx);
reset_meas (&RC.eNB[eNB_id][0]->rx_prach);
reset_meas (&RC.eNB[eNB_id][0]->ofdm_mod_stats);
reset_meas (&RC.eNB[eNB_id][0]->dlsch_encoding_stats);
reset_meas (&RC.eNB[eNB_id][0]->dlsch_modulation_stats);
reset_meas (&RC.eNB[eNB_id][0]->dlsch_scrambling_stats);
reset_meas (&RC.eNB[eNB_id][0]->dlsch_rate_matching_stats);
reset_meas (&RC.eNB[eNB_id][0]->dlsch_turbo_encoding_stats);
reset_meas (&RC.eNB[eNB_id][0]->dlsch_interleaving_stats);
// reset_meas (&RC.eNB[eNB_id][0]->ofdm_demod_stats);
//reset_meas(&RC.eNB[eNB_id]->rx_dft_stats);
//reset_meas(&RC.eNB[eNB_id]->ulsch_channel_estimation_stats);
//reset_meas(&RC.eNB[eNB_id]->ulsch_freq_offset_estimation_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_decoding_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_demodulation_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_rate_unmatching_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_turbo_decoding_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_deinterleaving_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_demultiplexing_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_llr_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_init_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_alpha_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_beta_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_gamma_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_ext_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_intl1_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_intl2_stats);
#ifdef LOCALIZATION
reset_meas(&RC.eNB[eNB_id][0]->localization_stats);
#endif
/*
* L2 functions
*/
// eNB MAC
reset_meas (&RC.mac[eNB_id]->eNB_scheduler); // total
reset_meas (&RC.mac[eNB_id]->schedule_si); // only schedule + tx
reset_meas (&RC.mac[eNB_id]->schedule_ra); // only ra
reset_meas (&RC.mac[eNB_id]->schedule_ulsch); // onlu ulsch
reset_meas (&RC.mac[eNB_id]->fill_DLSCH_dci); // only dci
reset_meas (&RC.mac[eNB_id]->schedule_dlsch_preprocessor); // include rlc_data_req + MAC header gen
reset_meas (&RC.mac[eNB_id]->schedule_dlsch); // include rlc_data_req + MAC header gen + pre-processor
reset_meas (&RC.mac[eNB_id]->schedule_mch); // only embms
reset_meas (&RC.mac[eNB_id]->rx_ulsch_sdu); // include rlc_data_ind + mac header parser
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);
}
}
void
print_opp_meas_oaisim (void)
{
uint8_t eNB_id = 0, UE_id = 0;
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);
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);
for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
for (ru_id = 0; ru_id < NB_RU; ru_id++) {
print_meas (&RU2UE[ru_id][UE_id][0]->random_channel,
"[DL][random_channel]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RU2UE[ru_id][UE_id][0]->interp_time,
"[DL][interp_time]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RU2UE[ru_id][UE_id][0]->interp_freq,
"[DL][interp_freq]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RU2UE[ru_id][UE_id][0]->convolution,
"[DL][convolution]", &oaisim_stats, &oaisim_stats_f);
print_meas (&UE2RU[UE_id][ru_id][0]->random_channel,
"[UL][random_channel]", &oaisim_stats, &oaisim_stats_f);
print_meas (&UE2RU[UE_id][ru_id][0]->interp_time,
"[UL][interp_time]", &oaisim_stats, &oaisim_stats_f);
print_meas (&UE2RU[UE_id][ru_id][0]->interp_freq,
"[UL][interp_freq]", &oaisim_stats, &oaisim_stats_f);
print_meas (&UE2RU[UE_id][ru_id][0]->convolution,
"[UL][convolution]", &oaisim_stats, &oaisim_stats_f);
}
}
for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
print_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc[0], "[UE][total_phy_proc[0]]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc[1], "[UE][total_phy_proc[1]]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc_rx[0],
"[UE][total_phy_proc_rx[0]]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc_rx[1],
"[UE][total_phy_proc_rx[1]]", &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[0],
"[UE][decoding[0]]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_decoding_stats[1],
"[UE][decoding[1]]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_rate_unmatching_stats,
"[UE][rate_unmatching]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_deinterleaving_stats,
"[UE][deinterleaving]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_turbo_decoding_stats,
"[UE][turbo_decoding]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_init_stats,
"[UE][ |_tc_init]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_alpha_stats,
"[UE][ |_tc_alpha]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_beta_stats,
"[UE][ |_tc_beta]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_gamma_stats,
"[UE][ |_tc_gamma]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_ext_stats,
"[UE][ |_tc_ext]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_intl1_stats,
"[UE][ |_tc_intl1]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_intl2_stats,
"[UE][ |_tc_intl2]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc_tx,
"[UE][total_phy_proc_tx]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->ofdm_mod_stats, "[UE][ofdm_mod]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_modulation_stats,
"[UE][modulation]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_encoding_stats,
"[UE][encoding]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_segmentation_stats,
"[UE][segmentation]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_rate_matching_stats,
"[UE][rate_matching]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_turbo_encoding_stats,
"[UE][turbo_encoding]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_interleaving_stats,
"[UE][interleaving]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_multiplexing_stats,
"[UE][multiplexing]", &oaisim_stats, &oaisim_stats_f);
}
for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) {
print_meas (&RC.eNB[eNB_id][0]->phy_proc,
"[eNB][total_phy_proc]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->phy_proc_tx,
"[eNB][total_phy_proc_tx]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ofdm_mod_stats,
"[eNB][ofdm_mod]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->dlsch_modulation_stats,
"[eNB][modulation]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->dlsch_scrambling_stats,
"[eNB][scrambling]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->dlsch_encoding_stats,
"[eNB][encoding]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->dlsch_interleaving_stats,
"[eNB][|_interleaving]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->dlsch_rate_matching_stats,
"[eNB][|_rate_matching]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->dlsch_turbo_encoding_stats,
"[eNB][|_turbo_encoding]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->phy_proc_rx,
"[eNB][total_phy_proc_rx]", &oaisim_stats, &oaisim_stats_f);
// print_meas (&RC.eNB[eNB_id][0]->ofdm_demod_stats,
// "[eNB][ofdm_demod]", &oaisim_stats, &oaisim_stats_f);
//print_meas(&RC.eNB[eNB_id][0]->ulsch_channel_estimation_stats,"[eNB][channel_est]");
//print_meas(&RC.eNB[eNB_id][0]->ulsch_freq_offset_estimation_stats,"[eNB][freq_offset]");
//print_meas(&RC.eNB[eNB_id][0]->rx_dft_stats,"[eNB][rx_dft]");
print_meas (&RC.eNB[eNB_id][0]->ulsch_demodulation_stats,
"[eNB][demodulation]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_decoding_stats,
"[eNB][decoding]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_deinterleaving_stats,
"[eNB][|_deinterleaving]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_demultiplexing_stats,
"[eNB][|_demultiplexing]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_rate_unmatching_stats,
"[eNB][|_rate_unmatching]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_turbo_decoding_stats,
"[eNB][|_turbo_decoding]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_init_stats,
"[eNB][ |_tc_init]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_alpha_stats,
"[eNB][ |_tc_alpha]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_beta_stats,
"[eNB][ |_tc_beta]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_gamma_stats,
"[eNB][ |_tc_gamma]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_ext_stats,
"[eNB][ |_tc_ext]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_intl1_stats,
"[eNB][ |_tc_intl1]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_intl2_stats,
"[eNB][ |_tc_intl2]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->rx_prach, "[eNB][rx_prach]",
&oaisim_stats, &oaisim_stats_f);
#ifdef LOCALIZATION
print_meas(&RC.eNB[eNB_id][0]->localization_stats, "[eNB][LOCALIZATION]",&oaisim_stats,&oaisim_stats_f);
#endif
}
for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
print_meas (&UE_mac_inst[UE_id].ue_scheduler, "[UE][mac_scheduler]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&UE_mac_inst[UE_id].tx_ulsch_sdu, "[UE][tx_ulsch_sdu]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&UE_mac_inst[UE_id].rx_dlsch_sdu, "[UE][rx_dlsch_sdu]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&UE_mac_inst[UE_id].ue_query_mch, "[UE][query_MCH]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&UE_mac_inst[UE_id].rx_mch_sdu, "[UE][rx_mch_sdu]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&UE_mac_inst[UE_id].rx_si, "[UE][rx_si]", &oaisim_stats,
&oaisim_stats_f);
print_meas (&UE_pdcp_stats[UE_id].pdcp_run, "[UE][total_pdcp_run]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&UE_pdcp_stats[UE_id].data_req, "[UE][DL][pdcp_data_req]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&UE_pdcp_stats[UE_id].data_ind, "[UE][UL][pdcp_data_ind]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&UE_pdcp_stats[UE_id].apply_security,
"[UE][DL][apply_security]", &oaisim_stats, &oaisim_stats_f);
print_meas (&UE_pdcp_stats[UE_id].validate_security,
"[UE][UL][validate_security]", &oaisim_stats,
&oaisim_stats_f);
print_meas (&UE_pdcp_stats[UE_id].ip_pdcp, "[UE][DL][ip_pdcp]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&UE_pdcp_stats[UE_id].pdcp_ip, "[UE][UL][pdcp_ip]",
&oaisim_stats, &oaisim_stats_f);
}
for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) {
print_meas (&RC.mac[eNB_id]->eNB_scheduler, "[eNB][mac_scheduler]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&RC.mac[eNB_id]->schedule_si, "[eNB][DL][SI]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&RC.mac[eNB_id]->schedule_ra, "[eNB][DL][RA]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&RC.mac[eNB_id]->fill_DLSCH_dci,
"[eNB][DL/UL][fill_DCI]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.mac[eNB_id]->schedule_dlsch_preprocessor,
"[eNB][DL][preprocessor]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.mac[eNB_id]->schedule_dlsch,
"[eNB][DL][schedule_tx_dlsch]", &oaisim_stats,
&oaisim_stats_f);
print_meas (&RC.mac[eNB_id]->schedule_mch, "[eNB][DL][mch]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&RC.mac[eNB_id]->schedule_ulsch, "[eNB][UL][ULSCH]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&RC.mac[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);
}
}
#if !defined(ENABLE_ITTI)
static void *
sigh (void *arg)
{
int signum;
sigset_t sigcatch;
sigemptyset (&sigcatch);
sigaddset (&sigcatch, SIGHUP);
sigaddset (&sigcatch, SIGINT);
sigaddset (&sigcatch, SIGTERM);
sigaddset (&sigcatch, SIGQUIT);
for (;;) {
sigwait (&sigcatch, &signum);
//sigwait(&sigblock, &signum);
switch (signum) {
case SIGHUP:
case SIGINT:
case SIGTERM:
case SIGQUIT:
fprintf (stderr, "received signal %d \n", signum);
// no need for mutx: when ITTI not used, this variable is only accessed by this function
l2l1_state = L2L1_TERMINATED;
break;
default:
fprintf (stderr, "Unexpected signal %d \n", signum);
exit (-1);
break;
}
}
pthread_exit (NULL);
}
#endif /* !defined(ENABLE_ITTI) */
void
oai_shutdown (void)
{
static int done = 0;
if (done)
return;
free (otg_pdcp_buffer);
otg_pdcp_buffer = 0;
#ifdef SMBV
// Rohde&Schwarz SMBV100A vector signal generator
if (config_smbv) {
smbv_send_config (smbv_fname,smbv_ip);
}
#endif
if (oai_emulation.info.opp_enabled == 1)
print_opp_meas_oaisim ();
#ifdef PROC
if (abstraction_flag == 0 && Channel_Flag==0 && Process_Flag==0)
#else
if (abstraction_flag == 0)
#endif
{
/*
#ifdef IFFT_FPGA
free(txdataF2[0]);
free(txdataF2[1]);
free(txdataF2);
free(txdata[0]);
free(txdata[1]);
free(txdata);
#endif
*/
/*
for (int 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);
s_re = 0;
s_im = 0;
r_re = 0;
r_im = 0;*/
lte_sync_time_free ();
}
// added for PHY abstraction
if (oai_emulation.info.ocm_enabled == 1) {
for (eNB_inst = 0; eNB_inst < NUMBER_OF_eNB_MAX; eNB_inst++) {
free (enb_data[eNB_inst]);
enb_data[eNB_inst] = 0;
}
for (UE_inst = 0; UE_inst < NUMBER_OF_UE_MAX; UE_inst++) {
free (ue_data[UE_inst]);
ue_data[UE_inst] = 0;
}
} //End of PHY abstraction changes
if ((oai_emulation.info.ocm_enabled == 1) && (ethernet_flag == 0)
&& (ShaF != NULL)) {
destroyMat (ShaF, map1, map2);
ShaF = 0;
}
if (opt_enabled == 1)
terminate_opt ();
for (int i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++)
if (oai_emulation.info.oai_ifup[i] == 1) {
char interfaceName[8];
snprintf (interfaceName, sizeof(interfaceName), "oai%d", i);
bringInterfaceUp (interfaceName, 0);
}
log_thread_finalize ();
logClean ();
VCD_SIGNAL_DUMPER_CLOSE ();
done = 1; // prevent next invokation of this function
LOG_N(EMU,
">>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU shutdown <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
}
eNB_MAC_INST*
get_eNB_mac_inst (module_id_t module_idP)
{
return (RC.mac[module_idP]);
}
OAI_Emulation*
get_OAI_emulation ()
{
return &oai_emulation;
}
// dummy function declarations
void *rrc_enb_task(void *args_p)
{
return NULL;
}
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file oaisim_functions.c
* \brief function primitives of oaisim
* \author Navid Nikaein
* \date 2013-2015
* \version 1.0
* \company Eurecom
* \email: openair_tech@eurecom.fr
* \note
* \warning
*/
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <execinfo.h>
#include <time.h>
#include <mcheck.h>
#include <sys/timerfd.h>
#include "assertions.h"
#include "oaisim_functions.h"
#include "PHY/phy_extern.h"
#include "PHY/phy_extern_ue.h"
#include "LAYER2/MAC/mac_extern.h"
#include "LAYER2/MAC/mac_proto.h"
#include "LAYER2/PDCP_v10.1.0/pdcp.h"
#include "LAYER2/PDCP_v10.1.0/pdcp_primitives.h"
#include "RRC/LTE/rrc_extern.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
#include "PHY_INTERFACE/phy_interface_extern.h"
//#include "ARCH/CBMIMO1/DEVICE_DRIVER/extern.h"
#include "SIMULATION/ETH_TRANSPORT/proto.h"
#include "UTIL/OCG/OCG_extern.h"
#include "UTIL/LOG/vcd_signal_dumper.h"
#include "UTIL/OPT/opt.h"
#include "UTIL/OTG/otg_config.h"
#include "UTIL/OTG/otg_tx.h"
#include "cor_SF_sim.h"
#include "enb_config.h"
#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
#endif
#if defined(ENABLE_USE_MME)
# include "s1ap_eNB.h"
#endif
#include "../../ARCH/COMMON/common_lib.h"
#include "../../ARCH/ETHERNET/USERSPACE/LIB/if_defs.h"
#include "ENB_APP/enb_paramdef.h"
#include "common/config/config_userapi.h"
//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
int otg_times = 0;
int if_times = 0;
int for_times = 0;
uint16_t Nid_cell = 0; //needed by init_lte_vars
int nb_antennas_rx_ue = 1; // //
uint8_t target_dl_mcs = 16; // max mcs used by MAC scheduler
uint8_t rate_adaptation_flag = 0;
uint8_t set_snr = 0;
uint8_t set_sinr = 0;
double snr_dB=0, sinr_dB=0;
uint8_t set_seed = 0;
uint8_t cooperation_flag; // for cooperative communication
uint8_t abstraction_flag = 0;
uint8_t ethernet_flag = 0;
double snr_step = 1.0;
uint8_t ue_connection_test = 0;
double forgetting_factor = 0.0;
uint8_t beta_ACK = 0;
uint8_t beta_RI = 0;
uint8_t beta_CQI = 2;
uint8_t target_ul_mcs = 16;
//LTE_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs];
int map1,map2;
double **ShaF = NULL;
// pointers signal buffers (s = transmit, r,r0 = receive)
double **s_re, **s_im, **r_re, **r_im, **r_re0, **r_im0;
node_list* ue_node_list = NULL;
node_list* enb_node_list = NULL;
int omg_period = 10000;
int pdcp_period = 0;
int cba_backoff = 30;
// time calibration for soft realtime mode
struct timespec time_spec;
unsigned long time_last = 0;
unsigned long time_now = 0;
int td = 0;
int td_avg = 0;
int sleep_time_us = 0;
int phy_test = 0;
extern node_desc_t *enb_data[NUMBER_OF_RU_MAX];
extern node_desc_t *ue_data[MAX_MOBILES_PER_ENB];
extern channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][MAX_MOBILES_PER_ENB][MAX_NUM_CCs];
extern channel_desc_t *UE2RU[MAX_MOBILES_PER_ENB][NUMBER_OF_RU_MAX][MAX_NUM_CCs];
extern mapping small_scale_names[];
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
extern pdcp_mbms_t pdcp_mbms_array_ue[MAX_MOBILES_PER_ENB][maxServiceCount][maxSessionPerPMCH];
extern pdcp_mbms_t pdcp_mbms_array_eNB[NUMBER_OF_eNB_MAX][maxServiceCount][maxSessionPerPMCH];
#endif
extern time_stats_t dl_chan_stats;
extern time_stats_t ul_chan_stats;
extern int xforms;
extern uint32_t downlink_frequency[MAX_NUM_CCs][4];
extern int32_t uplink_frequency_offset[MAX_NUM_CCs][4];
int oaisim_flag=1;
void RCConfig_sim(void) {
paramlist_def_t RUParamList = {CONFIG_STRING_RU_LIST,NULL,0};
// Get num RU instances
config_getlist( &RUParamList,NULL,0, NULL);
RC.nb_RU = RUParamList.numelt;
}
void get_simulation_options(int argc, char *argv[])
{
int option;
enum long_option_e {
LONG_OPTION_START = 0x100, /* Start after regular single char options */
LONG_OPTION_ENB_CONF,
LONG_OPTION_PDNC_PERIOD,
LONG_OPTION_OMG_PERIOD,
LONG_OPTION_OEH_ENABLED,
LONG_OPTION_ENB_RAL_LISTENING_PORT,
LONG_OPTION_ENB_RAL_IP_ADDRESS,
LONG_OPTION_ENB_RAL_LINK_ID,
LONG_OPTION_ENB_RAL_LINK_ADDRESS,
LONG_OPTION_ENB_MIHF_REMOTE_PORT,
LONG_OPTION_ENB_MIHF_IP_ADDRESS,
LONG_OPTION_ENB_MIHF_ID,
LONG_OPTION_UE_RAL_LISTENING_PORT,
LONG_OPTION_UE_RAL_IP_ADDRESS,
LONG_OPTION_UE_RAL_LINK_ID,
LONG_OPTION_UE_RAL_LINK_ADDRESS,
LONG_OPTION_UE_MIHF_REMOTE_PORT,
LONG_OPTION_UE_MIHF_IP_ADDRESS,
LONG_OPTION_UE_MIHF_ID,
LONG_OPTION_MALLOC_TRACE_ENABLED,
LONG_OPTION_CBA_BACKOFF_TIMER,
LONG_OPTION_PHYTEST,
LONG_OPTION_XFORMS,
#if T_TRACER
LONG_OPTION_T_PORT,
LONG_OPTION_T_NOWAIT,
LONG_OPTION_T_DONT_FORK,
#endif
};
static struct option long_options[] = {
{"enb-conf", required_argument, 0, LONG_OPTION_ENB_CONF},
{"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},
{"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},
{"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},
{"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},
{"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},
{"malloc-trace-enabled", no_argument, 0, LONG_OPTION_MALLOC_TRACE_ENABLED},
{"cba-backoff", required_argument, 0, LONG_OPTION_CBA_BACKOFF_TIMER},
{"phy-test", no_argument, NULL, LONG_OPTION_PHYTEST},
{"xforms", no_argument, 0, LONG_OPTION_XFORMS},
#if T_TRACER
{"T_port", required_argument, 0, LONG_OPTION_T_PORT},
{"T_nowait", no_argument, 0, LONG_OPTION_T_NOWAIT},
{"T_dont_fork", no_argument, 0, LONG_OPTION_T_DONT_FORK},
#endif
{NULL, 0, NULL, 0}
};
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) {
switch (option) {
case LONG_OPTION_PHYTEST:
phy_test = 1;
break;
case LONG_OPTION_ENB_CONF:
if (optarg) {
free(RC.config_file_name); // prevent memory leak if option is used multiple times
RC.config_file_name = strdup(optarg);
printf("eNB configuration file is %s\n", RC.config_file_name);
}
break;
case LONG_OPTION_PDNC_PERIOD:
if (optarg) {
pdcp_period = atoi(optarg);
printf("PDCP period is %d\n", pdcp_period);
}
break;
case LONG_OPTION_OMG_PERIOD:
if (optarg) {
omg_period = atoi(optarg);
printf("OMG period is %d\n", omg_period);
}
break;
case LONG_OPTION_OEH_ENABLED:
oai_emulation.info.oeh_enabled = 1;
break;
case LONG_OPTION_MALLOC_TRACE_ENABLED:
mtrace();
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;
#if ENABLE_RAL
case LONG_OPTION_ENB_RAL_LISTENING_PORT:
if (optarg) {
g_conf_enb_ral_listening_port = strdup(optarg);
printf("eNB RAL listening port is %s\n", g_conf_enb_ral_listening_port);
}
break;
case LONG_OPTION_ENB_RAL_IP_ADDRESS:
if (optarg) {
g_conf_enb_ral_ip_address = strdup(optarg);
printf("eNB RAL IP address is %s\n", g_conf_enb_ral_ip_address);
}
break;
case LONG_OPTION_ENB_RAL_LINK_ADDRESS:
if (optarg) {
g_conf_enb_ral_link_address = strdup(optarg);
printf("eNB RAL link address is %s\n", g_conf_enb_ral_link_address);
}
break;
case LONG_OPTION_ENB_RAL_LINK_ID:
if (optarg) {
g_conf_enb_ral_link_id = strdup(optarg);
printf("eNB RAL link id is %s\n", g_conf_enb_ral_link_id);
}
break;
case LONG_OPTION_ENB_MIHF_REMOTE_PORT:
if (optarg) {
g_conf_enb_mihf_remote_port = strdup(optarg);
printf("eNB MIH-F remote port is %s\n", g_conf_enb_mihf_remote_port);
}
break;
case LONG_OPTION_ENB_MIHF_IP_ADDRESS:
if (optarg) {
g_conf_enb_mihf_ip_address = strdup(optarg);
printf("eNB MIH-F IP address is %s\n", g_conf_enb_mihf_ip_address);
}
break;
case LONG_OPTION_ENB_MIHF_ID:
if (optarg) {
g_conf_enb_mihf_id = strdup(optarg);
printf("eNB MIH-F id is %s\n", g_conf_enb_mihf_id);
}
break;
case LONG_OPTION_UE_RAL_LISTENING_PORT:
if (optarg) {
g_conf_ue_ral_listening_port = strdup(optarg);
printf("UE RAL listening port is %s\n", g_conf_ue_ral_listening_port);
}
break;
case LONG_OPTION_UE_RAL_IP_ADDRESS:
if (optarg) {
g_conf_ue_ral_ip_address = strdup(optarg);
printf("UE RAL IP address is %s\n", g_conf_ue_ral_ip_address);
}
break;
case LONG_OPTION_UE_RAL_LINK_ID:
if (optarg) {
g_conf_ue_ral_link_id = strdup(optarg);
printf("UE RAL link id is %s\n", g_conf_ue_ral_link_id);
}
break;
case LONG_OPTION_UE_RAL_LINK_ADDRESS:
if (optarg) {
g_conf_ue_ral_link_address = strdup(optarg);
printf("UE RAL link address is %s\n", g_conf_ue_ral_link_address);
}
break;
case LONG_OPTION_UE_MIHF_REMOTE_PORT:
if (optarg) {
g_conf_ue_mihf_remote_port = strdup(optarg);
printf("UE MIH-F remote port is %s\n", g_conf_ue_mihf_remote_port);
}
break;
case LONG_OPTION_UE_MIHF_IP_ADDRESS:
if (optarg) {
g_conf_ue_mihf_ip_address = strdup(optarg);
printf("UE MIH-F IP address is %s\n", g_conf_ue_mihf_ip_address);
}
break;
case LONG_OPTION_UE_MIHF_ID:
if (optarg) {
g_conf_ue_mihf_id = strdup(optarg);
printf("UE MIH-F id is %s\n", g_conf_ue_mihf_id);
}
break;
#endif
case LONG_OPTION_XFORMS:
xforms=1;
break;
#if T_TRACER
case LONG_OPTION_T_PORT: {
extern int T_port;
if (optarg == NULL) abort(); /* should not happen */
T_port = atoi(optarg);
break;
}
case LONG_OPTION_T_NOWAIT: {
extern int T_wait;
T_wait = 0;
break;
}
case LONG_OPTION_T_DONT_FORK: {
extern int T_dont_fork;
T_dont_fork = 1;
break;
}
#endif
case 'a':
abstraction_flag = 1;
printf("FATAL: -a flag not functional for the moment.\nWe are working on fixing the abstraction mode.\n");
exit(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':
//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;
break;
case 'C':
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);
break;
case 'D':
oai_emulation.info.multicast_ifname = strdup(optarg);
break;
case 'e':
oai_emulation.info.extended_prefix_flag[0] = 1;
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");
oai_emulation.info.frame_type[0] = 0;
oai_emulation.info.frame_type_name[0] = "FDD";
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':
#ifdef PROC
Process_Flag=1;
node_id = wgt+atoi(optarg);
port+=atoi(optarg);
#endif
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");
exit(-1);
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);
printf("Max target downlink MCS used by MAC scheduler is set to %d\n", target_dl_mcs);
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);
oai_emulation.emulation_config.emulation_time_ms= oai_emulation.info.n_frames * 10; // 10 ms frame
//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':
if (optarg) {
free(RC.config_file_name); // prevent memory leak if option is used multiple times
RC.config_file_name = strdup(optarg);
}
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;
opt_enabled = 1;
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;
opt_enabled = 0;
}
oai_emulation.info.opt_mode = opt_type;
break;
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;
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':
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]);
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':
target_ul_mcs = atoi (optarg);
printf("Max target uplink MCS used by MAC scheduler is set to %d\n", target_ul_mcs);
break;
case 'T':
oai_emulation.info.otg_enabled = 1;
oai_emulation.info.otg_traffic = optarg;
break;
case 'u':
NB_UE_INST = 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':
#ifdef SMBV
config_smbv = 1;
if(atoi(optarg)!=0)
strcpy(smbv_ip,optarg);
#endif
break;
case 'x':
/*
oai_emulation.info.transmission_mode[0] = atoi (optarg);
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] != 4) &&
(oai_emulation.info.transmission_mode[0] != 5) && (oai_emulation.info.transmission_mode[0] != 6)) && (oai_emulation.info.transmission_mode[0] !=7)) {
printf("Unsupported transmission mode %d\n",oai_emulation.info.transmission_mode[0]);
exit(-1);
}
*/
printf("Option -x deprecated. Please set transmission mode in eNB config file\n");
exit(-1);
break;
case 'X':
#ifdef PROC
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;
}
#endif
break;
case 'y':
nb_antennas_rx_ue=atoi(optarg);
if (nb_antennas_rx_ue>4) {
printf("Cannot have more than 4 antennas\n");
exit(-1);
}
break;
case 'Y':
oai_emulation.info.g_log_verbosity_option = strdup(optarg);
break;
case 'z':
cooperation_flag = atoi (optarg);
break;
case 'Z':
/* Sebastien ROUX: Reserved for future use (currently used in ltenow branch) */
break;
default:
help ();
exit (-1);
break;
}
}
if ( load_configmodule(argc,argv) == NULL) {
exit_fun("[SOFTMODEM] Error, configuration module init failed\n");
}
if (RC.config_file_name != NULL) {
/* Read eNB configuration file */
RCConfig_sim();
printf("returned with %d eNBs, %d rus\n",RC.nb_inst,RC.nb_RU);
oai_emulation.info.nb_enb_local = RC.nb_inst;
oai_emulation.info.nb_ru_local = RC.nb_RU;
/*
for (int j=0; j<enb_properties->nb_ru; j++) {
// local_remote_radio = BBU_REMOTE_RADIO_HEAD;
(eth_params+j)->local_if_name = enb_properties->ru_config[j]->ru_if_name;
(eth_params+j)->my_addr = enb_properties->ru_config[j]->local_address;
(eth_params+j)->my_port = enb_properties->ru_config[j]->local_port;
(eth_params+j)->remote_addr = enb_properties->ru_config[j]->remote_address;
(eth_params+j)->remote_port = enb_properties->ru_config[j]->remote_port;
if (enb_properties->ru_config[j]->raw == 1) {
(eth_params+j)->transp_preference = ETH_RAW_MODE;
ru_if_in[j] = REMOTE_IF5;
node_function[j] = NGFI_RRU_IF5;
} else if (enb_properties->ru_config[j]->rawif4p5 == 1) {
(eth_params+j)->transp_preference = ETH_RAW_IF4p5_MODE;
ru_if_in[j] = REMOTE_IF4p5;
node_function[j] = NGFI_RRU_IF4p5;
} else if (enb_properties->ru_config[j]->udpif4p5 == 1) {
(eth_params+j)->transp_preference = ETH_UDP_IF4p5_MODE;
ru_if_in[j] = REMOTE_IF4p5;
node_function[j] = NGFI_RRU_IF4p5;
} else if (enb_properties->ru_config[j]->rawif5_mobipass == 1) {
(eth_params+j)->transp_preference = ETH_RAW_IF5_MOBIPASS;
ru_if_in[j] = REMOTE_IF5;
LOG_E(EMU,"Don't use 8-bit IF5 format with oaisim, please change in configuration file\n");
} else {
(eth_params+j)->transp_preference = ETH_UDP_MODE;
ru_if_in[j] = REMOTE_IF5;
node_function[j] = NGFI_RRU_IF5;
}
node_timing[j] = synch_to_ext_device;
if (enb_properties->number > 0) {
//Update some simulation parameters
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];
oai_emulation.info.node_function[0] = enb_properties->properties[0]->cc_node_function[0];
oai_emulation.info.node_timing[0] = enb_properties->properties[0]->cc_node_timing[0];
downlink_frequency[0][0] = enb_properties->properties[0]->downlink_frequency[0];
uplink_frequency_offset[0][0] = enb_properties->properties[0]->uplink_frequency_offset[0];
oai_emulation.info.N_RB_DL[0] = enb_properties->properties[0]->N_RB_DL[0];
LOG_E(EMU,"Please use only RRU with oaisim, remove eNB descriptors in configuration file\n");
exit(-1);
}
}*/
}
else {
printf("Please provide a configuration file\n");
exit(-1);
}
}
void check_and_adjust_params(void)
{
int32_t ret;
//int i,j;
if (oai_emulation.info.nb_ue_local + oai_emulation.info.nb_rn_local > MAX_MOBILES_PER_ENB) {
LOG_E(EMU,"Enter fewer than %d UEs/RNs for the moment or change the MAX_MOBILES_PER_ENB\n", MAX_MOBILES_PER_ENB);
exit(EXIT_FAILURE);
}
if (oai_emulation.info.nb_enb_local + oai_emulation.info.nb_rn_local > NUMBER_OF_eNB_MAX) {
LOG_E(EMU,"Enter fewer than %d eNBs/RNs for the moment or change the MAX_MOBILES_PER_ENB\n", NUMBER_OF_eNB_MAX);
exit(EXIT_FAILURE);
}
if (oai_emulation.info.nb_rn_local > NUMBER_OF_RN_MAX) {
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);
}
// 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");
ret = netlink_init();
if (ret < 0)
LOG_W(EMU,"[INIT] Netlink not available, careful ...\n");
/*
if (ethernet_flag == 1) {
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 ();
while (emu_tx_status != SYNCED_TRANSPORT) {
LOG_I (EMU, " Waiting for EMU Transport to be synced\n");
emu_transport_sync (); //emulation_tx_rx();
}
} // ethernet flag
*/
//
NB_RU = RC.nb_RU;
#if defined(PDCP_USE_NETLINK_QUEUES) && defined(OPENAIR2)
pdcp_netlink_init();
#endif
}
void init_seed(uint8_t set_seed)
{
if(set_seed) {
randominit (oai_emulation.info.seed);
set_taus_seed (oai_emulation.info.seed);
} else {
randominit (0);
set_taus_seed (0);
}
}
openair0_timestamp current_ru_rx_timestamp[NUMBER_OF_RU_MAX][MAX_NUM_CCs];
openair0_timestamp current_UE_rx_timestamp[MAX_MOBILES_PER_ENB][MAX_NUM_CCs];
openair0_timestamp last_ru_rx_timestamp[NUMBER_OF_RU_MAX][MAX_NUM_CCs];
openair0_timestamp last_UE_rx_timestamp[MAX_MOBILES_PER_ENB][MAX_NUM_CCs];
int ru_trx_start(openair0_device *device) {
return(0);
}
void ru_trx_end(openair0_device *device) {
return;
}
int ru_trx_stop(openair0_device *device) {
return(0);
}
int UE_trx_start(openair0_device *device) {
return(0);
}
void UE_trx_end(openair0_device *device) {
return;
}
int UE_trx_stop(openair0_device *device) {
return(0);
}
int ru_trx_set_freq(openair0_device *device, openair0_config_t *openair0_cfg, int dummy) {
return(0);
}
int ru_trx_set_gains(openair0_device *device, openair0_config_t *openair0_cfg) {
return(0);
}
int UE_trx_set_freq(openair0_device *device, openair0_config_t *openair0_cfg, int dummy) {
return(0);
}
int UE_trx_set_gains(openair0_device *device, openair0_config_t *openair0_cfg) {
return(0);
}
extern pthread_mutex_t subframe_mutex;
extern int subframe_ru_mask,subframe_UE_mask;
int ru_trx_read(openair0_device *device, openair0_timestamp *ptimestamp, void **buff, int nsamps, int cc) {
int ru_id = device->Mod_id;
int CC_id = device->CC_id;
int subframe;
int sample_count=0;
*ptimestamp = last_ru_rx_timestamp[ru_id][CC_id];
LOG_D(EMU,"RU_trx_read nsamps %d TS(%llu,%llu) => subframe %d\n",nsamps,
(unsigned long long)current_ru_rx_timestamp[ru_id][CC_id],
(unsigned long long)last_ru_rx_timestamp[ru_id][CC_id],
(int)((*ptimestamp/RC.ru[ru_id]->frame_parms.samples_per_tti)%10));
// if we're at a subframe boundary generate UL signals for this ru
while (sample_count<nsamps) {
while (current_ru_rx_timestamp[ru_id][CC_id]<
(nsamps+last_ru_rx_timestamp[ru_id][CC_id])) {
LOG_D(EMU,"RU: current TS %"PRIi64", last TS %"PRIi64", sleeping\n",current_ru_rx_timestamp[ru_id][CC_id],last_ru_rx_timestamp[ru_id][CC_id]);
usleep(500);
}
subframe = (last_ru_rx_timestamp[ru_id][CC_id]/RC.ru[ru_id]->frame_parms.samples_per_tti)%10;
if (subframe_select(&RC.ru[ru_id]->frame_parms,subframe) != SF_DL || RC.ru[ru_id]->frame_parms.frame_type == FDD) {
LOG_D(EMU,"RU_trx_read generating UL subframe %d (Ts %llu, current TS %llu)\n",
subframe,(unsigned long long)*ptimestamp,
(unsigned long long)current_ru_rx_timestamp[ru_id][CC_id]);
do_UL_sig(UE2RU,
enb_data,
ue_data,
subframe,
0, // abstraction_flag
&RC.ru[ru_id]->frame_parms,
0, // frame is only used for abstraction
ru_id,
CC_id);
}
last_ru_rx_timestamp[ru_id][CC_id] += RC.ru[ru_id]->frame_parms.samples_per_tti;
sample_count += RC.ru[ru_id]->frame_parms.samples_per_tti;
}
return(nsamps);
}
int UE_trx_read(openair0_device *device, openair0_timestamp *ptimestamp, void **buff, int nsamps, int cc)
{
int UE_id = device->Mod_id;
int CC_id = device->CC_id;
int subframe;
int sample_count=0;
int read_size;
int sptti = PHY_vars_UE_g[UE_id][CC_id]->frame_parms.samples_per_tti;
*ptimestamp = last_UE_rx_timestamp[UE_id][CC_id];
LOG_D(EMU,"UE %d DL simulation 0: UE_trx_read nsamps %d TS %llu (%llu, offset %d) antenna %d\n",
UE_id,
nsamps,
(unsigned long long)current_UE_rx_timestamp[UE_id][CC_id],
(unsigned long long)last_UE_rx_timestamp[UE_id][CC_id],
(int)(last_UE_rx_timestamp[UE_id][CC_id]%sptti),
cc);
if (nsamps < sptti)
read_size = nsamps;
else
read_size = sptti;
while (sample_count<nsamps) {
LOG_D(EMU,"UE %d: DL simulation 1: UE_trx_read : current TS now %"PRIi64", last TS %"PRIi64"\n",UE_id,current_UE_rx_timestamp[UE_id][CC_id],last_UE_rx_timestamp[UE_id][CC_id]);
while (current_UE_rx_timestamp[UE_id][CC_id] <
(last_UE_rx_timestamp[UE_id][CC_id]+read_size)) {
LOG_D(EMU,"UE %d: DL simulation 2: UE_trx_read : current TS %"PRIi64", last TS %"PRIi64", sleeping\n",UE_id,current_UE_rx_timestamp[UE_id][CC_id],last_UE_rx_timestamp[UE_id][CC_id]);
usleep(500);
}
LOG_D(EMU,"UE %d: DL simulation 3: UE_trx_read : current TS now %"PRIi64", last TS %"PRIi64"\n",UE_id,current_UE_rx_timestamp[UE_id][CC_id],last_UE_rx_timestamp[UE_id][CC_id]);
// if we cross a subframe-boundary
subframe = (last_UE_rx_timestamp[UE_id][CC_id]/sptti)%10;
// tell top-level we are busy
pthread_mutex_lock(&subframe_mutex);
subframe_UE_mask|=(1<<UE_id);
LOG_D(EMU,"Setting UE_id %d mask to busy (%d)\n",UE_id,subframe_UE_mask);
pthread_mutex_unlock(&subframe_mutex);
LOG_D(PHY,"UE %d: DL simulation 4: UE_trx_read generating DL subframe %d (Ts %llu, current TS %llu,nsamps %d)\n",
UE_id,subframe,(unsigned long long)*ptimestamp,
(unsigned long long)current_UE_rx_timestamp[UE_id][CC_id],
nsamps);
LOG_D(EMU,"UE %d: DL simulation 5: Doing DL simulation for %d samples starting in subframe %d at offset %d\n",
UE_id,nsamps,subframe,
(int)(last_UE_rx_timestamp[UE_id][CC_id]%sptti));
do_DL_sig(RU2UE,
enb_data,
ue_data,
subframe,
last_UE_rx_timestamp[UE_id][CC_id]%sptti,
sptti,
0, //abstraction_flag,
&PHY_vars_UE_g[UE_id][CC_id]->frame_parms,
UE_id,
CC_id);
LOG_D(EMU,"UE %d: DL simulation 6: UE_trx_read @ TS %"PRIi64" (%"PRIi64")=> frame %d, subframe %d\n",
UE_id, current_UE_rx_timestamp[UE_id][CC_id],
last_UE_rx_timestamp[UE_id][CC_id],
(int)((last_UE_rx_timestamp[UE_id][CC_id]/(sptti*10))&1023),
subframe);
last_UE_rx_timestamp[UE_id][CC_id] += read_size;
sample_count += read_size;
}
return(nsamps);
}
extern double ru_amp[NUMBER_OF_RU_MAX];
int ru_trx_write(openair0_device *device,openair0_timestamp timestamp, void **buff, int nsamps, int cc, int flags) {
int ru_id = device->Mod_id;
LTE_DL_FRAME_PARMS *frame_parms = &RC.ru[ru_id]->frame_parms;
pthread_mutex_lock(&subframe_mutex);
LOG_D(EMU,"[TXPATH] ru_trx_write: RU %d mask %d\n",ru_id,subframe_ru_mask);
pthread_mutex_unlock(&subframe_mutex);
// compute amplitude of TX signal from first symbol in subframe
// note: assumes that the packet is an entire subframe
ru_amp[ru_id] = 0;
for (int aa=0; aa<RC.ru[ru_id]->nb_tx; aa++) {
ru_amp[ru_id] += (double)signal_energy((int32_t*)buff[aa],frame_parms->ofdm_symbol_size)/(12*frame_parms->N_RB_DL);
}
ru_amp[ru_id] = sqrt(ru_amp[ru_id]);
LOG_D(EMU,"Setting amp for RU %d to %f (%d)\n",ru_id,ru_amp[ru_id], dB_fixed((double)signal_energy((int32_t*)buff[0],frame_parms->ofdm_symbol_size)));
// tell top-level we are done
pthread_mutex_lock(&subframe_mutex);
subframe_ru_mask|=(1<<ru_id);
LOG_D(EMU,"Setting RU %d to busy\n",ru_id);
pthread_mutex_unlock(&subframe_mutex);
return(nsamps);
}
int UE_trx_write(openair0_device *device,openair0_timestamp timestamp, void **buff, int nsamps, int cc, int flags) {
return(nsamps);
}
//void init_openair0(void);
//openair0_config_t openair0_cfg[MAX_CARDS];
/*
void init_openair0() {
int card;
int i;
for (card=0; card<MAX_CARDS; card++) {
openair0_cfg[card].configFilename = NULL;
if(frame_parms[0]->N_RB_DL == 100) {
if (frame_parms[0]->threequarter_fs) {
openair0_cfg[card].sample_rate=23.04e6;
openair0_cfg[card].samples_per_frame = 230400;
openair0_cfg[card].tx_bw = 10e6;
openair0_cfg[card].rx_bw = 10e6;
}
else {
openair0_cfg[card].sample_rate=30.72e6;
openair0_cfg[card].samples_per_frame = 307200;
openair0_cfg[card].tx_bw = 10e6;
openair0_cfg[card].rx_bw = 10e6;
}
} else if(frame_parms[0]->N_RB_DL == 50) {
openair0_cfg[card].sample_rate=15.36e6;
openair0_cfg[card].samples_per_frame = 153600;
openair0_cfg[card].tx_bw = 5e6;
openair0_cfg[card].rx_bw = 5e6;
} else if (frame_parms[0]->N_RB_DL == 25) {
openair0_cfg[card].sample_rate=7.68e6;
openair0_cfg[card].samples_per_frame = 76800;
openair0_cfg[card].tx_bw = 2.5e6;
openair0_cfg[card].rx_bw = 2.5e6;
} else if (frame_parms[0]->N_RB_DL == 6) {
openair0_cfg[card].sample_rate=1.92e6;
openair0_cfg[card].samples_per_frame = 19200;
openair0_cfg[card].tx_bw = 1.5e6;
openair0_cfg[card].rx_bw = 1.5e6;
}
if (frame_parms[0]->frame_type==TDD)
openair0_cfg[card].duplex_mode = duplex_mode_TDD;
else //FDD
openair0_cfg[card].duplex_mode = duplex_mode_FDD;
openair0_cfg[card].remote_addr = (eth_params+card)->remote_addr;
openair0_cfg[card].remote_port = (eth_params+card)->remote_port;
openair0_cfg[card].my_addr = (eth_params+card)->my_addr;
openair0_cfg[card].my_port = (eth_params+card)->my_port;
printf("HW: Configuring card %d, nb_antennas_tx/rx %d/%d\n",card,
RC.ru[0]->nb_tx,
RC.ru[0]->nb_rx);
openair0_cfg[card].Mod_id = 0;
openair0_cfg[card].num_rb_dl=frame_parms[0]->N_RB_DL;
openair0_cfg[card].tx_num_channels=min(2,RC.ru[0]->nb_tx);
openair0_cfg[card].rx_num_channels=min(2,RC.ru[0]->nb_rx);
for (i=0; i<4; i++) {
openair0_cfg[card].rx_gain[i] = RC.ru[0]->rx_total_gain_dB;
printf("Card %d, channel %d, Setting tx_gain %f, rx_gain %f, tx_freq %f, rx_freq %f\n",
card,i, openair0_cfg[card].tx_gain[i],
openair0_cfg[card].rx_gain[i],
openair0_cfg[card].tx_freq[i],
openair0_cfg[card].rx_freq[i]);
}
}
}
*/
void init_devices(void){
module_id_t UE_id, ru_id;
uint8_t CC_id;
RU_t *ru;
// allocate memory for RU if not already done
if (RC.ru==NULL) RC.ru = (RU_t**)malloc(RC.nb_RU*sizeof(RU_t*));
for (ru_id=0;ru_id<RC.nb_RU;ru_id++) {
LOG_I(EMU,"Initiaizing rfdevice for RU %d\n",ru_id);
if (RC.ru[ru_id]==NULL) RC.ru[ru_id] = (RU_t*)malloc(sizeof(RU_t));
ru = RC.ru[ru_id];
ru->rfdevice.Mod_id = ru_id;
ru->rfdevice.CC_id = 0;
ru->rfdevice.trx_start_func = ru_trx_start;
ru->rfdevice.trx_read_func = ru_trx_read;
ru->rfdevice.trx_write_func = ru_trx_write;
ru->rfdevice.trx_end_func = ru_trx_end;
ru->rfdevice.trx_stop_func = ru_trx_stop;
ru->rfdevice.trx_set_freq_func = ru_trx_set_freq;
ru->rfdevice.trx_set_gains_func = ru_trx_set_gains;
last_ru_rx_timestamp[ru_id][0] = 0;
}
if (PHY_vars_UE_g==NULL) {
PHY_vars_UE_g = (PHY_VARS_UE ***)malloc((1+NB_UE_INST)*sizeof(PHY_VARS_UE*));
for (UE_id=0;UE_id<NB_UE_INST;UE_id++) {
printf("Initializing UE %d\n",UE_id);
PHY_vars_UE_g[UE_id] = (PHY_VARS_UE **)malloc((1+MAX_NUM_CCs)*sizeof(PHY_VARS_UE*));
for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
PHY_vars_UE_g[UE_id][CC_id] = (PHY_VARS_UE *)malloc(sizeof(PHY_VARS_UE));
PHY_vars_UE_g[UE_id][CC_id]->rfdevice.Mod_id = UE_id;
PHY_vars_UE_g[UE_id][CC_id]->rfdevice.CC_id = CC_id;
PHY_vars_UE_g[UE_id][CC_id]->rfdevice.trx_start_func = UE_trx_start;
PHY_vars_UE_g[UE_id][CC_id]->rfdevice.trx_read_func = UE_trx_read;
PHY_vars_UE_g[UE_id][CC_id]->rfdevice.trx_write_func = UE_trx_write;
PHY_vars_UE_g[UE_id][CC_id]->rfdevice.trx_end_func = UE_trx_end;
PHY_vars_UE_g[UE_id][CC_id]->rfdevice.trx_stop_func = UE_trx_stop;
PHY_vars_UE_g[UE_id][CC_id]->rfdevice.trx_set_freq_func = UE_trx_set_freq;
PHY_vars_UE_g[UE_id][CC_id]->rfdevice.trx_set_gains_func = UE_trx_set_gains;
last_UE_rx_timestamp[UE_id][CC_id] = 0;
}
}
}
}
void init_ocm(void)
{
module_id_t UE_id, ru_id;
int CC_id;
/* Added for PHY abstraction */
/* TODO: frame_type is unused, is it intended? */
//char* frame_type = "unknown";
LTE_DL_FRAME_PARMS *fp = &RC.ru[0]->frame_parms;
init_channel_vars (fp, &s_re, &s_im, &r_re, &r_im, &r_re0, &r_im0);
// initialize channel descriptors
LOG_I(PHY,"Initializing channel descriptors (nb_RU %d, nb_UE %d)\n",RC.nb_RU,NB_UE_INST);
for (ru_id = 0; ru_id < RC.nb_RU; ru_id++) {
for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
LOG_I(PHY,"Initializing channel descriptors (RU %d, UE %d) for N_RB_DL %d\n",ru_id,UE_id,
RC.ru[ru_id]->frame_parms.N_RB_DL);
RU2UE[ru_id][UE_id][CC_id] =
new_channel_desc_scm(RC.ru[ru_id]->nb_tx,
PHY_vars_UE_g[UE_id][CC_id]->frame_parms.nb_antennas_rx,
map_str_to_int(small_scale_names,oai_emulation.environment_system_config.fading.small_scale.selected_option),
N_RB2sampling_rate(RC.ru[ru_id]->frame_parms.N_RB_DL),
N_RB2channel_bandwidth(RC.ru[ru_id]->frame_parms.N_RB_DL),
forgetting_factor,
0,
0);
random_channel(RU2UE[ru_id][UE_id][CC_id],abstraction_flag);
LOG_D(OCM,"[SIM] Initializing channel (%s, %d) from UE %d to ru %d\n", oai_emulation.environment_system_config.fading.small_scale.selected_option,
map_str_to_int(small_scale_names, oai_emulation.environment_system_config.fading.small_scale.selected_option),UE_id, ru_id);
UE2RU[UE_id][ru_id][CC_id] =
new_channel_desc_scm(PHY_vars_UE_g[UE_id][CC_id]->frame_parms.nb_antennas_tx,
RC.ru[ru_id]->nb_rx,
map_str_to_int(small_scale_names, oai_emulation.environment_system_config.fading.small_scale.selected_option),
N_RB2sampling_rate(RC.ru[ru_id]->frame_parms.N_RB_UL),
N_RB2channel_bandwidth(RC.ru[ru_id]->frame_parms.N_RB_UL),
forgetting_factor,
0,
0);
random_channel(UE2RU[UE_id][ru_id][CC_id],abstraction_flag);
// 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.
//UE2RU[UE_id][ru_id] = RU2UE[ru_id][UE_id];
AssertFatal(RU2UE[ru_id][UE_id][CC_id]!=NULL,"RU2UE[%d][%d][%d] is null\n",ru_id,UE_id,CC_id);
AssertFatal(UE2RU[UE_id][ru_id][CC_id]!=NULL,"UE2RU[%d][%d][%d] is null\n",UE_id,ru_id,CC_id);
//pathloss: -132.24 dBm/15kHz RE + target SNR - eNB TX power per RE
if (ru_id == (UE_id % RC.nb_RU)) {
RU2UE[ru_id][UE_id][CC_id]->path_loss_dB = -132.24 + snr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower;
UE2RU[UE_id][ru_id][CC_id]->path_loss_dB = -132.24 + snr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower;
} else {
RU2UE[ru_id][UE_id][CC_id]->path_loss_dB = -132.24 + sinr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower;
UE2RU[UE_id][ru_id][CC_id]->path_loss_dB = -132.24 + sinr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower;
}
LOG_D(OCM,"Path loss from eNB %d to UE %d (CCid %d)=> %f dB (eNB TX %d, SNR %f)\n",ru_id,UE_id,CC_id,
RU2UE[ru_id][UE_id][CC_id]->path_loss_dB,
RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower,snr_dB);
}
}
}
}
/*
void update_omg (frame_t frameP)
{
module_id_t UE_id, eNB_id;
int new_omg_model;
if ((frameP % omg_period) == 0 ) { // call OMG every 10ms
update_nodes(oai_emulation.info.time_s);
display_node_list(enb_node_list);
display_node_list(ue_node_list);
if (oai_emulation.info.omg_model_ue >= MAX_NUM_MOB_TYPES) { // mix mobility model
for(UE_id=oai_emulation.info.first_ue_local; UE_id<(oai_emulation.info.first_ue_local+oai_emulation.info.nb_ue_local); UE_id++) {
new_omg_model = randomgen(STATIC,RWALK);
LOG_D(OMG, "[UE] Node of ID %d is changing mobility generator ->%d \n", UE_id, new_omg_model);
// reset the mobility model for a specific node
set_new_mob_type (UE_id, UE, new_omg_model, oai_emulation.info.time_s);
}
}
if (oai_emulation.info.omg_model_enb >= MAX_NUM_MOB_TYPES) { // mix mobility model
for (eNB_id = oai_emulation.info.first_enb_local; eNB_id < (oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local); eNB_id++) {
new_omg_model = randomgen (STATIC, RWALK);
LOG_D (OMG,"[eNB] Node of ID %d is changing mobility generator ->%d \n", eNB_id, new_omg_model);
// reset the mobility model for a specific node
set_new_mob_type (eNB_id, eNB, new_omg_model, oai_emulation.info.time_s);
}
}
}
}
void update_omg_ocm()
{
enb_node_list=get_current_positions(oai_emulation.info.omg_model_enb, eNB, oai_emulation.info.time_s);
ue_node_list=get_current_positions(oai_emulation.info.omg_model_ue, UE, oai_emulation.info.time_s);
}
void update_ocm()
{
module_id_t UE_id, ru_id;
int CC_id;
// check if the openair channel model is activated used for PHY abstraction : path loss
if ((oai_emulation.info.ocm_enabled == 1)&& (ethernet_flag == 0 )) {
for (ru_id = 0; ru_id < RC.nb_RU; ru_id++)
enb_data[ru_id]->tx_power_dBm = RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower;
for (UE_id = 0; UE_id < NB_UE_INST; UE_id++)
ue_data[UE_id]->tx_power_dBm = PHY_vars_UE_g[UE_id][0]->tx_power_dBm[0];
//LOG_D(OMG," extracting position of eNb...\n");
//display_node_list(enb_node_list);
// display_node_list(ue_node_list);
//extract_position(enb_node_list, enb_data, RC.nb_RU);
//extract_position_fixed_enb(enb_data, NB_eNB_INST,frame);
//LOG_D(OMG," extracting position of UE...\n");
// if (oai_emulation.info.omg_model_ue == TRACE)
//extract_position(ue_node_list, ue_data, NB_UE_INST);
for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
for (ru_id = 0; ru_id < RC.nb_RU; ru_id++) {
for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
calc_path_loss (enb_data[ru_id], ue_data[UE_id], RU2UE[ru_id][UE_id][CC_id], oai_emulation.environment_system_config,ShaF);
//calc_path_loss (enb_data[ru_id], ue_data[UE_id], RU2UE[ru_id][UE_id], oai_emulation.environment_system_config,0);
UE2RU[UE_id][ru_id][CC_id]->path_loss_dB = RU2UE[ru_id][UE_id][CC_id]->path_loss_dB;
// if (frame % 50 == 0)
LOG_D(OCM,"Path loss (CCid %d) between eNB %d at (%f,%f) and UE %d at (%f,%f) is %f, angle %f\n",
CC_id,ru_id,enb_data[ru_id]->x,enb_data[ru_id]->y,UE_id,ue_data[UE_id]->x,ue_data[UE_id]->y,
RU2UE[ru_id][UE_id][CC_id]->path_loss_dB, RU2UE[ru_id][UE_id][CC_id]->aoa);
//double dx, dy, distance;
//dx = enb_data[ru_id]->x - ue_data[UE_id]->x;
//dy = enb_data[ru_id]->y - ue_data[UE_id]->y;
//distance = sqrt(dx * dx + dy * dy);
///LOG_D(LOCALIZE, " OCM distance between eNB %d at (%f,%f) and UE %d at (%f,%f) is %f \n",
// ru_id, enb_data[ru_id]->x,enb_data[ru_id]->y,
// UE_id, ue_data[UE_id]->x,ue_data[UE_id]->y,
// distance);
}
}
}
}
else {
for (ru_id = 0; ru_id < RC.nb_RU; ru_id++) {
for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
AssertFatal(RU2UE[ru_id][UE_id][CC_id]!=NULL,"RU2UE[%d][%d][%d] is null\n",ru_id,UE_id,CC_id);
AssertFatal(UE2RU[UE_id][ru_id][CC_id]!=NULL,"UE2RU[%d][%d][%d] is null\n",UE_id,ru_id,CC_id);
//pathloss: -132.24 dBm/15kHz RE + target SNR - eNB TX power per RE
if (ru_id == (UE_id % RC.nb_RU)) {
RU2UE[ru_id][UE_id][CC_id]->path_loss_dB = -132.24 + snr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower;
UE2RU[UE_id][ru_id][CC_id]->path_loss_dB = -132.24 + snr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower;
} else {
RU2UE[ru_id][UE_id][CC_id]->path_loss_dB = -132.24 + sinr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower;
UE2RU[UE_id][ru_id][CC_id]->path_loss_dB = -132.24 + sinr_dB - RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower;
}
LOG_D(OCM,"Path loss from eNB %d to UE %d (CCid %d)=> %f dB (eNB TX %d, SNR %f)\n",ru_id,UE_id,CC_id,
RU2UE[ru_id][UE_id][CC_id]->path_loss_dB,
RC.ru[ru_id]->frame_parms.pdsch_config_common.referenceSignalPower,snr_dB);
}
}
}
}
}
#ifdef OPENAIR2
void update_otg_eNB(module_id_t enb_module_idP, unsigned int ctime)
{
#if defined(USER_MODE) && defined(OAI_EMU)
//int rrc_state=0;
if (oai_emulation.info.otg_enabled ==1 ) {
int dst_id, app_id;
Packet_otg_elt_t *otg_pkt;
for (dst_id = 0; dst_id < MAX_MOBILES_PER_ENB; dst_id++) {
for_times += 1;
// generate traffic if the ue is rrc reconfigured state
//if ((rrc_state=mac_eNB_get_rrc_status(enb_module_idP, dst_id)) > 2 //RRC_CONNECTED
{
if (mac_eNB_get_rrc_status(enb_module_idP, oai_emulation.info.eNB_ue_module_id_to_rnti[enb_module_idP][dst_id]) > 2 ){
if_times += 1;
for (app_id=0; app_id<MAX_NUM_APPLICATION; app_id++) {
otg_pkt = malloc (sizeof(Packet_otg_elt_t));
(otg_pkt->otg_pkt).sdu_buffer = (uint8_t*) packet_gen(enb_module_idP, dst_id + NB_eNB_INST, app_id, ctime, &((otg_pkt->otg_pkt).sdu_buffer_size));
if ((otg_pkt->otg_pkt).sdu_buffer != NULL) {
otg_times += 1;
(otg_pkt->otg_pkt).rb_id = DTCH-2; // app could be binded to a given DRB
(otg_pkt->otg_pkt).module_id = enb_module_idP;
(otg_pkt->otg_pkt).dst_id = dst_id;
(otg_pkt->otg_pkt).is_ue = 0;
(otg_pkt->otg_pkt).mode = PDCP_TRANSMISSION_MODE_DATA;
//Adding the packet to the OTG-PDCP buffer
pkt_list_add_tail_eurecom(otg_pkt, &(otg_pdcp_buffer[enb_module_idP]));
LOG_D(EMU,"[eNB %d] ADD pkt to OTG buffer with size %d for dst %d on rb_id %d for app id %d \n",
(otg_pkt->otg_pkt).module_id, otg_pkt->otg_pkt.sdu_buffer_size, (otg_pkt->otg_pkt).dst_id,(otg_pkt->otg_pkt).rb_id, app_id);
} else {
free(otg_pkt);
otg_pkt=NULL;
}
}
}
}
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
mbms_service_id_t service_id;
mbms_session_id_t session_id;
rb_id_t rb_id;
// MBSM multicast traffic
if (ctime >= 500 ) {// only generate when UE can receive MTCH (need to control this value)
for (service_id = 0; service_id < 2 ; service_id++) { //maxServiceCount
for (session_id = 0; session_id < 2; session_id++) { // maxSessionPerPMCH
if (pdcp_mbms_array_eNB[enb_module_idP][service_id][session_id].instanciated_instance == TRUE) { // this service/session is configured
otg_pkt = malloc (sizeof(Packet_otg_elt_t));
// LOG_T(OTG,"multicast packet gen for (service/mch %d, session/lcid %d, rb_id %d)\n", service_id, session_id, service_id*maxSessionPerPMCH + session_id);
rb_id = pdcp_mbms_array_eNB[enb_module_idP][service_id][session_id].rb_id;
(otg_pkt->otg_pkt).sdu_buffer = (uint8_t*) packet_gen_multicast(enb_module_idP, session_id, ctime, &((otg_pkt->otg_pkt).sdu_buffer_size));
if ((otg_pkt->otg_pkt).sdu_buffer != NULL) {
(otg_pkt->otg_pkt).rb_id = rb_id;
(otg_pkt->otg_pkt).module_id = enb_module_idP;
(otg_pkt->otg_pkt).dst_id = session_id;
(otg_pkt->otg_pkt).is_ue = FALSE;
//Adding the packet to the OTG-PDCP buffer
(otg_pkt->otg_pkt).mode = PDCP_TRANSMISSION_MODE_TRANSPARENT;
pkt_list_add_tail_eurecom(otg_pkt, &(otg_pdcp_buffer[enb_module_idP]));
LOG_D(EMU, "[eNB %d] ADD packet (%p) multicast to OTG buffer for dst %d on rb_id %d\n",
(otg_pkt->otg_pkt).module_id, otg_pkt, (otg_pkt->otg_pkt).dst_id,(otg_pkt->otg_pkt).rb_id);
} else {
//LOG_I(EMU, "OTG returns null \n");
free(otg_pkt);
otg_pkt=NULL;
}
// old version
// MBSM multicast traffic
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
if (frame >= 46) {// only generate when UE can receive MTCH (need to control this value)
for (service_id = 0; service_id < 2 ; service_id++) { //maxServiceCount
for (session_id = 0; session_id < 2; session_id++) { // maxSessionPerPMCH
// LOG_I(OTG,"DUY:frame %d, pdcp_mbms_array[module_id][rb_id].instanciated_instance is %d\n",frame,pdcp_mbms_array[module_id][service_id*maxSessionPerPMCH + session_id].instanciated_instance);
if ((pdcp_mbms_array[module_idP][service_id*maxSessionPerPMCH + session_id].instanciated_instance== module_idP + 1) && (eNB_flag == 1)){ // this service/session is configured
// LOG_T(OTG,"multicast packet gen for (service/mch %d, session/lcid %d)\n", service_id, session_id);
// Duy add
LOG_I(OTG, "frame %d, multicast packet gen for (service/mch %d, session/lcid %d, rb_id %d)\n",frame, service_id, session_id,service_id*maxSessionPerPMCH + session_id);
// end Duy add
rb_id = pdcp_mbms_array[module_id][service_id*maxSessionPerPMCH + session_id].rb_id;
otg_pkt=(uint8_t*) packet_gen_multicast(module_idP, session_id, ctime, &pkt_size);
if (otg_pkt != NULL) {
LOG_D(OTG,"[eNB %d] sending a multicast packet from module %d on rab id %d (src %d, dst %d) pkt size %d\n", eNB_index, module_idP, rb_id, module_idP, session_id, pkt_size);
pdcp_data_req(module_id, frame, eNB_flag, rb_id, RLC_MUI_UNDEFINED, RLC_SDU_CONFIRM_NO, pkt_size, otg_pkt,PDCP_TM);
free(otg_pkt);
}
}
}
}
} // end multicast traffic
#endif
}
}
}
} // end multicast traffic
#endif
}
#else
}
void update_otg_UE(module_id_t ue_mod_idP, unsigned int ctime)
{
}
#endif
*/
int init_slot_isr(void)
{
if (oai_emulation.info.slot_isr) {
struct itimerspec its;
int sfd;
sfd = timerfd_create(CLOCK_REALTIME, 0);
if (sfd == -1) {
LOG_E(EMU, "Failed in timerfd_create (%d:%s)\n", errno, strerror(errno));
exit(EXIT_FAILURE);
}
/* Start the timer */
its.it_value.tv_sec = 0;
its.it_value.tv_nsec = 500 * 1000;
its.it_interval.tv_sec = its.it_value.tv_sec;
its.it_interval.tv_nsec = its.it_value.tv_nsec;
if (timerfd_settime(sfd, TFD_TIMER_ABSTIME, &its, NULL) == -1) {
LOG_E(EMU, "Failed in timer_settime (%d:%s)\n", errno, strerror(errno));
exit(EXIT_FAILURE);
}
oai_emulation.info.slot_sfd = sfd;
}
return 0;
}
void wait_for_slot_isr(void)
{
uint64_t exp;
ssize_t res;
if (oai_emulation.info.slot_sfd > 0) {
res = read(oai_emulation.info.slot_sfd, &exp, sizeof(exp));
if ((res < 0) || (res != sizeof(exp))) {
LOG_E(EMU, "Failed in read (%d:%s)\n", errno, strerror(errno));
exit(EXIT_FAILURE);
}
}
}
void exit_fun(const char* s)
{
void *array[10];
size_t size;
size = backtrace(array, 10);
backtrace_symbols_fd(array, size, 2);
fprintf(stderr, "Error: %s. Exiting!\n",s);
exit (-1);
}
void init_time()
{
clock_gettime (CLOCK_REALTIME, &time_spec);
time_now = (unsigned long) time_spec.tv_nsec;
td_avg = 0;
sleep_time_us = SLEEP_STEP_US;
td_avg = TARGET_SF_TIME_NS;
}
// dummy function
int oai_nfapi_rach_ind(nfapi_rach_indication_t *rach_ind) {
return(0);
}
/*
int openair0_transport_load(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t * eth_params) {
return(0);
}
int openair0_device_load(openair0_device *device, openair0_config_t *openair0_cfg) {
return(0);
}
*/
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#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>
//<<PAD>>//
//#include <mpi.h>
//#include "UTIL/FIFO/pad_list.h"
#include "discrete_event_generator.h"
#include "threadpool.h"
#include <pthread.h>
#include "oaisim_functions.h"
//<<PAD>>//
#include "SIMULATION/RF/defs.h"
#include "PHY/types.h"
#include "PHY/defs.h"
#include "PHY/vars.h"
#include "MAC_INTERFACE/vars.h"
//#ifdef OPENAIR2
#include "LAYER2/MAC/defs.h"
#include "LAYER2/MAC/vars.h"
#include "RRC/LITE/vars.h"
#include "PHY_INTERFACE/vars.h"
//#endif
#include "ARCH/CBMIMO1/DEVICE_DRIVER/vars.h"
#ifdef IFFT_FPGA
//#include "PHY/LTE_REFSIG/mod_table.h"
#endif //IFFT_FPGA
#include "SCHED/defs.h"
#include "SCHED/vars.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/LOG/vcd_signal_dumper.h"
#define RF
//#define DEBUG_SIM
#define MCS_COUNT 24//added for PHY abstraction
#define N_TRIALS 1
/*
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;
*/
#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
#define DECOR_DIST 100
#define SF_VAR 10
//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
//#ifdef OPENAIR2
//uint16_t NODE_ID[1];
//uint8_t NB_INST = 2;
//#endif //OPENAIR2
extern int otg_times;
extern int for_times;
extern int if_times;
int for_main_times = 0;
frame_t frame=0;
char stats_buffer[16384];
channel_desc_t *eNB2UE[NUMBER_OF_eNB_MAX][NUMBER_OF_UE_MAX];
channel_desc_t *UE2eNB[NUMBER_OF_UE_MAX][NUMBER_OF_eNB_MAX];
Signal_buffers *signal_buffers_g;
//Added for PHY abstraction
node_desc_t *enb_data[NUMBER_OF_eNB_MAX];
node_desc_t *ue_data[NUMBER_OF_UE_MAX];
//double sinr_bler_map[MCS_COUNT][2][16];
//double sinr_bler_map_up[MCS_COUNT][2][16];
//extern double SINRpost_eff[301];
extern int mcsPost;
extern int nrbPost;
extern int frbPost;
extern void kpi_gen();
extern uint16_t Nid_cell;
extern uint8_t target_dl_mcs;
extern uint8_t rate_adaptation_flag;
extern double snr_dB, sinr_dB;
extern uint8_t set_seed;
extern uint8_t cooperation_flag; // for cooperative communication
extern uint8_t abstraction_flag, ethernet_flag;
extern uint8_t ue_connection_test;
extern int map1,map2;
extern double **ShaF;
// pointers signal buffers (s = transmit, r,r0 = receive)
extern double **s_re, **s_im, **r_re, **r_im, **r_re0, **r_im0;
extern Node_list ue_node_list;
extern Node_list enb_node_list;
extern int pdcp_period, omg_period;
extern LTE_DL_FRAME_PARMS *frame_parms;
// time calibration for soft realtime mode
extern struct timespec time_spec;
extern unsigned long time_last, time_now;
extern int td, td_avg, sleep_time_us;
int eMBMS_active = 0;
threadpool_t * pool;
#ifdef OPENAIR2
extern int pfd[2];
#endif
// this should reflect the channel models in openair1/SIMULATION/TOOLS/defs.h
mapping small_scale_names[] = {
{"custom", custom},
{"SCM_A", SCM_A},
{"SCM_B", SCM_B},
{"SCM_C", SCM_C},
{"SCM_D", SCM_D},
{"EPA", EPA},
{"EVA", EVA},
{"ETU", ETU},
{"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}
};
//static void *sigh(void *arg);
void terminate(void);
void
help (void)
{
printf
("Usage: oaisim -h -a -F -C tdd_config -V -R N_RB_DL -e -x transmission_mode -m target_dl_mcs -r(ate_adaptation) -n n_frames -s snr_dB -k ricean_factor -t max_delay -f forgetting factor -A channel_model -z cooperation_flag -u nb_local_ue -U UE mobility -b nb_local_enb -B eNB_mobility -M ethernet_flag -p nb_master -g multicast_group -l log_level -c ocg_enable -T traffic model -D multicast network device\n");
printf ("-h provides this help message!\n");
printf ("-a Activates PHY abstraction mode\n");
printf ("-F Activates FDD transmission (TDD is default)\n");
printf ("-C [0-6] Sets TDD configuration\n");
printf ("-R [6,15,25,50,75,100] Sets N_RB_DL\n");
printf ("-e Activates extended prefix mode\n");
printf ("-m Gives a fixed DL mcs\n");
printf ("-r Activates rate adaptation (DL for now)\n");
printf ("-n Set the number of frames for the simulation\n");
printf ("-s snr_dB set a fixed (average) SNR, this deactivates the openair channel model generator (OCM)\n");
printf ("-S snir_dB set a fixed (average) SNIR, this deactivates the openair channel model generator (OCM)\n");
printf ("-k Set the Ricean factor (linear)\n");
printf ("-t Set the delay spread (microseconds)\n");
printf ("-f Set the forgetting factor for time-variation\n");
printf ("-A set the multipath channel simulation, options are: SCM_A, SCM_B, SCM_C, SCM_D, EPA, EVA, ETU, Rayleigh8, Rayleigh1, Rayleigh1_corr,Rayleigh1_anticorr, Rice8,, Rice1, AWGN \n");
printf ("-b Set the number of local eNB\n");
printf ("-u Set the number of local UE\n");
printf ("-M Set the machine ID for Ethernet-based emulation\n");
printf ("-p Set the total number of machine in emulation - valid if M is set\n");
printf ("-g Set multicast group ID (0,1,2,3) - valid if M is set\n");
printf ("-l Set the global log level (8:trace, 7:debug, 6:info, 4:warn, 3:error) \n");
printf
("-c [1,2,3,4] Activate the config generator (OCG) to process the scenario descriptor, or give the scenario manually: -c template_1.xml \n");
printf ("-x Set the transmission mode (1,2,5,6 supported for now)\n");
printf ("-z Set the cooperation flag (0 for no cooperation, 1 for delay diversity and 2 for distributed alamouti\n");
printf ("-T activate the traffic generator: 0 for NONE, 1 for CBR, 2 for M2M, 3 for FPS Gaming, 4 for mix\n");
printf ("-B Set the mobility model for eNB, options are: STATIC, RWP, RWALK, \n");
printf ("-U Set the mobility model for UE, options are: STATIC, RWP, RWALK \n");
printf ("-E Random number generator seed\n");
printf ("-P enable protocol analyzer : 0 for wireshark interface, 1: for pcap , 2 : for tshark \n");
printf ("-I Enable CLI interface (to connect use telnet localhost 1352)\n");
printf ("-V Enable VCD dump, file = openair_vcd_dump.vcd\n");
printf ("-G Enable background traffic \n");
printf ("-O [mme ipv4 address] Enable MME mode\n");
printf ("-Z Reserved\n");
}
#ifdef OPENAIR2
void omv_end (int pfd, Data_Flow_Unit omv_data);
int omv_write (int pfd, Node_list enb_node_list, Node_list ue_node_list, Data_Flow_Unit omv_data);
#endif
//<<<< PAD >>>>//
#define PAD 1
//#define PAD_FINE 1
//#define PAD_SYNC 1
#define JOB_REQUEST_TAG 246
#define JOB_REPLY_TAG 369
#define FRAME_END 888
#define NO_JOBS_TAG 404
#define JOB_DIST_DEBUG 33
//Global Variables
int worker_number;
int frame_number = 1;
//<<<< PAD >>>>//
//<<<< DEG >>>>//
extern End_Of_Sim_Event end_event; //Could later be a list of condition_events
extern Event_List event_list;
//<<<< DEG >>>>//
extern Packet_OTG_List *otg_pdcp_buffer;
void run(int argc, char *argv[]);
#ifdef PAD
void pad_init()
{
int UE_id, i;
pool = threadpool_create(PAD);
if (pool == NULL) {
printf("ERROR threadpool allocation\n");
return;
}
signal_buffers_g = malloc(NB_UE_INST * sizeof(Signal_buffers));
if (abstraction_flag == 0) {
for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
signal_buffers_g[UE_id].s_re = malloc(2*sizeof(double*));
signal_buffers_g[UE_id].s_im = malloc(2*sizeof(double*));
signal_buffers_g[UE_id].r_re = malloc(2*sizeof(double*));
signal_buffers_g[UE_id].r_im = malloc(2*sizeof(double*));
signal_buffers_g[UE_id].r_re0 = malloc(2*sizeof(double*));
signal_buffers_g[UE_id].r_im0 = malloc(2*sizeof(double*));
for (i=0; i<2; i++) {
signal_buffers_g[UE_id].s_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
bzero(signal_buffers_g[UE_id].s_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
signal_buffers_g[UE_id].s_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
bzero(signal_buffers_g[UE_id].s_im[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
signal_buffers_g[UE_id].r_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
bzero(signal_buffers_g[UE_id].r_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
signal_buffers_g[UE_id].r_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
bzero(signal_buffers_g[UE_id].r_im[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
signal_buffers_g[UE_id].r_re0[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
bzero(signal_buffers_g[UE_id].r_re0[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
signal_buffers_g[UE_id].r_im0[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
bzero(signal_buffers_g[UE_id].r_im0[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double));
}
}
}
}
void pad_finalize()
{
int ret, i;
module_id_t UE_id;
ret = threadpool_destroy(pool);
if (ret)
printf("ERROR threadpool destroy = %d\n", ret);
if (abstraction_flag == 0) {
for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
for (i = 0; i < 2; i++) {
free(signal_buffers_g[UE_id].s_re[i]);
free(signal_buffers_g[UE_id].s_im[i]);
free(signal_buffers_g[UE_id].r_re[i]);
free(signal_buffers_g[UE_id].r_im[i]);
}
free(signal_buffers_g[UE_id].s_re);
free(signal_buffers_g[UE_id].s_im);
free(signal_buffers_g[UE_id].r_re);
free(signal_buffers_g[UE_id].r_im);
}
//free node by node here same pattern as below
}
free(signal_buffers_g);
}
void pad_inject_job(int eNB_flag, int nid, int frame, int next_slot, int last_slot, enum Job_type type, int ctime)
{
int ret;
Job_elt *job_elt;
job_elt = malloc(sizeof(Job_elt));
job_elt->next = NULL;
(job_elt->job).eNB_flag = eNB_flag;
(job_elt->job).nid = nid;
(job_elt->job).frame = frame;
(job_elt->job).next_slot = next_slot;
(job_elt->job).last_slot = last_slot;
(job_elt->job).type = type;
(job_elt->job).ctime = ctime;
ret = threadpool_add(pool, job_elt);
if (ret) {
printf("ERROR threadpool_add %d\n", ret);
return;
}
}
void pad_synchronize()
{
pthread_mutex_lock(&(pool->sync_lock));
while(pool->active > 0) {
pthread_cond_wait(&(pool->sync_notify), &(pool->sync_lock));
}
pthread_mutex_unlock(&(pool->sync_lock));
}
#endif
//<<PAD(DEG_MAIN)>>//
int main (int argc, char *argv[])
{
//Mobility *mobility_frame_10;
//Application_Config *application_frame_20;
//Here make modifications on the mobility and traffic new models
//mob_frame_10 -> ...
//application_frame_30 -> ...
//schedule(ET_OMG, 10, NULL, mobility_frame_10);
//schedule(ET_OTG, 15, NULL, application_frame_20);
//event_list_display(&event_list);
schedule_end_of_simulation(FRAME, 100);
run(argc, argv);
return 0;
}
//<<PAD>>//
//<<PAD(RUN)>>//
void run(int argc, char *argv[])
{
int32_t i;
module_id_t UE_id, eNB_id;
Job_elt *job_elt;
int ret;
clock_t t;
Event_elt *user_defined_event;
Event event;
// Framing variables
int32_t slot, last_slot, next_slot;
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
double snr_direction,snr_step=1.0;//,sinr_direction;
lte_subframe_t direction;
char fname[64],vname[64];
#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
FD_lte_phy_scope_ue *form_ue[NUMBER_OF_UE_MAX];
FD_lte_phy_scope_enb *form_enb[NUMBER_OF_UE_MAX];
char title[255];
#endif
#ifdef PROC
int node_id;
int port,Process_Flag=0,wgt,Channel_Flag=0,temp;
#endif
// uint8_t awgn_flag = 0;
#ifdef PRINT_STATS
int len;
FILE *UE_stats[NUMBER_OF_UE_MAX], *UE_stats_th[NUMBER_OF_UE_MAX], *eNB_stats, *eNB_avg_thr, *eNB_l2_stats;
char UE_stats_filename[255];
char UE_stats_th_filename[255];
char eNB_stats_th_filename[255];
#endif
#ifdef SMBV
uint8_t config_smbv = 0;
char smbv_ip[16];
strcpy(smbv_ip,DEFAULT_SMBV_IP);
#endif
#ifdef OPENAIR2
Data_Flow_Unit omv_data;
#endif
//time_t t0,t1;
//clock_t start, stop;
//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
//{
/* INITIALIZATIONS */
target_dl_mcs = 0;
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
//Default values if not changed by the user in get_simulation_options();
pdcp_period = 1;
omg_period = 10;
mRAL_init_default_values(); //Default values
eRAL_init_default_values(); //Default values
init_oai_emulation(); //Default values
get_simulation_options(argc, argv); //Command-line options
oaisim_config(); // config OMG and OCG, OPT, OTG, OLG
//To fix eventual conflict on the value of n_frames
if (oai_emulation.info.n_frames_flag) {
schedule_end_of_simulation(FRAME, oai_emulation.info.n_frames);
}
VCD_SIGNAL_DUMPER_INIT(); // Initialize VCD LOG module
#ifdef OPENAIR2
init_omv();
#endif
check_and_adjust_params(); //Before this call, NB_UE_INST and NB_eNB_INST are not set correctly
init_otg_pdcp_buffer();
#ifdef PRINT_STATS
for (UE_id=0; UE_id<NB_UE_INST; UE_id++) {
sprintf(UE_stats_filename,"UE_stats%d.txt",UE_id);
UE_stats[UE_id] = fopen (UE_stats_filename, "w");
}
eNB_stats = fopen ("eNB_stats.txt", "w");
printf ("UE_stats=%p, eNB_stats=%p\n", UE_stats, eNB_stats);
eNB_avg_thr = fopen ("eNB_stats_th.txt", "w");
#endif
LOG_I(EMU,"total number of UE %d (local %d, remote %d) mobility %s \n", NB_UE_INST,oai_emulation.info.nb_ue_local,oai_emulation.info.nb_ue_remote,
oai_emulation.topology_config.mobility.eNB_mobility.eNB_mobility_type.selected_option);
LOG_I(EMU,"Total number of eNB %d (local %d, remote %d) mobility %s \n", NB_eNB_INST,oai_emulation.info.nb_enb_local,oai_emulation.info.nb_enb_remote,
oai_emulation.topology_config.mobility.UE_mobility.UE_mobility_type.selected_option);
LOG_I(OCM,"Running with frame_type %d, 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, Nid_cell, oai_emulation.info.N_RB_DL, oai_emulation.info.extended_prefix_flag, oai_emulation.info.transmission_mode,target_dl_mcs,rate_adaptation_flag,
oai_emulation.info.n_frames,abstraction_flag,oai_emulation.environment_system_config.fading.small_scale.selected_option);
init_seed(set_seed);
init_openair1();
init_openair2();
init_ocm();
#ifdef XFORMS
init_xforms();
#endif
printf ("before L2 init: Nid_cell %d\n", PHY_vars_eNB_g[0]->lte_frame_parms.Nid_cell);
printf ("before L2 init: frame_type %d,tdd_config %d\n",
PHY_vars_eNB_g[0]->lte_frame_parms.frame_type,
PHY_vars_eNB_g[0]->lte_frame_parms.tdd_config);
init_time();
#ifdef PAD
pad_init();
#endif
if (ue_connection_test == 1) {
snr_direction = -snr_step;
snr_dB=20;
sinr_dB=-20;
}
frame = 0;
slot = 0;
LOG_I(EMU,">>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU initialization done <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
printf ("after init: Nid_cell %d\n", PHY_vars_eNB_g[0]->lte_frame_parms.Nid_cell);
printf ("after init: frame_type %d,tdd_config %d\n",
PHY_vars_eNB_g[0]->lte_frame_parms.frame_type,
PHY_vars_eNB_g[0]->lte_frame_parms.tdd_config);
t = clock();
while (!end_of_simulation()) {
last_slot = (slot - 1)%20;
if (last_slot <0)
last_slot+=20;
next_slot = (slot + 1)%20;
oai_emulation.info.time_ms = frame * 10 + (next_slot>>1);
oai_emulation.info.frame = frame;
if (slot == 0) { //Frame's Prologue
//Run the aperiodic user-defined events
while ((user_defined_event = event_list_get_head(&event_list)) != NULL) {
event = user_defined_event->event;
if (event.frame == frame) {
switch (event.type) {
case ET_OMG:
update_omg_model(event.key, event.value); //implement it with assigning the new values to that of oai_emulation & second thing is to ensure mob model is always read from oai_emulation
user_defined_event = event_list_remove_head(&event_list);
break;
case ET_OTG:
update_otg_model(event.key, event.value);
user_defined_event = event_list_remove_head(&event_list);
break;
}
} else {
break;
}
}
//Comment (handle cooperation flag) deleted here. Look at oaisim.c to see it
if (ue_connection_test==1) {
if ((frame%20) == 0) {
snr_dB += snr_direction;
sinr_dB -= snr_direction;
}
if (snr_dB == -20) {
snr_direction=snr_step;
} else if (snr_dB==20) {
snr_direction=-snr_step;
}
}
update_omg(); // frequency is defined in the omg_global params configurable by the user
update_omg_ocm();
#ifdef OPENAIR2
// 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);
}
#endif
#ifdef DEBUG_OMG
if ((((int) oai_emulation.info.time_s) % 100) == 0) {
for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++) {
get_node_position (UE, UE_id);
}
}
#endif
update_ocm();
}
direction = subframe_select(frame_parms,next_slot>>1);
if((next_slot %2) ==0)
clear_eNB_transport_info(oai_emulation.info.nb_enb_local);
for (eNB_id=oai_emulation.info.first_enb_local;
(eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local)) && (oai_emulation.info.cli_start_enb[eNB_id]==1);
eNB_id++) {
for_main_times += 1;
//printf ("debug: Nid_cell %d\n", PHY_vars_eNB_g[eNB_id]->lte_frame_parms.Nid_cell);
//printf ("debug: frame_type %d,tdd_config %d\n", PHY_vars_eNB_g[eNB_id]->lte_frame_parms.frame_type,PHY_vars_eNB_g[eNB_id]->lte_frame_parms.tdd_config);
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_id, frame, slot, next_slot >> 1,last_slot>>1,
PHY_vars_eNB_g[eNB_id]->lte_frame_parms.frame_type,
PHY_vars_eNB_g[eNB_id]->lte_frame_parms.tdd_config,PHY_vars_eNB_g[eNB_id]->lte_frame_parms.Nid_cell);
//Appliation
#ifdef PAD_FINE
pad_inject_job(1, eNB_id, frame, next_slot, last_slot, JT_OTG, oai_emulation.info.time_ms);
#else
update_otg_eNB(eNB_id, oai_emulation.info.time_ms);
#endif
//Access layer
if (frame % pdcp_period == 0) {
#ifdef PAD_FINE
pad_inject_job(1, eNB_id, frame, next_slot, last_slot, JT_PDCP, oai_emulation.info.time_ms);
#else
pdcp_run(frame, 1, 0, eNB_id);//PHY_vars_eNB_g[eNB_id]->Mod_id
#endif
}
//Phy/Mac layer
#ifdef PAD_FINE
pad_inject_job(1, eNB_id, frame, next_slot, last_slot, JT_PHY_MAC, oai_emulation.info.time_ms);
#else
phy_procedures_eNB_lte (last_slot, next_slot, PHY_vars_eNB_g[eNB_id], abstraction_flag, no_relay, NULL);
#endif
#ifdef PRINT_STATS
if(last_slot==9 && frame%10==0)
if(eNB_avg_thr)
fprintf(eNB_avg_thr,"%d %d\n",PHY_vars_eNB_g[eNB_id]->frame,(PHY_vars_eNB_g[eNB_id]->total_system_throughput)/((PHY_vars_eNB_g[eNB_id]->frame+1)*10));
if (eNB_stats) {
len = dump_eNB_stats(PHY_vars_eNB_g[eNB_id], stats_buffer, 0);
rewind (eNB_stats);
fwrite (stats_buffer, 1, len, eNB_stats);
fflush(eNB_stats);
}
#ifdef OPENAIR2
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);
}
#endif
#endif
}
#ifdef PAD_SYNC
if ((direction == SF_DL) || ((direction == SF_S) && (next_slot%2==0)) )
pad_synchronize();
#endif
// Call ETHERNET emulation here
//emu_transport (frame, last_slot, next_slot, direction, oai_emulation.info.frame_type, ethernet_flag);
if ((next_slot % 2) == 0)
clear_UE_transport_info (oai_emulation.info.nb_ue_local);
for (UE_id = oai_emulation.info.first_ue_local;
(UE_id < (oai_emulation.info.first_ue_local+oai_emulation.info.nb_ue_local)) && (oai_emulation.info.cli_start_ue[UE_id]==1);
UE_id++)
if (frame >= (UE_id * 20)) { // activate UE only after 20*UE_id frames so that different UEs turn on separately
LOG_D(EMU,"PHY procedures UE %d for frame %d, slot %d (subframe TX %d, RX %d)\n",
UE_id, frame, slot, next_slot >> 1,last_slot>>1);
if (PHY_vars_UE_g[UE_id]->UE_mode[0] != NOT_SYNCHED) {
if (frame>0) {
PHY_vars_UE_g[UE_id]->frame = frame;
//Application UE
#ifdef PAD_FINE
pad_inject_job(0, UE_id, frame, next_slot, last_slot, JT_OTG, oai_emulation.info.time_ms);
#else
update_otg_UE(UE_id + NB_eNB_INST, oai_emulation.info.time_ms);
#endif
//Access layer UE
if (frame % pdcp_period == 0) {
#ifdef PAD_FINE
pad_inject_job(0, UE_id, frame, next_slot, last_slot, JT_PDCP, oai_emulation.info.time_ms);
#else
pdcp_run(frame, 0, UE_id, 0);
#endif
}
//Phy/Mac layer UE
#ifdef PAD_FINE
pad_inject_job(0, UE_id, frame, next_slot, last_slot, JT_PHY_MAC, oai_emulation.info.time_ms);
#else
phy_procedures_UE_lte (last_slot, next_slot, PHY_vars_UE_g[UE_id], 0, abstraction_flag, normal_txrx, no_relay, NULL);
ue_data[UE_id]->tx_power_dBm = PHY_vars_UE_g[UE_id]->tx_power_dBm;
#endif
}
} else {
if (abstraction_flag==1) {
LOG_E(EMU, "sync not supported in abstraction mode (UE%d,mode%d)\n", UE_id, PHY_vars_UE_g[UE_id]->UE_mode[0]);
exit(-1);
}
if ((frame>0) && (last_slot == (LTE_SLOTS_PER_FRAME-2))) {
#ifdef PAD_FINE
pad_inject_job(0, UE_id, frame, next_slot, last_slot, JT_INIT_SYNC, oai_emulation.info.time_ms);
#else
initial_sync(PHY_vars_UE_g[UE_id],normal_txrx);
#endif
/* LONG write output comment DELETED here */
}
}
#ifdef PRINT_STATS
if(last_slot==2 && frame%10==0)
if (UE_stats_th[UE_id])
fprintf(UE_stats_th[UE_id],"%d %d\n",frame, PHY_vars_UE_g[UE_id]->bitrate[0]/1000);
if (UE_stats[UE_id]) {
len = dump_ue_stats (PHY_vars_UE_g[UE_id], stats_buffer, 0, normal_txrx, 0);
rewind (UE_stats[UE_id]);
fwrite (stats_buffer, 1, len, UE_stats[UE_id]);
fflush(UE_stats[UE_id]);
}
#endif
}
#ifdef PAD_SYNC
if ((direction == SF_UL) || ((direction == SF_S) && (next_slot%2==1)) )
pad_synchronize();
#endif
emu_transport (frame, last_slot, next_slot,direction, oai_emulation.info.frame_type, ethernet_flag);
if ((direction == SF_DL)|| (frame_parms->frame_type==0)) {
for (UE_id=0; UE_id<NB_UE_INST; UE_id++) {
#ifdef PAD
pad_inject_job(0, UE_id, frame, next_slot, last_slot, JT_DL, oai_emulation.info.time_ms);
#else
do_DL_sig(r_re0,r_im0,r_re,r_im,s_re,s_im,eNB2UE,enb_data,ue_data,next_slot,abstraction_flag,frame_parms,UE_id);
#endif
}
}
if ((direction == SF_UL)|| (frame_parms->frame_type==0)) { //if ((subframe<2) || (subframe>4))
do_UL_sig(r_re0,r_im0,r_re,r_im,s_re,s_im,UE2eNB,enb_data,ue_data,next_slot,abstraction_flag,frame_parms,frame);
/*
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 (UE_id=0; UE_id<NB_UE_INST; UE_id++) {
#ifdef PAD
pad_inject_job(0, UE_id, frame, next_slot, last_slot, JT_DL, oai_emulation.info.time_ms);
#else
do_DL_sig(r_re0,r_im0,r_re,r_im,s_re,s_im,eNB2UE,enb_data,ue_data,next_slot,abstraction_flag,frame_parms,UE_id);
#endif
}
/*
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
/*#ifdef PAD
pthread_mutex_lock(&(pool->sync_lock));
while(pool->active != 0) {
pthread_cond_wait(&(pool->sync_notify), &(pool->sync_lock));
}
pthread_mutex_unlock(&(pool->sync_lock));
#endif*/
do_UL_sig(r_re0,r_im0,r_re,r_im,s_re,s_im,UE2eNB,enb_data,ue_data,next_slot,abstraction_flag,frame_parms,frame);
/*
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)) {
LOG_M ("dlchan0.m", "dlch0",
&(PHY_vars_UE_g[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[0][0][0]),
(6 * (PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)), 1, 1);
LOG_M ("dlchan1.m", "dlch1",
&(PHY_vars_UE_g[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[1][0][0]),
(6 * (PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)), 1, 1);
LOG_M ("dlchan2.m", "dlch2",
&(PHY_vars_UE_g[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[2][0][0]),
(6 * (PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)), 1, 1);
LOG_M ("pbch_rxF_comp0.m", "pbch_comp0",
PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->rxdataF_comp[0], 6 * 12 * 4, 1, 1);
LOG_M ("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);
}
if (next_slot %2 == 0) {
clock_gettime (CLOCK_REALTIME, &time_spec);
time_last = time_now;
time_now = (unsigned long) time_spec.tv_nsec;
td = (int) (time_now - time_last);
if (td>0) {
td_avg = (int)(((K*(long)td) + (((1<<3)-K)*((long)td_avg)))>>3); // in us
LOG_T(EMU,"sleep frame %d, time_now %ldus,time_last %ldus,average time difference %ldns, CURRENT TIME DIFF %dus, avgerage difference from the target %dus\n",
frame, time_now,time_last,td_avg, td/1000,(td_avg-TARGET_SF_TIME_NS)/1000);
}
if (td_avg<(TARGET_SF_TIME_NS - SF_DEVIATION_OFFSET_NS)) {
sleep_time_us += SLEEP_STEP_US;
LOG_D(EMU,"Faster than realtime increase the avg sleep time for %d us, frame %d\n",
sleep_time_us,frame);
// LOG_D(EMU,"Faster than realtime increase the avg sleep time for %d us, frame %d, time_now %ldus,time_last %ldus,average time difference %ldns, CURRENT TIME DIFF %dus, avgerage difference from the target %dus\n", sleep_time_us,frame, time_now,time_last,td_avg, td/1000,(td_avg-TARGET_SF_TIME_NS)/1000);
} else if (td_avg > (TARGET_SF_TIME_NS + SF_DEVIATION_OFFSET_NS)) {
sleep_time_us-= SLEEP_STEP_US;
LOG_D(EMU,"Slower than realtime reduce the avg sleep time for %d us, frame %d, time_now\n",
sleep_time_us,frame);
//LOG_T(EMU,"Slower than realtime reduce the avg sleep time for %d us, frame %d, time_now %ldus,time_last %ldus,average time difference %ldns, CURRENT TIME DIFF %dus, avgerage difference from the target %dus\n", sleep_time_us,frame, time_now,time_last,td_avg, td/1000,(td_avg-TARGET_SF_TIME_NS)/1000);
}
} // end if next_slot%2
slot++;
if (slot == 20) { //Frame's Epilogue
frame++;
slot = 0;
// 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);
}
oai_emulation.info.time_s += 0.01;
if ((frame>=1)&&(frame<=9)&&(abstraction_flag==0)) {
LOG_M("UEtxsig0.m","txs0", PHY_vars_UE_g[0]->lte_ue_common_vars.txdata[0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
sprintf(fname,"eNBtxsig%d.m",frame);
sprintf(vname,"txs%d",frame);
LOG_M(fname,vname, PHY_vars_eNB_g[0]->lte_eNB_common_vars.txdata[0][0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
LOG_M("eNBtxsigF0.m","txsF0",PHY_vars_eNB_g[0]->lte_eNB_common_vars.txdataF[0][0],PHY_vars_eNB_g[0]->lte_frame_parms.symbols_per_tti*PHY_vars_eNB_g[0]->lte_frame_parms.ofdm_symbol_size,1,1);
LOG_M("UErxsig0.m","rxs0", PHY_vars_UE_g[0]->lte_ue_common_vars.rxdata[0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
LOG_M("eNBrxsig0.m","rxs0", PHY_vars_eNB_g[0]->lte_eNB_common_vars.rxdata[0][0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
}
#ifdef XFORMS
do_xforms();
#endif
// calibrate at the end of each frame if there is some time left
if((sleep_time_us > 0)&& (ethernet_flag ==0)) {
LOG_I(EMU,"[TIMING] Adjust average frame duration, sleep for %d us\n",sleep_time_us);
usleep(sleep_time_us);
sleep_time_us=0; // reset the timer, could be done per n SF
}
#ifdef SMBV
if ((frame == config_frames[0]) || (frame == config_frames[1]) || (frame == config_frames[2]) || (frame == config_frames[3])) {
smbv_frame_cnt++;
}
#endif
}
}
t = clock() - t;
printf("rrc Duration of the simulation: %f seconds\n",((float)t)/CLOCKS_PER_SEC);
fclose(SINRpost);
LOG_I(EMU,">>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU Ending <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
free(otg_pdcp_buffer);
#ifdef SMBV
if (config_smbv) {
smbv_send_config (smbv_fname,smbv_ip);
}
#endif
//Perform KPI measurements
if (oai_emulation.info.otg_enabled==1)
kpi_gen();
#ifdef PAD
pad_finalize();
#endif
// relase all rx state
if (ethernet_flag == 1) {
emu_transport_release ();
}
if (abstraction_flag == 0) {
/*
#ifdef IFFT_FPGA
free(txdataF2[0]);
free(txdataF2[1]);
free(txdataF2);
free(txdata[0]);
free(txdata[1]);
free(txdata);
#endif
*/
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);
lte_sync_time_free ();
}
// pthread_join(sigth, NULL);
// added for PHY abstraction
if (oai_emulation.info.ocm_enabled == 1) {
for (eNB_id = 0; eNB_id < NUMBER_OF_eNB_MAX; eNB_id++)
free(enb_data[eNB_id]);
for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++)
free(ue_data[UE_id]);
} //End of PHY abstraction changes
#ifdef OPENAIR2
mac_top_cleanup();
#endif
#ifdef PRINT_STATS
for(UE_id=0; UE_id<NB_UE_INST; UE_id++) {
if (UE_stats[UE_id])
fclose (UE_stats[UE_id]);
if(UE_stats_th[UE_id])
fclose (UE_stats_th[UE_id]);
}
if (eNB_stats)
fclose (eNB_stats);
if (eNB_avg_thr)
fclose (eNB_avg_thr);
if (eNB_l2_stats)
fclose (eNB_l2_stats);
#endif
// stop OMG
stop_mobility_generator(oai_emulation.info.omg_model_ue);//omg_param_list.mobility_type
#ifdef OPENAIR2
if (oai_emulation.info.omv_enabled == 1)
omv_end(pfd[1],omv_data);
#endif
if ((oai_emulation.info.ocm_enabled == 1) && (ethernet_flag == 0) && (ShaF != NULL))
destroyMat(ShaF,map1, map2);
if (opt_enabled == 1 )
terminate_opt();
if (oai_emulation.info.cli_enabled)
cli_server_cleanup();
//bring oai if down
terminate();
logClean();
VCD_SIGNAL_DUMPER_CLOSE();
//printf("FOR MAIN TIMES = %d &&&& OTG TIMES = %d <-> FOR TIMES = %d <-> IF TIMES = %d\n", for_main_times, otg_times, for_times, if_times);
}
//<<PAD>>//
void terminate(void)
{
int i;
char interfaceName[8];
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);
}
}
#ifdef OPENAIR2
int omv_write (int pfd, Node_list enb_node_list, Node_list ue_node_list, Data_Flow_Unit omv_data)
{
int i,j;
omv_data.end=0;
//omv_data.total_num_nodes = NB_UE_INST + NB_eNB_INST;
for (i=0; i<NB_eNB_INST; i++) {
if (enb_node_list != NULL) {
omv_data.geo[i].x = (enb_node_list->node->X_pos < 0.0)? 0.0 : enb_node_list->node->X_pos;
omv_data.geo[i].y = (enb_node_list->node->Y_pos < 0.0)? 0.0 : enb_node_list->node->Y_pos;
omv_data.geo[i].z = 1.0;
omv_data.geo[i].mobility_type = oai_emulation.info.omg_model_enb;
omv_data.geo[i].node_type = 0; //eNB
enb_node_list = enb_node_list->next;
omv_data.geo[i].Neighbors=0;
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);
}
}
}
}
for (i=NB_eNB_INST; i<NB_UE_INST+NB_eNB_INST; i++) {
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;
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);
}
}
}
}
if( write( pfd, &omv_data, sizeof(struct Data_Flow_Unit) ) == -1 )
perror( "write omv failed" );
return 1;
}
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" );
}
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment