rlc_am_test.c 55.7 KB
Newer Older
1
/*******************************************************************************
gauthier's avatar
gauthier committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom

    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.


    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is
   included in this distribution in the file called "COPYING". If not,
   see <http://www.gnu.org/licenses/>.

  Contact Information
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
24
  OpenAirInterface Dev  : openair4g-devel@lists.eurecom.fr
gauthier's avatar
gauthier committed
25

ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
gauthier's avatar
gauthier committed
27
28

 *******************************************************************************/
29
30
31
#define RLC_AM_MODULE 1
#define RLC_AM_TEST_C 1
#define RLC_C 1
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
84
85

#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 "platform_types.h"
//-----------------------------------------------------------------------------
#include "rlc.h"
#include "rlc_am.h"
#include "rlc_am_test.h"
#include "list.h"
#include "LAYER2/MAC/extern.h"








#define TEST1
#define TEST2
#define TEST3
#define TEST4
#define TEST5
#define TEST6
#define TEST7

#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_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_mui = 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];
gauthier's avatar
gauthier committed
86
87
static uint8_t g_buffer[32];
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.",
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
124
125
126
                           "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."
                          };
127
128
129
130
131
132
133

/*  Returns the x-y size of the terminal  */

//-----------------------------------------------------------------------------
void rlc_am_v9_3_0_test_windows()
//-----------------------------------------------------------------------------
{
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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
  rlc_am_entity_t am1;
  rlc_am_entity_t am2;
  unsigned int    i;
  unsigned int    j;

  rlc_am_init(&am1, g_frame);
  rlc_am_init(&am2, g_frame);

  // TX window with vt_ms > vt_a
  for (j = 0; j < RLC_AM_SN_MODULO-RLC_AM_WINDOW_SIZE; j++) {
    am1.vt_a = j;
    am1.vt_s = j;
    am1.vt_ms = (am1.vt_a + RLC_AM_WINDOW_SIZE) & RLC_AM_SN_MASK;

    for (i = 0 ; i < am1.vt_a; i ++) {
      assert(rlc_am_in_tx_window(&am1, i) == 0);
    }

    for (i = j ; i < am1.vt_ms; i ++) {
      assert(rlc_am_in_tx_window(&am1, i) > 0);
    }

    for (i = am1.vt_ms ; i <= 0xFFFF; i ++) {
      //printf("assert(rlc_am_in_tx_window(&am1, %d) == 0)) vt(s)=%d vt(ms)=%d\n", i, am1.vt_s, am1.vt_ms);
      assert(rlc_am_in_tx_window(&am1, i) == 0);
    }
  }

  // TX window with vt_ms < vt_a
  for (j = RLC_AM_SN_MODULO-RLC_AM_WINDOW_SIZE; j < RLC_AM_SN_MODULO; j++) {
    am1.vt_a = j;
    am1.vt_s = j;
    am1.vt_ms = (am1.vt_a + RLC_AM_WINDOW_SIZE) & RLC_AM_SN_MASK;

    for (i = 0 ; i < am1.vt_ms; i ++) {
      assert(rlc_am_in_tx_window(&am1, i) > 0);
    }

    for (i = j ; i < am1.vt_a; i ++) {
      assert(rlc_am_in_tx_window(&am1, i) == 0);
    }

    for (i = am1.vt_a ; i < RLC_AM_SN_MODULO; i ++) {
      assert(rlc_am_in_tx_window(&am1, i) > 0);
    }

    for (i = RLC_AM_SN_MODULO ; i < 0xFFFF; i ++) {
      assert(rlc_am_in_tx_window(&am1, i) == 0);
    }
  }

  // RX window with vr_mr > vr_r
  for (j = 0; j < RLC_AM_SN_MODULO-RLC_AM_WINDOW_SIZE; j++) {
    am1.vr_r = j;
    am1.vr_mr = (am1.vr_r + RLC_AM_WINDOW_SIZE) & RLC_AM_SN_MASK;

    for (i = 0 ; i < am1.vr_r; i ++) {
      assert(rlc_am_in_rx_window(&am1, i) == 0);
    }

    for (i = j ; i < am1.vr_mr; i ++) {
      //printf("assert(rlc_am_in_rx_window(&am1, %d) == 0)) vr(r)=%d vr(mr)=%d\n", i, am1.vr_r, am1.vr_mr);
      assert(rlc_am_in_rx_window(&am1, i) > 0);
    }

    for (i = am1.vr_mr ; i <= 0xFFFF; i ++) {
      assert(rlc_am_in_rx_window(&am1, i) == 0);
    }
  }

  // RX window with vr_mr < vr_r
  for (j = RLC_AM_SN_MODULO-RLC_AM_WINDOW_SIZE; j < RLC_AM_SN_MODULO; j++) {
    am1.vr_r = j;
    am1.vr_mr = (am1.vr_r + RLC_AM_WINDOW_SIZE) & RLC_AM_SN_MASK;

    for (i = 0 ; i < am1.vr_mr; i ++) {
      assert(rlc_am_in_rx_window(&am1, i) > 0);
    }

    for (i = j ; i < am1.vr_r; i ++) {
      assert(rlc_am_in_rx_window(&am1, i) == 0);
    }

    for (i = am1.vr_r ; i < RLC_AM_SN_MODULO; i ++) {
      assert(rlc_am_in_rx_window(&am1, i) > 0);
    }

    for (i = RLC_AM_SN_MODULO ; i < 0xFFFF; i ++) {
      assert(rlc_am_in_rx_window(&am1, i) == 0);
    }
  }
225
226
227
228
229
230
231

}
//-----------------------------------------------------------------------------
void rlc_am_v9_3_0_test_read_write_bit_field()
//-----------------------------------------------------------------------------
{
  unsigned int bit_pos_write       = 0; // range from 0 (MSB/left) to 7 (LSB/right)
gauthier's avatar
gauthier committed
232
  uint8_t*        byte_pos_write      = g_buffer;
233
234

  unsigned int bit_pos_read       = 0; // range from 0 (MSB/left) to 7 (LSB/right)
gauthier's avatar
gauthier committed
235
236
  uint8_t*        byte_pos_read      = g_buffer;
  uint16_t        read_value;
237
238
239
240
241
242
243
244
245
246
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509

  memset (g_buffer, 0, 1024);
  // byte 0
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0);
  assert(g_buffer[0] == 0x96);
  assert(g_buffer[1] == 0x00);

  // byte 1
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1);
  assert(g_buffer[0] == 0x96);

  assert(g_buffer[1] == 0xD9);
  assert(g_buffer[2] == 0x00);

  // byte 2
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1);
  assert(g_buffer[0] == 0x96);
  assert(g_buffer[1] == 0xD9);

  assert(g_buffer[2] == 0x11);
  assert(g_buffer[3] == 0x00);
  // byte 3 & 4
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 2, 0x2);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 2, 0x1);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 2, 0x2);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0x0);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 2, 0x3);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0x0);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 2, 0x2);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 2, 0x1);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 2, 0x3);
  assert(g_buffer[0] == 0x96);
  assert(g_buffer[1] == 0xD9);
  assert(g_buffer[2] == 0x11);

  assert(g_buffer[3] == 0x99);
  assert(g_buffer[4] == 0xA7);
  assert(g_buffer[5] == 0x00);
  // byte 5 & 6
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 3, 0x7);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 3, 0x5);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 3, 0x1);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 3, 0x0);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 3, 0x3);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0x0);
  assert(g_buffer[0] == 0x96);
  assert(g_buffer[1] == 0xD9);
  assert(g_buffer[2] == 0x11);
  assert(g_buffer[3] == 0x99);
  assert(g_buffer[4] == 0xA7);

  assert(g_buffer[5] == 0xF4);
  assert(g_buffer[6] == 0x86);
  assert(g_buffer[7] == 0x00);
  // byte 7 & 8 & 9
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 4, 0xC);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 4, 0xD);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0x0);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 4, 0xF);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 4, 0xA);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 4, 0xB);
  rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 3, 0x0);
  assert(g_buffer[0] == 0x96);
  assert(g_buffer[1] == 0xD9);
  assert(g_buffer[2] == 0x11);
  assert(g_buffer[3] == 0x99);
  assert(g_buffer[4] == 0xA7);
  assert(g_buffer[5] == 0xF4);
  assert(g_buffer[6] == 0x86);

  assert(g_buffer[7] == 0xCD);
  assert(g_buffer[8] == 0x7D);
  assert(g_buffer[9] == 0x58);
  assert(g_buffer[10] == 0x00);
  // byte 10 & 11 & 12 & 13 & 14
  rlc_am_write16_bit_field(&byte_pos_write, &bit_pos_write, 10, 0x2AB);
  rlc_am_write16_bit_field(&byte_pos_write, &bit_pos_write, 10, 0x1BA);
  rlc_am_write16_bit_field(&byte_pos_write, &bit_pos_write, 10, 0x2AF);
  rlc_am_write16_bit_field(&byte_pos_write, &bit_pos_write, 10, 0x134);
  assert(g_buffer[0]  == 0x96);
  assert(g_buffer[1]  == 0xD9);
  assert(g_buffer[2]  == 0x11);
  assert(g_buffer[3]  == 0x99);
  assert(g_buffer[4]  == 0xA7);
  assert(g_buffer[5]  == 0xF4);
  assert(g_buffer[6]  == 0x86);
  assert(g_buffer[7]  == 0xCD);
  assert(g_buffer[8]  == 0x7D);
  assert(g_buffer[9]  == 0x58);

  assert(g_buffer[10] == 0xAA);
  assert(g_buffer[11] == 0xDB);
  assert(g_buffer[12] == 0xAA);
  assert(g_buffer[13] == 0xBD);
  assert(g_buffer[14] == 0x34);
  assert(g_buffer[15] == 0x00);
  // byte 15 - 29
  rlc_am_write16_bit_field(&byte_pos_write, &bit_pos_write, 15, 0x701F);
  rlc_am_write16_bit_field(&byte_pos_write, &bit_pos_write, 15, 0x612E);
  rlc_am_write16_bit_field(&byte_pos_write, &bit_pos_write, 15, 0x523D);
  rlc_am_write16_bit_field(&byte_pos_write, &bit_pos_write, 15, 0x434C);
  rlc_am_write16_bit_field(&byte_pos_write, &bit_pos_write, 15, 0x345B);
  rlc_am_write16_bit_field(&byte_pos_write, &bit_pos_write, 15, 0x256A);
  rlc_am_write16_bit_field(&byte_pos_write, &bit_pos_write, 15, 0x1679);
  rlc_am_write16_bit_field(&byte_pos_write, &bit_pos_write, 15, 0x0788);
  assert(g_buffer[0]  == 0x96);
  assert(g_buffer[1]  == 0xD9);
  assert(g_buffer[2]  == 0x11);
  assert(g_buffer[3]  == 0x99);
  assert(g_buffer[4]  == 0xA7);
  assert(g_buffer[5]  == 0xF4);
  assert(g_buffer[6]  == 0x86);
  assert(g_buffer[7]  == 0xCD);
  assert(g_buffer[8]  == 0x7D);
  assert(g_buffer[9]  == 0x58);
  assert(g_buffer[10] == 0xAA);
  assert(g_buffer[11] == 0xDB);
  assert(g_buffer[12] == 0xAA);
  assert(g_buffer[13] == 0xBD);
  assert(g_buffer[14] == 0x34);

  assert(g_buffer[15] == 0xE0);
  assert(g_buffer[16] == 0x3F);
  assert(g_buffer[17] == 0x84);
  assert(g_buffer[18] == 0xBA);
  assert(g_buffer[19] == 0x91);
  assert(g_buffer[20] == 0xEC);
  assert(g_buffer[21] == 0x34);
  assert(g_buffer[22] == 0xC6);
  assert(g_buffer[23] == 0x8B);
  assert(g_buffer[24] == 0x69);
  assert(g_buffer[25] == 0x5A);
  assert(g_buffer[26] == 0x8B);
  assert(g_buffer[27] == 0x3C);
  assert(g_buffer[28] == 0x87);
  assert(g_buffer[29] == 0x88);
  assert(g_buffer[30] == 0x00);

  // 0x96 0xD9
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b0
  assert(read_value == 1);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b1
  assert(read_value == 0);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b2
  assert(read_value == 0);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b3
  assert(read_value == 1);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b4
  assert(read_value == 0);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b5
  assert(read_value == 1);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b6
  assert(read_value == 1);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b7
  assert(read_value == 0);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b8
  assert(read_value == 1);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b9
  assert(read_value == 1);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b10
  assert(read_value == 0);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b11
  assert(read_value == 1);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b12
  assert(read_value == 1);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b13
  assert(read_value == 0);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b14
  assert(read_value == 0);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b15
  assert(read_value == 1);

  //  0x11 0x99
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 2);
  assert(read_value == 0);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 2);
  assert(read_value == 1);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 2);
  assert(read_value == 0);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);
  assert(read_value == 0);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 2);
  assert(read_value == 3);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 2);
  assert(read_value == 0);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);
  assert(read_value == 1);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 2);
  assert(read_value == 2);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 2);
  assert(read_value == 1);

  //  0xA7 0xF4 0x86 0xCD 0x7D;
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10);
  assert(read_value == 0x29F);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10);
  assert(read_value == 0x348);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10);
  assert(read_value == 0x1B3);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10);
  assert(read_value == 0x17D);

  //  0x58 0xAA 0xDB 0xAA 0xBD 0x34
  //  0xE0 0x3F 0x84 0xBA 0x91 0xEC

  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);
  assert(read_value == 0);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10);
  assert(read_value == 0x2C5);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10);
  assert(read_value == 0x15B);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10);
  assert(read_value == 0x1D5);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10);
  assert(read_value == 0x17A);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);
  assert(read_value == 0);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10);
  assert(read_value == 0x34E);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10);
  assert(read_value == 0x00F);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10);
  assert(read_value == 0x384);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10);
  assert(read_value == 0x2EA);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10);
  assert(read_value == 0x11E);

  bit_pos_read  = 0;
  byte_pos_read = g_buffer;
  // 0x96 0xD9 0x11 0x99 0xA7 0xF4 0x86 0xCD 0x7D 0x58 0xAA 0xDB 0xAA 0xBD 0x34
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 15);
  assert(read_value == 0x4B6C);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 15);
  assert(read_value == 0x4466);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 15);
  assert(read_value == 0x34FE);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 15);
  assert(read_value == 0x486C);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 15);
  assert(read_value == 0x6BEA);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 15);
  assert(read_value == 0x62AB);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 15);
  assert(read_value == 0x3755);
  read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 15);
  assert(read_value == 0x3D34);
}
//-----------------------------------------------------------------------------
void rlc_am_v9_3_0_test_reset_sdus()
//-----------------------------------------------------------------------------
{
510
511
512
513
514
  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;
515
    }
