- Fix: avoid infinite loop on mulitcast read thread if no data to read

Pre-ci test passed

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4000 818b1a75-f10b-46b9-bf7c-635c3b92a50f
This commit is contained in:
Cedric Roux
2013-06-25 09:05:02 +00:00
commit 56c66c09aa
4111 changed files with 2133103 additions and 0 deletions
+147
View File
@@ -0,0 +1,147 @@
/*
May 10, 2001
Modified in June, 2001, to include the length non multiple of 8
crc_byte.c
Byte oriented implementation of CRC's
*/
#include "rtos_header.h"
#include "platform_types.h"
/*ref 25.222 v4.0.0 , p12 */
/* the highest degree is set by default */
unsigned int poly24 = 0x80006100; // 1000 0000 0000 0000 0110 0001 D^24 + D^23 + D^6 + D^5 + D + 1
unsigned int poly16 = 0x10210000; // 0001 0000 0010 0001 D^16 + D^12 + D^5 + 1
unsigned int poly12 = 0x80F00000; // 1000 0000 1111 D^12 + D^11 + D^3 + D^2 + D + 1
unsigned int poly8 = 0x9B000000; // 1001 1011 D^8 + D^7 + D^4 + D^3 + D + 1
/*********************************************************
For initialization && verification purposes,
bit by bit implementation with any polynomial
The first bit is in the MSB of each byte
*********************************************************/
static unsigned int
crcbit (unsigned char * inputptr, int octetlen, unsigned int poly)
{
unsigned int i, crc = 0, c;
while (octetlen-- > 0) {
c = (*inputptr++) << 24;
for (i = 8; i != 0; i--) {
if ((1 << 31) & (c ^ crc))
crc = (crc << 1) ^ poly;
else
crc <<= 1;
c <<= 1;
}
}
return crc;
}
/*********************************************************
crc table initialization
*********************************************************/
static unsigned int crc24Table[256];
static unsigned short crc16Table[256];
static unsigned short crc12Table[256];
static unsigned char crc8Table[256];
void
crcTableInit ()
{
unsigned char c = 0;
do {
crc24Table[c] = crcbit (&c, 1, poly24);
crc16Table[c] = (unsigned short) (crcbit (&c, 1, poly16) >> 16);
crc12Table[c] = (unsigned short) (crcbit (&c, 1, poly12) >> 16);
crc8Table[c] = (unsigned char) (crcbit (&c, 1, poly8) >> 24);
} while (++c);
}
/*********************************************************
Byte by byte implementations,
assuming initial byte is 0 padded (in MSB) if necessary
*********************************************************/
unsigned int
crc24 (unsigned char * inptr, int bitlen)
{
int octetlen, resbit;
unsigned int crc = 0;
octetlen = bitlen / 8; /* Change in octets */
resbit = (bitlen % 8);
while (octetlen-- > 0) {
crc = (crc << 8) ^ crc24Table[(*inptr++) ^ (crc >> 24)];
}
if (resbit > 0)
crc = (crc << resbit) ^ crc24Table[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))];
return crc;
}
unsigned int
crc16 (unsigned char * inptr, int bitlen)
{
int octetlen, resbit;
unsigned int crc = 0;
octetlen = bitlen / 8; /* Change in octets */
resbit = (bitlen % 8);
while (octetlen-- > 0) {
crc = (crc << 8) ^ (crc16Table[(*inptr++) ^ (crc >> 24)] << 16);
}
if (resbit > 0)
crc = (crc << resbit) ^ (crc16Table[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))] << 16);
return crc;
}
unsigned int
crc12 (unsigned char * inptr, int bitlen)
{
int octetlen, resbit;
unsigned int crc = 0;
octetlen = bitlen / 8; /* Change in octets */
resbit = (bitlen % 8);
while (octetlen-- > 0) {
crc = (crc << 8) ^ (crc12Table[(*inptr++) ^ (crc >> 24)] << 16);
}
if (resbit > 0)
crc = (crc << resbit) ^ (crc12Table[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))] << 16);
return crc;
}
unsigned int
crc8 (unsigned char * inptr, int bitlen)
{
int octetlen, resbit;
unsigned int crc = 0;
octetlen = bitlen / 8; /* Change in octets */
resbit = (bitlen % 8);
while (octetlen-- > 0) {
crc = crc8Table[(*inptr++) ^ (crc >> 24)] << 24;
}
if (resbit > 0)
crc = (crc << resbit) ^ (crc8Table[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))] << 24);
return crc;
}
/*******************************************************************/
/**
Test code
********************************************************************/
/* #ifdef MAIN
#include <stdio.h>
main()
{
unsigned char test[] = "Thebigredfox";
crcTableInit();
printf("%x\n", crcbit(test, sizeof(test) - 1, poly24));
printf("%x\n", crc24(test, (sizeof(test) - 1)*8));
printf("%x\n", crcbit(test, sizeof(test) - 1, poly8));
printf("%x\n", crc8(test, (sizeof(test) - 1)*8));
}
#endif */
+238
View File
@@ -0,0 +1,238 @@
/*******************************************************************************
Eurecom OpenAirInterface
Copyright(c) 1999 - 2011 Eurecom
This program is free software; you can redistribute it and/or modify it
under the terms and conditions of the GNU General Public License,
version 2, as published by the Free Software Foundation.
This program is distributed in the hope it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
The full GNU General Public License is included in this distribution in
the file called "COPYING".
Contact Information
Openair Admin: openair_admin@eurecom.fr
Openair Tech : openair_tech@eurecom.fr
Forums : http://forums.eurecom.fsr/openairinterface
Address : Eurecom, 2229, route des crêtes, 06560 Valbonne Sophia Antipolis, France
*******************************************************************************/
/*! \file oml.c
* \brief Data structure for distribution libraries
* \author N. Nikaein and A. Hafsaoui
* \date 2011
* \version 1.0
* \company Eurecom
* \email: openair_tech@eurecom.fr
* \note
* \warning
*/
#include <stdio.h>
#include <math.h>
#include <errno.h>
#include "oml.h"
static int x, y, z;
void init_seeds(int seed){
set_taus_seed(seed);
LOG_I(OTG,"set taus seed to %d done \n", seed);
}
double uniform_rng() {
double random;
random = (double)taus(OTG)/((double)0xffffffff);
//LOG_D(OTG,"Uniform taus random number= %lf\n", random);
return random;
}
// Uniform Distribution using the Uniform_Random_Number_Generator
double uniform_dist(int min, int max) {
double uniform_rn;
uniform_rn = (max - min) * uniform_rng() + min;
LOG_T(OTG,"Uniform Random Nb = %lf, (min %d, max %d)\n", uniform_rn, min, max);
return uniform_rn;
}
// Gaussian Distribution using Box-Muller Transformation
double gaussian_dist(double mean, double std_dev) {
double x_rand1,x_rand2, w, gaussian_rn_1;
do {
do {
x_rand1 = 2.0 * uniform_rng() - 1;
x_rand2 = 2.0 * uniform_rng() - 1;
w = x_rand1 * x_rand1 + x_rand2 * x_rand2;
} while (w >= 1.0);
w = sqrt((-2.0 * log(w)) / w);
gaussian_rn_1 = (std_dev * (x_rand1 * w)) + mean;
} while (gaussian_rn_1 <= 0);
LOG_T(OTG,"Gaussian Random Nb= %lf (mean %lf, deviation %lf)\n", gaussian_rn_1, mean, std_dev);
return gaussian_rn_1;
}
// Exponential Distribution using the standard natural logarithmic transformations
double exponential_dist(double lambda) {
double exponential_rn;
if (log(uniform_rng()) > 0)
exponential_rn = log(uniform_rng()) / lambda;
else
exponential_rn = -log(uniform_rng()) / lambda;
LOG_T(OTG,"Exponential Random Nb = %lf (lambda %lf)\n", exponential_rn, lambda);
return exponential_rn;
}
// Poisson Distribution using Knuths Algorithm
double poisson_dist(double lambda){
double poisson_rn, L, p, u;
int k = 0;
p = 1;
L = exp(-lambda);
do {
u = uniform_rng();
p = p * u;
k += 1;
} while (p > L);
poisson_rn = k - 1;
LOG_T(OTG,"Poisson Random Nb = %lf (lambda %lf)\n", poisson_rn, lambda);
return poisson_rn;
}
double weibull_dist(double scale, double shape){
double weibull_rn;
if ((scale<=0)||(shape<=0)){
LOG_W(OTG,"Weibull :: scale=%.2f or shape%.2f <0 , adjust to new values: sale=3, shape=4 \n", scale,shape);
scale=3;
shape=4;
}
weibull_rn=scale * pow(-log(1-uniform_rng()), 1/shape);
LOG_T(OTG,"Weibull Random Nb = %lf (scale=%.2f, shape=%.2f)\n", weibull_rn, scale,shape);
return weibull_rn;
}
double pareto_dist(double scale, double shape) {
double pareto_rn;
if ((scale<=0)||(shape<=0)){
LOG_W(OTG,"Pareto :: scale=%.2f or shape%.2f <0 , adjust new values: sale=3, shape=4 \n", scale,shape);
scale=3;
shape=4;
}
pareto_rn=scale * pow(1/(1-uniform_rng()), 1/shape);
LOG_T(OTG,"Pareto Random Nb = %lf (scale=%.2f, shape=%.2f)\n", pareto_rn,scale,shape);
return pareto_rn;
}
double gamma_dist(double scale, double shape) {
double gamma_rn, mult_var=1;
int i, shape_int;
shape_int=ceil(shape);
if ((scale<=0)||(shape_int<=0)){
LOG_W(OTG,"Gamma :: scale=%.2f or shape%.2f <0 , adjust to new values: sale=0.5, shape=25 \n", scale,shape);
scale=0.5;
shape=25;
}
for(i=1;i<=shape_int;i++){
mult_var=mult_var*uniform_rng();
}
gamma_rn= (-1/scale)*log(mult_var);
LOG_T(OTG,"Gamma Random Nb = %lf (scale=%.2f, shape=%.2f)\n", gamma_rn, scale, shape);
return gamma_rn;
}
double cauchy_dist(double scale, double shape ) {
double cauchy_rn;
if ((scale<=0)||(shape<=0)){
LOG_W(OTG,"Cauchy :: scale=%.2f or shape%.2f <0 , new values: sale=2, shape=10 \n", scale,shape);
scale=2;
shape=10;
}
cauchy_rn= scale*tan(PI*(uniform_rng()-0.5)) + shape;
if (cauchy_rn<0){
cauchy_rn=fabs(cauchy_rn);
LOG_T(OTG,"Cauchy Random Nb = %lf <0 (scale=%.2f, shape=%.2f), we use absolute value\n", cauchy_rn, scale, shape);
}
else
LOG_T(OTG,"Cauchy Random Nb = %lf (scale=%.2f, shape=%.2f)\n", cauchy_rn, scale, shape);
return cauchy_rn;
}
double lognormal_dist(double mean, double std_dev){
double lognormal_rn;
lognormal_rn= exp(gaussian_dist(mean, std_dev));
return lognormal_rn;
}
double wichman_hill() { // not used
double temp, random;
int modx = x % 177;
int mody = y % 176;
int modz = z % 178;
//First Generator
x = (171 * modx) - (2 * modx);
if (x < 0)
x += 30269;
//Second Generator
y = (172 * mody) - (35 * mody);
if (y < 0)
y += 30307;
//Third Generator
z = (170 * modz) - (63 * modz);
if (z < 0)
z += 30323;
temp = (x / 30269.0) + (y / 30307.0) + (z / 30323.0);
random = temp - (int)temp;
return random;
}
+190
View File
@@ -0,0 +1,190 @@
/*******************************************************************************
Eurecom OpenAirInterface
Copyright(c) 1999 - 2011 Eurecom
This program is free software; you can redistribute it and/or modify it
under the terms and conditions of the GNU General Public License,
version 2, as published by the Free Software Foundation.
This program is distributed in the hope it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
The full GNU General Public License is included in this distribution in
the file called "COPYING".
Contact Information
Openair Admin: openair_admin@eurecom.fr
Openair Tech : openair_tech@eurecom.fr
Forums : http://forums.eurecom.fsr/openairinterface
Address : Eurecom, 2229, route des crêtes, 06560 Valbonne Sophia Antipolis, France
*******************************************************************************/
/*! \file oml.h
* \brief Data structure for OCG of OpenAir emulator
* \author N. Nikaein and A. Hafsaoui
* \date 2011
* \version 1.0
* \company Eurecom
* \email: openair_tech@eurecom.fr
* \note
* \warning
*/
#ifndef __OML_H__
#define __OML_H__
#include <math.h>
#include <stdlib.h>
#include "../OTG/otg.h"
#define PI 3.14159265
/*! \fn void set_taus_seed(unsigned int seed_type);
* \brief initialize seeds used for the generation of taus random values
* \param[in] initial value
* \param[out]
* \note
* @ingroup _oml
*/
void set_taus_seed(unsigned int seed_type);
/*! \fn inline unsigned int taus(unsigned int comp);
* \brief compute random number
* \param[in] integer
* \param[out]
* \note
* @ingroup _oml
*/
inline unsigned int taus(unsigned int comp);
/*! \fn void init_seeds(int seed);
* \brief init values for wichman_hill algo
* \param[in] seed
* \param[out]
* \note
* @ingroup _oml
*/
void init_seeds(int seed);
/*! \fn double wichman_hill() ;
* \brief generates uniform random number with wichman_hill algo
* \param[in]
* \param[out] random number: wichman_hill
* \note
* @ingroup _oml
*/
double wichman_hill() ;
/*! \fn double uniform_rng();
* \brief generates uniform random number with algo: wichman_hill / random() / Taus
* \param[in]
* \param[out] random number
* \note
* @ingroup _oml
*/
double uniform_rng();
/*! \fn double uniform_dist(double min, double max);
* \brief
* \param[in] double min
* \param[in] double max
* \param[out] uniform number
* \note
* @ingroup _oml
*/
double uniform_dist(int min, int max);
/*! \fn double gaussian_dist(double mean, double std_dev);
* \brief
* \param[in] double mean
* \param[in] double standard deviation
* \param[out] exponential gaussian number
* \note
* @ingroup _oml
*/
double gaussian_dist(double mean, double std_dev);
/*! \fn double exponential_dist(double lambda);
* \brief
* \param[in] double lambda
* \param[out] exponential random number
* \note
* @ingroup _oml
*/
double exponential_dist(double lambda);
/*! \fn double poisson_dist(double lambda);
* \brief generates random numbers for the poisson distribution
* \param[in] lambda used for poisson distrib configuration
* \param[out] poisson random number
* \note
* @ingroup _oml
*/
double poisson_dist(double lambda);
/*! \fn double weibull_dist(double scale, double shape);
* \brief generates random numbers for the Weibull distribution with scale parameter, and shape parameter.
* \param[in] scale parameter, and shape parameter.
* \param[out] weibull random number
* \note Formula (http://www.xycoon.com/wei_random.htm)
* @ingroup _oml
*/
double weibull_dist(double scale, double shape);
/*! \fn double pareto_dist(double scale, double shape);
* \brief enerates random numbers for the pareto distribution with scale parameter, and shape parameter.
* \param[in] double scale
* \param[in] double shape
* \param[out] pareto random number
* \note Formula (http://www.xycoon.com/par_random.htm)
* @ingroup _oml
*/
double pareto_dist(double scale, double shape);
/*! \fn double gamma_dist(double scale, double shape);
* \brief generates random numbers for the gamma distribution with scale parameter, and shape parameter.
* \param[in] double scale
* \param[in] double shape
* \param[out] gamma random number
* \note Formula (http://www.xycoon.com/gamma_random.htm)
* @ingroup _oml
*/
double gamma_dist(double scale, double shape);
/*! \fn double cauchy_dist(double scale, double shape);
* \brief generates random numbers for the cauchy distribution with scale parameter, and shape parameter.
* \param[in] double scale
* \param[in] double shape
* \param[out] cauchy random number
* \note Formula(http://www.xycoon.com/nor_relationships3.htm)
* @ingroup _oml
*/
double cauchy_dist(double scale, double shape);
/*! \fn double double lognormal_dist(double mean, double std_dev)
* \brief generates random numbers for the log normal distribution with mean parameter and standard deviation parameter.
* \param[in] double mean
* \param[in] double std_dev
* \param[out] lognormal random number
* \note Formula(http://www.xycoon.com/nor_relationships3.htm)
* @ingroup _oml
*/
double lognormal_dist(double mean, double std_dev);
#endif
+61
View File
@@ -0,0 +1,61 @@
/*
random.c
-------------------
AUTHOR : Lionel GAUTHIER
COMPANY : EURECOM
EMAIL : Lionel.Gauthier@eurecom.fr
***************************************************************************/
#include "rtos_header.h"
#include "platform_types.h"
#ifdef USER_MODE
# include <sys/time.h>
#else
#include <rtai_sched.h>
#endif
/* Random generators */
#define FACTOR 16807
#define LASTXN 127773
#define UPTOMOD -2836
static int seed;
void
init_uniform (void)
{
#ifdef USER_MODE
struct timeval tv;
struct timezone tz;
gettimeofday (&tv, &tz);
seed = (int) tv.tv_usec;
#ifdef NODE_MT
#warning TO DO seed = mobileId
//seed += mobileId;
#endif
#ifdef NODE_RG
#warning TO DO seed = rgId
//seed += rgId;
#endif
#else
seed = rt_get_time_ns();
#endif
}
int
uniform (void)
{
static int times, rest, prod1, prod2;
times = seed / LASTXN;
rest = seed - times * LASTXN;
prod1 = times * UPTOMOD;
prod2 = rest * FACTOR;
seed = prod1 + prod2;
return seed;
}
+9
View File
@@ -0,0 +1,9 @@
/*
random_proto_extern.h
-------------------
AUTHOR : Lionel GAUTHIER
COMPANY : EURECOM
EMAIL : Lionel.Gauthier@eurecom.fr
***************************************************************************/
extern int uniform (void);
+133
View File
@@ -0,0 +1,133 @@
/*******************************************************************************
Eurecom OpenAirInterface
Copyright(c) 1999 - 2011 Eurecom
This program is free software; you can redistribute it and/or modify it
under the terms and conditions of the GNU General Public License,
version 2, as published by the Free Software Foundation.
This program is distributed in the hope it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
The full GNU General Public License is included in this distribution in
the file called "COPYING".
Contact Information
Openair Admin: openair_admin@eurecom.fr
Openair Tech : openair_tech@eurecom.fr
Forums : http://forums.eurecom.fsr/openairinterface
Address : Eurecom, 2229, route des crêtes, 06560 Valbonne Sophia Antipolis, France
*******************************************************************************/
/*! \file taus.c
* \brief random number generator per OAI component
* \author Raymond Knopp and Navid Nikaein
* \date 2011
* \version 0.1
* \warning
* @ingroup util
*/
#ifndef RTAI_ENABLED
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include "oml.h"
#else
#include <asm/io.h>
#include <asm/rtai.h>
#include <rtai.h>
#include <rtai_sched.h>
#define time(x) (unsigned int)(rt_get_time_ns())
#endif
unsigned int s0[MAX_NUM_COMPS], s1[MAX_NUM_COMPS], s2[MAX_NUM_COMPS], b[MAX_NUM_COMPS], r[MAX_NUM_COMPS];
inline unsigned int taus(unsigned int comp) {
b[comp] = (((s0[comp] << 13) ^ s0[comp]) >> 19);
s0[comp] = (((s0[comp] & 0xFFFFFFFE) << 12)^ b[comp]);
b[comp] = (((s1[comp] << 2) ^ s1[comp]) >> 25);
s1[comp] = (((s1[comp] & 0xFFFFFFF8) << 4)^ b[comp]);
b[comp] = (((s2[comp] << 3) ^ s2[comp]) >> 11);
s2[comp] = (((s2[comp] & 0xFFFFFFF0) << 17)^ b[comp]);
r[comp] = s0[comp] ^ s1[comp] ^ s2[comp];
return r[comp];
}
void set_taus_seed(unsigned int seed_type) {
unsigned int i; // i index of component
for (i=MIN_NUM_COMPS; i < MAX_NUM_COMPS ; i ++) {
switch (seed_type){
case 0: // use rand func
if (i == 0) srand(time(NULL));
s0[i] = ((unsigned int)rand());
s1[i] = ((unsigned int)rand());
s2[i] = ((unsigned int)rand());
printf("Initial seeds use rand: s0[%d] = 0x%x, s1[%d] = 0x%x, s2[%d] = 0x%x\n", i, s0[i], i, s1[i], i, s2[i]);
break;
case 1: // use rand with seed
if (i == 0) srand(0x1e23d851);
s0[i] = ((unsigned int)rand());
s1[i] = ((unsigned int)rand());
s2[i] = ((unsigned int)rand());
printf("Initial seeds use rand with seed : s0[%d] = 0x%x, s1[%d] = 0x%x, s2[%d] = 0x%x\n", i, s0[i], i, s1[i], i, s2[i]);
break;
default:
break;
}
}
}
int get_rand (unsigned int comp){
if ((comp > MIN_NUM_COMPS) && (comp < MAX_NUM_COMPS))
return r[comp];
else{
//LOG_E(RNG,"unknown component %d\n",comp);
return -1;
}
}
unsigned int dtaus(unsigned int comp, unsigned int a, unsigned b){
return (int) (((double)taus(comp)/(double)0xffffffff)* (double)(b-a) + (double)a);
}
/*
#ifdef STANDALONE
main() {
unsigned int i,randomg, randphy;
set_taus_seed(0);
printf("dtaus %d \n",dtaus(PHY, 1000, 1000000));
do {//for (i=0;i<10;i++){
randphy = taus(PHY);
randomg = taus(OTG);
i++;
// printf("rand for OMG (%d,0x%x) PHY (%d,0x%x)\n",OMG, randomg, PHY, randphy);
} while (randphy != randomg);
printf("after %d run: get rand for (OMG 0x%x, PHY 0x%x)\n",i, get_rand(OTG), get_rand(PHY));
}
#endif
*/