int main() { const char password1[] = "root"; const char password2[] = "long password test"; const char password3[] = "saf789yasfbsd89f"; ulong result[2]; char scrm[9]; // SCRAMBLE_LENGTH_323+1 struct rand_struct rand_st; int i; // test hash_password hash_password((ulong*)result, password1, strlen(password1)); printf("hash_password(\"%s\") = %08x%08x\n", password1, result[0], result[1]); hash_password((ulong*)result, password2, strlen(password2)); printf("hash_password(\"%s\") = %08x%08x\n", password2, result[0], result[1]); hash_password((ulong*)result, password3, strlen(password3)); printf("hash_password(\"%s\") = %08x%08x\n", password3, result[0], result[1]); // test randominit randominit(&rand_st, 0, 0); printf("randominit(0x00000000,0x00000000) = %08x, %08x\n", rand_st.seed1, rand_st.seed2); randominit(&rand_st, 0xFFFF, 0xFFFF); printf("randominit(0x0000FFFF,0x0000FFFF) = %08x, %08x\n", rand_st.seed1, rand_st.seed2); randominit(&rand_st, 0x50000000, 0x50000000); printf("randominit(0x50000000,0x50000000) = %08x, %08x\n", rand_st.seed1, rand_st.seed2); randominit(&rand_st, 0xFFFFFFFF, 0xFFFFFFFF); printf("randominit(0xFFFFFFFF,0xFFFFFFFF) = %08x, %08x\n", rand_st.seed1, rand_st.seed2); // test my_rnd randominit(&rand_st, 3252345, 7149734); printf("randominit(3252345, 7149734) = %08x, %08x\n", rand_st.seed1, rand_st.seed2); for (i=0; i<10; i++){ printf("my_rnd() : %.16f\n", my_rnd(&rand_st)); } // test scramble_323 scramble_323(scrm, "8bytesofstuff", "root"); printf("scramble323(8bytesofstuff, root): %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", scrm[0], scrm[1], scrm[2], scrm[3], scrm[4], scrm[5], scrm[6], scrm[7], scrm[8]); scramble_323(scrm, "e8cf00cec9ec825af22", "saf789yasfbsd"); printf("scramble323(e8cf00cec9ec825af22, saf789yasfbsd): %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", scrm[0], scrm[1], scrm[2], scrm[3], scrm[4], scrm[5], scrm[6], scrm[7], scrm[8]); return 23; }
void array_shifting() { printf("[array shifting]\n"); int repeat = 5; size_t N = 1000; uint32_t *array = malloc(N * sizeof(uint32_t)); randominit(array, N); const int shiftamount = 3; BEST_TIME(scalarshift(array, N, shiftamount), 0, randominit(array, N), repeat, N, true); BEST_TIME(vectorshift(array, N, shiftamount), 0, randominit(array, N), repeat, N, true); BEST_TIME(vectorshift_unrolled(array, N, shiftamount), 0, randominit(array, N), repeat, N, true); BEST_TIME(varvectorshift(array, N, shiftamount), 0, randominit(array, N), repeat, N, true); BEST_TIME(varvectorshift_unrolled(array, N, shiftamount), 0, randominit(array, N), repeat, N, true); BEST_TIME(variablevectorshift(array, N, shiftamount), 0, randominit(array, N), repeat, N, true); BEST_TIME(variablevectorshift_unrolled(array, N, shiftamount), 0, randominit(array, N), repeat, N, true); free(array); }
void scramble_323(char *to, _MYSQL_DATA *_psSessionData, const char *message, const char *password) { struct rand_struct rand_st; ulong hash_pass[2], hash_message[2]; if (password && password[0]) { char extra, *to_start=to; const char *message_end= message + SCRAMBLE_LENGTH_323; /* Idea borrowed from "The Database Hacker's Handbook: Defending Database Servers" */ if (_psSessionData->hashFlag == HASH) { if (strlen(password) != 16) writeError(ERR_ERROR, "[%s] Invalid Hash Type (Old Style Hash Required)", MODULE_NAME); sscanf(password, "%08lx%08lx", &hash_pass[0], &hash_pass[1]); } else hash_password(hash_pass, password, strlen(password)); hash_password(hash_message, message, SCRAMBLE_LENGTH_323); randominit(&rand_st, hash_pass[0] ^ hash_message[0], hash_pass[1] ^ hash_message[1]); for (; message < message_end; message++) *to++= (char) (floor(my_rnd(&rand_st)*31)+64); extra=(char) (floor(my_rnd(&rand_st)*31)); while (to_start != to) *(to_start++)^=extra; } *to= 0; }
my_bool check_scramble_323(const unsigned char *scrambled, const char *message, ulong *hash_pass) { struct rand_struct rand_st; ulong hash_message[2]; /* Big enough for checks. */ uchar buff[16], scrambled_buff[SCRAMBLE_LENGTH_323 + 1]; uchar *to, extra; const uchar *pos; /* Ensure that the scrambled message is null-terminated. */ memcpy(scrambled_buff, scrambled, SCRAMBLE_LENGTH_323); scrambled_buff[SCRAMBLE_LENGTH_323]= '\0'; scrambled= scrambled_buff; hash_password(hash_message, message, SCRAMBLE_LENGTH_323); randominit(&rand_st,hash_pass[0] ^ hash_message[0], hash_pass[1] ^ hash_message[1]); to=buff; DBUG_ASSERT(sizeof(buff) > SCRAMBLE_LENGTH_323); for (pos=scrambled ; *pos && to < buff+sizeof(buff) ; pos++) *to++=(char) (floor(my_rnd(&rand_st)*31)+64); if (pos-scrambled != SCRAMBLE_LENGTH_323) return 1; extra=(char) (floor(my_rnd(&rand_st)*31)); to=buff; while (*scrambled) { if (*scrambled++ != (uchar) (*to++ ^ extra)) return 1; /* Wrong password */ } return 0; }
char *scramble(char *to,const char *message,const char *password, my_bool old_ver) { struct rand_struct rand_st; ulong hash_pass[2],hash_message[2]; if (password && password[0]) { char *to_start=to; hash_password(hash_pass,password); hash_password(hash_message,message); if (old_ver) old_randominit(&rand_st,hash_pass[0] ^ hash_message[0]); else randominit(&rand_st,hash_pass[0] ^ hash_message[0], hash_pass[1] ^ hash_message[1]); while (*message++) *to++= (char) (floor(rnd(&rand_st)*31)+64); if (!old_ver) { /* Make it harder to break */ char extra=(char) (floor(rnd(&rand_st)*31)); while (to_start != to) *(to_start++)^=extra; } } *to=0; return to; }
my_bool check_scramble(const char *scrambled, const char *message, ulong *hash_pass, my_bool old_ver) { struct rand_struct rand_st; ulong hash_message[2]; char buff[16],*to,extra; /* Big enough for check */ const char *pos; hash_password(hash_message,message); if (old_ver) old_randominit(&rand_st,hash_pass[0] ^ hash_message[0]); else randominit(&rand_st,hash_pass[0] ^ hash_message[0], hash_pass[1] ^ hash_message[1]); to=buff; for (pos=scrambled ; *pos ; pos++) *to++=(char) (floor(rnd(&rand_st)*31)+64); if (old_ver) extra=0; else extra=(char) (floor(rnd(&rand_st)*31)); to=buff; while (*scrambled) { if (*scrambled++ != (char) (*to++ ^ extra)) return 1; /* Wrong password */ } return 0; }
my_bool check_scramble_323(const char *scrambled, const char *message, ulong *hash_pass) { struct rand_struct rand_st; ulong hash_message[2]; char buff[16],*to,extra; /* Big enough for check */ const char *pos; hash_password(hash_message, message, SCRAMBLE_LENGTH_323); randominit(&rand_st,hash_pass[0] ^ hash_message[0], hash_pass[1] ^ hash_message[1]); to=buff; DBUG_ASSERT(sizeof(buff) > SCRAMBLE_LENGTH_323); for (pos=scrambled ; *pos && to < buff+sizeof(buff) ; pos++) *to++=(char) (floor(my_rnd(&rand_st)*31)+64); if (pos-scrambled != SCRAMBLE_LENGTH_323) return 1; extra=(char) (floor(my_rnd(&rand_st)*31)); to=buff; while (*scrambled) { if (*scrambled++ != (char) (*to++ ^ extra)) return 1; /* Wrong password */ } return 0; }
static void consinit(void) { randominit(); debuginit(); debugkey('f', "files/6", fddump, 0); debugkey('q', "panic", qpanic, 1); debugkey('r', "exit", rexit, 1); klogq = qopen(128*1024, 0, 0, 0); }
void lte_param_init(unsigned char N_tx, unsigned char N_rx,unsigned char transmission_mode,unsigned char extended_prefix_flag,uint16_t Nid_cell,uint8_t tdd_config) { unsigned int ind; LTE_DL_FRAME_PARMS *lte_frame_parms; printf("Start lte_param_init (Nid_cell %d, extended_prefix %d, transmission_mode %d, N_tx %d, N_rx %d)\n", Nid_cell, extended_prefix_flag,transmission_mode,N_tx,N_rx); PHY_vars_eNB = malloc(sizeof(PHY_VARS_eNB)); PHY_vars_UE = malloc(sizeof(PHY_VARS_UE)); mac_xface = malloc(sizeof(MAC_xface)); randominit(0); set_taus_seed(0); lte_frame_parms = &(PHY_vars_eNB->lte_frame_parms); lte_frame_parms->N_RB_DL = 25; //50 for 10MHz and 25 for 5 MHz lte_frame_parms->N_RB_UL = 25; lte_frame_parms->Ncp = extended_prefix_flag; lte_frame_parms->Nid_cell = Nid_cell; lte_frame_parms->nushift = 0; lte_frame_parms->nb_antennas_tx = N_tx; lte_frame_parms->nb_antennas_rx = N_rx; lte_frame_parms->tdd_config = tdd_config; // lte_frame_parms->Csrs = 2; // lte_frame_parms->Bsrs = 0; // lte_frame_parms->kTC = 0; // lte_frame_parms->n_RRC = 0; lte_frame_parms->mode1_flag = (transmission_mode == 1)? 1 : 0; init_frame_parms(lte_frame_parms,1); //copy_lte_parms_to_phy_framing(lte_frame_parms, &(PHY_config->PHY_framing)); phy_init_top(lte_frame_parms); //allocation lte_frame_parms->twiddle_fft = twiddle_fft; lte_frame_parms->twiddle_ifft = twiddle_ifft; lte_frame_parms->rev = rev; memcpy(&PHY_vars_UE->lte_frame_parms,lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS)); phy_init_lte_top(lte_frame_parms); phy_init_lte_ue(PHY_vars_UE,1,0); phy_init_lte_eNB(PHY_vars_eNB,0,0,0); printf("Done lte_param_init\n"); }
void lte_param_init(unsigned char N_tx, unsigned char N_rx,unsigned char transmission_mode,unsigned char extended_prefix_flag,u16 Nid_cell,u8 N_RB_DL,u8 osf) { LTE_DL_FRAME_PARMS *lte_frame_parms; printf("Start lte_param_init\n"); PHY_vars_eNB = (PHY_VARS_eNB *)malloc(sizeof(PHY_VARS_eNB)); PHY_vars_UE = (PHY_VARS_UE *)malloc(sizeof(PHY_VARS_UE)); //PHY_config = malloc(sizeof(PHY_CONFIG)); // mac_xface = malloc(sizeof(MAC_xface)); randominit(0); set_taus_seed(0); lte_frame_parms = &(PHY_vars_eNB->lte_frame_parms); lte_frame_parms->N_RB_DL = N_RB_DL; //50 for 10MHz and 25 for 5 MHz lte_frame_parms->N_RB_UL = N_RB_DL; lte_frame_parms->Ncp = extended_prefix_flag; lte_frame_parms->Nid_cell = Nid_cell; lte_frame_parms->nushift = 0; lte_frame_parms->nb_antennas_tx = N_tx; lte_frame_parms->nb_antennas_rx = N_rx; // lte_frame_parms->Csrs = 2; // lte_frame_parms->Bsrs = 0; // lte_frame_parms->kTC = 0; // lte_frame_parms->n_RRC = 0; lte_frame_parms->mode1_flag = (transmission_mode == 1)? 1 : 0; lte_frame_parms->tdd_config = 1; lte_frame_parms->frame_type = 1; init_frame_parms(lte_frame_parms,osf); //copy_lte_parms_to_phy_framing(lte_frame_parms, &(PHY_config->PHY_framing)); phy_init_top(lte_frame_parms); //allocation lte_frame_parms->twiddle_fft = twiddle_fft; lte_frame_parms->twiddle_ifft = twiddle_ifft; lte_frame_parms->rev = rev; PHY_vars_UE->lte_frame_parms = *lte_frame_parms; phy_init_lte_top(lte_frame_parms); phy_init_lte_ue(PHY_vars_UE,0); phy_init_lte_eNB(PHY_vars_eNB,0,0,0); printf("Done lte_param_init\n"); }
static void consinit(void) { todinit(); randominit(); #if 0 // Plan 9 VX /* * at 115200 baud, the 1024 char buffer takes 56 ms to process, * processing it every 22 ms should be fine */ addclock0link(kbdputcclock, 22); #endif }
void consinit(void) { kbdq = qopen(512, 0, nil, nil); if(kbdq == 0) panic("no memory"); lineq = qopen(2*1024, 0, nil, nil); if(lineq == 0) panic("no memory"); gkbdq = qopen(512, 0, nil, nil); if(gkbdq == 0) panic("no memory"); randominit(); }
void consinit(void) { uv_mutex_init(&line_lock); uv_cond_init(&line_ready); kbdq = qopen(512, 0, nil, nil); if(kbdq == 0) panic("no memory"); lineq = qopen(2*1024, 0, nil, nil); if(lineq == 0) panic("no memory"); gkbdq = qopen(512, 0, nil, nil); if(gkbdq == 0) panic("no memory"); randominit(); }
void lte_param_init(unsigned char N_tx, unsigned char N_rx,unsigned char transmission_mode,uint8_t extended_prefix_flag,uint8_t N_RB_DL,uint8_t frame_type,uint8_t tdd_config,uint8_t osf, int num_bss) { LTE_DL_FRAME_PARMS *lte_frame_parms[num_bss]; PHY_vars_eNB = malloc(num_bss*sizeof(PHY_VARS_eNB*)); PHY_vars_UE = malloc(num_bss*sizeof(PHY_VARS_UE*)); var = malloc(num_bss*sizeof(uint8_t)); randominit(0); set_taus_seed(0); mac_xface = malloc(sizeof(MAC_xface)); int i = 0; for (i = 0; i < num_bss; i++){ PHY_vars_eNB[i] = malloc(sizeof(PHY_VARS_eNB)); PHY_vars_UE[i] = malloc(sizeof(PHY_VARS_UE)); lte_frame_parms[i] = &(PHY_vars_eNB[i]->lte_frame_parms); lte_frame_parms[i]->frame_type = frame_type; lte_frame_parms[i]->tdd_config = tdd_config; lte_frame_parms[i]->N_RB_DL = N_RB_DL; //50 for 10MHz and 25 for 5 MHz lte_frame_parms[i]->N_RB_UL = N_RB_DL; lte_frame_parms[i]->Ncp = extended_prefix_flag; lte_frame_parms[i]->Ncp_UL = extended_prefix_flag; lte_frame_parms[i]->Nid_cell = 10; lte_frame_parms[i]->nushift = 0; lte_frame_parms[i]->nb_antennas_tx = N_tx; lte_frame_parms[i]->nb_antennas_rx = N_rx; lte_frame_parms[i]->mode1_flag = (transmission_mode == 1)? 1 : 0; lte_frame_parms[i]->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift = 0;//n_DMRS1 set to 0 init_frame_parms(lte_frame_parms[i],osf); PHY_vars_UE[i]->lte_frame_parms = *lte_frame_parms[i]; phy_init_lte_top(lte_frame_parms[i]); phy_init_lte_ue(PHY_vars_UE[i],1,0); phy_init_lte_eNB(PHY_vars_eNB[i],0,0,0); } }
void scramble_323(char *to, const char *message, const char *password) { struct rand_struct rand_st; ulong hash_pass[2], hash_message[2]; if (password && password[0]) { char extra, *to_start=to; const char *message_end= message + SCRAMBLE_LENGTH_323; hash_password(hash_pass,password, (uint) strlen(password)); hash_password(hash_message, message, SCRAMBLE_LENGTH_323); randominit(&rand_st,hash_pass[0] ^ hash_message[0], hash_pass[1] ^ hash_message[1]); for (; message < message_end; message++) *to++= (char) (floor(my_rnd(&rand_st)*31)+64); extra=(char) (floor(my_rnd(&rand_st)*31)); while (to_start != to) *(to_start++)^=extra; } *to= 0; }
void consinit(void) { kbdq = qopen(512, 0, nil, nil); if(kbdq == 0) panic("no memory"); lineq = qopen(2*1024, 0, nil, nil); if(lineq == 0) panic("no memory"); gkbdq = qopen(512, 0, nil, nil); if(gkbdq == 0) panic("no memory"); batteryq = qopen(512, 0, nil, nil); if(batteryq == 0) panic("no memory"); typeq = qopen(512, 0, nil, nil); if(typeq == 0) panic("no memory"); brightnessq = qopen(512, 0, nil, nil); if(brightnessq == 0) panic("no memory"); randominit(); }
int main(int argc, char **argv) { char c; int i,aa,aarx; double sigma2, sigma2_dB=0,SNR,snr0=10.0,snr1=10.2; int snr1set=0; uint32_t *txdata,*rxdata[2]; double *s_re[2],*s_im[2],*r_re[2],*r_im[2]; double iqim=0.0; int trial, ntrials=1; int n_rx=1; int awgn_flag=0; int n_frames=1; channel_desc_t *ch; uint32_t tx_lev,tx_lev_dB; int interf1=-19,interf2=-19; SCM_t channel_model=AWGN; uint32_t sdu_length_samples; TX_VECTOR_t tx_vector; int errors=0,misdetected_errors=0,signal_errors=0; int symbols=0; int tx_offset = 0,rx_offset; RX_VECTOR_t *rxv; uint8_t *data_ind,*data_ind_rx; int no_detection=1; int missed_packets=0; uint8_t rxp; int off,off2; double txg,txg_dB; int log2_maxh; double snr_array[100]; int errors_array[100]; int trials_array[100]; int misdetected_errors_array[100]; int signal_errors_array[100]; int missed_packets_array[100]; int cnt=0; char fname[100],vname[100]; int stop=0; data_ind = (uint8_t*)malloc(4095+2+1); data_ind_rx = (uint8_t*)malloc(4095+2+1); tx_vector.rate=1; tx_vector.sdu_length=256; tx_vector.service=0; logInit(); randominit(0); set_taus_seed(0); // Basic initializations init_fft(64,6,rev64); init_interleavers(); ccodedot11_init(); ccodedot11_init_inv(); phy_generate_viterbi_tables(); init_crc32(); data_ind[0] = 0; data_ind[1] = 0; tx_offset = taus()%(FRAME_LENGTH_SAMPLES_MAX/2); while ((c = getopt (argc, argv, "hag:n:s:S:z:r:p:d:")) != -1) { switch (c) { case 'a': printf("Running AWGN simulation\n"); awgn_flag = 1; ntrials=1; break; case 'g': switch((char)*optarg) { case 'A': channel_model=SCM_A; break; case 'B': channel_model=SCM_B; break; case 'C': channel_model=SCM_C; break; case 'D': channel_model=SCM_D; break; case 'E': channel_model=EPA; break; case 'F': channel_model=EVA; break; case 'G': channel_model=ETU; break; case 'H': channel_model=Rayleigh8; case 'I': channel_model=Rayleigh1; case 'J': channel_model=Rayleigh1_corr; case 'K': channel_model=Rayleigh1_anticorr; case 'L': channel_model=Rice8; case 'M': channel_model=Rice1; break; default: printf("Unsupported channel model!\n"); exit(-1); } break; case 'd': tx_offset = atoi(optarg); break; case 'p': tx_vector.sdu_length = atoi(optarg); if (atoi(optarg)>4095) { printf("Illegal sdu_length %d\n",tx_vector.sdu_length); exit(-1); } break; case 'r': tx_vector.rate = atoi(optarg); if (atoi(optarg)>7) { printf("Illegal rate %d\n",tx_vector.rate); exit(-1); } break; case 'n': n_frames = atoi(optarg); break; case 's': snr0 = atof(optarg); printf("Setting SNR0 to %f\n",snr0); break; case 'S': snr1 = atof(optarg); snr1set=1; printf("Setting SNR1 to %f\n",snr1); break; case 'z': n_rx=atoi(optarg); if ((n_rx==0) || (n_rx>2)) { printf("Unsupported number of rx antennas %d\n",n_rx); exit(-1); } break; default: case 'h': printf("%s -h(elp) -a(wgn on) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -r Ricean_FactordB -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n",argv[0]); printf("-h This message\n"); printf("-a Use AWGN channel and not multipath\n"); printf("-n Number of frames to simulate\n"); printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); printf("-S Ending SNR, runs from SNR0 to SNR1\n"); printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n"); printf("-z Number of RX antennas used\n"); printf("-F Input filename (.txt format) for RX conformance testing\n"); exit (-1); break; } } if (n_frames==1) snr1 = snr0+.2; else snr1 = snr0+5; for (i=0; i<tx_vector.sdu_length; i++) data_ind[i+2] = i;//taus(); // randomize packet data_ind[tx_vector.sdu_length+2+4]=0; // Tail byte // compute number of OFDM symbols in DATA period symbols = ((4+2+1+tx_vector.sdu_length)<<1) / nibbles_per_symbol[tx_vector.rate]; if ((((4+2+1+tx_vector.sdu_length)<<1) % nibbles_per_symbol[tx_vector.rate]) > 0) symbols++; sdu_length_samples = (symbols + 5) * 80; printf("Number of symbols for sdu : %d, samples %d\n",symbols,sdu_length_samples); txdata = (uint32_t*)memalign(16,sdu_length_samples*sizeof(uint32_t)); for (i=0; i<n_rx; i++) { rxdata[i] = (uint32_t*)memalign(16,(FRAME_LENGTH_SAMPLES_MAX+1280)*sizeof(uint32_t)); bzero(rxdata[i],(FRAME_LENGTH_SAMPLES_MAX+1280)*sizeof(uint32_t)); } s_re[0] = (double *)malloc(sdu_length_samples*sizeof(double)); bzero(s_re[0],sdu_length_samples*sizeof(double)); s_im[0] = (double *)malloc(sdu_length_samples*sizeof(double)); bzero(s_im[0],sdu_length_samples*sizeof(double)); for (i=0; i<n_rx; i++) { r_re[i] = (double *)malloc((sdu_length_samples+100)*sizeof(double)); bzero(r_re[i],(sdu_length_samples+100)*sizeof(double)); r_im[i] = (double *)malloc((sdu_length_samples+100)*sizeof(double)); bzero(r_im[i],(sdu_length_samples+100)*sizeof(double)); } ch = new_channel_desc_scm(1, n_rx, channel_model, BW, 0.0, 0, 0); if (ch==NULL) { printf("Problem generating channel model. Exiting.\n"); exit(-1); } phy_tx_start(&tx_vector,txdata,0,FRAME_LENGTH_SAMPLES_MAX,data_ind); tx_lev = signal_energy((int32_t*)txdata,320); tx_lev_dB = (unsigned int) dB_fixed(tx_lev); write_output("txsig0.m","txs", txdata,sdu_length_samples,1,1); // multipath channel for (i=0; i<sdu_length_samples; i++) { s_re[0][i] = (double)(((short *)txdata)[(i<<1)]); s_im[0][i] = (double)(((short *)txdata)[(i<<1)+1]); } for (SNR=snr0; SNR<snr1; SNR+=.2) { printf("n_frames %d SNR %f sdu_length %d rate %d\n",n_frames,SNR,tx_vector.sdu_length,tx_vector.rate); errors=0; misdetected_errors=0; signal_errors=0; missed_packets=0; stop=0; for (trial=0; trial<n_frames; trial++) { // printf("Trial %d (errors %d), sdu_length_samples %d\n",trial,errors,sdu_length_samples); sigma2_dB = 25; //10*log10((double)tx_lev) - SNR; txg_dB = 10*log10((double)tx_lev) - (SNR + sigma2_dB); txg = pow(10.0,-.05*txg_dB); if (n_frames==1) printf("sigma2_dB %f (SNR %f dB) tx_lev_dB %f, txg %f\n",sigma2_dB,SNR,10*log10((double)tx_lev)-txg_dB,txg_dB); //AWGN sigma2 = pow(10,sigma2_dB/10); // printf("Sigma2 %f (sigma2_dB %f)\n",sigma2,sigma2_dB); // sigma2 = 0; multipath_channel(ch,s_re,s_im,r_re,r_im, sdu_length_samples,0); if (n_frames==1) { printf("rx_level data symbol %f, tx_lev %f\n", 10*log10(signal_energy_fp(r_re,r_im,1,80,0)), 10*log10(tx_lev)); } for (aa=0; aa<n_rx; aa++) { for (i=0; i<(sdu_length_samples+100); i++) { ((short*)&rxdata[aa][tx_offset])[(i<<1)] = (short) (((txg*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); ((short*)&rxdata[aa][tx_offset])[1+(i<<1)] = (short) (((txg*r_im[aa][i]) + (iqim*r_re[aa][i]*txg) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); // if (i<128) // printf("i%d : rxdata %d, txdata %d\n",i,((short *)rxdata[aa])[rx_offset+(i<<1)],((short *)txdata)[i<<1]); } for (i=0; i<tx_offset; i++) { ((short*) rxdata[aa])[(i<<1)] = (short) (sqrt(sigma2/2)*gaussdouble(0.0,1.0)); ((short*) rxdata[aa])[1+(i<<1)] = (short) (sqrt(sigma2/2)*gaussdouble(0.0,1.0)); } for (i=(tx_offset+sdu_length_samples+100); i<FRAME_LENGTH_SAMPLES_MAX; i++) { ((short*) rxdata[aa])[(i<<1)] = (short) (sqrt(sigma2/2)*gaussdouble(0.0,1.0)); ((short*) rxdata[aa])[1+(i<<1)] = (short) (sqrt(sigma2/2)*gaussdouble(0.0,1.0)); } } if (n_frames==1) { write_output("rxsig0.m","rxs", &rxdata[0][0],FRAME_LENGTH_SAMPLES_MAX,1,1); } no_detection=1; off = 0; while(off<FRAME_LENGTH_SAMPLES_MAX) { rxp = dB_fixed(signal_energy(rxdata[0]+off,512)); if (n_frames==1) printf("off %d: rxp %d (%d)\n",off,rxp,signal_energy(rxdata[0]+off,104)); if (rxp>RX_THRES_dB) { if (off<105) off2 = FRAME_LENGTH_SAMPLES_MAX-105; else off2=off; if ((initial_sync(&rxv,&rx_offset,&log2_maxh,(uint32_t*)rxdata[0],FRAME_LENGTH_SAMPLES_MAX,off2,1) == BUSY)) { if (n_frames==1) printf("Channel is busy, rxv %p, offset %d\n",(void*)rxv,rx_offset); no_detection=0; if (rxv) { if (n_frames==1) printf("Rate %d, SDU_LENGTH %d\n",rxv->rate,rxv->sdu_length); if ( (rxv->rate != tx_vector.rate)||(rxv->sdu_length != tx_vector.sdu_length)) { signal_errors++; if ((signal_errors > (n_frames/10)) && (trial>=100)) { stop=1; } if (n_frames == 1) printf("SIGNAL error: rx_offset %d, tx_offset %d (off2 %d)\n",rx_offset,tx_offset,off2); break; } else { memset(data_ind_rx,0,rxv->sdu_length+4+2+1); if (data_detection(rxv,data_ind_rx,(uint32_t*)rxdata[0],FRAME_LENGTH_SAMPLES_MAX,rx_offset,log2_maxh,NULL)) { for (i=0; i<rxv->sdu_length+6; i++) { if (data_ind[i]!=data_ind_rx[i]) { //printf("error position %d : %x,%x\n",i,data_ind[i],data_ind_rx[i]); misdetected_errors++; errors++; } } if ((errors > (n_frames/10)) && (trial>100)) { stop=1; break; } } // initial_synch returns IDLE else { errors++; if (n_frames == 1) { printf("Running data_detection fails\n"); for (i=0; i<rxv->sdu_length+6; i++) { if (data_ind[i]!=data_ind_rx[i]) { printf("error position %d : %x,%x\n",i,data_ind[i],data_ind_rx[i]); } } } if ((errors > (n_frames/10)) && (trial>=100)) { stop=1; break; } } break; } } } } off+=105; } if (no_detection==1) missed_packets++; if (stop==1) break; } printf("\nSNR %f dB: errors %d/%d, misdetected errors %d/%d,signal_errors %d/%d, missed_packets %d/%d\n",SNR,errors,trial-signal_errors,misdetected_errors,trial-signal_errors,signal_errors,trial,missed_packets,trial); snr_array[cnt] = SNR; errors_array[cnt] = errors; trials_array[cnt] = trial; misdetected_errors_array[cnt] = misdetected_errors; signal_errors_array[cnt] = signal_errors; missed_packets_array[cnt] = missed_packets; cnt++; if (cnt>99) { printf("too many SNR points, exiting ...\n"); break; } if (errors == 0) break; #ifdef EXECTIME print_is_stats(); print_dd_stats(); #endif } sprintf(fname,"SNR_%d_%d.m",tx_vector.rate,tx_vector.sdu_length); sprintf(vname,"SNR_%d_%d_v",tx_vector.rate,tx_vector.sdu_length); write_output(fname,vname,snr_array,cnt,1,7); sprintf(fname,"errors_%d_%d.m",tx_vector.rate,tx_vector.sdu_length); sprintf(vname,"errors_%d_%d_v",tx_vector.rate,tx_vector.sdu_length); write_output(fname,vname,errors_array,cnt,1,2); sprintf(fname,"trials_%d_%d.m",tx_vector.rate,tx_vector.sdu_length); sprintf(vname,"trials_%d_%d_v",tx_vector.rate,tx_vector.sdu_length); write_output(fname,vname,trials_array,cnt,1,2); sprintf(fname,"signal_errors_%d_%d.m",tx_vector.rate,tx_vector.sdu_length); sprintf(vname,"signal_errors_%d_%d_v",tx_vector.rate,tx_vector.sdu_length); write_output(fname,vname,signal_errors_array,cnt,1,2); free(data_ind); free(data_ind_rx); // free_channel_desc_scm(ch); free(txdata); for (i=0; i<n_rx; i++) { free(rxdata[i]); } free(s_re[0]); free(s_im[0]); for (i=0; i<n_rx; i++) { free(r_re[i]); free(r_im[i]); } return(0); }
// Leosam 08/08: What are the arguments? int main (int argc, char **argv) { // Command line parsing int input_val = 1000; // Value serving as an input relatad to the SNR int max_num_ofdm_sym = 64; // Index of the last frame for the channel estimation int be_verbose = 0; // Operate in verbose mode int index; int c; unsigned int rx_energy[NB_ANTENNAS], n0_energy[NB_ANTENNAS]; if (argc == 1) { error (); exit (-1); } while ((c = getopt (argc, argv, "hVv:n:")) != -1) { switch (c) { case 'h': help (); exit (1); case 'V': be_verbose = 1; break; case 'v': input_val = atoi (optarg); break; return 1; case 'n': max_num_ofdm_sym = atoi (optarg); break; return 1; default: error (); exit (-1); } } // // Initialization stuff // int i, ii, j, ret, delay, l; short seed[3]; // Leosam 08/08: What is this amps? double amps[8] = { 1.0, .8, .4, .2, .1, .05, .025, .01 }; struct complex ch[NB_ANTENNAS * NB_ANTENNAS][10 + (int) (1 + 2 * BW * Td)]; struct complex rx_tmp, tx, n, phase; char *chbch_pdu; int chbch_size; int extension; unsigned char dummy_mac_pdu[120]; #ifdef USER_MODE char fname[40], vname[40]; #endif // USER_MODE if (be_verbose) printf ("Allocating memory for PHY_VARS\n"); // Memory allocation for PHY and MAC structures PHY_vars = malloc (sizeof (PHY_VARS)); PHY_config = malloc (sizeof (PHY_CONFIG)); mac_xface = malloc (sizeof (MAC_xface)); // Loading of the configuration data if ((config = fopen ("config.cfg", "r")) == NULL) // this can be configured { if (be_verbose) printf ("[Main USER] The openair configuration file <config.cfg> could not be found!\n"); exit (0); } if ((scenario = fopen ("scenario.scn", "r")) == NULL) { if (be_verbose) printf ("[Main USER] The openair scenario file <scenario.scn> could not be found!\n"); exit (0); } if (be_verbose) printf ("Opened configuration files\n"); reconfigure_MACPHY (scenario); if (be_verbose) dump_config (); // Leosam 08/08: This is repeated bellow. Is it necessary? mac_xface->is_cluster_head = 0; // Initialize the PHY and MAC variables phy_init (NB_ANTENNAS_TX); if (be_verbose) printf ("Initialized PHY variables\n"); // Fill MAC PDU buffer for CHBCH seed[0] = (short) time (NULL); seed[1] = (short) time (NULL); seed[2] = (short) time (NULL); seed48 (&seed[0]); randominit (); /* * for (i=0;i<mac_xface->mac_tch->bch_tx[0].size-4;i++) { * mac_xface->mac_tch->bch_tx[0].data[i] = i;//(u8)lrand48(); * } * * * printf("Filled CHBCH PDU with random data\n"); * * // Generate one CHBCH * phy_generate_chbch(0); * */ // // Preparation for the TX procedure // // Creation of the CHBCH chbch_size = (NUMBER_OF_CARRIERS_PER_GROUP * (NUMBER_OF_CHBCH_SYMBOLS) * 16) >> 3; if (be_verbose) printf ("chbch_size = %d\n", chbch_size); chbch_pdu = malloc (chbch_size); for (i = 0; i < chbch_size - 4; i++) { chbch_pdu[i] = i; } if (be_verbose) printf ("Filled CHBCH PDU (%d bytes) with data\n", chbch_size); // Leosam 08/08: O.o delay = 1032; // delay = 0; // Generation of the CHBCH phy_generate_chbch (0, 1, NB_ANTENNAS_TX, chbch_pdu); // Generation of the pilot symbols for (i = 16; i < max_num_ofdm_sym; i++) { phy_generate_sch (0, i, 0xFFFF, 1, NB_ANTENNAS_TX); } mac_xface->is_cluster_head = 0; if (be_verbose) { for (ii=0; ii<NB_ANTENNAS; ii++) { sprintf (fname, "txsig%d.m", ii); sprintf (vname, "txs%d", ii); write_output (fname, vname, (s16 *) PHY_vars->tx_vars[ii].TX_DMA_BUFFER, NUMBER_OF_SYMBOLS_PER_FRAME * OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES, 1, 1); } } // generate channels if (be_verbose) printf ("Generating MIMO Channels\n"); phase.r = 0; phase.i = 0; printf("Phase pointer %0x\n",&phase); for (i = 0; i < NB_ANTENNAS; i++) { for (j = 0; j < NB_ANTENNAS; j++) { random_channel (amps, Td, 8, BW, ch[j + (i * NB_ANTENNAS)],0.0,&phase); } } if (be_verbose) printf ("chbch_pdu %x (%d)\n", PHY_vars->chbch_data[0].demod_pdu, chbch_size); if (be_verbose) { for (l = 0; l < (1 + 2 * BW * Td); l++) { printf ("(%f,%f)\n", ch[0][l]); } } // // TX procedure // // Transmission // ////////////////////////// // Foreach symbol for (i = 0; i < (max_num_ofdm_sym) * OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) { // Foreach RX antenna for (ii = 0; ii < NB_ANTENNAS; ii++) { rx_tmp.r = 0; rx_tmp.i = 0; n.r = gaussdouble (0.0, 10.0); n.i = gaussdouble (0.0, 10.0); // Foreach TX antenna for (j = 0; j < NB_ANTENNAS; j++) { // Foreach symbol for (l = 0; l < (1 + 2 * BW * Td); l++) { tx.r = (double) (((s16 *) & PHY_vars->tx_vars[j]. TX_DMA_BUFFER[0 * OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES]) [2 * (i - l)]) / sqrt (1.0 * input_val); tx.i = (double) (((s16 *) & PHY_vars->tx_vars[j]. TX_DMA_BUFFER[0 * OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES]) [1 + (2 * (i - l))]) / sqrt (1.0 * input_val); rx_tmp.r += (tx.r * ch[j + (ii * NB_ANTENNAS)][l].r) - (tx.i * ch[j + (ii * NB_ANTENNAS)][l].i); rx_tmp.i += (tx.i * ch[j + (ii * NB_ANTENNAS)][l].r) + (tx.r * ch[j + (ii * NB_ANTENNAS)][l].i); } } ((s16 *) & PHY_vars->rx_vars[ii]. RX_DMA_BUFFER[delay + (0 * OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES)])[2 * i] = (short) (rx_tmp.r + n.r); ((s16 *) & PHY_vars->rx_vars[ii]. RX_DMA_BUFFER[delay + (0 * OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES)])[1 + (2 * i)] = (short) (rx_tmp.i + n.i); } } if (be_verbose) { for (ii=0; ii<NB_ANTENNAS; ii++) { sprintf (fname, "rxsig%d.m", ii); sprintf (vname, "rxs%d", ii); write_output (fname, vname, (s16 *) PHY_vars->rx_vars[ii].RX_DMA_BUFFER, NUMBER_OF_SYMBOLS_PER_FRAME * OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES, 1, 1); } } // // RX procedure // if (be_verbose) printf ("Starting RX\n"); // Sync phy_synch_time (PHY_vars->rx_vars[0].RX_DMA_BUFFER, &sync_pos, FRAME_LENGTH_COMPLEX_SAMPLES, 768, CHSCH, 0); // Forcing sync to 0 since were running offline if (be_verbose) msg ("sync_pos = %d\n", sync_pos); PHY_vars->rx_vars[0].offset = 0; //sync_pos; // estamte the signal and noise energy for (ii=0; ii < NB_ANTENNAS; ii++) { rx_energy[ii] = signal_energy((int *)&PHY_vars->rx_vars[ii].RX_DMA_BUFFER[PHY_vars->rx_vars[0].offset+CYCLIC_PREFIX_LENGTH], OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES); n0_energy[ii] = signal_energy((int *)&PHY_vars->rx_vars[ii].RX_DMA_BUFFER[PHY_vars->rx_vars[0].offset+CYCLIC_PREFIX_LENGTH + (NUMBER_OF_CHSCH_SYMBOLS+NUMBER_OF_CHBCH_SYMBOLS+1) * OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES], OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES); //msg("CYCLIC_PREFIX_LENGTH=%d, NUMBER_OF_CHSCH_SYMBOLS=%d, NUMBER_OF_CHBCH_SYMBOLS=%d, OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES=%d\n", CYCLIC_PREFIX_LENGTH, NUMBER_OF_CHSCH_SYMBOLS, NUMBER_OF_CHBCH_SYMBOLS, OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES); msg("symbol = %d\n", PHY_vars->rx_vars[ii].RX_DMA_BUFFER[PHY_vars->rx_vars[0].offset+CYCLIC_PREFIX_LENGTH + (NUMBER_OF_CHSCH_SYMBOLS+NUMBER_OF_CHBCH_SYMBOLS) * OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES]); msg("SNR Ant %d = %d / %d \n", ii, rx_energy[ii], n0_energy[ii]); } // CHBCH channel estimation phy_channel_estimation_top(PHY_vars->rx_vars[0].offset,0,0,0,NB_ANTENNAS,0); //phy_channel_estimation_top (PHY_vars->rx_vars[0].offset, 0, 0, 0); phy_decode_chbch (0, &dummy_mac_pdu[0], NB_ANTENNAS, NB_ANTENNAS_TX, 120); if (be_verbose) { for (i = 0; i < chbch_size; i++) { msg ("Data %x : %x\n", i, PHY_vars->chbch_data[0].demod_pdu[i]); } } printf("PERROR_SHIFT: %d\n", PERROR_SHIFT); // // Channel estimation procedure // // for (i = 0; i < max_num_ofdm_sym; i++) // { // phy_channel_estimation_top(PHY_vars->rx_vars[0].offset,i,0,0,1); // } phy_channel_est_emos(16, 16, max_num_ofdm_sym-1, TRUE, 0); phy_cleanup (); if (be_verbose) printf ("Exiting\n"); }
void lte_param_init(unsigned char N_tx, unsigned char N_rx,unsigned char transmission_mode) { unsigned int ind; printf("Start lte_param_init\n"); PHY_vars_eNb = malloc(sizeof(PHY_VARS_eNB)); PHY_vars_UE = malloc(sizeof(PHY_VARS_UE)); PHY_config = malloc(sizeof(PHY_CONFIG)); mac_xface = malloc(sizeof(MAC_xface)); randominit(0); set_taus_seed(0); lte_frame_parms = &(PHY_vars_eNb->lte_frame_parms); lte_frame_parms->N_RB_DL = 25; //50 for 10MHz and 25 for 5 MHz lte_frame_parms->N_RB_UL = 25; lte_frame_parms->Ncp = 1; lte_frame_parms->Nid_cell = 0; lte_frame_parms->nushift = 0; lte_frame_parms->nb_antennas_tx = N_tx; lte_frame_parms->nb_antennas_rx = N_rx; lte_frame_parms->first_dlsch_symbol = 4; lte_frame_parms->num_dlsch_symbols = 6; lte_frame_parms->Csrs = 2; lte_frame_parms->Bsrs = 0; lte_frame_parms->kTC = 0; lte_frame_parms->n_RRC = 0; lte_frame_parms->mode1_flag = (transmission_mode == 1)? 1 : 0; init_frame_parms(lte_frame_parms); copy_lte_parms_to_phy_framing(lte_frame_parms, &(PHY_config->PHY_framing)); phy_init_top(N_tx); //allocation lte_frame_parms->twiddle_fft = twiddle_fft; lte_frame_parms->twiddle_ifft = twiddle_ifft; lte_frame_parms->rev = rev; PHY_vars_UE->lte_frame_parms = *lte_frame_parms; lte_gold(lte_frame_parms); generate_ul_ref_sigs(); generate_ul_ref_sigs_rx(); generate_64qam_table(); generate_16qam_table(); generate_RIV_tables(); generate_pcfich_reg_mapping(lte_frame_parms); generate_phich_reg_mapping_ext(lte_frame_parms); phy_init_lte_ue(&PHY_vars_UE->lte_frame_parms, &PHY_vars_UE->lte_ue_common_vars, PHY_vars_UE->lte_ue_dlsch_vars, PHY_vars_UE->lte_ue_dlsch_vars_cntl, PHY_vars_UE->lte_ue_dlsch_vars_ra, PHY_vars_UE->lte_ue_dlsch_vars_1A, PHY_vars_UE->lte_ue_pbch_vars, PHY_vars_UE->lte_ue_pdcch_vars, PHY_vars_UE); phy_init_lte_eNB(&PHY_vars_eNb->lte_frame_parms, &PHY_vars_eNb->lte_eNB_common_vars, PHY_vars_eNb->lte_eNB_ulsch_vars, 0, PHY_vars_eNb); printf("Done lte_param_init\n"); }
int main(int argc, char **argv) { int i,l,aa,sector; double sigma2, sigma2_dB=0; mod_sym_t **txdataF; #ifdef IFFT_FPGA int **txdataF2; #endif int **txdata,**rxdata; double **s_re,**s_im,**r_re,**r_im; double amps[8] = {0.3868472 , 0.3094778 , 0.1547389 , 0.0773694 , 0.0386847 , 0.0193424 , 0.0096712 , 0.0038685}; double aoa=.03,ricean_factor=1,Td=1.0; int channel_length; int amp; unsigned char pbch_pdu[6]; int sync_pos, sync_pos_slot; FILE *rx_frame_file; int result; int freq_offset; int subframe_offset; char fname[40], vname[40]; int trial, n_errors=0; unsigned int nb_rb = 25; unsigned int first_rb = 0; unsigned int eNb_id = 0; unsigned int slot_offset = 0; unsigned int sample_offset = 0; unsigned int channel_offset = 0; int n_frames; int slot=0,last_slot=0,next_slot=0; double nf[2] = {3.0,3.0}; //currently unused double ip =0.0; double N0W, path_loss, path_loss_dB, tx_pwr, rx_pwr; double rx_gain; int rx_pwr2, target_rx_pwr_dB; struct complex **ch; unsigned char first_call = 1; LTE_DL_FRAME_PARMS frame_parms; LTE_DL_FRAME_PARMS *lte_frame_parms = &frame_parms; if (argc==2) amp = atoi(argv[1]); else amp = 1024; // we normalize the tx power to 0dBm, assuming the amplitude of the signal is 1024 // the SNR is this given by the difference of the path loss and the thermal noise (~-105dBm) // the rx_gain is adjusted automatically to achieve the target_rx_pwr_dB path_loss_dB = -90; path_loss = pow(10,path_loss_dB/10); target_rx_pwr_dB = 60; lte_frame_parms->N_RB_DL = 25; lte_frame_parms->N_RB_UL = 25; lte_frame_parms->Ng_times6 = 1; lte_frame_parms->Ncp = 1; lte_frame_parms->Nid_cell = 0; lte_frame_parms->nushift = 0; lte_frame_parms->nb_antennas_tx = 2; lte_frame_parms->nb_antennas_rx = 2; lte_frame_parms->first_dlsch_symbol = 4; lte_frame_parms->num_dlsch_symbols = 6; lte_frame_parms->Csrs = 2; lte_frame_parms->Bsrs = 0; lte_frame_parms->kTC = 0; lte_frame_parms->n_RRC = 0; lte_frame_parms->mode1_flag = 1; lte_frame_parms->ofdm_symbol_size = 512; lte_frame_parms->log2_symbol_size = 9; lte_frame_parms->samples_per_tti = 7680; lte_frame_parms->first_carrier_offset = 362; lte_frame_parms->nb_prefix_samples>>=2; #ifdef IFFT_FPGA txdata = (int **)malloc16(2*sizeof(int*)); txdata[0] = (int *)malloc16(FRAME_LENGTH_BYTES); txdata[1] = (int *)malloc16(FRAME_LENGTH_BYTES); bzero(txdata[0],FRAME_LENGTH_BYTES); bzero(txdata[1],FRAME_LENGTH_BYTES); rxdata = (int **)malloc16(2*sizeof(int*)); rxdata[0] = (int *)malloc16(2*FRAME_LENGTH_BYTES); rxdata[1] = (int *)malloc16(2*FRAME_LENGTH_BYTES); bzero(rxdata[0],2*FRAME_LENGTH_BYTES); bzero(rxdata[1],2*FRAME_LENGTH_BYTES); txdataF2 = (int **)malloc16(2*sizeof(int*)); txdataF2[0] = (int *)malloc16(FRAME_LENGTH_BYTES); txdataF2[1] = (int *)malloc16(FRAME_LENGTH_BYTES); bzero(txdataF2[0],FRAME_LENGTH_BYTES); bzero(txdataF2[1],FRAME_LENGTH_BYTES); #endif s_re = malloc(2*sizeof(double*)); s_im = malloc(2*sizeof(double*)); r_re = malloc(2*sizeof(double*)); r_im = malloc(2*sizeof(double*)); for (i=0; i<2; i++) { s_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(s_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); s_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(s_im[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); r_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(r_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); r_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(r_im[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); } for (i=0; i<2; i++) { for (l=0; l<FRAME_LENGTH_COMPLEX_SAMPLES; l++) { ((short*) txdata[i])[2*l] = amp * cos(M_PI/2*l); ((short*) txdata[i])[2*l+1] = amp * sin(M_PI/2*l); } } tx_pwr = signal_energy(txdata[0],lte_frame_parms->samples_per_tti>>1); printf("tx_pwr (DAC in) %d dB for slot %d (subframe %d)\n",dB_fixed(tx_pwr),next_slot,next_slot>>1); channel_length = (int) 11+2*BW*Td; ch = (struct complex**) malloc(4 * sizeof(struct complex*)); for (i = 0; i<4; i++) ch[i] = (struct complex*) malloc(channel_length * sizeof(struct complex)); randominit(0); set_taus_seed(0); #ifdef RF tx_pwr = dac_fixed_gain(s_re, s_im, txdata, lte_frame_parms->nb_antennas_tx, lte_frame_parms->samples_per_tti>>1, 14, 18); //this should give 0dBm output level for input with amplitude 1024 printf("tx_pwr (DAC out) %f dB for slot %d (subframe %d)\n",10*log10(tx_pwr),next_slot,next_slot>>1); #else for (i=0; i<(lte_frame_parms->samples_per_tti>>1); i++) { for (aa=0; aa<lte_frame_parms->nb_antennas_tx; aa++) { s_re[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)]); s_im[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)+1]); } } #endif // printf("channel for slot %d (subframe %d)\n",next_slot,next_slot>>1); multipath_channel(ch,s_re,s_im,r_re,r_im, amps,Td,BW,ricean_factor,aoa, lte_frame_parms->nb_antennas_tx, lte_frame_parms->nb_antennas_rx, lte_frame_parms->samples_per_tti>>1, channel_length, 0, .9, (first_call == 1) ? 1 : 0); if (first_call == 1) first_call = 0; #ifdef RF //path_loss_dB = 0; //path_loss = 1; for (i=0; i<(lte_frame_parms->samples_per_tti>>1); i++) { for (aa=0; aa<lte_frame_parms->nb_antennas_rx; aa++) { r_re[aa][i]=r_re[aa][i]*sqrt(path_loss); r_im[aa][i]=r_im[aa][i]*sqrt(path_loss); } } rx_pwr = signal_energy_fp(r_re,r_im,lte_frame_parms->nb_antennas_rx,lte_frame_parms->samples_per_tti>>1,0); printf("rx_pwr (RF in) %f dB for slot %d (subframe %d)\n",10*log10(rx_pwr),next_slot,next_slot>>1); rx_gain = target_rx_pwr_dB - 10*log10(rx_pwr); // RF model rf_rx(r_re, r_im, NULL, NULL, 0, lte_frame_parms->nb_antennas_rx, lte_frame_parms->samples_per_tti>>1, 1.0/7.68e6 * 1e9, // sampling time (ns) 0.0, // freq offset (Hz) (-20kHz..20kHz) 0.0, // drift (Hz) NOT YET IMPLEMENTED nf, // noise_figure NOT YET IMPLEMENTED rx_gain-66.227, // rx gain (66.227 = 20*log10(pow2(11)) = gain from the adc that will be applied later) 200, // IP3_dBm (dBm) &ip, // initial phase 30.0e3, // pn_cutoff (kHz) -500.0, // pn_amp (dBc) default: 50 0.0, // IQ imbalance (dB), 0.0); // IQ phase imbalance (rad) rx_pwr = signal_energy_fp(r_re,r_im,lte_frame_parms->nb_antennas_rx,lte_frame_parms->samples_per_tti>>1,0); printf("rx_pwr (ADC in) %f dB for slot %d (subframe %d)\n",10*log10(rx_pwr),next_slot,next_slot>>1); #endif #ifdef RF adc(r_re, r_im, 0, slot_offset, rxdata, lte_frame_parms->nb_antennas_rx, lte_frame_parms->samples_per_tti>>1, 12); rx_pwr2 = signal_energy(rxdata[0]+slot_offset,lte_frame_parms->samples_per_tti>>1); printf("rx_pwr (ADC out) %f dB (%d) for slot %d (subframe %d)\n",10*log10((double)rx_pwr2),rx_pwr2,next_slot,next_slot>>1); #else for (i=0; i<(lte_frame_parms->samples_per_tti>>1); i++) { for (aa=0; aa<lte_frame_parms->nb_antennas_rx; aa++) { ((short*) rxdata[aa])[2*slot_offset + (2*i)] = (short) ((r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)); ((short*) rxdata[aa])[2*slot_offset + (2*i)+1] = (short) ((r_im[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)); } } #endif write_output("rxsig0.m","rxs0",rxdata[0],lte_frame_parms->samples_per_tti>>1,1,1); write_output("rxsig1.m","rxs1",rxdata[1],lte_frame_parms->samples_per_tti>>1,1,1); #ifdef IFFT_FPGA free(txdataF2[0]); free(txdataF2[1]); free(txdataF2); free(txdata[0]); free(txdata[1]); free(txdata); free(rxdata[0]); free(rxdata[1]); free(rxdata); #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); return(0); }
int main(int argc, char *argv[]) { int ret,ret2; unsigned int errors,uerrors,errors2,crc_misses,iterations,trials,trials2,block_length,errors3,trials3; double SNR,sigma,rate=.5; unsigned char qbits,mcs; char done0=0; char done1=1; char done2=1; unsigned short iind; unsigned int coded_bits; unsigned char NB_RB=25; int num_pdcch_symbols = 3; int subframe = 6; randominit(0); logInit(); lte_param_init(1,1,1,0,0,3); PHY_vars_eNB->dlsch_eNB[0][0] = new_eNB_dlsch(1,8,0); PHY_vars_UE->dlsch_ue[0][0] = new_ue_dlsch(1,8,0); PHY_vars_eNB->dlsch_eNB[0][1] = new_eNB_dlsch(1,8,0); PHY_vars_UE->dlsch_ue[0][1] = new_ue_dlsch(1,8,0); if (argc>1) mcs = atoi(argv[1]); else mcs = 0; printf("NB_RB %d\n",NB_RB); DLSCH_alloc_pdu2.rah = 0; DLSCH_alloc_pdu2.rballoc = DLSCH_RB_ALLOC; DLSCH_alloc_pdu2.TPC = 0; DLSCH_alloc_pdu2.dai = 0; DLSCH_alloc_pdu2.harq_pid = 0; DLSCH_alloc_pdu2.tb_swap = 0; DLSCH_alloc_pdu2.mcs1 = mcs; DLSCH_alloc_pdu2.ndi1 = 1; DLSCH_alloc_pdu2.rv1 = 0; if (argc>2) qbits = atoi(argv[2]); else qbits = 4; printf("Quantization bits %d\n",qbits); generate_eNB_dlsch_params_from_dci(subframe, &DLSCH_alloc_pdu2, 0x1234, format2_2A_M10PRB, PHY_vars_eNB->dlsch_eNB[0], &PHY_vars_eNB->lte_frame_parms, SI_RNTI, 0, P_RNTI, 0); //change this later generate_ue_dlsch_params_from_dci(subframe, &DLSCH_alloc_pdu2, C_RNTI, format2_2A_M10PRB, PHY_vars_UE->dlsch_ue[0], &PHY_vars_UE->lte_frame_parms, SI_RNTI, 0, P_RNTI); coded_bits = get_G(&PHY_vars_eNB->lte_frame_parms,NB_RB,PHY_vars_eNB->dlsch_eNB[0][0]->rb_alloc, get_Qm(mcs),num_pdcch_symbols,subframe); printf("Coded_bits (G) = %d\n",coded_bits); block_length = dlsch_tbs25[get_I_TBS(mcs)][NB_RB-1]>>3; printf("Block_length = %d bytes (%d bits, rate %f), mcs %d, I_TBS %d, NB_RB %d\n",block_length, dlsch_tbs25[get_I_TBS(mcs)][NB_RB-1],(double)dlsch_tbs25[get_I_TBS(mcs)][NB_RB-1]/coded_bits, mcs,get_I_TBS(mcs),NB_RB); // Test Openair0 3GPP encoder /* test_encoder(block_length, f1f2mat[(block_length-5)*2], // f1 (see 36121-820, page 14) f1f2mat[((block_length-5)*2)+1], // f2 (see 36121-820, page 14) 3); */ // exit(0); for (SNR=-6;SNR<16;SNR+=.5) { // printf("\n\nSNR %f dB\n",SNR); sigma = pow(10.0,-.05*SNR); errors=0; crc_misses=0; errors2=0; errors3=0; iterations=0; if (done0 == 0) { ret = test_logmap8(PHY_vars_eNB->dlsch_eNB[0][0], PHY_vars_UE->dlsch_ue[0][0], coded_bits, NB_RB, sigma, // noise standard deviation qbits, block_length, // block length bytes NTRIALS, &errors, &trials, &uerrors, &crc_misses, &iterations, num_pdcch_symbols, subframe); if (ret>=0) // printf("ref: Errors %d (%f), Uerrors %d (%f), CRC Misses %d (%f), Avg iterations %f\n",errors,(double)errors/trials,uerrors,(double)uerrors/trials,crc_misses,(double)crc_misses/trials,(double)iterations/trials); printf("%f,%f,%f,%f\n",SNR,(double)errors/trials,(double)crc_misses/trials,(double)iterations/trials); if (((double)errors/trials) < 1e-2) done0=1; } /* if (done1 == 0) { printf("exmimo\n"); ret = test_logmapexmimo(rate, // code rate sigma, // noise standard deviation qbits, block_length, // block length bytes f1f2mat[iind*2], // f1 (see 36121-820, page 14) f1f2mat[(iind*2)+1], // f2 (see 36121-820, page 14) 3, NTRIALS, &errors3, &trials3); if (ret>=0) printf("exmimo : Errors %d (%f)\n",errors3,(double)errors3/trials3); if (((double)errors3/trials3) < 1e-3) done1=1; } if (done2 == 0) { printf("Viterbi ...\n"); ret2 = test_viterbi(sigma, 8*block_length, NTRIALS, &errors2, &trials2, rate); if (ret2>=0) printf("viterbi : Errors %d (%f)\n",errors2,(double)errors2/trials2); if (((double)errors2/trials2) < 1e-3) done2=1; } */ if ((done0==1) && (done1==1) && (done2==1)) { printf("done\n"); break; } } return(0); }
Layer::Layer(const int pnnodes, const int nnodes, const double lrate, const double lambda, double (*act)(double), double (*actd)(double)) : lrate(lrate), lambda(lambda), act(act), actd(actd), W(pnnodes+1, nnodes), grad(pnnodes+1, nnodes) { randominit(6.0); }
int main (int argc, char **argv) { Interface_init(); s_t* st2=(s_t*)(Instance[1].gm->mem_ref.pointer); st2->port=38800; char c; s32 i, j; int new_omg_model; // goto ocg in oai_emulation.info. // pointers signal buffers (s = transmit, r,r0 = receive) double **s_re[NINST], **s_im[NINST], **r_re[NINST], **r_im[NINST], **r_re0, **r_im0; double **r_re0_d[8][3], **r_im0_d[8][3], **r_re0_u[3][8],**r_im0_u[3][8]; // double **s_re, **s_im, **r_re, **r_im, **r_re0, **r_im0; double forgetting_factor=0; int map1,map2; double **ShaF= NULL; // Framing variables s32 slot, last_slot, next_slot; // variables/flags which are set by user on command-line double snr_dB, sinr_dB; u8 set_snr=0,set_sinr=0; u8 cooperation_flag; // for cooperative communication u8 target_dl_mcs = 4; u8 target_ul_mcs = 2; u8 rate_adaptation_flag; u8 abstraction_flag = 0, ethernet_flag = 0; u16 Nid_cell = 0; s32 UE_id, eNB_id, ret; // time calibration for soft realtime mode struct timespec time_spec; unsigned long time_last, time_now; int td, td_avg, sleep_time_us; char *g_log_level = "trace"; // by default global log level is set to trace lte_subframe_t direction; #ifdef XFORMS FD_phy_procedures_sim *form[NUMBER_OF_eNB_MAX][NUMBER_OF_UE_MAX]; char title[255]; #endif LTE_DL_FRAME_PARMS *frame_parms; FILE *UE_stats[NUMBER_OF_UE_MAX], *eNB_stats; char UE_stats_filename[255]; int len; #ifdef ICIC remove ("dci.txt"); #endif //time_t t0,t1; clock_t start, stop; // Added for PHY abstraction Node_list ue_node_list = NULL; Node_list enb_node_list = NULL; //default parameters target_dl_mcs = 0; rate_adaptation_flag = 0; oai_emulation.info.n_frames = 0xffff;//1024; //100; 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 init_oai_emulation(); // to initialize everything !!! // get command-line options while ((c = getopt (argc, argv, "haePToFt:C:N:k:x:m:rn:s:S:f:z:u:b:c:M:p:g:l:d:U:B:R:E:")) != -1) { switch (c) { case 'F': // set FDD oai_emulation.info.frame_type = 0; break; case 'C': oai_emulation.info.tdd_config = atoi (optarg); if (oai_emulation.info.tdd_config > 6) { msg ("Illegal tdd_config %d (should be 0-6)\n", oai_emulation.info.tdd_config); exit (-1); } break; case 'R': oai_emulation.info.N_RB_DL = atoi (optarg); if ((oai_emulation.info.N_RB_DL != 6) && (oai_emulation.info.N_RB_DL != 15) && (oai_emulation.info.N_RB_DL != 25) && (oai_emulation.info.N_RB_DL != 50) && (oai_emulation.info.N_RB_DL != 75) && (oai_emulation.info.N_RB_DL != 100)) { msg ("Illegal N_RB_DL %d (should be one of 6,15,25,50,75,100)\n", oai_emulation.info.N_RB_DL); exit (-1); } case 'N': Nid_cell = atoi (optarg); if (Nid_cell > 503) { msg ("Illegal Nid_cell %d (should be 0 ... 503)\n", Nid_cell); exit(-1); } break; case 'h': help (); exit (1); case 'x': oai_emulation.info.transmission_mode = atoi (optarg); if ((oai_emulation.info.transmission_mode != 1) && (oai_emulation.info.transmission_mode != 2) && (oai_emulation.info.transmission_mode != 5) && (oai_emulation.info.transmission_mode != 6)) { msg("Unsupported transmission mode %d\n",oai_emulation.info.transmission_mode); exit(-1); } break; case 'm': target_dl_mcs = atoi (optarg); break; case 'r': rate_adaptation_flag = 1; break; case 'n': oai_emulation.info.n_frames = atoi (optarg); //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 '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 '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 't': //Td = atof (optarg); printf("[SIM] Option t is no longer supported on the command line. Please specify your channel model in the xml template\n"); exit(-1); break; case 'f': forgetting_factor = atof (optarg); break; case 'z': cooperation_flag = atoi (optarg); break; case 'u': oai_emulation.info.nb_ue_local = atoi (optarg); break; case 'b': oai_emulation.info.nb_enb_local = atoi (optarg); break; case 'a': abstraction_flag = 1; break; case 'p': oai_emulation.info.nb_master = atoi (optarg); 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 'e': oai_emulation.info.extended_prefix_flag = 1; break; case 'l': g_log_level = optarg; break; case 'c': strcpy(oai_emulation.info.local_server, optarg); oai_emulation.info.ocg_enabled=1; break; case 'g': oai_emulation.info.multicast_group = atoi (optarg); break; case 'B': oai_emulation.info.omg_model_enb = atoi (optarg); break; case 'U': oai_emulation.info.omg_model_ue = atoi (optarg); break; case 'T': oai_emulation.info.otg_enabled = 1; break; case 'P': oai_emulation.info.opt_enabled = 1; break; case 'E': oai_emulation.info.seed = atoi (optarg); break; default: help (); exit (-1); break; } } // configure oaisim with OCG oaisim_config(g_log_level); // config OMG and OCG, OPT, OTG, OLG if (oai_emulation.info.nb_ue_local > NUMBER_OF_UE_MAX ) { printf ("Enter fewer than %d UEs for the moment or change the NUMBER_OF_UE_MAX\n", NUMBER_OF_UE_MAX); exit (-1); } if (oai_emulation.info.nb_enb_local > NUMBER_OF_eNB_MAX) { printf ("Enter fewer than %d eNBs for the moment or change the NUMBER_OF_UE_MAX\n", NUMBER_OF_eNB_MAX); exit (-1); } // fix ethernet and abstraction with RRC_CELLULAR Flag #ifdef RRC_CELLULAR abstraction_flag = 1; ethernet_flag = 0; #endif if (set_sinr == 0) sinr_dB = snr_dB - 20; // setup ntedevice interface (netlink socket) #ifndef CYGWIN ret = netlink_init (); #endif if (ethernet_flag == 1) { oai_emulation.info.master[oai_emulation.info.master_id].nb_ue = oai_emulation.info.nb_ue_local; oai_emulation.info.master[oai_emulation.info.master_id].nb_enb = oai_emulation.info.nb_enb_local; 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); #ifdef LINUX init_bypass (); #endif 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_UE_INST = oai_emulation.info.nb_ue_local + oai_emulation.info.nb_ue_remote; NB_eNB_INST = oai_emulation.info.nb_enb_local + oai_emulation.info.nb_enb_remote; #ifndef NAS_NETLINK 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); #endif LOG_I(EMU, "total number of UE %d (local %d, remote %d) \n", NB_UE_INST,oai_emulation.info.nb_ue_local,oai_emulation.info.nb_ue_remote); LOG_I(EMU, "Total number of eNB %d (local %d, remote %d) \n", NB_eNB_INST,oai_emulation.info.nb_enb_local,oai_emulation.info.nb_enb_remote); printf("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\n", 1+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); // init_lte_vars (&frame_parms, oai_emulation.info.frame_type, oai_emulation.info.tdd_config, oai_emulation.info.extended_prefix_flag,oai_emulation.info.N_RB_DL, Nid_cell, cooperation_flag, oai_emulation.info.transmission_mode, abstraction_flag); init_frame_params (&frame_parms, oai_emulation.info.frame_type, oai_emulation.info.tdd_config, oai_emulation.info.extended_prefix_flag,oai_emulation.info.N_RB_DL, Nid_cell, cooperation_flag, oai_emulation.info.transmission_mode, abstraction_flag); printf ("Nid_cell %d\n", frame_parms->Nid_cell); /* Added for PHY abstraction */ if (abstraction_flag) get_beta_map(); for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { enb_data[eNB_id] = (node_desc_t *)malloc(sizeof(node_desc_t)); init_enb(enb_data[eNB_id],oai_emulation.environment_system_config.antenna.eNB_antenna); } for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) { ue_data[UE_id] = (node_desc_t *)malloc(sizeof(node_desc_t)); init_ue(ue_data[UE_id],oai_emulation.environment_system_config.antenna.UE_antenna); } // init SF map here!!! map1 =(int)oai_emulation.topology_config.area.x_km; map2 =(int)oai_emulation.topology_config.area.y_km; //ShaF = createMat(map1,map2); -> memory is allocated within init_SF ShaF = init_SF(map1,map2,DECOR_DIST,SF_VAR); // size of area to generate shadow fading map printf("Simulation area x=%f, y=%f\n", oai_emulation.topology_config.area.x_km, oai_emulation.topology_config.area.y_km); if (abstraction_flag == 0){ int ci; int ji=0; for(ci=0;ci<NB_eNB_INST;ci++) { init_channel_mmap_channel(10+ji,frame_parms, &(s_re[ci]), &(s_im[ci]), &(r_re[ci]), &(r_im[ci]), &(r_re0), &(r_im0)); ji++; //printf("ci %d\n",ci); } ji=0; for(ci=NB_eNB_INST;ci<(NB_eNB_INST+NB_UE_INST);ci++) { init_channel_mmap_channel(20+ji,frame_parms, &(s_re[ci]), &(s_im[ci]), &(r_re[ci]), &(r_im[ci]), &(r_re0), &(r_im0)); ji++; //printf("ci %d\n",ci); } } for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) { init_rre(frame_parms,&(r_re0_u[eNB_id][UE_id]),&(r_im0_u[eNB_id][UE_id])); init_rre(frame_parms,&(r_re0_d[UE_id][eNB_id]),&(r_im0_d[UE_id][eNB_id])); } } // printf("r_re0 %lf , r_im0 %lf\n",r_re0_u[0][0][0][0],r_im0_u[0][0][0][0]); // // r_im0_u[0][0][0][0]=100; // // printf("r_re0 %lf , r_im0 %lf\n",r_re0_u[0][0][0][0],r_im0_u[0][0][0][0]); // // // clean_param((r_re0_u[0][0]),(r_im0_u[0][0]),frame_parms); // // printf("r_re0 %lf , r_im0 %lf\n",r_re0_u[0][0][0][0],r_im0_u[0][0][0][0]); for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) { #ifdef DEBUG_SIM printf ("[SIM] Initializing channel from eNB %d to UE %d\n", eNB_id, UE_id); #endif eNB2UE[eNB_id][UE_id] = new_channel_desc_scm(2, 2, map_str_to_int(small_scale_names, oai_emulation.environment_system_config.fading.small_scale.selected_option), oai_emulation.environment_system_config.system_bandwidth_MB, forgetting_factor, 0, 0); UE2eNB[UE_id][eNB_id] = new_channel_desc_scm(2, 2, map_str_to_int(small_scale_names, oai_emulation.environment_system_config.fading.small_scale.selected_option), oai_emulation.environment_system_config.system_bandwidth_MB, forgetting_factor, 0, 0); } } randominit (0); set_taus_seed (0); number_of_cards = 1; openair_daq_vars.rx_rf_mode = 1; openair_daq_vars.tdd = 1; openair_daq_vars.rx_gain_mode = DAQ_AGC_ON; openair_daq_vars.dlsch_transmission_mode = oai_emulation.info.transmission_mode; openair_daq_vars.target_ue_dl_mcs = target_dl_mcs; openair_daq_vars.target_ue_ul_mcs = target_ul_mcs; openair_daq_vars.dlsch_rate_adaptation = rate_adaptation_flag; openair_daq_vars.ue_ul_nb_rb = 2; #ifdef XFORMS fl_initialize (&argc, argv, NULL, 0, 0); for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { form[eNB_id][UE_id] = create_form_phy_procedures_sim (); sprintf (title, "LTE SIM UE %d eNB %d", UE_id, eNB_id); fl_show_form (form[eNB_id][UE_id]->phy_procedures_sim, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); } #endif // time calibration for OAI 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; // s_t* st2=(s_t*)(Instance[1].gm->mem_ref.pointer); st2->Exec_FLAG=0; int count; IntInitAll(); Soc_t* this = (Soc_t*)(obj_inst[0].ptr->mem_ref.pointer); fd_set read_ibits; fd_set write_ibits; int n; struct timeval tvp ; tvp.tv_sec=10; tvp.tv_usec=0; FD_ZERO(&read_ibits); FD_SET(this->m_io_sync.io_sync_entries->fd_read, &read_ibits); ch_thread *e2u_t[NB_eNB_INST][NB_UE_INST]; ch_thread *u2e_t[NB_UE_INST][NB_eNB_INST]; for(eNB_id=0;eNB_id<NB_eNB_INST;eNB_id++){ for(UE_id=0;UE_id<NB_UE_INST;UE_id++){ e2u_t[eNB_id][UE_id]=(ch_thread*)calloc(1,sizeof(ch_thread)); }} for(UE_id=0;UE_id<NB_UE_INST;UE_id++){ for(eNB_id=0;eNB_id<NB_eNB_INST;eNB_id++){ u2e_t[UE_id][eNB_id]=(ch_thread*)calloc(1,sizeof(ch_thread)); }} pthread_t thread,thread2; pthread_t cthr_u[NB_eNB_INST][NB_UE_INST]; pthread_t cthr_d[NB_UE_INST][NB_eNB_INST]; 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++){ 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++) { u2e_t[UE_id][eNB_id]->eNB_id=eNB_id; u2e_t[UE_id][eNB_id]->UE_id=UE_id; u2e_t[UE_id][eNB_id]->r_re0=r_re0_d[UE_id][eNB_id]; u2e_t[UE_id][eNB_id]->r_im0=r_im0_d[UE_id][eNB_id]; u2e_t[UE_id][eNB_id]->r_re=r_re[NB_eNB_INST+UE_id]; u2e_t[UE_id][eNB_id]->r_im=r_im[NB_eNB_INST+UE_id]; u2e_t[UE_id][eNB_id]->s_im=s_im[eNB_id]; u2e_t[UE_id][eNB_id]->s_re=s_re[eNB_id]; u2e_t[UE_id][eNB_id]->eNB2UE=eNB2UE[eNB_id][UE_id]; u2e_t[UE_id][eNB_id]->UE2eNB=UE2eNB[UE_id][eNB_id]; u2e_t[UE_id][eNB_id]->enb_data=enb_data[eNB_id]; u2e_t[UE_id][eNB_id]->ue_data=ue_data[UE_id]; u2e_t[UE_id][eNB_id]->next_slot=&next_slot; u2e_t[UE_id][eNB_id]->abstraction_flag=&abstraction_flag; u2e_t[UE_id][eNB_id]->frame_parms=frame_parms; pthread_create (&cthr_d[UE_id][eNB_id], NULL, do_DL_sig_channel_T,(void*)(u2e_t[UE_id][eNB_id])); } } int sock; int port=(35000+(10+eNB_id)+(20+UE_id)); port=35010; sock = openairInetCreateSocket(SOCK_DGRAM,IPPROTO_UDP,"127.0.0.1",port); // int n; // fd_set read_ibits; // fd_set write_ibits; // struct timeval tvp = { 0, 0 }; FD_ZERO(&read_ibits); FD_SET(sock,&read_ibits); n = openairSelect(sock+1, &read_ibits, NULL, NULL, NULL); printf("Waiting is over\n"); FD_ISSET(sock, &read_ibits); for (mac_xface->frame=0; mac_xface->frame<oai_emulation.info.n_frames; mac_xface->frame++) { int dir_flag=0; printf("=============== Frame Number %d ============= \n ",mac_xface->frame); /* // Handling the cooperation Flag if (cooperation_flag == 2) { if ((PHY_vars_eNB_g[0]->eNB_UE_stats[0].mode == PUSCH) && (PHY_vars_eNB_g[0]->eNB_UE_stats[1].mode == PUSCH)) PHY_vars_eNB_g[0]->cooperation_flag = 2; } */ // for dubugging the frame counter update_nodes(oai_emulation.info.time); enb_node_list = get_current_positions(oai_emulation.info.omg_model_enb, eNB, oai_emulation.info.time); ue_node_list = get_current_positions(oai_emulation.info.omg_model_ue, UE, oai_emulation.info.time); // update the position of all the nodes (eNB/CH, and UE/MR) every frame if (((int)oai_emulation.info.time % 10) == 0 ) { 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, MAX_NUM_MOB_TYPES); 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); } } 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, MAX_NUM_MOB_TYPES); LOG_D (OMG, "[eNB] 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 (eNB_id, eNB, new_omg_model, oai_emulation.info.time); } } } #ifdef DEBUG_OMG if ((((int) oai_emulation.info.time) % 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 if (oai_emulation.info.n_frames_flag == 0){ // if n_frames not set by the user then let the emulation run to infinity mac_xface->frame %=(oai_emulation.info.n_frames-1); // set the emulation time based on 1ms subframe number oai_emulation.info.time += 0.01; // emu time in s } else { // user set the number of frames for the emulation // let the time go faster to see the effect of mobility oai_emulation.info.time += 0.1; } /* check if the openair channel model is activated used for PHY abstraction */ /* if ((oai_emulation.info.ocm_enabled == 1)&& (ethernet_flag == 0 )) { extract_position(enb_node_list, enb_data, NB_eNB_INST); extract_position(ue_node_list, ue_data, NB_UE_INST); for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) { calc_path_loss (enb_data[eNB_id], ue_data[UE_id], eNB2UE[eNB_id][UE_id], oai_emulation.environment_system_config,ShaF[(int)ue_data[UE_id]->x][(int)ue_data[UE_id]->y]); UE2eNB[UE_id][eNB_id]->path_loss_dB = eNB2UE[eNB_id][UE_id]->path_loss_dB; printf("[CHANNEL_SIM] Pathloss bw enB %d at (%f,%f) and UE%d at (%f,%f) is %f (ShaF %f)\n", eNB_id,enb_data[eNB_id]->x,enb_data[eNB_id]->y,UE_id,ue_data[UE_id]->x,ue_data[UE_id]->y, eNB2UE[eNB_id][UE_id]->path_loss_dB, ShaF[(int)ue_data[UE_id]->x][(int)ue_data[UE_id]->y]); } } } */ // else { for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) { eNB2UE[eNB_id][UE_id]->path_loss_dB = -105 + snr_dB; //UE2eNB[UE_id][eNB_id]->path_loss_dB = -105 + snr_dB; if (eNB_id == (UE_id % NB_eNB_INST)) UE2eNB[UE_id][eNB_id]->path_loss_dB = -105 + snr_dB - 10; else UE2eNB[UE_id][eNB_id]->path_loss_dB = -105 + sinr_dB - 10; #ifdef DEBUG_SIM printf("[SIM] Path loss from eNB %d to UE %d => %f dB\n",eNB_id,UE_id,eNB2UE[eNB_id][UE_id]->path_loss_dB); printf("[SIM] Path loss from UE %d to eNB %d => %f dB\n",UE_id,eNB_id,UE2eNB[UE_id][eNB_id]->path_loss_dB); #endif } } // } else st2->EResp_FLAG=0; for (slot=0 ; slot<20 ; slot++) { printf("=============== Frame Number %d , Slot %d ============= \n ",mac_xface->frame,slot); last_slot = (slot - 1)%20; if (last_slot <0) last_slot+=20; next_slot = (slot + 1)%20; direction = subframe_select(frame_parms,next_slot>>1); if (direction == SF_DL) { dir_flag=1; } else if (direction == SF_UL) { dir_flag=2; } else {//it must be a special subframe if (next_slot%2==0) {//DL part dir_flag=1; } else {// UL part dir_flag=2; } } int count=0; if(dir_flag==1) { st2->EResp_FLAG=0; count=0; 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++) { send_exec_msg(next_slot,last_slot,mac_xface->frame,mac_xface->frame,slot,0,38810+eNB_id); printf("Waiting for Exec Msg Complete \n"); // n = openairIoSyncCreateThread_2(&this->m_io_sync); } // for loop while(count<NB_eNB_INST){ n=trig_wait((void*)&this->m_io_sync); count++; } 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++){ 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++) { //trigger message send_exec_msg(0,0,0,0,0,0,(35000+(10+eNB_id)+(20+UE_id))); } } usleep(5); // while(st2->EResp_FLAG<NB_eNB_INST) // { /* 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++){ 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++) { u2e_t[UE_id][eNB_id]->eNB_id=eNB_id; u2e_t[UE_id][eNB_id]->UE_id=UE_id; u2e_t[UE_id][eNB_id]->r_re0=r_re0_d[UE_id][eNB_id]; u2e_t[UE_id][eNB_id]->r_im0=r_im0_d[UE_id][eNB_id]; u2e_t[UE_id][eNB_id]->r_re=r_re[NB_eNB_INST+UE_id]; u2e_t[UE_id][eNB_id]->r_im=r_im[NB_eNB_INST+UE_id]; u2e_t[UE_id][eNB_id]->s_im=s_im[eNB_id]; u2e_t[UE_id][eNB_id]->s_re=s_re[eNB_id]; u2e_t[UE_id][eNB_id]->eNB2UE=eNB2UE[eNB_id][UE_id]; u2e_t[UE_id][eNB_id]->UE2eNB=UE2eNB[UE_id][eNB_id]; u2e_t[UE_id][eNB_id]->enb_data=enb_data[eNB_id]; u2e_t[UE_id][eNB_id]->ue_data=ue_data[UE_id]; u2e_t[UE_id][eNB_id]->next_slot=&next_slot; u2e_t[UE_id][eNB_id]->abstraction_flag=&abstraction_flag; u2e_t[UE_id][eNB_id]->frame_parms=frame_parms; // pthread_create (&thread[eNB_id][UE_id], NULL, do_DL_sig_channel_T,(void*)cthread); pthread_create (&cthr_d[UE_id][eNB_id], NULL, do_DL_sig_channel_T,(void*)(u2e_t[UE_id][eNB_id])); // pthread_join(cthr_d[UE_id][eNB_id], NULL); // pthread_join(cthr_d[UE_id][eNB_id], NULL); // pthread_join(thread[eNB_id][UE_id], NULL); // do_DL_sig_channel(eNB_id,UE_id,r_re0,r_im0,r_re[NB_eNB_INST+UE_id],r_im[NB_eNB_INST+UE_id],s_re[eNB_id],s_im[eNB_id],eNB2UE,enb_data, ue_data,next_slot,abstraction_flag,frame_parms); // do_DL_sig_channel(eNB_id,UE_id,r_re0_d[UE_id][eNB_id],r_im0_d[UE_id][eNB_id],r_re[NB_eNB_INST+UE_id],r_im[NB_eNB_INST+UE_id],s_re[eNB_id],s_im[eNB_id],eNB2UE,enb_data, ue_data,next_slot,abstraction_flag,frame_parms); } } */ // //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++){ //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++) { //pthread_join(cthr_d[UE_id][eNB_id], NULL); //} //} 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++){ clean_param(r_re[NB_eNB_INST+UE_id],r_im[NB_eNB_INST+UE_id],frame_parms); 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++) { channel_add(r_re[NB_eNB_INST+UE_id],r_im[NB_eNB_INST+UE_id],r_re0_d[UE_id][eNB_id],r_im0_d[UE_id][eNB_id],frame_parms); } } // if(UE_id==NB_UE_INST) // pthread_join(thread, NULL); //} 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++){ 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++) { // pthread_join(thread, NULL); //pthread_join(thread[eNB_id][UE_id], NULL); } } // } st2->EResp_FLAG=0; count=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++) if (mac_xface->frame >= (UE_id * 10)) { // activate UE only after 10*UE_id frames so that different UEs turn on separately send_exec_msg(next_slot,last_slot,mac_xface->frame,mac_xface->frame,slot,0,38820+UE_id); printf("Waiting for Exec Msg Complete \n"); //n = openairIoSyncCreateThread_2(&this->m_io_sync); // n=trig_wait((void*)&this->m_io_sync); } else{ st2->EResp_FLAG=st2->EResp_FLAG+1; count++; } while(count<NB_UE_INST){ n=trig_wait((void*)&this->m_io_sync); count++; } //while(st2->EResp_FLAG<NB_UE_INST) // { // n = select(this->m_io_sync.hfd, &read_ibits, NULL, NULL,NULL); // FD_ISSET(this->m_io_sync.io_sync_entries->fd_read, &read_ibits); // printf(".."); // } } else if(dir_flag==2) { st2->EResp_FLAG=0; count=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++) if (mac_xface->frame >= (UE_id * 10)) { // activate UE only after 10*UE_id frames so that different UEs turn on separately send_exec_msg(next_slot,last_slot,mac_xface->frame,mac_xface->frame,slot,0,38820+UE_id); // printf("Waiting for Exec Msg Complete \n"); // n = openairIoSyncCreateThread_2(&this->m_io_sync); // n=trig_wait((void*)&this->m_io_sync); } else{ st2->EResp_FLAG=st2->EResp_FLAG+1; count++; } while(count<NB_UE_INST){ n=trig_wait((void*)&this->m_io_sync); count++; } //while(st2->EResp_FLAG<NB_UE_INST) // { // n = select(this->m_io_sync.hfd, &read_ibits, NULL, NULL,NULL); // FD_ISSET(this->m_io_sync.io_sync_entries->fd_read, &read_ibits); // printf(".."); // } // do_UL_sig_channel2(1,0,r_re0,r_im0,r_re,r_im,s_re,s_im,UE2eNB,next_slot,abstraction_flag,frame_parms); // do_UL_sig_channel(r_re0,r_im0,r_re,r_im,s_re,s_im,UE2eNB,next_slot,abstraction_flag,frame_parms); 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++) { 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++){ e2u_t[eNB_id][UE_id]->eNB_id=eNB_id; e2u_t[eNB_id][UE_id]->UE_id=UE_id; e2u_t[eNB_id][UE_id]->r_re=r_re[eNB_id]; e2u_t[eNB_id][UE_id]->r_im=r_im[eNB_id]; e2u_t[eNB_id][UE_id]->r_re0=r_re0_u[eNB_id][UE_id]; e2u_t[eNB_id][UE_id]->r_im0=r_im0_u[eNB_id][UE_id]; e2u_t[eNB_id][UE_id]->s_im=s_im[NB_eNB_INST+UE_id]; e2u_t[eNB_id][UE_id]->s_re=s_re[NB_eNB_INST+UE_id]; e2u_t[eNB_id][UE_id]->eNB2UE=eNB2UE[eNB_id][UE_id]; e2u_t[eNB_id][UE_id]->UE2eNB=UE2eNB[UE_id][eNB_id]; e2u_t[eNB_id][UE_id]->enb_data=enb_data[eNB_id]; e2u_t[eNB_id][UE_id]->ue_data=ue_data[UE_id]; e2u_t[eNB_id][UE_id]->next_slot=&next_slot; e2u_t[eNB_id][UE_id]->abstraction_flag=&abstraction_flag; e2u_t[eNB_id][UE_id]->frame_parms=frame_parms; pthread_create (&cthr_u[eNB_id][UE_id], NULL, do_UL_sig_channel_T,(void*)e2u_t[eNB_id][UE_id]); // pthread_create (&thread[eNB_id][UE_id], NULL, do_UL_sig_channel_T,(void*)cthread); // do_UL_sig_channel(eNB_id,UE_id,r_re0,r_im0,r_re[eNB_id],r_im[eNB_id],s_re[NB_eNB_INST+UE_id],s_im[NB_eNB_INST+UE_id],UE2eNB,next_slot,abstraction_flag,frame_parms); // do_UL_sig_channel(eNB_id,UE_id,r_re0_u[eNB_id][UE_id],r_im0_u[eNB_id][UE_id],r_re[eNB_id],r_im[eNB_id],s_re[NB_eNB_INST+UE_id],s_im[NB_eNB_INST+UE_id],UE2eNB,next_slot,abstraction_flag,frame_parms); } } 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++) { 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++){ // pthread_join(thread[eNB_id][UE_id], NULL); pthread_join(cthr_u[eNB_id][UE_id], NULL); } } 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++) { clean_param(r_re[eNB_id],r_im[eNB_id],frame_parms); 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++){ channel_add(r_re[eNB_id],r_im[eNB_id],r_re0_u[eNB_id][UE_id],r_im0_u[eNB_id][UE_id],frame_parms); } } // } st2->EResp_FLAG=0; count=0; 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++) { send_exec_msg(next_slot,last_slot,mac_xface->frame,mac_xface->frame,slot,0,38810+eNB_id); // n = openairIoSyncCreateThread_2(&this->m_io_sync); // n=trig_wait((void*)&this->m_io_sync); // printf("Waiting for Exec Msg Complete \n"); } // for loop while(count<NB_eNB_INST){ n=trig_wait((void*)&this->m_io_sync); count++; } // while(st2->EResp_FLAG<NB_eNB_INST) // { // n = select(this->m_io_sync.hfd, &read_ibits, NULL, NULL,NULL); // FD_ISSET(this->m_io_sync.io_sync_entries->fd_read, &read_ibits); // // printf(".."); // } } if ((last_slot == 1) && (mac_xface->frame == 0) && (abstraction_flag == 0) && (oai_emulation.info.n_frames == 1)) { // write_output ("dlchan0.m", "dlch0", // &(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][0][0]), // (6 * (PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)), 1, 1); // write_output ("dlchan1.m", "dlch1", // &(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[1][0][0]), // (6 * (PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)), 1, 1); // write_output ("dlchan2.m", "dlch2", // &(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[2][0][0]), // (6 * (PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)), 1, 1); // write_output ("pbch_rxF_comp0.m", "pbch_comp0", // PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->rxdataF_comp[0], 6 * 12 * 4, 1, 1); // write_output ("pbch_rxF_llr.m", "pbch_llr", // PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->llr, (frame_parms->Ncp == 0) ? 1920 : 1728, 1, 4); } /* if ((last_slot==1) && (mac_xface->frame==1)) { write_output("dlsch_rxF_comp0.m","dlsch0_rxF_comp0",PHY_vars_UE->lte_ue_dlsch_vars[eNB_id]->rxdataF_comp[0],300*(-(PHY_vars_UE->lte_frame_parms.Ncp*2)+14),1,1); write_output("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",PHY_vars_UE->lte_ue_pdcch_vars[eNB_id]->rxdataF_comp[0],4*300,1,1); } */ if (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_I(EMU,"sleep frame %d, average time difference %ldns, CURRENT TIME DIFF %dus, avgerage difference from the target %dus\n", mac_xface->frame, 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; } else if (td_avg > (TARGET_SF_TIME_NS + SF_DEVIATION_OFFSET_NS)) { sleep_time_us-= SLEEP_STEP_US; } }// end if next_slot%2 } //end of slot
Layer::Layer(const int pnnodes, const int nnodes, const double lrate, const double lambda, ActFunc actfunc) : lrate(lrate), lambda(lambda), act(actfunc.act), actd(actfunc.actd), W(pnnodes+1, nnodes), grad(pnnodes+1, nnodes) { randominit(6.0); }
/* MAIN------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { //Initialization struct sockaddr_in localaddr,remoteaddr; SOCKET s; char send_buffer[BUFFESIZE],receive_buffer[BUFFESIZE]; int n,bytes,addrlen; int SN_expected = 0; //added. int SN_checked = -1; //added. addrlen = sizeof(remoteaddr); memset(&localaddr,0,sizeof(localaddr));//clean up the structure memset(&remoteaddr,0,sizeof(remoteaddr));//clean up the structure randominit(); // WSSTARTUP if (WSAStartup(WSVERS, &wsadata) != 0) { WSACleanup(); printf("WSAStartup failed\n"); } //SOCKET s = socket(PF_INET, SOCK_DGRAM, 0); if (s <0) { printf("socket failed\n"); } localaddr.sin_family = AF_INET; localaddr.sin_addr.s_addr = INADDR_ANY;//server address should be local if (argc != 4) { printf("2012 code USAGE: server port lossesbit(0 or 1) damagebit(0 or 1)\n"); exit(1); } localaddr.sin_port = htons((u_short)atoi(argv[1])); int remotePort=1234; packets_damagedbit=atoi(argv[3]); packets_lostbit=atoi(argv[2]); if (packets_damagedbit<0 || packets_damagedbit>1 || packets_lostbit<0 || packets_lostbit>1) { printf("2012 code USAGE: server port lossesbit(0 or 1) damagebit(0 or 1)\n"); exit(0); } //REMOTE HOST IP AND PORT remoteaddr.sin_family = AF_INET; remoteaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); remoteaddr.sin_port = htons(remotePort); //int counter=0; //BIND if (bind(s,(struct sockaddr *)(&localaddr),sizeof(localaddr)) != 0) { printf("Bind failed!\n"); exit(0); } FILE *fout=fopen("file1_saved.txt","w");// Open file to save the incoming packets while (1) { //RECEIVE bytes = recvfrom(s, receive_buffer, SEGMENTSIZE, 0,(struct sockaddr *)(&remoteaddr),&addrlen); //PROCESS REQUEST n=0; while (n<bytes) { n++; if ((bytes < 0) || (bytes == 0)) break; if (receive_buffer[n] == '\n') /*end on a LF*/ { receive_buffer[n] = '\0'; break; } if (receive_buffer[n] == '\r') /*ignore CRs*/ receive_buffer[n] = '\0'; } if ((bytes < 0) || (bytes == 0)) break; printf("\n================================================\n"); printf("RECEIVED --> %s \n",receive_buffer); /** * @brief Coding from here */ //"close" handling if (strncmp(receive_buffer,"CLOSE",5)==0) {//if client says "CLOSE", the last packet for the file was sent. Close the file //Remember that the packet carrying "CLOSE" may be lost or damaged! fclose(fout); closesocket(s); printf("Server saved file1_saved.txt \n");//you have to manually check to see if this file is identical to file1.txt exit(0); } //SN check and CRC check.if pass save the line. if(wy_SN_check(SN_expected,receive_buffer)&& wy_CRC_check(receive_buffer)) { save_line_without_header(receive_buffer,fout); //save without header. SN_expected++; SN_checked ++; } //default :build and send ACK using SN_checked. if(SN_checked >= 0) { wy_ACK_build(send_buffer, SN_checked); send_unreliably(s,send_buffer,remoteaddr); } /** * @brief coding end. */ } closesocket(s); exit(0); }
int main(int argc, char *argv[]) { int ret,ret2; unsigned int errors,uerrors,errors2,crc_misses,iterations,trials,trials2,block_length,errors3,trials3; double SNR,sigma,rate=.5; unsigned char qbits,mcs; char done0=0; char done1=1; char done2=1; unsigned int coded_bits; unsigned char NB_RB=25; int num_pdcch_symbols = 1; int subframe = 6; randominit(0); logInit(); lte_param_init(1,1,1,0,0,3); PHY_vars_eNB->dlsch_eNB[0][0] = new_eNB_dlsch(1,8,NB_RB,0); PHY_vars_UE->dlsch_ue[0][0] = new_ue_dlsch(1,8,4,NB_RB,0); PHY_vars_eNB->dlsch_eNB[0][1] = new_eNB_dlsch(1,8,NB_RB,0); PHY_vars_UE->dlsch_ue[0][1] = new_ue_dlsch(1,8,4,NB_RB,0); if (argc>1) mcs = atoi(argv[1]); else mcs = 0; printf("NB_RB %d\n",NB_RB); DLSCH_alloc_pdu.rah = 0; DLSCH_alloc_pdu.rballoc = DLSCH_RB_ALLOC; DLSCH_alloc_pdu.TPC = 0; DLSCH_alloc_pdu.dai = 0; DLSCH_alloc_pdu.harq_pid = 0; //DLSCH_alloc_pdu2.tb_swap = 0; DLSCH_alloc_pdu.mcs = mcs; DLSCH_alloc_pdu.ndi = 1; DLSCH_alloc_pdu.rv = 0; if (argc>2) qbits = atoi(argv[2]); else qbits = 4; printf("Quantization bits %d\n",qbits); generate_eNB_dlsch_params_from_dci(subframe, &DLSCH_alloc_pdu, 0x1234, format1, PHY_vars_eNB->dlsch_eNB[0], &PHY_vars_eNB->lte_frame_parms, PHY_vars_eNB->pdsch_config_dedicated, SI_RNTI, 0, P_RNTI, 0); //change this later generate_ue_dlsch_params_from_dci(subframe, &DLSCH_alloc_pdu, C_RNTI, format1, PHY_vars_UE->dlsch_ue[0], &PHY_vars_UE->lte_frame_parms, PHY_vars_UE->pdsch_config_dedicated, SI_RNTI, 0, P_RNTI); coded_bits = get_G(&PHY_vars_eNB->lte_frame_parms, PHY_vars_eNB->dlsch_eNB[0][0]->harq_processes[0]->nb_rb, PHY_vars_eNB->dlsch_eNB[0][0]->harq_processes[0]->rb_alloc, get_Qm(mcs), 1, num_pdcch_symbols, 0, subframe); printf("Coded_bits (G) = %d\n",coded_bits); block_length = dlsch_tbs25[get_I_TBS(mcs)][NB_RB-1]>>3; printf("Block_length = %d bytes (%d bits, rate %f), mcs %d, I_TBS %d, F %d, NB_RB %d\n",block_length, dlsch_tbs25[get_I_TBS(mcs)][NB_RB-1],(double)dlsch_tbs25[get_I_TBS(mcs)][NB_RB-1]/coded_bits, mcs,get_I_TBS(mcs),PHY_vars_eNB->dlsch_eNB[0][0]->harq_processes[0]->F,NB_RB); for (SNR=-5; SNR<15; SNR+=.1) { sigma = pow(10.0,-.05*SNR); printf("\n\nSNR %f dB => sigma %f\n",SNR,sigma); errors=0; crc_misses=0; errors2=0; errors3=0; iterations=0; if (done0 == 0) { ret = test_logmap8(PHY_vars_eNB->dlsch_eNB[0][0], PHY_vars_UE->dlsch_ue[0][0], coded_bits, NB_RB, sigma, // noise standard deviation qbits, block_length, // block length bytes NTRIALS, &errors, &trials, &uerrors, &crc_misses, &iterations, num_pdcch_symbols, subframe); if (ret>=0) printf("%f,%f,%f,%f\n",SNR,(double)errors/trials,(double)crc_misses/trials,(double)iterations/trials); if (((double)errors/trials) < 1e-2) done0=1; } if ((done0==1) && (done1==1) && (done2==1)) { printf("done\n"); break; } } return(0); }
/* MAIN------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { //Initialization struct sockaddr_in localaddr,remoteaddr; SOCKET s; char send_buffer[BUFFESIZE],receive_buffer[BUFFESIZE]; int n,bytes,addrlen; int SN_expected = 0; //added. int SN_checked = -1; //added. addrlen = sizeof(remoteaddr); memset(&localaddr,0,sizeof(localaddr));//clean up the structure memset(&remoteaddr,0,sizeof(remoteaddr));//clean up the structure randominit(); // WSSTARTUP if (WSAStartup(WSVERS, &wsadata) != 0) { WSACleanup(); printf("WSAStartup failed\n"); } //SOCKET s = socket(PF_INET, SOCK_DGRAM, 0); if (s <0) { printf("socket failed\n"); } localaddr.sin_family = AF_INET; localaddr.sin_addr.s_addr = INADDR_ANY;//server address should be local if (argc != 4) { printf("2012 code USAGE: server port lossesbit(0 or 1) damagebit(0 or 1)\n"); exit(1); } localaddr.sin_port = htons((u_short)atoi(argv[1])); int remotePort=1234; packets_damagedbit=atoi(argv[3]); packets_lostbit=atoi(argv[2]); if (packets_damagedbit<0 || packets_damagedbit>1 || packets_lostbit<0 || packets_lostbit>1) { printf("2012 code USAGE: server port lossesbit(0 or 1) damagebit(0 or 1)\n"); exit(0); } //REMOTE HOST IP AND PORT remoteaddr.sin_family = AF_INET; remoteaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); remoteaddr.sin_port = htons(remotePort); int counter=0; //BIND if (bind(s,(struct sockaddr *)(&localaddr),sizeof(localaddr)) != 0) { printf("Bind failed!\n"); exit(0); } FILE *fout=fopen("file1_saved.txt","w");// Open file to save the incoming packets while (1) { //RECEIVE bytes = recvfrom(s, receive_buffer, SEGMENTSIZE, 0,(struct sockaddr *)(&remoteaddr),&addrlen); //PROCESS REQUEST n=0; while (n<bytes) { n++; if ((bytes < 0) || (bytes == 0)) break; if (receive_buffer[n] == '\n') /*end on a LF*/ { receive_buffer[n] = '\0'; break; } if (receive_buffer[n] == '\r') /*ignore CRs*/ receive_buffer[n] = '\0'; } if ((bytes < 0) || (bytes == 0)) break; printf("\n================================================\n"); printf("RECEIVED --> %s \n",receive_buffer); /** * @brief Coding from here */ printf("Alan: when the expected SN is 3...%d...",wy_SN_check(3, receive_buffer)); if (strncmp(receive_buffer,"PACKET",6)==0) //check { sscanf(receive_buffer, "PACKET %d",&counter); //SEND ACK sprintf(send_buffer,"ACKNOW %d \r\n",counter); send_unreliably(s,send_buffer,remoteaddr); //save the received line without header save_line_without_header(receive_buffer,fout); } else { if (strncmp(receive_buffer,"CLOSE",5)==0) {//if client says "CLOSE", the last packet for the file was sent. Close the file //Remember that the packet carrying "CLOSE" may be lost or damaged! fclose(fout); closesocket(s); printf("Server saved file1_saved.txt \n");//you have to manually check to see if this file is identical to file1.txt exit(0); } else {//it is not PACKET nor CLOSE, therefore there might be a damaged packet //in this assignment, CLOSE always arrive (read UDP_supporting_functions_2012.c to see why...) //do nothing, ignoring the damaged packet? Or send a negative ACK? It is up to you to decide. } /** * @brief coding end. */ } } closesocket(s); exit(0); }
int main(int argc, char* argv[]) { // Fill input vector with complex sinusoid int nb_antennas = 1; int length = 100000; int i,j,n; double input_amp = pow(10.0,(.05*INPUT_dBm))/sqrt(2); double nf[2] = {3.0,3.0}; double ip =0.0; double path_loss_dB = -90, rx_gain_dB = 125; double tx_pwr, rx_pwr; uint32_t **input = malloc(nb_antennas*sizeof(uint32_t*)); uint32_t **output = malloc(nb_antennas*sizeof(uint32_t*)); double **s_re = malloc(nb_antennas*sizeof (double *)); double **s_im = malloc(nb_antennas*sizeof (double *)); double **r_re = malloc(nb_antennas*sizeof (double *)); double **r_im = malloc(nb_antennas*sizeof (double *)); channel_desc_t *channel; srand(0); randominit(0); set_taus_seed(0); channel = new_channel_desc_scm(nb_antennas, nb_antennas, AWGN, 7.68e6, 0, 0, path_loss_dB); for (i=0; i<nb_antennas; i++) { s_re[i] = (double *)malloc(length * sizeof (double )); s_im[i] = (double *)malloc(length * sizeof (double )); r_re[i] = (double *)malloc(length * sizeof (double )); r_im[i] = (double *)malloc(length * sizeof (double )); input[i] = (uint32_t*)malloc(length * sizeof(uint32_t)); output[i] = (uint32_t*)malloc(length * sizeof(uint32_t)); } for (i=0; i<nb_antennas; i++) { // generate a random QPSK signal for (j=0; j<length/2; j++) { input[i][j] = QPSK[taus()&3]; } } tx_pwr = dac_fixed_gain(s_re, s_im, input, 0, nb_antennas, length, 0, 512, 14, 15.0); multipath_channel(channel,s_re,s_im,r_re,r_im, length,0); rf_rx_simple(r_re, r_im, nb_antennas, length, 1.0/7.68e6 * 1e9,// sampling time (ns) rx_gain_dB - 66.227); /* rf_rx(r_re, r_im, nb_antennas, length, 1.0/6.5e6 * 1e9,// sampling time (ns) 1000.0 , //freq offset (Hz) 0.0, //drift (Hz) NOT YET IMPLEMENTED nf, //noise_figure NOT YET IMPLEMENTED -INPUT_dBm, //rx_gain (dB) 200, // IP3_dBm (dBm) &ip, // initial phase 30.0e3, // pn_cutoff (kHz) -500.0, // pn_amp (dBc) -0.0, // IQ imbalance (dB), 0.0); // IQ phase imbalance (rad) */ adc(r_re, r_im, 0, 0, output, nb_antennas, length, 12); write_output("s_im.m","s_im",s_im[0],length,1,7); write_output("s_re.m","s_re",s_re[0],length,1,7); write_output("r_im.m","r_im",r_im[0],length,1,7); write_output("r_re.m","r_re",r_re[0],length,1,7); write_output("input.m","rfin",input[0],length,1,1); write_output("output.m","rfout",output[0],length,1,1); }
/* MAIN------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { // WSSTARTUP if (WSAStartup(WSVERS, &wsadata) != 0) { WSACleanup(); printf("WSAStartup failed\n"); } // Initialization memset(&localaddr, 0, sizeof(localaddr));//clean up int localPort=1234; localaddr.sin_family = AF_INET; localaddr.sin_addr.s_addr = INADDR_ANY;//server address should be local localaddr.sin_port = htons(localPort); memset(&remoteaddr, 0, sizeof(remoteaddr));//clean up randominit(); SOCKET s; char send_buffer[BUFFESIZE],receive_buffer[BUFFESIZE]; remoteaddr.sin_family = AF_INET; // Dealing with user's arguments if (argc != 5) { printf("2011 code USAGE: client remote_IP-address port lossesbit(0 or 1) damagebit(0 or 1)\n"); exit(1); } remoteaddr.sin_addr.s_addr = inet_addr(argv[1]);//IP address remoteaddr.sin_port = htons((u_short)atoi(argv[2]));//always get the port number packets_lostbit=atoi(argv[3]); packets_damagedbit=atoi(argv[4]); if (packets_damagedbit<0 || packets_damagedbit>1 || packets_lostbit<0 || packets_lostbit>1) { printf("2011 code USAGE: client remote_IP-address port lossesbit(0 or 1) damagebit(0 or 1)\n"); exit(0); } //CREATE CLIENT'S SOCKET s = socket(AF_INET, SOCK_DGRAM, 0);//this is a UDP socket if (s < 0) { printf("socket failed\n"); exit(1); } //NONBLOCKING OPTION for Windows u_long iMode=1; ioctlsocket(s,FIONBIO,&iMode); //Open A TEXT FILE int counter=0;//sequence of packets int ackcounter=0; char temp_buffer[BUFFESIZE]; char CRC_str[BUFFESIZE]; FILE *fin=fopen("file1_Windows.txt","r"); if(fin==NULL) { printf("cannot open file\n"); exit(0); } while (1) { memset(send_buffer, 0, sizeof(send_buffer));//clean up the send_buffer before reading the next line fgets(send_buffer,SEGMENTSIZE,fin); if (!feof(fin)) { //add a headert to the packet with the sequence number sprintf(temp_buffer,"PACKET %d ",counter); counter++; strcat(temp_buffer,send_buffer); strcpy(send_buffer,temp_buffer); //---------coding------- temp_buffer[strlen(temp_buffer)-1] = 0; sprintf(CRC_str,"%d ",CRCpolynomial(temp_buffer)); strcat(CRC_str,send_buffer); strcpy(send_buffer, CRC_str); //---------------------- send_unreliably(s,send_buffer, remoteaddr); Sleep(1000); //RECEIVE memset(receive_buffer, 0, sizeof(receive_buffer)); recv_nonblocking(s,receive_buffer, remoteaddr);//you can replace this, but use MSG_DONTWAIT to get non-blocking recv printf("RECEIVE -->%s__\n",receive_buffer); //printf("@Alan the CRC check result is %d\n",wy_CRC_check(receive_buffer)); Sleep(1000); } else { printf("end of the file \n"); memset(send_buffer, 0, sizeof(send_buffer)); sprintf(send_buffer,"CLOSE \r\n"); send_unreliably(s,send_buffer,remoteaddr);//we actually send this reliably, read UDP_supporting_functions_2012.c break; } } //CLOSESOCKET printf("closing everything on the client's side ... \n"); fclose(fin); closesocket(s); exit(0); }
static void consinit(void) { todinit(); randominit(); }