516
517
518
519

    g_send_id_write_index[j] = 0;
    g_send_id_read_index[j]  = 0;
  }
520
521
522
523
524
525
526
527
528
}
//-----------------------------------------------------------------------------
void rlc_am_v9_3_0_test_send_sdu(rlc_am_entity_t *am_txP, int sdu_indexP)
//-----------------------------------------------------------------------------
{
  mem_block_t *sdu;
  sdu = get_free_mem_block (strlen(g_sdus[sdu_indexP]) + 1 + sizeof (struct rlc_am_data_req_alloc));

  if (sdu != NULL) {
529
530
531
532
533
534
535
536
537
538
539
540
541
    // PROCESS OF COMPRESSION HERE:
    printf("[FRAME %05d][RLC][MOD %02d][RB %02d] TX SDU %d %04d bytes\n",g_frame,am_txP->module_id, am_txP->rb_id, sdu_indexP, strlen(g_sdus[sdu_indexP]) + 1);
    memset (sdu->data, 0, sizeof (struct rlc_am_data_req_alloc));
    strcpy (&sdu->data[sizeof (struct rlc_am_data_req_alloc)],g_sdus[sdu_indexP]);

    ((struct rlc_am_data_req *) (sdu->data))->data_size = strlen(g_sdus[sdu_indexP])+ 1;
    ((struct rlc_am_data_req *) (sdu->data))->conf = 1;
    ((struct rlc_am_data_req *) (sdu->data))->mui  = g_mui++;
    ((struct rlc_am_data_req *) (sdu->data))->data_offset = sizeof (struct rlc_am_data_req_alloc);
    rlc_am_data_req(am_txP, g_frame, sdu);

    g_send_sdu_ids[g_send_id_write_index[am_txP->rb_id]++][am_txP->rb_id] = sdu_indexP;
    assert(g_send_id_write_index[am_txP->rb_id] < TEST_MAX_SEND_SDU);
542
543
544
545
546
547
  } else {
    printf("Out of memory error\n");
    exit(-1);
  }
}
//-----------------------------------------------------------------------------
548
549
void rlc_am_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) //-----------------------------------------------------------------------------
550
551
552
553
554
555
556
557
{


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

  data_indP->no_tb = 0;
558

559
560
  while (data_requestP->data.nb_elements > 0) {
    tb_src = list_remove_head (&data_requestP->data);
561

562
    if (tb_src != NULL) {
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
      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) {
        tb_dst  = get_free_mem_block(sizeof (mac_rlc_max_rx_header_size_t) + tb_size);

        if (tb_dst != 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;
585
        } else {
586
587
          printf("Out of memory error\n");
          exit(-1);
588
        }
589
590
591
592
593
594
595
596
597
598
599
      } else {
        printf("[RLC-LOOP] DROPPING 1 TB\n");
        *drop_countP = *drop_countP - 1;
        *dropped_tx_packetsP = *dropped_tx_packetsP + 1;
      }

      free_mem_block(tb_src);

      if (data_indP->no_tb > 0) {
        printf("[RLC-LOOP] Exchange %d TBs\n",data_indP->no_tb);
      }
600
601
602
603
604
605
    }
  }
}
//-----------------------------------------------------------------------------
void rlc_am_v9_3_0_test_exchange_pdus(rlc_am_entity_t *am_txP,
                                      rlc_am_entity_t *am_rxP,
gauthier's avatar
gauthier committed
606
607
                                      uint16_t           bytes_txP,
                                      uint16_t           bytes_rxP)
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
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
//-----------------------------------------------------------------------------
{
  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));

  mac_rlc_status_resp_tx = rlc_am_mac_status_indication(am_txP, g_frame, bytes_txP, tx_status);
  data_request_tx        = rlc_am_mac_data_request(am_txP, g_frame);
  mac_rlc_status_resp_rx = rlc_am_mac_status_indication(am_rxP, g_frame, bytes_rxP, tx_status);
  data_request_rx        = rlc_am_mac_data_request(am_rxP, g_frame);


  rlc_am_v9_3_0_test_mac_rlc_loop(&data_ind_rx, &data_request_tx, &g_drop_tx, &g_tx_packets, &g_dropped_tx_packets);
  rlc_am_v9_3_0_test_mac_rlc_loop(&data_ind_tx, &data_request_rx, &g_drop_rx, &g_rx_packets, &g_dropped_rx_packets);
  rlc_am_mac_data_indication(am_rxP, g_frame, am_txP->is_enb, data_ind_rx);
  rlc_am_mac_data_indication(am_txP, g_frame, am_txP->is_enb, data_ind_tx);
  g_frame += 1;

  //rlc_am_tx_buffer_display(am_txP,NULL);
  //assert(am_txP->t_status_prohibit.time_out != 1);
  //assert(am_rxP->t_status_prohibit.time_out != 1);
  //assert(!((am_txP->vt_a == 954) && (am_txP->vt_s == 53)));
  //assert(g_frame <= 151);
  //check_mem_area(NULL);
  //display_mem_load();
}
//-----------------------------------------------------------------------------
void rlc_am_v9_3_0_test_data_conf(module_id_t module_idP, rb_id_t rb_idP, mui_t muiP, rlc_tx_status_t statusP)
//-----------------------------------------------------------------------------
{
651
652
653
654
655
  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);
  }
