rlc.c 27.3 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 21
 * 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
 */

Lionel Gauthier's avatar
Lionel Gauthier committed
22 23 24 25 26 27 28
/*
                                rlc.c
                             -------------------
  AUTHOR  : Lionel GAUTHIER
  COMPANY : EURECOM
  EMAIL   : Lionel.Gauthier at eurecom dot fr
*/
29 30 31
#define RLC_C
#include "rlc.h"
#include "mem_block.h"
32
#include "../MAC/mac_extern.h"
laurent's avatar
laurent committed
33
#include "LAYER2/RLC/UM_v9.3.0/rlc_um.h"
34
#include "common/utils/LOG/log.h"
35
#include "UTIL/OCG/OCG_vars.h"
36
#include "common/utils/LOG/vcd_signal_dumper.h"
Y_Tomita's avatar
Y_Tomita committed
37
#include "targets/COMMON/openairinterface5g_limits.h"
38 39
#include "assertions.h"

40 41
#include "common/ran_context.h"
extern RAN_CONTEXT_t RC;
42

43
extern boolean_t pdcp_data_ind(
44
  const protocol_ctxt_t *const ctxt_pP,
45 46 47 48
  const srb_flag_t srb_flagP,
  const MBMS_flag_t MBMS_flagP,
  const rb_id_t rb_idP,
  const sdu_size_t sdu_buffer_sizeP,
49
  mem_block_t *const sdu_buffer_pP);
50

Lionel Gauthier's avatar
 
Lionel Gauthier committed
51
#define DEBUG_RLC_PDCP_INTERFACE 1
52
//#define TRACE_RLC_PAYLOAD 1
53
#define DEBUG_RLC_DATA_REQ 1
54 55

//-----------------------------------------------------------------------------
56
void rlc_util_print_hex_octets(comp_name_t componentP, unsigned char *dataP, const signed long sizeP)
57 58 59 60 61 62 63 64
//-----------------------------------------------------------------------------
{
  unsigned long octet_index = 0;

  if (dataP == NULL) {
    return;
  }

65 66 67
  LOG_T(componentP, "+-----+-------------------------------------------------+\n");
  LOG_T(componentP, "|     |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
  LOG_T(componentP, "+-----+-------------------------------------------------+\n");
68

69
  for (octet_index = 0; octet_index < sizeP; octet_index++) {
70
    if ((octet_index % 16) == 0) {
71
      if (octet_index != 0) {
72
        LOG_T(componentP, " |\n");
73
      }
74

Cedric Roux's avatar
Cedric Roux committed
75
      LOG_T(componentP, " %04lu |", octet_index);
76
    }
77

78 79 80 81 82 83 84 85 86 87 88 89 90
    /*
     * Print every single octet in hexadecimal form
     */
    LOG_T(componentP, " %02x", dataP[octet_index]);
    /*
     * Align newline and pipes according to the octets in groups of 2
     */
  }

  /*
   * Append enough spaces and put final pipe
   */
  unsigned char index;
91

92
  for (index = octet_index; index < 16; ++index) {
93
    LOG_T(componentP, "   ");
94
  }
95

96 97
  LOG_T(componentP, " |\n");
}
98

99
//-----------------------------------------------------------------------------
100
rlc_op_status_t rlc_stat_req     (
101
  const protocol_ctxt_t *const ctxt_pP,
102 103
  const srb_flag_t    srb_flagP,
  const rb_id_t       rb_idP,
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
  unsigned int *stat_rlc_mode,
  unsigned int *stat_tx_pdcp_sdu,
  unsigned int *stat_tx_pdcp_bytes,
  unsigned int *stat_tx_pdcp_sdu_discarded,
  unsigned int *stat_tx_pdcp_bytes_discarded,
  unsigned int *stat_tx_data_pdu,
  unsigned int *stat_tx_data_bytes,
  unsigned int *stat_tx_retransmit_pdu_by_status,
  unsigned int *stat_tx_retransmit_bytes_by_status,
  unsigned int *stat_tx_retransmit_pdu,
  unsigned int *stat_tx_retransmit_bytes,
  unsigned int *stat_tx_control_pdu,
  unsigned int *stat_tx_control_bytes,
  unsigned int *stat_rx_pdcp_sdu,
  unsigned int *stat_rx_pdcp_bytes,
  unsigned int *stat_rx_data_pdus_duplicate,
  unsigned int *stat_rx_data_bytes_duplicate,
  unsigned int *stat_rx_data_pdu,
  unsigned int *stat_rx_data_bytes,
  unsigned int *stat_rx_data_pdu_dropped,
  unsigned int *stat_rx_data_bytes_dropped,
  unsigned int *stat_rx_data_pdu_out_of_window,
  unsigned int *stat_rx_data_bytes_out_of_window,
  unsigned int *stat_rx_control_pdu,
  unsigned int *stat_rx_control_bytes,
  unsigned int *stat_timer_reordering_timed_out,
  unsigned int *stat_timer_poll_retransmit_timed_out,
  unsigned int *stat_timer_status_prohibit_timed_out) {
132 133 134
  //-----------------------------------------------------------------------------
  rlc_mode_t             rlc_mode        = RLC_MODE_NONE;
  rlc_union_t           *rlc_union_p     = NULL;
135
  hash_key_t             key             = HASHTABLE_NOT_A_KEY_VALUE;
136
  hashtable_rc_t         h_rc;
137

teramoto.genki's avatar
teramoto.genki committed
138
  //AssertFatal (rb_idP < NB_RB_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
139
  if(rb_idP >= NB_RB_MAX) {
laurent's avatar
laurent committed
140
    LOG_E(RLC, "RB id is too high (%ld/%d)!\n", rb_idP, NB_RB_MAX);
141 142 143
    return RLC_OP_STATUS_BAD_PARAMETER;
  }

144
  key = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
145
  h_rc = hashtable_get(rlc_coll_p, key, (void **)&rlc_union_p);
146 147 148 149

  if (h_rc == HASH_TABLE_OK) {
    rlc_mode = rlc_union_p->mode;
  }
150

151
  *stat_rlc_mode                     = rlc_mode;
152

153
  switch (rlc_mode) {
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 225 226 227 228 229 230 231 232 233 234 235 236 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
    case RLC_MODE_NONE:
      *stat_tx_pdcp_sdu                     = 0;
      *stat_tx_pdcp_bytes                   = 0;
      *stat_tx_pdcp_sdu_discarded           = 0;
      *stat_tx_pdcp_bytes_discarded         = 0;
      *stat_tx_data_pdu                     = 0;
      *stat_tx_data_bytes                   = 0;
      *stat_tx_retransmit_pdu_by_status     = 0;
      *stat_tx_retransmit_bytes_by_status   = 0;
      *stat_tx_retransmit_pdu               = 0;
      *stat_tx_retransmit_bytes             = 0;
      *stat_tx_control_pdu                  = 0;
      *stat_tx_control_bytes                = 0;
      *stat_rx_pdcp_sdu                     = 0;
      *stat_rx_pdcp_bytes                   = 0;
      *stat_rx_data_pdus_duplicate          = 0;
      *stat_rx_data_bytes_duplicate         = 0;
      *stat_rx_data_pdu                     = 0;
      *stat_rx_data_bytes                   = 0;
      *stat_rx_data_pdu_dropped             = 0;
      *stat_rx_data_bytes_dropped           = 0;
      *stat_rx_data_pdu_out_of_window       = 0;
      *stat_rx_data_bytes_out_of_window     = 0;
      *stat_rx_control_pdu                  = 0;
      *stat_rx_control_bytes                = 0;
      *stat_timer_reordering_timed_out      = 0;
      *stat_timer_poll_retransmit_timed_out = 0;
      *stat_timer_status_prohibit_timed_out = 0;
      return RLC_OP_STATUS_BAD_PARAMETER;
      break;

    case RLC_MODE_AM:
      rlc_am_stat_req(ctxt_pP,
                      &rlc_union_p->rlc.am,
                      stat_tx_pdcp_sdu,
                      stat_tx_pdcp_bytes,
                      stat_tx_pdcp_sdu_discarded,
                      stat_tx_pdcp_bytes_discarded,
                      stat_tx_data_pdu,
                      stat_tx_data_bytes,
                      stat_tx_retransmit_pdu_by_status,
                      stat_tx_retransmit_bytes_by_status,
                      stat_tx_retransmit_pdu,
                      stat_tx_retransmit_bytes,
                      stat_tx_control_pdu,
                      stat_tx_control_bytes,
                      stat_rx_pdcp_sdu,
                      stat_rx_pdcp_bytes,
                      stat_rx_data_pdus_duplicate,
                      stat_rx_data_bytes_duplicate,
                      stat_rx_data_pdu,
                      stat_rx_data_bytes,
                      stat_rx_data_pdu_dropped,
                      stat_rx_data_bytes_dropped,
                      stat_rx_data_pdu_out_of_window,
                      stat_rx_data_bytes_out_of_window,
                      stat_rx_control_pdu,
                      stat_rx_control_bytes,
                      stat_timer_reordering_timed_out,
                      stat_timer_poll_retransmit_timed_out,
                      stat_timer_status_prohibit_timed_out);
      return RLC_OP_STATUS_OK;
      break;

    case RLC_MODE_UM:
      *stat_tx_retransmit_pdu_by_status     = 0;
      *stat_tx_retransmit_bytes_by_status   = 0;
      *stat_tx_retransmit_pdu               = 0;
      *stat_tx_retransmit_bytes             = 0;
      *stat_tx_control_pdu                  = 0;
      *stat_tx_control_bytes                = 0;
      *stat_rx_data_pdu_dropped             = 0;
      *stat_rx_data_bytes_dropped           = 0;
      *stat_rx_data_pdu_out_of_window       = 0;
      *stat_rx_data_bytes_out_of_window     = 0;
      *stat_timer_poll_retransmit_timed_out = 0;
      *stat_timer_status_prohibit_timed_out = 0;
      rlc_um_stat_req (&rlc_union_p->rlc.um,
                       stat_tx_pdcp_sdu,
                       stat_tx_pdcp_bytes,
                       stat_tx_pdcp_sdu_discarded,
                       stat_tx_pdcp_bytes_discarded,
                       stat_tx_data_pdu,
                       stat_tx_data_bytes,
                       stat_rx_pdcp_sdu,
                       stat_rx_pdcp_bytes,
                       stat_rx_data_pdus_duplicate,
                       stat_rx_data_bytes_duplicate,
                       stat_rx_data_pdu,
                       stat_rx_data_bytes,
                       stat_rx_data_pdu_dropped,
                       stat_rx_data_bytes_dropped,
                       stat_rx_data_pdu_out_of_window,
                       stat_rx_data_bytes_out_of_window,
                       stat_timer_reordering_timed_out);
      return RLC_OP_STATUS_OK;
      break;

    case RLC_MODE_TM:
      *stat_tx_pdcp_sdu                     = 0;
      *stat_tx_pdcp_bytes                   = 0;
      *stat_tx_pdcp_sdu_discarded           = 0;
      *stat_tx_pdcp_bytes_discarded         = 0;
      *stat_tx_data_pdu                     = 0;
      *stat_tx_data_bytes                   = 0;
      *stat_tx_retransmit_pdu_by_status     = 0;
      *stat_tx_retransmit_bytes_by_status   = 0;
      *stat_tx_retransmit_pdu               = 0;
      *stat_tx_retransmit_bytes             = 0;
      *stat_tx_control_pdu                  = 0;
      *stat_tx_control_bytes                = 0;
      *stat_rx_pdcp_sdu                     = 0;
      *stat_rx_pdcp_bytes                   = 0;
      *stat_rx_data_pdus_duplicate          = 0;
      *stat_rx_data_bytes_duplicate         = 0;
      *stat_rx_data_pdu                     = 0;
      *stat_rx_data_bytes                   = 0;
      *stat_rx_data_pdu_dropped             = 0;
      *stat_rx_data_bytes_dropped           = 0;
      *stat_rx_data_pdu_out_of_window       = 0;
      *stat_rx_data_bytes_out_of_window     = 0;
      *stat_rx_control_pdu                  = 0;
      *stat_rx_control_bytes                = 0;
      *stat_timer_reordering_timed_out      = 0;
      *stat_timer_poll_retransmit_timed_out = 0;
      *stat_timer_status_prohibit_timed_out = 0;
      return RLC_OP_STATUS_BAD_PARAMETER;
      break;

    default:
      *stat_tx_pdcp_sdu                     = 0;
      *stat_tx_pdcp_bytes                   = 0;
      *stat_tx_pdcp_sdu_discarded           = 0;
      *stat_tx_pdcp_bytes_discarded         = 0;
      *stat_tx_data_pdu                     = 0;
      *stat_tx_data_bytes                   = 0;
      *stat_tx_retransmit_pdu_by_status     = 0;
      *stat_tx_retransmit_bytes_by_status   = 0;
      *stat_tx_retransmit_pdu               = 0;
      *stat_tx_retransmit_bytes             = 0;
      *stat_tx_control_pdu                  = 0;
      *stat_tx_control_bytes                = 0;
      *stat_rx_pdcp_sdu                     = 0;
      *stat_rx_pdcp_bytes                   = 0;
      *stat_rx_data_pdus_duplicate          = 0;
      *stat_rx_data_bytes_duplicate         = 0;
      *stat_rx_data_pdu                     = 0;
      *stat_rx_data_bytes                   = 0;
      *stat_rx_data_pdu_dropped             = 0;
      *stat_rx_data_bytes_dropped           = 0;
      *stat_rx_data_pdu_out_of_window       = 0;
      *stat_rx_data_bytes_out_of_window     = 0;
      *stat_rx_control_pdu                  = 0;
      *stat_rx_control_bytes                = 0;
      *stat_timer_poll_retransmit_timed_out = 0;
      *stat_timer_status_prohibit_timed_out = 0;
      return RLC_OP_STATUS_BAD_PARAMETER;
311
  }
312
}
313

314
//-----------------------------------------------------------------------------
315
rlc_op_status_t rlc_data_req     (const protocol_ctxt_t *const ctxt_pP,
316 317 318 319
                                  const srb_flag_t   srb_flagP,
                                  const MBMS_flag_t  MBMS_flagP,
                                  const rb_id_t      rb_idP,
                                  const mui_t        muiP,
320 321
                                  confirm_t    confirmP,
                                  sdu_size_t   sdu_sizeP,
322 323 324
                                  mem_block_t *sdu_pP,
                                  const uint32_t *const sourceL2Id,
                                  const uint32_t *const destinationL2Id
325
                                 ) {
326
  //-----------------------------------------------------------------------------
327
  mem_block_t           *new_sdu_p    = NULL;
Lionel Gauthier's avatar
Lionel Gauthier committed
328
  rlc_mode_t             rlc_mode     = RLC_MODE_NONE;
329
  rlc_union_t           *rlc_union_p = NULL;
330
  hash_key_t             key         = HASHTABLE_NOT_A_KEY_VALUE;
331
  hashtable_rc_t         h_rc;
332 333
  rlc_mbms_id_t         *mbms_id_p  = NULL;
  logical_chan_id_t      log_ch_id  = 0;
334
#ifdef DEBUG_RLC_DATA_REQ
laurent's avatar
laurent committed
335
  LOG_D(RLC,PROTOCOL_CTXT_FMT"rlc_data_req:  rb_id %ld (MAX %d), muip %d, confirmP %d, sdu_sizeP %d, sdu_pP %p\n",
336
        PROTOCOL_CTXT_ARGS(ctxt_pP),
337 338 339 340 341 342
        rb_idP,
        NB_RAB_MAX,
        muiP,
        confirmP,
        sdu_sizeP,
        sdu_pP);
343
#endif
Cedric Roux's avatar
Cedric Roux committed
344
#if T_TRACER
345

Cedric Roux's avatar
Cedric Roux committed
346 347
  if (ctxt_pP->enb_flag)
    T(T_ENB_RLC_DL, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->rnti), T_INT(rb_idP), T_INT(sdu_sizeP));
348

Cedric Roux's avatar
Cedric Roux committed
349 350
#endif

351
  if (MBMS_flagP) {
teramoto.genki's avatar
teramoto.genki committed
352
    //AssertFatal (rb_idP < NB_RB_MBMS_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MBMS_MAX);
353
    if(rb_idP >= NB_RB_MBMS_MAX) {
laurent's avatar
laurent committed
354
      LOG_E(RLC, "RB id is too high (%ld/%d)!\n", rb_idP, NB_RB_MBMS_MAX);
355 356
      return RLC_OP_STATUS_BAD_PARAMETER;
    }
357
  } else {
teramoto.genki's avatar
teramoto.genki committed
358
    //AssertFatal (rb_idP < NB_RB_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
359
    if(rb_idP >= NB_RB_MAX) {
laurent's avatar
laurent committed
360
      LOG_E(RLC, "RB id is too high (%ld/%d)!\n", rb_idP, NB_RB_MAX);
361 362
      return RLC_OP_STATUS_BAD_PARAMETER;
    }
363
  }
364

teramoto.genki's avatar
teramoto.genki committed
365
  //DevAssert(sdu_pP != NULL);
366 367 368 369 370
  if(sdu_pP == NULL) {
    LOG_E(RLC, "sdu_pP == NULL\n");
    return RLC_OP_STATUS_BAD_PARAMETER;
  }

Haruki NAOI's avatar
Haruki NAOI committed
371 372
  //DevCheck(sdu_sizeP > 0, sdu_sizeP, 0, 0);
  if(sdu_sizeP <= 0) {
373
    LOG_E(RLC, "sdu_sizeP %d, file %s, line %d\n", sdu_sizeP, __FILE__,__LINE__);
Haruki NAOI's avatar
Haruki NAOI committed
374 375
    return RLC_OP_STATUS_BAD_PARAMETER;
  }
376

377
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_IN);
378

