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

This program is free software; you can redistribute it and/or modify it
under the terms and conditions of the GNU General Public License,
version 2, as published by the Free Software Foundation.

This program is distributed in the hope 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
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.

The full GNU General Public License is included in this distribution in
the file called "COPYING".

Contact Information
Openair Admin: openair_admin@eurecom.fr
Openair Tech : openair_tech@eurecom.fr
Forums       : http://forums.eurecom.fsr/openairinterface
gauthier's avatar
Licence    
gauthier committed
25
26
27
28
29
30
31
Address      : EURECOM,
               Campus SophiaTech,
               450 Route des Chappes,
               CS 50193
               06904 Biot Sophia Antipolis cedex,
               FRANCE
*******************************************************************************/
32
33
34
#define RLC_UM_MODULE
#define RLC_UM_CONTROL_PRIMITIVES_C
#include "platform_types.h"
35
#include "assertions.h"
36
37
38
39
40
41
42
43
44
45
46
47
//-----------------------------------------------------------------------------
#include "rlc_um.h"
#include "rlc_primitives.h"
#include "list.h"
#include "rrm_config_structs.h"
#include "LAYER2/MAC/extern.h"
#include "UTIL/LOG/log.h"

#include "rlc_um_control_primitives.h"
#include "T-Reordering.h"

//-----------------------------------------------------------------------------
48
49
50
51
52
53
54
55
void config_req_rlc_um (
    const module_id_t     enb_module_idP,
    const module_id_t     ue_module_idP,
    const frame_t         frameP,
    const eNB_flag_t      eNB_flagP,
    const srb_flag_t      srb_flagP,
    const rlc_um_info_t  * const config_um_pP,
    const rb_id_t         rb_idP)
56
{
gauthier's avatar
gauthier committed
57
  //-----------------------------------------------------------------------------
58
59
60
61
  rlc_union_t     *rlc_union_p  = NULL;
  rlc_um_entity_t *rlc_p        = NULL;
  hash_key_t       key          = RLC_COLL_KEY_VALUE(enb_module_idP, ue_module_idP, eNB_flagP, rb_idP, srb_flagP);
  hashtable_rc_t   h_rc;
gauthier's avatar
gauthier committed
62

63
64
65
66
67
68
  h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p);
  if (h_rc == HASH_TABLE_OK) {
      rlc_p = &rlc_union_p->rlc.um;
      LOG_D(RLC, "[FRAME %05d][%s][RRC][MOD %u/%u][][--- CONFIG_REQ timer_reordering=%d sn_field_length=%d is_mXch=%d --->][RLC_UM][MOD %u/%u][RB %u]    \n",
          frameP,
          (eNB_flagP) ? "eNB" : "UE",
gauthier's avatar
gauthier committed
69
70
71
72
73
74
75
76
77
          enb_module_idP,
          ue_module_idP,
          config_um_pP->timer_reordering,
          config_um_pP->sn_field_length,
          config_um_pP->is_mXch,
          enb_module_idP,
          ue_module_idP,
          rb_idP);

78
79
80
81
82
83
84
85
86
87
88
89
      rlc_um_init(rlc_p);
      if (rlc_um_fsm_notify_event (rlc_p, RLC_UM_RECEIVE_CRLC_CONFIG_REQ_ENTER_DATA_TRANSFER_READY_STATE_EVENT)) {
          rlc_um_set_debug_infos(rlc_p, enb_module_idP, ue_module_idP, frameP, eNB_flagP, srb_flagP, rb_idP);
          rlc_um_configure(rlc_p,
              frameP,
              config_um_pP->timer_reordering,
              config_um_pP->sn_field_length,
              config_um_pP->sn_field_length,
              config_um_pP->is_mXch);
      }
  } else {
      LOG_E(RLC, "[FRAME %05d][%s][RRC][MOD %u/%u][][--- CONFIG_REQ --->][RLC_UM][MOD %u/%u][RB %u]  RLC NOT FOUND\n",
90
          frameP,
91
92
93
94
95
96
          (eNB_flagP) ? "eNB" : "UE",
          enb_module_idP,
          ue_module_idP,
          enb_module_idP,
          ue_module_idP,
          rb_idP);  }
97
98
}
//-----------------------------------------------------------------------------
99
const uint32_t const t_Reordering_tab[T_Reordering_spare1] = {0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,110,120,130,140,150,160,170,180,190,200};
100

