Merge branch 'next' into mobility

master
Ismael Gomez 8 years ago
commit 93ff9294f5

@ -66,7 +66,7 @@ option(ENABLE_BLADERF "Enable BladeRF" ON)
option(BUILD_STATIC "Attempt to statically link external deps" OFF)
option(RPATH "Enable RPATH" OFF)
option(USE_LTE_RATES "Use standard LTE sampling rates" OFF)
option(USE_LTE_RATES "Use standard LTE sampling rates" OFF)
set(GCC_ARCH native CACHE STRING "GCC compile for specific architecture.")
@ -79,13 +79,21 @@ find_package(Threads REQUIRED)
find_package(Polarssl)
if (POLARSSL_FOUND)
set(SEC_INCLUDE_DIRS "${POLARSSL_INCLUDE_DIRS}")
set(SEC_LIBRARIES "${POLARSSL_LIBRARIES}")
if(BUILD_STATIC)
set(SEC_LIBRARIES "${POLARSSL_STATIC_LIBRARIES}")
else(BUILD_STATIC)
set(SEC_LIBRARIES "${POLARSSL_LIBRARIES}")
endif(BUILD_STATIC)
add_definitions(-DHAVE_POLARSSL)
else(POLARSSL_FOUND)
find_package(MbedTLS REQUIRED)
if (MBEDTLS_FOUND)
set(SEC_INCLUDE_DIRS "${MBEDTLS_INCLUDE_DIRS}")
set(SEC_LIBRARIES "${MBEDTLS_LIBRARIES}")
if(BUILD_STATIC)
set(SEC_LIBRARIES "${MBEDTLS_STATIC_LIBRARIES}")
else(BUILD_STATIC)
set(SEC_LIBRARIES "${MBEDTLS_LIBRARIES}")
endif(BUILD_STATIC)
add_definitions(-DHAVE_MBEDTLS)
endif (MBEDTLS_FOUND)
endif(POLARSSL_FOUND)
@ -119,6 +127,10 @@ endif(BLADERF_FOUND OR UHD_FOUND OR SOAPYSDR_FOUND)
if(ENABLE_SRSUE OR ENABLE_SRSENB)
# Find Boost
if(BUILD_STATIC)
set(Boost_USE_STATIC_LIBS ON)
endif(BUILD_STATIC)
set(BOOST_REQUIRED_COMPONENTS
program_options
system

@ -81,6 +81,12 @@ Build Instructions
* lksctp: http://lksctp.sourceforge.net/
* config: http://www.hyperrealm.com/libconfig/
For example, on Ubuntu 17.04, one can install the required libraries with:
```
sudo apt-get install libfftw3-dev libmbedtls-dev libboost-all-dev libconfig++-dev libsctp-dev
```
Note that depending on your flavor and version of Linux, the actual package names may be different.
* Optional requirements:
* srsgui: https://github.com/srslte/srsgui - for real-time plotting.
* VOLK: https://github.com/gnuradio/volk - if the VOLK library and headers are detected, they will be used to accelerate some signal processing functions.

@ -32,9 +32,23 @@ FIND_LIBRARY(
/usr/lib64
)
FIND_LIBRARY(
MBEDTLS_STATIC_LIBRARIES
NAMES libmbedcrypto.a
HINTS $ENV{MBEDTLS_DIR}/lib
${PC_MBEDTLS_LIBDIR}
${CMAKE_INSTALL_PREFIX}/lib
${CMAKE_INSTALL_PREFIX}/lib64
PATHS /usr/local/lib
/usr/local/lib64
/usr/lib
/usr/lib64
)
message(STATUS "MBEDTLS LIBRARIES: " ${MBEDTLS_LIBRARIES})
message(STATUS "MBEDTLS STATIC LIBRARIES: " ${MBEDTLS_STATIC_LIBRARIES})
message(STATUS "MBEDTLS INCLUDE DIRS: " ${MBEDTLS_INCLUDE_DIRS})
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(MBEDTLS DEFAULT_MSG MBEDTLS_LIBRARIES MBEDTLS_INCLUDE_DIRS)
MARK_AS_ADVANCED(MBEDTLS_LIBRARIES MBEDTLS_INCLUDE_DIRS)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(MBEDTLS DEFAULT_MSG MBEDTLS_LIBRARIES MBEDTLS_STATIC_LIBRARIES MBEDTLS_INCLUDE_DIRS)
MARK_AS_ADVANCED(MBEDTLS_LIBRARIES MBEDTLS_STATIC_LIBRARIES MBEDTLS_INCLUDE_DIRS)

@ -31,9 +31,23 @@ FIND_LIBRARY(
/usr/lib64
)
FIND_LIBRARY(
POLARSSL_STATIC_LIBRARIES
NAMES libpolarssl.a
HINTS $ENV{POLARSSL_DIR}/lib
${PC_POLARSSL_LIBDIR}
${CMAKE_INSTALL_PREFIX}/lib
${CMAKE_INSTALL_PREFIX}/lib64
PATHS /usr/local/lib
/usr/local/lib64
/usr/lib
/usr/lib64
)
message(STATUS "POLARSSL LIBRARIES: " ${POLARSSL_LIBRARIES})
message(STATUS "POLARSSL STATIC LIBRARIES: " ${POLARSSL_STATIC_LIBRARIES})
message(STATUS "POLARSSL INCLUDE DIRS: " ${POLARSSL_INCLUDE_DIRS})
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(POLARSSL DEFAULT_MSG POLARSSL_LIBRARIES POLARSSL_INCLUDE_DIRS)
MARK_AS_ADVANCED(POLARSSL_LIBRARIES POLARSSL_INCLUDE_DIRS)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(POLARSSL DEFAULT_MSG POLARSSL_LIBRARIES POLARSSL_STATIC_LIBRARIES POLARSSL_INCLUDE_DIRS)
MARK_AS_ADVANCED(POLARSSL_STATIC_LIBRARIES POLARSSL_LIBRARIES POLARSSL_INCLUDE_DIRS)

@ -65,7 +65,7 @@ if(RF_FOUND)
add_executable(cell_search cell_search.c)
target_link_libraries(cell_search srslte_phy srslte_rf)
add_executable(cell_measurement cell_measurement.c)
add_executable(cell_measurement cell_measurement.c ../include/srslte/common/logger_stdout.h)
target_link_libraries(cell_measurement srslte_phy srslte_rf)
add_executable(usrp_capture usrp_capture.c)

@ -38,15 +38,19 @@
#include <stdarg.h>
#include <string>
#include "srslte/common/log.h"
#include "logger.h"
#include "srslte/common/logger.h"
#include "srslte/common/logger_stdout.h"
namespace srslte {
typedef std::string* str_ptr;
class log_filter : public srslte::log
{
public:
log_filter();
log_filter(std::string layer);
log_filter(std::string layer, logger *logger_, bool tti=false);
void init(std::string layer, logger *logger_, bool tti=false);
@ -71,6 +75,8 @@ private:
logger *logger_h;
bool do_tti;
logger_stdout def_logger_stdout;
void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, char *msg);
void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, char *msg, uint8_t *hex, int size);
void all_log_line(srslte::LOG_LEVEL_ENUM level, uint32_t tti, std::string file, int line, char *msg);

@ -1,82 +0,0 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2015 Software Radio Systems Limited
*
* \section LICENSE
*
* This file is part of the srsUE library.
*
* srsUE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* srsUE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
/******************************************************************************
* File: log_stout.h
*
* Description: Logging service through standard output. Inherits log interface
*
* Reference:
*****************************************************************************/
#ifndef LOGSTDOUT_H
#define LOGSTDOUT_H
#include <stdarg.h>
#include <string>
#include "srslte/common/log.h"
namespace srslte {
class log_stdout : public log
{
public:
log_stdout(std::string service_name_) : log(service_name_) { }
void console(std::string message, ...);
void error(std::string message, ...);
void warning(std::string message, ...);
void info(std::string message, ...);
void debug(std::string message, ...);
// Same with hex dump
void error_hex(uint8_t *hex, int size, std::string message, ...);
void warning_hex(uint8_t *hex, int size, std::string message, ...);
void info_hex(uint8_t *hex, int size, std::string message, ...);
void debug_hex(uint8_t *hex, int size, std::string message, ...);
// Same with line and file info
void error_line(std::string file, int line, std::string message, ...);
void warning_line(std::string file, int line, std::string message, ...);
void info_line(std::string file, int line, std::string message, ...);
void debug_line(std::string file, int line, std::string message, ...);
private:
void printlog(srslte::LOG_LEVEL_ENUM level, uint32_t tti, std::string file, int line, std::string message, va_list args);
void printlog(srslte::LOG_LEVEL_ENUM level, uint32_t tti, std::string message, va_list args);
void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, char *msg);
void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, char *msg, uint8_t *hex, int size);
void all_log_line(srslte::LOG_LEVEL_ENUM level, uint32_t tti, std::string file, int line, char *msg);
std::string now_time();
std::string hex_string(uint8_t *hex, int size);
};
}
#endif

