From 8154c8fb8b7b95aeb7e68f02e6cd00959a0ea2d1 Mon Sep 17 00:00:00 2001
From: Navid Nikaein <navid.nikaein@eurecom.fr>
Date: Wed, 3 Jun 2015 21:34:56 +0000
Subject: [PATCH] fix OTG issues in oaisim without s1

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@7526 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c      | 12 ++--
 openair2/UTIL/OTG/otg_kpi.c                   | 32 ++++++++--
 .../SIMU/EXAMPLES/OSD/WEBXML/template_5.xml   | 58 +++++++++++--------
 targets/SIMU/USER/oaisim.c                    | 16 ++---
 targets/SIMU/USER/oaisim_config.c             |  4 +-
 targets/SIMU/USER/oaisim_functions.c          | 10 +++-
 6 files changed, 87 insertions(+), 45 deletions(-)

diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
index 616288b74..6064abaf7 100755
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
@@ -754,7 +754,7 @@ void pdcp_fifo_read_input_sdus_from_otg (const protocol_ctxt_t* const  ctxt_pP)
             ctxt_pP->subframe,
 	    src_id);
 
-          LOG_D(OTG,"[eNB %d] Frame %d sending packet %d from module %d on rab id %d (src %d, dst %d) pkt size %d for pdcp mode %d\n",
+          LOG_D(OTG,"[eNB %d] Frame %d sending packet %d from module %d on rab id %d (src %d, dst %d/%x) pkt size %d for pdcp mode %d\n",
                 ctxt.module_id,
                 ctxt.frame,
                 pkt_cnt_enb++,
@@ -762,6 +762,7 @@ void pdcp_fifo_read_input_sdus_from_otg (const protocol_ctxt_t* const  ctxt_pP)
                 rb_id,
                 src_id,
                 dst_id,
+		oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id][dst_id],
                 pkt_size,
                 pdcp_mode);
           result = pdcp_data_req(&ctxt,
@@ -779,20 +780,21 @@ void pdcp_fifo_read_input_sdus_from_otg (const protocol_ctxt_t* const  ctxt_pP)
           //rb_id= eNB_index * MAX_NUM_RB + DTCH;
 
 
-          LOG_D(OTG,"[UE %d] Frame %d: sending packet %d from module %d on rab id %d (src %d, dst %d) pkt size %d\n",
+          LOG_D(OTG,"[UE %d] Frame %d: sending packet %d from module %d on rab id %d (src %d/%x, dst %d) pkt size %d\n",
                 ctxt_pP->module_id,
                 ctxt_pP->frame,
                 pkt_cnt_ue++,
                 ctxt_pP->module_id,
                 rb_id,
-                ctxt_pP->module_id,
+                src_id,
+		pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id], // [src_id]
                 dst_id,
                 pkt_size);
           PROTOCOL_CTXT_SET_BY_MODULE_ID(
             &ctxt,
-            src_id,
+            ctxt_pP->module_id, //src_id,
             ENB_FLAG_NO,
-            pdcp_UE_UE_module_id_to_rnti[src_id],
+            pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id],// [src_id]
             ctxt_pP->frame,
             ctxt_pP->subframe,
 	    dst_id);
diff --git a/openair2/UTIL/OTG/otg_kpi.c b/openair2/UTIL/OTG/otg_kpi.c
index 29a76f148..f69c6940f 100644
--- a/openair2/UTIL/OTG/otg_kpi.c
+++ b/openair2/UTIL/OTG/otg_kpi.c
@@ -54,9 +54,20 @@ extern unsigned char NB_UE_INST;
 void tx_throughput(int src, int dst, int application)
 {
 
-  if (otg_info->tx_num_bytes[src][dst][application]>0)
-    otg_info->tx_throughput[src][dst][application]=((double)otg_info->tx_num_bytes[src][dst][application] *1000*8)/ (get_ctime()*1024); // unit Kbit/sec, if ctime in ms
-
+  if (otg_info->tx_num_bytes[src][dst][application]>0) {
+    //  otg_info->tx_throughput[src][dst][application]=((double)otg_info->tx_num_bytes[src][dst][application] *1000*8)/ (get_ctime()*1024); // unit Kbit/sec, if ctime in ms
+    if ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][application]) < get_ctime() )
+      otg_info->tx_throughput[src][dst][application]=((double)otg_info->tx_num_bytes[src][dst][application] *1000*8)/ ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][application])*1024); // unit Kbit/sec, if ctime in ms
+    else if (g_otg->flow_start[src][dst][application] < get_ctime() )
+      otg_info->tx_throughput[src][dst][application]=((double)otg_info->tx_num_bytes[src][dst][application] *1000*8)/ ((get_ctime() - g_otg->flow_start[src][dst][application])*1024);
+    else 
+      LOG_W("[src %d][dst %d][app %d] flow start time less than the simu time (start %d, duration %d, ctime %d)\n",
+	    src, dst, application,
+	    g_otg->flow_start[src][dst][application],
+	    g_otg->flow_duration[src][dst][application],
+	    get_ctime());
+  }
+  
   if (otg_info->tx_num_bytes_background[src][dst]>0)
     otg_info->tx_throughput_background[src][dst]=((double)otg_info->tx_num_bytes_background[src][dst]*1000*8)/ (get_ctime()*1024); // unit Kbit/sec, if ctime in ms
 
