astyle --recursive --indent=spaces=2 --style=kr --indent-col1-comments --break-blocks --convert-tabs --max-code-length=200

This is done for better merging branch/LG_PRE_RELEASE_0.3 into trunk (same process is applied on this branch)

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@7073 818b1a75-f10b-46b9-bf7c-635c3b92a50f
This commit is contained in:
Lionel Gauthier
2015-04-09 09:29:12 +00:00
parent f0a8a0b3b5
commit 059a0a3fdc
2044 changed files with 1182666 additions and 1145123 deletions
+29 -12
View File
@@ -56,16 +56,20 @@ 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;
}
@@ -82,6 +86,7 @@ void
crcTableInit ()
{
unsigned char c = 0;
do {
crc24Table[c] = crcbit (&c, 1, poly24);
crc16Table[c] = (unsigned short) (crcbit (&c, 1, poly16) >> 16);
@@ -104,11 +109,14 @@ crc24 (unsigned char * inptr, int bitlen)
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;
}
@@ -119,11 +127,14 @@ crc16 (unsigned char * inptr, int bitlen)
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;
}
@@ -134,11 +145,14 @@ crc12 (unsigned char * inptr, int bitlen)
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;
}
@@ -149,11 +163,14 @@ crc8 (unsigned char * inptr, int bitlen)
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;
}
@@ -162,15 +179,15 @@ crc8 (unsigned char * inptr, int bitlen)
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 */
/* #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 */
+147 -119
View File
@@ -49,18 +49,20 @@
static int x, y, z;
void init_seeds(int seed){
void init_seeds(int seed)
{
set_taus_seed(seed);
LOG_I(OTG,"set taus seed to %d done \n", seed);
}
double uniform_rng() {
double uniform_rng()
{
double random;
random = (double)(taus(OTG)%0xffffffff)/((double)0xffffffff);
//LOG_D(OTG,"Uniform taus random number= %lf\n", random);
return random;
return random;
}
@@ -70,170 +72,196 @@ return random;
// Uniform Distribution using the Uniform_Random_Number_Generator
double uniform_dist(int min, int max) {
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);
//printf("Uniform Random Nb = %lf, (min %d, max %d)\n", uniform_rn, min, max);
// LOG_T(OTG,"Uniform Random Nb = %lf, (min %d, max %d)\n", uniform_rn, min, max);
//printf("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;
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;
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_dist(double lambda)
{
double exponential_rn;
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;
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 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;
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;
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 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_dist(double scale, double shape)
{
double gamma_rn, mult_var=1;
int i, shape_int;
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;
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;
}
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;
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_dist(double mean, double std_dev)
{
double lognormal_rn;
lognormal_rn= exp(gaussian_dist(mean, std_dev));
return lognormal_rn;
return lognormal_rn;
}
double wichman_hill() { // not used
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;
double temp, random;
int modx = x % 177;
int mody = y % 176;
int modz = z % 178;
return random;
//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;
}
+30 -30
View File
@@ -53,17 +53,17 @@
/*! \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
* \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
* \brief compute random number
* \param[in] integer
* \param[out]
* \note
* \param[out]
* \note
* @ingroup _oml
*/
unsigned int taus(unsigned int comp);
@@ -72,8 +72,8 @@ 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
* \param[out]
* \note
* @ingroup _oml
*/
void init_seeds(int seed);
@@ -82,7 +82,7 @@ void init_seeds(int seed);
* \brief generates uniform random number with wichman_hill algo
* \param[in]
* \param[out] random number: wichman_hill
* \note
* \note
* @ingroup _oml
*/
double wichman_hill(void) ;
@@ -90,37 +90,37 @@ double wichman_hill(void) ;
/*! \fn double uniform_rng();
* \brief generates uniform random number with algo: wichman_hill / random() / Taus
* \param[in]
* \param[out] random number
* \note
* \param[out] random number
* \note
* @ingroup _oml
*/
double uniform_rng(void);
/*! \fn double uniform_dist(double min, double max);
* \brief
* \param[in] double min
* \brief
* \param[in] double min
* \param[in] double max
* \param[out] uniform number
* \note
* \note
* @ingroup _oml
*/
double uniform_dist(int min, int max);
/*! \fn double gaussian_dist(double mean, double std_dev);
* \brief
* \brief
* \param[in] double mean
* \param[in] double standard deviation
* \param[in] double standard deviation
* \param[out] exponential gaussian number
* \note
* \note
* @ingroup _oml
*/
double gaussian_dist(double mean, double std_dev);
/*! \fn double exponential_dist(double lambda);
* \brief
* \param[in] double lambda
* \brief
* \param[in] double lambda
* \param[out] exponential random number
* \note
* \note
* @ingroup _oml
*/
@@ -130,13 +130,13 @@ double exponential_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
* \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.
* \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)
@@ -145,8 +145,8 @@ double poisson_dist(double lambda);
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
* \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)
@@ -155,8 +155,8 @@ double weibull_dist(double scale, double shape);
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
* \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)
@@ -165,8 +165,8 @@ double pareto_dist(double scale, double shape);
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
* \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)
@@ -176,8 +176,8 @@ 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
* \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)
@@ -187,4 +187,4 @@ double lognormal_dist(double mean, double std_dev);
#endif
+31 -23
View File
@@ -28,12 +28,12 @@
*******************************************************************************/
/*! \file taus.c
* \brief random number generator per OAI component
* \brief random number generator per OAI component
* \author Navid Nikaein
* \date 2011 - 2014
* \version 0.1
* \email navid.nikaein@eurecom.fr
* \warning
* \warning
* @ingroup util
*/
@@ -58,7 +58,8 @@ unsigned int s0[MAX_NUM_COMPS], s1[MAX_NUM_COMPS], s2[MAX_NUM_COMPS], b[MAX_NUM_
inline unsigned int taus(unsigned int comp) {
inline unsigned int taus(unsigned int comp)
{
b[comp] = (((s0[comp] << 13) ^ s0[comp]) >> 19);
s0[comp] = (((s0[comp] & 0xFFFFFFFE) << 12)^ b[comp]);
@@ -66,50 +67,57 @@ inline unsigned int taus(unsigned int comp) {
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];
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
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:
default:
break;
}
}
}
int get_rand (unsigned int comp){
int get_rand (unsigned int comp)
{
if ((comp > MIN_NUM_COMPS) && (comp < MAX_NUM_COMPS))
return r[comp];
else{
else {
//LOG_E(RNG,"unknown component %d\n",comp);
return -1;
}
}
unsigned int dtaus(unsigned int comp, unsigned int a, unsigned b){
unsigned int dtaus(unsigned int comp, unsigned int a, unsigned b)
{
return (int) (((double)taus(comp)/(double)0xffffffff)* (double)(b-a) + (double)a);
}
/*
@@ -122,14 +130,14 @@ main() {
printf("dtaus %d \n",dtaus(PHY, 1000, 1000000));
do {//for (i=0;i<10;i++){
randphy = taus(PHY);
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);
} 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
#endif
*/