101
102
103
104
105
106
107
108
109
110
111
112
void config_req_rlc_um_asn1 (
    const module_id_t         enb_module_idP,
    const module_id_t         ue_module_idP,
    const frame_t             frameP,
    const eNB_flag_t          eNB_flagP,
    const srb_flag_t          srb_flagP,
    const MBMS_flag_t         mbms_flagP,
    const mbms_session_id_t   mbms_session_idP,
    const mbms_service_id_t   mbms_service_idP,
    const UL_UM_RLC_t       * const ul_rlc_pP,
    const DL_UM_RLC_t       * const dl_rlc_pP,
    const rb_id_t             rb_idP)
113
{
114
115
116
117
  uint32_t         ul_sn_FieldLength   = 0;
  uint32_t         dl_sn_FieldLength   = 0;
  uint32_t         t_Reordering        = 0;
  rlc_union_t     *rlc_union_p         = NULL;
gauthier's avatar
gauthier committed
118
  rlc_um_entity_t *rlc_p               = NULL;
119
120
121
  hash_key_t       key                 = RLC_COLL_KEY_VALUE(enb_module_idP, ue_module_idP, eNB_flagP, rb_idP, srb_flagP);
  hashtable_rc_t   h_rc;

122
#if defined(Rel10)
gauthier's avatar
gauthier committed
123
  if (mbms_flagP) {
gauthier's avatar
gauthier committed
124
125
      AssertFatal(dl_rlc_pP, "No RLC UM DL config");
      AssertFatal(ul_rlc_pP == NULL, "RLC UM UL config present");
126
      key = RLC_COLL_KEY_MBMS_VALUE(enb_module_idP, ue_module_idP, eNB_flagP, mbms_service_idP, mbms_session_idP);
gauthier's avatar
gauthier committed
127
128
129
130
131
132
133
134
      h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p);
      AssertFatal (h_rc == HASH_TABLE_OK, "RLC NOT FOUND enb id %u ue id %i enb flag %u service id %u, session id %u",
          enb_module_idP,
          ue_module_idP,
          eNB_flagP,
          mbms_service_idP,
          mbms_session_idP);
      rlc_p = &rlc_union_p->rlc.um;
gauthier's avatar
gauthier committed
135
136
137
138
  }
  else
#endif
  {
139
140
141
142
143
144
145
146
147
      key  = RLC_COLL_KEY_VALUE(enb_module_idP, ue_module_idP, eNB_flagP, rb_idP, srb_flagP);
      h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p);
      AssertFatal (h_rc == HASH_TABLE_OK, "RLC NOT FOUND enb id %u ue id %i enb flag %u rb id %u, srb flag %u",
          enb_module_idP,
          ue_module_idP,
          eNB_flagP,
          rb_idP,
          srb_flagP);
      rlc_p = &rlc_union_p->rlc.um;
gauthier's avatar
gauthier committed
148
  }
149
150

  //-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
151
  LOG_D(RLC, "[FRAME %05d][%s][RRC][MOD %u/%u][][--- CONFIG_REQ timer_reordering=%dms sn_field_length=  --->][RLC_UM][MOD %u/%u][RB %u]    \n",
152
      frameP,
gauthier's avatar
gauthier committed
153
      (eNB_flagP) ? "eNB" : "UE",
154
155
156
157
158
159
      enb_module_idP,
      ue_module_idP,
      (dl_rlc_pP->t_Reordering<31)?t_Reordering_tab[dl_rlc_pP->t_Reordering]:-1,
      enb_module_idP,
      ue_module_idP,
      rb_idP);
gauthier's avatar
gauthier committed
160