379
  if (MBMS_flagP == TRUE) {
380 381 382
    if (ctxt_pP->enb_flag) {
      log_ch_id = rlc_mbms_enb_get_lcid_by_rb_id(ctxt_pP->module_id,rb_idP);
      mbms_id_p = &rlc_mbms_lcid2service_session_id_eNB[ctxt_pP->module_id][log_ch_id];
383
    } else {
384 385
      log_ch_id = rlc_mbms_ue_get_lcid_by_rb_id(ctxt_pP->rnti,rb_idP);
      mbms_id_p = &rlc_mbms_lcid2service_session_id_ue[ctxt_pP->rnti][log_ch_id];
386 387
    }

388
    key = RLC_COLL_KEY_MBMS_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, mbms_id_p->service_id, mbms_id_p->session_id);
389
  } else if (sourceL2Id && destinationL2Id) {
laurent's avatar
laurent committed
390
    LOG_D (RLC, "RLC_COLL_KEY_VALUE: ctxt_pP->module_id: %d, ctxt_pP->rnti: %d, ctxt_pP->enb_flag: %d, rb_idP:%ld, srb_flagP: %d \n \n", ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP,
391 392 393 394 395
           srb_flagP);
    key = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
    //Thinh's line originally uncommented
    //key = RLC_COLL_KEY_SOURCE_DEST_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, *sourceL2Id, *destinationL2Id, srb_flagP);
    //key_lcid = RLC_COLL_KEY_LCID_SOURCE_DEST_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, chan_idP, *sourceL2Id, *destinationL2Id, srb_flagP);
396
  } else {
laurent's avatar
laurent committed
397
    LOG_D (RLC, "RLC_COLL_KEY_VALUE: ctxt_pP->module_id: %d, ctxt_pP->rnti: %d, ctxt_pP->enb_flag: %d, rb_idP:%ld, srb_flagP: %d \n \n", ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP,
398
           srb_flagP);
399
    key = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
400 401
  }