656
657
658
659
660
}
//-----------------------------------------------------------------------------
void rlc_am_v9_3_0_test_data_ind (module_id_t module_idP, rb_id_t rb_idP, sdu_size_t sizeP, mem_block_t *sduP)
//-----------------------------------------------------------------------------
{
661
  int i;
662

663
664
665
666
667
  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]);
668

669
      if (g_send_sdu_ids[g_send_id_read_index[rb_idP]][rb_idP^1] != i) {
670

671
672
673
674
675
676
        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]);
677
678
679
680
681
682
683
684

        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);
      }

      assert(g_send_sdu_ids[g_send_id_read_index[rb_idP]][rb_idP^1] == i);
      g_send_id_read_index[rb_idP] += 1;
      free_mem_block(sduP);
      return;
685
    }
686
687
688
689
690
  }

  printf("[FRAME %05d][RLC][MOD %d][RB %d] RX UNKNOWN SDU %04d bytes\n",g_frame,module_idP, rb_idP,  sizeP);
  free_mem_block(sduP);
  assert(1==2);
691
692
693
694
695
}
//-----------------------------------------------------------------------------
void rlc_am_v9_3_0_test_tx_rx()
//-----------------------------------------------------------------------------
{
gauthier's avatar
gauthier committed
696
697
698
699
700
701
  uint16_t                 max_retx_threshold = 255;
  uint16_t                 poll_pdu           = 8;
  uint16_t                 poll_byte          = 1000;
  uint32_t                 t_poll_retransmit  = 15;
  uint32_t                 t_reordering       = 5000;
  uint32_t                 t_status_prohibit  = 10;
702
703
704
705
706
707
  int                   i,j,r;

  srand (0);

  rlc_am_init(&g_am_tx, g_frame);
  rlc_am_init(&g_am_rx, g_frame);
708
709
  rlc_am_set_debug_infos(&g_am_tx, g_frame, 0, 0, 0, 1, 1 /* LC-id = DRB-id */);
  rlc_am_set_debug_infos(&g_am_rx, g_frame, 1, 1, 1, 1, 1 /* LC-id = DRB-id */);
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738

  rlc_am_configure(&g_am_tx, g_frame, max_retx_threshold, poll_pdu, poll_byte, t_poll_retransmit, t_reordering, t_status_prohibit);
  rlc_am_configure(&g_am_rx, g_frame, max_retx_threshold, poll_pdu, poll_byte, t_poll_retransmit, t_reordering, t_status_prohibit);

#ifdef TEST1
  srand (0);
  rlc_am_v9_3_0_test_reset_sdus();
  rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 1);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 8000, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 8000, 200);
  rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 2);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 8000, 200);
  rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 1);
  rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 2);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 8000, 200);
  rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 1);
  rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 2);
  rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 3);
  rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 4);
  rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 5);
  rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 6);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 1000, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 1000, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 1000, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 1000, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 1000, 200);
  rlc_am_rx_list_display(&g_am_tx, "RLC-AM TX:");
  rlc_am_rx_list_display(&g_am_rx, "RLC-AM RX:");
  assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
  printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_am_v9_3_0_test 1: END OF SIMPLE TEST SEVERAL SDUs IN PDU\n\n\n\n");

  rlc_am_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_am_v9_3_0_test_send_sdu(&g_am_tx, 1);
    rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 8000, 200);
    rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 8000, 200);
    rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 2);
    rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 8000, 200);
    rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 1);
    rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 2);
    rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 8000, 200);
    rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 1);
    rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 2);
    rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 3);
    rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 4);
    rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 5);
    rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 6);

    for (i = 0; i < 50; i++) {
      rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 200, 200);
