rlc.c 33.7 KB
Newer Older
1
/*******************************************************************************
gauthier's avatar
gauthier committed
2 3
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom
4

gauthier's avatar
gauthier committed
5 6 7 8
    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.
9 10


gauthier's avatar
gauthier committed
11 12 13 14
    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.
15

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

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

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

 *******************************************************************************/
gauthier's avatar
gauthier committed
29 30 31 32 33 34 35
/*
                                rlc.c
                             -------------------
  AUTHOR  : Lionel GAUTHIER
  COMPANY : EURECOM
  EMAIL   : Lionel.Gauthier at eurecom dot fr
*/
36 37 38 39 40
#define RLC_C
#include "rlc.h"
#include "mem_block.h"
#include "../MAC/extern.h"
#include "UTIL/LOG/log.h"
gauthier's avatar
gauthier committed
41
#include "UTIL/OCG/OCG_vars.h"
42
#include "UTIL/LOG/vcd_signal_dumper.h"
43 44 45

#include "assertions.h"

46 47 48 49 50 51 52 53 54 55
extern boolean_t pdcp_data_ind(
    const module_id_t enb_mod_idP,
    const module_id_t ue_mod_idP,
    const frame_t frameP,
    const eNB_flag_t enb_flagP,
    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,
    mem_block_t* const sdu_buffer_pP);
56

57 58
#define DEBUG_RLC_PDCP_INTERFACE 1
//#define DEBUG_RLC_PAYLOAD 1
gauthier's avatar
gauthier committed
59
#define DEBUG_RLC_DATA_REQ 1
60

61
#if defined(DEBUG_RLC_PAYLOAD)
62
//-----------------------------------------------------------------------------
63
void rlc_util_print_hex_octets(comp_name_t componentP, unsigned char* dataP, const signed long sizeP)
64 65 66 67 68 69 70 71 72
//-----------------------------------------------------------------------------
{
  unsigned long octet_index = 0;

  if (dataP == NULL) {
    return;
  }


73 74 75 76 77


  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");
78 79 80
  for (octet_index = 0; octet_index < sizeP; octet_index++) {
    if ((octet_index % 16) == 0){
      if (octet_index != 0) {
81
        LOG_T(componentP, " |\n");
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
      }
      LOG_T(componentP, " %04d |", octet_index);
    }
    /*
     * 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;
  for (index = octet_index; index < 16; ++index)
    LOG_T(componentP, "   ");
  LOG_T(componentP, " |\n");
}
102
#endif
103
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
104
rlc_op_status_t rlc_stat_req     (
105 106 107 108 109 110
                  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,
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
                  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) {
//-----------------------------------------------------------------------------
139 140 141 142
    rlc_mode_t             rlc_mode        = RLC_MODE_NONE;
    rlc_union_t           *rlc_union_p     = NULL;
    hash_key_t             key             = HASHTABLE_QUESTIONABLE_KEY_VALUE;
    hashtable_rc_t         h_rc;
gauthier's avatar
gauthier committed
143 144

#ifdef OAI_EMU
145
    if (enb_flagP) {
146
        AssertFatal ((enb_module_idP >= oai_emulation.info.first_enb_local) && (oai_emulation.info.nb_enb_local > 0),
147
            "eNB module id is too low (%u/%d)!\n",
148
            enb_module_idP,
149
            oai_emulation.info.first_enb_local);
150
        AssertFatal ((enb_module_idP < (oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local)) && (oai_emulation.info.nb_enb_local > 0),
151
            "eNB module id is too high (%u/%d)!\n",
152
            enb_module_idP,
153
            oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local);
154
        AssertFatal (ue_module_idP  < NB_UE_INST,
155
            "UE module id is too high (%u/%d)!\n",
156
            ue_module_idP,
157 158
            oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local);
    } else {
159
        AssertFatal (ue_module_idP  < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local),
160
            "UE module id is too high (%u/%d)!\n",
161
            ue_module_idP,
162
            oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local);
163
        AssertFatal (ue_module_idP  >= oai_emulation.info.first_ue_local,
164
            "UE module id is too low (%u/%d)!\n",
165
            ue_module_idP,
166 167
            oai_emulation.info.first_ue_local);
    }
gauthier's avatar
gauthier committed
168 169
#endif
    AssertFatal (rb_idP < NB_RB_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
170 171 172 173
    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);
    if (h_rc == HASH_TABLE_OK) {
        rlc_mode = rlc_union_p->mode;
gauthier's avatar
gauthier committed
174 175
    }
    switch (rlc_mode) {
gauthier's avatar
gauthier committed
176
        case RLC_MODE_NONE:
gauthier's avatar
gauthier committed
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
            *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;

gauthier's avatar
gauthier committed
207
        case RLC_MODE_AM:
208
            rlc_am_stat_req(&rlc_union_p->rlc.am,
gauthier's avatar
gauthier committed
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
                            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;

gauthier's avatar
gauthier committed
239
       case RLC_MODE_UM:
gauthier's avatar
gauthier committed
240 241 242 243 244 245 246 247 248 249 250 251
           *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;
252
           rlc_um_stat_req (&rlc_union_p->rlc.um,
gauthier's avatar
gauthier committed
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
                              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;

gauthier's avatar
gauthier committed
273
       case RLC_MODE_TM:
gauthier's avatar
gauthier committed
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
           *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;
    }
334
}
335

336
//-----------------------------------------------------------------------------
337 338 339 340 341 342 343 344
rlc_op_status_t rlc_data_req     (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 rb_id_t      rb_idP,
                                  const mui_t        muiP,
345 346
                                  confirm_t    confirmP,
                                  sdu_size_t   sdu_sizeP,
gauthier's avatar
gauthier committed
347
                                  mem_block_t *sdu_pP) {
348
//-----------------------------------------------------------------------------
349
  mem_block_t           *new_sdu_p    = NULL;
gauthier's avatar
gauthier committed
350
  rlc_mode_t             rlc_mode     = RLC_MODE_NONE;
351 352 353 354
  rlc_union_t           *rlc_union_p = NULL;
  hash_key_t             key         = HASHTABLE_QUESTIONABLE_KEY_VALUE;
  hashtable_rc_t         h_rc;

355
#ifdef Rel10
356 357
  rlc_mbms_id_t         *mbms_id_p  = NULL;
  logical_chan_id_t      log_ch_id  = 0;
358 359
#endif
#ifdef DEBUG_RLC_DATA_REQ
gauthier's avatar
gauthier committed
360
  LOG_D(RLC,"rlc_data_req: %s enb id  %u  ue id %u, rb_id %u (MAX %d), muip %d, confirmP %d, sud_sizeP %d, sdu_pP %p\n",
361
        (enb_flagP) ? "eNB" : "UE",
362 363
        enb_module_idP,
        ue_module_idP,
gauthier's avatar
gauthier committed
364 365 366 367 368 369
        rb_idP,
        NB_RAB_MAX,
        muiP,
        confirmP,
        sdu_sizeP,
        sdu_pP);
370
#endif
371 372
#ifdef Rel10
#else
gauthier's avatar
gauthier committed
373
  AssertFatal(MBMS_flagP == 0, "MBMS_flagP %u", MBMS_flagP);
374
#endif
gauthier's avatar
gauthier committed
375
#ifdef OAI_EMU
376
  if (enb_flagP) {
377
      AssertFatal ((enb_module_idP >= oai_emulation.info.first_enb_local) && (oai_emulation.info.nb_enb_local > 0),
378
          "eNB module id is too low (%u/%d)!\n",
379
          enb_module_idP,
380
          oai_emulation.info.first_enb_local);
381
      AssertFatal ((enb_module_idP < (oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local)) && (oai_emulation.info.nb_enb_local > 0),
382
          "eNB module id is too high (%u/%d)!\n",
383
          enb_module_idP,
384
          oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local);
385
      AssertFatal (ue_module_idP  < NB_UE_INST,
386
          "UE module id is too high (%u/%d)!\n",
387
          ue_module_idP,
388 389
          oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local);
  } else {
390
      AssertFatal (ue_module_idP  < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local),
391
          "UE module id is too high (%u/%d)!\n",
392
          ue_module_idP,
393
          oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local);
394
      AssertFatal (ue_module_idP  >= oai_emulation.info.first_ue_local,
395
          "UE module id is too low (%u/%d)!\n",
396
          ue_module_idP,
397 398
          oai_emulation.info.first_ue_local);
  }
gauthier's avatar
gauthier committed
399
#endif
400 401 402 403 404
  if (MBMS_flagP) {
      AssertFatal (rb_idP < NB_RB_MBMS_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MBMS_MAX);
  } else {
      AssertFatal (rb_idP < NB_RB_MAX, "RB id is too high (%u/%d)!\n", rb_idP, NB_RB_MAX);
  }
gauthier's avatar
gauthier committed
405
  DevAssert(sdu_pP != NULL);
406 407 408 409 410 411
  DevCheck(sdu_sizeP > 0, sdu_sizeP, 0, 0);

#ifndef Rel10
  DevCheck(MBMS_flagP == 0, MBMS_flagP, 0, 0);
#endif

412 413
  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_IN);

414 415 416
#ifdef Rel10
  if (MBMS_flagP == TRUE) {
      if (enb_flagP) {
417 418
            log_ch_id = rlc_mbms_enb_get_lcid_by_rb_id(enb_module_idP,rb_idP);
            mbms_id_p = &rlc_mbms_lcid2service_session_id_eNB[enb_module_idP][log_ch_id];
419
      } else {
420 421
            log_ch_id = rlc_mbms_ue_get_lcid_by_rb_id(ue_module_idP,rb_idP);
            mbms_id_p = &rlc_mbms_lcid2service_session_id_ue[ue_module_idP][log_ch_id];
gauthier's avatar
gauthier committed
422
      }
423
      key = RLC_COLL_KEY_MBMS_VALUE(enb_module_idP, ue_module_idP, enb_flagP, mbms_id_p->service_id, mbms_id_p->session_id);
424 425 426
  } else
#endif
  {
427 428 429 430 431 432 433 434
      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);
  if (h_rc == HASH_TABLE_OK) {
      rlc_mode = rlc_union_p->mode;
  } else {
      rlc_mode = RLC_MODE_NONE;
thomasl's avatar
thomasl committed
435
      AssertFatal (0 , "RLC not configured key %ju\n", key);
gauthier's avatar
gauthier committed
436 437
  }

438
  if (MBMS_flagP == 0) {
gauthier's avatar
gauthier committed
439
      LOG_D(RLC, "[FRAME %5u][%s][RLC][INST %u/%u][RB %u] Display of rlc_data_req:\n",
440
          frameP,
441
          (enb_flagP) ? "eNB" : "UE",
442 443
          enb_module_idP,
          ue_module_idP,
gauthier's avatar
gauthier committed
444
          rb_idP);
445
#if defined(DEBUG_RLC_PAYLOAD)
gauthier's avatar
gauthier committed
446
      rlc_util_print_hex_octets(RLC, (unsigned char*)sdu_pP->data, sdu_sizeP);
447
#endif
448 449

#ifdef DEBUG_RLC_DATA_REQ
gauthier's avatar
gauthier committed
450
      LOG_D(RLC,"RLC_TYPE : %d ",rlc_mode);
451
#endif
gauthier's avatar
gauthier committed
452
      switch (rlc_mode) {
gauthier's avatar
gauthier committed
453
          case RLC_MODE_NONE:
gauthier's avatar
gauthier committed
454
              free_mem_block(sdu_pP);
gauthier's avatar
gauthier committed
455
              LOG_E(RLC, "Received RLC_MODE_NONE as rlc_type for %s eNB id  %u, ue id %u, rb_id %u\n",
456
                    (enb_flagP) ? "eNB" : "UE",
457 458
                    enb_module_idP,
                    ue_module_idP,
gauthier's avatar
gauthier committed
459
                    rb_idP);
460
	      vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
gauthier's avatar
gauthier committed
461
              return RLC_OP_STATUS_BAD_PARAMETER;
462

gauthier's avatar
gauthier committed
463
          case RLC_MODE_AM:
464
#ifdef DEBUG_RLC_DATA_REQ
gauthier's avatar
gauthier committed
465
              msg("RLC_MODE_AM\n");
466
#endif
467
              new_sdu_p = get_free_mem_block (sdu_sizeP + sizeof (struct rlc_am_data_req_alloc));
gauthier's avatar
gauthier committed
468

469
              if (new_sdu_p != NULL) {
gauthier's avatar
gauthier committed
470
                  // PROCESS OF COMPRESSION HERE:
471 472
                  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);
gauthier's avatar
gauthier committed
473

474 475 476 477
                  ((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);
gauthier's avatar
gauthier committed
478 479 480
                  free_mem_block(sdu_pP);
                  LOG_D(RLC, "%s\n",RLC_FG_BRIGHT_COLOR_RED);

481
                  LOG_D(RLC, "[FRAME %5u][%s][%s][INST %u/%u][%s %u][--- RLC_AM_DATA_REQ/%d Bytes --->][RLC_AM][INST %u/%u][%s %u]\n",
482
                          frameP,
483
                          (enb_flagP) ? "eNB" : "UE",
484 485 486 487
                          (srb_flagP) ? "RRC" : "PDCP",
                          enb_module_idP,
                          ue_module_idP,
                          (srb_flagP) ? "SRB" : "DRB",
gauthier's avatar
gauthier committed
488 489
                          rb_idP,
                          sdu_sizeP,
490 491 492
                          enb_module_idP,
                          ue_module_idP,
                          (srb_flagP) ? "SRB" : "DRB",
gauthier's avatar
gauthier committed
493 494
                          rb_idP);
                  LOG_D(RLC, "%s\n",RLC_FG_COLOR_DEFAULT);
495
                  rlc_am_data_req(&rlc_union_p->rlc.am, frameP, new_sdu_p);
496
		  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
gauthier's avatar
gauthier committed
497 498
                  return RLC_OP_STATUS_OK;
              } else {
499
		vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
gauthier's avatar
gauthier committed
500 501 502 503
                  return RLC_OP_STATUS_INTERNAL_ERROR;
              }
              break;

gauthier's avatar
gauthier committed
504
          case RLC_MODE_UM:
505
            new_sdu_p = get_free_mem_block (sdu_sizeP + sizeof (struct rlc_um_data_req_alloc));
gauthier's avatar
gauthier committed
506

507
              if (new_sdu_p != NULL) {
gauthier's avatar
gauthier committed
508
                  // PROCESS OF COMPRESSION HERE:
509 510
                  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);
gauthier's avatar
gauthier committed
511

512 513
                  ((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);
gauthier's avatar
gauthier committed
514 515
                  free_mem_block(sdu_pP);

516
                  //LOG_D(RLC, "%s\n",RLC_FG_BRIGHT_COLOR_RED);
517
                  LOG_D(RLC, "[FRAME %5u][%s][%s][INST %u/%u][%s %u][--- RLC_UM_DATA_REQ/%d Bytes --->][RLC_UM][INST %u/%u][%s %u]\n",
518
                          frameP,
519
                          (enb_flagP) ? "eNB" : "UE",
520 521 522 523
                          (srb_flagP) ? "RRC" : "PDCP",
                          enb_module_idP,
                          ue_module_idP,
                          (srb_flagP) ? "SRB" : "DRB",
gauthier's avatar
gauthier committed
524 525
                          rb_idP,
                          sdu_sizeP,
526 527 528
                          enb_module_idP,
                          ue_module_idP,
                          (srb_flagP) ? "SRB" : "DRB",
gauthier's avatar
gauthier committed
529
                          rb_idP);
530
                  //LOG_D(RLC, "%s\n",RLC_FG_COLOR_DEFAULT);
531
                  rlc_um_data_req(&rlc_union_p->rlc.um, frameP, new_sdu_p);
532

gauthier's avatar
gauthier committed
533
                  //free_mem_block(new_sdu);
534
		  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
gauthier's avatar
gauthier committed
535 536
                  return RLC_OP_STATUS_OK;
              } else {
537 538
		vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
		return RLC_OP_STATUS_INTERNAL_ERROR;
gauthier's avatar
gauthier committed
539 540 541
              }
              break;

gauthier's avatar
gauthier committed
542
          case RLC_MODE_TM:
543
            new_sdu_p = get_free_mem_block (sdu_sizeP + sizeof (struct rlc_tm_data_req_alloc));
gauthier's avatar
gauthier committed
544

545
              if (new_sdu_p != NULL) {
gauthier's avatar
gauthier committed
546
                  // PROCESS OF COMPRESSION HERE:
547 548
                  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);
gauthier's avatar
gauthier committed
549

550 551
                  ((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);
gauthier's avatar
gauthier committed
552 553
                  free_mem_block(sdu_pP);
                  LOG_D(RLC, "%s\n",RLC_FG_BRIGHT_COLOR_RED);
554
                  LOG_D(RLC, "[FRAME %5u][%s][%s][INST %u/%u][%s %u][--- RLC_TM_DATA_REQ/%d Bytes --->][RLC_TM][INST %u/%u][%s %u]\n",
555
                                 frameP,
556
                                 (enb_flagP) ? "eNB" : "UE",
557 558 559 560
                                 (srb_flagP) ? "RRC" : "PDCP",
                                 enb_module_idP,
                                 ue_module_idP,
                                 (srb_flagP) ? "SRB" : "DRB",
gauthier's avatar
gauthier committed
561 562
                                 rb_idP,
                                 sdu_sizeP,
563 564 565
                                 enb_module_idP,
                                 ue_module_idP,
                                 (srb_flagP) ? "SRB" : "DRB",
gauthier's avatar
gauthier committed
566 567
                                 rb_idP);
                  LOG_D(RLC, "%s\n",RLC_FG_COLOR_DEFAULT);
568
                  rlc_tm_data_req(&rlc_union_p->rlc.tm, new_sdu_p);
569
		  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
gauthier's avatar
gauthier committed
570 571 572
                  return RLC_OP_STATUS_OK;
              } else {
                  //handle_event(ERROR,"FILE %s FONCTION rlc_data_req() LINE %s : out of memory\n", __FILE__, __LINE__);
573 574
		vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
		return RLC_OP_STATUS_INTERNAL_ERROR;
gauthier's avatar
gauthier committed
575 576 577 578 579
              }
              break;

          default:
              free_mem_block(sdu_pP);
580
	      vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
gauthier's avatar
gauthier committed
581 582 583
              return RLC_OP_STATUS_INTERNAL_ERROR;

      }
584

585
#ifdef Rel10
586
  } else { /* MBMS_flag != 0 */
587
	  //  LOG_I(RLC,"DUY rlc_data_req: mbms_rb_id in RLC instant is: %d\n", mbms_rb_id);
gauthier's avatar
gauthier committed
588
          if (sdu_pP != NULL) {
589 590
              if (sdu_sizeP > 0) {
                  LOG_I(RLC,"received a packet with size %d for MBMS \n", sdu_sizeP);
591 592
                  new_sdu_p = get_free_mem_block (sdu_sizeP + sizeof (struct rlc_um_data_req_alloc));
                  if (new_sdu_p != NULL) {
593
                      // PROCESS OF COMPRESSION HERE:
594 595 596 597
                      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);
gauthier's avatar
gauthier committed
598
                      free_mem_block(sdu_pP);
599
                      LOG_D(RLC, "%s\n",RLC_FG_BRIGHT_COLOR_RED);
600
                          LOG_D(RLC, "[FRAME %5u][%s][%s][INST %u/%u][RB %u][--- RLC_UM_DATA_REQ/%d Bytes (MBMS) --->][RLC_UM][INST %u/%u][RB %u]\n",
601
                            frameP,
602 603 604 605
                            (enb_flagP) ? "eNB" : "UE",
                            (srb_flagP) ? "RRC" : "PDCP",
                            enb_module_idP,
                            ue_module_idP,
gauthier's avatar
gauthier committed
606 607
                            rb_idP,
                            sdu_sizeP,
608 609
                            enb_module_idP,
                            ue_module_idP,
610
                            rb_idP);
611
                      LOG_D(RLC, "%s\n",RLC_FG_COLOR_DEFAULT);
612
                      rlc_um_data_req(&rlc_union_p->rlc.um, frameP, new_sdu_p);
613 614

                      //free_mem_block(new_sdu);
615
		      vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
616 617
                      return RLC_OP_STATUS_OK;
                  } else {
618
		    vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
619 620 621
                      return RLC_OP_STATUS_BAD_PARAMETER;
                  }
              } else {
622
		vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
623 624 625
                  return RLC_OP_STATUS_BAD_PARAMETER;
              }
          } else {
626
	    vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
627 628
              return RLC_OP_STATUS_BAD_PARAMETER;
          }
629 630 631
  }
