rlc_um_test.c 63 KB
Newer Older
1 2 3 4 5
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83

#define RLC_UM_MODULE
#define RLC_C
#define RLC_UM_TEST_C
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <assert.h>
#include <signal.h>
#include <sys/time.h>
//#include <curses.h>

#include "platform_types.h"
//-----------------------------------------------------------------------------
#include "rlc.h"
#include "rlc_um.h"
#include "list.h"
#include "rlc_um_control_primitives.h"
#include "LAYER2/MAC/extern.h"


#define TEST1
#define TEST2
#define TEST3
#define TEST4
#define TEST5

#define INCREMENT_FRAME_YES 1
#define INCREMENT_FRAME_NO  0

#define TEST_MAX_SEND_SDU 8192
#define TARGET_MAX_RX_ERROR_RATE 10
#define TARGET_MAX_TX_ERROR_RATE 10
static int  g_frame = 0;
static int  g_error_on_phy = 0;
static int  g_random_sdu;
static int  g_random_nb_frames;

static int  g_random_tx_pdu_size;
static int  g_random_rx_pdu_size;

static int  g_target_tx_error_rate;
static int  g_target_rx_error_rate;

static int  g_tx_packets = 0;
static int  g_dropped_tx_packets = 0;
static int  g_rx_packets = 0;
static int  g_dropped_rx_packets = 0;
static int  g_drop_rx = 0;
static int  g_drop_tx = 0;

static int  g_send_sdu_ids[TEST_MAX_SEND_SDU][2];
static int  g_send_id_write_index[2];
static int  g_send_id_read_index[2];

// time in frame numbers
#define MAX_TIME_DELAYED_PDU_DUE_TO_HARQ     256
static struct mac_data_ind g_tx_delayed_indications[MAX_TIME_DELAYED_PDU_DUE_TO_HARQ];
static struct mac_data_ind g_rx_delayed_indications[MAX_TIME_DELAYED_PDU_DUE_TO_HARQ];


84
static int8_t *g_sdus[] = {"En dépit de son volontarisme affiché, le premier ministre est de plus en plus décrié pour son incompétence. La tension politique et dans l'opinion publique est encore montée d'un cran au Japon, sur fond d'inquiétantes nouvelles, avec du plutonium détecté dans le sol autour de la centrale de Fukushima. Le premier ministre Naoto Kan a solennellement déclaré que son gouvernement était «en état d'alerte maximum». Tout en reconnaissant que la situation restait «imprévisible». Ce volontarisme affiché par le premier ministre - que Nicolas Sarkozy rencontrera demain lors d'une visite au Japon - ne l'a pas empêché d'être la cible de violentes critiques de la part de parlementaires sur sa gestion de la crise. Attaqué sur le manque de transparence, il a assuré qu'il rendait publiques toutes les informations en sa possession. Un député de l'opposition, Yosuke Isozaki, a aussi reproché à Naoto Kan de ne pas avoir ordonné l'évacuation des populations dans la zone comprise entre 20 et 30 km autour de la centrale. «Peut-il y avoir quelque chose de plus irresponsable que cela ?», a-t-il lancé. Pour l'heure, la zone d'évacuation est limitée à un rayon de 20 km, seul le confinement étant recommandé pour les 10 km suivants. Sur ce sujet, les autorités japonaises ont été fragilisées mardi par les déclarations de Greenpeace, affirmant que ses experts avaient détecté une radioactivité dangereuse à 40 km de la centrale. L'organisation écologiste a appelé à une extension de la zone d'évacuation, exhortant Tokyo à «cesser de privilégier la politique aux dépens de la science». L'Agence japonaise de sûreté nucléaire a balayé ces critiques.",
85

86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
                           "La pâquerette (Bellis perennis) est une plante vivace des prés, des pelouses, des bords de chemins et des prairies, haute de dix à vingt centimètres, de la famille des Astéracées, dont les fleurs naissent sur des inflorescences appelées capitules : celles du pourtour, que l'on croit à tort être des pétales, appelées fleurs ligulées, parce qu'elles ont la forme d'une languette, ou demi-fleurons, sont des fleurs femelles, dont la couleur varie du blanc au rose plus ou moins prononcé ; celles du centre, jaunes, appelées fleurs tubuleuses, parce que leur corolle forme un tube, ou fleurons, sont hermaphrodites. Ainsi, contrairement à l'opinion populaire, ce qu'on appelle une « fleur » de pâquerette n'est en réalité pas « une » fleur mais un capitule portant des fleurs très nombreuses.Leurs fruits s'envolent grâce au vent et dégagent des odeurs qui attirent les insectes.Une variété muricole peut pousser sur des murs humides verticaux.Les pâquerettes sont des fleurs rustiques et très communes en Europe, sur les gazons, les prairies, les chemins et les zones d'herbe rase.Elles ont la particularité, comme certaines autres fleurs de plantes herbacées, de se fermer la nuit et de s'ouvrir le matin pour s'épanouir au soleil ; elles peuvent aussi se fermer pendant les averses, voire un peu avant, ce qui permet dans les campagnes de prédire la pluie légèrement à l'avance.",

                           "La pâquerette",
                           " (Bellis perennis)",
                           " est une plante vivace des prés,",
                           " des pelouses,",
                           " des bords de chemins et des prairies,",
                           "haute de dix à",
                           " vingt centimètres",
                           ", de la",
                           " famille des",
                           " Astéracées",
                           ", dont",
                           " les",
                           " fleurs",
                           " naissent",
                           " sur",
                           " des",
                           " inflorescences",
                           " appelées",
                           " capitules",
                           " : celles",
                           " du pourtour",
                           ", que l'on",
                           " croit à",
                           " tort",
                           " être",
                           " des pétales",
                           ", appelées",
                           " fleurs ligulées",
                           ", parce qu'elles",
                           " ont la forme d'une languette, ou demi-fleurons, sont",
                           " des fleurs femelles,",
                           " dont la couleur varie du blanc au rose plus ou moins prononcé ; celles du centre, jaunes,",
                           " appelées ",
                           "fleurs tubuleuses",
                           ", parce que leur corolle forme un tube, ou fleurons, sont hermaphrodites."
                          };
124 125 126 127 128 129 130