762
    }
763

764
    assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
765
766
767
768
769
770
  }

  rlc_am_rx_list_display(&g_am_tx, "RLC-AM TX:");
  rlc_am_rx_list_display(&g_am_rx, "RLC-AM RX:");
  assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
  printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_am_v9_3_0_test 1: END OF TEST SEVERAL SDUs IN PDU\n\n\n\n");
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
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
#endif
#ifdef TEST2
  srand (0);
  rlc_am_v9_3_0_test_reset_sdus();
  // BIG SDU SMALL PDUS NO ERRORS
  rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 1);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 3, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 3, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 3, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 4, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 5, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 6, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 7, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 8, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 9, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 10, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 11, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 12, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 13, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 16, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 17, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 18, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 19, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 20, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 21, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 22, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 23, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 24, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 25, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 26, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 27, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 28, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 29, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 2000, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 2000, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 2000, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 2000, 200);

  rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 1);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 30, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 31, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 32, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 33, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 34, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 35, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 36, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 37, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 38, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 39, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 40, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 41, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 42, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 43, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 44, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 45, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 46, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 47, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 48, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 49, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 50, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 51, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 52, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 53, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 54, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 55, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 56, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 57, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 58, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 59, 200);
842

843
844
  //rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 60, 200); if uncomment: error because too many segments of SDU
  for (i = 0; i < 24; i++) {
845
    rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 2000, 200);
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
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
  rlc_am_rx_list_display(&g_am_tx, "RLC-AM TX:");
  rlc_am_rx_list_display(&g_am_rx, "RLC-AM RX:");
  assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
  printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_am_v9_3_0_test 2: END OF TEST BIG SDU SMALL PDUs\n\n\n\n");
