rlc_am_reassembly.c 15.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * 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
 * the OAI Public License, Version 1.0  (the "License"); you may not use this file
 * 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
 */

22 23
#define RLC_AM_MODULE 1
#define RLC_AM_REASSEMBLY_C 1
24 25
#include "platform_types.h"
//-----------------------------------------------------------------------------
26
#if ENABLE_ITTI
gauthier's avatar
gauthier committed
27 28
# include "intertask_interface.h"
#endif
gauthier's avatar
gauthier committed
29
#include "assertions.h"
30 31 32 33 34
#include "rlc.h"
#include "rlc_am.h"
#include "list.h"
#include "LAYER2/MAC/extern.h"
#include "UTIL/LOG/log.h"
35
#include "msc.h"
36 37

//-----------------------------------------------------------------------------
38 39
inline void
rlc_am_clear_rx_sdu (
40 41
  const protocol_ctxt_t* const ctxt_pP,
  rlc_am_entity_t * const      rlc_pP)
42
{
gauthier's avatar
gauthier committed
43
  rlc_pP->output_sdu_size_to_write = 0;
44 45
}
//-----------------------------------------------------------------------------
46 47
void
rlc_am_reassembly (
48 49 50 51
  const protocol_ctxt_t* const ctxt_pP,
  rlc_am_entity_t * const rlc_pP,
  uint8_t * src_pP,
  const int32_t lengthP)
52
{
53 54
  LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PAYLOAD] reassembly()  %d bytes\n",
        PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
55
        lengthP);
56

gauthier's avatar
gauthier committed
57
  if (rlc_pP->output_sdu_in_construction == NULL) {
58
    rlc_pP->output_sdu_in_construction = get_free_mem_block (RLC_SDU_MAX_SIZE, __func__);
59 60
    rlc_pP->output_sdu_size_to_write = 0;
    assert(rlc_pP->output_sdu_in_construction != NULL);
61
  }
62