#define RLC_2_PRINT_BUFFER_LEN 10000
static char rlc_2_print_buffer[RLC_2_PRINT_BUFFER_LEN];
//-----------------------------------------------------------------------------
void rlc_util_print_hex_octets(comp_name_t componentP, unsigned char* dataP, unsigned long sizeP)
//-----------------------------------------------------------------------------
{
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
  unsigned long octet_index = 0;
  unsigned long buffer_marker = 0;
  unsigned char aindex;

  if (dataP == NULL) {
    return;
  }


  LOG_D(RLC, "------+-------------------------------------------------|\n");
  LOG_D(RLC, "      |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
  LOG_D(RLC, "------+-------------------------------------------------|\n");

  for (octet_index = 0; octet_index < sizeP; octet_index++) {
    if ((octet_index % 16) == 0) {
      if (octet_index != 0) {
        buffer_marker+=snprintf(&rlc_2_print_buffer[buffer_marker], RLC_2_PRINT_BUFFER_LEN - buffer_marker, " |\n");
        LOG_D(RLC, "%s", rlc_2_print_buffer);
        buffer_marker = 0;
      }

      buffer_marker+=snprintf(&rlc_2_print_buffer[buffer_marker], RLC_2_PRINT_BUFFER_LEN - buffer_marker, " %04ld |", octet_index);
    }

    /*
     * Print every single octet in hexadecimal form
     */
    buffer_marker+=snprintf(&rlc_2_print_buffer[buffer_marker], RLC_2_PRINT_BUFFER_LEN - buffer_marker, " %02x", dataP[octet_index]);
    /*
     * Align newline and pipes according to the octets in groups of 2
     */
  }

  /*
   * Append enough spaces and put final pipe
   */
167
  for (aindex = octet_index; aindex < 16; ++aindex) {
168
    buffer_marker+=snprintf(&rlc_2_print_buffer[buffer_marker], RLC_2_PRINT_BUFFER_LEN - buffer_marker, "   ");
169
  }
170 171 172 173

  // LOG_D(RLC, "   ");
  buffer_marker+=snprintf(&rlc_2_print_buffer[buffer_marker], RLC_2_PRINT_BUFFER_LEN - buffer_marker, " |\n");
  LOG_D(RLC, "%s",rlc_2_print_buffer);
174 175 176 177 178 179
}

//-----------------------------------------------------------------------------
void rlc_um_v9_3_0_test_windows_10()
//-----------------------------------------------------------------------------
{
180 181 182 183 184 185 186 187 188 189 190
  rlc_um_entity_t um1;
  rlc_um_entity_t um2;
  unsigned int    h,w, sn, result;

  uint32_t             timer_reordering = 2000;
  uint32_t             sn_field_length  = 10;
  uint32_t             is_mXch          = 0; // boolean, true if configured for MTCH or MCCH

  rlc_um_init(&um1);
  rlc_um_init(&um2);

191 192
  rlc_um_set_debug_infos(&um1, g_frame, 0, 0, 0, 1, 1 /*LC-id = RAB-id*/);
  rlc_um_set_debug_infos(&um2, g_frame, 1, 1, 1, 1, 1 /*LC-id = RAB-id*/);
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228

  rlc_um_configure(&um1, g_frame, timer_reordering, sn_field_length, sn_field_length, is_mXch);
  rlc_um_configure(&um2, g_frame, timer_reordering, sn_field_length, sn_field_length, is_mXch);

  // RX window with vr_uh > vr_ur
  for (h = 0; h < RLC_UM_SN_10_BITS_MODULO; h++) {
    um1.vr_uh = h;

    for (w = 1; w < RLC_UM_WINDOW_SIZE_SN_10_BITS; w++) {
      um1.vr_ur = (um1.vr_uh - w) & RLC_UM_SN_10_BITS_MASK;

      for (sn = ((um1.vr_uh - um1.rx_um_window_size) & RLC_UM_SN_10_BITS_MASK) ; sn != um1.vr_uh; sn = ((sn+1) & RLC_UM_SN_10_BITS_MASK)) {
        assert(rlc_um_in_reordering_window(&um1, g_frame, sn) >= 0);
        // returns -2 if lower_bound  > sn
        // returns -1 if higher_bound < sn
        // returns  0 if lower_bound  < sn < higher_bound
        // returns  1 if lower_bound  == sn
        // returns  2 if higher_bound == sn
        // returns  3 if higher_bound == sn == lower_bound
        result = rlc_um_in_window(&um1, g_frame, (um1.vr_uh - um1.rx_um_window_size) & RLC_UM_SN_10_BITS_MASK, sn, um1.vr_uh);
        assert((result < 2) && (result >=0));
      }

      for (sn = um1.vr_uh ; sn != ((um1.vr_uh - um1.rx_um_window_size) & RLC_UM_SN_10_BITS_MASK) ; sn = ((sn+1) & RLC_UM_SN_10_BITS_MASK)) {
        // returns -2 if lower_bound  > sn
        // returns -1 if higher_bound < sn
        // returns  0 if lower_bound  < sn < higher_bound
        // returns  1 if lower_bound  == sn
        // returns  2 if higher_bound == sn
        // returns  3 if higher_bound == sn == lower_bound
        assert(rlc_um_in_window(&um1, g_frame, (um1.vr_uh - um1.rx_um_window_size) & RLC_UM_SN_10_BITS_MASK, sn, (um1.vr_uh -1) & RLC_UM_SN_10_BITS_MASK) < 0);
        assert(rlc_um_in_reordering_window(&um1, g_frame, sn) < 0);
      }

    }
  }
229 230 231 232 233
}
//-----------------------------------------------------------------------------
void rlc_um_v9_3_0_test_windows_5()
//-----------------------------------------------------------------------------
{
234 235 236 237 238 239 240 241 242 243 244
  rlc_um_entity_t um1;
  rlc_um_entity_t um2;
  unsigned int    h,w, sn, result;

  uint32_t             timer_reordering = 2000;
  uint32_t             sn_field_length  = 5;
  uint32_t             is_mXch          = 0; // boolean, true if configured for MTCH or MCCH

  rlc_um_init(&um1);
  rlc_um_init(&um2);

245 246
  rlc_um_set_debug_infos(&um1, g_frame, 0, 0, 0, 1, 1 /* LC-id = DRB-id */);
  rlc_um_set_debug_infos(&um2, g_frame, 1, 1, 1, 1, 1 /* LC-id = DRB-id */);
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282

  rlc_um_configure(&um1, g_frame, timer_reordering, sn_field_length, sn_field_length, is_mXch);
  rlc_um_configure(&um2, g_frame, timer_reordering, sn_field_length, sn_field_length, is_mXch);

  // RX window with vr_uh > vr_ur
  for (h = 0; h < RLC_UM_SN_5_BITS_MODULO; h++) {
    um1.vr_uh = h;

    for (w = 1; w < RLC_UM_WINDOW_SIZE_SN_5_BITS; w++) {
      um1.vr_ur = (um1.vr_uh - w) & RLC_UM_SN_5_BITS_MASK;

      for (sn = ((um1.vr_uh - um1.rx_um_window_size) & RLC_UM_SN_5_BITS_MASK) ; sn != um1.vr_uh; sn = ((sn+1) & RLC_UM_SN_5_BITS_MASK)) {
        assert(rlc_um_in_reordering_window(&um1, g_frame, sn) >= 0);
        // returns -2 if lower_bound  > sn
        // returns -1 if higher_bound < sn
        // returns  0 if lower_bound  < sn < higher_bound
        // returns  1 if lower_bound  == sn
        // returns  2 if higher_bound == sn
        // returns  3 if higher_bound == sn == lower_bound
        result = rlc_um_in_window(&um1, g_frame, (um1.vr_uh - um1.rx_um_window_size) & RLC_UM_SN_5_BITS_MASK, sn, um1.vr_uh);
        assert((result < 2) && (result >=0));
      }

      for (sn = um1.vr_uh ; sn != ((um1.vr_uh - um1.rx_um_window_size) & RLC_UM_SN_5_BITS_MASK) ; sn = ((sn+1) & RLC_UM_SN_5_BITS_MASK)) {
        // returns -2 if lower_bound  > sn
        // returns -1 if higher_bound < sn
        // returns  0 if lower_bound  < sn < higher_bound
        // returns  1 if lower_bound  == sn
        // returns  2 if higher_bound == sn
        // returns  3 if higher_bound == sn == lower_bound
        assert(rlc_um_in_window(&um1, g_frame, (um1.vr_uh - um1.rx_um_window_size) & RLC_UM_SN_5_BITS_MASK, sn, (um1.vr_uh -1) & RLC_UM_SN_5_BITS_MASK) < 0);
        assert(rlc_um_in_reordering_window(&um1, g_frame, sn) < 0);
      }

    }
  }
283 284 285 286 287
}
//-----------------------------------------------------------------------------
void rlc_um_v9_3_0_test_reset_sdus()
//-----------------------------------------------------------------------------
{
288 289 290 291 292
  int i, j;

  for (j = 0; j < 2; j++) {
    for (i = 0; i < TEST_MAX_SEND_SDU; i++) {
      g_send_sdu_ids[i][j]= -1;
293
    }
294 295 296 297

    g_send_id_write_index[j] = 0;
    g_send_id_read_index[j]  = 0;
  }
298 299 300 301 302 303
}
//-----------------------------------------------------------------------------
void rlc_um_v9_3_0_test_send_sdu(rlc_um_entity_t *um_txP, int sdu_indexP)
//-----------------------------------------------------------------------------
{
  mem_block_t *sdu;
304
  sdu = get_free_mem_block (strlen(g_sdus[sdu_indexP]) + 1 + sizeof (struct rlc_um_data_req_alloc), __func__);
305 306

  if (sdu != NULL) {
307 308 309 310
    // PROCESS OF COMPRESSION HERE:
    printf("[FRAME %05d][RLC][MOD %02d][RB %02d] TX SDU %d %04d bytes\n",g_frame,um_txP->module_id, um_txP->rb_id, sdu_indexP, strlen(g_sdus[sdu_indexP]) + 1);
    memset (sdu->data, 0, sizeof (struct rlc_um_data_req_alloc));
    strcpy (&sdu->data[sizeof (struct rlc_um_data_req_alloc)],g_sdus[sdu_indexP]);
311

312 313 314
    ((struct rlc_um_data_req *) (sdu->data))->data_size = strlen(g_sdus[sdu_indexP])+ 1;
    ((struct rlc_um_data_req *) (sdu->data))->data_offset = sizeof (struct rlc_um_data_req_alloc);
    rlc_um_data_req(um_txP, g_frame, sdu);
315

316 317
    g_send_sdu_ids[g_send_id_write_index[um_txP->rb_id]++][um_txP->rb_id] = sdu_indexP;
    assert(g_send_id_write_index[um_txP->rb_id] < TEST_MAX_SEND_SDU);
318 319
  } else {
    printf("Out of memory error\n");
320
//    exit(-1);
321 322 323 324 325 326 327
  }
}

//-----------------------------------------------------------------------------
void rlc_um_v9_3_0_buffer_delayed_rx_mac_data_ind(struct mac_data_ind* data_indP, signed int time_delayedP)
//-----------------------------------------------------------------------------
{
328 329
  int   frame_modulo;
  mem_block_t* tb;
330

331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
  if (time_delayedP <= 0) {
    frame_modulo = g_frame % MAX_TIME_DELAYED_PDU_DUE_TO_HARQ;
  } else {
    frame_modulo = (g_frame + time_delayedP) % MAX_TIME_DELAYED_PDU_DUE_TO_HARQ;
  }

  while (data_indP->data.nb_elements > 0) {
    tb = list_remove_head (&data_indP->data);

    if (tb != NULL) {
      if (time_delayedP < 0) {
        list_add_head(tb, &g_rx_delayed_indications[frame_modulo].data);
      } else {
        list_add_tail_eurecom(tb, &g_rx_delayed_indications[frame_modulo].data);
      }

      g_rx_delayed_indications[frame_modulo].no_tb  += 1;
348
    }
349 350 351
  }

  assert(data_indP->data.head == NULL);
352 353 354 355 356
}
//-----------------------------------------------------------------------------
void rlc_um_v9_3_0_buffer_delayed_tx_mac_data_ind(struct mac_data_ind* data_indP, signed int time_delayedP)
//-----------------------------------------------------------------------------
{
357 358
  int   frame_modulo;
  mem_block_t* tb;
359

360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
  if (time_delayedP <= 0) {
    frame_modulo = g_frame % MAX_TIME_DELAYED_PDU_DUE_TO_HARQ;
  } else {
    frame_modulo = (g_frame + time_delayedP) % MAX_TIME_DELAYED_PDU_DUE_TO_HARQ;
  }

  while (data_indP->data.nb_elements > 0) {
    tb = list_remove_head (&data_indP->data);

    if (tb != NULL) {
      if (time_delayedP < 0) {
        list_add_head(tb, &g_rx_delayed_indications[frame_modulo].data);
      } else {
        list_add_tail_eurecom(tb, &g_rx_delayed_indications[frame_modulo].data);
      }

      g_rx_delayed_indications[frame_modulo].no_tb  += 1;
377
    }
378 379 380
  }

  assert(data_indP->data.head == NULL);
381 382 383
}

//-----------------------------------------------------------------------------
384 385
void rlc_um_v9_3_0_test_mac_rlc_loop (struct mac_data_ind* data_indP,  struct mac_data_req* data_requestP, int* drop_countP, int* tx_packetsP,
                                      int* dropped_tx_packetsP)
386 387 388 389 390 391 392 393 394
//-----------------------------------------------------------------------------
{


  mem_block_t* tb_src;
  mem_block_t* tb_dst;
  unsigned int tb_size;

  data_indP->no_tb = 0;
395

396 397
  while (data_requestP->data.nb_elements > 0) {
    tb_src = list_remove_head (&data_requestP->data);
398

399
    if (tb_src != NULL) {
400 401 402 403 404 405 406 407
      tb_size = ((struct mac_tb_req *) (tb_src->data))->tb_size_in_bits >> 3;
      printf("[RLC-LOOP] FOUND TB SIZE IN BITS %d IN BYTES %d sizeof (mac_rlc_max_rx_header_size_t) %d\n",
             ((struct mac_tb_req *) (tb_src->data))->tb_size_in_bits,
             tb_size, sizeof (mac_rlc_max_rx_header_size_t));

      *tx_packetsP = *tx_packetsP + 1;

      if (*drop_countP == 0) {
408
        tb_dst  = get_free_mem_block(sizeof (mac_rlc_max_rx_header_size_t) + tb_size, __func__);
409
        if (tb_dst != NULL) {
410
          memset(tb_dst->data, 0, sizeof (mac_rlc_max_rx_header_size_t) + tb_size);
411
          //printf("[RLC-LOOP] Testing tb_dst (1)\n");
412
          check_free_mem_block(tb_dst, __func__);
413 414 415 416 417 418 419 420 421 422 423 424 425
          tb_dst->next = NULL;
          ((struct mac_tb_ind *) (tb_dst->data))->first_bit        = 0;
          ((struct mac_tb_ind *) (tb_dst->data))->data_ptr         = &tb_dst->data[sizeof (mac_rlc_max_rx_header_size_t)];
          ((struct mac_tb_ind *) (tb_dst->data))->size             = tb_size;
          ((struct mac_tb_ind *) (tb_dst->data))->error_indication = 0;

          memcpy(((struct mac_tb_ind *) (tb_dst->data))->data_ptr,
                 &((struct mac_tb_req *) (tb_src->data))->data_ptr[0],
                 tb_size);

          list_add_tail_eurecom(tb_dst, &data_indP->data);
          data_indP->no_tb  += 1;
          //printf("[RLC-LOOP] Testing tb_dst (2)\n");
426
          check_free_mem_block(tb_dst, __func__);
427
        } else {
428
          printf("Out of memory error\n");
429
//          exit(-1);
430
        }
431 432 433 434 435
      } else {
        printf("[RLC-LOOP] DROPPING 1 TB\n");
        *drop_countP = *drop_countP - 1;
        *dropped_tx_packetsP = *dropped_tx_packetsP + 1;
      }
436 437


438
      //printf("[RLC-LOOP] Testing tb_src\n");
439
      check_free_mem_block(tb_src, __func__);
440

441
      free_mem_block(tb_src, __func__);
442 443 444 445

      if (data_indP->no_tb > 0) {
        printf("[RLC-LOOP] Exchange %d TBs\n",data_indP->no_tb);
      }
446 447 448 449 450 451
    }
  }
}
//-----------------------------------------------------------------------------
void rlc_um_v9_3_0_test_exchange_pdus(rlc_um_entity_t *um_txP,
                                      rlc_um_entity_t *um_rxP,
452 453
                                      uint16_t           bytes_txP,
                                      uint16_t           bytes_rxP)
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
//-----------------------------------------------------------------------------
{
  struct mac_data_req    data_request_tx;
  struct mac_data_req    data_request_rx;
  struct mac_data_ind    data_ind_tx;
  struct mac_data_ind    data_ind_rx;
  struct mac_status_ind  tx_status;
  struct mac_status_resp mac_rlc_status_resp_tx;
  struct mac_status_resp mac_rlc_status_resp_rx;


  memset(&data_request_tx, 0, sizeof(struct mac_data_req));
  memset(&data_request_rx, 0, sizeof(struct mac_data_req));
  memset(&data_ind_tx,     0, sizeof(struct mac_data_ind));
  memset(&data_ind_rx,     0, sizeof(struct mac_data_ind));
  memset(&tx_status,       0, sizeof(struct mac_status_ind));
  memset(&mac_rlc_status_resp_tx, 0, sizeof(struct mac_status_resp));
  memset(&mac_rlc_status_resp_rx, 0, sizeof(struct mac_status_resp));

473
  mac_rlc_status_resp_tx = rlc_um_mac_status_indication(um_txP, g_frame, 1, bytes_txP, tx_status,ENB_FLAG_YES);
474
  data_request_tx        = rlc_um_mac_data_request(um_txP, g_frame);
475
  mac_rlc_status_resp_rx = rlc_um_mac_status_indication(um_rxP, g_frame, 0, bytes_rxP, tx_status,ENB_FLAG_YES);
476 477 478 479 480 481 482 483 484 485 486 487 488
  data_request_rx        = rlc_um_mac_data_request(um_rxP, g_frame);


  rlc_um_v9_3_0_test_mac_rlc_loop(&data_ind_rx, &data_request_tx, &g_drop_tx, &g_tx_packets, &g_dropped_tx_packets);
  rlc_um_v9_3_0_test_mac_rlc_loop(&data_ind_tx, &data_request_rx, &g_drop_rx, &g_rx_packets, &g_dropped_rx_packets);
  rlc_um_mac_data_indication(um_rxP, g_frame, um_rxP->is_enb, data_ind_rx);
  rlc_um_mac_data_indication(um_txP, g_frame, um_txP->is_enb, data_ind_tx);
  g_frame += 1;
  //check_mem_area();
  //display_mem_load();
}
//-----------------------------------------------------------------------------
void rlc_um_v9_3_0_test_exchange_delayed_pdus(rlc_um_entity_t *um_txP,
489 490 491 492 493 494 495 496 497 498
    rlc_um_entity_t *um_rxP,
    uint16_t           bytes_txP,
    uint16_t           bytes_rxP,
    signed int      time_tx_delayedP, // if -1 added to the head of current frame tx mac data ind if any
    // if 0  added to the tail of current frame tx mac data ind if any
    // if > 0  added to the tail of frame+time_tx_delayedP mac data ind if any
    signed int      time_rx_delayedP, // if -1 added to the head of current frame rx mac data ind if any
    // if 0  added to the tail of current frame rx mac data ind if any
    // if > 0  added to the tail of frame+time_rx_delayedP mac data ind if any
    int             is_frame_incrementedP)
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
//-----------------------------------------------------------------------------
{
  struct mac_data_req    data_request_tx;
  struct mac_data_req    data_request_rx;
  struct mac_data_ind    data_ind_tx;
  struct mac_data_ind    data_ind_rx;
  struct mac_status_ind  tx_status;
  struct mac_status_resp mac_rlc_status_resp_tx;
  struct mac_status_resp mac_rlc_status_resp_rx;
  int                    frame_modulo = g_frame % MAX_TIME_DELAYED_PDU_DUE_TO_HARQ;


  memset(&data_request_tx, 0, sizeof(struct mac_data_req));
  memset(&data_request_rx, 0, sizeof(struct mac_data_req));
  memset(&data_ind_tx,     0, sizeof(struct mac_data_ind));
  memset(&data_ind_rx,     0, sizeof(struct mac_data_ind));
  memset(&tx_status,       0, sizeof(struct mac_status_ind));
  memset(&mac_rlc_status_resp_tx, 0, sizeof(struct mac_status_resp));
  memset(&mac_rlc_status_resp_rx, 0, sizeof(struct mac_status_resp));

519
  mac_rlc_status_resp_tx = rlc_um_mac_status_indication(um_txP, g_frame, 1, bytes_txP, tx_status,ENB_FLAG_YES);
520
  data_request_tx        = rlc_um_mac_data_request(um_txP, g_frame);
521
  mac_rlc_status_resp_rx = rlc_um_mac_status_indication(um_rxP, g_frame, 0, bytes_rxP, tx_status,ENB_FLAG_YES);
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
  data_request_rx        = rlc_um_mac_data_request(um_rxP, g_frame);


  rlc_um_v9_3_0_test_mac_rlc_loop(&data_ind_rx, &data_request_tx, &g_drop_tx, &g_tx_packets, &g_dropped_tx_packets);
  rlc_um_v9_3_0_test_mac_rlc_loop(&data_ind_tx, &data_request_rx, &g_drop_rx, &g_rx_packets, &g_dropped_rx_packets);

  rlc_um_v9_3_0_buffer_delayed_rx_mac_data_ind(&data_ind_rx, time_tx_delayedP);
  rlc_um_v9_3_0_buffer_delayed_tx_mac_data_ind(&data_ind_tx, time_rx_delayedP);


  rlc_um_mac_data_indication(um_rxP, g_frame, um_rxP->is_enb, g_rx_delayed_indications[frame_modulo]);
  memset(&g_rx_delayed_indications[frame_modulo], 0, sizeof(struct mac_data_ind));

  rlc_um_mac_data_indication(um_txP, g_frame, um_txP->is_enb, g_tx_delayed_indications[frame_modulo]);
  memset(&g_tx_delayed_indications[frame_modulo], 0, sizeof(struct mac_data_ind));

  if (is_frame_incrementedP) {
539
    g_frame += 1;
540 541 542 543 544 545 546
  }
}

//-----------------------------------------------------------------------------
void rlc_um_v9_3_0_test_data_conf(module_id_t module_idP, rb_id_t rb_idP, mui_t muiP, rlc_tx_status_t statusP)
//-----------------------------------------------------------------------------
{
547 548 549 550 551
  if (statusP == RLC_SDU_CONFIRM_YES) {
    printf("[FRAME %05d][RLC][MOD %02d][RB %02d]  CONFIRM SEND SDU MUI %05d\n",g_frame,module_idP, rb_idP, muiP);
  } else {
    printf("[FRAME %05d][RLC][MOD %02d][RB %02d]  CONFIRM LOST SDU MUI %05d\n",g_frame,module_idP, rb_idP, muiP);
  }
552 553 554 555 556
}
//-----------------------------------------------------------------------------
void rlc_um_v9_3_0_test_data_ind (module_id_t module_idP, rb_id_t rb_idP, sdu_size_t sizeP, mem_block_t *sduP)
//-----------------------------------------------------------------------------
{
557
  int i;
558

559 560 561 562 563 564
  if (g_error_on_phy == 0) {
    for (i = 0; i < 37; i++) {
      if (strcmp(g_sdus[i], sduP->data) == 0) {
        printf("[FRAME %05d][RLC][MOD %02d][RB %02d] RX SDU %d %04d bytes\n",g_frame,module_idP, rb_idP, i, sizeP);
        assert(TEST_MAX_SEND_SDU > g_send_id_read_index[rb_idP]);
        assert(g_send_id_write_index[rb_idP^1] > g_send_id_read_index[rb_idP]);
565

566
        if (g_send_sdu_ids[g_send_id_read_index[rb_idP]][rb_idP^1] != i) {
567

568 569 570 571 572 573
          printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_sdu_ids[%d] = %d\n",g_frame,module_idP, rb_idP,  g_send_id_read_index[rb_idP]-2,
                 g_send_sdu_ids[g_send_id_read_index[rb_idP]-2][rb_idP^1]);
          printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_sdu_ids[%d] = %d\n",g_frame,module_idP, rb_idP,  g_send_id_read_index[rb_idP]-1,
                 g_send_sdu_ids[g_send_id_read_index[rb_idP]-1][rb_idP^1]);
          printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_sdu_ids[%d] = %d\n",g_frame,module_idP, rb_idP,  g_send_id_read_index[rb_idP],
                 g_send_sdu_ids[g_send_id_read_index[rb_idP]][rb_idP^1]);
574 575

          printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_id_read_index = %d sdu sent = %d\n",g_frame,module_idP, rb_idP,  g_send_id_read_index[rb_idP], i);
576
        }
577 578 579

        assert(g_send_sdu_ids[g_send_id_read_index[rb_idP]][rb_idP^1] == i);
        g_send_id_read_index[rb_idP] += 1;
580
        free_mem_block(sduP, __func__);
581 582 583 584 585
        return;
      }
    }

    printf("[FRAME %05d][RLC][MOD %d][RB %d] RX UNKNOWN SDU %04d bytes\n",g_frame,module_idP, rb_idP,  sizeP);