#endif
#ifdef TEST3
  srand (0);
  rlc_am_v9_3_0_test_reset_sdus();
  // BIG SDU SMALL PDUS  ERRORs  ()
  rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 1);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 3, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 3, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 3, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 4, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 5, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 6, 200);
  g_drop_tx = 1;
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 7, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 8, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 9, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 10, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 11, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 12, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 13, 200);
  g_drop_tx = 2;
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 16, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 17, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 18, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 19, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 20, 200);
  g_drop_tx = 4;
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 21, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 22, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 23, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 24, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 25, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 26, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 300, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 300, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 300, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 300, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 300, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 300, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 300, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 300, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 300, 200);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 300, 200);
897

898
  for (i = 0; i < 30; i++) {
899
    rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 500, 200);
900
  }
901
902
903

  // Purge
  for (i = 0; i < 24; i++) {
904
905
    rlc_am_v9_3_0_test_send_sdu(&g_am_tx, i);
    rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 300, 200);
906
  }
907

908
  for (i = 0; i < 100; i++) {
909
    rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 300, 200);
910
  }
911

912
913
914
915
916
917
918
919
  rlc_am_rx_list_display(&g_am_tx, "RLC-AM TX:");
  rlc_am_rx_list_display(&g_am_rx, "RLC-AM RX:");
  assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
  printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_am_v9_3_0_test 3: END OF TEST BIG SDU SMALL PDUs WITH ERRORS ON PHY LAYER\n\n\n\n");
