From 597890ab6108059d71995c5f797fbb7e40ea0f64 Mon Sep 17 00:00:00 2001
From: Haruki NAOI <naoi.haruki@jp.fujitsu.com>
Date: Wed, 11 Apr 2018 19:01:43 +0900
Subject: [PATCH] eNB RLC Assertions(assert macros) skip & fix warning.

---
 openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_in_sdu.c |  9 +++++--
 .../LAYER2/RLC/AM_v9.3.0/rlc_am_reassembly.c  |  7 ++++-
 .../LAYER2/RLC/AM_v9.3.0/rlc_am_retransmit.c  | 27 ++++++++++++++-----
 .../LAYER2/RLC/AM_v9.3.0/rlc_am_rx_list.c     |  9 ++++---
 .../LAYER2/RLC/AM_v9.3.0/rlc_am_segment.c     | 17 +++++++++---
 .../RLC/AM_v9.3.0/rlc_am_status_report.c      | 14 +++++++---
 .../LAYER2/RLC/UM_v9.3.0/rlc_um_segment.c     |  6 ++---
 openair2/LAYER2/RLC/rlc.c                     |  4 +--
 openair2/LAYER2/RLC/rlc_mac.c                 |  2 +-
 9 files changed, 68 insertions(+), 27 deletions(-)