586
    free_mem_block(sduP, __func__);
587 588 589 590 591 592 593
    assert(1==2);
  } else {
    for (i = 0; i < 37; i++) {
      if (strcmp(g_sdus[i], sduP->data) == 0) {
        printf("[FRAME %05d][RLC][MOD %02d][RB %02d] RX SDU %d %04d bytes\n",g_frame,module_idP, rb_idP, i, sizeP);
        assert(TEST_MAX_SEND_SDU > g_send_id_read_index[rb_idP]);
        g_send_id_read_index[rb_idP] += 1;
594
        free_mem_block(sduP, __func__);
595
        return;
596
      }
597
    }
598 599

    printf("[FRAME %05d][RLC][MOD %d][RB %d] RX UNKNOWN SDU %04d bytes\n",g_frame,module_idP, rb_idP,  sizeP);
600
    free_mem_block(sduP, __func__);
601 602
    return;
  }
603 604
}
//-----------------------------------------------------------------------------
605
void rlc_um_v9_3_0_test_reordering(uint32_t sn_field_lengthP)
606 607
//-----------------------------------------------------------------------------
{
608 609
  rlc_um_info_t     um_info;
  int                   i,j,r;
610

611 612 613
  um_info.timer_reordering = (32 * sn_field_lengthP * sn_field_lengthP)/100;
  um_info.sn_field_length  = sn_field_lengthP;
  um_info.is_mXch          = 0;
614

615
  srand (0);
616 617
  config_req_rlc_um (&um_tx, 0,0,0, &um_info, 0, SIGNALLING_RADIO_BEARER, SIGNALLING_RADIO_BEARER /*LC-id = DRB-id*/);
  config_req_rlc_um (&um_rx, 0,1,1, &um_info, 1, SIGNALLING_RADIO_BEARER, SIGNALLING_RADIO_BEARER /*LC-id = DRB-id*/);
618

619
  rlc_um_display_rx_window(&um_tx);
620

621
  rlc_um_display_rx_window(&um_rx);
622 623


624
  srand (0);
625 626


627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
  // BIG SDU SMALL PDUS NO ERRORS
  rlc_um_v9_3_0_test_reset_sdus();

  for (i = 0; i < 128; i++) {
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 3,    200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 3,    200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 3,    200, um_info.timer_reordering - 5, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 4,    200, 7, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 5,    200, 5, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 6,    200, 3, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 7,    200, 1, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 8,    200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 9,    200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 10,   200, 7, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 11,   200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 12,   200, 5, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 13,   200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 14,   200, 3, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 15,   200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 16,   200, 1, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 17,   200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 18,   200, 3, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 19,   200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 20,   200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 21,   200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 22,   200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 23,   200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 24,   200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 25,   200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 26,   200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 27,   200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 28,   200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 29,   200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES);

    assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
    printf("\n\n\n\n\n\n\n\n");

  }

  printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test_reordering 3: END OF TEST BIG SDU, SMALL PDUs\n\n\n\n");

  rlc_um_v9_3_0_test_reset_sdus();

  for (j = 0; j < 16; j++) {
    //i = getchar();

681 682
    rlc_um_v9_3_0_test_reset_sdus();

683 684 685 686
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);

    for (i = 0; i < 32; i++) {
      rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 3, 200, 0, 0, INCREMENT_FRAME_YES);
