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

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

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

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.

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

Contact Information
Openair Admin: openair_admin@eurecom.fr
Openair Tech : openair_tech@eurecom.fr
Forums       : http://forums.eurecom.fsr/openairinterface
gauthier's avatar
Licence    
gauthier committed
25
26
27
28
29
30
Address      : EURECOM,
               Campus SophiaTech,
               450 Route des Chappes,
               CS 50193
               06904 Biot Sophia Antipolis cedex,
               FRANCE
31
32
33
34
35
36
37
38
39
40
41
*******************************************************************************/
#define RLC_AM_MODULE
#define RLC_AM_INIT_C
#ifdef USER_MODE
#include <string.h>
#endif
//-----------------------------------------------------------------------------
#include "rlc_am.h"
#include "LAYER2/MAC/extern.h"
#include "UTIL/LOG/log.h"
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
42
void rlc_am_init(rlc_am_entity_t *rlc_pP, frame_t frameP)
43
44
//-----------------------------------------------------------------------------
{
gauthier's avatar
gauthier committed
45
46
47
48
49
50
51
52
53
    int saved_allocation = rlc_pP->allocation;
    LOG_D(RLC, "[FRAME %5u][RLC_AM][MOD XX][RB XX][INIT] STATE VARIABLES, BUFFERS, LISTS\n", frameP);
    memset(rlc_pP, 0, sizeof(rlc_am_entity_t));
    rlc_pP->allocation = saved_allocation;

    list2_init(&rlc_pP->receiver_buffer,      "RX BUFFER");
    list_init(&rlc_pP->pdus_to_mac_layer,     "PDUS TO MAC");
    list_init(&rlc_pP->control_pdu_list,      "CONTROL PDU LIST");
    list_init(&rlc_pP->segmentation_pdu_list, "SEGMENTATION PDU LIST");
54
55
    //LOG_D(RLC,"RLC_AM_SDU_CONTROL_BUFFER_SIZE %d sizeof(rlc_am_tx_sdu_management_t) %d \n",  RLC_AM_SDU_CONTROL_BUFFER_SIZE, sizeof(rlc_am_tx_sdu_management_t));
    
gauthier's avatar
gauthier committed
56
57
    rlc_pP->input_sdus_alloc         = get_free_mem_block(RLC_AM_SDU_CONTROL_BUFFER_SIZE*sizeof(rlc_am_tx_sdu_management_t));
    rlc_pP->input_sdus               = (rlc_am_tx_sdu_management_t*)((rlc_pP->input_sdus_alloc)->data);
gauthier's avatar
gauthier committed
58
    rlc_pP->pdu_retrans_buffer_alloc = get_free_mem_block((uint16_t)((unsigned int)RLC_AM_PDU_RETRANSMISSION_BUFFER_SIZE*(unsigned int)sizeof(rlc_am_tx_data_pdu_management_t)));
gauthier's avatar
gauthier committed
59
60
61
    rlc_pP->pdu_retrans_buffer       = (rlc_am_tx_data_pdu_management_t*)((rlc_pP->pdu_retrans_buffer_alloc)->data);
    LOG_D(RLC, "[FRAME %5u][RLC_AM][MOD XX][RB XX][INIT] input_sdus[] = %p  element size=%d\n", frameP, rlc_pP->input_sdus,sizeof(rlc_am_tx_sdu_management_t));
    LOG_D(RLC, "[FRAME %5u][RLC_AM][MOD XX][RB XX][INIT] pdu_retrans_buffer[] = %p element size=%d\n", frameP, rlc_pP->pdu_retrans_buffer,sizeof(rlc_am_tx_data_pdu_management_t));
62
63

    // TX state variables
gauthier's avatar
gauthier committed
64
65
66
67
    //rlc_pP->vt_a    = 0;
    rlc_pP->vt_ms   = rlc_pP->vt_a + RLC_AM_WINDOW_SIZE;
    //rlc_pP->vt_s    = 0;
    //rlc_pP->poll_sn = 0;
68
    // TX counters
gauthier's avatar
gauthier committed
69
70
    //rlc_pP->c_pdu_without_poll  = 0;
    //rlc_pP->c_byte_without_poll = 0;
71
    // RX state variables
gauthier's avatar
gauthier committed
72
73
74
75
76
77
78
79
    //rlc_pP->vr_r    = 0;
    rlc_pP->vr_mr   = rlc_pP->vr_r + RLC_AM_WINDOW_SIZE;
    //rlc_pP->vr_x    = 0;
    //rlc_pP->vr_ms   = 0;
    //rlc_pP->vr_h    = 0;

    rlc_pP->last_frame_status_indication = 123456; // any value > 1
    rlc_pP->first_retrans_pdu_sn         = -1;
80
81
}
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
82
void rlc_am_cleanup(rlc_am_entity_t *rlc_pP, frame_t frameP)
83
84
//-----------------------------------------------------------------------------
{
gauthier's avatar
gauthier committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
    LOG_I(RLC, "[FRAME %5u][%s][RLC_AM][MOD %u/%u][RB %u][CLEANUP]\n",
          frameP,
          (rlc_pP->is_enb) ? "eNB" : "UE",
          rlc_pP->enb_module_id,
          rlc_pP->ue_module_id,
          rlc_pP->rb_id);

    list2_free(&rlc_pP->receiver_buffer);
    list_free(&rlc_pP->pdus_to_mac_layer);
    list_free(&rlc_pP->control_pdu_list);
    list_free(&rlc_pP->segmentation_pdu_list);


    if (rlc_pP->output_sdu_in_construction != NULL) {
        free_mem_block(rlc_pP->output_sdu_in_construction);
        rlc_pP->output_sdu_in_construction = NULL;
101
102
    }
    unsigned int i;
gauthier's avatar
gauthier committed
103
    if (rlc_pP->input_sdus_alloc != NULL) {
104
        for (i=0; i < RLC_AM_SDU_CONTROL_BUFFER_SIZE; i++) {
gauthier's avatar
gauthier committed
105
106
107
            if (rlc_pP->input_sdus[i].mem_block != NULL) {
                free_mem_block(rlc_pP->input_sdus[i].mem_block);
                rlc_pP->input_sdus[i].mem_block = NULL;
108
109
            }
        }
gauthier's avatar
gauthier committed
110
111
112
        free_mem_block(rlc_pP->input_sdus_alloc);
        rlc_pP->input_sdus_alloc = NULL;
        rlc_pP->input_sdus       = NULL;
113
    }
gauthier's avatar
gauthier committed
114
    if (rlc_pP->pdu_retrans_buffer_alloc != NULL) {
115
        for (i=0; i < RLC_AM_PDU_RETRANSMISSION_BUFFER_SIZE; i++) {
gauthier's avatar
gauthier committed
116
117
118
            if (rlc_pP->pdu_retrans_buffer[i].mem_block != NULL) {
                free_mem_block(rlc_pP->pdu_retrans_buffer[i].mem_block);
                rlc_pP->pdu_retrans_buffer[i].mem_block = NULL;
119
120
            }
        }
gauthier's avatar
gauthier committed
121
122
123
        free_mem_block(rlc_pP->pdu_retrans_buffer_alloc);
        rlc_pP->pdu_retrans_buffer_alloc = NULL;
        rlc_pP->pdu_retrans_buffer       = NULL;
124
    }
gauthier's avatar
gauthier committed
125
    memset(rlc_pP, 0, sizeof(rlc_am_entity_t));
126
127
}
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
128
129
void rlc_am_configure(rlc_am_entity_t *rlc_pP,
		      frame_t          frameP,
gauthier's avatar
gauthier committed
130
131
132
133
134
135
                      uint16_t            max_retx_thresholdP,
                      uint16_t            poll_pduP,
                      uint16_t            poll_byteP,
                      uint32_t            t_poll_retransmitP,
                      uint32_t            t_reorderingP,
                      uint32_t            t_status_prohibitP)