@@ -76,8 +87,19 @@ void tx_throughput(int src, int dst, int application)
 void rx_goodput(int src, int dst, int application)
 {
 
-  if (otg_info->rx_num_bytes[src][dst][application]>0)
-    otg_info->rx_goodput[src][dst][application]=((double)otg_info->rx_num_bytes[src][dst][application]*1000*8)/(get_ctime()*1024); // unit kB/sec, if ctime in ms
+  if (otg_info->rx_num_bytes[src][dst][application]>0) {
+    // otg_info->rx_goodput[src][dst][application]=((double)otg_info->rx_num_bytes[src][dst][application]*1000*8)/(get_ctime()*1024); // unit kB/sec, if ctime in ms
+if ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][application]) < get_ctime() )
+      otg_info->rx_goodput[src][dst][application]=((double)otg_info->rx_num_bytes[src][dst][application] *1000*8)/ ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][application])*1024); // unit Kbit/sec, if ctime in ms
+    else if (g_otg->flow_start[src][dst][application] < get_ctime() )
+      otg_info->rx_goodput[src][dst][application]=((double)otg_info->rx_num_bytes[src][dst][application] *1000*8)/ ((get_ctime() - g_otg->flow_start[src][dst][application])*1024);
+    else 
+      LOG_W("[src %d][dst %d][app %d] flow start time less than the simu time (start %d, duration %d, ctime %d)\n",
+	    src, dst, application,
+	    g_otg->flow_start[src][dst][application],
+	    g_otg->flow_duration[src][dst][application],
+	    get_ctime());
+  }
 
   if (otg_info->rx_num_bytes_background[src][dst]>0)
     otg_info->rx_goodput_background[src][dst]=((double)otg_info->rx_num_bytes_background[src][dst] *1000*8)/(get_ctime()*1024); // unit kB/sec, if ctime in ms
diff --git a/targets/SIMU/EXAMPLES/OSD/WEBXML/template_5.xml b/targets/SIMU/EXAMPLES/OSD/WEBXML/template_5.xml
index bf5d14653..32526c6f6 100644
--- a/targets/SIMU/EXAMPLES/OSD/WEBXML/template_5.xml
+++ b/targets/SIMU/EXAMPLES/OSD/WEBXML/template_5.xml
@@ -3,8 +3,8 @@
     <FADING>
       <LARGE_SCALE>urban</LARGE_SCALE>
       <FREE_SPACE_MODEL_PARAMETERS>
-	<PATHLOSS_EXPONENT>3.67</PATHLOSS_EXPONENT>
-	<PATHLOSS_0_dB>-128</PATHLOSS_0_dB><!--pathloss at 1km -->
+	<PATHLOSS_EXPONENT>2.67</PATHLOSS_EXPONENT>
+	<PATHLOSS_0_dB>-100</PATHLOSS_0_dB><!--pathloss at 1km -->
       </FREE_SPACE_MODEL_PARAMETERS>
       <SMALL_SCALE>AWGN</SMALL_SCALE>
     </FADING>
@@ -29,8 +29,8 @@
   
   <TOPOLOGY_CONFIG>	
     <AREA>			
-      <X_m>500</X_m>
-      <Y_m>500</Y_m>	
+      <X_m>1000</X_m>
+      <Y_m>1000</Y_m>	
     </AREA>
     <MOBILITY> 
       <UE_MOBILITY>
@@ -38,14 +38,12 @@
 	<RANDOM_UE_DISTRIBUTION>
 	  <NUMBER_OF_NODES>2</NUMBER_OF_NODES>
 	</RANDOM_UE_DISTRIBUTION>
-	<UE_MOBILITY_TYPE>STATIC</UE_MOBILITY_TYPE>
+	<UE_MOBILITY_TYPE>RWP</UE_MOBILITY_TYPE>
 	<UE_MOVING_DYNAMICS>
 	  <MIN_SPEED_mps>1</MIN_SPEED_mps>
