Commit bacf3537 authored by Robert Schmidt's avatar Robert Schmidt

Merge remote-tracking branch 'origin/fix-seed-physim-script' into integration_2022_wk51

parents 1af5062b 8cacbb88
This diff is collapsed.
......@@ -114,6 +114,7 @@ function test_run() {
for (( run_index=1; run_index <= $nruns; run_index++ ))
do
temp_exec_log="$log_dir/test.$test_case_name.${tags_array[$tags_array_index]}.run_$run_index"
echo "</EXECUTION LOG Test Case = $test_case_name.${tags_array[$tags_array_index]}, Run = $run_index >" >> $temp_exec_log 2>&1
cat "$temp_exec_log" >> "$log_file" 2>&1
......
......@@ -70,7 +70,6 @@ COPY --from=lte-ue-build \
/oai-ran/cmake_targets/ran_build/build/liboai_usrpdevif.so \
/oai-ran/cmake_targets/ran_build/build/libcoding.so \
/oai-ran/cmake_targets/ran_build/build/libparams_libconfig.so \
/oai-ran/cmake_targets/ran_build/build/libSIMU.so \
/oai-ran/cmake_targets/ran_build/build/libdfts.so \
/oai-ran/cmake_targets/ran_build/build/libtelnetsrv.so \
/usr/local/lib/
......
......@@ -76,7 +76,6 @@ COPY --from=lte-ue-build \
/oai-ran/cmake_targets/ran_build/build/liboai_usrpdevif.so \
/oai-ran/cmake_targets/ran_build/build/libcoding.so \
/oai-ran/cmake_targets/ran_build/build/libparams_libconfig.so \
/oai-ran/cmake_targets/ran_build/build/libSIMU.so \
/oai-ran/cmake_targets/ran_build/build/libdfts.so \
/oai-ran/cmake_targets/ran_build/build/libtelnetsrv.so \
/usr/local/lib/
......
......@@ -89,7 +89,6 @@ COPY --from=phy-sim-build \
/lib64/libxslt.so.1 \
/usr/lib64/libasan.so.5 \
/oai-ran/cmake_targets/ran_build/build/libdfts.so \
/oai-ran/cmake_targets/ran_build/build/libSIMU.so \
/oai-ran/cmake_targets/ran_build/build/libldpc.so \
/oai-ran/cmake_targets/ran_build/build/libldpc_orig.so \
/usr/local/lib/
......
......@@ -26,21 +26,7 @@
//#include "PHY/defs.h"
#include "SIMULATION/TOOLS/sim.h"
#include "rf.h"
/*
extern void randominit(void);
extern double gaussdouble(double,double);
//free(input_data);
//extern int LOG_M(const char *,const char *,void *,int,int,char);
//flag change
extern int LOG_M(const char *,const char *,void *,int,int,char);
*/
//double pn[1024];
//#define DEBUG_RF 1
//free(input_data);
void rf_rx(double **r_re,
double **r_im,
double **r_re_i1,
......
......@@ -26,57 +26,67 @@
#include "sim.h"
static unsigned int seed, iy, ir[98];
/*
@defgroup _uniformdouble
@ingroup numerical Uniform linear congruential random number generator.
*/
/*!\brief Initialization routine for Uniform/Gaussian random number generators. */
#define a 1664525lu
#define mod 4294967296.0 /* is 2**32 */
static unsigned int urseed, iy, ir[98]; /// uniformrandom
static bool tableNordDone = false; /// gaussZiggurat
#if 1
void randominit(unsigned seed_init)
/*!\brief Generate a random number form `/dev/urandom`. */
void fill_random(void *buf, size_t sz)
{
int i;
// this need to be integrated with the existing rng, like taus: navid
if (seed_init == 0) {
srand((unsigned)time(NULL));
seed = (unsigned int) rand();
} else {
seed = seed_init;
const char* fn = "/dev/urandom";
FILE* f = fopen(fn, "rb");
if (f == NULL) {
fprintf(stderr, "could not open %s for seed generation: %d %s\n", fn, errno, strerror(errno));
abort();
}
printf("Initializing random number generator, seed %x\n",seed);
int rc = fread(buf, sz, 1, f);
if (rc < 0) {
fprintf(stderr, "could not read %s for seed generation: %d %s\n", fn, errno, strerror(errno));
abort();
}
fclose(f);
}
if (seed % 2 == 0) seed += 1; /* seed and mod are relative prime */
static const unsigned int a = 1664525lu;
for (i=1; i<=97; i++) {
seed = a*seed; /* mod 2**32 */
ir[i]= seed; /* initialize the shuffle table */
/*!\brief Initialization routine for Uniform/Gaussian random number generators. */
void randominit(unsigned long seed_init)
{
unsigned long seed = seed_init;
if (seed_init == 0)
fill_random(&seed, sizeof(seed));
printf("Initializing random number generator, seed %ld\n", seed);
// initialize uniformrandom RNG
urseed = (unsigned int) seed;
if (urseed % 2 == 0)
urseed += 1; /* urseed and mod are relative prime */
for (int i = 1; i <= 97; i++) {
urseed = a * urseed; /* mod 2**32 */
ir[i] = urseed; /* initialize the shuffle table */
}
iy = 1;
iy=1;
// initialize gaussZiggurat RNG
tableNor(seed);
tableNordDone = true;
}
#endif
/*
@defgroup _uniformdouble
@ingroup numerical Uniform linear congruential random number generator.
*/
/*!\brief Uniform linear congruential random number generator on \f$[0,1)\f$. Returns a double-precision floating-point number.*/
double uniformrandom(void)
{
#define a 1664525lu
#define mod 4294967296.0 /* is 2**32 */
int j;
j=1 + 97.0*iy/mod;
iy=ir[j];
seed = a*seed; /* mod 2**32 */
ir[j] = seed;
return( (double) iy/mod );
const double mod = 4294967296.0; /* is 2**32 */
int j = 1 + 97.0 * iy / mod;
iy = ir[j];
urseed = a * urseed; /* mod 2**32 */
ir[j] = urseed;
return (double)iy / mod;
}
/*
......@@ -109,8 +119,12 @@ double __attribute__ ((no_sanitize_address)) gaussdouble(double mean, double var
}
}
/*
@defgroup _gaussZiggurat
@ingroup numerical ziggurat random number generator for exponentially distributed numbers
*/
// Ziggurat
static bool tableNordDone=false;
static double wn[128], fn[128];
static uint32_t iz, jz, jsr = 123456789, kn[128];
static int32_t hz;
......@@ -180,9 +194,9 @@ double __attribute__ ((no_sanitize_address)) gaussZiggurat(double mean, double v
{
if (!tableNordDone) {
// let's make reasonnable constant tables
struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
tableNor((long)(t.tv_nsec%INT_MAX));
unsigned long seed;
fill_random(&seed, sizeof(seed));
tableNor(seed);
}
hz = SHR3;
iz = hz & 127;
......
......@@ -523,8 +523,9 @@ the value \f$\mathrm{sgn}(u)i\f$. The search requires at most \f$Nbits-1\f$ com
*/
int gauss(unsigned int *gauss_LUT,unsigned char Nbits);
void fill_random(void *buf, size_t sz);
double gaussdouble(double,double);
void randominit(unsigned int seed_init);
void randominit(unsigned long seed_init);
double uniformrandom(void);
double gaussZiggurat(double mean, double variance);
void tableNor(unsigned long seed);
......
......@@ -23,7 +23,7 @@
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
//#include "SIMULATION/TOOLS/sim.h"
#include "sim.h"
static unsigned int s0, s1, s2;
......@@ -52,20 +52,9 @@ void set_taus_seed(unsigned int seed_init)
unsigned long result = 0;
if (seed_init == 0) {
unsigned int data[3];
int fd = open("/dev/urandom", O_RDONLY);
if (fd == -1)
{
abort();
}
if (read(fd, data, sizeof(data)) != sizeof(data))
{
abort();
}
close(fd);
s0 = data[0];
s1 = data[1];
s2 = data[2];
fill_random(&s0, sizeof(s0));
fill_random(&s1, sizeof(s1));
fill_random(&s2, sizeof(s2));
} else {
/* Use reentrant version of rand48 to ensure that no conflicts with other generators occur */
srand48_r((long int)seed_init, &buffer);
......
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*
random.c
-------------------
AUTHOR : Lionel GAUTHIER
COMPANY : EURECOM
EMAIL : Lionel.Gauthier@eurecom.fr
***************************************************************************/
#include "rtos_header.h"
#include "platform_types.h"
#include <sys/time.h>
/* Random generators */
#define FACTOR 16807
#define LASTXN 127773
#define UPTOMOD -2836
static int seed;
void
init_uniform (void)
{
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
}
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;
}
......@@ -19,7 +19,7 @@ extern "C" {
#include <openair2/LAYER2/PDCP_v10.1.0/pdcp.h>
#include <openair2/LAYER2/nr_rlc/nr_rlc_oai_api.h>
#include "openair2/SDAP/nr_sdap/nr_sdap.h"
//#include <openair1/PHY/phy_extern.h>
#include "sim.h"
#pragma pack(1)
......@@ -143,6 +143,12 @@ class gtpEndPoints {
// the instance id will be the Linux socket handler, as this is uniq
map<uint64_t, gtpEndPoint> instances;
gtpEndPoints() {
unsigned int seed;
fill_random(&seed, sizeof(seed));
srandom(seed);
}
~gtpEndPoints() {
// automatically close all sockets on quit
for (const auto &p : instances)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment