openair2_proc.c 33.2 KB
Newer Older
1 2 3 4 5
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * 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
 */
21

gauthier's avatar
gauthier committed
22 23
/******************************************************************************
 \file openair2_proc
24
# \brief print openair2 overall statistics
25
# \author Navid Nikaein
26 27
# \date 2013-2015
# \version 0.2
28
# \email navid.nikaein@eurecom.fr
29
# @ingroup _openair2
30 31
*/

32 33 34
#ifdef USER_MODE
# include <inttypes.h>
#else
35 36 37 38
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/proc_fs.h>

39 40 41 42 43 44 45
# ifndef PRIu64
#  if __WORDSIZE == 64
#     define PRIu64 "lu"
#   else
#     define PRIu64 "llu"
#   endif
# endif
46
#endif
47

48 49 50
#include "LAYER2/RLC/rlc.h"
#include "LAYER2/MAC/defs.h"
#include "LAYER2/MAC/extern.h"
gauthier's avatar
gauthier committed
51
#include "LAYER2/PDCP_v10.1.0/pdcp.h"
52
#include "UTIL/LOG/log.h"
53
#include "common/ran_context.h"
54 55

static mapping rrc_status_names[] = {
56 57 58 59 60 61
  {"RRC_INACTIVE", 0},
  {"RRC_IDLE", 1},
  {"RRC_SI_RECEIVED",2},
  {"RRC_CONNECTED",3},
  {"RRC_RECONFIGURED",4},
  {"RRC_HO_EXECUTION",5},
62 63 64
  {NULL, -1}
};

65 66
extern RAN_CONTEXT_t RC;