#else
  } else {/* MBMS_flag != 0 */
gauthier's avatar
gauthier committed
632
    free_mem_block(sdu_pP);
633
    LOG_E(RLC, "MBMS_flag != 0 while Rel10 is not defined...\n");
634
    //handle_event(ERROR,"FILE %s FONCTION rlc_data_req() LINE %s : parameter module_id out of bounds :%d\n", __FILE__, __LINE__, module_idP);
635
    vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RLC_DATA_REQ,VCD_FUNCTION_OUT);
636
    return RLC_OP_STATUS_BAD_PARAMETER;
637
  }
638
#endif
639 640 641
}

//-----------------------------------------------------------------------------
642 643 644 645 646 647 648 649 650 651
void rlc_data_ind     (
    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 rb_id_t     rb_idP,
    const sdu_size_t  sdu_sizeP,
    mem_block_t      *sdu_pP) {
652
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
653 654


655
#if defined(DEBUG_RLC_PAYLOAD)
656
  LOG_D(RLC, "[FRAME %5u][%s][RLC][INST %u/%u][%s %u] Display of rlc_data_ind: size %u\n",
657
        frameP,
658
        (enb_flagP) ? "eNB" : "UE",
659 660 661
        enb_module_idP,
        ue_module_idP,
        (srb_flagP) ? "SRB" : "DRB",
gauthier's avatar
gauthier committed
662 663 664 665
        rb_idP,
        sdu_sizeP);

  rlc_util_print_hex_octets(RLC, (unsigned char*)sdu_pP->data, sdu_sizeP);
666
#endif
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
  LOG_D(RLC, "[FRAME %5u][%s][RLC][INST %u/%u][%s %u][--- RLC_DATA_IND/%d Bytes --->][PDCP][INST %u/%u][%s %u]\n",
      frameP,
      (enb_flagP) ? "eNB" : "UE",
      enb_module_idP,
      ue_module_idP,
      (srb_flagP) ? "SRB" : "DRB",
      rb_idP,
      sdu_sizeP,
      enb_module_idP,
      ue_module_idP,
      (srb_flagP) ? "SRB" : "DRB",
      rb_idP);

  pdcp_data_ind (
      enb_module_idP,
      ue_module_idP,
      frameP,
      enb_flagP,
      srb_flagP,
      MBMS_flagP,
      rb_idP,
      sdu_sizeP,
      sdu_pP);
690 691
}
//-----------------------------------------------------------------------------
692 693 694 695 696 697 698 699
void rlc_data_conf     (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,
                        const mui_t           muiP,
                        const rlc_tx_status_t statusP) {
700
//-----------------------------------------------------------------------------
701 702

    if (srb_flagP) {
703 704
        if (rlc_rrc_data_conf != NULL) {
            LOG_D(RLC, "%s\n",RLC_FG_BRIGHT_COLOR_RED);
705 706 707 708 709 710 711 712 713 714 715 716 717
            LOG_D(RLC, "[FRAME %5u][%s][RLC_AM][INST %u/%u][%s %u][--- RLC_DATA_CONF /MUI %d --->][%s][INST %u/%u][][RLC_DATA_CONF/ MUI %d]\n",
                frameP,
                (enb_flagP) ? "eNB" : "UE",
                enb_module_idP,
                ue_module_idP,
                (srb_flagP) ? "SRB" : "DRB",
                rb_idP,
                muiP,
                (srb_flagP) ? "RRC" : "PDCP",
                enb_module_idP,
                ue_module_idP,
                muiP);

718
            LOG_D(RLC, "%s\n",RLC_FG_COLOR_DEFAULT);
719
            rlc_rrc_data_conf (enb_module_idP , ue_module_idP, enb_flagP, rb_idP , muiP, statusP);
720 721 722 723 724
        }
    }
}
//-----------------------------------------------------------------------------
int
725
rlc_module_init (void)
726 727
{
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
728 729 730
   int          k;
   module_id_t  module_id1;

731 732 733
   LOG_D(RLC, "MODULE INIT\n");
   rlc_rrc_data_ind  = NULL;
   rlc_rrc_data_conf = NULL;
gauthier's avatar
gauthier committed
734

735 736
   rlc_coll_p = hashtable_create ((maxDRB + 2) * 16, NULL, rb_free_rlc_union);
   AssertFatal(rlc_coll_p != NULL, "UNRECOVERABLE error, RLC hashtable_create failed");
gauthier's avatar
gauthier committed
737 738

   for (module_id1=0; module_id1 < NUMBER_OF_UE_MAX; module_id1++) {
gauthier's avatar
gauthier committed
739
#if defined(Rel10)
740 741 742 743
      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;
      }
744 745 746
      for (k=0; k < NB_RB_MBMS_MAX; k++) {
          rlc_mbms_rbid2lcid_eNB[module_id1][k] = RLC_LC_UNALLOCATED;
      }
gauthier's avatar
gauthier committed
747
#endif
748
   }