402
  h_rc = hashtable_get(rlc_coll_p, key, (void **)&rlc_union_p);
403

404
  if (h_rc == HASH_TABLE_OK) {
405
    rlc_mode = rlc_union_p->mode;
406
  } else {
407
    rlc_mode = RLC_MODE_NONE;
teramoto.genki's avatar
teramoto.genki committed
408
    //AssertFatal (0 , "RLC not configured key %ju\n", key);
409 410
    LOG_E(RLC, "not configured key %lu\n", key);
    return RLC_OP_STATUS_OUT_OF_RESSOURCES;
411 412
  }

413
  if (MBMS_flagP == 0) {
laurent's avatar
laurent committed
414
    LOG_D(RLC, PROTOCOL_CTXT_FMT"[RB %ld] Display of rlc_data_req:\n",
415
          PROTOCOL_CTXT_ARGS(ctxt_pP),
416
          rb_idP);
417
#if defined(TRACE_RLC_PAYLOAD)
418
    rlc_util_print_hex_octets(RLC, (unsigned char *)sdu_pP->data, sdu_sizeP);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
419
#endif
420
#ifdef DEBUG_RLC_DATA_REQ
Cedric Roux's avatar
typo  
Cedric Roux committed
421
    LOG_D(RLC,"RLC_TYPE : %d\n", rlc_mode);
422
#endif
423 424

    switch (rlc_mode) {
425 426
      case RLC_MODE_NONE:
        free_mem_block(sdu_pP, __func__);
laurent's avatar
laurent committed
427
        LOG_E(RLC, PROTOCOL_CTXT_FMT" Received RLC_MODE_NONE as rlc_type for rb_id %ld\n",
428 429 430 431
              PROTOCOL_CTXT_ARGS(ctxt_pP),
              rb_idP);
        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
        return RLC_OP_STATUS_BAD_PARAMETER;
432

433
      case RLC_MODE_AM:
434
#ifdef DEBUG_RLC_DATA_REQ
435
        LOG_D(RLC,"RLC_MODE_AM\n");
436
#endif
437
        new_sdu_p = get_free_mem_block (sdu_sizeP + sizeof (struct rlc_am_data_req_alloc), __func__);
438

439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
        if (new_sdu_p != NULL) {
          // PROCESS OF COMPRESSION HERE:
          memset (new_sdu_p->data, 0, sizeof (struct rlc_am_data_req_alloc));
          memcpy (&new_sdu_p->data[sizeof (struct rlc_am_data_req_alloc)], &sdu_pP->data[0], sdu_sizeP);
          ((struct rlc_am_data_req *) (new_sdu_p->data))->data_size = sdu_sizeP;
          ((struct rlc_am_data_req *) (new_sdu_p->data))->conf = confirmP;
          ((struct rlc_am_data_req *) (new_sdu_p->data))->mui  = muiP;
          ((struct rlc_am_data_req *) (new_sdu_p->data))->data_offset = sizeof (struct rlc_am_data_req_alloc);
          free_mem_block(sdu_pP, __func__);
          rlc_am_data_req(ctxt_pP, &rlc_union_p->rlc.am, new_sdu_p);
          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
          return RLC_OP_STATUS_OK;
        } else {
          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
          free_mem_block(sdu_pP, __func__);
          return RLC_OP_STATUS_INTERNAL_ERROR;
        }
456

457
        break;
458

459
      case RLC_MODE_UM:
460

461 462 463 464 465 466 467 468
        /* TODO: this is a hack, needs better solution. Let's not use too
         * much memory and store at maximum 5 millions bytes.
         */
        /* look for HACK_RLC_UM_LIMIT for others places related to the hack. Please do not remove this comment. */
        if (rlc_um_get_buffer_occupancy(&rlc_union_p->rlc.um) > 5000000) {
          free_mem_block(sdu_pP, __func__);
          return RLC_OP_STATUS_OUT_OF_RESSOURCES;
        }
469

470
        new_sdu_p = get_free_mem_block (sdu_sizeP + sizeof (struct rlc_um_data_req_alloc), __func__);
471

472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
        if (new_sdu_p != NULL) {
          // PROCESS OF COMPRESSION HERE:
          memset (new_sdu_p->data, 0, sizeof (struct rlc_um_data_req_alloc));
          memcpy (&new_sdu_p->data[sizeof (struct rlc_um_data_req_alloc)], &sdu_pP->data[0], sdu_sizeP);
          ((struct rlc_um_data_req *) (new_sdu_p->data))->data_size = sdu_sizeP;
          ((struct rlc_um_data_req *) (new_sdu_p->data))->data_offset = sizeof (struct rlc_um_data_req_alloc);
          free_mem_block(sdu_pP, __func__);
          rlc_um_data_req(ctxt_pP, &rlc_union_p->rlc.um, new_sdu_p);
          //free_mem_block(new_sdu, __func__);
          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
          return RLC_OP_STATUS_OK;
        } else {
          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
          free_mem_block(sdu_pP, __func__);
          return RLC_OP_STATUS_INTERNAL_ERROR;
        }
488

489
        break;
490

491 492
      case RLC_MODE_TM:
        new_sdu_p = get_free_mem_block (sdu_sizeP + sizeof (struct rlc_tm_data_req_alloc), __func__);
493

494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
        if (new_sdu_p != NULL) {
          // PROCESS OF COMPRESSION HERE:
          memset (new_sdu_p->data, 0, sizeof (struct rlc_tm_data_req_alloc));
          memcpy (&new_sdu_p->data[sizeof (struct rlc_tm_data_req_alloc)], &sdu_pP->data[0], sdu_sizeP);
          ((struct rlc_tm_data_req *) (new_sdu_p->data))->data_size = sdu_sizeP;
          ((struct rlc_tm_data_req *) (new_sdu_p->data))->data_offset = sizeof (struct rlc_tm_data_req_alloc);
          free_mem_block(sdu_pP, __func__);
          rlc_tm_data_req(ctxt_pP, &rlc_union_p->rlc.tm, new_sdu_p);
          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
          return RLC_OP_STATUS_OK;
        } else {
          //handle_event(ERROR,"FILE %s FONCTION rlc_data_req() LINE %s : out of memory\n", __FILE__, __LINE__);
          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
          free_mem_block(sdu_pP, __func__);
          return RLC_OP_STATUS_INTERNAL_ERROR;
        }
510

511
        break;
512

513
      default:
514
        free_mem_block(sdu_pP, __func__);
515
        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
516 517
        return RLC_OP_STATUS_INTERNAL_ERROR;
    }
518
  } else { /* MBMS_flag != 0 */
519 520 521 522
    //  LOG_I(RLC,"DUY rlc_data_req: mbms_rb_id in RLC instant is: %d\n", mbms_rb_id);
    if (sdu_pP != NULL) {
      if (sdu_sizeP > 0) {
        LOG_I(RLC,"received a packet with size %d for MBMS \n", sdu_sizeP);
523
        new_sdu_p = get_free_mem_block (sdu_sizeP + sizeof (struct rlc_um_data_req_alloc), __func__);
524 525 526 527 528 529 530

        if (new_sdu_p != NULL) {
          // PROCESS OF COMPRESSION HERE:
          memset (new_sdu_p->data, 0, sizeof (struct rlc_um_data_req_alloc));
          memcpy (&new_sdu_p->data[sizeof (struct rlc_um_data_req_alloc)], &sdu_pP->data[0], sdu_sizeP);
          ((struct rlc_um_data_req *) (new_sdu_p->data))->data_size = sdu_sizeP;
          ((struct rlc_um_data_req *) (new_sdu_p->data))->data_offset = sizeof (struct rlc_um_data_req_alloc);
531
          free_mem_block(sdu_pP, __func__);
532
          rlc_um_data_req(ctxt_pP, &rlc_union_p->rlc.um, new_sdu_p);
533
          //free_mem_block(new_sdu, __func__);
534
          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
535 536
          return RLC_OP_STATUS_OK;
        } else {
537
          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
538
          free_mem_block(sdu_pP, __func__);
539 540 541
          return RLC_OP_STATUS_BAD_PARAMETER;
        }
      } else {
542
        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
543 544 545
        return RLC_OP_STATUS_BAD_PARAMETER;
      }
    } else {
546
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
547 548
      return RLC_OP_STATUS_BAD_PARAMETER;
    }
549
  }