-	  <MAX_SPEED_mps>200</MAX_SPEED_mps>
+	  <MAX_SPEED_mps>2</MAX_SPEED_mps>
 	  <MIN_SLEEP_ms>0.1</MIN_SLEEP_ms>
-	  <MAX_SLEEP_ms>5.0</MAX_SLEEP_ms>
-	  <MIN_JOURNEY_TIME_ms>0.1</MIN_JOURNEY_TIME_ms>
-	  <MAX_JOURNEY_TIME_ms>10</MAX_JOURNEY_TIME_ms>
+	  <MAX_SLEEP_ms>15.0</MAX_SLEEP_ms>
 	</UE_MOVING_DYNAMICS>
       </UE_MOBILITY>
       <eNB_MOBILITY>
@@ -61,32 +59,46 @@
  
   <APPLICATION_CONFIG>
     <PREDEFINED_TRAFFIC>
-      <SOURCE_ID>0</SOURCE_ID> <!-- valid formats are: -->					
-      <APPLICATION_TYPE>scbr</APPLICATION_TYPE> <!-- OPTIONS: scbr,mcbr,bcbr, gaming_OA, gaming_TF,  m2m_AP, m2m_BR, , random, ,full_buffer --> 
-      <DESTINATION_ID>1:2</DESTINATION_ID> <!-- valid formats are: -->
-    </PREDEFINED_TRAFFIC>
-    <PREDEFINED_TRAFFIC>
-      <SOURCE_ID>1:2</SOURCE_ID> <!-- valid formats are: -->					
-      <APPLICATION_TYPE>scbr</APPLICATION_TYPE> <!-- OPTIONS: scbr,mcbr,bcbr, gaming_OA, gaming_TF,  m2m_AP, m2m_BR, , random, ,full_buffer --> 
-      <DESTINATION_ID>0</DESTINATION_ID> <!-- valid formats are: -->
+      <SOURCE_ID>0</SOURCE_ID> 
+      <APPLICATION_TYPE>mcbr</APPLICATION_TYPE> 
+      <DESTINATION_ID>1:2</DESTINATION_ID> 
+      <FLOW_START_ms>100</FLOW_START_ms> 
+      <FLOW_DURATION_ms>6000</FLOW_DURATION_ms>
     </PREDEFINED_TRAFFIC>
+
+    <CUSTOMIZED_TRAFFIC>	 
+      <SOURCE_ID>1:2</SOURCE_ID> 		
+      <TRANSPORT_PROTOCOL>udp</TRANSPORT_PROTOCOL> 
+      <FLOW_START_ms>100</FLOW_START_ms> 
+      <FLOW_DURATION_ms>6000</FLOW_DURATION_ms>
+      <IP_VERSION>ipv4</IP_VERSION> 
+      <DESTINATION_ID>0</DESTINATION_ID> 
+      <IDT_DIST>uniform</IDT_DIST>  
+      <IDT_MIN_ms>10</IDT_MIN_ms>  
+      <IDT_MAX_ms>100</IDT_MAX_ms>  
+      <SIZE_DIST>uniform</SIZE_DIST>   
+      <SIZE_MIN_byte>64</SIZE_MIN_byte>  
+      <SIZE_MAX_byte>1024</SIZE_MAX_byte>  
+    </CUSTOMIZED_TRAFFIC>
   
   </APPLICATION_CONFIG>
   
   <EMULATION_CONFIG>
     <EMULATION_TIME_ms>10000</EMULATION_TIME_ms> <!--set to infinity--> 
     
+    <CURVE>disable</CURVE>
     <PERFORMANCE_METRICS>
-      <THROUGHPUT>1</THROUGHPUT>
+      <THROUGHPUT>enable</THROUGHPUT>
+      <LATENCY>enable</LATENCY>
+      <LOSS_RATE>enable</LOSS_RATE>
     </PERFORMANCE_METRICS>
     <LOG>  <!-- set the global log level -->
-      <LEVEL>debug</LEVEL>
-      <VERBOSITY>medium</VERBOSITY> <!-- low, medium, high, full -->
-      <INTERVAL>1</INTERVAL>
-    </LOG>		
+      <LEVEL>info</LEVEL>
+      <VERBOSITY>low</VERBOSITY>
+    </LOG>				
     <SEED_VALUE>0</SEED_VALUE>	 <!-- value 0 means randomly generated by OAI -->
     
    </EMULATION_CONFIG>
  
-   <PROFILE>OCM_OMG</PROFILE>	
+   <PROFILE>OCM_OMG_OTG</PROFILE>	
 </OAI_EMULATION>