@ -26,49 +26,23 @@
/******************************************************************************
* File: logger.h
* Description: Common log object. Maintains a queue of log messages
* and runs a thread to read messages and write to file.
* Multiple producers, single consumer. If full, producers
* increase queue size. If empty, consumer blocks.
* Description: Interface for logging output
*****************************************************************************/
#ifndef LOGGER_H
#define LOGGER_H
#include <stdio.h>
#include <deque>
#include <string>
#include "srslte/common/threads.h"
namespace srslte {
typedef std::string* str_ptr;
class logger : public thread
class logger
{
public:
logger();
logger(std::string file);
~logger();
void init(std::string file);
void log(const char *msg);
void log(str_ptr msg);
private:
void run_thread();
void flush();
FILE* logfile;
bool inited;
bool not_done;
std::string filename;
pthread_cond_t not_empty;
pthread_cond_t not_full;
pthread_mutex_t mutex;
pthread_t thread;
std::deque<str_ptr> buffer;
virtual void log(std::string *msg) = 0;
};
} // namespace srsue
} // namespace srslte
#endif // LOGGER_H

@ -0,0 +1,76 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2015 Software Radio Systems Limited
*
* \section LICENSE
*
* This file is part of the srsUE library.
*
* srsUE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* srsUE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
/******************************************************************************
* File: logger_file.h
* Description: Common log object. Maintains a queue of log messages
* and runs a thread to read messages and write to file.
* Multiple producers, single consumer. If full, producers
* increase queue size. If empty, consumer blocks.
*****************************************************************************/
#ifndef LOGGER_FILE_H
#define LOGGER_FILE_H
#include <stdio.h>
#include <deque>
#include <string>
#include "srslte/common/logger.h"
#include "srslte/common/threads.h"
namespace srslte {
typedef std::string* str_ptr;
class logger_file : public thread, public logger
{
public:
logger_file();
logger_file(std::string file);
~logger_file();
void init(std::string file);
// Implementation of log_out
void log(str_ptr msg);
void log(const char *msg);
private:
void run_thread();
void flush();
FILE* logfile;
bool inited;
bool not_done;
std::string filename;
pthread_cond_t not_empty;
pthread_cond_t not_full;
pthread_mutex_t mutex;
pthread_t thread;
std::deque<str_ptr> buffer;
};
} // namespace srsue
#endif // LOGGER_H

@ -0,0 +1,51 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2015 Software Radio Systems Limited
*
* \section LICENSE
*
* This file is part of the srsUE library.
*
* srsUE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* srsUE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
/******************************************************************************
* File: logger_stdout.h
* Description: Interface for logging output
*****************************************************************************/
#ifndef LOGGER_STDOUT_H
#define LOGGER_STDOUT_H
#include <stdio.h>
#include <string>
#include "srslte/common/logger.h"
namespace srslte {
class logger_stdout : public logger
{
public:
void log(std::string *msg) {
fprintf(stdout, "%s", msg->c_str());
}
};
} // namespace srslte
#endif // LOGGER_H

@ -39,22 +39,14 @@ SRSLTE_API int srslte_vec_dot_prod_sss_sse(short *x, short *y, uint32_t len);
SRSLTE_API int srslte_vec_dot_prod_sss_avx2(short *x, short *y, uint32_t len);
SRSLTE_API void srslte_vec_sum_sss_sse(short *x, short *y, short *z, uint32_t len);
SRSLTE_API void srslte_vec_sum_sss_avx2(short *x, short *y, short *z, uint32_t len);
SRSLTE_API void srslte_vec_sub_sss_sse(short *x, short *y, short *z, uint32_t len);
SRSLTE_API void srslte_vec_sub_sss_avx2(short *x, short *y, short *z, uint32_t len);
SRSLTE_API void srslte_vec_prod_sss_sse(short *x, short *y, short *z, uint32_t len);
SRSLTE_API void srslte_vec_prod_sss_avx2(short *x, short *y, short *z, uint32_t len);
@ -64,17 +56,11 @@ SRSLTE_API void srslte_vec_sc_div2_sss_sse(short *x, int n_rightshift, short *z,
SRSLTE_API void srslte_vec_sc_div2_sss_avx2(short *x, int k, short *z, uint32_t len);
SRSLTE_API void srslte_vec_lut_sss_sse(short *x, unsigned short *lut, short *y, uint32_t len);
SRSLTE_API void srslte_vec_convert_fi_sse(float *x, int16_t *z, float scale, uint32_t len);
SRSLTE_API void srslte_vec_convert_fi_sse(float *x, int16_t *z, float scale, uint32_t len);
SRSLTE_API void srslte_vec_mult_scalar_cf_f_avx( cf_t *z,const cf_t *x,const float h,const uint32_t len);
SRSLTE_API void srslte_vec_sc_prod_cfc_avx(const cf_t *x,const float h,cf_t *y,const uint32_t len);
#ifdef __cplusplus
}
#endif

@ -66,14 +66,13 @@ public:
void write_pdu_pcch(byte_buffer_t *sdu);
private:
log *pdcp_log;
pdcp_entity pdcp_array[SRSLTE_N_RADIO_BEARERS];
srsue::rlc_interface_pdcp *rlc;
srsue::rrc_interface_pdcp *rrc;
srsue::gw_interface_pdcp *gw;
uint8_t direction;
log *pdcp_log;
pdcp_entity pdcp_array[SRSLTE_N_RADIO_BEARERS];
uint8_t direction;
bool valid_lcid(uint32_t lcid);
};

