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

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


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

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

  Contact Information
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  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

 *******************************************************************************/
29 30 31
#define RLC_UM_MODULE
#define RLC_UM_DAR_C
#include "platform_types.h"
gauthier's avatar
gauthier committed
32
#include "assertions.h"
33 34 35 36 37 38 39 40 41
//-----------------------------------------------------------------------------
#include "rlc.h"
#include "rlc_um.h"
#include "rlc_primitives.h"
#include "mac_primitives.h"
#include "list.h"
#include "MAC_INTERFACE/extern.h"
#include "UTIL/LOG/log.h"

gauthier's avatar
 
gauthier committed
42
//#define TRACE_RLC_UM_DAR 1
gauthier's avatar
gauthier committed
43
//#define TRACE_RLC_UM_RX  1
44
//-----------------------------------------------------------------------------
45 46 47 48 49 50
signed int rlc_um_get_pdu_infos(
    const frame_t               frameP,
    rlc_um_pdu_sn_10_t  * const header_pP,
    const sdu_size_t            total_sizeP,
    rlc_um_pdu_info_t   * const pdu_info_pP,
    const uint8_t               sn_lengthP)
51 52
//-----------------------------------------------------------------------------
{
gauthier's avatar
gauthier committed
53 54
    sdu_size_t         sum_li = 0;
    memset(pdu_info_pP, 0, sizeof (rlc_um_pdu_info_t));
55

gauthier's avatar
gauthier committed
56
    pdu_info_pP->num_li = 0;
57

58 59 60
    AssertFatal( total_sizeP > 0 , "RLC UM PDU LENGTH %d", total_sizeP);

    if (sn_lengthP == 10) {
gauthier's avatar
gauthier committed
61 62
        pdu_info_pP->fi           = (header_pP->b1 >> 3) & 0x03;
        pdu_info_pP->e            = (header_pP->b1 >> 2) & 0x01;
gauthier's avatar
gauthier committed
63
        pdu_info_pP->sn           = header_pP->b2 + (((uint16_t)(header_pP->b1 & 0x03)) << 8);
gauthier's avatar
gauthier committed
64 65
        pdu_info_pP->header_size  = 2;
        pdu_info_pP->payload      = &header_pP->data[0];
66
    } else if (sn_lengthP == 5) {
gauthier's avatar
gauthier committed
67 68 69 70 71
        pdu_info_pP->fi           = (header_pP->b1 >> 6) & 0x03;
        pdu_info_pP->e            = (header_pP->b1 >> 5) & 0x01;
        pdu_info_pP->sn           = header_pP->b1 & 0x1F;
        pdu_info_pP->header_size  = 1;
        pdu_info_pP->payload      = &header_pP->b2;
72 73 74
    } else {
        AssertFatal( sn_lengthP == 5 || sn_lengthP == 10, "RLC UM SN LENGTH %d", sn_lengthP);
    }
75 76


gauthier's avatar
gauthier committed
77 78
    if (pdu_info_pP->e) {
        rlc_am_e_li_t      *e_li_p;
79 80 81
        unsigned int li_length_in_bytes  = 1;
        unsigned int li_to_read          = 1;

gauthier's avatar
gauthier committed
82
        e_li_p = (rlc_am_e_li_t*)(pdu_info_pP->payload);
83 84 85 86

        while (li_to_read)  {
            li_length_in_bytes = li_length_in_bytes ^ 3;
            if (li_length_in_bytes  == 2) {
gauthier's avatar
gauthier committed
87
                AssertFatal( total_sizeP >= ((uint64_t)(&e_li_p->b2) - (uint64_t)header_pP),
88
                        "DECODING PDU TOO FAR PDU size %d", total_sizeP);
gauthier's avatar
gauthier committed
89 90
                pdu_info_pP->li_list[pdu_info_pP->num_li] = ((uint16_t)(e_li_p->b1 << 4)) & 0x07F0;
                pdu_info_pP->li_list[pdu_info_pP->num_li] |= (((uint8_t)(e_li_p->b2 >> 4)) & 0x000F);
gauthier's avatar
gauthier committed
91 92
                li_to_read = e_li_p->b1 & 0x80;
                pdu_info_pP->header_size  += 2;
93
            } else {
gauthier's avatar
gauthier committed
94
                AssertFatal( total_sizeP >= ((uint64_t)(&e_li_p->b3) - (uint64_t)header_pP),
95
                        "DECODING PDU TOO FAR PDU size %d", total_sizeP);
gauthier's avatar
gauthier committed
96
                pdu_info_pP->li_list[pdu_info_pP->num_li] = ((uint16_t)(e_li_p->b2 << 8)) & 0x0700;
gauthier's avatar
gauthier committed
97 98 99 100
                pdu_info_pP->li_list[pdu_info_pP->num_li] |=  e_li_p->b3;
                li_to_read = e_li_p->b2 & 0x08;
                e_li_p++;
                pdu_info_pP->header_size  += 1;
101
            }
gauthier's avatar
gauthier committed
102 103 104 105 106 107 108 109
            AssertFatal( pdu_info_pP->num_li <= RLC_UM_SEGMENT_NB_MAX_LI_PER_PDU,
                         "[FRAME %05u][RLC_UM][MOD XX][RB XX][GET PDU INFO]  SN %04d TOO MANY LIs ",
                         frameP,
                         pdu_info_pP->sn);

            sum_li += pdu_info_pP->li_list[pdu_info_pP->num_li];
            pdu_info_pP->num_li = pdu_info_pP->num_li + 1;
            if (pdu_info_pP->num_li > RLC_UM_SEGMENT_NB_MAX_LI_PER_PDU) {
110 111 112 113
                return -2;
            }
        }
        if (li_length_in_bytes  == 2) {
gauthier's avatar
gauthier committed
114
            pdu_info_pP->payload = &e_li_p->b3;
115
        } else {
gauthier's avatar
gauthier committed
116
            pdu_info_pP->payload = &e_li_p->b1;
117 118
        }
    }
gauthier's avatar
gauthier committed
119 120 121
    pdu_info_pP->payload_size = total_sizeP - pdu_info_pP->header_size;
    if (pdu_info_pP->payload_size > sum_li) {
        pdu_info_pP->hidden_size = pdu_info_pP->payload_size - sum_li;
122 123 124 125
    }
    return 0;
}
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
126
int rlc_um_read_length_indicators(unsigned char**data_ppP, rlc_um_e_li_t* e_liP, unsigned int* li_array_pP, unsigned int *num_li_pP, sdu_size_t *data_size_pP) {
127
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
128 129 130 131 132 133
    int          continue_loop = 1;
    unsigned int e1  = 0;
    unsigned int li1 = 0;
    unsigned int e2  = 0;
    unsigned int li2 = 0;
    *num_li_pP = 0;
134 135 136 137 138 139

    while ((continue_loop)) {
        //msg("[RLC_UM] e_liP->b1 = %02X\n", e_liP->b1);
        //msg("[RLC_UM] e_liP->b2 = %02X\n", e_liP->b2);
        e1 = ((unsigned int)e_liP->b1 & 0x00000080) >> 7;
        li1 = (((unsigned int)e_liP->b1 & 0x0000007F) << 4) + (((unsigned int)e_liP->b2 & 0x000000F0) >> 4);
gauthier's avatar
gauthier committed
140 141 142
        li_array_pP[*num_li_pP] = li1;
        *data_size_pP = *data_size_pP - li1 - 2;
        *num_li_pP = *num_li_pP +1;
143 144 145
        if ((e1)) {
            e2 = ((unsigned int)e_liP->b2 & 0x00000008) >> 3;
            li2 = (((unsigned int)e_liP->b2 & 0x00000007) << 8) + ((unsigned int)e_liP->b3 & 0x000000FF);
gauthier's avatar
gauthier committed
146 147 148
            li_array_pP[*num_li_pP] = li2;
            *data_size_pP = *data_size_pP - li2 - 1;
            *num_li_pP = *num_li_pP +1;
149 150 151 152 153 154 155 156
            if (e2 == 0) {
                continue_loop = 0;
            } else {
                e_liP++;
            }
        } else {
            continue_loop = 0;
        }
gauthier's avatar
gauthier committed
157
        if (*num_li_pP >= RLC_UM_SEGMENT_NB_MAX_LI_PER_PDU) {
158 159 160
            return -1;
        }
    }
gauthier's avatar
gauthier committed
161
    *data_ppP = *data_ppP + (((*num_li_pP*3) +1) >> 1);
162 163 164
    return 0;
}
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
165
void rlc_um_try_reassembly(rlc_um_entity_t *rlc_pP, frame_t frameP, eNB_flag_t eNB_flagP, rlc_sn_t start_snP, rlc_sn_t end_snP) {
166
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
167 168 169 170 171 172 173 174 175 176
    mem_block_t        *pdu_mem_p              = NULL;
    struct mac_tb_ind  *tb_ind_p               = NULL;
    rlc_um_e_li_t      *e_li_p                 = NULL;
    unsigned char      *data_p                 = NULL;
    int                 e                      = 0;
    int                 fi                     = 0;
    sdu_size_t          size                   = 0;
    rlc_sn_t            sn                     = 0;
    unsigned int        continue_reassembly    = 0;
    unsigned int        num_li                 = 0;
177
    unsigned int        li_array[RLC_UM_SEGMENT_NB_MAX_LI_PER_PDU];
gauthier's avatar
gauthier committed
178 179
    int                 i                      = 0;
    int                 reassembly_start_index = 0;
180

gauthier's avatar
gauthier committed
181 182
    if (end_snP < 0)   end_snP   = end_snP   + rlc_pP->rx_sn_modulo;
    if (start_snP < 0) start_snP = start_snP + rlc_pP->rx_sn_modulo;
183

gauthier's avatar
gauthier committed
184
#if defined (TRACE_RLC_UM_DAR)
gauthier's avatar
 
gauthier committed
185
    LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line %u TRY REASSEMBLY FROM PDU SN=%03d+1  TO  PDU SN=%03d   SN Length = %d bits\n",
gauthier's avatar
gauthier committed
186 187 188 189
            frameP,
            (rlc_pP->is_enb) ? "eNB" : "UE",
            rlc_pP->enb_module_id,
            rlc_pP->ue_module_id,
190
            (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
191
            rlc_pP->rb_id,
gauthier's avatar
 
gauthier committed
192
            __LINE__,
gauthier's avatar
gauthier committed
193 194 195 196
            rlc_pP->last_reassemblied_sn,
            end_snP,
            rlc_pP->rx_sn_length);
#endif
197 198 199 200 201
    // nothing to be reassemblied
    if (start_snP == end_snP) {
        return;
    }
    continue_reassembly = 1;
gauthier's avatar
gauthier committed
202
    //sn = (rlc_pP->last_reassemblied_sn + 1) % rlc_pP->rx_sn_modulo;
203 204 205 206 207
    sn = start_snP;

    //check_mem_area();

    while (continue_reassembly) {
gauthier's avatar
gauthier committed
208
        if ((pdu_mem_p = rlc_pP->dar_buffer[sn])) {
209

gauthier's avatar
gauthier committed
210
            if ((rlc_pP->last_reassemblied_sn+1)%rlc_pP->rx_sn_modulo != sn) {
gauthier's avatar
 
gauthier committed
211 212
//#if defined (TRACE_RLC_UM_DAR)
                LOG_W(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line %u FINDING a HOLE in RLC UM SN: CLEARING OUTPUT SDU BECAUSE NEW SN (%03d) TO REASSEMBLY NOT CONTIGUOUS WITH LAST REASSEMBLIED SN (%03d)\n",
gauthier's avatar
gauthier committed
213 214 215 216
                        frameP,
                        (rlc_pP->is_enb) ? "eNB" : "UE",
                        rlc_pP->enb_module_id,
                        rlc_pP->ue_module_id,
217
                        (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
218
                        rlc_pP->rb_id,
gauthier's avatar
 
gauthier committed
219
                        __LINE__,
gauthier's avatar
gauthier committed
220 221
                        sn,
                        rlc_pP->last_reassemblied_sn);
gauthier's avatar
 
gauthier committed
222
//#endif
gauthier's avatar
gauthier committed
223
                rlc_um_clear_rx_sdu(rlc_pP);
224
            }
gauthier's avatar
gauthier committed
225 226 227 228
            rlc_pP->last_reassemblied_sn = sn;
            tb_ind_p = (struct mac_tb_ind *)(pdu_mem_p->data);
            if (rlc_pP->rx_sn_length == 10) {
#if defined (TRACE_RLC_UM_DAR)
gauthier's avatar
 
gauthier committed
229
                LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line %u TRY REASSEMBLY 10 PDU SN=%03d\n",
gauthier's avatar
gauthier committed
230 231 232 233
                        frameP,
                        (rlc_pP->is_enb) ? "eNB" : "UE",
                        rlc_pP->enb_module_id,
                        rlc_pP->ue_module_id,
234
                        (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
235
                        rlc_pP->rb_id,
gauthier's avatar
 
gauthier committed
236
                        __LINE__,
gauthier's avatar
gauthier committed
237 238 239 240 241 242 243
                        sn);
#endif
                e  = (((rlc_um_pdu_sn_10_t*)(tb_ind_p->data_ptr))->b1 & 0x04) >> 2;
                fi = (((rlc_um_pdu_sn_10_t*)(tb_ind_p->data_ptr))->b1 & 0x18) >> 3;
                e_li_p = (rlc_um_e_li_t*)((rlc_um_pdu_sn_10_t*)(tb_ind_p->data_ptr))->data;
                size   = tb_ind_p->size - 2;
                data_p = &tb_ind_p->data_ptr[2];
244
            } else {
gauthier's avatar
gauthier committed
245
#if defined (TRACE_RLC_UM_DAR)
gauthier's avatar
 
gauthier committed
246
                LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line TRY REASSEMBLY 5 PDU SN=%03d Byte 0=%02X\n",
gauthier's avatar
gauthier committed
247 248 249 250
                        frameP,
                        (rlc_pP->is_enb) ? "eNB" : "UE",
                        rlc_pP->enb_module_id,
                        rlc_pP->ue_module_id,
251
                        (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
252
                        rlc_pP->rb_id,
gauthier's avatar
 
gauthier committed
253
                        __LINE__,
gauthier's avatar
gauthier committed
254 255 256 257 258 259 260 261 262
                        sn,
                        ((rlc_um_pdu_sn_5_t*)(tb_ind_p->data_ptr))->b1);
#endif
                e  = (((rlc_um_pdu_sn_5_t*)(tb_ind_p->data_ptr))->b1 & 0x00000020) >> 5;
                fi = (((rlc_um_pdu_sn_5_t*)(tb_ind_p->data_ptr))->b1 & 0x000000C0) >> 6;
                e_li_p = (rlc_um_e_li_t*)((rlc_um_pdu_sn_5_t*)(tb_ind_p->data_ptr))->data;
                size   = tb_ind_p->size - 1;
                data_p = &tb_ind_p->data_ptr[1];
#if defined (TRACE_RLC_UM_DAR)
gauthier's avatar
 
gauthier committed
263
                LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line %u e=%01X fi=%01X\n",
gauthier's avatar
gauthier committed
264 265 266 267
                        frameP,
                        (rlc_pP->is_enb) ? "eNB" : "UE",
                        rlc_pP->enb_module_id,
                        rlc_pP->ue_module_id,
268
                        (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
269
                        rlc_pP->rb_id,
gauthier's avatar
 
gauthier committed
270
                        __LINE__,
gauthier's avatar
gauthier committed
271 272 273
                        e,
                        fi);
#endif
274 275 276 277
            }
            if (e == RLC_E_FIXED_PART_DATA_FIELD_FOLLOW) {
                switch (fi) {
                    case RLC_FI_1ST_BYTE_DATA_IS_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_LAST_BYTE_SDU:
gauthier's avatar
gauthier committed
278
#if defined (TRACE_RLC_UM_DAR)
gauthier's avatar
 
gauthier committed
279
                        LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line %u TRY REASSEMBLY PDU NO E_LI FI=11 (00)\n",
gauthier's avatar
gauthier committed
280 281 282 283
                                frameP,
                                (rlc_pP->is_enb) ? "eNB" : "UE",
                                rlc_pP->enb_module_id,
                                rlc_pP->ue_module_id,
284
                                (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
 
gauthier committed
285 286
                                rlc_pP->rb_id,
                                __LINE__);
gauthier's avatar
gauthier committed
287
#endif
288
                        // one complete SDU
gauthier's avatar
gauthier committed
289 290 291 292 293
                        //LGrlc_um_send_sdu(rlc_pP,frameP,eNB_flagP); // may be not necessary
                        rlc_um_clear_rx_sdu(rlc_pP);
                        rlc_um_reassembly (data_p, size, rlc_pP,frameP);
                        rlc_um_send_sdu(rlc_pP,frameP,eNB_flagP);
                        rlc_pP->reassembly_missing_sn_detected = 0;
294 295 296

                        break;
                    case RLC_FI_1ST_BYTE_DATA_IS_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_NOT_LAST_BYTE_SDU:
gauthier's avatar
gauthier committed
297
#if defined (TRACE_RLC_UM_DAR)
gauthier's avatar
 
gauthier committed
298
                        LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line %u TRY REASSEMBLY PDU NO E_LI FI=10 (01)\n",
gauthier's avatar
gauthier committed
299 300 301 302
                                frameP,
                                (rlc_pP->is_enb) ? "eNB" : "UE",
                                rlc_pP->enb_module_id,
                                rlc_pP->ue_module_id,
303
                                (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
 
gauthier committed
304 305
                                rlc_pP->rb_id,
                                __LINE__);
gauthier's avatar
gauthier committed
306
#endif
307
                        // one beginning segment of SDU in PDU
gauthier's avatar
gauthier committed
308 309 310 311
                        //LG rlc_um_send_sdu(rlc_pP,frameP,eNB_flagP); // may be not necessary
                        rlc_um_clear_rx_sdu(rlc_pP);
                        rlc_um_reassembly (data_p, size, rlc_pP,frameP);
                        rlc_pP->reassembly_missing_sn_detected = 0;
312 313
                        break;
                    case RLC_FI_1ST_BYTE_DATA_IS_NOT_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_LAST_BYTE_SDU:
gauthier's avatar
gauthier committed
314
#if defined (TRACE_RLC_UM_DAR)
gauthier's avatar
 
gauthier committed
315
                        LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line %u TRY REASSEMBLY PDU NO E_LI FI=01 (10)\n",
gauthier's avatar
gauthier committed
316 317 318 319
                                frameP,
                                (rlc_pP->is_enb) ? "eNB" : "UE",
                                rlc_pP->enb_module_id,
                                rlc_pP->ue_module_id,
320
                                (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
 
gauthier committed
321 322
                                rlc_pP->rb_id,
                                __LINE__);
gauthier's avatar
gauthier committed
323
#endif
324
                        // one last segment of SDU
gauthier's avatar
gauthier committed
325 326 327
                        if (rlc_pP->reassembly_missing_sn_detected == 0) {
                            rlc_um_reassembly (data_p, size, rlc_pP,frameP);
                            rlc_um_send_sdu(rlc_pP,frameP,eNB_flagP);
328
                        } else {
329
                            //clear sdu already done
gauthier's avatar
gauthier committed
330 331
                            rlc_pP->stat_rx_data_pdu_dropped += 1;
                            rlc_pP->stat_rx_data_bytes_dropped += tb_ind_p->size;
332
                        }
gauthier's avatar
gauthier committed
333
                        rlc_pP->reassembly_missing_sn_detected = 0;
334 335
                        break;
                    case RLC_FI_1ST_BYTE_DATA_IS_NOT_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_NOT_LAST_BYTE_SDU:
gauthier's avatar
gauthier committed
336
#if defined (TRACE_RLC_UM_DAR)
gauthier's avatar
 
gauthier committed
337
                        LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line %u TRY REASSEMBLY PDU NO E_LI FI=00 (11)\n",
gauthier's avatar
gauthier committed
338 339 340 341
                                frameP,
                                (rlc_pP->is_enb) ? "eNB" : "UE",
                                rlc_pP->enb_module_id,
                                rlc_pP->ue_module_id,
342
                                (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
 
gauthier committed
343 344
                                rlc_pP->rb_id,
                                __LINE__);
gauthier's avatar
gauthier committed
345 346
#endif
                        if (rlc_pP->reassembly_missing_sn_detected == 0) {
347
                            // one whole segment of SDU in PDU
gauthier's avatar
gauthier committed
348
                            rlc_um_reassembly (data_p, size, rlc_pP,frameP);
349
                        } else {
gauthier's avatar
 
gauthier committed
350 351
//#if defined (TRACE_RLC_UM_DAR)
                            LOG_W(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line %u TRY REASSEMBLY PDU NO E_LI FI=00 (11) MISSING SN DETECTED\n",
gauthier's avatar
gauthier committed
352 353 354 355
                                    frameP,
                                    (rlc_pP->is_enb) ? "eNB" : "UE",
                                    rlc_pP->enb_module_id,
                                    rlc_pP->ue_module_id,
356
                                    (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
 
gauthier committed
357 358 359
                                    rlc_pP->rb_id,
                                    __LINE__);
//#endif
gauthier's avatar
gauthier committed
360 361 362 363 364
                            //LOG_D(RLC, "[MSC_NBOX][FRAME %05u][%s][RLC_UM][MOD %u/%u][RB %u][Missing SN detected][RLC_UM][MOD %u/%u][RB %u]\n",
                            //      frameP, rlc_pP->module_id,rlc_pP->rb_id, rlc_pP->module_id,rlc_pP->rb_id);
                            rlc_pP->reassembly_missing_sn_detected = 1; // not necessary but for readability of the code
                            rlc_pP->stat_rx_data_pdu_dropped += 1;
                            rlc_pP->stat_rx_data_bytes_dropped += tb_ind_p->size;
365
#if defined(RLC_STOP_ON_LOST_PDU)
gauthier's avatar
gauthier committed
366
                            AssertFatal( rlc_pP->reassembly_missing_sn_detected == 1,
367
                                    "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] MISSING PDU DETECTED\n",
gauthier's avatar
gauthier committed
368 369 370 371
                                    frameP,
                                    (rlc_pP->is_enb) ? "eNB" : "UE",
                                    rlc_pP->enb_module_id,
                                    rlc_pP->ue_module_id,
372
                                    (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
373
                                    rlc_pP->rb_id);
374
#endif
375 376 377 378
                        }

                        break;
                    default:
379
                        AssertFatal( 0 , "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] TRY REASSEMBLY SHOULD NOT GO HERE\n",
gauthier's avatar
gauthier committed
380 381 382 383
                                frameP,
                                (rlc_pP->is_enb) ? "eNB" : "UE",
                                rlc_pP->enb_module_id,
                                rlc_pP->ue_module_id,
384
                                (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
385
                                rlc_pP->rb_id);
386 387
                }
            } else {
gauthier's avatar
gauthier committed
388
                if (rlc_um_read_length_indicators(&data_p, e_li_p, li_array, &num_li, &size ) >= 0) {
389 390
                    switch (fi) {
                        case RLC_FI_1ST_BYTE_DATA_IS_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_LAST_BYTE_SDU:
gauthier's avatar
gauthier committed
391
#if defined (TRACE_RLC_UM_DAR)
gauthier's avatar
 
gauthier committed
392
                            LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line %u TRY REASSEMBLY PDU FI=11 (00) Li=",
gauthier's avatar
gauthier committed
393 394 395 396
                                    frameP,
                                    (rlc_pP->is_enb) ? "eNB" : "UE",
                                    rlc_pP->enb_module_id,
                                    rlc_pP->ue_module_id,
397
                                    (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
 
gauthier committed
398 399
                                    rlc_pP->rb_id,
                                    __LINE__);
gauthier's avatar
gauthier committed
400

401 402 403 404
                            for (i=0; i < num_li; i++) {
                                LOG_D(RLC, "%d ",li_array[i]);
                            }
                            LOG_D(RLC, " remaining size %d\n",size);
gauthier's avatar
gauthier committed
405
#endif
406
                            // N complete SDUs
gauthier's avatar
gauthier committed
407 408
                            //LGrlc_um_send_sdu(rlc_pP,frameP,eNB_flagP);
                            rlc_um_clear_rx_sdu(rlc_pP);
409 410

                            for (i = 0; i < num_li; i++) {
gauthier's avatar
gauthier committed
411 412 413
                                rlc_um_reassembly (data_p, li_array[i], rlc_pP,frameP);
                                rlc_um_send_sdu(rlc_pP,frameP,eNB_flagP);
                                data_p = &data_p[li_array[i]];
414 415
                            }
                            if (size > 0) { // normally should always be > 0 but just for help debug
gauthier's avatar
gauthier committed
416 417 418
                                // data_p is already ok, done by last loop above
                                rlc_um_reassembly (data_p, size, rlc_pP,frameP);
                                rlc_um_send_sdu(rlc_pP,frameP,eNB_flagP);
419
                            }
gauthier's avatar
gauthier committed
420
                            rlc_pP->reassembly_missing_sn_detected = 0;
421 422
                            break;
                        case RLC_FI_1ST_BYTE_DATA_IS_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_NOT_LAST_BYTE_SDU:
gauthier's avatar
gauthier committed
423
#if defined (TRACE_RLC_UM_DAR)
gauthier's avatar
 
gauthier committed
424
                            LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line %u TRY REASSEMBLY PDU FI=10 (01) Li=",
gauthier's avatar
gauthier committed
425 426 427 428
                                    frameP,
                                    (rlc_pP->is_enb) ? "eNB" : "UE",
                                    rlc_pP->enb_module_id,
                                    rlc_pP->ue_module_id,
429
                                    (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
 
gauthier committed
430 431
                                    rlc_pP->rb_id,
                                    __LINE__);
432 433 434 435
                            for (i=0; i < num_li; i++) {
                                LOG_D(RLC, "%d ",li_array[i]);
                            }
                            LOG_D(RLC, " remaining size %d\n",size);
gauthier's avatar
gauthier committed
436
#endif
437
                            // N complete SDUs + one segment of SDU in PDU
gauthier's avatar
gauthier committed
438 439
                            //LG rlc_um_send_sdu(rlc_pP,frameP,eNB_flagP);
                            rlc_um_clear_rx_sdu(rlc_pP);
440
                            for (i = 0; i < num_li; i++) {
gauthier's avatar
gauthier committed
441 442 443
                                rlc_um_reassembly (data_p, li_array[i], rlc_pP,frameP);
                                rlc_um_send_sdu(rlc_pP,frameP,eNB_flagP);
                                data_p = &data_p[li_array[i]];
444 445
                            }
                            if (size > 0) { // normally should always be > 0 but just for help debug
gauthier's avatar
gauthier committed
446 447
                                // data_p is already ok, done by last loop above
                                rlc_um_reassembly (data_p, size, rlc_pP,frameP);
448
                            }
gauthier's avatar
gauthier committed
449
                            rlc_pP->reassembly_missing_sn_detected = 0;
450 451
                            break;
                        case RLC_FI_1ST_BYTE_DATA_IS_NOT_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_LAST_BYTE_SDU:
gauthier's avatar
gauthier committed
452
#if defined (TRACE_RLC_UM_DAR)
gauthier's avatar
 
gauthier committed
453
                            LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line %u TRY REASSEMBLY PDU FI=01 (10) Li=",
gauthier's avatar
gauthier committed
454 455 456 457
                                    frameP,
                                    (rlc_pP->is_enb) ? "eNB" : "UE",
                                    rlc_pP->enb_module_id,
                                    rlc_pP->ue_module_id,
458
                                    (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
 
gauthier committed
459 460
                                    rlc_pP->rb_id,
                                    __LINE__);
461 462 463 464
                            for (i=0; i < num_li; i++) {
                                LOG_D(RLC, "%d ",li_array[i]);
                            }
                            LOG_D(RLC, " remaining size %d\n",size);
gauthier's avatar
gauthier committed
465 466
#endif
                            if (rlc_pP->reassembly_missing_sn_detected) {
467
                                reassembly_start_index = 1;
gauthier's avatar
gauthier committed
468 469 470
                                data_p = &data_p[li_array[0]];
                                //rlc_pP->stat_rx_data_pdu_dropped += 1;
                                rlc_pP->stat_rx_data_bytes_dropped += li_array[0];
471 472 473 474 475 476
                            } else {
                                reassembly_start_index = 0;
                            }

                            // one last segment of SDU + N complete SDUs in PDU
                            for (i = reassembly_start_index; i < num_li; i++) {
gauthier's avatar
gauthier committed
477 478 479
                                rlc_um_reassembly (data_p, li_array[i], rlc_pP,frameP);
                                rlc_um_send_sdu(rlc_pP,frameP,eNB_flagP);
                                data_p = &data_p[li_array[i]];
480 481
                            }
                            if (size > 0) { // normally should always be > 0 but just for help debug
gauthier's avatar
gauthier committed
482 483 484
                                // data_p is already ok, done by last loop above
                                rlc_um_reassembly (data_p, size, rlc_pP,frameP);
                                rlc_um_send_sdu(rlc_pP,frameP,eNB_flagP);
485
                            }
gauthier's avatar
gauthier committed
486
                            rlc_pP->reassembly_missing_sn_detected = 0;
487 488
                            break;
                        case RLC_FI_1ST_BYTE_DATA_IS_NOT_1ST_BYTE_SDU_LAST_BYTE_DATA_IS_NOT_LAST_BYTE_SDU:
gauthier's avatar
gauthier committed
489
#if defined (TRACE_RLC_UM_DAR)
gauthier's avatar
 
gauthier committed
490
                            LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line %u TRY REASSEMBLY PDU FI=00 (11) Li=",
gauthier's avatar
gauthier committed
491 492 493 494
                                    frameP,
                                    (rlc_pP->is_enb) ? "eNB" : "UE",
                                    rlc_pP->enb_module_id,
                                    rlc_pP->ue_module_id,
495
                                    (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
 
gauthier committed
496 497
                                    rlc_pP->rb_id,
                                    __LINE__);
498 499 500 501
                            for (i=0; i < num_li; i++) {
                                LOG_D(RLC, "%d ",li_array[i]);
                            }
                            LOG_D(RLC, " remaining size %d\n",size);
gauthier's avatar
gauthier committed
502 503
#endif
                            if (rlc_pP->reassembly_missing_sn_detected) {
gauthier's avatar
 
gauthier committed
504 505
//#if defined (TRACE_RLC_UM_DAR)
                                LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line %u DISCARD FIRST LI %d",
gauthier's avatar
gauthier committed
506 507 508 509
                                        frameP,
                                        (rlc_pP->is_enb) ? "eNB" : "UE",
                                        rlc_pP->enb_module_id,
                                        rlc_pP->ue_module_id,
510
                                        (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
511
                                        rlc_pP->rb_id,
gauthier's avatar
 
gauthier committed
512
                                        __LINE__,
gauthier's avatar
gauthier committed
513
                                        li_array[0]);
gauthier's avatar
 
gauthier committed
514
//#endif
515
                                reassembly_start_index = 1;
gauthier's avatar
gauthier committed
516 517 518
                                data_p = &data_p[li_array[0]];
                            	//rlc_pP->stat_rx_data_pdu_dropped += 1;
                            	rlc_pP->stat_rx_data_bytes_dropped += li_array[0];
519 520 521 522 523
                            } else {
                                reassembly_start_index = 0;
                            }

                            for (i = reassembly_start_index; i < num_li; i++) {
gauthier's avatar
gauthier committed
524 525 526
                                rlc_um_reassembly (data_p, li_array[i], rlc_pP,frameP);
                                rlc_um_send_sdu(rlc_pP,frameP,eNB_flagP);
                                data_p = &data_p[li_array[i]];
527 528
                            }
                            if (size > 0) { // normally should always be > 0 but just for help debug
gauthier's avatar
gauthier committed
529 530
                                // data_p is already ok, done by last loop above
                                rlc_um_reassembly (data_p, size, rlc_pP,frameP);
531
                            } else {
532
                                AssertFatal( 0 !=0, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] SHOULD NOT GO HERE\n",
gauthier's avatar
gauthier committed
533 534 535 536
                                        frameP,
                                        (rlc_pP->is_enb) ? "eNB" : "UE",
                                        rlc_pP->enb_module_id,
                                        rlc_pP->ue_module_id,
537
                                        (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
538 539 540
                                        rlc_pP->rb_id);
                                //rlc_pP->stat_rx_data_pdu_dropped += 1;
                                rlc_pP->stat_rx_data_bytes_dropped += size;
541
                            }
gauthier's avatar
gauthier committed
542
                            rlc_pP->reassembly_missing_sn_detected = 0;
543 544
                            break;
                        default:
gauthier's avatar
 
gauthier committed
545 546
//#if defined (TRACE_RLC_UM_DAR)
                            LOG_W(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line %u Missing SN detected\n",
gauthier's avatar
gauthier committed
547 548 549 550
                                    frameP,
                                    (rlc_pP->is_enb) ? "eNB" : "UE",
                                    rlc_pP->enb_module_id,
                                    rlc_pP->ue_module_id,
551
                                    (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
 
gauthier committed
552 553 554
                                    rlc_pP->rb_id,
                                    __LINE__);
//#endif
gauthier's avatar
gauthier committed
555 556
                            rlc_pP->stat_rx_data_pdu_dropped += 1;
                            rlc_pP->stat_rx_data_bytes_dropped += tb_ind_p->size;
557

gauthier's avatar
gauthier committed
558
                            rlc_pP->reassembly_missing_sn_detected = 1;
559
#if defined(RLC_STOP_ON_LOST_PDU)
gauthier's avatar
gauthier committed
560
                            AssertFatal( rlc_pP->reassembly_missing_sn_detected == 1,
561
                                    "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] MISSING PDU DETECTED\n",
gauthier's avatar
gauthier committed
562 563 564 565
                                    frameP,
                                    (rlc_pP->is_enb) ? "eNB" : "UE",
                                    rlc_pP->enb_module_id,
                                    rlc_pP->ue_module_id,
566
                                    (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
567
                                    rlc_pP->rb_id);
568
#endif
569 570 571
                    }
                }
            }
gauthier's avatar
gauthier committed
572
#if defined (TRACE_RLC_UM_DAR)
gauthier's avatar
 
gauthier committed
573
            LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line %u REMOVE PDU FROM DAR BUFFER  SN=%03d\n",
gauthier's avatar
gauthier committed
574 575 576 577
                    frameP,
                    (rlc_pP->is_enb) ? "eNB" : "UE",
                    rlc_pP->enb_module_id,
                    rlc_pP->ue_module_id,
578
                    (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
579
                    rlc_pP->rb_id,
gauthier's avatar
 
gauthier committed
580
                    __LINE__,
gauthier's avatar
gauthier committed
581 582 583 584
                    sn);
#endif
            free_mem_block(rlc_pP->dar_buffer[sn]);
            rlc_pP->dar_buffer[sn] = NULL;
585
        } else {
gauthier's avatar
gauthier committed
586
            rlc_pP->last_reassemblied_missing_sn = sn;
gauthier's avatar
 
gauthier committed
587 588
//#if defined (TRACE_RLC_UM_DAR)
            LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line %u Missing SN %04d detected, clearing RX SDU\n",
gauthier's avatar
gauthier committed
589 590 591 592
                    frameP,
                    (rlc_pP->is_enb) ? "eNB" : "UE",
                    rlc_pP->enb_module_id,
                    rlc_pP->ue_module_id,
593
                    (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
594
                    rlc_pP->rb_id,
gauthier's avatar
 
gauthier committed
595
                    __LINE__,
gauthier's avatar
gauthier committed
596
                    sn);
gauthier's avatar
 
gauthier committed
597
//#endif
gauthier's avatar
gauthier committed
598 599
            rlc_pP->reassembly_missing_sn_detected = 1;
            rlc_um_clear_rx_sdu(rlc_pP);
600
#if defined(RLC_STOP_ON_LOST_PDU)
gauthier's avatar
gauthier committed
601
            AssertFatal( rlc_pP->reassembly_missing_sn_detected == 1,
602
                    "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] MISSING PDU DETECTED\n",
gauthier's avatar
gauthier committed
603 604 605 606
                    frameP,
                    (rlc_pP->is_enb) ? "eNB" : "UE",
                    rlc_pP->enb_module_id,
                    rlc_pP->ue_module_id,
607
                    (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
608
                    rlc_pP->rb_id);
609
#endif
610
        }
gauthier's avatar
gauthier committed
611 612
        sn = (sn + 1) % rlc_pP->rx_sn_modulo;
        if ((sn == rlc_pP->vr_uh) || (sn == end_snP)){
613 614 615
            continue_reassembly = 0;
        }
    }
gauthier's avatar
gauthier committed
616
#if defined (TRACE_RLC_UM_DAR)
gauthier's avatar
 
gauthier committed
617
    LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] Line %u TRIED REASSEMBLY VR(UR)=%03d VR(UX)=%03d VR(UH)=%03d\n",
gauthier's avatar
gauthier committed
618 619 620 621
            frameP,
            (rlc_pP->is_enb) ? "eNB" : "UE",
            rlc_pP->enb_module_id,
            rlc_pP->ue_module_id,
622
            (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
623
            rlc_pP->rb_id,
gauthier's avatar
 
gauthier committed
624
            __LINE__,
gauthier's avatar
gauthier committed
625 626 627 628
            rlc_pP->vr_ur,
            rlc_pP->vr_ux,
            rlc_pP->vr_uh);
#endif
629 630 631

}
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
632
void rlc_um_stop_and_reset_timer_reordering(rlc_um_entity_t *rlc_pP,frame_t frameP)
633 634
//-----------------------------------------------------------------------------
{
gauthier's avatar
gauthier committed
635
#if defined (TRACE_RLC_UM_DAR)
636
    LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u][T-REORDERING] STOPPED AND RESET\n",
gauthier's avatar
gauthier committed
637 638 639 640
            frameP,
            (rlc_pP->is_enb) ? "eNB" : "UE",
            rlc_pP->enb_module_id,
            rlc_pP->ue_module_id,
641
            (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
642 643 644 645 646 647
            rlc_pP->rb_id);
#endif
    rlc_pP->t_reordering.running         = 0;
    rlc_pP->t_reordering.frame_time_out  = 0;
    rlc_pP->t_reordering.frame_start     = 0;
    rlc_pP->t_reordering.timed_out       = 0;
648 649
}
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
650
void rlc_um_start_timer_reordering(rlc_um_entity_t *rlc_pP,frame_t frameP)
651 652
//-----------------------------------------------------------------------------
{
gauthier's avatar
gauthier committed
653 654 655 656 657
    rlc_pP->t_reordering.running         = 1;
    rlc_pP->t_reordering.frame_time_out  = frameP + rlc_pP->t_reordering.time_out;
    rlc_pP->t_reordering.frame_start     = frameP;
    rlc_pP->t_reordering.timed_out       = 0;
#if defined (TRACE_RLC_UM_DAR)
658
    LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u][T-REORDERING] STARTED (TIME-OUT = FRAME %05u)\n",
gauthier's avatar
gauthier committed
659 660 661 662
            frameP,
            (rlc_pP->is_enb) ? "eNB" : "UE",
            rlc_pP->enb_module_id,
            rlc_pP->ue_module_id,
663
            (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
664 665 666
            rlc_pP->rb_id,
            rlc_pP->t_reordering.frame_time_out);
#endif
667 668
}
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
669
void rlc_um_init_timer_reordering(rlc_um_entity_t *rlc_pP, uint32_t time_outP)
670 671
//-----------------------------------------------------------------------------
{
gauthier's avatar
gauthier committed
672 673 674 675 676
    rlc_pP->t_reordering.running         = 0;
    rlc_pP->t_reordering.frame_time_out  = 0;
    rlc_pP->t_reordering.frame_start     = 0;
    rlc_pP->t_reordering.time_out        = time_outP;
    rlc_pP->t_reordering.timed_out       = 0;
677 678
}
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
679
void rlc_um_check_timer_dar_time_out(rlc_um_entity_t *rlc_pP, frame_t frameP, eNB_flag_t eNB_flagP) {
680
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
681 682 683
    signed int     in_window;
    rlc_usn_t      old_vr_ur;
    if ((rlc_pP->t_reordering.running)) {
684 685 686 687 688 689
        if (
        // CASE 1:          start              time out
        //        +-----------+------------------+----------+
        //        |           |******************|          |
        //        +-----------+------------------+----------+
        //FRAME # 0                                     FRAME MAX
gauthier's avatar
gauthier committed
690 691 692
        ((rlc_pP->t_reordering.frame_start < rlc_pP->t_reordering.frame_time_out) &&
            ((frameP >= rlc_pP->t_reordering.frame_time_out) ||
             (frameP < rlc_pP->t_reordering.frame_start)))                                   ||
693 694 695 696 697
        // CASE 2:        time out            start
        //        +-----------+------------------+----------+
        //        |***********|                  |**********|
        //        +-----------+------------------+----------+
        //FRAME # 0                                     FRAME MAX VALUE
gauthier's avatar
gauthier committed
698 699
        ((rlc_pP->t_reordering.frame_start > rlc_pP->t_reordering.frame_time_out) &&
           (frameP < rlc_pP->t_reordering.frame_start) && (frameP >= rlc_pP->t_reordering.frame_time_out))
700 701
        ) {

gauthier's avatar
gauthier committed
702
        //if ((uint32_t)((uint32_t)rlc_pP->timer_reordering  + (uint32_t)rlc_pP->timer_reordering_init)   <= frameP) {
703 704 705 706 707 708 709
            // 5.1.2.2.4   Actions when t-Reordering expires
            //  When t-Reordering expires, the receiving UM RLC entity shall:
            //  -update VR(UR) to the SN of the first UMD PDU with SN >= VR(UX) that has not been received;
            //  -reassemble RLC SDUs from any UMD PDUs with SN < updated VR(UR), remove RLC headers when doing so and deliver the reassembled RLC SDUs to upper layer in ascending order of the RLC SN if not delivered before;
            //  -if VR(UH) > VR(UR):
            //      -start t-Reordering;
            //      -set VR(UX) to VR(UH).
gauthier's avatar
gauthier committed
710 711
        	rlc_pP->stat_timer_reordering_timed_out += 1;
#if defined (TRACE_RLC_UM_DAR)
712
            LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u]*****************************************************\n",
gauthier's avatar
gauthier committed
713 714 715 716
                    frameP,
                    (rlc_pP->is_enb) ? "eNB" : "UE",
                    rlc_pP->enb_module_id,
                    rlc_pP->ue_module_id,
717
                    (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
718
                    rlc_pP->rb_id);
719
            LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u]*    T I M E  -  O U T                              *\n",
gauthier's avatar
gauthier committed
720 721 722 723
                    frameP,
                    (rlc_pP->is_enb) ? "eNB" : "UE",
                    rlc_pP->enb_module_id,
                    rlc_pP->ue_module_id,
724
                    (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
725
                    rlc_pP->rb_id);
726
            LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u]*****************************************************\n",
gauthier's avatar
gauthier committed
727 728 729 730
                    frameP,
                    (rlc_pP->is_enb) ? "eNB" : "UE",
                    rlc_pP->enb_module_id,
                    rlc_pP->ue_module_id,
731
                    (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
732
                    rlc_pP->rb_id);
733
            LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] TIMER t-Reordering expiration\n",
gauthier's avatar
gauthier committed
734 735 736 737
                    frameP,
                    (rlc_pP->is_enb) ? "eNB" : "UE",
                    rlc_pP->enb_module_id,
                    rlc_pP->ue_module_id,
738
                    (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
739
                    rlc_pP->rb_id);
740
            LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] timer_reordering=%d frameP=%d expire frameP %d\n",
gauthier's avatar
gauthier committed
741 742 743 744
                    frameP,
                    (rlc_pP->is_enb) ? "eNB" : "UE",
                    rlc_pP->enb_module_id,
                    rlc_pP->ue_module_id,
745
                    (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
746 747 748 749
                    rlc_pP->rb_id,
                    rlc_pP->t_reordering.time_out,
                    rlc_pP->t_reordering.frame_time_out,
                    frameP);
750
            LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] set VR(UR)=%03d to",
gauthier's avatar
gauthier committed
751 752 753 754
                    frameP,
                    (rlc_pP->is_enb) ? "eNB" : "UE",
                    rlc_pP->enb_module_id,
                    rlc_pP->ue_module_id,
755
                    (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
756 757 758 759 760 761 762 763 764
                    rlc_pP->rb_id,
                    rlc_pP->vr_ur);
#endif

            old_vr_ur   = rlc_pP->vr_ur;

            rlc_pP->vr_ur = rlc_pP->vr_ux;
            while (rlc_um_get_pdu_from_dar_buffer(rlc_pP, rlc_pP->vr_ur)) {
                rlc_pP->vr_ur = (rlc_pP->vr_ur+1)%rlc_pP->rx_sn_modulo;
765
            }
gauthier's avatar
gauthier committed
766
            LOG_D(RLC, " %d", rlc_pP->vr_ur);
767 768
            LOG_D(RLC, "\n");

gauthier's avatar
gauthier committed
769
            rlc_um_try_reassembly(rlc_pP,frameP,eNB_flagP,old_vr_ur, rlc_pP->vr_ur);
770

gauthier's avatar
gauthier committed
771
            in_window = rlc_um_in_window(rlc_pP, frameP, rlc_pP->vr_ur,  rlc_pP->vr_uh,  rlc_pP->vr_uh);
772
            if (in_window == 2) {
gauthier's avatar
gauthier committed
773 774 775
            	rlc_um_start_timer_reordering(rlc_pP, frameP);
                rlc_pP->vr_ux = rlc_pP->vr_uh;
#if defined (TRACE_RLC_UM_DAR)
776
                LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] restarting t-Reordering set VR(UX) to %d (VR(UH)>VR(UR))\n",
gauthier's avatar
gauthier committed
777 778 779 780
                        frameP,
                        (rlc_pP->is_enb) ? "eNB" : "UE",
                        rlc_pP->enb_module_id,
                        rlc_pP->ue_module_id,
781
                        (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
782 783 784
                        rlc_pP->rb_id,
                        rlc_pP->vr_ux);
#endif
785
            } else {
gauthier's avatar
gauthier committed
786
#if defined (TRACE_RLC_UM_DAR)
787
                LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] STOP t-Reordering VR(UX) = %03d\n",