687 688
    }

689 690
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES);
    assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
691 692


693 694 695 696
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 3, 200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 3, 200, 0, 0, INCREMENT_FRAME_YES);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 3, 200, um_info.timer_reordering + 5, 0, INCREMENT_FRAME_YES);
697

698 699 700
    for (i = 0; i < 600; i++) {
      rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 3, 200, 0, 0, INCREMENT_FRAME_YES);
    }
701

702 703 704
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES);
    printf("g_send_id_read_index[1]=%d g_send_id_write_index[0]=%d Loop %d (1)\n", g_send_id_read_index[1], g_send_id_write_index[0], j);
    assert (g_send_id_read_index[1] != g_send_id_write_index[0]);
705

706 707
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 3, 200, 0, 0, INCREMENT_FRAME_YES);
708

709 710 711 712
    for (i = 0; i < 600; i++) {
      if ((i % 32) == 0) {
        rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 3, 200, um_info.timer_reordering + 5, 0, INCREMENT_FRAME_YES);
      } else {
713
        rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 3, 200, 0, 0, INCREMENT_FRAME_YES);
714
      }
715
    }
716 717 718 719 720 721 722 723

    rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES);
    printf("g_send_id_read_index[1]=%d g_send_id_write_index[0]=%d Loop %d (2)\n", g_send_id_read_index[1], g_send_id_write_index[0], j);

    assert (g_send_id_read_index[1] != g_send_id_write_index[0]);
  }

  printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test_reordering 4: END OF TEST BIG SDU, SMALL PDUs\n\n\n\n");