gauthier's avatar
gauthier committed
63
  if (rlc_pP->output_sdu_in_construction != NULL) {
64

65 66 67 68 69
    // check if no overflow in size
    if ((rlc_pP->output_sdu_size_to_write + lengthP) <= RLC_SDU_MAX_SIZE) {
      memcpy (&rlc_pP->output_sdu_in_construction->data[rlc_pP->output_sdu_size_to_write], src_pP, lengthP);
      rlc_pP->output_sdu_size_to_write += lengthP;
    } else {
70 71
      LOG_E(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PAYLOAD] ERROR  SDU SIZE OVERFLOW SDU GARBAGED\n",
            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
72
#if STOP_ON_IP_TRAFFIC_OVERLOAD
73 74
      AssertFatal(0, PROTOCOL_RLC_AM_CTXT_FMT" RLC_AM_DATA_IND, SDU SIZE OVERFLOW SDU GARBAGED\n",
                  PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
gauthier's avatar
gauthier committed
75
#endif
76 77 78
      // erase  SDU
      rlc_pP->output_sdu_size_to_write = 0;
    }
79
  } else {
80 81
    LOG_E(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PAYLOAD] ERROR  OUTPUT SDU IS NULL\n",
          PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
82
#if STOP_ON_IP_TRAFFIC_OVERLOAD
83 84
    AssertFatal(0, PROTOCOL_RLC_AM_CTXT_FMT" RLC_AM_DATA_IND, SDU DROPPED, OUT OF MEMORY\n",
                PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
gauthier's avatar
gauthier committed
85
#endif
86 87 88
  }
}
//-----------------------------------------------------------------------------
89 90
void
rlc_am_send_sdu (
91 92
  const protocol_ctxt_t* const ctxt_pP,
  rlc_am_entity_t * const      rlc_pP)
93
{
Wilson's avatar
Wilson committed
94
#   if TRACE_RLC_AM_PDU
gauthier's avatar
gauthier committed
95 96
  char                 message_string[7000];
  size_t               message_string_size = 0;
97
#if ENABLE_ITTI
gauthier's avatar
gauthier committed
98
  MessageDef          *msg_p;
99
#endif
gauthier's avatar
gauthier committed
100 101 102
  int                  octet_index, index;
#endif

gauthier's avatar
gauthier committed
103
  if ((rlc_pP->output_sdu_in_construction)) {
104 105
    LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEND_SDU] %d bytes sdu %p\n",
          PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
106 107 108 109 110 111
          rlc_pP->output_sdu_size_to_write,
          rlc_pP->output_sdu_in_construction);

    if (rlc_pP->output_sdu_size_to_write > 0) {
      rlc_pP->stat_rx_pdcp_sdu   += 1;
      rlc_pP->stat_rx_pdcp_bytes += rlc_pP->output_sdu_size_to_write;
112
#if TEST_RLC_AM
113 114 115 116
      rlc_am_v9_3_0_test_data_ind (rlc_pP->module_id,
                                   rlc_pP->rb_id,
                                   rlc_pP->output_sdu_size_to_write,
                                   rlc_pP->output_sdu_in_construction);
gauthier's avatar
gauthier committed
117
#else
118
#   if TRACE_RLC_AM_PDU
119 120 121 122 123 124 125 126 127 128 129 130
      message_string_size += sprintf(&message_string[message_string_size], "Bearer      : %u\n", rlc_pP->rb_id);
      message_string_size += sprintf(&message_string[message_string_size], "SDU size    : %u\n", rlc_pP->output_sdu_size_to_write);

      message_string_size += sprintf(&message_string[message_string_size], "\nPayload  : \n");
      message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");
      message_string_size += sprintf(&message_string[message_string_size], "      |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |\n");
      message_string_size += sprintf(&message_string[message_string_size], "------+-------------------------------------------------|\n");

      for (octet_index = 0; octet_index < rlc_pP->output_sdu_size_to_write; octet_index++) {
        if ((octet_index % 16) == 0) {
          if (octet_index != 0) {
            message_string_size += sprintf(&message_string[message_string_size], " |\n");
gauthier's avatar
gauthier committed
131
          }
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154

          message_string_size += sprintf(&message_string[message_string_size], " %04d |", octet_index);
        }

        /*
         * Print every single octet in hexadecimal form
         */
        message_string_size += sprintf(&message_string[message_string_size],
                                       " %02x",
                                       rlc_pP->output_sdu_in_construction->data[octet_index]);
        /*
         * Align newline and pipes according to the octets in groups of 2
         */
      }

      /*
       * Append enough spaces and put final pipe
       */
      for (index = octet_index; index < 16; ++index) {
        message_string_size += sprintf(&message_string[message_string_size], "   ");
      }

      message_string_size += sprintf(&message_string[message_string_size], " |\n");
gauthier's avatar
gauthier committed
155

gauthier's avatar
gauthier committed
156

157

158
#      if ENABLE_ITTI
159 160 161 162 163 164
      msg_p = itti_alloc_new_message_sized (ctxt_pP->enb_flag > 0 ? TASK_RLC_ENB:TASK_RLC_UE ,
                                            RLC_AM_SDU_IND,
                                            message_string_size + sizeof (IttiMsgText));
      msg_p->ittiMsg.rlc_am_sdu_ind.size = message_string_size;
      memcpy(&msg_p->ittiMsg.rlc_am_sdu_ind.text, message_string, message_string_size);

165
      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
166

gauthier's avatar
gauthier committed
167
#      else
168
      LOG_T(RLC, "%s", message_string);
gauthier's avatar
gauthier committed
169 170
#      endif
#   endif
171
#if !ENABLE_ITTI
knopp's avatar
knopp committed
172
      RLC_AM_MUTEX_UNLOCK(&rlc_pP->lock_input_sdus);
173
#endif
gauthier's avatar
gauthier committed
174 175 176 177 178 179 180 181 182 183 184
      MSC_LOG_TX_MESSAGE(
        (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_RLC_ENB:MSC_RLC_UE,
        (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
        (const char*)(rlc_pP->output_sdu_in_construction->data),
        rlc_pP->output_sdu_size_to_write,
        MSC_AS_TIME_FMT" "PROTOCOL_RLC_AM_MSC_FMT" DATA-IND size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        PROTOCOL_RLC_AM_MSC_ARGS(ctxt_pP,rlc_pP),
        rlc_pP->output_sdu_size_to_write
      );

185 186 187 188 189 190
      rlc_data_ind (ctxt_pP,
                    BOOL_NOT(rlc_pP->is_data_plane),
                    MBMS_FLAG_NO,
                    rlc_pP->rb_id,
                    rlc_pP->output_sdu_size_to_write,
                    rlc_pP->output_sdu_in_construction);
191
#if !ENABLE_ITTI
knopp's avatar
knopp committed
192
      RLC_AM_MUTEX_LOCK(&rlc_pP->lock_input_sdus, ctxt_pP, rlc_pP);
193
#endif
gauthier's avatar
gauthier committed
194
#endif
195 196
      rlc_pP->output_sdu_in_construction = NULL;
    } else {
197 198
      LOG_E(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEND_SDU] ERROR SIZE <= 0 ... DO NOTHING, SET SDU SIZE TO 0\n",
            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
199
      //msg("[RLC_AM][MOD %d] Freeing mem_block ...\n", rlc_pP->module_id);
200
      //free_mem_block (rlc_pP->output_sdu_in_construction, __func__);
201
      AssertFatal(3==4,
202 203
                  PROTOCOL_RLC_AM_CTXT_FMT" SEND SDU REQUESTED %d bytes",
                  PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
gauthier's avatar
gauthier committed
204
                  rlc_pP->output_sdu_size_to_write);
205 206 207
    }

    rlc_pP->output_sdu_size_to_write = 0;
208 209 210
  }
}
//-----------------------------------------------------------------------------
211 212
void
rlc_am_reassemble_pdu(
213 214 215 216
  const protocol_ctxt_t* const ctxt_pP,
  rlc_am_entity_t * const      rlc_pP,
  mem_block_t * const          tb_pP)
{
gauthier's avatar
gauthier committed
217
  int i,j;
218

gauthier's avatar
gauthier committed
219
  rlc_am_pdu_info_t* pdu_info        = &((rlc_am_rx_pdu_management_t*)(tb_pP->data))->pdu_info;
220 221
  LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU SN=%03d\n",
        PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
222
        pdu_info->sn);
223
#if TRACE_RLC_AM_RX_DECODE
224
  rlc_am_display_data_pdu_infos(ctxt_pP, rlc_pP, pdu_info);
225 226
#endif

gauthier's avatar
gauthier committed
227
  if (pdu_info->e == RLC_E_FIXED_PART_DATA_FIELD_FOLLOW) {
228 229
    switch (pdu_info->fi) {
    case RLC_FI_1ST_BYTE_DATA_IS_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_LAST_BYTE_SDU:
230 231
      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU NO E_LI FI=11 (00)\n",
            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
232 233 234 235 236 237 238 239
      // one complete SDU
      rlc_am_send_sdu(ctxt_pP, rlc_pP); // may be not necessary
      rlc_am_reassembly (ctxt_pP, rlc_pP, pdu_info->payload, pdu_info->payload_size);
      rlc_am_send_sdu(ctxt_pP, rlc_pP); // may be not necessary
      //rlc_pP->reassembly_missing_sn_detected = 0;
      break;

    case RLC_FI_1ST_BYTE_DATA_IS_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_NOT_LAST_BYTE_SDU:
240 241
      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU NO E_LI FI=10 (01)\n",
            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
242 243 244 245 246 247 248
      // one beginning segment of SDU in PDU
      rlc_am_send_sdu(ctxt_pP, rlc_pP); // may be not necessary
      rlc_am_reassembly (ctxt_pP, rlc_pP,pdu_info->payload, pdu_info->payload_size);
      //rlc_pP->reassembly_missing_sn_detected = 0;
      break;

    case RLC_FI_1ST_BYTE_DATA_IS_NOT_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_LAST_BYTE_SDU:
249 250
      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU NO E_LI FI=01 (10)\n",
            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
251 252 253 254 255 256 257 258 259
      // one last segment of SDU
      //if (rlc_pP->reassembly_missing_sn_detected == 0) {
      rlc_am_reassembly (ctxt_pP, rlc_pP, pdu_info->payload, pdu_info->payload_size);
      rlc_am_send_sdu(ctxt_pP, rlc_pP);
      //} // else { clear sdu already done
      //rlc_pP->reassembly_missing_sn_detected = 0;
      break;

    case RLC_FI_1ST_BYTE_DATA_IS_NOT_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_NOT_LAST_BYTE_SDU:
260 261
      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU NO E_LI FI=00 (11)\n",
            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
262 263 264 265 266 267 268 269
      //if (rlc_pP->reassembly_missing_sn_detected == 0) {
      // one whole segment of SDU in PDU
      rlc_am_reassembly (ctxt_pP, rlc_pP, pdu_info->payload, pdu_info->payload_size);
      //} else {
      //    rlc_pP->reassembly_missing_sn_detected = 1; // not necessary but for readability of the code
      //}

      break;
270
#if USER_MODE
271 272 273

    default:
      assert(0 != 0);
274
#endif
275
    }
gauthier's avatar
gauthier committed
276
  } else {
277 278
    switch (pdu_info->fi) {
    case RLC_FI_1ST_BYTE_DATA_IS_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_LAST_BYTE_SDU:
279 280
      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU FI=11 (00) Li=",
            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
281 282 283 284 285 286 287 288 289 290 291 292 293

      for (i=0; i < pdu_info->num_li; i++) {
        LOG_D(RLC, "%d ",pdu_info->li_list[i]);
      }

      LOG_D(RLC, "\n");
      //msg(" remaining size %d\n",size);
      // N complete SDUs
      rlc_am_send_sdu(ctxt_pP, rlc_pP);
      j = 0;

      for (i = 0; i < pdu_info->num_li; i++) {
        rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->li_list[i]);
294
        rlc_am_send_sdu(ctxt_pP, rlc_pP);
295 296 297 298 299 300 301 302 303 304 305 306 307
        j = j + pdu_info->li_list[i];
      }

      if (pdu_info->hidden_size > 0) { // normally should always be > 0 but just for help debug
        // data is already ok, done by last loop above
        rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->hidden_size);
        rlc_am_send_sdu(ctxt_pP, rlc_pP);
      }

      //rlc_pP->reassembly_missing_sn_detected = 0;
      break;

    case RLC_FI_1ST_BYTE_DATA_IS_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_NOT_LAST_BYTE_SDU:
308 309
      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU FI=10 (01) Li=",
            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
310 311 312 313 314 315 316 317 318 319 320 321 322

      for (i=0; i < pdu_info->num_li; i++) {
        LOG_D(RLC, "%d ",pdu_info->li_list[i]);
      }

      LOG_D(RLC, "\n");
      //msg(" remaining size %d\n",size);
      // N complete SDUs + one segment of SDU in PDU
      rlc_am_send_sdu(ctxt_pP, rlc_pP);
      j = 0;

      for (i = 0; i < pdu_info->num_li; i++) {
        rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->li_list[i]);
323
        rlc_am_send_sdu(ctxt_pP, rlc_pP);
324 325 326 327 328 329 330 331 332 333 334 335
        j = j + pdu_info->li_list[i];
      }

      if (pdu_info->hidden_size > 0) { // normally should always be > 0 but just for help debug
        // data is already ok, done by last loop above
        rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->hidden_size);
      }

      //rlc_pP->reassembly_missing_sn_detected = 0;
      break;

    case RLC_FI_1ST_BYTE_DATA_IS_NOT_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_LAST_BYTE_SDU:
336 337
      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU FI=01 (10) Li=",
            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363

      for (i=0; i < pdu_info->num_li; i++) {
        LOG_D(RLC, "%d ",pdu_info->li_list[i]);
      }

      LOG_D(RLC, "\n");
      //msg(" remaining size %d\n",size);
      // one last segment of SDU + N complete SDUs in PDU
      j = 0;

      for (i = 0; i < pdu_info->num_li; i++) {
        rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->li_list[i]);
        rlc_am_send_sdu(ctxt_pP, rlc_pP);
        j = j + pdu_info->li_list[i];
      }

      if (pdu_info->hidden_size > 0) { // normally should always be > 0 but just for help debug
        // data is already ok, done by last loop above
        rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->hidden_size);
        rlc_am_send_sdu(ctxt_pP, rlc_pP);
      }

      //rlc_pP->reassembly_missing_sn_detected = 0;
      break;

    case RLC_FI_1ST_BYTE_DATA_IS_NOT_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_NOT_LAST_BYTE_SDU:
364 365
      LOG_D(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PDU] TRY REASSEMBLY PDU FI=00 (11) Li=",
            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384

      for (i=0; i < pdu_info->num_li; i++) {
        LOG_D(RLC, "%d ",pdu_info->li_list[i]);
      }

      LOG_D(RLC, "\n");
      //msg(" remaining size %d\n",size);
      j = 0;

      for (i = 0; i < pdu_info->num_li; i++) {
        rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->li_list[i]);
        rlc_am_send_sdu(ctxt_pP, rlc_pP);
        j = j + pdu_info->li_list[i];
      }

      if (pdu_info->hidden_size > 0) { // normally should always be > 0 but just for help debug
        // data is already ok, done by last loop above
        rlc_am_reassembly (ctxt_pP, rlc_pP, &pdu_info->payload[j], pdu_info->hidden_size);
      } else {
385
#if USER_MODE
386
        //assert (5!=5);
387
#endif
388 389 390 391
      }

      //rlc_pP->reassembly_missing_sn_detected = 0;
      break;
392
#if USER_MODE
393 394 395

    default:
      assert(1 != 1);
396
#endif
397
    }
gauthier's avatar
gauthier committed
398
  }
399

400
  free_mem_block(tb_pP, __func__);
401
}