gauthier's avatar
gauthier committed
788 789 790 791
                        frameP,
                        (rlc_pP->is_enb) ? "eNB" : "UE",
                        rlc_pP->enb_module_id,
                        rlc_pP->ue_module_id,
792
                        (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
793 794 795 796
                        rlc_pP->rb_id,
                        rlc_pP->vr_ux);
#endif
                rlc_um_stop_and_reset_timer_reordering(rlc_pP, frameP);
797 798 799 800 801 802
            }
        }
    }
}
//-----------------------------------------------------------------------------
inline mem_block_t *
gauthier's avatar
gauthier committed
803
rlc_um_remove_pdu_from_dar_buffer(rlc_um_entity_t *rlc_pP, rlc_usn_t snP)
804 805
{
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
806 807
    mem_block_t * pdu_p     = rlc_pP->dar_buffer[snP];
#if defined (TRACE_RLC_UM_DAR)
808
    LOG_D(RLC, "[FRAME ?????][%s][RLC_UM][MOD %u/%u][%s %u] REMOVE PDU FROM DAR BUFFER  SN=%03d\n",
gauthier's avatar
gauthier committed
809 810 811
            (rlc_pP->is_enb) ? "eNB" : "UE",
            rlc_pP->enb_module_id,
            rlc_pP->ue_module_id,
812
            (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
813 814 815 816 817
            rlc_pP->rb_id,
            snP);
#endif
    rlc_pP->dar_buffer[snP] = NULL;
    return pdu_p;
818 819 820
}
//-----------------------------------------------------------------------------
inline mem_block_t *
gauthier's avatar
gauthier committed
821
rlc_um_get_pdu_from_dar_buffer(rlc_um_entity_t *rlc_pP, rlc_usn_t snP)
822 823
{
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
824
    return rlc_pP->dar_buffer[snP];
825 826 827
}
//-----------------------------------------------------------------------------
inline void
gauthier's avatar
gauthier committed
828
rlc_um_store_pdu_in_dar_buffer(rlc_um_entity_t *rlc_pP, frame_t frameP, mem_block_t *pdu_pP, rlc_usn_t snP)
829 830
{
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
831
#if defined (TRACE_RLC_UM_DAR)
832
    LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] STORE PDU IN DAR BUFFER  SN=%03d  VR(UR)=%03d VR(UX)=%03d VR(UH)=%03d\n",
gauthier's avatar
gauthier committed
833 834 835 836
            frameP,
            (rlc_pP->is_enb) ? "eNB" : "UE",
            rlc_pP->enb_module_id,
            rlc_pP->ue_module_id,
837
            (rlc_pP->is_data_plane) ? "DRB" : "SRB",
gauthier's avatar
gauthier committed
838 839 840 841 842 843 844
            rlc_pP->rb_id,
            snP,
            rlc_pP->vr_ur,
            rlc_pP->vr_ux,
            rlc_pP->vr_uh);