@ -40,6 +40,11 @@ log_filter::log_filter()
do_tti = false;
}
log_filter::log_filter(std::string layer)
{
init(layer, &def_logger_stdout, tti);
}
log_filter::log_filter(std::string layer, logger *logger_, bool tti)
{
init(layer, logger_, tti);

@ -1,290 +0,0 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2015 Software Radio Systems Limited
*
* \section LICENSE
*
* This file is part of the srsUE library.
*
* srsUE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* srsUE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <stdarg.h>
#include <string>
#include "srslte/common/log_stdout.h"
using namespace std;
namespace srslte {
void log_stdout::all_log(srslte::LOG_LEVEL_ENUM level,
uint32_t tti,
char *msg)
{
std::stringstream ss;
ss << now_time() << " ";
ss << "[" <<get_service_name() << "] ";
ss << log_level_text[level] << " ";
ss << "[" << std::setfill('0') << std::setw(5) << tti << "] ";
ss << msg;
cout << ss.str();
}
void log_stdout::all_log(srslte::LOG_LEVEL_ENUM level,
uint32_t tti,
char *msg,
uint8_t *hex,
int size)
{
std::stringstream ss;
ss << now_time() << " ";
ss << "[" <<get_service_name() << "] ";
ss << log_level_text[level] << " ";
ss << "[" << std::setfill('0') << std::setw(5) << tti << "] ";
ss << msg << std::endl;
ss << hex_string(hex, size);
cout << ss.str();
}
void log_stdout::all_log_line(srslte::LOG_LEVEL_ENUM level,
uint32_t tti,
std::string file,
int line,
char *msg)
{
std::stringstream ss;
ss << now_time() << " ";
ss << "[" <<get_service_name() << "] ";
ss << log_level_text[level] << " ";
ss << "[" << std::setfill('0') << std::setw(5) << tti << "] ";
ss << msg;
cout << ss.str();
}
void log_stdout::console(std::string message, ...) {
char *args_msg;
va_list args;
va_start(args, message);
if(vasprintf(&args_msg, message.c_str(), args) > 0)
printf("%s",args_msg); // Print directly to stdout
va_end(args);
free(args_msg);
}
void log_stdout::error(std::string message, ...) {
if (level >= LOG_LEVEL_ERROR) {
char *args_msg;
va_list args;
va_start(args, message);
if(vasprintf(&args_msg, message.c_str(), args) > 0)
all_log(LOG_LEVEL_ERROR, tti, args_msg);
va_end(args);
free(args_msg);
}
}
void log_stdout::warning(std::string message, ...) {
if (level >= LOG_LEVEL_WARNING) {
char *args_msg;
va_list args;
va_start(args, message);
if(vasprintf(&args_msg, message.c_str(), args) > 0)
all_log(LOG_LEVEL_WARNING, tti, args_msg);
va_end(args);
free(args_msg);
}
}
void log_stdout::info(std::string message, ...) {
if (level >= LOG_LEVEL_INFO) {
char *args_msg;
va_list args;
va_start(args, message);
if(vasprintf(&args_msg, message.c_str(), args) > 0)
all_log(LOG_LEVEL_INFO, tti, args_msg);
va_end(args);
free(args_msg);
}
}
void log_stdout::debug(std::string message, ...) {
if (level >= LOG_LEVEL_DEBUG) {
char *args_msg;
va_list args;
va_start(args, message);
if(vasprintf(&args_msg, message.c_str(), args) > 0)
all_log(LOG_LEVEL_DEBUG, tti, args_msg);
va_end(args);
free(args_msg);
}
}
void log_stdout::error_hex(uint8_t *hex, int size, std::string message, ...) {
if (level >= LOG_LEVEL_ERROR) {
char *args_msg;
va_list args;
va_start(args, message);
if(vasprintf(&args_msg, message.c_str(), args) > 0)
all_log(LOG_LEVEL_ERROR, tti, args_msg, hex, size);
va_end(args);
free(args_msg);
}
}
void log_stdout::warning_hex(uint8_t *hex, int size, std::string message, ...) {
if (level >= LOG_LEVEL_WARNING) {
char *args_msg;
va_list args;
va_start(args, message);
if(vasprintf(&args_msg, message.c_str(), args) > 0)
all_log(LOG_LEVEL_WARNING, tti, args_msg, hex, size);
va_end(args);
free(args_msg);
}
}
void log_stdout::info_hex(uint8_t *hex, int size, std::string message, ...) {
if (level >= LOG_LEVEL_INFO) {
char *args_msg;
va_list args;
va_start(args, message);
if(vasprintf(&args_msg, message.c_str(), args) > 0)
all_log(LOG_LEVEL_INFO, tti, args_msg, hex, size);
va_end(args);
free(args_msg);
}
}
void log_stdout::debug_hex(uint8_t *hex, int size, std::string message, ...) {
if (level >= LOG_LEVEL_DEBUG) {
char *args_msg;
va_list args;
va_start(args, message);
if(vasprintf(&args_msg, message.c_str(), args) > 0)
all_log(LOG_LEVEL_DEBUG, tti, args_msg, hex, size);
va_end(args);
free(args_msg);
}
}
void log_stdout::error_line(std::string file, int line, std::string message, ...)
{
if (level >= LOG_LEVEL_ERROR) {
char *args_msg;
va_list args;
va_start(args, message);
if(vasprintf(&args_msg, message.c_str(), args) > 0)
all_log_line(LOG_LEVEL_ERROR, tti, file, line, args_msg);
va_end(args);
free(args_msg);
}
}
void log_stdout::warning_line(std::string file, int line, std::string message, ...)
{
if (level >= LOG_LEVEL_WARNING) {
char *args_msg;
va_list args;
va_start(args, message);
if(vasprintf(&args_msg, message.c_str(), args) > 0)
all_log_line(LOG_LEVEL_WARNING, tti, file, line, args_msg);
va_end(args);
free(args_msg);
}
}
void log_stdout::info_line(std::string file, int line, std::string message, ...)
{
if (level >= LOG_LEVEL_INFO) {
char *args_msg;
va_list args;
va_start(args, message);
if(vasprintf(&args_msg, message.c_str(), args) > 0)
all_log_line(LOG_LEVEL_INFO, tti, file, line, args_msg);
va_end(args);
free(args_msg);
}
}
void log_stdout::debug_line(std::string file, int line, std::string message, ...)
{
if (level >= LOG_LEVEL_DEBUG) {
char *args_msg;
va_list args;
va_start(args, message);
if(vasprintf(&args_msg, message.c_str(), args) > 0)
all_log_line(LOG_LEVEL_DEBUG, tti, file, line, args_msg);
va_end(args);
free(args_msg);
}
}
std::string log_stdout::now_time()
{
struct timeval rawtime;
struct tm * timeinfo;
char buffer[64];
char us[16];
gettimeofday(&rawtime, NULL);
timeinfo = localtime(&rawtime.tv_sec);
strftime(buffer,64,"%H:%M:%S",timeinfo);
strcat(buffer,".");
snprintf(us,16,"%ld",rawtime.tv_usec);
strcat(buffer,us);
return std::string(buffer);
}
std::string log_stdout::hex_string(uint8_t *hex, int size)
{
std::stringstream ss;
int c = 0;
ss << std::hex << std::setfill('0');
if(hex_limit >= 0) {
size = (size > hex_limit) ? hex_limit : size;
}
while(c < size) {
ss << " " << std::setw(4) << static_cast<unsigned>(c) << ": ";
int tmp = (size-c < 16) ? size-c : 16;
for(int i=0;i<tmp;i++) {
ss << std::setw(2) << static_cast<unsigned>(hex[c++]) << " ";
}
ss << "\n";
}
return ss.str();
}
}

@ -27,20 +27,20 @@
#define LOG_BUFFER_SIZE 1024*32
#include "srslte/common/logger.h"
#include "srslte/common/logger_file.h"
using namespace std;
namespace srslte{
logger::logger()
logger_file::logger_file()
:inited(false)
,not_done(true)
{}
logger::~logger() {
logger_file::~logger_file() {
not_done = false;
log("Closing log");
log(new std::string("Closing log"));
if(inited) {
wait_thread_finish();
flush();
@ -48,7 +48,7 @@ logger::~logger() {
}
}
void logger::init(std::string file) {
void logger_file::init(std::string file) {
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&not_empty, NULL);
pthread_cond_init(&not_full, NULL);
@ -61,19 +61,18 @@ void logger::init(std::string file) {
inited = true;
}
void logger::log(const char *msg) {
str_ptr s_ptr(new std::string(msg));
log(s_ptr);
void logger_file::log(const char *msg) {
log(new std::string(msg));
}
void logger::log(str_ptr msg) {
void logger_file::log(str_ptr msg) {
pthread_mutex_lock(&mutex);
buffer.push_back(msg);
pthread_cond_signal(&not_empty);
pthread_mutex_unlock(&mutex);
}
void logger::run_thread() {
void logger_file::run_thread() {
while(not_done) {
pthread_mutex_lock(&mutex);
while(buffer.empty()) {
@ -89,7 +88,7 @@ void logger::run_thread() {
}
}
void logger::flush() {
void logger_file::flush() {
std::deque<str_ptr>::iterator it;
for(it=buffer.begin();it!=buffer.end();it++)
{

@ -72,11 +72,11 @@ endif(MKL_FOUND)
if(MKL_FOUND)
if(STATIC_MKL)
if(BUILD_STATIC)
target_link_libraries(srslte_phy ${MKL_STATIC_LIBRARIES})
else(STATIC_MKL)
else(BUILD_STATIC)
target_link_libraries(srslte_phy ${MKL_LIBRARIES})
endif(STATIC_MKL)
endif(BUILD_STATIC)
else(MKL_FOUND)
target_link_libraries(srslte_phy ${FFTW3F_LIBRARIES})
endif(MKL_FOUND)

@ -240,7 +240,7 @@ void srslte_vec_norm_cfc(cf_t *x, float amplitude, cf_t *y, uint32_t len) {
void srslte_vec_sc_prod_cfc(cf_t *x, float h, cf_t *z, uint32_t len) {
#ifdef LV_HAVE_AVX
srslte_vec_mult_scalar_cf_f_avx(z,x, h, len);
srslte_vec_sc_prod_cfc_avx(x,h,z,len);
#else
int i;
for (i=0;i<len;i++) {

@ -469,7 +469,7 @@ void srslte_vec_convert_fi_sse(float *x, int16_t *z, float scale, uint32_t len)
}
//srslte_32fc_s32f_multiply_32fc_avx
void srslte_vec_mult_scalar_cf_f_avx( cf_t *z,const cf_t *x,const float h,const uint32_t len)
void srslte_vec_sc_prod_cfc_avx( const cf_t *x,const float h,cf_t *z,const uint32_t len)
{
#ifdef LV_HAVE_AVX

@ -29,11 +29,12 @@
#include <stdio.h>
#include "srslte/common/log_filter.h"
#include "srslte/common/logger_file.h"
using namespace srslte;
typedef struct {
logger *l;
logger_file *l;
int thread_id;
}args_t;
@ -78,7 +79,7 @@ void* thread_loop_hex(void *a) {
}
void write(std::string filename) {
logger l;
logger_file l;
l.init(filename);
pthread_t threads[NTHREADS];
args_t args[NTHREADS];

@ -29,12 +29,12 @@
#include <stdlib.h>
#include <stdio.h>
#include "srslte/common/logger.h"
#include "srslte/common/logger_file.h"
using namespace srslte;
typedef struct {
logger *l;
logger_file *l;
int thread_id;
}args_t;
@ -44,13 +44,13 @@ void* thread_loop(void *a) {
for(int i=0;i<NMSGS;i++)
{
sprintf(buf, "Thread %d: %d", args->thread_id, i);
args->l->log(buf);
args->l->log(new std::string(buf));
}
return NULL;
}
void write(std::string filename) {
logger l;
logger_file l;
l.init(filename);
pthread_t threads[NTHREADS];
args_t args[NTHREADS];

@ -25,7 +25,8 @@
*/
#include <iostream>
#include "srslte/common/log_stdout.h"
#include "srslte/common/log_filter.h"
#include "srslte/common/logger_stdout.h"
#include "srslte/upper/rlc_am.h"
#include <assert.h>
#define NBUFS 5
@ -73,8 +74,8 @@ public:
void basic_test()
{
srslte::log_stdout log1("RLC_AM_1");
srslte::log_stdout log2("RLC_AM_2");
srslte::log_filter log1("RLC_AM_1");
srslte::log_filter log2("RLC_AM_2");
log1.set_level(srslte::LOG_LEVEL_DEBUG);
log2.set_level(srslte::LOG_LEVEL_DEBUG);
log1.set_hex_limit(-1);
@ -152,8 +153,8 @@ void basic_test()
void concat_test()
{
srslte::log_stdout log1("RLC_AM_1");
srslte::log_stdout log2("RLC_AM_2");
srslte::log_filter log1("RLC_AM_1");
srslte::log_filter log2("RLC_AM_2");
log1.set_level(srslte::LOG_LEVEL_DEBUG);
log2.set_level(srslte::LOG_LEVEL_DEBUG);
log1.set_hex_limit(-1);
@ -216,8 +217,8 @@ void concat_test()
void segment_test()
{
srslte::log_stdout log1("RLC_AM_1");
srslte::log_stdout log2("RLC_AM_2");
srslte::log_filter log1("RLC_AM_1");
srslte::log_filter log2("RLC_AM_2");
log1.set_level(srslte::LOG_LEVEL_DEBUG);
log2.set_level(srslte::LOG_LEVEL_DEBUG);
log1.set_hex_limit(-1);
@ -298,8 +299,8 @@ void segment_test()
void retx_test()
{
srslte::log_stdout log1("RLC_AM_1");
srslte::log_stdout log2("RLC_AM_2");
srslte::log_filter log1("RLC_AM_1");
srslte::log_filter log2("RLC_AM_2");
log1.set_level(srslte::LOG_LEVEL_DEBUG);
log2.set_level(srslte::LOG_LEVEL_DEBUG);
log1.set_hex_limit(-1);
@ -394,8 +395,8 @@ void resegment_test_1()
// PDUs: | 10 | 10 | 10 | 10 | 10 |
// Retx PDU segments: | 5 | 5|
srslte::log_stdout log1("RLC_AM_1");
srslte::log_stdout log2("RLC_AM_2");
srslte::log_filter log1("RLC_AM_1");
srslte::log_filter log2("RLC_AM_2");
log1.set_level(srslte::LOG_LEVEL_DEBUG);
log2.set_level(srslte::LOG_LEVEL_DEBUG);
log1.set_hex_limit(-1);
@ -503,8 +504,8 @@ void resegment_test_2()
// PDUs: | 5 | 10 | 20 | 10 | 5 |
// Retx PDU segments: | 10 | 10 |
srslte::log_stdout log1("RLC_AM_1");
srslte::log_stdout log2("RLC_AM_2");
srslte::log_filter log1("RLC_AM_1");
srslte::log_filter log2("RLC_AM_2");
log1.set_level(srslte::LOG_LEVEL_DEBUG);
log2.set_level(srslte::LOG_LEVEL_DEBUG);
log1.set_hex_limit(-1);
@ -609,8 +610,8 @@ void resegment_test_3()
// PDUs: | 5 | 5| 20 | 10 | 10 |
// Retx PDU segments: | 10 | 10 |
srslte::log_stdout log1("RLC_AM_1");
srslte::log_stdout log2("RLC_AM_2");
srslte::log_filter log1("RLC_AM_1");
srslte::log_filter log2("RLC_AM_2");
log1.set_level(srslte::LOG_LEVEL_DEBUG);
log2.set_level(srslte::LOG_LEVEL_DEBUG);
log1.set_hex_limit(-1);
@ -711,8 +712,8 @@ void resegment_test_4()
// PDUs: | 5 | 5| 30 | 5 | 5|
// Retx PDU segments: | 15 | 15 |
srslte::log_stdout log1("RLC_AM_1");
srslte::log_stdout log2("RLC_AM_2");
srslte::log_filter log1("RLC_AM_1");
srslte::log_filter log2("RLC_AM_2");
log1.set_level(srslte::LOG_LEVEL_DEBUG);
log2.set_level(srslte::LOG_LEVEL_DEBUG);
log1.set_hex_limit(-1);
@ -813,8 +814,8 @@ void resegment_test_5()
// PDUs: |2|3| 40 |3|2|
// Retx PDU segments: | 20 | 20 |
srslte::log_stdout log1("RLC_AM_1");
srslte::log_stdout log2("RLC_AM_2");
srslte::log_filter log1("RLC_AM_1");
srslte::log_filter log2("RLC_AM_2");
log1.set_level(srslte::LOG_LEVEL_DEBUG);
log2.set_level(srslte::LOG_LEVEL_DEBUG);
log1.set_hex_limit(-1);
@ -914,8 +915,8 @@ void resegment_test_6()
// PDUs: |10|10|10| 270 | 54 |
// Retx PDU segments: | 120 | 150 |
srslte::log_stdout log1("RLC_AM_1");
srslte::log_stdout log2("RLC_AM_2");
srslte::log_filter log1("RLC_AM_1");
srslte::log_filter log2("RLC_AM_2");
log1.set_level(srslte::LOG_LEVEL_DEBUG);
log2.set_level(srslte::LOG_LEVEL_DEBUG);
log1.set_hex_limit(-1);

@ -25,7 +25,7 @@
*/
#include <iostream>
#include "srslte/common/log_stdout.h"
#include "srslte/common/log_filter.h"
#include "srslte/upper/rlc_um.h"
#include <assert.h>
@ -78,8 +78,8 @@ public:
void basic_test()
{
srslte::log_stdout log1("RLC_UM_1");
srslte::log_stdout log2("RLC_UM_2");
srslte::log_filter log1("RLC_UM_1");
srslte::log_filter log2("RLC_UM_2");
log1.set_level(srslte::LOG_LEVEL_DEBUG);
log2.set_level(srslte::LOG_LEVEL_DEBUG);
log1.set_hex_limit(-1);
@ -146,8 +146,8 @@ void basic_test()
void loss_test()
{
srslte::log_stdout log1("RLC_UM_1");
srslte::log_stdout log2("RLC_UM_2");
srslte::log_filter log1("RLC_UM_1");
srslte::log_filter log2("RLC_UM_2");
log1.set_level(srslte::LOG_LEVEL_DEBUG);
log2.set_level(srslte::LOG_LEVEL_DEBUG);
log1.set_hex_limit(-1);

@ -21,9 +21,9 @@
find_package(LibConfig REQUIRED)
find_package(SCTP REQUIRED)
if(STATIC_LIBCONFIGPP)
if(BUILD_STATIC)
set(LIBCONFIGPP_LIBRARIES "${LIBCONFIGPP_STATIC_LIBRARY_PATH}")
endif(STATIC_LIBCONFIGPP)
endif(BUILD_STATIC)
if(NOT Boost_FOUND)
message(FATAL_ERROR "Boost required to compile srsENB")

@ -50,7 +50,7 @@
#include "srslte/common/bcd_helpers.h"
#include "srslte/common/buffer_pool.h"
#include "srslte/interfaces/ue_interfaces.h"
#include "srslte/common/logger.h"
#include "srslte/common/logger_file.h"
#include "srslte/common/log_filter.h"
#include "srslte/common/mac_pcap.h"
#include "srslte/interfaces/sched_interface.h"
@ -173,15 +173,15 @@ private:
srsenb::gtpu gtpu;
srsenb::s1ap s1ap;
srslte::logger logger;
srslte::log_filter rf_log;
std::vector<void*> phy_log;
srslte::log_filter mac_log;
srslte::log_filter rlc_log;
srslte::log_filter pdcp_log;
srslte::log_filter rrc_log;
srslte::log_filter gtpu_log;
srslte::log_filter s1ap_log;
srslte::logger_file logger;
srslte::log_filter rf_log;
std::vector<void*> phy_log;
srslte::log_filter mac_log;
srslte::log_filter rlc_log;
srslte::log_filter pdcp_log;
srslte::log_filter rrc_log;
srslte::log_filter gtpu_log;
srslte::log_filter s1ap_log;
srslte::byte_buffer_pool *pool;

@ -5,9 +5,9 @@ add_subdirectory(upper)
# Link libstdc++ and libgcc
if(STATIC_LIB)
if(BUILD_STATIC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
endif(STATIC_LIB)
endif(BUILD_STATIC)
if (RPATH)

@ -6,7 +6,7 @@
#include "srslte/interfaces/enb_interfaces.h"
#include "srslte/interfaces/sched_interface.h"
#include "srslte/common/log_stdout.h"
#include "srslte/common/log_filter.h"
#include "srslte/radio/radio.h"
#include "srslte/phy/utils/debug.h"
@ -62,7 +62,7 @@ private:
// Create classes
srslte::log_stdout log_out("ALL");
srslte::log_filter log_out("ALL");
srsenb::sched my_sched;
srsenb::dl_metric_rr dl_metric;
srsenb::ul_metric_rr ul_metric;

@ -16,7 +16,7 @@
#include "srslte/interfaces/enb_interfaces.h"
#include "srslte/common/common.h"
#include "srslte/common/buffer_pool.h"
#include "srslte/common/logger.h"
#include "srslte/common/logger_file.h"
#include "srslte/common/log_filter.h"
#include "srslte/upper/rlc.h"
#include "srslte/radio/radio.h"
@ -320,11 +320,11 @@ private:
// Create classes
srslte::logger logger;
srslte::log_filter log_phy;
srslte::log_filter log_mac;
srslte::log_filter log_rlc;
srslte::log_filter log_tester;
srslte::logger_file logger;
srslte::log_filter log_phy;
srslte::log_filter log_mac;
srslte::log_filter log_rlc;
srslte::log_filter log_tester;
srsenb::phy my_phy;
srsenb::mac my_mac;
srslte::rlc my_rlc;

@ -49,7 +49,7 @@
#include "srslte/common/buffer_pool.h"
#include "srslte/interfaces/ue_interfaces.h"
#include "srslte/common/logger.h"
#include "srslte/common/logger_file.h"
#include "srslte/common/log_filter.h"
#include "ue_metrics_interface.h"
@ -173,16 +173,16 @@ private:
srslte::gw gw;
srsue::usim usim;
srslte::logger logger;
srslte::log_filter rf_log;
srslte::log_filter phy_log;
srslte::log_filter mac_log;
srslte::log_filter rlc_log;
srslte::log_filter pdcp_log;
srslte::log_filter rrc_log;
srslte::log_filter nas_log;
srslte::log_filter gw_log;
srslte::log_filter usim_log;
srslte::logger_file logger;
srslte::log_filter rf_log;
srslte::log_filter phy_log;
srslte::log_filter mac_log;
srslte::log_filter rlc_log;
srslte::log_filter pdcp_log;
srslte::log_filter rrc_log;
srslte::log_filter nas_log;
srslte::log_filter gw_log;
srslte::log_filter usim_log;
srslte::byte_buffer_pool *pool;

@ -22,6 +22,11 @@ add_subdirectory(phy)
add_subdirectory(mac)
add_subdirectory(upper)
# Link libstdc++ and libgcc
if(BUILD_STATIC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
endif(BUILD_STATIC)
if (RPATH)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
endif (RPATH)

@ -32,7 +32,7 @@
#include "srslte/radio/radio_multi.h"
#include "phy/phy.h"
#include "srslte/interfaces/ue_interfaces.h"
#include "srslte/common/log_stdout.h"
#include "srslte/common/log_filter.h"
#include "mac/mac.h"
#include "srslte/common/mac_pcap.h"
@ -427,7 +427,7 @@ private:
int main(int argc, char *argv[])
{
srslte::log_stdout mac_log("MAC"), phy_log("PHY");
srslte::log_filter mac_log("MAC"), phy_log("PHY");
rlctest my_rlc;
parse_args(&prog_args, argc, argv);

@ -29,7 +29,7 @@
#include "srslte/phy/utils/debug.h"
#include "phy/phy.h"
#include "srslte/interfaces/ue_interfaces.h"
#include "srslte/common/log_stdout.h"
#include "srslte/common/log_filter.h"
#include "srslte/radio/radio_multi.h"
/**********************************************************************
@ -330,7 +330,7 @@ srslte::radio_multi radio;
int main(int argc, char *argv[])
{
srslte::log_stdout log("PHY");
srslte::log_filter log("PHY");
parse_args(&prog_args, argc, argv);

@ -28,7 +28,7 @@
#include "srslte/phy/utils/debug.h"
#include "phy/phy.h"
#include "srslte/common/log_stdout.h"
#include "srslte/common/log_filter.h"
#include "srslte/interfaces/ue_interfaces.h"
#include "srslte/radio/radio_multi.h"
@ -153,7 +153,7 @@ srslte::radio_multi radio;
int main(int argc, char *argv[])
{
srslte::log_stdout log("PHY");
srslte::log_filter log("PHY");
parse_args(&prog_args, argc, argv);

@ -0,0 +1,645 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <arpa/inet.h>
#include <linux/ip.h>
#include <linux/if.h>
#include <linux/if_tun.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <assert.h>
#include "srslte/phy/utils/debug.h"
#include "mac/mac.h"
#include "phy/phy.h"
#include "srslte/common/threads.h"
#include "srslte/common/common.h"
#include "srslte/common/buffer_pool.h"
#include "srslte/common/logger_file.h"
#include "srslte/common/log_filter.h"
#include "srslte/upper/rlc.h"
#include "upper/rrc.h"
#include "srslte/radio/radio_multi.h"
#define START_TUNTAP
#define USE_RADIO
#define PRINT_GW 0
/**********************************************************************
* Program arguments processing
***********************************************************************/
#define LCID 3
typedef struct {
float rx_freq;
float tx_freq;
float rx_gain;
float tx_gain;
int time_adv;
std::string ip_address;
}prog_args_t;
uint32_t srsapps_verbose = 1;
prog_args_t prog_args;
void args_default(prog_args_t *args) {
args->tx_freq = 2.505e9;
args->rx_freq = 2.625e9;
args->rx_gain = 50.0;
args->tx_gain = 70.0;
args->time_adv = -1; // calibrated for b210
args->ip_address = "192.168.3.2";
}
void usage(prog_args_t *args, char *prog) {
printf("Usage: %s [gGIrfFtv]\n", prog);
printf("\t-f RX frequency [Default %.1f MHz]\n", args->rx_freq/1e6);
printf("\t-F TX frequency [Default %.1f MHz]\n", args->tx_freq/1e6);
printf("\t-g RX gain [Default %.1f]\n", args->rx_gain);
printf("\t-G TX gain [Default %.1f]\n", args->tx_gain);
printf("\t-I IP address [Default %s]\n", args->ip_address.c_str());
printf("\t-t time advance (in samples) [Default %d]\n", args->time_adv);
printf("\t-v [increase verbosity, default none]\n");
}
void parse_args(prog_args_t *args, int argc, char **argv) {
int opt;
args_default(args);
while ((opt = getopt(argc, argv, "gGfFItv")) != -1) {
switch (opt) {
case 'g':
args->rx_gain = atof(argv[optind]);
break;
case 'G':
args->tx_gain = atof(argv[optind]);
break;
case 'f':
args->rx_freq = atof(argv[optind]);
break;
case 'F':
args->tx_freq = atof(argv[optind]);
break;
case 'I':
args->ip_address = argv[optind];
break;
case 't':
args->time_adv = atoi(argv[optind]);
break;
case 'v':
srsapps_verbose++;
break;
default:
usage(args, argv[0]);
exit(-1);
}
}
if (args->rx_freq < 0 || args->tx_freq < 0) {
usage(args, argv[0]);
exit(-1);
}
}
int setup_if_addr(char *ip_addr);
// Define dummy RLC always transmitts
class tester : public srsue::pdcp_interface_rlc,
public srsue::rrc_interface_rlc,
public srsue::rrc_interface_phy,
public srsue::rrc_interface_mac,
public srsue::ue_interface,
public thread
{
public:
tester() {
state = srsue::RRC_STATE_SIB1_SEARCH;
read_enable = true;
}
void init(srsue::phy *phy_, srsue::mac *mac_, srslte::rlc *rlc_, srslte::log *log_h_, std::string ip_address) {
log_h = log_h_;
rlc = rlc_;
mac = mac_;
phy = phy_;
#ifdef START_TUNTAP
if (init_tuntap((char*) ip_address.c_str())) {
log_h->error("Initiating IP address\n");
}
#endif
pool = srslte::byte_buffer_pool::get_instance();
// Start reader thread
running=true;
start();
}
void sib_search()
{
bool searching = true;
uint32_t tti ;
uint32_t si_win_start, si_win_len;
uint16_t period;
uint32_t nof_sib1_trials = 0;
const int SIB1_SEARCH_TIMEOUT = 30;
while(searching)
{
switch(state)
{
case srsue::RRC_STATE_SIB1_SEARCH:
// Instruct MAC to look for SIB1
while(!phy->status_is_sync()){
usleep(50000);
}
usleep(10000);
tti = mac->get_current_tti();
si_win_start = sib_start_tti(tti, 2, 5);
mac->bcch_start_rx(si_win_start, 1);
log_h->info("Instructed MAC to search for SIB1, win_start=%d, win_len=%d\n",
si_win_start, 1);
nof_sib1_trials++;
if (nof_sib1_trials >= SIB1_SEARCH_TIMEOUT) {
log_h->info("Timeout while searching for SIB1. Resynchronizing SFN...\n");
log_h->console("Timeout while searching for SIB1. Resynchronizing SFN...\n");
phy->resync_sfn();
nof_sib1_trials = 0;
}
break;
case srsue::RRC_STATE_SIB2_SEARCH:
// Instruct MAC to look for SIB2
usleep(10000);
tti = mac->get_current_tti();
period = liblte_rrc_si_periodicity_num[sib1.sched_info[0].si_periodicity];
si_win_start = sib_start_tti(tti, period, 0);
si_win_len = liblte_rrc_si_window_length_num[sib1.si_window_length];
mac->bcch_start_rx(si_win_start, si_win_len);
log_h->info("Instructed MAC to search for SIB2, win_start=%d, win_len=%d\n",
si_win_start, si_win_len);
break;
default:
searching = false;
break;
}
usleep(100000);
}
}
bool is_sib_received() {
return state == srsue::RRC_STATE_WAIT_FOR_CON_SETUP;
}
void release_pucch_srs() {}
void ra_problem() {}
void write_pdu_bcch_bch(srslte::byte_buffer_t *pdu) {}
void write_pdu_bcch_dlsch(srslte::byte_buffer_t *pdu)
{
log_h->info_hex(pdu->msg, pdu->N_bytes, "BCCH DLSCH message received.");
log_h->info("BCCH DLSCH message Stack latency: %ld us\n", pdu->get_latency_us());
LIBLTE_RRC_BCCH_DLSCH_MSG_STRUCT dlsch_msg;
srslte_bit_unpack_vector(pdu->msg, bit_buf.msg, pdu->N_bytes*8);
bit_buf.N_bits = pdu->N_bytes*8;
pool->deallocate(pdu);
liblte_rrc_unpack_bcch_dlsch_msg((LIBLTE_BIT_MSG_STRUCT*)&bit_buf, &dlsch_msg);
if (dlsch_msg.N_sibs > 0) {
if (LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_1 == dlsch_msg.sibs[0].sib_type && srsue::RRC_STATE_SIB1_SEARCH == state) {
// Handle SIB1
memcpy(&sib1, &dlsch_msg.sibs[0].sib.sib1, sizeof(LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_1_STRUCT));
log_h->info("SIB1 received, CellID=%d, si_window=%d, sib2_period=%d\n",
sib1.cell_id&0xfff,
liblte_rrc_si_window_length_num[sib1.si_window_length],
liblte_rrc_si_periodicity_num[sib1.sched_info[0].si_periodicity]);
std::stringstream ss;
for(uint32_t i=0;i<sib1.N_plmn_ids;i++){
ss << " PLMN Id: MCC " << sib1.plmn_id[i].id.mcc << " MNC " << sib1.plmn_id[i].id.mnc;
}
log_h->console("SIB1 received, CellID=%d, %s\n",
sib1.cell_id&0xfff,
ss.str().c_str());
state = srsue::RRC_STATE_SIB2_SEARCH;
mac->bcch_stop_rx();
//TODO: Use all SIB1 info
} else if (LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2 == dlsch_msg.sibs[0].sib_type && srsue::RRC_STATE_SIB2_SEARCH == state) {
// Handle SIB2
memcpy(&sib2, &dlsch_msg.sibs[0].sib.sib2, sizeof(LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2_STRUCT));
log_h->console("SIB2 received\n");
log_h->info("SIB2 received\n");
state = srsue::RRC_STATE_WAIT_FOR_CON_SETUP;
mac->bcch_stop_rx();
apply_sib2_configs();
srslte::byte_buffer_t *sdu = pool_allocate;
assert(sdu);
// Send Msg3
sdu->N_bytes = 10;
for (uint32_t i=0;i<sdu->N_bytes;i++) {
sdu->msg[i] = i+1;
}
uint64_t uecri = 0;
uint8_t *ue_cri_ptr = (uint8_t*) &uecri;
uint32_t nbytes = 6;
for (uint32_t i=0;i<nbytes;i++) {
ue_cri_ptr[nbytes-i-1] = sdu->msg[i];
}
log_h->info("Setting UE contention resolution ID: %d\n", uecri);
mac->set_contention_id(uecri);
rlc->write_sdu(0, sdu);
}
}
}
void write_pdu_pcch(srslte::byte_buffer_t *sdu) {}
void max_retx_attempted(){}
void in_sync() {};
void out_of_sync() {};
void write_pdu(uint32_t lcid, srslte::byte_buffer_t *sdu)
{
uint32_t n=0;
switch(lcid) {
case LCID:
n = write(tun_fd, sdu->msg, sdu->N_bytes);
if (n != sdu->N_bytes) {
log_h->error("TUN/TAP write failure n=%d, nof_bytes=%d\n", n, sdu->N_bytes);
return;
}
log_h->debug_hex(sdu->msg, sdu->N_bytes,
"Wrote %d bytes to TUN/TAP\n",
sdu->N_bytes);
pool->deallocate(sdu);
break;
case 0:
log_h->info("Received ConnectionSetupComplete\n");
// Setup a single UM bearer
LIBLTE_RRC_RLC_CONFIG_STRUCT cfg;
bzero(&cfg, sizeof(LIBLTE_RRC_RLC_CONFIG_STRUCT));
cfg.rlc_mode = LIBLTE_RRC_RLC_MODE_UM_BI;
cfg.dl_um_bi_rlc.t_reordering = LIBLTE_RRC_T_REORDERING_MS100;
cfg.dl_um_bi_rlc.sn_field_len = LIBLTE_RRC_SN_FIELD_LENGTH_SIZE10;
cfg.ul_um_bi_rlc.sn_field_len = LIBLTE_RRC_SN_FIELD_LENGTH_SIZE10;
rlc->add_bearer(LCID, &cfg);
mac->setup_lcid(LCID, 0, 1, -1, 100000);
LIBLTE_RRC_PHYSICAL_CONFIG_DEDICATED_STRUCT dedicated;
bzero(&dedicated, sizeof(LIBLTE_RRC_PHYSICAL_CONFIG_DEDICATED_STRUCT));
dedicated.pusch_cnfg_ded.beta_offset_ack_idx = 5;
dedicated.pusch_cnfg_ded.beta_offset_ri_idx = 12;
dedicated.pusch_cnfg_ded.beta_offset_cqi_idx = 15;
dedicated.pusch_cnfg_ded_present = true;
dedicated.sched_request_cnfg.dsr_trans_max = LIBLTE_RRC_DSR_TRANS_MAX_N4;
dedicated.sched_request_cnfg.sr_pucch_resource_idx = 0;
dedicated.sched_request_cnfg.sr_cnfg_idx = 35;
dedicated.sched_request_cnfg.setup_present = true;
dedicated.sched_request_cnfg_present = true;
phy->set_config_dedicated(&dedicated);
phy->configure_ul_params();
srsue::mac_interface_rrc::mac_cfg_t mac_cfg;
mac->get_config(&mac_cfg);
memcpy(&mac_cfg.sr, &dedicated.sched_request_cnfg, sizeof(LIBLTE_RRC_SCHEDULING_REQUEST_CONFIG_STRUCT));
mac_cfg.main.ulsch_cnfg.periodic_bsr_timer = LIBLTE_RRC_PERIODIC_BSR_TIMER_SF40;
mac->set_config(&mac_cfg);
break;
default:
log_h->error("Received message for lcid=%d\n", lcid);
break;
}
}
private:
int tun_fd;
bool running;
srslte::log *log_h;
srslte::byte_buffer_pool *pool;
srslte::rlc *rlc;
srsue::mac *mac;
srsue::phy *phy;
srslte::bit_buffer_t bit_buf;
srsue::rrc_state_t state;
LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_1_STRUCT sib1;
LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2_STRUCT sib2;
bool read_enable;
// Determine SI messages scheduling as in 36.331 5.2.3 Acquisition of an SI message
uint32_t sib_start_tti(uint32_t tti, uint32_t period, uint32_t x) {
return (period*10*(1+tti/(period*10))+x)%10240; // the 1 means next opportunity
}
int init_tuntap(char *ip_address) {
read_enable = true;
tun_fd = setup_if_addr(ip_address);
if (tun_fd<0) {
fprintf(stderr, "Error setting up IP %s\n", ip_address);
return -1;
}
printf("Created tun/tap interface at IP %s\n", ip_address);
return 0;
}
void run_thread() {
struct iphdr *ip_pkt;
uint32_t idx = 0;
int32_t N_bytes;
srslte::byte_buffer_t *pdu = pool_allocate;
log_h->info("TUN/TAP reader thread running\n");
while(running) {
N_bytes = read(tun_fd, &pdu->msg[idx], SRSLTE_MAX_BUFFER_SIZE_BYTES-SRSLTE_BUFFER_HEADER_OFFSET - idx);
if(N_bytes > 0 && read_enable)
{
pdu->N_bytes = idx + N_bytes;
ip_pkt = (struct iphdr*)pdu->msg;
log_h->debug_hex(pdu->msg, pdu->N_bytes,
"Read %d bytes from TUN/TAP\n",
N_bytes);
// Check if entire packet was received
if(ntohs(ip_pkt->tot_len) == pdu->N_bytes)
{
log_h->info_hex(pdu->msg, pdu->N_bytes, "UL PDU");
// Send PDU directly to PDCP
pdu->set_timestamp();
rlc->write_sdu(LCID, pdu);
pdu = pool_allocate;
idx = 0;
} else{
idx += N_bytes;
}
}else{
log_h->error("Failed to read from TUN interface - gw receive thread exiting.\n");
break;
}
}
}
void apply_sib2_configs()
{
// Apply RACH timeAlginmentTimer configuration
srsue::mac_interface_rrc::mac_cfg_t cfg;
mac->get_config(&cfg);
cfg.main.time_alignment_timer = sib2.time_alignment_timer;
memcpy(&cfg.rach, &sib2.rr_config_common_sib.rach_cnfg, sizeof(LIBLTE_RRC_RACH_CONFIG_COMMON_STRUCT));
cfg.prach_config_index = sib2.rr_config_common_sib.prach_cnfg.root_sequence_index;
mac->set_config(&cfg);
log_h->info("Set RACH ConfigCommon: NofPreambles=%d, ResponseWindow=%d, ContentionResolutionTimer=%d ms\n",
liblte_rrc_number_of_ra_preambles_num[sib2.rr_config_common_sib.rach_cnfg.num_ra_preambles],
liblte_rrc_ra_response_window_size_num[sib2.rr_config_common_sib.rach_cnfg.ra_resp_win_size],
liblte_rrc_mac_contention_resolution_timer_num[sib2.rr_config_common_sib.rach_cnfg.mac_con_res_timer]);
// Apply PHY RR Config Common
srsue::phy_interface_rrc::phy_cfg_common_t common;
memcpy(&common.pdsch_cnfg, &sib2.rr_config_common_sib.pdsch_cnfg, sizeof(LIBLTE_RRC_PDSCH_CONFIG_COMMON_STRUCT));
memcpy(&common.pusch_cnfg, &sib2.rr_config_common_sib.pusch_cnfg, sizeof(LIBLTE_RRC_PUSCH_CONFIG_COMMON_STRUCT));
memcpy(&common.pucch_cnfg, &sib2.rr_config_common_sib.pucch_cnfg, sizeof(LIBLTE_RRC_PUCCH_CONFIG_COMMON_STRUCT));
memcpy(&common.ul_pwr_ctrl, &sib2.rr_config_common_sib.ul_pwr_ctrl, sizeof(LIBLTE_RRC_UL_POWER_CONTROL_COMMON_STRUCT));
memcpy(&common.prach_cnfg, &sib2.rr_config_common_sib.prach_cnfg, sizeof(LIBLTE_RRC_PRACH_CONFIG_SIB_STRUCT));
if (sib2.rr_config_common_sib.srs_ul_cnfg.present) {
memcpy(&common.srs_ul_cnfg, &sib2.rr_config_common_sib.srs_ul_cnfg, sizeof(LIBLTE_RRC_SRS_UL_CONFIG_COMMON_STRUCT));
} else {
// default is release
common.srs_ul_cnfg.present = false;
}
phy->set_config_common(&common);
phy->configure_ul_params();
log_h->info("Set PUSCH ConfigCommon: HopOffset=%d, RSGroup=%d, RSNcs=%d, N_sb=%d\n",
sib2.rr_config_common_sib.pusch_cnfg.pusch_hopping_offset,
sib2.rr_config_common_sib.pusch_cnfg.ul_rs.group_assignment_pusch,
sib2.rr_config_common_sib.pusch_cnfg.ul_rs.cyclic_shift,
sib2.rr_config_common_sib.pusch_cnfg.n_sb);
log_h->info("Set PUCCH ConfigCommon: DeltaShift=%d, CyclicShift=%d, N1=%d, NRB=%d\n",
liblte_rrc_delta_pucch_shift_num[sib2.rr_config_common_sib.pucch_cnfg.delta_pucch_shift],
sib2.rr_config_common_sib.pucch_cnfg.n_cs_an,
sib2.rr_config_common_sib.pucch_cnfg.n1_pucch_an,
sib2.rr_config_common_sib.pucch_cnfg.n_rb_cqi);
log_h->info("Set PRACH ConfigCommon: SeqIdx=%d, HS=%d, FreqOffset=%d, ZC=%d, ConfigIndex=%d\n",
sib2.rr_config_common_sib.prach_cnfg.root_sequence_index,
sib2.rr_config_common_sib.prach_cnfg.prach_cnfg_info.high_speed_flag?1:0,
sib2.rr_config_common_sib.prach_cnfg.prach_cnfg_info.prach_freq_offset,
sib2.rr_config_common_sib.prach_cnfg.prach_cnfg_info.zero_correlation_zone_config,
sib2.rr_config_common_sib.prach_cnfg.prach_cnfg_info.prach_config_index);
log_h->info("Set SRS ConfigCommon: BW-Configuration=%d, SF-Configuration=%d, ACKNACK=%d\n",
sib2.rr_config_common_sib.srs_ul_cnfg.bw_cnfg,
sib2.rr_config_common_sib.srs_ul_cnfg.subfr_cnfg,
sib2.rr_config_common_sib.srs_ul_cnfg.ack_nack_simul_tx);
}
};
// Create classes
srslte::logger_file logger;
srslte::log_filter log_phy;
srslte::log_filter log_mac;
srslte::log_filter log_rlc;
srslte::log_filter log_tester;
srslte::mac_pcap mac_pcap;
srsue::phy my_phy;
srsue::mac my_mac;
srslte::rlc rlc;
srslte::radio_multi my_radio;
// Local classes for testing
tester my_tester;
bool running = true;
void sig_int_handler(int signo)
{
running = false;
}
int main(int argc, char *argv[])
{
parse_args(&prog_args, argc, argv);
// set to null to disable pcap
const char *pcap_filename = "/tmp/ip_test.pcap";
logger.init("/tmp/ip_test_ue.log");
log_phy.init("PHY ", &logger, true);
log_mac.init("MAC ", &logger, true);
log_rlc.init("RLC ", &logger);
log_tester.init("TEST", &logger);
logger.log("\n\n");
if (srsapps_verbose == 1) {
log_phy.set_level(srslte::LOG_LEVEL_INFO);
log_phy.set_hex_limit(100);
log_mac.set_level(srslte::LOG_LEVEL_DEBUG);
log_mac.set_hex_limit(100);
log_rlc.set_level(srslte::LOG_LEVEL_DEBUG);
log_rlc.set_hex_limit(1000);
log_tester.set_level(srslte::LOG_LEVEL_DEBUG);
log_tester.set_hex_limit(100);
printf("Log level info\n");
}
if (srsapps_verbose == 2) {
log_phy.set_level(srslte::LOG_LEVEL_DEBUG);
log_phy.set_hex_limit(100);
log_mac.set_level(srslte::LOG_LEVEL_DEBUG);
log_mac.set_hex_limit(100);
log_rlc.set_level(srslte::LOG_LEVEL_DEBUG);
log_rlc.set_hex_limit(100);
log_tester.set_level(srslte::LOG_LEVEL_DEBUG);
log_tester.set_hex_limit(100);
srslte_verbose = SRSLTE_VERBOSE_DEBUG;
printf("Log level debug\n");
}
// Init Radio and PHY
#ifdef USE_RADIO
my_radio.init();
#else
my_radio.init(NULL, "dummy");
#endif
my_radio.set_tx_freq(prog_args.tx_freq);
my_radio.set_tx_gain(prog_args.tx_gain);
my_radio.set_rx_freq(prog_args.rx_freq);
my_radio.set_rx_gain(prog_args.rx_gain);
if (prog_args.time_adv >= 0) {
printf("Setting TA=%d samples\n",prog_args.time_adv);
my_radio.set_tx_adv(prog_args.time_adv);
}
my_phy.init(&my_radio, &my_mac, &my_tester, &log_phy, NULL);
my_mac.init(&my_phy, &rlc, &my_tester, &log_mac);
rlc.init(&my_tester, &my_tester, &my_tester, &log_rlc, &my_mac);
my_tester.init(&my_phy, &my_mac, &rlc, &log_tester, prog_args.ip_address);
if (pcap_filename) {
mac_pcap.open(pcap_filename);
my_mac.start_pcap(&mac_pcap);
signal(SIGINT, sig_int_handler);
}
// Set MAC defaults
LIBLTE_RRC_MAC_MAIN_CONFIG_STRUCT default_cfg;
bzero(&default_cfg, sizeof(LIBLTE_RRC_MAC_MAIN_CONFIG_STRUCT));
default_cfg.ulsch_cnfg.max_harq_tx = LIBLTE_RRC_MAX_HARQ_TX_N5;
default_cfg.ulsch_cnfg.periodic_bsr_timer = LIBLTE_RRC_PERIODIC_BSR_TIMER_INFINITY;
default_cfg.ulsch_cnfg.retx_bsr_timer = LIBLTE_RRC_RETRANSMISSION_BSR_TIMER_SF2560;
default_cfg.ulsch_cnfg.tti_bundling = false;
default_cfg.drx_cnfg.setup_present = false;
default_cfg.phr_cnfg.setup_present = false;
default_cfg.time_alignment_timer = LIBLTE_RRC_TIME_ALIGNMENT_TIMER_INFINITY;
my_mac.set_config_main(&default_cfg);
while(running) {
if (my_tester.is_sib_received()) {
printf("Main running\n");
sleep(1);
} else {
my_tester.sib_search();
}
}
if (pcap_filename) {
mac_pcap.close();
}
my_phy.stop();
my_mac.stop();
}
/******************* This is copied from srsue gw **********************/
int setup_if_addr(char *ip_addr)
{
char *dev = (char*) "tun_srsue";
// Construct the TUN device
int tun_fd = open("/dev/net/tun", O_RDWR);
if(0 > tun_fd)
{
perror("open");
return(-1);
}
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
strncpy(ifr.ifr_ifrn.ifrn_name, dev, IFNAMSIZ);
if(0 > ioctl(tun_fd, TUNSETIFF, &ifr))
{
perror("ioctl");
return -1;
}
// Bring up the interface
int sock = socket(AF_INET, SOCK_DGRAM, 0);
if(0 > ioctl(sock, SIOCGIFFLAGS, &ifr))
{
perror("socket");
return -1;
}
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
if(0 > ioctl(sock, SIOCSIFFLAGS, &ifr))
{
perror("ioctl");
return -1;
}
// Setup the IP address
sock = socket(AF_INET, SOCK_DGRAM, 0);
ifr.ifr_addr.sa_family = AF_INET;
((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr = inet_addr(ip_addr);
if(0 > ioctl(sock, SIOCSIFADDR, &ifr))
{
perror("ioctl");
return -1;
}
ifr.ifr_netmask.sa_family = AF_INET;
((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr.s_addr = inet_addr("255.255.255.0");
if(0 > ioctl(sock, SIOCSIFNETMASK, &ifr))
{
perror("ioctl");
return -1;
}
return(tun_fd);
}

@ -26,12 +26,12 @@
#include <iostream>
#include <srslte/srslte.h>
#include "srslte/common/log_stdout.h"
#include "srslte/common/log_filter.h"
#include "srslte/asn1/liblte_rrc.h"
#include "srslte/asn1/liblte_mme.h"
void nas_test() {
srslte::log_stdout log1("NAS");
srslte::log_filter log1("NAS");
log1.set_level(srslte::LOG_LEVEL_DEBUG);
log1.set_hex_limit(-1);
@ -91,7 +91,7 @@ void nas_test() {
}
void basic_test() {
srslte::log_stdout log1("RRC");
srslte::log_filter log1("RRC");
log1.set_level(srslte::LOG_LEVEL_DEBUG);
log1.set_hex_limit(-1);

@ -26,7 +26,7 @@
#include <iostream>
#include "upper/usim.h"
#include "srslte/common/log_stdout.h"
#include "srslte/common/log_filter.h"
#include <assert.h>
using namespace srsue;
@ -67,7 +67,7 @@ uint16 mnc = 93;
int main(int argc, char **argv)
{
srslte::log_stdout usim_log("USIM");
srslte::log_filter usim_log("USIM");
bool net_valid;
uint8_t res[16];

Loading…
Cancel
Save