#endif
#ifdef TEST4
  srand (0);
  rlc_am_v9_3_0_test_reset_sdus();
920

921
  for (i = 2 ; i < 37 ; i++) {
922
    rlc_am_v9_3_0_test_send_sdu(&g_am_tx, i);
923
  }
924

925
  for (i = 2 ; i < 37 ; i++) {
926
    rlc_am_v9_3_0_test_send_sdu(&g_am_tx, i);
927
  }
928

929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 30, 100);
  g_drop_tx = 4;
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 100, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 100, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 100, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 300, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 20, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 20, 100);
  g_drop_tx = 4;
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 20, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100);

  t_poll_retransmit = 6;
  rlc_am_configure(&g_am_tx, g_frame, max_retx_threshold, poll_pdu, poll_byte, t_poll_retransmit, t_reordering, t_status_prohibit);

  for (i = 0 ; i < 50 ; i++) {
972
    rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 100, 100);
973
  }
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
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
  //exit(0);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 400, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 400, 100);
  //exit(0);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 400, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  //exit(0);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 14, 100);
  rlc_am_rx_list_display(&g_am_tx, "RLC-AM TX:");
  rlc_am_rx_list_display(&g_am_rx, "RLC-AM RX:");
  assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
  printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_am_v9_3_0_test 4: END OF TEST SEVERAL SDUS IN PDUs WITH ERRORS ON PHY LAYER\n\n\n\n");
  assert (g_send_id_write_index[0] < TEST_MAX_SEND_SDU);
