Merge branch 'next' into enbmimo

master
Xavier Arteaga 7 years ago
commit 57d443ace2

@ -96,35 +96,6 @@ static const char error_text[ERROR_N_ITEMS][20] = { "None",
"Can't start",
"Already started"};
// Radio bearers
typedef enum{
RB_ID_SRB0 = 0,
RB_ID_SRB1,
RB_ID_SRB2,
RB_ID_DRB1,
RB_ID_DRB2,
RB_ID_DRB3,
RB_ID_DRB4,
RB_ID_DRB5,
RB_ID_DRB6,
RB_ID_DRB7,
RB_ID_DRB8,
RB_ID_MAX
} rb_id_t;
static const char rb_id_str[RB_ID_MAX][8] = {"SRB0", "SRB1", "SRB2",
"DRB1", "DRB2", "DRB3",
"DRB4", "DRB5", "DRB6",
"DRB7", "DRB8"};
inline const char* get_rb_name(uint32_t lcid) {
if (lcid < RB_ID_MAX) {
return rb_id_str[lcid];
} else {
return "INVALID_RB";
}
}
/******************************************************************************
* Byte and Bit buffers
*

@ -174,6 +174,7 @@ public:
virtual void enable_capabilities() = 0;
virtual void plmn_search() = 0;
virtual void plmn_select(LIBLTE_RRC_PLMN_IDENTITY_STRUCT plmn_id) = 0;
virtual std::string get_rb_name(uint32_t lcid) = 0;
};
// RRC interface for PDCP
@ -184,6 +185,7 @@ public:
virtual void write_pdu_bcch_bch(srslte::byte_buffer_t *pdu) = 0;
virtual void write_pdu_bcch_dlsch(srslte::byte_buffer_t *pdu) = 0;
virtual void write_pdu_pcch(srslte::byte_buffer_t *pdu) = 0;
virtual std::string get_rb_name(uint32_t lcid) = 0;
};
// RRC interface for RLC
@ -191,6 +193,7 @@ class rrc_interface_rlc
{
public:
virtual void max_retx_attempted() = 0;
virtual std::string get_rb_name(uint32_t lcid) = 0;
};
// PDCP interface for GW

@ -57,10 +57,13 @@ typedef struct SRSLTE_API{
float gain_quant;
int16_t gain_quant_s;
int (*decode) (void*, uint8_t*, uint8_t*, uint32_t);
int (*decode_s) (void*, uint16_t*, uint8_t*, uint32_t);
int (*decode_f) (void*, float*, uint8_t*, uint32_t);
void (*free) (void*);
uint8_t *tmp;
uint16_t *tmp_s;
uint8_t *symbols_uc;
uint16_t *symbols_us;
}srslte_viterbi_t;
SRSLTE_API int srslte_viterbi_init(srslte_viterbi_t *q,
@ -87,6 +90,8 @@ SRSLTE_API int srslte_viterbi_decode_s(srslte_viterbi_t *q,
uint8_t *data,
uint32_t frame_length);
SRSLTE_API int srslte_viterbi_decode_us(srslte_viterbi_t *q, uint16_t *symbols, uint8_t *data, uint32_t frame_length);
SRSLTE_API int srslte_viterbi_decode_uc(srslte_viterbi_t *q,
uint8_t *symbols,
uint8_t *data,

@ -141,8 +141,9 @@ SRSLTE_API uint32_t srslte_vec_max_abs_ci(const cf_t *x, const uint32_t len);
/* quantify vector of floats or int16 and convert to uint8_t */
SRSLTE_API void srslte_vec_quant_fuc(const float *in, uint8_t *out, const float gain, const float offset, const float clip, const uint32_t len);
SRSLTE_API void srslte_vec_quant_fus(float *in, uint16_t *out, float gain, float offset, float clip, uint32_t len);
SRSLTE_API void srslte_vec_quant_suc(const int16_t *in, uint8_t *out, const float gain, const int16_t offset, const int16_t clip, const uint32_t len);
SRSLTE_API void srslte_vec_quant_sus(const int16_t *in, uint16_t *out, const float gain, const int16_t offset, const uint32_t len);
/* magnitude of each vector element */
SRSLTE_API void srslte_vec_abs_cf(const cf_t *x, float *abs, const uint32_t len);
SRSLTE_API void srslte_vec_abs_square_cf(const cf_t *x, float *abs_square, const uint32_t len);