724 725 726 727 728 729 730 731 732 733 734 735 736 737
}
//-----------------------------------------------------------------------------
void rlc_um_v9_3_0_test_tx_rx_10(void)
//-----------------------------------------------------------------------------
{
  rlc_um_info_t     um_info;
  int                   i,j,r;


  um_info.timer_reordering = 32;
  um_info.sn_field_length  = 10;
  um_info.is_mXch          = 0;

  srand (0);
738 739
  config_req_rlc_um (&um_tx, 0,0,0, &um_info, 0, SIGNALLING_RADIO_BEARER, SIGNALLING_RADIO_BEARER /*LC-id = DRB-id*/);
  config_req_rlc_um (&um_rx, 0,1,1, &um_info, 1, SIGNALLING_RADIO_BEARER, SIGNALLING_RADIO_BEARER /*LC-id = DRB-id*/);
740 741 742 743 744 745

  rlc_um_display_rx_window(&um_tx);

  rlc_um_display_rx_window(&um_rx);


746
#ifdef TEST1
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769
  srand (0);
  rlc_um_v9_3_0_test_reset_sdus();
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 8000, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 8000, 200);
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 2);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 8000, 200);
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 2);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 8000, 200);
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 2);
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 3);
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 4);
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 5);
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 6);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200);

  assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792
  printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test 1: END OF SIMPLE TEST SEVERAL SDUs IN PDU\n\n\n\n");
  sleep(2);
  rlc_um_v9_3_0_test_reset_sdus();

  // RANDOM TESTS
  for (i = g_send_id_write_index[0]; g_send_id_write_index[0] < TEST_MAX_SEND_SDU-12; i++) {
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
    rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 8000, 200);
    rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 8000, 200);
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 2);
    rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 8000, 200);
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 2);
    rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 8000, 200);
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 2);
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 3);
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 4);
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 5);
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 6);

    for (i = 0; i < 50; i++) {
      rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 200, 200);