#endif
#ifdef TEST5
  srand (0);
  rlc_am_v9_3_0_test_reset_sdus();
1020

1021
1022
  // RANDOM TESTS
  for (i = 0; g_send_id_write_index < TEST_MAX_SEND_SDU-1; i++) {
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
    //for (i = 0; g_send_id_write_index < 434; i++) {
    printf("AM.TX SDU %d\n", g_am_tx.nb_sdu);

    if (g_am_tx.nb_sdu < (RLC_AM_SDU_CONTROL_BUFFER_SIZE - 16)) {
      g_random_sdu = rand() % 37;
      rlc_am_v9_3_0_test_send_sdu(&g_am_tx, g_random_sdu);
    }

    //g_random_nb_frames   = (rand() % 2) + 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;
      g_random_rx_pdu_size = rand() % RLC_SDU_MAX_SIZE;
      rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, g_random_tx_pdu_size, g_random_rx_pdu_size);
    }
1039
  }
1040

1041
1042
1043
  rlc_am_rx_list_display(&g_am_tx, "RLC-AM TX:");
  rlc_am_rx_list_display(&g_am_rx, "RLC-AM RX:");
  printf("g_send_id_read_index %d g_send_id_write_index %d\n", g_send_id_read_index[1], g_send_id_write_index[0]);
1044

1045
  for (j = 0; j < 100; j++) {
1046
1047
1048
    g_random_tx_pdu_size = rand() % RLC_SDU_MAX_SIZE;
    g_random_rx_pdu_size = rand() % RLC_SDU_MAX_SIZE;
    rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, g_random_tx_pdu_size, g_random_rx_pdu_size);
1049
  }
1050

1051
1052
1053
1054
1055
  rlc_am_rx_list_display(&g_am_tx, "RLC-AM TX:");
  rlc_am_rx_list_display(&g_am_rx, "RLC-AM RX:");
  assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
  printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_am_v9_3_0_test 5: END OF TEST RANDOM TX ONLY  WITH NO ERRORS ON PHY LAYER\n\n\n\n");
#endif
1056
1057
1058

  for (r = 0; r < 128; r++) {
    srand (r);
1059
1060
#ifdef TEST6

1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
    for (g_target_tx_error_rate = 0; g_target_tx_error_rate < TARGET_MAX_TX_ERROR_RATE; g_target_tx_error_rate++) {
      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_am_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-1; i++) {
          printf("AM.TX SDU %d\n", g_am_tx.nb_sdu);

          if (g_am_tx.nb_sdu < (RLC_AM_SDU_CONTROL_BUFFER_SIZE - 2)) {
            g_random_sdu = rand() % 37;
            rlc_am_v9_3_0_test_send_sdu(&g_am_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_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, g_random_tx_pdu_size, g_random_rx_pdu_size);
          }

          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;
1092
            }
1093
1094
1095
1096
1097
1098
1099
1100
1101
          }

          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;
            }
          }