@ -36,8 +36,13 @@
#include "viterbi_test.h"
#define VITERBI_16
int frame_length = 1000, nof_frames = 128;
#ifndef LV_HAVE_AVX2
#undef VITERBI_16
#endif
int frame_length = 1000, nof_frames = 256;
float ebno_db = 100.0;
uint32_t seed = 0;
bool tail_biting = false;
@ -84,6 +89,7 @@ void parse_args(int argc, char **argv) {
int main(int argc, char **argv) {
int frame_cnt;
float *llr;
uint16_t *llr_s;
uint8_t *llr_c;
uint8_t *data_tx, *data_rx, *data_rx2, *symbols;
int i, j;
@ -154,6 +160,11 @@ int main(int argc, char **argv) {
perror("malloc");
exit(-1);
}
llr_s = malloc(2 * coded_length * sizeof(uint16_t));
if (!llr_s) {
perror("malloc");
exit(-1);
}
llr_c = malloc(2 * coded_length * sizeof(uint8_t));
if (!llr_c) {
perror("malloc");
@ -177,7 +188,7 @@ int main(int argc, char **argv) {
snr_points = 1;
}
float Gain = 32;
float Gain = 2500;
for (i = 0; i < snr_points; i++) {
frame_cnt = 0;
@ -206,17 +217,22 @@ int main(int argc, char **argv) {
}
srslte_ch_awgn_f(llr, llr, var[i], coded_length);
//srslte_vec_fprint_f(stdout, llr, 100);
srslte_vec_quant_fuc(llr, llr_c, 32, 127.5, 255, coded_length);
srslte_vec_quant_fus(llr, llr_s, 8192, 32767.5, 65535, coded_length);
srslte_vec_quant_fuc(llr, llr_c, Gain, 127.5, 255, coded_length);
struct timeval t[3];
gettimeofday(&t[1], NULL);
int M = 1;
//srslte_vec_fprint_b(stdout, data_tx, frame_length);
for (int i=0;i<M;i++) {
srslte_viterbi_decode_uc(&dec, llr_c, data_rx, frame_length);
#ifdef VITERBI_16
srslte_viterbi_decode_us(&dec, llr_s, data_rx, frame_length);
#else
srslte_viterbi_decode_uc(&dec, llr_c, data_rx, frame_length);
#endif
}
#ifdef TEST_SSE

@ -42,6 +42,13 @@
#define DEFAULT_GAIN 100
#define DEFAULT_GAIN_16 10000
#define VITERBI_16
#ifndef LV_HAVE_AVX2
#undef VITERBI_16
#endif
//#undef LV_HAVE_SSE
@ -66,7 +73,7 @@ int decode37(void *o, uint8_t *symbols, uint8_t *data, uint32_t frame_length) {
}
update_viterbi37_blk_port(q->ptr, q->tmp, TB_ITER*frame_length, &best_state);
chainback_viterbi37_port(q->ptr, q->tmp, TB_ITER*frame_length, best_state);
memcpy(data, &q->tmp[((int) (TB_ITER/2))*frame_length], frame_length*sizeof(uint8_t));
memcpy(data, q->tmp, frame_length*sizeof(uint8_t));
} else {
update_viterbi37_blk_port(q->ptr, symbols, frame_length + q->K - 1, NULL);
chainback_viterbi37_port(q->ptr, data, frame_length, 0);
@ -98,7 +105,7 @@ int decode37_sse(void *o, uint8_t *symbols, uint8_t *data, uint32_t frame_length
}
update_viterbi37_blk_sse(q->ptr, q->tmp, TB_ITER*frame_length, &best_state);
chainback_viterbi37_sse(q->ptr, q->tmp, TB_ITER*frame_length, best_state);
memcpy(data, &q->tmp[((int) (TB_ITER/2))*frame_length], frame_length*sizeof(uint8_t));
memcpy(data, q->tmp, frame_length*sizeof(uint8_t));
} else {
update_viterbi37_blk_sse(q->ptr, symbols, frame_length+q->K-1, NULL);
chainback_viterbi37_sse(q->ptr, data, frame_length, 0);
@ -123,7 +130,7 @@ void free37_sse(void *o) {
#ifdef LV_HAVE_AVX2
int decode37_avx2(void *o, uint8_t *symbols, uint8_t *data, uint32_t frame_length) {
int decode37_avx2_16bit(void *o, uint16_t *symbols, uint8_t *data, uint32_t frame_length) {
srslte_viterbi_t *q = o;
uint32_t best_state;
@ -133,10 +140,51 @@ int decode37_avx2(void *o, uint8_t *symbols, uint8_t *data, uint32_t frame_lengt
q->framebits);
return -1;
}
/* Initialize Viterbi decoder */
init_viterbi37_avx2_16bit(q->ptr, q->tail_biting?-1:0);
/* Decode block */
if (q->tail_biting) {
for (int i=0;i<TB_ITER;i++) {
memcpy(&q->tmp_s[i*3*frame_length], symbols, 3*frame_length*sizeof(uint16_t));
}
update_viterbi37_blk_avx2_16bit(q->ptr, q->tmp_s, TB_ITER*frame_length, &best_state);
chainback_viterbi37_avx2_16bit(q->ptr, q->tmp, TB_ITER*frame_length, best_state);
memcpy(data, q->tmp, frame_length*sizeof(uint8_t));
} else {
update_viterbi37_blk_avx2_16bit(q->ptr, symbols, frame_length+q->K-1, NULL);
chainback_viterbi37_avx2_16bit(q->ptr, data, frame_length, 0);
}
return q->framebits;
}
void free37_avx2_16bit(void *o) {
srslte_viterbi_t *q = o;
if (q->symbols_uc) {
free(q->symbols_uc);
}
if (q->tmp) {
free(q->tmp);
}
delete_viterbi37_avx2_16bit(q->ptr);
}
int decode37_avx2(void *o, uint8_t *symbols, uint8_t *data, uint32_t frame_length) {
srslte_viterbi_t *q = o;
uint32_t best_state;
if (frame_length > q->framebits) {
fprintf(stderr, "Initialized decoder for max frame length %d bits\n",
q->framebits);
return -1;
}
/* Initialize Viterbi decoder */
init_viterbi37_avx2(q->ptr, q->tail_biting?-1:0);
/* Decode block */
if (q->tail_biting) {
for (int i=0;i<TB_ITER;i++) {
@ -144,7 +192,7 @@ int decode37_avx2(void *o, uint8_t *symbols, uint8_t *data, uint32_t frame_lengt
}
update_viterbi37_blk_avx2(q->ptr, q->tmp, TB_ITER*frame_length, &best_state);
chainback_viterbi37_avx2(q->ptr, q->tmp, TB_ITER*frame_length, best_state);
memcpy(data, &q->tmp[((int) (TB_ITER/2))*frame_length], frame_length*sizeof(uint8_t));
memcpy(data, q->tmp, frame_length*sizeof(uint8_t));
} else {
update_viterbi37_blk_avx2(q->ptr, symbols, frame_length+q->K-1, NULL);
chainback_viterbi37_avx2(q->ptr, data, frame_length, 0);
@ -164,6 +212,7 @@ void free37_avx2(void *o) {
delete_viterbi37_avx2(q->ptr);
}
#endif
#ifdef HAVE_NEON
@ -188,7 +237,7 @@ int decode37_neon(void *o, uint8_t *symbols, uint8_t *data, uint32_t frame_lengt
}
update_viterbi37_blk_neon(q->ptr, q->tmp, TB_ITER*frame_length, &best_state);
chainback_viterbi37_neon(q->ptr, q->tmp, TB_ITER*frame_length, best_state);
memcpy(data, &q->tmp[((int) (TB_ITER/2))*frame_length], frame_length*sizeof(uint8_t));
memcpy(data, q->tmp, frame_length*sizeof(uint8_t));
} else {
update_viterbi37_blk_neon(q->ptr, symbols, frame_length+q->K-1, NULL);
chainback_viterbi37_neon(q->ptr, data, frame_length, 0);
@ -368,6 +417,44 @@ int init37_avx2(srslte_viterbi_t *q, int poly[3], uint32_t framebits, bool tail_
return 0;
}
}
int init37_avx2_16bit(srslte_viterbi_t *q, int poly[3], uint32_t framebits, bool tail_biting) {
q->K = 7;
q->R = 3;
q->framebits = framebits;
q->gain_quant_s = 4;
q->gain_quant = DEFAULT_GAIN;
q->tail_biting = tail_biting;
q->decode_s = decode37_avx2_16bit;
q->free = free37_avx2_16bit;
q->decode_f = NULL;
q->symbols_uc = srslte_vec_malloc(3 * (q->framebits + q->K - 1) * sizeof(uint8_t));
q->symbols_us = srslte_vec_malloc(3 * (q->framebits + q->K - 1) * sizeof(uint16_t));
if (!q->symbols_uc || !q->symbols_us) {
perror("malloc");
return -1;
}
if (q->tail_biting) {
q->tmp = srslte_vec_malloc(TB_ITER*3*(q->framebits + q->K - 1) * sizeof(uint8_t));
q->tmp_s = srslte_vec_malloc(TB_ITER*3*(q->framebits + q->K - 1) * sizeof(uint16_t));
if (!q->tmp) {
perror("malloc");
free37(q);
return -1;
}
} else {
q->tmp = NULL;
}
//printf("pt0\n");
if ((q->ptr = create_viterbi37_avx2_16bit(poly, TB_ITER*framebits)) == NULL) {
fprintf(stderr, "create_viterbi37 failed\n");
free37(q);
return -1;
} else {
return 0;
}
}
#endif
void srslte_viterbi_set_gain_quant(srslte_viterbi_t *q, float gain_quant) {
@ -383,8 +470,13 @@ int srslte_viterbi_init(srslte_viterbi_t *q, srslte_viterbi_type_t type, int pol
switch (type) {
case SRSLTE_VITERBI_37:
#ifdef LV_HAVE_SSE
#ifdef LV_HAVE_AVX2
#ifdef VITERBI_16
return init37_avx2_16bit(q, poly, max_frame_length, tail_bitting);
#else
return init37_avx2(q, poly, max_frame_length, tail_bitting);
#endif
#else
return init37_sse(q, poly, max_frame_length, tail_bitting);
#endif
@ -444,8 +536,13 @@ int srslte_viterbi_decode_f(srslte_viterbi_t *q, float *symbols, uint8_t *data,
max = fabs(symbols[i]);
}
}
srslte_vec_quant_fuc(symbols, q->symbols_uc, q->gain_quant/max, 127.5, 255, len);
return srslte_viterbi_decode_uc(q, q->symbols_uc, data, frame_length);
#ifdef VITERBI_16
srslte_vec_quant_fus(symbols, q->symbols_us, DEFAULT_GAIN_16/max, 32767.5, 65535, len);
return srslte_viterbi_decode_us(q, q->symbols_us, data, frame_length);
#else
srslte_vec_quant_fuc(symbols, q->symbols_uc, q->gain_quant/max, 127.5, 255, len);
return srslte_viterbi_decode_uc(q, q->symbols_uc, data, frame_length);
#endif
} else {
return q->decode_f(q, symbols, data, frame_length);
}
@ -472,8 +569,20 @@ int srslte_viterbi_decode_s(srslte_viterbi_t *q, int16_t *symbols, uint8_t *data
max = abs(symbols[i]);
}
}
srslte_vec_quant_suc(symbols, q->symbols_uc, (float) q->gain_quant/max, 127, 255, len);
return srslte_viterbi_decode_uc(q, q->symbols_uc, data, frame_length);
#ifdef VITERBI_16
srslte_vec_quant_sus(symbols, q->symbols_us, 1, 32767, len);
return srslte_viterbi_decode_us(q, q->symbols_us, data, frame_length);
#else
srslte_vec_quant_suc(symbols, q->symbols_uc, (float) q->gain_quant/max, 127, 255, len);
return srslte_viterbi_decode_uc(q, q->symbols_uc, data, frame_length);
#endif
}
int srslte_viterbi_decode_us(srslte_viterbi_t *q, uint16_t *symbols, uint8_t *data, uint32_t frame_length)
{
return q->decode_s(q, symbols, data, frame_length);
}

@ -110,3 +110,23 @@ int update_viterbi37_blk_avx2(void *p,
uint32_t *best_state);
void *create_viterbi37_avx2_16bit(int polys[3],
uint32_t len);
int init_viterbi37_avx2_16bit(void *p,
int starting_state);
void reset_blk_avx2_16bit(void *p, int nbits);
int chainback_viterbi37_avx2_16bit(void *p,
uint8_t *data,
uint32_t nbits,
uint32_t endstate);
void delete_viterbi37_avx2_16bit(void *p);
int update_viterbi37_blk_avx2_16bit(void *p,
uint16_t *syms,
uint32_t nbits,
uint32_t *best_state);

@ -76,14 +76,16 @@ int init_viterbi37_avx2(void *p, int starting_state) {
struct v37 *vp = p;
uint32_t i;
firstGo = 1;
for(i=0;i<64;i++)
vp->metrics1.c[i] = 63;
clear_v37_avx2(vp);
vp->old_metrics = &vp->metrics1;
vp->new_metrics = &vp->metrics2;
vp->dp = vp->decisions;
if (starting_state != -1) {
vp->old_metrics->c[starting_state & 63] = 0; /* Bias known start state */
}
@ -259,7 +261,7 @@ void update_viterbi37_blk_avx2(void *p,unsigned char *syms,int nbits, uint32_t *
d->s[0] = (short) y;
d->s[1] = (short) x;
d->s[2] = (short) (y >>16);
d->s[3] = (short)(x>> 16);
d->s[3] = (short) (x >>16);
__m256i unpack;

@ -0,0 +1,363 @@
/* Adapted Phil Karn's r=1/3 k=9 viterbi decoder to r=1/3 k=7
*
* K=15 r=1/6 Viterbi decoder for x86 SSE2
* Copyright Mar 2004, Phil Karn, KA9Q
* May be used under the terms of the GNU Lesser General Public License (LGPL)
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <memory.h>
#include <limits.h>
#include "parity.h"
//#define DEBUG
#ifdef LV_HAVE_AVX2
#include <emmintrin.h>
#include <tmmintrin.h>
#include <immintrin.h>
#include <emmintrin.h>
typedef union {
//unsigned char c[64];
//__m128i v[4];
unsigned short c[64];
__m256i v[4];
} metric_t;
typedef union {
unsigned int w[2];
unsigned char c[8];
unsigned short s[4];
__m64 v[1];
} decision_t;
union branchtab27 {
//unsigned char c[32];
//__m128i v[2];
unsigned short c[32];
__m256i v[2];
} Branchtab37_sse2[3];
int firstGo;
/* State info for instance of Viterbi decoder */
struct v37 {
metric_t metrics1; /* path metric buffer 1 */
metric_t metrics2; /* path metric buffer 2 */
decision_t *dp; /* Pointer to current decision */
metric_t *old_metrics,*new_metrics; /* Pointers to path metrics, swapped on every bit */
decision_t *decisions; /* Beginning of decisions for block */
uint32_t len;
};
void set_viterbi37_polynomial_avx2_16bit(int polys[3]) {
int state;
for(state=0;state < 32;state++){
Branchtab37_sse2[0].c[state] = (polys[0] < 0) ^ parity((2*state) & polys[0]) ? 65535:0;
Branchtab37_sse2[1].c[state] = (polys[1] < 0) ^ parity((2*state) & polys[1]) ? 65535:0;
Branchtab37_sse2[2].c[state] = (polys[2] < 0) ^ parity((2*state) & polys[2]) ? 65535:0;
}
}
void clear_v37_avx2_16bit(struct v37 *vp) {
bzero(vp->decisions, sizeof(decision_t)*vp->len);
vp->dp = NULL;
bzero(&vp->metrics1, sizeof(metric_t));
bzero(&vp->metrics2, sizeof(metric_t));
vp->old_metrics = NULL;
vp->new_metrics = NULL;
}
/* Initialize Viterbi decoder for start of new frame */
int init_viterbi37_avx2_16bit(void *p, int starting_state) {
struct v37 *vp = p;
uint32_t i;
for(i=0;i<64;i++)
vp->metrics1.c[i] = 63;
clear_v37_avx2_16bit(vp);
firstGo = 1;
vp->old_metrics = &vp->metrics1;
vp->new_metrics = &vp->metrics2;
vp->dp = vp->decisions;
if (starting_state != -1) {
vp->old_metrics->c[starting_state & 63] = 0; /* Bias known start state */
}
return 0;
}
/* Create a new instance of a Viterbi decoder */
void *create_viterbi37_avx2_16bit(int polys[3], uint32_t len) {
void *p;
struct v37 *vp;
set_viterbi37_polynomial_avx2_16bit(polys);
/* Ordinary malloc() only returns 8-byte alignment, we need 16 */
if(posix_memalign(&p, sizeof(__m256i),sizeof(struct v37)))
return NULL;
vp = (struct v37 *)p;
if(posix_memalign(&p, sizeof(__m256i),(len+6)*sizeof(decision_t))) {
free(vp);
return NULL;
}
vp->decisions = (decision_t *)p;
vp->len = len+6;
return vp;
}
/* Viterbi chainback */
int chainback_viterbi37_avx2_16bit(
void *p,
uint8_t *data, /* Decoded output data */
uint32_t nbits, /* Number of data bits */
uint32_t endstate) { /* Terminal encoder state */
struct v37 *vp = p;
if (p == NULL)
return -1;
decision_t *d = (decision_t *)vp->decisions;
/* Make room beyond the end of the encoder register so we can
* accumulate a full byte of decoded data
*/
endstate %= 64;
endstate <<= 2;
/* The store into data[] only needs to be done every 8 bits.
* But this avoids a conditional branch, and the writes will
* combine in the cache anyway
*/
d += 6; /* Look past tail */
while(nbits--) {
int k;
k = (d[nbits].c[(endstate>>2)/8] >> ((endstate>>2)%8)) & 1;
endstate = (endstate >> 1) | (k << 7);
data[nbits] = k;
//printf("nbits=%d, endstate=%3d, k=%d, w[0]=%d, w[1]=%d, c=%d\n", nbits, endstate, k, d[nbits].s[1]&1, d[nbits].s[2]&1, d[nbits].c[(endstate>>2)/8]&1);
}
return 0;
}
/* Delete instance of a Viterbi decoder */
void delete_viterbi37_avx2_16bit(void *p){
struct v37 *vp = p;
if(vp != NULL){
free(vp->decisions);
free(vp);
}
}
void print_256i(char *s, __m256i val) {
printf("%s: ", s);
uint16_t *x = (uint16_t*) &val;
for (int i=0;i<16;i++) {
printf("%.5f, ", (float)x[i]/65535);
}
printf("\n");
}
void print_256i_char(char *s, __m256i val) {
printf("%s: ", s);
uint8_t *x = (uint8_t*) &val;
for (int i=0;i<32;i++) {
printf("%d, ",x[31-i]);
}
printf("\n");
}
inline unsigned short my_mm256_movemask_epi16(__m256i x) {
uint32_t x1 = _mm256_movemask_epi8(x);
uint16_t tmp = 0;
for(int i = 0; i<16;i++){
tmp |= ((x1 >> ((i*2)+1)) & 0x01) << i;
}
return (tmp);
}
void update_viterbi37_blk_avx2_16bit(void *p, unsigned short *syms, int nbits, uint32_t *best_state) {
struct v37 *vp = p;
decision_t *d;
if(p == NULL)
return;
#ifdef DEBUG
printf("[");
#endif
d = (decision_t *) vp->dp;
for (int s=0;s<nbits;s++) {
memset(d+s,0,sizeof(decision_t));
}
while(nbits--) {
__m256i sym0v,sym1v,sym2v;
void *tmp;
int i;
// printf("nbits=%d, syms=%d,%d,%d\n", nbits, syms[0], syms[1], syms[2]);fflush(stdout);
/* Splat the 0th symbol across sym0v, the 1st symbol across sym1v, etc */
sym0v = _mm256_set1_epi16(syms[0]);
sym1v = _mm256_set1_epi16(syms[1]);
sym2v = _mm256_set1_epi16(syms[2]);
syms += 3;
for(i=0;i<2;i++){
__m256i decision0,decision1,metric,m_metric,m0,m1,m2,m3,survivor0,survivor1;
/* Form branch metrics */
m0 = _mm256_avg_epu16(_mm256_xor_si256(Branchtab37_sse2[0].v[i],sym0v),_mm256_xor_si256(Branchtab37_sse2[1].v[i],sym1v));
metric = _mm256_avg_epu16(_mm256_xor_si256(Branchtab37_sse2[2].v[i],sym2v),m0);
#ifdef DEBUG
print_128i("metric_initial", metric);
#endif
/* There's no packed bytes right shift in SSE2, so we use the word version and mask
*/
metric = _mm256_srli_epi16(metric,3);
m_metric = _mm256_sub_epi16(_mm256_set1_epi16(8191),metric);
#ifdef DEBUG
print_128i("metric ", metric);
print_128i("m_metric ", m_metric);
#endif
/* Add branch metrics to path metrics */
m0 = _mm256_add_epi16(vp->old_metrics->v[i],metric);
m3 = _mm256_add_epi16(vp->old_metrics->v[2+i],metric);
m1 = _mm256_add_epi16(vp->old_metrics->v[2+i],m_metric);
m2 = _mm256_add_epi16(vp->old_metrics->v[i],m_metric);
/* Compare and select, using modulo arithmetic */
decision0 = _mm256_cmpgt_epi16(_mm256_sub_epi16(m0,m1),_mm256_setzero_si256());
decision1 = _mm256_cmpgt_epi16(_mm256_sub_epi16(m2,m3),_mm256_setzero_si256());
survivor0 = _mm256_or_si256(_mm256_and_si256(decision0,m1),_mm256_andnot_si256(decision0,m0));
survivor1 = _mm256_or_si256(_mm256_and_si256(decision1,m3),_mm256_andnot_si256(decision1,m2));
/* Pack each set of decisions into 16 bits */
decision0 = _mm256_permute4x64_epi64(decision0,216);
decision1 = _mm256_permute4x64_epi64(decision1,216);
__m256i packed = _mm256_packus_epi16( _mm256_srli_epi16(_mm256_unpacklo_epi16(decision0,decision1),8),_mm256_srli_epi16(_mm256_unpackhi_epi16(decision0,decision1),8));
d->w[i] = _mm256_movemask_epi8(packed);
unsigned char temp_char1 = d->c[4*i + 1];
unsigned char temp_char2 = d->c[4*i + 2];
d->c[4*i+1] = temp_char2;
d->c[4*i+2] = temp_char1;
/* Store surviving metrics */
survivor0 = _mm256_permute4x64_epi64(survivor0,216);
survivor1 = _mm256_permute4x64_epi64(survivor1,216);
vp->new_metrics->v[2*i] = _mm256_unpacklo_epi16(survivor0,survivor1);
vp->new_metrics->v[2*i+1] = _mm256_unpackhi_epi16(survivor0,survivor1);
}
// See if we need to normalize
if (vp->new_metrics->c[0] > 25600) {
int i;
uint16_t adjust;
__m256i adjustv;
union { __m256i v; signed short w[8]; } t;
adjustv = vp->new_metrics->v[0];
for(i=1;i<4;i++) {
adjustv = _mm256_min_epu16(adjustv,vp->new_metrics->v[i]);
}
adjustv = _mm256_min_epu16(adjustv,_mm256_srli_si256(adjustv,16));
adjustv = _mm256_min_epu16(adjustv,_mm256_srli_si256(adjustv,8));
adjustv = _mm256_min_epu16(adjustv,_mm256_srli_si256(adjustv,4));
t.v = adjustv;
adjust = t.w[0];
adjustv = _mm256_set1_epi16(adjust);
/* We cannot use a saturated subtract, because we often have to adjust by more than SHRT_MAX
* This is okay since it can't overflow anyway
*/
for(i=0;i<4;i++)
vp->new_metrics->v[i] = _mm256_sub_epi16(vp->new_metrics->v[i],adjustv);
}
d++;
/* Swap pointers to old and new metrics */
tmp = vp->old_metrics;
vp->old_metrics = vp->new_metrics;
vp->new_metrics = tmp;
}
if (best_state) {
uint32_t i, bst=0;
uint16_t minmetric= UINT16_MAX;
for (i=0;i<64;i++) {
if (vp->old_metrics->c[i] <= minmetric) {
bst = i;
minmetric = vp->old_metrics->c[i];
}
}
*best_state = bst;
}
#ifdef DEBUG
printf("];\n===========================================\n");
#endif
vp->dp = d;
}
#endif

@ -363,6 +363,20 @@ uint32_t srslte_vec_max_abs_ci(const cf_t *x, const uint32_t len) {
return srslte_vec_max_ci_simd(x, len);
}
void srslte_vec_quant_fus(float *in, uint16_t *out, float gain, float offset, float clip, uint32_t len) {
int i;
long tmp;
for (i=0;i<len;i++) {
tmp = (long) (offset + gain * in[i]);
if (tmp < 0)
tmp = 0;
if (tmp > clip)
tmp = clip;
out[i] = (uint16_t) tmp;
}
}
void srslte_vec_quant_fuc(const float *in, uint8_t *out, const float gain, const float offset, const float clip, const uint32_t len) {
int i;
int tmp;
@ -391,6 +405,18 @@ void srslte_vec_quant_suc(const int16_t *in, uint8_t *out, const float gain, con
}
}
void srslte_vec_quant_sus(const int16_t *in, uint16_t *out, const float gain, const int16_t offset, const uint32_t len) {
int i;
int16_t tmp;
for (i=0;i<len;i++) {
tmp = (offset + in[i]*gain);
if (tmp < 0)
tmp = 0;
out[i] = (uint16_t) tmp;
}
}
void srs_vec_cf_cpy(const cf_t *dst, cf_t *src, int len) {
srslte_vec_cp_simd(dst, src, len);
}

@ -100,9 +100,9 @@ void pdcp::add_bearer(uint32_t lcid, srslte_pdcp_config_t cfg)
}
if (!pdcp_array[lcid].is_active()) {
pdcp_array[lcid].init(rlc, rrc, gw, pdcp_log, lcid, cfg);
pdcp_log->info("Added bearer %s\n", get_rb_name(lcid));
pdcp_log->info("Added bearer %s\n", rrc->get_rb_name(lcid).c_str());
} else {
pdcp_log->warning("Bearer %s already configured. Reconfiguration not supported\n", get_rb_name(lcid));
pdcp_log->warning("Bearer %s already configured. Reconfiguration not supported\n", rrc->get_rb_name(lcid).c_str());
}
}

@ -64,7 +64,7 @@ void pdcp_entity::init(srsue::rlc_interface_pdcp *rlc_,
start(PDCP_THREAD_PRIO);
log->debug("Init %s\n", get_rb_name(lcid));
log->debug("Init %s\n", rrc->get_rb_name(lcid).c_str());
}
void pdcp_entity::stop()
@ -94,7 +94,7 @@ void pdcp_entity::reset()
{
active = false;
if(log)
log->debug("Reset %s\n", get_rb_name(lcid));
log->debug("Reset %s\n", rrc->get_rb_name(lcid).c_str());
}
bool pdcp_entity::is_active()
@ -107,7 +107,7 @@ void pdcp_entity::write_sdu(byte_buffer_t *sdu)
{
log->info_hex(sdu->msg, sdu->N_bytes,
"TX %s SDU, SN: %d, do_integrity = %s, do_encryption = %s",
get_rb_name(lcid), tx_count,
rrc->get_rb_name(lcid).c_str(), tx_count,
(do_integrity) ? "true" : "false", (do_encryption) ? "true" : "false");
if (cfg.is_control) {
@ -131,7 +131,7 @@ void pdcp_entity::write_sdu(byte_buffer_t *sdu)
cipher_encrypt(&sdu->msg[sn_len_bytes],
sdu->N_bytes-sn_len_bytes,
&sdu->msg[sn_len_bytes]);
log->info_hex(sdu->msg, sdu->N_bytes, "TX %s SDU (encrypted)", get_rb_name(lcid));
log->info_hex(sdu->msg, sdu->N_bytes, "TX %s SDU (encrypted)", rrc->get_rb_name(lcid).c_str());
}
tx_count++;
@ -340,49 +340,17 @@ void pdcp_entity::run_thread()
while(running) {
rx_pdu_queue.read(&pdu);
log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU, do_integrity = %s, do_encryption = %s",
get_rb_name(lcid), (do_integrity) ? "true" : "false", (do_encryption) ? "true" : "false");
// Handle SRB messages
switch(lcid)
{
case RB_ID_SRB0:
// Simply pass on to RRC
rrc->write_pdu(RB_ID_SRB0, pdu);
break;
case RB_ID_SRB1: // Intentional fall-through
case RB_ID_SRB2:
uint32_t sn;
if (do_encryption) {
cipher_decrypt(&(pdu->msg[sn_len_bytes]),
rx_count,
pdu->N_bytes - sn_len_bytes,
&(pdu->msg[sn_len_bytes]));
log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU (decrypted)", get_rb_name(lcid));
}
if (do_integrity) {
integrity_verify(pdu->msg,
rx_count,
pdu->N_bytes - 4,
&(pdu->msg[pdu->N_bytes - 4]));
}
pdcp_unpack_control_pdu(pdu, &sn);
log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU SN: %d", get_rb_name(lcid), sn);
rrc->write_pdu(lcid, pdu);
break;
}
rrc->get_rb_name(lcid).c_str(), (do_integrity) ? "true" : "false", (do_encryption) ? "true" : "false");
// Handle DRB messages
if(lcid >= RB_ID_DRB1)
{
if (cfg.is_data) {
uint32_t sn;
if (do_encryption) {
cipher_decrypt(&(pdu->msg[sn_len_bytes]),
rx_count,
pdu->N_bytes - sn_len_bytes,
&(pdu->msg[sn_len_bytes]));
log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU (decrypted)", get_rb_name(lcid));
log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU (decrypted)", rrc->get_rb_name(lcid).c_str());
}
if(12 == cfg.sn_len)
{
@ -390,16 +358,40 @@ void pdcp_entity::run_thread()
} else {
pdcp_unpack_data_pdu_short_sn(pdu, &sn);
}
log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU SN: %d", get_rb_name(lcid), sn);
log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU SN: %d", rrc->get_rb_name(lcid).c_str(), sn);
gw->write_pdu(lcid, pdu);
} else {
// Handle SRB messages
if (cfg.is_control) {
uint32_t sn;
if (do_encryption) {
cipher_decrypt(&(pdu->msg[sn_len_bytes]),
rx_count,
pdu->N_bytes - sn_len_bytes,
&(pdu->msg[sn_len_bytes]));
log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU (decrypted)", rrc->get_rb_name(lcid).c_str());
}
if (do_integrity) {
integrity_verify(pdu->msg,
rx_count,
pdu->N_bytes - 4,
&(pdu->msg[pdu->N_bytes - 4]));
}
pdcp_unpack_control_pdu(pdu, &sn);
log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU SN: %d", rrc->get_rb_name(lcid).c_str(), sn);
}
// pass to RRC
rrc->write_pdu(lcid, pdu);
}
rx_count++;
}
}
uint8_t pdcp_entity::get_bearer_id(uint8_t lcid)
{
#define RB_ID_SRB2 2
if(lcid <= RB_ID_SRB2) {
return lcid - 1;
} else {

@ -224,10 +224,10 @@ void rlc::add_bearer(uint32_t lcid)
cnfg.dl_am_rlc.t_status_prohibit = LIBLTE_RRC_T_STATUS_PROHIBIT_MS0;
add_bearer(lcid, srslte_rlc_config_t(&cnfg));
} else {
rlc_log->warning("Bearer %s already configured. Reconfiguration not supported\n", get_rb_name(lcid));
rlc_log->warning("Bearer %s already configured. Reconfiguration not supported\n", rrc->get_rb_name(lcid).c_str());
}
}else{
rlc_log->error("Radio bearer %s does not support default RLC configuration.\n", get_rb_name(lcid));
rlc_log->error("Radio bearer %s does not support default RLC configuration.\n", rrc->get_rb_name(lcid).c_str());
}
}
@ -240,7 +240,7 @@ void rlc::add_bearer(uint32_t lcid, srslte_rlc_config_t cnfg)
if (!rlc_array[lcid].active()) {
rlc_log->info("Adding radio bearer %s with mode %s\n",
get_rb_name(lcid), liblte_rrc_rlc_mode_text[cnfg.rlc_mode]);
rrc->get_rb_name(lcid).c_str(), liblte_rrc_rlc_mode_text[cnfg.rlc_mode]);
switch(cnfg.rlc_mode)
{
case LIBLTE_RRC_RLC_MODE_AM:
@ -260,7 +260,7 @@ void rlc::add_bearer(uint32_t lcid, srslte_rlc_config_t cnfg)
return;
}
} else {
rlc_log->warning("Bearer %s already created.\n", get_rb_name(lcid));
rlc_log->warning("Bearer %s already created.\n", rrc->get_rb_name(lcid).c_str());
}
rlc_array[lcid].configure(cnfg);

@ -79,7 +79,7 @@ void rlc_am::configure(srslte_rlc_config_t cfg_)
cfg = cfg_.am;
log->info("%s configured: t_poll_retx=%d, poll_pdu=%d, poll_byte=%d, max_retx_thresh=%d, "
"t_reordering=%d, t_status_prohibit=%d\n",
get_rb_name(lcid), cfg.t_poll_retx, cfg.poll_pdu, cfg.poll_byte, cfg.max_retx_thresh,
rrc->get_rb_name(lcid).c_str(), cfg.t_poll_retx, cfg.poll_pdu, cfg.poll_byte, cfg.max_retx_thresh,
cfg.t_reordering, cfg.t_status_prohibit);
}
@ -175,7 +175,7 @@ uint32_t rlc_am::get_bearer()
void rlc_am::write_sdu(byte_buffer_t *sdu)
{
log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU", get_rb_name(lcid));
log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU", rrc->get_rb_name(lcid).c_str());
tx_sdu_queue.write(sdu);
}
@ -229,7 +229,7 @@ uint32_t rlc_am::get_total_buffer_state()
// Room needed for fixed header?
if(n_bytes > 0) {
n_bytes += 2;
n_bytes += 3;
log->debug("Buffer state - tx SDUs: %d bytes\n", n_bytes);
}
@ -285,7 +285,7 @@ uint32_t rlc_am::get_buffer_state()
// Room needed for fixed header?
if(n_bytes > 0) {
n_bytes += 2;
n_bytes += 3;
log->debug("Buffer state - tx SDUs: %d bytes\n", n_bytes);
}
@ -359,7 +359,7 @@ void rlc_am::check_reordering_timeout()
if(reordering_timeout.is_running() && reordering_timeout.expired())
{
reordering_timeout.reset();
log->debug("%s reordering timeout expiry - updating vr_ms\n", get_rb_name(lcid));
log->debug("%s reordering timeout expiry - updating vr_ms\n", rrc->get_rb_name(lcid).c_str());
// 36.322 v10 Section 5.1.3.2.4
vr_ms = vr_x;
@ -433,7 +433,7 @@ int rlc_am::build_status_pdu(uint8_t *payload, uint32_t nof_bytes)
if(pdu_len > 0 && nof_bytes >= (uint32_t)pdu_len)
{
log->info("%s Tx status PDU - %s\n",
get_rb_name(lcid), rlc_am_to_string(&status).c_str());
rrc->get_rb_name(lcid).c_str(), rlc_am_to_string(&status).c_str());
do_status = false;
poll_received = false;
@ -444,7 +444,7 @@ int rlc_am::build_status_pdu(uint8_t *payload, uint32_t nof_bytes)
return rlc_am_write_status_pdu(&status, payload);
}else{
log->warning("%s Cannot tx status PDU - %d bytes available, %d bytes required\n",
get_rb_name(lcid), nof_bytes, pdu_len);
rrc->get_rb_name(lcid).c_str(), nof_bytes, pdu_len);
return 0;
}
}
@ -478,7 +478,7 @@ int rlc_am::build_retx_pdu(uint8_t *payload, uint32_t nof_bytes)
return -1;
}
if(retx.is_segment || req_size > (int)nof_bytes) {
log->debug("%s build_retx_pdu - resegmentation required\n", get_rb_name(lcid));
log->debug("%s build_retx_pdu - resegmentation required\n", rrc->get_rb_name(lcid).c_str());
return build_segment(payload, nof_bytes, retx);
}
@ -503,7 +503,7 @@ int rlc_am::build_retx_pdu(uint8_t *payload, uint32_t nof_bytes)
if(tx_window[retx.sn].retx_count >= cfg.max_retx_thresh)
rrc->max_retx_attempted();
log->info("%s Retx PDU scheduled for tx. SN: %d, retx count: %d\n",
get_rb_name(lcid), retx.sn, tx_window[retx.sn].retx_count);
rrc->get_rb_name(lcid).c_str(), retx.sn, tx_window[retx.sn].retx_count);
debug_state();
return (ptr-payload) + tx_window[retx.sn].buf->N_bytes;
@ -540,7 +540,7 @@ int rlc_am::build_segment(uint8_t *payload, uint32_t nof_bytes, rlc_amd_retx_t r
if(nof_bytes <= head_len)
{
log->warning("%s Cannot build a PDU segment - %d bytes available, %d bytes required for header\n",
get_rb_name(lcid), nof_bytes, head_len);
rrc->get_rb_name(lcid).c_str(), nof_bytes, head_len);
return 0;
}
pdu_space = nof_bytes-head_len;
@ -606,15 +606,15 @@ int rlc_am::build_segment(uint8_t *payload, uint32_t nof_bytes, rlc_amd_retx_t r
memcpy(ptr, data, len);
log->info("%s Retx PDU segment scheduled for tx. SN: %d, SO: %d\n",
get_rb_name(lcid), retx.sn, retx.so_start);
rrc->get_rb_name(lcid).c_str(), retx.sn, retx.so_start);
debug_state();
int pdu_len = (ptr-payload) + len;
if(pdu_len > (int)nof_bytes) {
log->error("%s Retx PDU segment length error. Available: %d, Used: %d\n",
get_rb_name(lcid), nof_bytes, pdu_len);
rrc->get_rb_name(lcid).c_str(), nof_bytes, pdu_len);
log->debug("%s Retx PDU segment length error. Header len: %d, Payload len: %d, N_li: %d\n",
get_rb_name(lcid), (ptr-payload), len, new_header.N_li);
rrc->get_rb_name(lcid).c_str(), (ptr-payload), len, new_header.N_li);
}
return pdu_len;
@ -662,13 +662,13 @@ int rlc_am::build_data_pdu(uint8_t *payload, uint32_t nof_bytes)
if(pdu_space <= head_len + 1)
{
log->warning("%s Cannot build a PDU - %d bytes available, %d bytes required for header\n",
get_rb_name(lcid), nof_bytes, head_len);
rrc->get_rb_name(lcid).c_str(), nof_bytes, head_len);
pool->deallocate(pdu);
return 0;
}
log->debug("%s Building PDU - pdu_space: %d, head_len: %d \n",
get_rb_name(lcid), pdu_space, head_len);
rrc->get_rb_name(lcid).c_str(), pdu_space, head_len);
// Check for SDU segment
if(tx_sdu)
@ -683,7 +683,7 @@ int rlc_am::build_data_pdu(uint8_t *payload, uint32_t nof_bytes)
if(tx_sdu->N_bytes == 0)
{
log->info("%s Complete SDU scheduled for tx. Stack latency: %ld us\n",
get_rb_name(lcid), tx_sdu->get_latency_us());
rrc->get_rb_name(lcid).c_str(), tx_sdu->get_latency_us());
pool->deallocate(tx_sdu);
tx_sdu = NULL;
}
@ -694,7 +694,7 @@ int rlc_am::build_data_pdu(uint8_t *payload, uint32_t nof_bytes)
header.fi |= RLC_FI_FIELD_NOT_START_ALIGNED; // First byte does not correspond to first byte of SDU
log->debug("%s Building PDU - added SDU segment (len:%d) - pdu_space: %d, head_len: %d \n",
get_rb_name(lcid), to_move, pdu_space, head_len);
rrc->get_rb_name(lcid).c_str(), to_move, pdu_space, head_len);
}
// Pull SDUs from queue
@ -718,7 +718,7 @@ int rlc_am::build_data_pdu(uint8_t *payload, uint32_t nof_bytes)
if(tx_sdu->N_bytes == 0)
{
log->info("%s Complete SDU scheduled for tx. Stack latency: %ld us\n",
get_rb_name(lcid), tx_sdu->get_latency_us());
rrc->get_rb_name(lcid).c_str(), tx_sdu->get_latency_us());
pool->deallocate(tx_sdu);
tx_sdu = NULL;
}
@ -728,7 +728,7 @@ int rlc_am::build_data_pdu(uint8_t *payload, uint32_t nof_bytes)
pdu_space = 0;
log->debug("%s Building PDU - added SDU segment (len:%d) - pdu_space: %d, head_len: %d \n",
get_rb_name(lcid), to_move, pdu_space, head_len);
rrc->get_rb_name(lcid).c_str(), to_move, pdu_space, head_len);
}
if(tx_sdu)
@ -737,11 +737,11 @@ int rlc_am::build_data_pdu(uint8_t *payload, uint32_t nof_bytes)
// Set Poll bit
pdu_without_poll++;
byte_without_poll += (pdu->N_bytes + head_len);
log->debug("%s pdu_without_poll: %d\n", get_rb_name(lcid), pdu_without_poll);
log->debug("%s byte_without_poll: %d\n", get_rb_name(lcid), byte_without_poll);
log->debug("%s pdu_without_poll: %d\n", rrc->get_rb_name(lcid).c_str(), pdu_without_poll);
log->debug("%s byte_without_poll: %d\n", rrc->get_rb_name(lcid).c_str(), byte_without_poll);
if(poll_required())
{
log->debug("%s setting poll bit to request status\n", get_rb_name(lcid));
log->debug("%s setting poll bit to request status\n", rrc->get_rb_name(lcid).c_str());
header.p = 1;
poll_sn = vt_s;
pdu_without_poll = 0;
@ -752,7 +752,7 @@ int rlc_am::build_data_pdu(uint8_t *payload, uint32_t nof_bytes)
// Set SN
header.sn = vt_s;
vt_s = (vt_s + 1)%MOD;
log->info("%s PDU scheduled for tx. SN: %d\n", get_rb_name(lcid), header.sn);
log->info("%s PDU scheduled for tx. SN: %d\n", rrc->get_rb_name(lcid).c_str(), header.sn);
// Place PDU in tx_window, write header and TX
tx_window[header.sn].buf = pdu;
@ -773,26 +773,26 @@ void rlc_am::handle_data_pdu(uint8_t *payload, uint32_t nof_bytes, rlc_amd_pdu_h
std::map<uint32_t, rlc_amd_rx_pdu_t>::iterator it;
log->info_hex(payload, nof_bytes, "%s Rx data PDU SN: %d",
get_rb_name(lcid), header.sn);
rrc->get_rb_name(lcid).c_str(), header.sn);
if(!inside_rx_window(header.sn)) {
if(header.p) {
log->info("%s Status packet requested through polling bit\n", get_rb_name(lcid));
log->info("%s Status packet requested through polling bit\n", rrc->get_rb_name(lcid).c_str());
do_status = true;
}
log->info("%s SN: %d outside rx window [%d:%d] - discarding\n",
get_rb_name(lcid), header.sn, vr_r, vr_mr);
rrc->get_rb_name(lcid).c_str(), header.sn, vr_r, vr_mr);
return;
}
it = rx_window.find(header.sn);
if(rx_window.end() != it) {
if(header.p) {
log->info("%s Status packet requested through polling bit\n", get_rb_name(lcid));
log->info("%s Status packet requested through polling bit\n", rrc->get_rb_name(lcid).c_str());
do_status = true;
}
log->info("%s Discarding duplicate SN: %d\n",
get_rb_name(lcid), header.sn);
rrc->get_rb_name(lcid).c_str(), header.sn);
return;
}
@ -825,7 +825,7 @@ void rlc_am::handle_data_pdu(uint8_t *payload, uint32_t nof_bytes, rlc_amd_pdu_h
// Check poll bit
if(header.p)
{
log->info("%s Status packet requested through polling bit\n", get_rb_name(lcid));
log->info("%s Status packet requested through polling bit\n", rrc->get_rb_name(lcid).c_str());
poll_received = true;
// 36.322 v10 Section 5.2.3
@ -870,16 +870,16 @@ void rlc_am::handle_data_pdu_segment(uint8_t *payload, uint32_t nof_bytes, rlc_a
std::map<uint32_t, rlc_amd_rx_pdu_segments_t>::iterator it;
log->info_hex(payload, nof_bytes, "%s Rx data PDU segment. SN: %d, SO: %d",
get_rb_name(lcid), header.sn, header.so);
rrc->get_rb_name(lcid).c_str(), header.sn, header.so);
// Check inside rx window
if(!inside_rx_window(header.sn)) {
if(header.p) {
log->info("%s Status packet requested through polling bit\n", get_rb_name(lcid));
log->info("%s Status packet requested through polling bit\n", rrc->get_rb_name(lcid).c_str());
do_status = true;
}
log->info("%s SN: %d outside rx window [%d:%d] - discarding\n",
get_rb_name(lcid), header.sn, vr_r, vr_mr);
rrc->get_rb_name(lcid).c_str(), header.sn, vr_r, vr_mr);
return;
}
@ -898,7 +898,7 @@ void rlc_am::handle_data_pdu_segment(uint8_t *payload, uint32_t nof_bytes, rlc_a
if(rx_segments.end() != it) {
if(header.p) {
log->info("%s Status packet requested through polling bit\n", get_rb_name(lcid));
log->info("%s Status packet requested through polling bit\n", rrc->get_rb_name(lcid).c_str());
do_status = true;
}
@ -928,7 +928,7 @@ void rlc_am::handle_data_pdu_segment(uint8_t *payload, uint32_t nof_bytes, rlc_a
// Check poll bit
if(header.p)
{
log->info("%s Status packet requested through polling bit\n", get_rb_name(lcid));
log->info("%s Status packet requested through polling bit\n", rrc->get_rb_name(lcid).c_str());
poll_received = true;
// 36.322 v10 Section 5.2.3
@ -946,12 +946,12 @@ void rlc_am::handle_data_pdu_segment(uint8_t *payload, uint32_t nof_bytes, rlc_a
void rlc_am::handle_control_pdu(uint8_t *payload, uint32_t nof_bytes)
{
log->info_hex(payload, nof_bytes, "%s Rx control PDU", get_rb_name(lcid));
log->info_hex(payload, nof_bytes, "%s Rx control PDU", rrc->get_rb_name(lcid).c_str());
rlc_status_pdu_t status;
rlc_am_read_status_pdu(payload, nof_bytes, &status);
log->info("%s Rx Status PDU: %s\n", get_rb_name(lcid), rlc_am_to_string(&status).c_str());
log->info("%s Rx Status PDU: %s\n", rrc->get_rb_name(lcid).c_str(), rlc_am_to_string(&status).c_str());
poll_retx_timeout.reset();
@ -989,7 +989,7 @@ void rlc_am::handle_control_pdu(uint8_t *payload, uint32_t nof_bytes)
}
} else {
log->warning("%s invalid segment NACK received for SN %d. so_start: %d, so_end: %d, N_bytes: %d\n",
get_rb_name(lcid), i, status.nacks[j].so_start, status.nacks[j].so_end, it->second.buf->N_bytes);
rrc->get_rb_name(lcid).c_str(), i, status.nacks[j].so_start, status.nacks[j].so_end, it->second.buf->N_bytes);
}
}
@ -1043,7 +1043,7 @@ void rlc_am::reassemble_rx_sdus()
rx_sdu->N_bytes += len;
rx_window[vr_r].buf->msg += len;
rx_window[vr_r].buf->N_bytes -= len;
log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU", get_rb_name(lcid));
log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU", rrc->get_rb_name(lcid).c_str());
rx_sdu->set_timestamp();
pdcp->write_pdu(lcid, rx_sdu);
rx_sdu = pool_allocate;
@ -1059,7 +1059,7 @@ void rlc_am::reassemble_rx_sdus()
rx_sdu->N_bytes += rx_window[vr_r].buf->N_bytes;
if(rlc_am_end_aligned(rx_window[vr_r].header.fi))
{
log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU", get_rb_name(lcid));
log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU", rrc->get_rb_name(lcid).c_str());
rx_sdu->set_timestamp();
pdcp->write_pdu(lcid, rx_sdu);
rx_sdu = pool_allocate;
@ -1103,7 +1103,7 @@ void rlc_am::debug_state()
{
log->debug("%s vt_a = %d, vt_ms = %d, vt_s = %d, poll_sn = %d "
"vr_r = %d, vr_mr = %d, vr_x = %d, vr_ms = %d, vr_h = %d\n",
get_rb_name(lcid), vt_a, vt_ms, vt_s, poll_sn,
rrc->get_rb_name(lcid).c_str(), vt_a, vt_ms, vt_s, poll_sn,
vr_r, vr_mr, vr_x, vr_ms, vr_h);
}

@ -84,7 +84,7 @@ uint32_t rlc_tm::get_bearer()
// PDCP interface
void rlc_tm::write_sdu(byte_buffer_t *sdu)
{
log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU", get_rb_name(lcid));
log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU", rrc->get_rb_name(lcid).c_str());
ul_queue.write(sdu);
}
@ -104,7 +104,7 @@ int rlc_tm::read_pdu(uint8_t *payload, uint32_t nof_bytes)
uint32_t pdu_size = ul_queue.size_tail_bytes();
if(pdu_size > nof_bytes)
{
log->error("TX %s PDU size larger than MAC opportunity\n", get_rb_name(lcid));
log->error("TX %s PDU size larger than MAC opportunity\n", rrc->get_rb_name(lcid).c_str());
return 0;
}
byte_buffer_t *buf;
@ -112,9 +112,9 @@ int rlc_tm::read_pdu(uint8_t *payload, uint32_t nof_bytes)
pdu_size = buf->N_bytes;
memcpy(payload, buf->msg, buf->N_bytes);
log->info("%s Complete SDU scheduled for tx. Stack latency: %ld us\n",
get_rb_name(lcid), buf->get_latency_us());
rrc->get_rb_name(lcid).c_str(), buf->get_latency_us());
pool->deallocate(buf);
log->info_hex(payload, pdu_size, "TX %s, %s PDU", get_rb_name(lcid), rlc_mode_text[RLC_MODE_TM]);
log->info_hex(payload, pdu_size, "TX %s, %s PDU", rrc->get_rb_name(lcid).c_str(), rlc_mode_text[RLC_MODE_TM]);
return pdu_size;
}

@ -75,18 +75,18 @@ void rlc_um::configure(srslte_rlc_config_t cnfg_)
case LIBLTE_RRC_RLC_MODE_UM_BI:
log->info("%s configured in %s mode: "
"t_reordering=%d ms, rx_sn_field_length=%u bits, tx_sn_field_length=%u bits\n",
get_rb_name(lcid), liblte_rrc_rlc_mode_text[cnfg_.rlc_mode],
rrc->get_rb_name(lcid).c_str(), liblte_rrc_rlc_mode_text[cnfg_.rlc_mode],
cfg.t_reordering, rlc_umd_sn_size_num[cfg.rx_sn_field_length], rlc_umd_sn_size_num[cfg.rx_sn_field_length]);
break;
case LIBLTE_RRC_RLC_MODE_UM_UNI_UL:
log->info("%s configured in %s mode: tx_sn_field_length=%u bits\n",
get_rb_name(lcid), liblte_rrc_rlc_mode_text[cnfg_.rlc_mode],
rrc->get_rb_name(lcid).c_str(), liblte_rrc_rlc_mode_text[cnfg_.rlc_mode],
rlc_umd_sn_size_num[cfg.rx_sn_field_length]);
break;
case LIBLTE_RRC_RLC_MODE_UM_UNI_DL:
log->info("%s configured in %s mode: "
"t_reordering=%d ms, rx_sn_field_length=%u bits\n",
get_rb_name(lcid), liblte_rrc_rlc_mode_text[cnfg_.rlc_mode],
rrc->get_rb_name(lcid).c_str(), liblte_rrc_rlc_mode_text[cnfg_.rlc_mode],
cfg.t_reordering, rlc_umd_sn_size_num[cfg.rx_sn_field_length]);
break;
default:
@ -153,7 +153,7 @@ uint32_t rlc_um::get_bearer()
void rlc_um::write_sdu(byte_buffer_t *sdu)
{
log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU", get_rb_name(lcid));
log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU", rrc->get_rb_name(lcid).c_str());
tx_sdu_queue.write(sdu);
}
@ -216,7 +216,7 @@ void rlc_um::timer_expired(uint32_t timeout_id)
// 36.322 v10 Section 5.1.2.2.4
log->info("%s reordering timeout expiry - updating vr_ur and reassembling\n",
get_rb_name(lcid));
rrc->get_rb_name(lcid).c_str());
log->warning("Lost PDU SN: %d\n", vr_ur);
pdu_lost = true;
@ -281,7 +281,7 @@ int rlc_um::build_data_pdu(uint8_t *payload, uint32_t nof_bytes)
{
pool->deallocate(pdu);
log->warning("%s Cannot build a PDU - %d bytes available, %d bytes required for header\n",
get_rb_name(lcid), nof_bytes, head_len);
rrc->get_rb_name(lcid).c_str(), nof_bytes, head_len);
return 0;
}
@ -291,7 +291,7 @@ int rlc_um::build_data_pdu(uint8_t *payload, uint32_t nof_bytes)
uint32_t space = pdu_space-head_len;
to_move = space >= tx_sdu->N_bytes ? tx_sdu->N_bytes : space;
log->debug("%s adding remainder of SDU segment - %d bytes of %d remaining\n",
get_rb_name(lcid), to_move, tx_sdu->N_bytes);
rrc->get_rb_name(lcid).c_str(), to_move, tx_sdu->N_bytes);
memcpy(pdu_ptr, tx_sdu->msg, to_move);
last_li = to_move;
pdu_ptr += to_move;
@ -301,7 +301,7 @@ int rlc_um::build_data_pdu(uint8_t *payload, uint32_t nof_bytes)
if(tx_sdu->N_bytes == 0)
{
log->info("%s Complete SDU scheduled for tx. Stack latency: %ld us\n",
get_rb_name(lcid), tx_sdu->get_latency_us());
rrc->get_rb_name(lcid).c_str(), tx_sdu->get_latency_us());
pool->deallocate(tx_sdu);
tx_sdu = NULL;
}
@ -320,7 +320,7 @@ int rlc_um::build_data_pdu(uint8_t *payload, uint32_t nof_bytes)
uint32_t space = pdu_space-head_len;
to_move = space >= tx_sdu->N_bytes ? tx_sdu->N_bytes : space;
log->debug("%s adding new SDU segment - %d bytes of %d remaining\n",
get_rb_name(lcid), to_move, tx_sdu->N_bytes);
rrc->get_rb_name(lcid).c_str(), to_move, tx_sdu->N_bytes);
memcpy(pdu_ptr, tx_sdu->msg, to_move);
last_li = to_move;
pdu_ptr += to_move;
@ -330,7 +330,7 @@ int rlc_um::build_data_pdu(uint8_t *payload, uint32_t nof_bytes)
if(tx_sdu->N_bytes == 0)
{
log->info("%s Complete SDU scheduled for tx. Stack latency: %ld us\n",
get_rb_name(lcid), tx_sdu->get_latency_us());
rrc->get_rb_name(lcid).c_str(), tx_sdu->get_latency_us());
pool->deallocate(tx_sdu);
tx_sdu = NULL;
}
@ -345,11 +345,11 @@ int rlc_um::build_data_pdu(uint8_t *payload, uint32_t nof_bytes)
vt_us = (vt_us + 1)%cfg.tx_mod;
// Add header and TX
log->debug("%s packing PDU with length %d\n", get_rb_name(lcid), pdu->N_bytes);
log->debug("%s packing PDU with length %d\n", rrc->get_rb_name(lcid).c_str(), pdu->N_bytes);
rlc_um_write_data_pdu_header(&header, pdu);
memcpy(payload, pdu->msg, pdu->N_bytes);
uint32_t ret = pdu->N_bytes;
log->debug("%s returning length %d\n", get_rb_name(lcid), pdu->N_bytes);
log->debug("%s returning length %d\n", rrc->get_rb_name(lcid).c_str(), pdu->N_bytes);
pool->deallocate(pdu);
debug_state();
@ -363,20 +363,20 @@ void rlc_um::handle_data_pdu(uint8_t *payload, uint32_t nof_bytes)
rlc_um_read_data_pdu_header(payload, nof_bytes, cfg.rx_sn_field_length, &header);
log->info_hex(payload, nof_bytes, "RX %s Rx data PDU SN: %d",
get_rb_name(lcid), header.sn);
rrc->get_rb_name(lcid).c_str(), header.sn);
if(RX_MOD_BASE(header.sn) >= RX_MOD_BASE(vr_uh-cfg.rx_window_size) &&
RX_MOD_BASE(header.sn) < RX_MOD_BASE(vr_ur))
{
log->info("%s SN: %d outside rx window [%d:%d] - discarding\n",
get_rb_name(lcid), header.sn, vr_ur, vr_uh);
rrc->get_rb_name(lcid).c_str(), header.sn, vr_ur, vr_uh);
return;
}
it = rx_window.find(header.sn);
if(rx_window.end() != it)
{
log->info("%s Discarding duplicate SN: %d\n",
get_rb_name(lcid), header.sn);
rrc->get_rb_name(lcid).c_str(), header.sn);
return;
}
@ -451,7 +451,7 @@ void rlc_um::reassemble_rx_sdus()
log->warning("Dropping remainder of lost PDU (lower edge middle segments, vr_ur=%d, vr_ur_in_rx_sdu=%d)\n", vr_ur, vr_ur_in_rx_sdu);
rx_sdu->reset();
} else {
log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU vr_ur=%d, i=%d (lower edge middle segments)", get_rb_name(lcid), vr_ur, i);
log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU vr_ur=%d, i=%d (lower edge middle segments)", rrc->get_rb_name(lcid).c_str(), vr_ur, i);
rx_sdu->set_timestamp();
pdcp->write_pdu(lcid, rx_sdu);
rx_sdu = pool_allocate;
@ -471,7 +471,7 @@ void rlc_um::reassemble_rx_sdus()
log->warning("Dropping remainder of lost PDU (lower edge last segments)\n");
rx_sdu->reset();
} else {
log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU vr_ur=%d (lower edge last segments)", get_rb_name(lcid), vr_ur);
log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU vr_ur=%d (lower edge last segments)", rrc->get_rb_name(lcid).c_str(), vr_ur);
rx_sdu->set_timestamp();
pdcp->write_pdu(lcid, rx_sdu);
rx_sdu = pool_allocate;
@ -505,7 +505,7 @@ void rlc_um::reassemble_rx_sdus()
log->warning("Dropping remainder of lost PDU (update vr_ur middle segments, vr_ur=%d, vr_ur_in_rx_sdu=%d)\n", vr_ur, vr_ur_in_rx_sdu);
rx_sdu->reset();
} else {
log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU vr_ur=%d, i=%d, (update vr_ur middle segments)", get_rb_name(lcid), vr_ur, i);
log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU vr_ur=%d, i=%d, (update vr_ur middle segments)", rrc->get_rb_name(lcid).c_str(), vr_ur, i);
rx_sdu->set_timestamp();
pdcp->write_pdu(lcid, rx_sdu);
rx_sdu = pool_allocate;
@ -534,7 +534,7 @@ void rlc_um::reassemble_rx_sdus()
log->warning("Dropping remainder of lost PDU (update vr_ur last segments)\n");
rx_sdu->reset();
} else {
log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU vr_ur=%d (update vr_ur last segments)", get_rb_name(lcid), vr_ur);
log->info_hex(rx_sdu->msg, rx_sdu->N_bytes, "%s Rx SDU vr_ur=%d (update vr_ur last segments)", rrc->get_rb_name(lcid).c_str(), vr_ur);
rx_sdu->set_timestamp();
pdcp->write_pdu(lcid, rx_sdu);
rx_sdu = pool_allocate;
@ -564,7 +564,7 @@ bool rlc_um::inside_reordering_window(uint16_t sn)
void rlc_um::debug_state()
{
log->debug("%s vt_us = %d, vr_ur = %d, vr_ux = %d, vr_uh = %d \n",
get_rb_name(lcid), vt_us, vr_ur, vr_ux, vr_uh);
rrc->get_rb_name(lcid).c_str(), vt_us, vr_ur, vr_ux, vr_uh);
}