diff --git a/targets/SIMU/USER/oaisim.c b/targets/SIMU/USER/oaisim.c
index 7707d4807..8e1e3a98c 100644
--- a/targets/SIMU/USER/oaisim.c
+++ b/targets/SIMU/USER/oaisim.c
@@ -1198,10 +1198,7 @@ l2l1_task (void *args_p)
   //end of frame
 
   stop_meas (&oaisim_stats);
-
-#if defined(ENABLE_ITTI)
-  itti_terminate_tasks(TASK_L2L1);
-#endif
+  oai_shutdown ();
 
 #ifdef PRINT_STATS
 
@@ -1226,6 +1223,10 @@ l2l1_task (void *args_p)
 
 #endif
 
+#if defined(ENABLE_ITTI)
+  itti_terminate_tasks(TASK_L2L1);
+#endif
+
   return NULL;
 }
 
@@ -1364,7 +1365,7 @@ main (int argc, char **argv)
         ">>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU Ending <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
 
   raise (SIGINT);
-  oai_shutdown ();
+  //  oai_shutdown ();
 
   return (0);
 }
@@ -1808,9 +1809,10 @@ oai_shutdown (void)
 #endif
 
   //Perform KPI measurements
-  if (oai_emulation.info.otg_enabled == 1)
+  if (oai_emulation.info.otg_enabled == 1){
+    LOG_N(EMU,"calling OTG kpi gen .... \n");
     kpi_gen ();
-
+  }
   if (oai_emulation.info.opp_enabled == 1)
     print_opp_meas ();
 
diff --git a/targets/SIMU/USER/oaisim_config.c b/targets/SIMU/USER/oaisim_config.c
index d812fca53..dfaf02508 100644
--- a/targets/SIMU/USER/oaisim_config.c
+++ b/targets/SIMU/USER/oaisim_config.c
@@ -450,14 +450,14 @@ int olg_config(void)
    //set_log(OCM,  LOG_INFO, 20);
    //set_log(OTG,  LOG_INFO, 1);
    set_comp_log(OCG,  LOG_ERR, 0x15,1);
-   set_comp_log(EMU,  LOG_ERR,  0x15,20);
+   set_comp_log(EMU,  LOG_DEBUG,  0x15,20);
    set_comp_log(MAC,  LOG_TRACE, 0x15,1);
    set_comp_log(RLC,  LOG_TRACE, 0x15,1);
    set_comp_log(PHY,  LOG_TRACE, 0x15, 1);
    set_comp_log(PDCP, LOG_DEBUG, 0x15,1);
    set_comp_log(RRC,  LOG_DEBUG, 0x15,1);
    set_comp_log(OCM,  LOG_ERR, 0x15,20);
-   set_comp_log(OTG,  LOG_INFO, 0x15,1);
+   set_comp_log(OTG,  LOG_DEBUG, 0x15,1);
    set_comp_log(OMG,  LOG_INFO, 0x15,1);
    set_comp_log(OPT,  LOG_ERR, 0x15,1);
 
diff --git a/targets/SIMU/USER/oaisim_functions.c b/targets/SIMU/USER/oaisim_functions.c
index 11d52ad6c..a1fda4611 100644
--- a/targets/SIMU/USER/oaisim_functions.c
+++ b/targets/SIMU/USER/oaisim_functions.c
@@ -1268,6 +1268,8 @@ void update_otg_eNB(module_id_t enb_module_idP, unsigned int ctime)
 {
 #if defined(USER_MODE) && defined(OAI_EMU)
 
+  int rrc_state=0; 
+
   if (oai_emulation.info.otg_enabled ==1 ) {
 
     int dst_id, app_id;
@@ -1277,9 +1279,11 @@ void update_otg_eNB(module_id_t enb_module_idP, unsigned int ctime)
       for_times += 1;
 
       // generate traffic if the ue is rrc reconfigured state
-      if (mac_eNB_get_rrc_status(enb_module_idP, dst_id) > 2 /*RRC_CONNECTED*/ ) {
-        if_times += 1;
-
+      //if ((rrc_state=mac_eNB_get_rrc_status(enb_module_idP, dst_id)) > 2 /*RRC_CONNECTED*/ ) {
+      if (mac_eNB_get_rrc_status(enb_module_idP, oai_emulation.info.eNB_ue_module_id_to_rnti[enb_module_idP][dst_id]) > 2 ){ 
+	
+	if_times += 1;
+	
         for (app_id=0; app_id<MAX_NUM_APPLICATION; app_id++) {
           otg_pkt = malloc (sizeof(Packet_otg_elt_t));
 
-- 
GitLab