1102
        }
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112

        for (j = 0; j < 400; j++) {
          rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 500, 500);
        }

        printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_am_v9_3_0_test 6: END OF TEST RANDOM (SEED=%d BLER TX=%d BLER RX=%d) TX ONLY WITH ERRORS ON PHY LAYER:\n\n\n\n",
               r, g_target_tx_error_rate, g_target_rx_error_rate);
        rlc_am_rx_list_display(&g_am_tx, "RLC-AM TX:");
        rlc_am_rx_list_display(&g_am_rx, "RLC-AM RX:");
        assert (g_send_id_read_index[1] == g_send_id_write_index[0]);
1113
1114
        printf("REAL BLER TX=%d (TARGET=%d) BLER RX=%d (TARGET=%d) \n",(g_dropped_tx_packets*100)/g_tx_packets, g_target_tx_error_rate,
               (g_dropped_rx_packets*100)/g_rx_packets, g_target_rx_error_rate);
1115
1116
1117
      }
    }

1118
1119
1120
#endif
#ifdef TEST7

1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
    for (g_target_tx_error_rate = 0; g_target_tx_error_rate < TARGET_MAX_TX_ERROR_RATE; g_target_tx_error_rate++) {
      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_am_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++) {
          if (g_am_tx.nb_sdu < (RLC_AM_SDU_CONTROL_BUFFER_SIZE - 2)) {
            g_random_sdu = rand() % 37;
            rlc_am_v9_3_0_test_send_sdu(&g_am_tx, g_random_sdu);

            if (g_am_rx.nb_sdu < (RLC_AM_SDU_CONTROL_BUFFER_SIZE - 2)) {
              g_random_sdu = rand() % 37;
              rlc_am_v9_3_0_test_send_sdu(&g_am_rx, g_random_sdu);
            } else {
              i = i-1;
            }
          } else {
            if (g_am_rx.nb_sdu < (RLC_AM_SDU_CONTROL_BUFFER_SIZE - 2)) {
              g_random_sdu = rand() % 37;
              rlc_am_v9_3_0_test_send_sdu(&g_am_rx, g_random_sdu);
            } else {
              i = i-1;
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
          }

          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_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, g_random_tx_pdu_size, g_random_rx_pdu_size);
          }

          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;
            }
          }

          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;
            }
          }
1172
        }
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185

        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_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, g_random_tx_pdu_size, g_random_rx_pdu_size);
        }

        printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_am_v9_3_0_test 7: 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);
        rlc_am_rx_list_display(&g_am_tx, "RLC-AM TX:");
        rlc_am_rx_list_display(&g_am_rx, "RLC-AM RX:");
        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]);
1186
1187
        printf("REAL BLER TX=%d (TARGET=%d) BLER RX=%d (TARGET=%d) \n",(g_dropped_tx_packets*100)/g_tx_packets, g_target_tx_error_rate,
               (g_dropped_rx_packets*100)/g_rx_packets, g_target_rx_error_rate);
1188
1189

      }
1190
    }
1191
1192
1193

#endif
  }
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
}
//-----------------------------------------------------------------------------
void rlc_am_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);

1209
  for (i = 0; i < size; i++) {
1210
    printf ("%s\n", strings[i]);
1211
  }
1212
1213
1214
1215
1216
1217
1218
1219

  free (strings);
}

//-----------------------------------------------------------------------------
void rlc_am_v9_3_0_test(void)
//-----------------------------------------------------------------------------
{
1220
1221
1222
  //     initscr();
  //     cbreak();
  //     keypad(stdscr, TRUE);
1223
1224
1225



1226
1227
1228
  // under test
  pool_buffer_init();
  set_comp_log(RLC, LOG_ERR, LOG_MED, 1);
1229

1230
  rlc_am_v9_3_0_test_tx_rx();
1231

1232
1233
1234
1235
1236
  // already tested
  rlc_am_v9_3_0_test_windows();
  rlc_am_v9_3_0_test_read_write_bit_field();
  printf("rlc_am_v9_3_0_test: END OF TESTS\n");
  exit(0);
1237
}