793 794 795
    }

    assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
796 797 798 799 800
  }

  assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
  printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test 1: END OF TEST SEVERAL SDUs IN PDU\n\n\n\n");
  sleep(2);
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871
#endif
#ifdef TEST2
  srand (0);
  rlc_um_v9_3_0_test_reset_sdus();
  // BIG SDU SMALL PDUS NO ERRORS
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 3, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 3, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 3, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 4, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 5, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 6, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 7, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 8, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 9, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 10, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 11, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 12, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 13, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 14, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 15, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 16, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 17, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 18, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 19, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 20, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 21, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 22, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 23, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 24, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 25, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 26, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 27, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 28, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 29, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200);

  rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 30, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 31, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 32, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 33, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 34, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 35, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 36, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 37, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 38, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 39, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 40, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 41, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 42, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 43, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 44, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 45, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 46, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 47, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 48, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 49, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 50, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 51, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 52, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 53, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 54, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 55, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 56, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 57, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 58, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 59, 200);
872

873 874
  //rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 60, 200); if uncomment: error because too many segments of SDU
  for (i = 0; i < 24; i++) {
875
    rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200);
876 877 878 879 880
  }

  assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
  printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test 2: END OF TEST BIG SDU SMALL PDUs\n\n\n\n");
#endif
881

882
  for (r = 0; r < 32; r++) {
883 884 885
    //for (r = 0; r < 1024; r++) {
    srand (r);
#ifdef TEST3
886 887 888 889
    g_error_on_phy = 0;
    g_tx_packets = 0;
    g_rx_packets = 0;
    rlc_um_v9_3_0_test_reset_sdus();
890

891 892
    // RANDOM TESTS
    for (i = g_send_id_write_index[0]; g_send_id_write_index[0] < TEST_MAX_SEND_SDU-1; i++) {
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907
      printf("UM.TX SDU %d\n", um_tx.nb_sdu);

      if (um_tx.nb_sdu < (um_tx.size_input_sdus_buffer - 2)) {
        g_random_sdu = rand() % 37;
        rlc_um_v9_3_0_test_send_sdu(&um_tx, g_random_sdu);
      }

      g_random_nb_frames   = (rand() % 10) + 1;

      //g_random_nb_frames   = 1;
      for (j = 0; j < g_random_nb_frames; j++) {
        g_random_tx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
        g_random_rx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
        rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, g_random_tx_pdu_size, g_random_rx_pdu_size);
      }
908
    }
909

910
    for (j = 0; j < 400; j++) {
911
      rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 500, 500);
912
    }
913

914 915
    printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test 3: END OF TEST RANDOM (SEED=%d ) TX ONLY :\n\n\n\n",
           r);
916
    assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
917 918
#endif
#ifdef TEST4
919 920 921 922
    g_error_on_phy = 0;
    g_tx_packets = 0;
    g_rx_packets = 0;
    rlc_um_v9_3_0_test_reset_sdus();
923

924
    for (i = g_send_id_write_index[0]; g_send_id_write_index[0] < TEST_MAX_SEND_SDU-1; i++) {
925 926 927 928 929 930 931
      if (um_tx.nb_sdu < (um_rx.size_input_sdus_buffer - 2)) {
        g_random_sdu = rand() % 37;
        rlc_um_v9_3_0_test_send_sdu(&um_tx, g_random_sdu);

        if (um_rx.nb_sdu < (um_rx.size_input_sdus_buffer - 2)) {
          g_random_sdu = rand() % 37;
          rlc_um_v9_3_0_test_send_sdu(&um_rx, g_random_sdu);
932
        } else {
933
          i = i-1;
934
        }
935 936 937 938 939 940
      } else {
        if (um_rx.nb_sdu < (um_rx.size_input_sdus_buffer - 2)) {
          g_random_sdu = rand() % 37;
          rlc_um_v9_3_0_test_send_sdu(&um_rx, g_random_sdu);
        } else {
          i = i-1;
941
        }
942 943 944 945 946
      }

      g_random_nb_frames   = rand() % 4;

      for (j = 0; j < g_random_nb_frames; j++) {
947 948 949
        g_random_tx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
        g_random_rx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
        rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, g_random_tx_pdu_size, g_random_rx_pdu_size);
950 951 952 953 954 955 956
      }
    }

    for (j = 0; j < 100; j++) {
      g_random_tx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
      g_random_rx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
      rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, g_random_tx_pdu_size, g_random_rx_pdu_size);
957
    }
958

959 960 961
    printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test 4: END OF TEST RANDOM (SEED=%d) TX RX:\n\n\n\n",r);
    assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
    assert (g_send_id_read_index[0] == g_send_id_write_index[1]);
962
#endif
963
  }
964 965

#ifdef TEST5
966 967
  rlc_um_display_rx_window(&um_tx);
  rlc_um_display_rx_window(&um_rx);
968