67 68 69
int dump_eNB_l2_stats(char *buffer, int length)
{

knopp's avatar
knopp committed
70
  int eNB_id,UE_id,number_of_cards;
71
  int len= length;
knopp's avatar
knopp committed
72
  int CC_id=0;
73
  int i;
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
  protocol_ctxt_t      ctxt;
  rlc_op_status_t rlc_status;
  unsigned int stat_rlc_mode;
  unsigned int stat_tx_pdcp_sdu;
  unsigned int stat_tx_pdcp_bytes;
  unsigned int stat_tx_pdcp_sdu_discarded;
  unsigned int stat_tx_pdcp_bytes_discarded;
  unsigned int stat_tx_data_pdu;
  unsigned int  stat_tx_data_bytes;
  unsigned int  stat_tx_retransmit_pdu_by_status;
  unsigned int  stat_tx_retransmit_bytes_by_status;
  unsigned int stat_tx_retransmit_pdu;
  unsigned int  stat_tx_retransmit_bytes;
  unsigned int  stat_tx_control_pdu;
  unsigned int  stat_tx_control_bytes;
  unsigned int  stat_rx_pdcp_sdu;
  unsigned int  stat_rx_pdcp_bytes;
  unsigned int  stat_rx_data_pdus_duplicate;
  unsigned int  stat_rx_data_bytes_duplicate;
  unsigned int  stat_rx_data_pdu;
  unsigned int  stat_rx_data_bytes;
  unsigned int  stat_rx_data_pdu_dropped;
  unsigned int  stat_rx_data_bytes_dropped;
  unsigned int  stat_rx_data_pdu_out_of_window;
  unsigned int  stat_rx_data_bytes_out_of_window;
  unsigned int  stat_rx_control_pdu;
  unsigned int  stat_rx_control_bytes;
  unsigned int  stat_timer_reordering_timed_out;
  unsigned int  stat_timer_poll_retransmit_timed_out;
  unsigned int  stat_timer_status_prohibit_timed_out;
knopp's avatar
knopp committed
104

105 106
#ifdef EXMIMO
  number_of_cards=1;
107
#else
108 109
  number_of_cards=NB_eNB_INST;
#endif
knopp's avatar
knopp committed
110 111
  eNB_MAC_INST *eNB;
  UE_list_t *UE_list;
112

113 114
  for (eNB_id=0; eNB_id<number_of_cards; eNB_id++) {
    /* reset the values */
115
    eNB = RC.mac[eNB_id];
knopp's avatar
knopp committed
116
    UE_list = &eNB->UE_list;
117

118
    for (CC_id=0 ; CC_id < MAX_NUM_CCs; CC_id++) {
119 120
      eNB->eNB_stats[CC_id].dlsch_bitrate= 0;

121
      len += sprintf(&buffer[len],"eNB %d CC %d Frame %d: Active UEs %d, Available PRBs %d, nCCE %d, Scheduling decisions %d, Missed Deadlines %d \n",
122 123 124
                     eNB_id, CC_id, eNB->frame,
                     eNB->eNB_stats[CC_id].num_dlactive_UEs,
                     eNB->eNB_stats[CC_id].available_prbs,
125 126 127
                     eNB->eNB_stats[CC_id].available_ncces,
		     eNB->eNB_stats[CC_id].sched_decisions,
		     eNB->eNB_stats[CC_id].missed_deadlines);
128 129 130 131 132 133
      
      len += sprintf(&buffer[len],"BCCH , NB_TX_MAC = %d, transmitted bytes (TTI %d, total %d) MCS (TTI %d)\n",
		     eNB->eNB_stats[CC_id].total_num_bcch_pdu,
		     eNB->eNB_stats[CC_id].bcch_buffer,
		     eNB->eNB_stats[CC_id].total_bcch_buffer,
		     eNB->eNB_stats[CC_id].bcch_mcs);
134 135 136 137 138 139

      len += sprintf(&buffer[len],"PCCH , NB_TX_MAC = %d, transmitted bytes (TTI %d, total %d) MCS (TTI %d)\n",
         eNB->eNB_stats[CC_id].total_num_pcch_pdu,
         eNB->eNB_stats[CC_id].pcch_buffer,
         eNB->eNB_stats[CC_id].total_pcch_buffer,
         eNB->eNB_stats[CC_id].pcch_mcs);
140
      
141 142 143 144
      eNB->eNB_stats[CC_id].dlsch_bitrate=((eNB->eNB_stats[CC_id].dlsch_bytes_tx*8)/((eNB->frame + 1)*10));
      eNB->eNB_stats[CC_id].total_dlsch_pdus_tx+=eNB->eNB_stats[CC_id].dlsch_pdus_tx;
      eNB->eNB_stats[CC_id].total_dlsch_bytes_tx+=eNB->eNB_stats[CC_id].dlsch_bytes_tx;
      eNB->eNB_stats[CC_id].total_dlsch_bitrate=((eNB->eNB_stats[CC_id].total_dlsch_bytes_tx*8)/((eNB->frame + 1)*10));
145

146 147 148
      eNB->eNB_stats[CC_id].ulsch_bitrate=((eNB->eNB_stats[CC_id].ulsch_bytes_rx*8)/((eNB->frame + 1)*10));
      eNB->eNB_stats[CC_id].total_ulsch_bitrate=((eNB->eNB_stats[CC_id].total_ulsch_bytes_rx*8)/((eNB->frame + 1)*10));

149
      len += sprintf(&buffer[len],"DLSCH bitrate (TTI %u, avg %u) kbps, Transmitted bytes (TTI %u, total %u), Transmitted PDU (TTI %u, total %u) \n",
150 151 152 153 154 155
                     eNB->eNB_stats[CC_id].dlsch_bitrate,
                     eNB->eNB_stats[CC_id].total_dlsch_bitrate,
                     eNB->eNB_stats[CC_id].dlsch_bytes_tx,
                     eNB->eNB_stats[CC_id].total_dlsch_bytes_tx,
                     eNB->eNB_stats[CC_id].dlsch_pdus_tx,
                     eNB->eNB_stats[CC_id].total_dlsch_pdus_tx);
156

Cedric Roux's avatar
Cedric Roux committed
157
      len += sprintf(&buffer[len],"ULSCH bitrate (TTI %u, avg %u) kbps, Received bytes (TTI %u, total %u), Received PDU (TTI %lu, total %u) \n",
158 159 160 161 162 163
                     eNB->eNB_stats[CC_id].ulsch_bitrate,
                     eNB->eNB_stats[CC_id].total_ulsch_bitrate,
                     eNB->eNB_stats[CC_id].ulsch_bytes_rx,
                     eNB->eNB_stats[CC_id].total_ulsch_bytes_rx,
                     eNB->eNB_stats[CC_id].ulsch_pdus_rx,
                     eNB->eNB_stats[CC_id].total_ulsch_pdus_rx);
164
    }
165

166 167
    len += sprintf(&buffer[len],"\n");

168 169 170
    for (UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) {
      for (i=0; i<UE_list->numactiveCCs[UE_id]; i++) {
        CC_id=UE_list->ordered_CCids[i][UE_id];
171 172
	
	UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_bitrate=((UE_list->eNB_UE_stats[CC_id][UE_id].TBS*8)/((eNB->frame + 1)*10));
173 174 175
        UE_list->eNB_UE_stats[CC_id][UE_id].total_dlsch_bitrate= ((UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes*8)/((eNB->frame + 1)*10));
        UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes+=  UE_list->eNB_UE_stats[CC_id][UE_id].overhead_bytes;
        UE_list->eNB_UE_stats[CC_id][UE_id].avg_overhead_bytes=((UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes*8)/((eNB->frame + 1)*10));
176 177 178 179
	
	UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_bitrate=((UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS*8)/((eNB->frame + 1)*10));
        UE_list->eNB_UE_stats[CC_id][UE_id].total_ulsch_bitrate= ((UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes_rx*8)/((eNB->frame + 1)*10));
       
180
        len += sprintf(&buffer[len],"[MAC] UE %d (DLSCH),status %s, RNTI %x : CQI %d, MCS1 %d, MCS2 %d, RB (tx %d, retx %d, total %d), ncce (tx %d, retx %d) \n",
181 182 183
                       UE_id,
                       map_int_to_str(rrc_status_names, UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status),
                       UE_list->eNB_UE_stats[CC_id][UE_id].crnti,
Cedric Roux's avatar
Cedric Roux committed
184
                       UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id],
185 186 187 188 189 190 191 192 193 194
                       UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1,
                       UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs2,
                       UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used,
                       UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx,
                       UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used,
                       UE_list->eNB_UE_stats[CC_id][UE_id].ncce_used,
                       UE_list->eNB_UE_stats[CC_id][UE_id].ncce_used_retx
                      );

        len += sprintf(&buffer[len],
195 196
                       "[MAC] DLSCH bitrate (TTI %d, avg %d), Transmitted bytes "
                       "(TTI %d, total %"PRIu64"), Total Transmitted PDU %d, Overhead "
197
                       "(TTI %"PRIu64", total %"PRIu64", avg %"PRIu64")\n",
198 199 200 201 202 203 204 205 206
                       UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_bitrate,
                       UE_list->eNB_UE_stats[CC_id][UE_id].total_dlsch_bitrate,
                       UE_list->eNB_UE_stats[CC_id][UE_id].TBS,
                       UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes,
                       UE_list->eNB_UE_stats[CC_id][UE_id].total_num_pdus,
                       UE_list->eNB_UE_stats[CC_id][UE_id].overhead_bytes,
                       UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes,
                       UE_list->eNB_UE_stats[CC_id][UE_id].avg_overhead_bytes
                      );
207
        
208 209

	len += sprintf(&buffer[len],"[MAC] UE %d (ULSCH), Status %s, Failute timer %d, RNTI %x : rx power (normalized %d,  target %d), MCS (pre %d, post %d), RB (rx %d, retx %d, total %d), Current TBS %d \n",
210 211
                       UE_id,
                       map_int_to_str(rrc_status_names, UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status),
212
		       UE_list->UE_sched_ctrl[UE_id].ul_failure_timer,
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
                       UE_list->eNB_UE_stats[CC_id][UE_id].crnti,
		       UE_list->eNB_UE_stats[CC_id][UE_id].normalized_rx_power,
		       UE_list->eNB_UE_stats[CC_id][UE_id].target_rx_power,
		       UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs1,
		       UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2,
		       UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_rx,
		       UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx_rx,
		       UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx,
		       UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS
		       );

	len += sprintf(&buffer[len],
                       "[MAC] ULSCH bitrate (TTI %d, avg %d), received bytes (total %"PRIu64"),"
                       "Total received PDU %d, Total errors %d\n", 
		       UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_bitrate,
                       UE_list->eNB_UE_stats[CC_id][UE_id].total_ulsch_bitrate,
229 230 231
                       UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes_rx,
                       UE_list->eNB_UE_stats[CC_id][UE_id].total_num_pdus_rx,
                       UE_list->eNB_UE_stats[CC_id][UE_id].num_errors_rx);
232

233 234
        len+= sprintf(&buffer[len],"[MAC] Received PHR PH = %d (db)\n", UE_list->UE_template[CC_id][UE_id].phr_info);
        len+= sprintf(&buffer[len],"[MAC] Received BSR LCGID[0][1][2][3] = %u %u %u %u\n",
235 236 237 238 239
                      UE_list->UE_template[CC_id][UE_id].bsr_info[LCGID0],
                      UE_list->UE_template[CC_id][UE_id].bsr_info[LCGID1],
                      UE_list->UE_template[CC_id][UE_id].bsr_info[LCGID2],
                      UE_list->UE_template[CC_id][UE_id].bsr_info[LCGID3]
                     );
240
      }
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 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 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
      
      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt,
				     eNB_id,
				     ENB_FLAG_YES,
				     UE_list->eNB_UE_stats[UE_PCCID(eNB_id,UE_id)][UE_id].crnti, 
				     eNB->frame,
				     eNB->subframe,
				     eNB_id);

      rlc_status = rlc_stat_req(&ctxt,
				SRB_FLAG_YES,
				DCCH,
				&stat_rlc_mode,
				&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);
      
      if (rlc_status == RLC_OP_STATUS_OK) {
	len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_SDU_TO_TX = %d (bytes %d)\tNB_SDU_TO_TX_DISC %d (bytes %d)\n",
		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
		     stat_tx_pdcp_sdu,
		     stat_tx_pdcp_bytes,
		     stat_tx_pdcp_sdu_discarded,
		     stat_tx_pdcp_bytes_discarded);
	
	len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_TX_DATA   = %d (bytes %d)\tNB_TX_CONTROL %d (bytes %d)\tNB_TX_RETX %d (bytes %d)\tNB_TX_RETX_BY_STATUS = %d (bytes %d)\n",
		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
		     stat_tx_data_pdu,
		     stat_tx_data_bytes,
		     stat_tx_control_pdu,
		     stat_tx_control_bytes,
		     stat_tx_retransmit_pdu,
		     stat_tx_retransmit_bytes,
		     stat_tx_retransmit_pdu_by_status,
		     stat_tx_retransmit_bytes_by_status);
		
	
	len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_RX_DATA   = %d (bytes %d)\tNB_RX_CONTROL %d (bytes %d)\tNB_RX_DUPL %d (bytes %d)\tNB_RX_DROP = %d (bytes %d)\tNB_RX_OUT_OF_WINDOW = %d (bytes %d)\n",
		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
		     stat_rx_data_pdu,
		     stat_rx_data_bytes,
		     stat_rx_control_pdu,
		     stat_rx_control_bytes,
		     stat_rx_data_pdus_duplicate,
		     stat_rx_data_bytes_duplicate,
		     stat_rx_data_pdu_dropped,
		     stat_rx_data_bytes_dropped,
		     stat_rx_data_pdu_out_of_window,
		     stat_rx_data_bytes_out_of_window);
	

	len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, RX_REODERING_TIMEOUT = %d\tRX_POLL_RET_TIMEOUT %d\tRX_PROHIBIT_TIME_OUT %d\n",
		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
		     stat_timer_reordering_timed_out,
		     stat_timer_poll_retransmit_timed_out,
		     stat_timer_status_prohibit_timed_out);

	len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_SDU_TO_RX = %d (bytes %d)\n",
		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
		     stat_rx_pdcp_sdu,
		     stat_rx_pdcp_bytes);
      }
      
      rlc_status = rlc_stat_req(&ctxt,
				SRB_FLAG_NO,
				DTCH-2, // DRB_IDENTITY
				&stat_rlc_mode,
				&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);
      
      if (rlc_status == RLC_OP_STATUS_OK) {
	len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_SDU_TO_TX = %d (bytes %d)\tNB_SDU_TO_TX_DISC %d (bytes %d)\n",
		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
		     stat_tx_pdcp_sdu,
		     stat_tx_pdcp_bytes,
		     stat_tx_pdcp_sdu_discarded,
		     stat_tx_pdcp_bytes_discarded);
	
	len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_TX_DATA   = %d (bytes %d)\tNB_TX_CONTROL %d (bytes %d)\tNB_TX_RETX %d (bytes %d)\tNB_TX_RETX_BY_STATUS = %d (bytes %d)\n",
		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
		     stat_tx_data_pdu,
		     stat_tx_data_bytes,
		     stat_tx_control_pdu,
		     stat_tx_control_bytes,
		     stat_tx_retransmit_pdu,
		     stat_tx_retransmit_bytes,
		     stat_tx_retransmit_pdu_by_status,
		     stat_tx_retransmit_bytes_by_status);
		
	
	len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_RX_DATA   = %d (bytes %d)\tNB_RX_CONTROL %d (bytes %d)\tNB_RX_DUPL %d (bytes %d)\tNB_RX_DROP = %d (bytes %d)\tNB_RX_OUT_OF_WINDOW = %d (bytes %d)\n",
		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
		     stat_rx_data_pdu,
		     stat_rx_data_bytes,
		     stat_rx_control_pdu,
		     stat_rx_control_bytes,
		     stat_rx_data_pdus_duplicate,
		     stat_rx_data_bytes_duplicate,
		     stat_rx_data_pdu_dropped,
		     stat_rx_data_bytes_dropped,
		     stat_rx_data_pdu_out_of_window,
		     stat_rx_data_bytes_out_of_window);
	

	len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, RX_REODERING_TIMEOUT = %d\tRX_POLL_RET_TIMEOUT %d\tRX_PROHIBIT_TIME_OUT %d\n",
		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
		     stat_timer_reordering_timed_out,
		     stat_timer_poll_retransmit_timed_out,
		     stat_timer_status_prohibit_timed_out);

	len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_SDU_TO_RX = %d (bytes %d)\n",
		     (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE",
		     stat_rx_pdcp_sdu,
		     stat_rx_pdcp_bytes);

      }  		