gauthier's avatar
gauthier committed
161
162
  rlc_um_init(rlc_p);
  if (rlc_um_fsm_notify_event (rlc_p, RLC_UM_RECEIVE_CRLC_CONFIG_REQ_ENTER_DATA_TRANSFER_READY_STATE_EVENT)) {
163
      rlc_um_set_debug_infos(rlc_p, enb_module_idP, ue_module_idP, frameP, eNB_flagP, srb_flagP, rb_idP);
gauthier's avatar
gauthier committed
164
165
      if (ul_rlc_pP != NULL) {
          switch (ul_rlc_pP->sn_FieldLength) {
166
          case SN_FieldLength_size5:
gauthier's avatar
gauthier committed
167
168
            ul_sn_FieldLength = 5;
            break;
169
          case SN_FieldLength_size10:
gauthier's avatar
gauthier committed
170
171
            ul_sn_FieldLength = 10;
            break;
172
          default:
gauthier's avatar
gauthier committed
173
            LOG_E(RLC,"[FRAME %05d][%s][RLC_UM][MOD %u/%u][RB %u][CONFIGURE] INVALID Uplink sn_FieldLength %d, RLC NOT CONFIGURED\n",
174
                frameP,
gauthier's avatar
gauthier committed
175
176
177
178
                (rlc_p->is_enb) ? "eNB" : "UE",
                    rlc_p->enb_module_id,
                    rlc_p->ue_module_id,
                    rlc_p->rb_id,
gauthier's avatar
gauthier committed
179
180
                    ul_rlc_pP->sn_FieldLength);
            return;
181
          }
182
      }
gauthier's avatar
gauthier committed
183
184
185

      if (dl_rlc_pP != NULL) {
          switch (dl_rlc_pP->sn_FieldLength) {
186
          case SN_FieldLength_size5:
gauthier's avatar
gauthier committed
187
188
            dl_sn_FieldLength = 5;
            break;
189
          case SN_FieldLength_size10:
gauthier's avatar
gauthier committed
190
191
            dl_sn_FieldLength = 10;
            break;
192
          default:
gauthier's avatar
gauthier committed
193
            LOG_E(RLC,"[FRAME %05d][%s][RLC_UM][MOD %u/%u][RB %u][CONFIGURE] INVALID Downlink sn_FieldLength %d, RLC NOT CONFIGURED\n",
194
                frameP,
gauthier's avatar
gauthier committed
195
196
197
198
                (rlc_p->is_enb) ? "eNB" : "UE",
                    rlc_p->enb_module_id,
                    rlc_p->ue_module_id,
                    rlc_p->rb_id,
gauthier's avatar
gauthier committed
199
200
                    dl_rlc_pP->sn_FieldLength);
            return;
201
          }
gauthier's avatar
gauthier committed
202
203
          if (dl_rlc_pP->t_Reordering<T_Reordering_spare1) {
              t_Reordering = t_Reordering_tab[dl_rlc_pP->t_Reordering];
204
          } else {
gauthier's avatar
gauthier committed
205
              LOG_E(RLC,"[FRAME %05d][%s][RLC_UM][MOD %u/%u][RB %u][CONFIGURE] INVALID T_Reordering %d, RLC NOT CONFIGURED\n",
206
                  frameP,
gauthier's avatar
gauthier committed
207
208
209
210
                  (rlc_p->is_enb) ? "eNB" : "UE",
                      rlc_p->enb_module_id,
                      rlc_p->ue_module_id,
                      rlc_p->rb_id,
gauthier's avatar
gauthier committed
211
212
                      dl_rlc_pP->t_Reordering);
              return;
213
214
215
          }
      }
      if (eNB_flagP > 0) {
gauthier's avatar
gauthier committed
216
          rlc_um_configure(rlc_p,
217
              frameP,
gauthier's avatar
gauthier committed
218
219
220
221
              t_Reordering,
              ul_sn_FieldLength,
              dl_sn_FieldLength,
              mbms_flagP);
222
      } else {
gauthier's avatar
gauthier committed
223
          rlc_um_configure(rlc_p,
224
              frameP,
gauthier's avatar
gauthier committed
225
226
227
228
              t_Reordering,
              dl_sn_FieldLength,
              ul_sn_FieldLength,
              mbms_flagP);
229
      }
230
231
232
      if (mbms_flagP == MBMS_FLAG_YES) {
          rlc_p->allocation = TRUE;
      }
gauthier's avatar
gauthier committed
233
  }