969 970 971
  for (r = 0; r < 1024; r++) {
    srand (r);
    g_error_on_phy = 1;
972

973
    for (g_target_tx_error_rate = 0; g_target_tx_error_rate < TARGET_MAX_TX_ERROR_RATE; g_target_tx_error_rate++) {
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
      for (g_target_rx_error_rate = 0; g_target_rx_error_rate < TARGET_MAX_RX_ERROR_RATE; g_target_rx_error_rate++) {
        g_tx_packets = 0;
        g_dropped_tx_packets = 0;
        g_rx_packets = 0;
        g_dropped_rx_packets = 0;
        rlc_um_v9_3_0_test_reset_sdus();

        for (i = g_send_id_write_index[0]; g_send_id_write_index[0] < TEST_MAX_SEND_SDU-1; i++) {
          g_random_sdu = rand() % 37;
          rlc_um_v9_3_0_test_send_sdu(&um_tx, g_random_sdu);
          g_random_sdu = rand() % 37;
          //rlc_um_v9_3_0_test_send_sdu(&um_rx, g_random_sdu);


          g_random_nb_frames   = rand() % 4;

          for (j = 0; j < g_random_nb_frames; j++) {
            g_random_tx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
            g_random_rx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
            rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, g_random_tx_pdu_size, g_random_rx_pdu_size);
          }

          //rlc_um_display_rx_window(&um_tx);
          rlc_um_display_rx_window(&um_rx);

          int dropped = (rand() % 3);

          if ((dropped == 0) && (g_tx_packets > 0)) {
            if ((((g_dropped_tx_packets + 1)*100) / g_tx_packets) <= g_target_tx_error_rate) {
              g_drop_tx = 1;
1004
            }
1005 1006 1007 1008 1009 1010 1011
          }

          dropped = (rand() % 3);

          if ((dropped == 0) && (g_rx_packets > 0)) {
            if ((((g_dropped_rx_packets + 1)*100) / g_rx_packets) <= g_target_rx_error_rate) {
              g_drop_rx = 1;
1012
            }
1013 1014
          }
        }
1015

1016 1017 1018 1019
        for (j = 0; j < 100; j++) {
          g_random_tx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
          g_random_rx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
          rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, g_random_tx_pdu_size, g_random_rx_pdu_size);
1020
        }
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032

        printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test 5: END OF TEST RANDOM (SEED=%d BLER TX=%d BLER RX=%d ) TX RX WITH ERRORS ON PHY LAYER:\n\n\n\n",
               r, g_target_tx_error_rate, g_target_rx_error_rate);
        //assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
        //assert (g_send_id_read_index[0] == g_send_id_write_index[1]);
        printf("REAL BLER TX=%d (TARGET=%d) BLER RX=%d (TARGET=%d) \n",
               (g_tx_packets >0)?(g_dropped_tx_packets*100)/g_tx_packets:0,
               g_target_tx_error_rate,
               (g_rx_packets >0)?(g_dropped_rx_packets*100)/g_rx_packets:0,
               g_target_rx_error_rate);

      }
1033
    }
1034

1035 1036 1037 1038 1039 1040 1041
    g_drop_tx = 0;
    g_drop_rx = 0;
    g_tx_packets = 0;
    g_dropped_tx_packets = 0;
    g_rx_packets = 0;
    g_dropped_rx_packets = 0;
    rlc_um_v9_3_0_test_reset_sdus();
1042

1043
    for (j = 0; j < 100; j++) {
1044 1045 1046 1047
      rlc_um_v9_3_0_test_send_sdu(&um_rx, 1);
      g_random_tx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
      g_random_rx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
      rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, g_random_tx_pdu_size, g_random_rx_pdu_size);
1048 1049
    }
  }
1050

1051
  g_error_on_phy = 0;
1052
#endif
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
}
//-----------------------------------------------------------------------------
void rlc_um_v9_3_0_test_tx_rx_5(void)
//-----------------------------------------------------------------------------
{
  rlc_um_info_t     um_info;
  int                   i,j,r;


  um_info.timer_reordering = 32;
  um_info.sn_field_length  = 5;
  um_info.is_mXch          = 0;

  srand (0);
1067 1068
  config_req_rlc_um (&um_tx, 0,0,0, &um_info, 0, SIGNALLING_RADIO_BEARER, SIGNALLING_RADIO_BEARER /*LC-id = DRB-id*/);
  config_req_rlc_um (&um_rx, 0,1,1, &um_info, 1, SIGNALLING_RADIO_BEARER, SIGNALLING_RADIO_BEARER /*LC-id = DRB-id*/);
1069 1070 1071 1072 1073 1074

  rlc_um_display_rx_window(&um_tx);

  rlc_um_display_rx_window(&um_rx);


1075
#ifdef TEST1
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
  srand (0);
  printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test_5 1: START OF SIMPLE TEST SEVERAL SDUs IN PDU\n\n\n\n");
  rlc_um_v9_3_0_test_reset_sdus();
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 8000, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 8000, 200);
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 2);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 8000, 200);
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 2);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 8000, 200);
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 2);
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 3);
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 4);
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 5);
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 6);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200);

  assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122
  printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test_5 1: END OF SIMPLE TEST SEVERAL SDUs IN PDU\n\n\n\n");
  sleep(2);
  rlc_um_v9_3_0_test_reset_sdus();

  // RANDOM TESTS
  for (i = g_send_id_write_index[0]; g_send_id_write_index[0] < TEST_MAX_SEND_SDU-12; i++) {
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
    rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 8000, 200);
    rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 8000, 200);
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 2);
    rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 8000, 200);
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 2);
    rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 8000, 200);
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 2);
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 3);
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 4);
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 5);
    rlc_um_v9_3_0_test_send_sdu(&um_tx, 6);

    for (i = 0; i < 50; i++) {
      rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 400, 200);
1123 1124 1125
    }

    assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
1126 1127 1128 1129 1130
  }

  assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
  printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test 1: END OF TEST SEVERAL SDUs IN PDU\n\n\n\n");
  sleep(2);
1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190
#endif
#ifdef TEST2
  srand (0);
  rlc_um_v9_3_0_test_reset_sdus();
  // BIG SDU SMALL PDUS NO ERRORS
  rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 3, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 3, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 3, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 4, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 5, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 6, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 7, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 8, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 9, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 10, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 11, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 12, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 13, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 14, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 15, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 16, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 17, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 18, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 19, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 20, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 21, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 22, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 23, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 24, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 25, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200);

  rlc_um_v9_3_0_test_send_sdu(&um_tx, 1);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 26, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 27, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 28, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 29, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 30, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 31, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 32, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 33, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 34, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 35, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 36, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 37, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 38, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 39, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 40, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 41, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 42, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 43, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 44, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 45, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 46, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 47, 200);
  rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 48, 200);
1191

1192 1193
  //rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 60, 200); if uncomment: error because too many segments of SDU
  for (i = 0; i < 24; i++) {
1194
    rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200);
1195 1196 1197 1198 1199
  }

  assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
  printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test 2: END OF TEST BIG SDU SMALL PDUs\n\n\n\n");
#endif
1200

1201
  for (r = 0; r < 32; r++) {
1202 1203 1204
    //for (r = 0; r < 1024; r++) {
    srand (r);
#ifdef TEST3
1205 1206 1207 1208
    g_error_on_phy = 0;
    g_tx_packets = 0;
    g_rx_packets = 0;
    rlc_um_v9_3_0_test_reset_sdus();
1209

1210 1211
    // RANDOM TESTS
    for (i = g_send_id_write_index[0]; g_send_id_write_index[0] < TEST_MAX_SEND_SDU-1; i++) {
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226
      printf("UM.TX SDU %d\n", um_tx.nb_sdu);

      if (um_tx.nb_sdu < (um_tx.size_input_sdus_buffer - 2)) {
        g_random_sdu = rand() % 37;
        rlc_um_v9_3_0_test_send_sdu(&um_tx, g_random_sdu);
      }

      g_random_nb_frames   = (rand() % 10) + 1;

      //g_random_nb_frames   = 1;
      for (j = 0; j < g_random_nb_frames; j++) {
        g_random_tx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
        g_random_rx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
        rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, g_random_tx_pdu_size, g_random_rx_pdu_size);
      }
1227
    }
1228

1229
    for (j = 0; j < 400; j++) {
1230
      rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 500, 500);
1231
    }
1232

1233 1234
    printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test 3: END OF TEST RANDOM (SEED=%d ) TX ONLY :\n\n\n\n",r);
    assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