diff --git a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_in_sdu.c b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_in_sdu.c
index dff1545612..64e1847f90 100644
--- a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_in_sdu.c
+++ b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_in_sdu.c
@@ -130,8 +130,13 @@ rlc_am_pdu_sdu_data_cnf(
 
       for (pdu_sdu_index = 0; pdu_sdu_index < rlc_pP->tx_data_pdu_buffer[snP % RLC_AM_WINDOW_SIZE].nb_sdus; pdu_sdu_index++) {
         sdu_index = rlc_pP->tx_data_pdu_buffer[snP % RLC_AM_WINDOW_SIZE].sdus_index[pdu_sdu_index];
-        assert(sdu_index >= 0);
-        assert(sdu_index < RLC_AM_SDU_CONTROL_BUFFER_SIZE);
+        //assert(sdu_index >= 0);
+        //assert(sdu_index < RLC_AM_SDU_CONTROL_BUFFER_SIZE);
+        if(sdu_index < 0 || sdu_index >= RLC_AM_SDU_CONTROL_BUFFER_SIZE) {
+          LOG_E(RLC, "sdu_index error. sdu_index %d, pdu_sdu_index %d\n", sdu_index, pdu_sdu_index);
+          continue;
+        }
+        
         rlc_pP->input_sdus[sdu_index].nb_pdus_ack += 1;
 
         if ((rlc_pP->input_sdus[sdu_index].nb_pdus_ack == rlc_pP->input_sdus[sdu_index].nb_pdus) &&
diff --git a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_reassembly.c b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_reassembly.c
index 43a946cb0c..469b3461c0 100644
--- a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_reassembly.c
+++ b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_reassembly.c
@@ -57,7 +57,12 @@ rlc_am_reassembly (
   if (rlc_pP->output_sdu_in_construction == NULL) {
     rlc_pP->output_sdu_in_construction = get_free_mem_block (RLC_SDU_MAX_SIZE, __func__);
     rlc_pP->output_sdu_size_to_write = 0;
-    assert(rlc_pP->output_sdu_in_construction != NULL);
+    //assert(rlc_pP->output_sdu_in_construction != NULL);
+    if(rlc_pP->output_sdu_in_construction == NULL) {
+      LOG_E(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[REASSEMBLY PAYLOAD] output_sdu_in_construction is NULL\n",
+            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP));
+      return;
+    }
   }
 
   if (rlc_pP->output_sdu_in_construction != NULL) {
diff --git a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_retransmit.c b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_retransmit.c
index eb47b9ba28..1bde8ad1d0 100644
--- a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_retransmit.c
+++ b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_retransmit.c
@@ -60,10 +60,14 @@ boolean_t rlc_am_nack_pdu (
   sdu_size_t pdu_data_to_retx = 0;
 
   if (mb_p != NULL) {
-    assert(so_startP <= so_endP);
-
+    //assert(so_startP <= so_endP);
+    if(so_startP > so_endP) {
+      LOG_E(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[NACK-PDU] ERROR NACK MISSING PDU, so_startP %d, so_endP %d\n",
+            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),so_startP, so_endP);
+      status = FALSE;
+    }
     // Handle full PDU NACK first
-    if ((so_startP == 0) && (so_endP == 0x7FFF)) {
+    else if ((so_startP == 0) && (so_endP == 0x7FFF)) {
     	if ((prev_nack_snP != snP) && (tx_data_pdu_buffer_p->flags.ack == 0) && (tx_data_pdu_buffer_p->flags.max_retransmit == 0)) {
     		pdu_data_to_retx = tx_data_pdu_buffer_p->payload_size;
             /* Increment VtReTxNext if this is the first NACK or if some segments have already been transmitted */
@@ -82,12 +86,17 @@ boolean_t rlc_am_nack_pdu (
                   snP,
                   so_stopP);
         #endif
-            assert(tx_data_pdu_buffer_p->nack_so_start < tx_data_pdu_buffer_p->payload_size);
+            //assert(tx_data_pdu_buffer_p->nack_so_start < tx_data_pdu_buffer_p->payload_size);
+    	      if(tx_data_pdu_buffer_p->nack_so_start >= tx_data_pdu_buffer_p->payload_size){
+              LOG_E(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[NACK-PDU] ERROR NACK MISSING PDU, nack_so_start %d, payload_size %d\n",
+                    PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),tx_data_pdu_buffer_p->nack_so_start, tx_data_pdu_buffer_p->payload_size);
+    	        status = FALSE;
+    	      }
     	}
     	else {
     		status = FALSE;
     	}
-      }
+    }
     else if (tx_data_pdu_buffer_p->flags.max_retransmit == 0) {
     	// Handle Segment offset
 		if (so_endP == 0x7FFF) {
@@ -230,7 +239,7 @@ void rlc_am_ack_pdu (
       {
         LOG_E(RLC, "RLC AM Rx Status Report sn=%d acked twice but is pending for Retx vtA=%d vtS=%d LcId=%d\n",
               snP, rlc_pP->vt_a,rlc_pP->vt_s,rlc_pP->channel_id);
-         return NULL;
+         return;
       }
 /*
     	AssertFatal (tx_data_pdu_buffer->flags.ack == 0,
@@ -1264,7 +1273,11 @@ void rlc_am_tx_buffer_display (
         LOG_D(RLC, "SO:%04d->%04d)\t", tx_data_pdu_buffer_p->nack_so_start, tx_data_pdu_buffer_p->nack_so_stop);
       } else {
         for (i=0; i<tx_data_pdu_buffer_p->num_holes; i++) {
-          assert(i < RLC_AM_MAX_HOLES_REPORT_PER_PDU);
+          //assert(i < RLC_AM_MAX_HOLES_REPORT_PER_PDU);
+          if(i >= RLC_AM_MAX_HOLES_REPORT_PER_PDU) {
+            LOG_E(RLC, "num_holes error. %d %d %d\n", tx_data_pdu_buffer_p->num_holes, i, RLC_AM_MAX_HOLES_REPORT_PER_PDU);
+            break;
+          }
           LOG_D(RLC, "SO:%04d->%04d)\t", tx_data_pdu_buffer_p->hole_so_start[i], tx_data_pdu_buffer_p->hole_so_stop[i]);
         }
       }
diff --git a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_rx_list.c b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_rx_list.c
index 2691107f02..383fd489b9 100644
--- a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_rx_list.c
+++ b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_rx_list.c
@@ -1649,7 +1649,8 @@ list2_insert_before_element (
 
     return element_to_insert_pP;
   } else {
-    assert(2==1);
+    //assert(2==1);
+    LOG_E(RLC, "list2_insert_before_element error. element_to_insert_pP %p, element_pP %p\n", element_to_insert_pP,element_pP);
     return NULL;
   }
 }
@@ -1676,7 +1677,8 @@ list2_insert_after_element (
 
     return element_to_insert_pP;
   } else {
-    assert(2==1);
+    //assert(2==1);
+    LOG_E(RLC, "list2_insert_after_element error. element_to_insert_pP %p, element_pP %p\n", element_to_insert_pP,element_pP);
     return NULL;
   }
 }
@@ -1726,7 +1728,8 @@ rlc_am_rx_list_display (
       //if (cursor_p == cursor_p->next) {
       //    rlc_am_v9_3_0_test_print_trace();
       //}
-      assert(cursor_p != cursor_p->next);
+      //assert(cursor_p != cursor_p->next);
+      LOG_E(RLC, "rlc_am_rx_list_display error. cursor_p %p, cursor_p->next %p\n", cursor_p, cursor_p->next);
       cursor_p = cursor_p->next;
       loop++;
     }
diff --git a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_segment.c b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_segment.c
index c16e897bb6..1bd0dce9cb 100644
--- a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_segment.c
+++ b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_segment.c
@@ -299,7 +299,12 @@ void rlc_am_segment_10 (
 
       pdu_mngt_p->sdus_index[pdu_mngt_p->nb_sdus++] = sdu_buffer_index;
       sdu_mngt_p->pdus_index[sdu_mngt_p->nb_pdus++] = rlc_pP->vt_s % RLC_AM_PDU_RETRANSMISSION_BUFFER_SIZE;
-      assert(sdu_mngt_p->nb_pdus < RLC_AM_MAX_SDU_FRAGMENTS);
+      //assert(sdu_mngt_p->nb_pdus < RLC_AM_MAX_SDU_FRAGMENTS);
+      if(sdu_mngt_p->nb_pdus >= RLC_AM_MAX_SDU_FRAGMENTS) {
+        LOG_E(RLC,PROTOCOL_RLC_AM_CTXT_FMT"[SEGMENT] loop error. %d %d\n",
+          PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP), sdu_mngt_p->nb_pdus, RLC_AM_MAX_SDU_FRAGMENTS);
+        break;
+      }
       sdu_buffer_index = (sdu_buffer_index + 1) % RLC_AM_SDU_CONTROL_BUFFER_SIZE;
     }
 
@@ -462,11 +467,11 @@ void rlc_am_segment_10 (
           rlc_pP->current_sdu_index = (rlc_pP->current_sdu_index + 1) % RLC_AM_SDU_CONTROL_BUFFER_SIZE;
         }
       } else {
-        LOG_T(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEGMENT] Filling  PDU with %d all remaining bytes of SDU and reduce TB size by %d bytes\n",
+        LOG_E(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEGMENT] Filling  PDU with %d all remaining bytes of SDU and reduce TB size by %d bytes\n",
               PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),
               sdu_mngt_p->sdu_remaining_size,
               pdu_remaining_size - sdu_mngt_p->sdu_remaining_size);
-        assert(1!=1);
+        //assert(1!=1);
         memcpy(data, data_sdu_p, sdu_mngt_p->sdu_remaining_size);
         pdu_mngt_p->payload_size += sdu_mngt_p->sdu_remaining_size;
         pdu_remaining_size = pdu_remaining_size - sdu_mngt_p->sdu_remaining_size;
@@ -520,7 +525,11 @@ void rlc_am_segment_10 (
     pdu_tb_req_p->data_ptr        = (unsigned char*)pdu_p;
     pdu_tb_req_p->tb_size         = data_pdu_size - pdu_remaining_size;
 //#warning "why 3000: changed to RLC_SDU_MAX_SIZE "
-    assert(pdu_tb_req_p->tb_size < RLC_SDU_MAX_SIZE );
+    //assert(pdu_tb_req_p->tb_size < RLC_SDU_MAX_SIZE );
+    if(pdu_tb_req_p->tb_size >= RLC_SDU_MAX_SIZE) {
+      LOG_E(RLC, PROTOCOL_RLC_AM_CTXT_FMT"[SEGMENT] tb_size error. %d, %d\n",
+            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP),pdu_tb_req_p->tb_size, RLC_SDU_MAX_SIZE);
+    }
     rlc_am_pdu_polling(ctxt_pP, rlc_pP, pdu_p, pdu_mngt_p->payload_size,true);
 
     //list_add_tail_eurecom (pdu_mem_p, &rlc_pP->segmentation_pdu_list);
diff --git a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_status_report.c b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_status_report.c
index 72b106d1c0..2640dc8072 100644
--- a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_status_report.c
+++ b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_status_report.c
@@ -154,7 +154,10 @@ rlc_am_write16_bit_field(
   signed int bits_to_writeP,
   const uint16_t valueP)
 {
-  assert(bits_to_writeP <= 16);
+  //assert(bits_to_writeP <= 16);
+  if(bits_to_writeP > 16) {
+    LOG_E(RLC, "bits_to_writeP error. %d\n", bits_to_writeP);
+  }
 
   if (bits_to_writeP > 8) {
     rlc_am_write8_bit_field(data_ppP,bit_pos_pP,  bits_to_writeP - 8, (uint8_t)(valueP >> 8));
@@ -309,8 +312,13 @@ rlc_am_receive_process_control_pdu(
     //     POLL_SN:
     //     - if t-PollRetransmit is running:
     //         - stop and reset t-PollRetransmit.
-    assert(ack_sn < RLC_AM_SN_MODULO);
-    assert(rlc_pP->control_pdu_info.num_nack < RLC_AM_MAX_NACK_IN_STATUS_PDU);
+    //assert(ack_sn < RLC_AM_SN_MODULO);
+    //assert(rlc_pP->control_pdu_info.num_nack < RLC_AM_MAX_NACK_IN_STATUS_PDU);
+    if(ack_sn >= RLC_AM_SN_MODULO || rlc_pP->control_pdu_info.num_nack >= RLC_AM_MAX_NACK_IN_STATUS_PDU) {
+      LOG_E(RLC, PROTOCOL_RLC_AM_CTXT_FMT" illegal ack_sn %d, num_nack %d\n",
+            PROTOCOL_RLC_AM_CTXT_ARGS(ctxt_pP,rlc_pP), ack_sn, rlc_pP->control_pdu_info.num_nack);
+      return;
+    }
 
     /* Note : ackSn can be equal to current vtA only in case the status pdu contains a list of nack_sn with same value = vtA with SOStart/SOEnd */
     /* and meaning the report is not complete due to not enough ressources to fill all SOStart/SOEnd of this NACK_SN */
diff --git a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_segment.c b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_segment.c
index 26a68849dd..6e5393f48a 100644
--- a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_segment.c
+++ b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_segment.c
@@ -748,13 +748,11 @@ rlc_um_segment_5 (const protocol_ctxt_t* const ctxt_pP, rlc_um_entity_t *rlc_pP)
         sdu_mngt_p    = NULL;
 
       } else {
-#if TRACE_RLC_UM_SEGMENT
-        LOG_D(RLC, PROTOCOL_RLC_UM_CTXT_FMT" Filling  PDU with %d all remaining bytes of SDU and reduce TB size by %d bytes\n",
+        LOG_E(RLC, PROTOCOL_RLC_UM_CTXT_FMT" Filling  PDU with %d all remaining bytes of SDU and reduce TB size by %d bytes\n",
               PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP,rlc_pP),
               sdu_mngt_p->sdu_remaining_size,
               pdu_remaining_size - sdu_mngt_p->sdu_remaining_size);
-#endif
-        assert(1!=1);
+        //assert(1!=1);
         memcpy(data, data_sdu_p, sdu_mngt_p->sdu_remaining_size);
         // reduce the size of the PDU
         continue_fill_pdu_with_sdu = 0;
diff --git a/openair2/LAYER2/RLC/rlc.c b/openair2/LAYER2/RLC/rlc.c
index 4353e213dc..c40d3472e6 100644
--- a/openair2/LAYER2/RLC/rlc.c
+++ b/openair2/LAYER2/RLC/rlc.c
@@ -374,7 +374,7 @@ rlc_op_status_t rlc_data_req     (const protocol_ctxt_t* const ctxt_pP,
 	
   //DevCheck(sdu_sizeP > 0, sdu_sizeP, 0, 0);
   if(sdu_sizeP <= 0) {
-    LOG_E(RLC, "sdu_sizeP %d, file %s, line %s\n", sdu_sizeP, __FILE__ ,__LINE__);
+    LOG_E(RLC, "sdu_sizeP %d, file %s, line %d\n", sdu_sizeP, __FILE__ ,__LINE__);
     return RLC_OP_STATUS_BAD_PARAMETER;
   }
 
@@ -409,7 +409,7 @@ rlc_op_status_t rlc_data_req     (const protocol_ctxt_t* const ctxt_pP,
   } else {
     rlc_mode = RLC_MODE_NONE;
     //AssertFatal (0 , "RLC not configured key %ju\n", key);
-  	LOG_E("RLC not configured key %ju\n", key);
+  	LOG_E(RLC, "not configured key %lu\n", key);
   	return RLC_OP_STATUS_OUT_OF_RESSOURCES;
   }
 
diff --git a/openair2/LAYER2/RLC/rlc_mac.c b/openair2/LAYER2/RLC/rlc_mac.c
index c949702ea3..53b801d78e 100644
--- a/openair2/LAYER2/RLC/rlc_mac.c
+++ b/openair2/LAYER2/RLC/rlc_mac.c
@@ -430,7 +430,7 @@ rlc_buffer_occupancy_t mac_rlc_get_buffer_occupancy_ind(
   /* Then this function is called during MAC multiplexing ue_get_sdu(), and it may be call several times for the same bearer if it is in AM mode and there are several PDU types to transmit */
   //AssertFatal(enb_flagP == FALSE,"RLC Tx mac_rlc_get_buffer_occupancy_ind function is not implemented for eNB LcId=%d\n", channel_idP);
 	if(enb_flagP != FALSE){
-		LOG_E("RLC Tx mac_rlc_get_buffer_occupancy_ind function is not implemented for eNB LcId=%d\n", channel_idP);
+		LOG_E(RLC, "Tx mac_rlc_get_buffer_occupancy_ind function is not implemented for eNB LcId=%u\n", channel_idP);
 		return 0;
 	}
 	
-- 
GitLab