234
235
236
}
//-----------------------------------------------------------------------------
void
237
rlc_um_init (rlc_um_entity_t * const rlc_pP)
238
{
gauthier's avatar
gauthier committed
239
  //-----------------------------------------------------------------------------
240

gauthier's avatar
gauthier committed
241
  AssertFatal(rlc_pP, "Bad RLC UM pointer (NULL)");
gauthier's avatar
gauthier committed
242
243
244
  int saved_allocation = rlc_pP->allocation;
  memset (rlc_pP, 0, sizeof (rlc_um_entity_t));
  rlc_pP->allocation = saved_allocation;
245
  // TX SIDE
gauthier's avatar
gauthier committed
246
  list_init (&rlc_pP->pdus_to_mac_layer, NULL);
247

gauthier's avatar
gauthier committed
248
249
250
251
  rlc_pP->protocol_state = RLC_NULL_STATE;
  //rlc_pP->nb_sdu           = 0;
  //rlc_pP->next_sdu_index   = 0;
  //rlc_pP->current_sdu_index = 0;
252

gauthier's avatar
gauthier committed
253
  //rlc_pP->vt_us = 0;
254
255

  // RX SIDE
gauthier's avatar
gauthier committed
256
257
258
259
260
261
262
263
264
265
266
  list_init (&rlc_pP->pdus_from_mac_layer, NULL);
  //rlc_pP->vr_ur = 0;
  //rlc_pP->vr_ux = 0;
  //rlc_pP->vr_uh = 0;
  //rlc_pP->output_sdu_size_to_write = 0;
  //rlc_pP->output_sdu_in_construction = NULL;

  rlc_pP->rx_sn_length          = 10;
  rlc_pP->rx_header_min_length_in_bytes = 2;
  rlc_pP->tx_sn_length          = 10;
  rlc_pP->tx_header_min_length_in_bytes = 2;
267
268

  // SPARE : not 3GPP
gauthier's avatar
gauthier committed
269
  rlc_pP->size_input_sdus_buffer =128;
270

271
272
  if ((rlc_pP->input_sdus == NULL) && (rlc_pP->size_input_sdus_buffer > 0)) {
      rlc_pP->input_sdus = calloc(1 , rlc_pP->size_input_sdus_buffer * sizeof (void *));
273
  }
274
275
  if (rlc_pP->dar_buffer == NULL) {
      rlc_pP->dar_buffer = calloc (1, 1024 * sizeof (void *));
276
277
  }

gauthier's avatar
gauthier committed
278
  rlc_pP->first_pdu = 1;
279
280
281
}
//-----------------------------------------------------------------------------
void
282
rlc_um_reset_state_variables (rlc_um_entity_t * const rlc_pP)
283
{
gauthier's avatar
gauthier committed
284
285
286
287
288
  //-----------------------------------------------------------------------------
  rlc_pP->buffer_occupancy = 0;
  rlc_pP->nb_sdu = 0;
  rlc_pP->next_sdu_index = 0;
  rlc_pP->current_sdu_index = 0;
289
290

  // TX SIDE
gauthier's avatar
gauthier committed
291
  rlc_pP->vt_us = 0;
292
  // RX SIDE
gauthier's avatar
gauthier committed
293
294
295
  rlc_pP->vr_ur = 0;
  rlc_pP->vr_ux = 0;
  rlc_pP->vr_uh = 0;
296
297
298
}
//-----------------------------------------------------------------------------
void
299
rlc_um_cleanup (rlc_um_entity_t * const rlc_pP)
300
{
gauthier's avatar
gauthier committed
301
  //-----------------------------------------------------------------------------
302
303
  int             index;
  // TX SIDE
gauthier's avatar
gauthier committed
304
  list_free (&rlc_pP->pdus_to_mac_layer);
305

306
  if (rlc_pP->input_sdus) {
gauthier's avatar
gauthier committed
307
308
309
310
      for (index = 0; index < rlc_pP->size_input_sdus_buffer; index++) {
          if (rlc_pP->input_sdus[index]) {
              free_mem_block (rlc_pP->input_sdus[index]);
          }
311
      }
312
313
      free (rlc_pP->input_sdus);
      rlc_pP->input_sdus = NULL;
314
315
  }
  // RX SIDE
gauthier's avatar
gauthier committed
316
317
318
  list_free (&rlc_pP->pdus_from_mac_layer);
  if ((rlc_pP->output_sdu_in_construction)) {
      free_mem_block (rlc_pP->output_sdu_in_construction);
319
  }
320
  if (rlc_pP->dar_buffer) {
gauthier's avatar
gauthier committed
321
322
323
324
      for (index = 0; index < 1024; index++) {
          if (rlc_pP->dar_buffer[index]) {
              free_mem_block (rlc_pP->dar_buffer[index]);
          }
325
      }
326
327
      free (rlc_pP->dar_buffer);
      rlc_pP->dar_buffer = NULL;
328
  }
gauthier's avatar
gauthier committed
329
  memset(rlc_pP, 0, sizeof(rlc_um_entity_t));
330
331
332
}

//-----------------------------------------------------------------------------
333
334
335
336
337
338
339
void rlc_um_configure(
    rlc_um_entity_t * const rlc_pP,
    const frame_t          frameP,
    const uint32_t         timer_reorderingP,
    const uint32_t         rx_sn_field_lengthP,
    const uint32_t         tx_sn_field_lengthP,
    const uint32_t         is_mXchP)