550 551 552
}

//-----------------------------------------------------------------------------
553
void rlc_data_ind     (
554
  const protocol_ctxt_t *const ctxt_pP,
555 556 557 558
  const srb_flag_t  srb_flagP,
  const MBMS_flag_t MBMS_flagP,
  const rb_id_t     rb_idP,
  const sdu_size_t  sdu_sizeP,
559
  mem_block_t      *sdu_pP) {
560
  //-----------------------------------------------------------------------------
laurent's avatar
laurent committed
561
  LOG_D(RLC, PROTOCOL_CTXT_FMT"[%s %ld] Display of rlc_data_ind: size %u\n",
562
        PROTOCOL_CTXT_ARGS(ctxt_pP),
563
        (srb_flagP) ? "SRB" : "DRB",
564 565
        rb_idP,
        sdu_sizeP);
566 567
  rlc_util_print_hex_octets(RLC, (unsigned char *)sdu_pP->data, sdu_sizeP);

frtabu's avatar
frtabu committed
568 569
  if (ctxt_pP->enb_flag) {
#if T_TRACER
Cedric Roux's avatar
Cedric Roux committed
570
    T(T_ENB_RLC_UL, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->rnti), T_INT(rb_idP), T_INT(sdu_sizeP));
571
#endif
frtabu's avatar
frtabu committed
572 573 574 575 576 577 578 579 580 581 582 583 584 585
    const ngran_node_t type = RC.rrc[ctxt_pP->module_id]->node_type;
    AssertFatal(type != ngran_eNB_CU && type != ngran_ng_eNB_CU && type != ngran_gNB_CU,
                "Can't be CU, bad node type %d\n", type);

    if (NODE_IS_DU(type) && srb_flagP == 1) {
      MessageDef *msg = itti_alloc_new_message(TASK_RLC_ENB, F1AP_UL_RRC_MESSAGE);
      F1AP_UL_RRC_MESSAGE(msg).rnti = ctxt_pP->rnti;
      F1AP_UL_RRC_MESSAGE(msg).srb_id = rb_idP;
      F1AP_UL_RRC_MESSAGE(msg).rrc_container = sdu_pP->data;
      F1AP_UL_RRC_MESSAGE(msg).rrc_container_length = sdu_sizeP;
      itti_send_msg_to_task(TASK_DU_F1, ENB_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id), msg);
      return;
    }
  } // case monolithic eNodeB or UE