1235 1236
#endif
#ifdef TEST4
1237 1238 1239 1240
    g_error_on_phy = 0;
    g_tx_packets = 0;
    g_rx_packets = 0;
    rlc_um_v9_3_0_test_reset_sdus();
1241

1242
    for (i = g_send_id_write_index[0]; g_send_id_write_index[0] < TEST_MAX_SEND_SDU-1; i++) {
1243 1244 1245 1246 1247 1248 1249
      if (um_tx.nb_sdu < (um_rx.size_input_sdus_buffer - 2)) {
        g_random_sdu = rand() % 37;
        rlc_um_v9_3_0_test_send_sdu(&um_tx, g_random_sdu);

        if (um_rx.nb_sdu < (um_rx.size_input_sdus_buffer - 2)) {
          g_random_sdu = rand() % 37;
          rlc_um_v9_3_0_test_send_sdu(&um_rx, g_random_sdu);
1250
        } else {
1251
          i = i-1;
1252
        }
1253 1254 1255 1256 1257 1258
      } else {
        if (um_rx.nb_sdu < (um_rx.size_input_sdus_buffer - 2)) {
          g_random_sdu = rand() % 37;
          rlc_um_v9_3_0_test_send_sdu(&um_rx, g_random_sdu);
        } else {
          i = i-1;
1259
        }
1260 1261 1262 1263 1264
      }

      g_random_nb_frames   = rand() % 4;

      for (j = 0; j < g_random_nb_frames; j++) {
1265 1266 1267
        g_random_tx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
        g_random_rx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
        rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, g_random_tx_pdu_size, g_random_rx_pdu_size);
1268 1269 1270 1271 1272 1273 1274
      }
    }

    for (j = 0; j < 100; j++) {
      g_random_tx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
      g_random_rx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
      rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, g_random_tx_pdu_size, g_random_rx_pdu_size);
1275
    }
1276

1277 1278 1279
    printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test 4: END OF TEST RANDOM (SEED=%d) TX RX:\n\n\n\n",r);
    assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
    assert (g_send_id_read_index[0] == g_send_id_write_index[1]);
1280
#endif
1281
  }
1282 1283

#ifdef TEST5
1284 1285
  rlc_um_display_rx_window(&um_tx);
  rlc_um_display_rx_window(&um_rx);
1286

1287 1288 1289
  for (r = 0; r < 1024; r++) {
    srand (r);
    g_error_on_phy = 1;
1290

1291
    for (g_target_tx_error_rate = 0; g_target_tx_error_rate < TARGET_MAX_TX_ERROR_RATE; g_target_tx_error_rate++) {
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321
      for (g_target_rx_error_rate = 0; g_target_rx_error_rate < TARGET_MAX_RX_ERROR_RATE; g_target_rx_error_rate++) {
        g_tx_packets = 0;
        g_dropped_tx_packets = 0;
        g_rx_packets = 0;
        g_dropped_rx_packets = 0;
        rlc_um_v9_3_0_test_reset_sdus();

        for (i = g_send_id_write_index[0]; g_send_id_write_index[0] < TEST_MAX_SEND_SDU-1; i++) {
          g_random_sdu = rand() % 37;
          rlc_um_v9_3_0_test_send_sdu(&um_tx, g_random_sdu);
          g_random_sdu = rand() % 37;
          //rlc_um_v9_3_0_test_send_sdu(&um_rx, g_random_sdu);


          g_random_nb_frames   = rand() % 4;

          for (j = 0; j < g_random_nb_frames; j++) {
            g_random_tx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
            g_random_rx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
            rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, g_random_tx_pdu_size, g_random_rx_pdu_size);
          }

          //rlc_um_display_rx_window(&um_tx);
          rlc_um_display_rx_window(&um_rx);

          int dropped = (rand() % 3);

          if ((dropped == 0) && (g_tx_packets > 0)) {
            if ((((g_dropped_tx_packets + 1)*100) / g_tx_packets) <= g_target_tx_error_rate) {
              g_drop_tx = 1;
1322
            }
1323 1324 1325 1326 1327 1328 1329
          }

          dropped = (rand() % 3);

          if ((dropped == 0) && (g_rx_packets > 0)) {
            if ((((g_dropped_rx_packets + 1)*100) / g_rx_packets) <= g_target_rx_error_rate) {
              g_drop_rx = 1;
1330
            }
1331 1332
          }
        }
1333

1334 1335 1336 1337
        for (j = 0; j < 100; j++) {
          g_random_tx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
          g_random_rx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
          rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, g_random_tx_pdu_size, g_random_rx_pdu_size);
1338
        }
1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350

        printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test 5: END OF TEST RANDOM (SEED=%d BLER TX=%d BLER RX=%d ) TX RX WITH ERRORS ON PHY LAYER:\n\n\n\n",
               r, g_target_tx_error_rate, g_target_rx_error_rate);
        //assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
        //assert (g_send_id_read_index[0] == g_send_id_write_index[1]);
        printf("REAL BLER TX=%d (TARGET=%d) BLER RX=%d (TARGET=%d) \n",
               (g_tx_packets >0)?(g_dropped_tx_packets*100)/g_tx_packets:0,
               g_target_tx_error_rate,
               (g_rx_packets >0)?(g_dropped_rx_packets*100)/g_rx_packets:0,
               g_target_rx_error_rate);

      }
1351
    }
1352

1353 1354 1355 1356 1357 1358 1359
    g_drop_tx = 0;
    g_drop_rx = 0;
    g_tx_packets = 0;
    g_dropped_tx_packets = 0;
    g_rx_packets = 0;
    g_dropped_rx_packets = 0;
    rlc_um_v9_3_0_test_reset_sdus();
1360

1361
    for (j = 0; j < 100; j++) {
1362 1363 1364 1365
      rlc_um_v9_3_0_test_send_sdu(&um_rx, 1);
      g_random_tx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
      g_random_rx_pdu_size = (rand() % RLC_SDU_MAX_SIZE)  / ((rand () % 4)+1);
      rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, g_random_tx_pdu_size, g_random_rx_pdu_size);
1366 1367
    }
  }
1368

1369
  g_error_on_phy = 0;
1370
#endif
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385
}

//-----------------------------------------------------------------------------
void rlc_um_v9_3_0_test_print_trace (void)
//-----------------------------------------------------------------------------
{
  void *array[100];
  size_t size;
  char **strings;
  size_t i;

  size = backtrace (array, 100);
  strings = backtrace_symbols (array, size);

  printf ("Obtained %d stack frames.\n", size);
1386

1387
  for (i = 0; i < size; i++) {
1388
    printf ("%s\n", strings[i]);
1389
  }
1390 1391 1392 1393 1394 1395 1396

  free (strings);
}
//-----------------------------------------------------------------------------
void rlc_um_v9_3_0_test(void)
//-----------------------------------------------------------------------------
{
1397
  pool_buffer_init();
1398

1399
  set_comp_log(RLC, LOG_TRACE, LOG_MED, 1);
1400 1401


1402 1403
  // tested OK
  rlc_um_v9_3_0_test_reordering(10);
1404

1405
  rlc_um_v9_3_0_test_tx_rx_10();
1406

1407 1408
  // tested OK
  rlc_um_v9_3_0_test_windows_10();
1409

1410 1411 1412
  rlc_um_v9_3_0_test_tx_rx_5();
  rlc_um_v9_3_0_test_windows_5();
  rlc_um_v9_3_0_test_reordering(5);
1413 1414


1415 1416
  printf("rlc_um_v9_3_0_test: END OF TESTS\n");
  exit(0);
1417
}