From a663654418f6c39fac29af7492d2251ef33c280b Mon Sep 17 00:00:00 2001
From: Xenofon Foukas <x.foukas@sms.ed.ac.uk>
Date: Wed, 10 Feb 2016 13:41:56 +0000
Subject: [PATCH] Patch to get tx_queue size from RLC for the LCs of a UE

---
 openair2/ENB_APP/enb_agent_common.c | 7 +++++++
 openair2/ENB_APP/enb_agent_common.h | 2 +-
 openair2/ENB_APP/enb_agent_mac.c    | 8 ++++----
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/openair2/ENB_APP/enb_agent_common.c b/openair2/ENB_APP/enb_agent_common.c
index 7c820bfa5c..5ddcb39868 100644
--- a/openair2/ENB_APP/enb_agent_common.c
+++ b/openair2/ENB_APP/enb_agent_common.c
@@ -393,6 +393,13 @@ int get_ue_wcqi (mid_t mod_id, mid_t ue_id) {
 
   return ((UE_list_t *)enb_ue[mod_id])->eNB_UE_stats[UE_PCCID(mod_id,ue_id)][ue_id].dl_cqi;
 }
+int get_tx_queue_size(mid_t mod_id, mid_t ue_id, logical_chan_id_t channel_id)
+{
+	rnti_t rnti = get_ue_crnti(mod_id,ue_id);
+	uint16_t frame = (uint16_t) get_current_frame(mod_id);
+	mac_rlc_status_resp_t rlc_status = mac_rlc_status_ind(mod_id,rnti, mod_id,frame,ENB_FLAG_YES,MBMS_FLAG_NO,channel_id,0);
+	return rlc_status.bytes_in_buffer;
+}
 /*
  * timer primitives
  */
diff --git a/openair2/ENB_APP/enb_agent_common.h b/openair2/ENB_APP/enb_agent_common.h
index afa2179ff4..784c86bf6a 100644
--- a/openair2/ENB_APP/enb_agent_common.h
+++ b/openair2/ENB_APP/enb_agent_common.h
@@ -148,7 +148,7 @@ int get_ue_phr (mid_t mod_id, mid_t ue_id);
 
 int get_ue_wcqi (mid_t mod_id, mid_t ue_id);
 
-
+int get_tx_queue_size(mid_t mod_id, mid_t ue_id, logical_chan_id_t channel_id);
 
 
 
diff --git a/openair2/ENB_APP/enb_agent_mac.c b/openair2/ENB_APP/enb_agent_mac.c
index df614df60c..4a62c9dcbb 100644
--- a/openair2/ENB_APP/enb_agent_mac.c
+++ b/openair2/ENB_APP/enb_agent_mac.c
@@ -413,9 +413,9 @@ int enb_agent_mac_stats_reply(mid_t mod_id,
       /* Check flag for creation of RLC buffer status report */
       if (report_config->ue_report_type[i].ue_report_flags & PROTOCOL__PRP_UE_STATS_TYPE__PRUST_RLC_BS) {
 	// TODO: Fill in the actual RLC buffer status reports
-	ue_report[i]->n_rlc_report = 1; // Set this to the number of LCs for this UE
+	ue_report[i]->n_rlc_report = 3; // Set this to the number of LCs for this UE
 	Protocol__PrpRlcBsr ** rlc_reports;
-	rlc_reports = malloc(sizeof(Protocol__PrpRlcBsr) * ue_report[i]->n_rlc_report);
+	rlc_reports = malloc(sizeof(Protocol__PrpRlcBsr *) * ue_report[i]->n_rlc_report);
 	if (rlc_reports == NULL)
 	  goto error;
 	
@@ -427,10 +427,10 @@ int enb_agent_mac_stats_reply(mid_t mod_id,
 	    goto error;
 	  protocol__prp_rlc_bsr__init(rlc_reports[j]);
 	  //TODO:Set logical channel id
-	  rlc_reports[j]->lc_id = 1;
+	  rlc_reports[j]->lc_id = j+1;
 	  rlc_reports[j]->has_lc_id = 1;
 	  //TODO:Set tx queue size in bytes
-	  rlc_reports[j]->tx_queue_size = 10;
+	  rlc_reports[j]->tx_queue_size = get_tx_queue_size(enb_id,i,j+1);
 	  rlc_reports[j]->has_tx_queue_size = 1;
 	  //TODO:Set tx queue head of line delay in ms
 	  rlc_reports[j]->tx_queue_hol_delay = 100;
-- 
GitLab