340
341
//-----------------------------------------------------------------------------
{
gauthier's avatar
gauthier committed
342
343
344
345
346
347
348
349
350
351
352
353
  if (rx_sn_field_lengthP == 10) {
      rlc_pP->rx_sn_length                  = 10;
      rlc_pP->rx_sn_modulo                  = RLC_UM_SN_10_BITS_MODULO;
      rlc_pP->rx_um_window_size             = RLC_UM_WINDOW_SIZE_SN_10_BITS;
      rlc_pP->rx_header_min_length_in_bytes = 2;
  } else if (rx_sn_field_lengthP == 5) {
      rlc_pP->rx_sn_length                  = 5;
      rlc_pP->rx_sn_modulo                  = RLC_UM_SN_5_BITS_MODULO;
      rlc_pP->rx_um_window_size             = RLC_UM_WINDOW_SIZE_SN_5_BITS;
      rlc_pP->rx_header_min_length_in_bytes = 1;
  } else if (rx_sn_field_lengthP != 0) {
      LOG_E(RLC, "[FRAME %05d][%s][RLC_UM][MOD %u/%u][RB %u][CONFIGURE] INVALID RX SN LENGTH %d BITS NOT IMPLEMENTED YET, RLC NOT CONFIGURED\n",
354
          frameP,
gauthier's avatar
gauthier committed
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
          (rlc_pP->is_enb) ? "eNB" : "UE",
              rlc_pP->enb_module_id,
              rlc_pP->ue_module_id,
              rlc_pP->rb_id,
              rx_sn_field_lengthP);
      return;
  }

  if (tx_sn_field_lengthP == 10) {
      rlc_pP->tx_sn_length                  = 10;
      rlc_pP->tx_sn_modulo                  = RLC_UM_SN_10_BITS_MODULO;
      rlc_pP->tx_um_window_size             = RLC_UM_WINDOW_SIZE_SN_10_BITS;
      rlc_pP->tx_header_min_length_in_bytes = 2;
  } else if (tx_sn_field_lengthP == 5) {
      rlc_pP->tx_sn_length                  = 5;
      rlc_pP->tx_sn_modulo                  = RLC_UM_SN_5_BITS_MODULO;
      rlc_pP->tx_um_window_size             = RLC_UM_WINDOW_SIZE_SN_5_BITS;
      rlc_pP->tx_header_min_length_in_bytes = 1;
  } else if (tx_sn_field_lengthP != 0) {
      LOG_E(RLC, "[FRAME %05d][%s][RLC_UM][MOD %02d/%02][RB %u][CONFIGURE] INVALID RX SN LENGTH %d BITS NOT IMPLEMENTED YET, RLC NOT CONFIGURED\n",
375
          frameP,
gauthier's avatar
gauthier committed
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
          (rlc_pP->is_enb) ? "eNB" : "UE",
              rlc_pP->enb_module_id,
              rlc_pP->ue_module_id,
              rlc_pP->rb_id,
              tx_sn_field_lengthP);
      return;
  }

  if (is_mXchP > 0) {
      rlc_pP->tx_um_window_size = 0;
      rlc_pP->rx_um_window_size = 0;
  }
  rlc_pP->is_mxch = is_mXchP;

  rlc_pP->last_reassemblied_sn  = rlc_pP->rx_sn_modulo - 1;
  rlc_pP->last_reassemblied_missing_sn  = rlc_pP->rx_sn_modulo - 1;
  rlc_pP->reassembly_missing_sn_detected = 0;
  // timers
  rlc_um_init_timer_reordering(rlc_pP, timer_reorderingP);

  rlc_pP->first_pdu = 1;

  rlc_um_reset_state_variables (rlc_pP);
399
400
}
//-----------------------------------------------------------------------------
401
402
403
404
405
406
407
408
void rlc_um_set_debug_infos(
    rlc_um_entity_t *rlc_pP,
    const module_id_t      enb_module_idP,
    const module_id_t      ue_module_idP,
    const frame_t          frameP,
    const eNB_flag_t       eNB_flagP,
    const srb_flag_t       srb_flagP,
    const rb_id_t          rb_idP)
409
410
//-----------------------------------------------------------------------------
{
411
  LOG_D(RLC, "[FRAME %05d][%s][RLC_UM][SET DEBUG INFOS] enb_module_id %u ue_module_id %u rb_id %d srb_flag %d\n",
412
      frameP,
413
414
415
416
      (eNB_flagP) ? "eNB" : "UE",
      enb_module_idP,
      ue_module_idP,
      rb_idP,
417
      srb_flagP);
gauthier's avatar
gauthier committed
418
419
420

  rlc_pP->enb_module_id = enb_module_idP;
  rlc_pP->ue_module_id  = ue_module_idP;
421
  rlc_pP->rb_id         = rb_idP;
422
  if (srb_flagP) {
gauthier's avatar
gauthier committed
423
      rlc_pP->is_data_plane = 0;
424
425
  } else {
      rlc_pP->is_data_plane = 1;
gauthier's avatar
gauthier committed
426
427
  }
  rlc_pP->is_enb = eNB_flagP;
428
}