#endif
    rlc_pP->dar_buffer[snP] = pdu_pP;
845 846 847 848 849 850 851 852
}
//-----------------------------------------------------------------------------
// returns -2 if lower_bound  > sn
// returns -1 if higher_bound < sn
// returns  0 if lower_bound  < sn < higher_bound
// returns  1 if lower_bound  == sn
// returns  2 if higher_bound == sn
// returns  3 if higher_bound == sn == lower_bound
gauthier's avatar
gauthier committed
853
inline signed int rlc_um_in_window(rlc_um_entity_t *rlc_pP, frame_t frameP, rlc_sn_t lower_boundP, rlc_sn_t snP, rlc_sn_t higher_boundP) {
854 855
//-----------------------------------------------------------------------------

gauthier's avatar
gauthier committed
856 857 858 859 860
    rlc_sn_t modulus = (rlc_sn_t)rlc_pP->vr_uh - rlc_pP->rx_um_window_size;
#ifdef TRACE_RLC_UM_RX
    rlc_sn_t     lower_bound  = lower_boundP;
    rlc_sn_t     higher_bound = higher_boundP;
    rlc_sn_t     sn           = snP;
861
#endif
gauthier's avatar
gauthier committed
862 863 864
    lower_boundP  = (lower_boundP  - modulus) % rlc_pP->rx_sn_modulo;
    higher_boundP = (higher_boundP - modulus) % rlc_pP->rx_sn_modulo;
    snP           = (snP           - modulus) % rlc_pP->rx_sn_modulo;
865 866

    if ( lower_boundP > snP) {
gauthier's avatar
gauthier committed
867
#ifdef TRACE_RLC_UM_RX
868
        LOG_D(RLC, "[FRAME %05u][%s][RLC_UM][MOD %u/%u][%s %u] %d not in WINDOW[%03d:%03d] (SN<LOWER BOUND)\n",
gauthier's avatar
gauthier committed
869 870 871 872
                frameP,
                (rlc_pP->is_enb) ? "eNB" : "UE",
                rlc_pP->enb_module_id,
                rlc_pP->ue_module_id,