406 407
    }
  }
408
  
409
  return len + 1 /* SR: for trailing \0 */;
410
}
411

412
#ifdef PROC
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
#ifndef USER_MODE
static int openair2_stats_read(char *buffer, char **my_buffer, off_t off, int length)
#else
int openair2_stats_read(char *buffer, char **my_buffer, off_t off, int length)
#endif
{

  int len = 0,fg,Overhead, Sign;
  unsigned int i,j,k,kk;
  unsigned int Mod_id = 0,CH_index;
  unsigned int tx_pdcp_sdu;
  unsigned int tx_pdcp_sdu_discarded;
  unsigned int tx_retransmit_pdu_unblock;
  unsigned int tx_retransmit_pdu_by_status;
  unsigned int tx_retransmit_pdu;
  unsigned int tx_data_pdu;
  unsigned int tx_control_pdu;
  unsigned int rx_sdu;
431
  unsigned int rx_error_pdu;
432 433 434 435 436
  unsigned int rx_data_pdu;
  unsigned int rx_data_pdu_out_of_window;
  unsigned int rx_control_pdu;

  //    if (mac_xface->is_cluster_head == 0) {
437
  for (k=0; k<NB_INST; k++) {
438 439 440



441
    if (Mac_rlc_xface->Is_cluster_head[k] == 0) {
442
#ifndef PHY_EMUL_ONE_MACHINE
443
      Mod_id=k-NB_CH_INST;
444 445 446

      len+=sprintf(&buffer[len],"UE TTI: %d\n",Mac_rlc_xface->frame);

447 448 449 450 451 452 453 454 455
      for (CH_index = 0; CH_index<NB_CNX_UE; CH_index++) {


        if (UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Active==1) {
          len+=sprintf(&buffer[len],"CH %d: Wideband SINR %d dB---\n",
                       CH_index,UE_mac_inst[Mod_id].Def_meas[CH_index].Wideband_sinr);
          len+=sprintf(&buffer[len],"CH %d: Subband SINR (dB) :",
                       CH_index);

456
          for (fg=0; fg<NUMBER_OF_MEASUREMENT_SUBBANDS; fg++) {
457
            len+=sprintf(&buffer[len],"%d ",UE_mac_inst[Mod_id].Def_meas[CH_index].Sinr_meas[0][fg]);
458
          }
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490

          len+=sprintf(&buffer[len],"\n");


          len+=sprintf(&buffer[len],"BCCH %d, NB_RX_MAC = %d (%d errors)\n",
                       UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.Lchan_id.Index,
                       UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.NB_RX,
                       UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.NB_RX_ERRORS);



          len+=sprintf(&buffer[len],"CCCH %d, NB_RX_MAC = %d (%d errors)\n",
                       UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.Lchan_id.Index,
                       UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.NB_RX,
                       UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.NB_RX_ERRORS);


          len+=sprintf(&buffer[len],"LCHAN %d (DCCH), NB_TX_MAC = %d (%d bits/TTI, %d kbits/sec), NB_RX_MAC = %d (%d errors)\n",
                       UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.Lchan_id.Index,
                       UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_TX,
                       UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.output_rate,
                       (10*UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.output_rate)>>5,
                       UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_RX,
                       UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_RX_ERRORS);

          for(i=1; i<NB_RAB_MAX; i++) {
            if (UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Active==1) {
              Overhead=UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate - Pdcp_stats_tx_rate[k][CH_index][i];

              if(Overhead<0) {
                Overhead=-Overhead;
                Sign=-1;
491 492 493
              } else {
                Sign=1;
              }
494

495 496
              len+=sprintf(&buffer[len],
                           "[PDCP]LCHAN %d: NB_TX = %d ,Tx_rate =(%d bits/TTI ,%d Kbits/s), NB_RX = %d ,Rx_rate =(%d bits/TTI ,%d Kbits/s) , LAYER2 TX OVERHEAD: %d Kbits/s\n",
497 498 499 500 501 502 503 504 505 506 507
                           UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
                           Pdcp_stats_tx[k][CH_index][i],
                           Pdcp_stats_tx_rate[k][CH_index][i],
                           (10*Pdcp_stats_tx_rate[k][CH_index][i])>>5,
                           Pdcp_stats_rx[k][CH_index][i],
                           Pdcp_stats_rx_rate[k][CH_index][i],
                           (10*Pdcp_stats_rx_rate[k][CH_index][i])>>5,
                           Sign*(10*Overhead)>>5);


              int status =  rlc_stat_req     (k,
508
                                              UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
                                              &tx_pdcp_sdu,
                                              &tx_pdcp_sdu_discarded,
                                              &tx_retransmit_pdu_unblock,
                                              &tx_retransmit_pdu_by_status,
                                              &tx_retransmit_pdu,
                                              &tx_data_pdu,
                                              &tx_control_pdu,
                                              &rx_sdu,
                                              &rx_error_pdu,
                                              &rx_data_pdu,
                                              &rx_data_pdu_out_of_window,
                                              &rx_control_pdu) ;

              if (status == RLC_OP_STATUS_OK) {
                len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_SDU_TO_TX = %d\tNB_SDU_DISC %d\tNB_RX_SDU %d\n",
                             UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
                             tx_pdcp_sdu,
                             tx_pdcp_sdu_discarded,
                             rx_sdu);
                len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_TB_TX_DATA = %d\tNB_TB_TX_CONTROL %d\tNB_TX_TB_RETRANS %d",
                             UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
                             tx_data_pdu,
                             tx_control_pdu,
                             tx_retransmit_pdu);
                len+=sprintf(&buffer[len],"\tRLC LCHAN %d, NB_TX_TB_RETRANS_BY_STATUS = %d\tNB_TX_TB_RETRANS_PADD %d\n",
                             UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
                             tx_retransmit_pdu_by_status,
                             tx_retransmit_pdu_unblock);
                len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_RX_DATA = %d\tNB_RX_TB_OUT_WIN %d\tNB_RX_TB_CORRUPT %d\n",
                             UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
                             rx_data_pdu,
                             rx_data_pdu_out_of_window,
                             rx_error_pdu);
              }

              len+=sprintf(&buffer[len],"[MAC]: LCHAN %d, NB_TX_MAC = %d (%d bits/TTI, %d kbits/s), NB_RX_MAC = %d (%d errors)\n",
                           UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index,
                           UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_TX,
                           UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate,
                           (10*UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate)>>5,
                           UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX,
                           UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_ERRORS);
              len+=sprintf(&buffer[len],"        TX per TB: ");

553
              for(kk=0; kk<MAX_NUMBER_TB_PER_LCHAN/2; kk++) {
554
                len+=sprintf(&buffer[len],"%d . ",UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_TX_TB[kk]);
555
              }
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571

              len+=sprintf(&buffer[len],"\n");
              len+=sprintf(&buffer[len],"        RXerr per TB: ");

              for(kk=0; kk<MAX_NUMBER_TB_PER_LCHAN/2; kk++)
                len+=sprintf(&buffer[len],"%d/%d . ",UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_ERRORS_TB[kk],
                             UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_TB[kk]);

              len+=sprintf(&buffer[len],"\n");



            }

          }
        }
572
      }