136
137
//-----------------------------------------------------------------------------
{
gauthier's avatar
gauthier committed
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
    LOG_I(RLC, "[FRAME %5u][%s][RLC_AM][MOD %u/%u][RB %u][CONFIGURE] max_retx_threshold %d poll_pdu %d poll_byte %d t_poll_retransmit %d t_reordering %d t_status_prohibit %d\n",
          frameP,
          (rlc_pP->is_enb) ? "eNB" : "UE",
          rlc_pP->enb_module_id,
          rlc_pP->ue_module_id,
          rlc_pP->rb_id,
          max_retx_thresholdP,
          poll_pduP,
          poll_byteP,
          t_poll_retransmitP,
          t_reorderingP,
          t_status_prohibitP);

    rlc_pP->max_retx_threshold = max_retx_thresholdP;
    rlc_pP->poll_pdu           = poll_pduP;
    rlc_pP->poll_byte          = poll_byteP;
    rlc_pP->protocol_state     = RLC_DATA_TRANSFER_READY_STATE;

    rlc_am_init_timer_poll_retransmit(rlc_pP, t_poll_retransmitP);
    rlc_am_init_timer_reordering     (rlc_pP, t_reorderingP);
    rlc_am_init_timer_status_prohibit(rlc_pP, t_status_prohibitP);
159
160
}
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
161
162
163
164
165
166
167
void rlc_am_set_debug_infos(rlc_am_entity_t *rlc_pP,
                            frame_t          frameP,
                            eNB_flag_t       eNB_flagP,
                            module_id_t      enb_module_idP,
                            module_id_t      ue_module_idP,
                            rb_id_t          rb_idP,
                            rb_type_t        rb_typeP)
168
169
//-----------------------------------------------------------------------------
{
gauthier's avatar
gauthier committed
170
171
172
173
174
175
176
177
178
179
180
181
182
183
    LOG_D(RLC, "[FRAME %5u][%s][RLC_AM][MOD %u/%u][RB %u][SET DEBUG INFOS] module_id %d rb_id %d rb_type %d\n",
          frameP,
          (rlc_pP->is_enb) ? "eNB" : "UE",
          rlc_pP->enb_module_id,
          rlc_pP->ue_module_id,
          rb_idP,
          enb_module_idP,
          ue_module_idP,
          rb_idP,
          rb_typeP);

    rlc_pP->enb_module_id = enb_module_idP;
    rlc_pP->ue_module_id  = ue_module_idP;
    rlc_pP->rb_id         = rb_idP;
184
    if (rb_typeP != SIGNALLING_RADIO_BEARER) {
gauthier's avatar
gauthier committed
185
      rlc_pP->is_data_plane = 1;
186
    } else {
gauthier's avatar
gauthier committed
187
      rlc_pP->is_data_plane = 0;
188
    }
gauthier's avatar
gauthier committed
189
    rlc_pP->is_enb = eNB_flagP;
190
}