586

frtabu's avatar
frtabu committed
587
  get_pdcp_data_ind_func()(ctxt_pP, srb_flagP, MBMS_flagP, rb_idP, sdu_sizeP, sdu_pP,NULL,NULL);
588 589
}
//-----------------------------------------------------------------------------
590
void rlc_data_conf     (const protocol_ctxt_t *const ctxt_pP,
591 592 593
                        const srb_flag_t      srb_flagP,
                        const rb_id_t         rb_idP,
                        const mui_t           muiP,
594
                        const rlc_tx_status_t statusP) {
595 596 597
  //-----------------------------------------------------------------------------
  if (srb_flagP) {
    if (rlc_rrc_data_conf != NULL) {
598
      rlc_rrc_data_conf (ctxt_pP, rb_idP, muiP, statusP);
599
    }
600
  }
601 602 603
}
//-----------------------------------------------------------------------------
int
Cedric Roux's avatar
Cedric Roux committed
604 605
rlc_module_init (int enb_flag) { /* enb_flag is unused, but needed for binary
                                  * compatibility with rlc_v2 */
606 607 608
  //-----------------------------------------------------------------------------
  int          k;
  module_id_t  module_id1;
Cedric Roux's avatar
Cedric Roux committed
609 610
  /* for no gcc warnings */
  (void)k;
611 612 613
  LOG_D(RLC, "MODULE INIT\n");
  rlc_rrc_data_ind  = NULL;
  rlc_rrc_data_conf = NULL;
614
  rlc_coll_p = hashtable_create ((LTE_maxDRB + 2) * NUMBER_OF_UE_MAX, NULL, rb_free_rlc_union);
615

Haruki NAOI's avatar
Haruki NAOI committed
616 617 618 619 620
  //AssertFatal(rlc_coll_p != NULL, "UNRECOVERABLE error, RLC hashtable_create failed");
  if(rlc_coll_p == NULL) {
    LOG_E(RLC, "UNRECOVERABLE error, RLC hashtable_create failed\n");
    return -1;
  }
621

622
  for (module_id1=0; module_id1 < MAX_MOBILES_PER_ENB; module_id1++) {
623 624 625 626 627 628
    for (k=0; k < RLC_MAX_MBMS_LC; k++) {
      rlc_mbms_lcid2service_session_id_ue[module_id1][k].service_id = 0;
      rlc_mbms_lcid2service_session_id_ue[module_id1][k].session_id = 0;
    }

    for (k=0; k < NB_RB_MBMS_MAX; k++) {
629
      rlc_mbms_rbid2lcid_ue[module_id1][k] = RLC_LC_UNALLOCATED;
630 631
    }
  }
632

frtabu's avatar
frtabu committed
633
  for (k=0; k < RLC_MAX_MBMS_LC; k++) {
634 635
    rlc_mbms_lcid2service_session_id_eNB[0][k].service_id = 0;
    rlc_mbms_lcid2service_session_id_eNB[0][k].session_id = 0;
frtabu's avatar
frtabu committed
636
  }
637

frtabu's avatar
frtabu committed
638
  for (k=0; k < NB_RB_MBMS_MAX; k++) {
639
    rlc_mbms_rbid2lcid_eNB[0][k] = RLC_LC_UNALLOCATED;
640
  }
641

642 643
  pool_buffer_init();
  return(0);
644 645 646
}
//-----------------------------------------------------------------------------
void
647
rlc_module_cleanup (void)
648 649
//-----------------------------------------------------------------------------
{
frtabu's avatar
frtabu committed
650
  hashtable_destroy(&rlc_coll_p);
651 652 653
}
//-----------------------------------------------------------------------------
void
654
rlc_layer_init (void) {
655
  //-----------------------------------------------------------------------------
656 657 658
}
//-----------------------------------------------------------------------------
void
659
rlc_layer_cleanup (void)
660 661 662 663
//-----------------------------------------------------------------------------
{
}