573

574
#endif //PHY_EMUL_ONE_MACHINE
575
    } else if(Mac_rlc_xface->Is_cluster_head[k] ==1) {
576

577
      Mod_id=k;
578 579
      len+=sprintf(&buffer[len],
                   "-------------------------------------------------------------------CH %d: TTI: %d------------------------------------------------------------------\n",
580 581 582 583 584 585 586 587 588
                   NODE_ID[Mod_id],Mac_rlc_xface->frame);

      for(i=1; i<=NB_CNX_CH; i++) {
        if (CH_mac_inst[Mod_id].Dcch_lchan[i].Active==1) {
          len+=sprintf(&buffer[len],"\nMR index %d: DL SINR (feedback) %d dB, CQI: %s\n\n",
                       i,//CH_rrc_inst[Mod_id].Info.UE_list[i].L2_id[0],
                       CH_mac_inst[Mod_id].Def_meas[i].Wideband_sinr,
                       print_cqi(CH_mac_inst[Mod_id].Def_meas[i].cqi));

589 590
          len+=sprintf(&buffer[len],
                       "[MAC] LCHAN %d (DCCH), NB_TX_MAC= %d (%d bits/TTI, %d kbits/s), NB_RX_MAC= %d (errors %d, sacch errors %d, sach errors %d, sach_missing %d)\n\n",
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
                       CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.Lchan_id.Index,
                       CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_TX,
                       CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.output_rate,
                       (10*CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.output_rate)>>5,
                       CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX,
                       CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_ERRORS,
                       CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACCH_ERRORS,
                       CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACH_ERRORS,
                       CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACH_MISSING);

          for(j=0; j<NB_RAB_MAX; j++) {
            if (CH_mac_inst[Mod_id].Dtch_lchan[j][i].Active==1) {
              Overhead=CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate - Pdcp_stats_tx_rate[k][i][j];

              if(Overhead<0) {
                Overhead=-Overhead;
                Sign=-1;
608 609 610
              } else {
                Sign=1;
              }
611

612 613
              len+=sprintf(&buffer[len],
                           "[PDCP]LCHAN %d: NB_TX = %d ,Tx_rate =(%d bits/TTI ,%d Kbits/s), NB_RX = %d ,Rx_rate =(%d bits/TTI ,%d Kbits/s), LAYER2 TX OVERHEAD= %d Kbits/s\n",
614 615 616 617 618 619 620 621 622
                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
                           Pdcp_stats_tx[k][i][j],
                           Pdcp_stats_tx_rate[k][i][j],
                           (10*Pdcp_stats_tx_rate[k][i][j])>>5,
                           Pdcp_stats_rx[k][i][j],
                           Pdcp_stats_rx_rate[k][i][j],
                           (10*Pdcp_stats_rx_rate[k][i][j])>>5,
                           Sign*(10*Overhead)>>5);
              int status =  rlc_stat_req     (k,
623
                                              CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
                                              &tx_pdcp_sdu,
                                              &tx_pdcp_sdu_discarded,
                                              &tx_retransmit_pdu_unblock,
                                              &tx_retransmit_pdu_by_status,
                                              &tx_retransmit_pdu,
                                              &tx_data_pdu,
                                              &tx_control_pdu,
                                              &rx_sdu,
                                              &rx_error_pdu,
                                              &rx_data_pdu,
                                              &rx_data_pdu_out_of_window,
                                              &rx_control_pdu) ;
              /*
              if (status == RLC_OP_STATUS_OK) {
              len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_SDU_TO_TX = %d\tNB_SDU_DISC %d\tNB_RX_SDU %d\n",
                  CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
               tx_pdcp_sdu,
               tx_pdcp_sdu_discarded,
               rx_sdu);
              len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_TB_TX_DATA = %d\tNB_TB_TX_CONTROL %d\tNB_TX_TB_RETRANS %\n",
                  CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
               tx_data_pdu,
               tx_control_pdu,
               tx_retransmit_pdu);
              len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_TX_TB_RETRANS_BY_STATUS = %d\tNB_TX_TB_RETRANS_PADD %d\n",
                  CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
               tx_retransmit_pdu_by_status,
               tx_retransmit_pdu_unblock);
              len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_RX_DATA = %d\tNB_RX_TB_OUT_WIN %d\tNB_RX_TB_CORRUPT %d\n",
                  CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
               rx_data_pdu,
               rx_data_pdu_out_of_window,
               rx_error_pdu);
              }
              */
659 660
              len+=sprintf(&buffer[len],
                           "[MAC]LCHAN %d (CNX %d,RAB %d), NB_TX_MAC= %d (%d bits/TTI, %d kbit/s), NB_RX_MAC= %d (errors %d, sacch_errors %d, sach_errors %d, sach_missing %d)\n",
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index,
                           i,j,
                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_TX,
                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate,
                           (10*CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate)>>5,
                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX,
                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_ERRORS,
                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACCH_ERRORS,
                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACH_ERRORS,
                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACH_MISSING);
              len+=sprintf(&buffer[len],"[MAC][SCHEDULER] TX Arrival Rate %d, TX Service Rate %d, RX Arrival rate %d, RX Service rate %d, NB_BW_REQ_RX %d\n\n",
                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Arrival_rate,
                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Tx_rate,
                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Req_rate,
                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Rx_rate,
                           CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_BW_REQ_RX);

              /*
                      len+=sprintf(&buffer[len],"        TX per TB: ");
                      for(kk=0;kk<MAX_NUMBER_TB_PER_LCHAN/2;kk++)
                  len+=sprintf(&buffer[len],"%d.",CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_TX_TB[kk]);
                      len+=sprintf(&buffer[len],"\n");
                      len+=sprintf(&buffer[len],"        RXerr per TB: ");
                      for(kk=0;kk<MAX_NUMBER_TB_PER_LCHAN/2;kk++)
                  len+=sprintf(&buffer[len],"%d/%d . ",CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_ERRORS_TB[kk],
                         CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_TB[kk]);
                      len+=sprintf(&buffer[len],"\n");
              */
            }
          }
        }
692
      }
693

694 695
    }
  }
696 697

  return len;
698 699 700 701 702 703 704 705 706 707 708 709 710 711
}

#ifndef USER_MODE
static struct proc_dir_entry *proc_openair2_root;
/*
 * Initialize the module and add the /proc file.
 */
int add_openair2_stats()
{
  struct proc_dir_entry *pde;

  proc_openair2_root = proc_mkdir("openair2",0);
  // pde = proc_create_entry("lchan_stats", S_IFREG | S_IRUGO, proc_openair2_root);
  pde = proc_create_data("lchan_stats", S_IFREG | S_IRUGO, proc_openair2_root, NULL,openair2_stats_read);
712

713
  if (!pde) {
714
    printk("[OPENAIR][ERROR] can't create proc entry !\n");
715
  }
716

717 718 719 720 721 722 723 724 725 726 727
  return 0;
}
/*
 * Unregister the file when the module is closed.
 */
void remove_openair_stats()
{

  if (proc_openair2_root) {
    printk("[OPENAIR][CLEANUP] Removing openair proc entry\n");
    remove_proc_entry("lchan_stats", proc_openair2_root);
728

729 730 731
  }
}
#endif
732
#endif