gauthier's avatar
gauthier committed
749 750

   for (module_id1=0; module_id1 < NUMBER_OF_eNB_MAX; module_id1++) {
gauthier's avatar
gauthier committed
751
#if defined(Rel10)
752 753 754 755
      for (k=0; k < RLC_MAX_MBMS_LC; k++) {
          rlc_mbms_lcid2service_session_id_eNB[module_id1][k].service_id = 0;
          rlc_mbms_lcid2service_session_id_eNB[module_id1][k].session_id = 0;
      }
756 757 758
      for (k=0; k < NB_RB_MBMS_MAX; k++) {
          rlc_mbms_rbid2lcid_ue[module_id1][k] = RLC_LC_UNALLOCATED;
      }
gauthier's avatar
gauthier committed
759
#endif
gauthier's avatar
gauthier committed
760 761
   }

762 763 764 765 766 767
   pool_buffer_init();

   return(0);
}
//-----------------------------------------------------------------------------
void
768
rlc_module_cleanup (void)
769 770
//-----------------------------------------------------------------------------
{
771
    hashtable_destroy(rlc_coll_p);
772 773 774
}
//-----------------------------------------------------------------------------
void
775
rlc_layer_init (void)
776 777 778 779 780
{
//-----------------------------------------------------------------------------
}
//-----------------------------------------------------------------------------
void
781
rlc_layer_cleanup (void)
782 783 784 785
//-----------------------------------------------------------------------------
{
}