@ -93,6 +93,8 @@ void pdcp::config_security(uint16_t rnti, uint32_t lcid, uint8_t* k_rrc_enc_, ui
{
if (users.count(rnti)) {
users[rnti].pdcp->config_security(lcid, k_rrc_enc_, k_rrc_int_, cipher_algo_, integ_algo_);
users[rnti].pdcp->enable_integrity(lcid);
users[rnti].pdcp->enable_encryption(lcid);
}
}

@ -49,13 +49,6 @@ typedef struct {
using srslte::byte_buffer_t;
static std::string rb_id_str[] = {"SRB0", "SRB1", "SRB2",
"DRB1","DRB2","DRB3",
"DRB4","DRB5","DRB6",
"DRB7","DRB8"};
namespace srsue {
class rrc
@ -195,6 +188,33 @@ private:
uint32_t n311_cnt, N311;
uint32_t t301, t310, t311, t304;
// Radio bearers
typedef enum{
RB_ID_SRB0 = 0,
RB_ID_SRB1,
RB_ID_SRB2,
RB_ID_DRB1,
RB_ID_DRB2,
RB_ID_DRB3,
RB_ID_DRB4,
RB_ID_DRB5,
RB_ID_DRB6,
RB_ID_DRB7,
RB_ID_DRB8,
RB_ID_MAX
} rb_id_t;
static const std::string rb_id_str[];
std::string get_rb_name(uint32_t lcid)
{
if (lcid < RB_ID_MAX) {
return rb_id_str[lcid];
} else {
return "INVALID_RB";
}
}
typedef struct {
uint32_t earfcn;
srslte_cell_t phy_cell;
@ -405,7 +425,6 @@ private:
void set_phy_default();
void set_mac_default();
void set_rrc_default();
void set_bearers();
};
} // namespace srsue

@ -339,6 +339,9 @@ void phch_common::reset() {
rx_gain_offset = 0;
sr_last_tx_tti = -1;
cur_pusch_power = 0;
avg_rsrp = 0;
avg_rsrp_dbm = 0;
avg_rsrq_db = 0;
pcell_meas_enabled = false;
pcell_report_period = 20;

@ -52,6 +52,7 @@ phch_recv::phch_recv() {
dl_freq = -1;
ul_freq = -1;
bzero(&cell, sizeof(srslte_cell_t));
bzero(&metrics, sizeof(sync_metrics_t));
running = false;
worker_com = NULL;
}

@ -198,7 +198,7 @@ void nas::write_pdu(uint32_t lcid, byte_buffer_t *pdu) {
uint8 sec_hdr_type;
bool mac_valid = false;
nas_log->info_hex(pdu->msg, pdu->N_bytes, "DL %s PDU", get_rb_name(lcid));
nas_log->info_hex(pdu->msg, pdu->N_bytes, "DL %s PDU", rrc->get_rb_name(lcid).c_str());
// Parse the message security header
liblte_mme_parse_msg_sec_header((LIBLTE_BYTE_MSG_STRUCT*)pdu, &pd, &sec_hdr_type);
@ -228,7 +228,7 @@ void nas::write_pdu(uint32_t lcid, byte_buffer_t *pdu) {
// Parse the message header
liblte_mme_parse_msg_header((LIBLTE_BYTE_MSG_STRUCT *) pdu, &pd, &msg_type);
nas_log->info_hex(pdu->msg, pdu->N_bytes, "DL %s Decrypted PDU", get_rb_name(lcid));
nas_log->info_hex(pdu->msg, pdu->N_bytes, "DL %s Decrypted PDU", rrc->get_rb_name(lcid).c_str());
// TODO: Check if message type requieres specical security header type and if it isvalid
switch (msg_type) {
@ -770,7 +770,7 @@ void nas::parse_security_mode_command(uint32_t lcid, byte_buffer_t *pdu)
&sdu->msg[1]);
nas_log->info("Sending Security Mode Complete nas_current_ctxt.tx_count=%d, RB=%s\n",
ctxt.tx_count,
get_rb_name(lcid));
rrc->get_rb_name(lcid).c_str());
rrc->write_sdu(lcid, sdu);
ctxt.tx_count++;
pool->deallocate(pdu);

@ -1447,7 +1447,7 @@ void rrc::send_ul_dcch_msg(byte_buffer_t *pdu)
void rrc::write_sdu(uint32_t lcid, byte_buffer_t *sdu) {
rrc_log->info_hex(sdu->msg, sdu->N_bytes, "TX %s SDU", get_rb_name(lcid));
rrc_log->info_hex(sdu->msg, sdu->N_bytes, "TX %s SDU", get_rb_name(lcid).c_str());
switch (state) {
case RRC_STATE_CONNECTING:
send_con_setup_complete(sdu);
@ -1462,7 +1462,7 @@ void rrc::write_sdu(uint32_t lcid, byte_buffer_t *sdu) {
}
void rrc::write_pdu(uint32_t lcid, byte_buffer_t *pdu) {
rrc_log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU", get_rb_name(lcid));
rrc_log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU", get_rb_name(lcid).c_str());
switch (lcid) {
case RB_ID_SRB0:
@ -1524,7 +1524,7 @@ void rrc::parse_dl_dcch(uint32_t lcid, byte_buffer_t *pdu) {
liblte_rrc_unpack_dl_dcch_msg((LIBLTE_BIT_MSG_STRUCT *) &bit_buf, &dl_dcch_msg);
rrc_log->info("%s - Received %s\n",
get_rb_name(lcid),
get_rb_name(lcid).c_str(),
liblte_rrc_dl_dcch_msg_type_text[dl_dcch_msg.msg_type]);
// Reset and reuse pdu buffer if possible
@ -2098,7 +2098,7 @@ void rrc::add_srb(LIBLTE_RRC_SRB_TO_ADD_MOD_STRUCT *srb_cnfg) {
}
srbs[srb_cnfg->srb_id] = *srb_cnfg;
rrc_log->info("Added radio bearer %s\n", get_rb_name(srb_cnfg->srb_id));
rrc_log->info("Added radio bearer %s\n", get_rb_name(srb_cnfg->srb_id).c_str());
}
void rrc::add_drb(LIBLTE_RRC_DRB_TO_ADD_MOD_STRUCT *drb_cnfg) {
@ -2157,7 +2157,7 @@ void rrc::add_drb(LIBLTE_RRC_DRB_TO_ADD_MOD_STRUCT *drb_cnfg) {
drbs[lcid] = *drb_cnfg;
drb_up = true;
rrc_log->info("Added radio bearer %s\n", get_rb_name(lcid));
rrc_log->info("Added radio bearer %s\n", get_rb_name(lcid).c_str());
}
void rrc::release_drb(uint8_t lcid) {
@ -2807,13 +2807,9 @@ float rrc::rrc_meas::range_to_value(quantity_t quant, uint8_t range) {
return val;
}
const std::string rrc::rb_id_str[] = {"SRB0", "SRB1", "SRB2",
"DRB1", "DRB2", "DRB3",
"DRB4", "DRB5", "DRB6",
"DRB7", "DRB8"};
} // namespace srsue

Loading…
Cancel
Save