otg_kpi.c 45.5 KB
Newer Older
1
/*******************************************************************************
nikaeinn's avatar
nikaeinn committed
2 3
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom
4

nikaeinn's avatar
nikaeinn committed
5 6 7 8
    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
9 10


nikaeinn's avatar
nikaeinn committed
11 12 13 14
    OpenAirInterface is distributed in the hope that 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.
15

nikaeinn's avatar
nikaeinn committed
16 17 18 19
    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is
    included in this distribution in the file called "COPYING". If not,
    see <http://www.gnu.org/licenses/>.
20 21

  Contact Information
nikaeinn's avatar
nikaeinn committed
22 23 24 25
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr

ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
27 28 29 30

*******************************************************************************/

/*! \file otg_kpi.c main used funstions to compute KPIs
31
* \brief define KPIs to compute for performance analysis
nikaeinn's avatar
nikaeinn committed
32
* \author Navid Nikaein and A. Hafsaoui
33 34 35
* \date 2012
* \version 0.1
* \company Eurecom
36
* \email: navid.nikaein@eurecom.fr
37 38 39 40 41
* \note
* \warning

*/

42 43 44 45 46
unsigned int start_log_latency=0;
unsigned int start_log_latency_bg=0;
unsigned int start_log_GP=0;
unsigned int start_log_GP_bg=0;
unsigned int start_log_jitter=0;
47 48 49 50 51 52 53

#include"otg_kpi.h"
#include"otg_externs.h"

extern unsigned char NB_eNB_INST;
extern unsigned char NB_UE_INST;

54 55 56
void tx_throughput(int src, int dst, int application)
{

nikaeinn's avatar
nikaeinn committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70
  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());
  }
  
71 72
  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
73 74

  if (otg_multicast_info->tx_num_bytes[src][dst][application]>0) {
75 76
    if (application < 2)
      otg_multicast_info->tx_throughput[src][dst]=((double)otg_multicast_info->tx_num_bytes[src][dst][application]*1000*8)/ (get_ctime()*1024); // unit Kbit/sec, if ctime in ms
77 78

    //otg_multicast_info->tx_num_bytes[src][dst][app] is 3 dimension param in otg_tx.c, only use [app]=0
79
    //    LOG_I(OTG,"DUY, get_ctime() [i=%d,j=%d,k=%d] = %.d\n", src,dst,application,get_ctime());
80
    LOG_I(OTG,"otg_multicast_info->tx_num_bytes[i=%d,j=%d,k=%d] = %.d\n", src,dst,application,otg_multicast_info->tx_num_bytes[src][dst][application]);
81 82
  }

83 84 85 86
}



87 88
void rx_goodput(int src, int dst, int application)
{
89

nikaeinn's avatar
nikaeinn committed
90 91 92 93 94 95 96 97 98 99 100 101 102
  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());
  }
103

104 105
  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
106 107

  if (otg_multicast_info->rx_num_bytes[src][dst][application]>0) {
108
    otg_multicast_info->rx_goodput[src][dst]=((double)otg_multicast_info->rx_num_bytes[src][dst][application] *1000*8)/(get_ctime()*1024); // unit kB/sec, if ctime in ms
109
    LOG_I(OTG,"otg_multicast_info->rx_num_bytes[i=%d,j=%d,k=%d] = %.d\n", src,dst,application,otg_multicast_info->rx_num_bytes[src][dst][application]);
110
  }
111 112 113 114 115
}




116 117
void rx_loss_rate_pkts(int src, int dst, int application)
{
118 119 120 121 122 123 124 125 126 127

  if (otg_info->rx_num_pkt[src][dst][application]<otg_info->tx_num_pkt[src][dst][application])
    otg_info->rx_loss_rate[src][dst][application]= 1 - ((double)otg_info->rx_num_pkt[src][dst][application]/otg_info->tx_num_pkt[src][dst][application]);
  else
    otg_info->rx_loss_rate[src][dst][application]=0;

  if (otg_info->rx_num_pkt_background[src][dst]<otg_info->tx_num_pkt_background[src][dst])
    otg_info->rx_loss_rate_background[src][dst]= 1 - ((double)otg_info->rx_num_pkt_background[src][dst]/otg_info->tx_num_pkt_background[src][dst]);
  else
    otg_info->rx_loss_rate_background[src][dst]=0;
128 129 130 131

  /*
  if (otg_info->rx_loss_rate[src][dst][application]>0)
  LOG_I(OTG, "LOSS_RATE (src=%d, dst=%d, appli %d ):: = %lf(pkts) [TX %d] [RX %d], [NB UL %d] [NB DL %d]\n",src, dst, application, otg_info->rx_loss_rate[src][dst][application], otg_info->tx_num_pkt[src][dst][application],otg_info->rx_num_pkt[src][dst][application],otg_info->nb_loss_pkts_ul[src][dst][application], otg_info->nb_loss_pkts_dl[src][dst][application]);
132 133
  */

134
  if (otg_multicast_info->rx_num_pkt[src][dst] < otg_multicast_info->tx_num_pkt[src][dst])
135 136 137 138
    otg_multicast_info->rx_loss_rate[src][dst]= 1 - ((double)otg_multicast_info->rx_num_pkt[src][dst][application]/otg_multicast_info->tx_num_pkt[src][dst][0]);
  else
    otg_multicast_info->rx_loss_rate[src][dst]=0;

139 140 141
}


142 143
void rx_loss_rate_bytes(int src, int dst, int application)
{
144 145 146 147 148

  if (otg_info->rx_num_pkt[src][dst][application]<otg_info->tx_num_pkt[src][dst][application])
    otg_info->rx_loss_rate[src][dst][application]= 1 - ((double)otg_info->rx_num_bytes[src][dst][application]/otg_info->tx_num_bytes[src][dst][application]);
  else
    otg_info->rx_loss_rate[src][dst][application]=0;
149

150 151 152 153
  LOG_I(OTG, "loss rate (src=%d, dst=%d, appli %d ):: = %lf(bytes) \n",src, dst, application, otg_info->rx_loss_rate[src][dst][application]);

}

154 155 156
void otg_kpi_nb_loss_pkts(void)
{
  unsigned int i,j,k;
157

158 159
  otg_info->total_loss_dl=0;
  otg_info->total_loss_ul=0;
160

161 162 163 164 165 166 167
  for (i=0; i<(NB_eNB_INST + NB_UE_INST); i++) {
    for (j=0; j<(NB_eNB_INST + NB_UE_INST); j++) {
      for (k=0; k<MAX_EMU_TRAFFIC; k++) {
        if (i<NB_eNB_INST)
          otg_info->total_loss_dl+=(otg_info->nb_loss_pkts_dl[i][j][k] + otg_info->nb_loss_pkts_background_dl[i][j]);
        else
          otg_info->total_loss_ul+=(otg_info->nb_loss_pkts_ul[i][j][k] + otg_info->nb_loss_pkts_background_ul[i][j]);
168 169 170 171 172
      }
    }
  }
}

173 174 175
void average_pkt_jitter(int src, int dst, int application)
{

nikaeinn's avatar
nikaeinn committed
176 177 178 179
  if (otg_info->rx_jitter_sample[src][dst][application] > 0 ) {
    otg_info->rx_jitter_avg[src][dst][application]/= otg_info->rx_jitter_sample[src][dst][application];
    otg_info->rx_jitter_avg_e2e[src][dst][application]/= otg_info->rx_jitter_sample[src][dst][application];
  } else {
180
    LOG_T(OTG,"[src %d][dst %d][app %d]number of samples for jitter calculation is %d\n",src, dst, application, otg_info->rx_jitter_sample[src][dst][application]);
181 182
  }

183 184 185 186 187
  if (otg_info->rx_jitter_avg[src][dst][application] > 0) {
    if (src<NB_eNB_INST)
      otg_info->average_jitter_dl+=otg_info->rx_jitter_avg[src][dst][application];
    else
      otg_info->average_jitter_ul+=otg_info->rx_jitter_avg[src][dst][application];
188

189 190
    LOG_T(OTG,"average_jitter_dl %lf average_jitter_ul %lf \n",otg_info->average_jitter_dl,otg_info->average_jitter_ul  );
  }
nikaeinn's avatar
nikaeinn committed
191 192 193 194 195 196

  if (otg_info->rx_jitter_avg_e2e[src][dst][application] > 0) {
    if (src<NB_eNB_INST)
      otg_info->average_jitter_dl_e2e+=otg_info->rx_jitter_avg_e2e[src][dst][application];
    else
      otg_info->average_jitter_ul_e2e+=otg_info->rx_jitter_avg_e2e[src][dst][application];
197

nikaeinn's avatar
nikaeinn committed
198 199 200
    LOG_T(OTG,"average_jitter_dl %lf average_jitter_ul %lf \n",otg_info->average_jitter_dl_e2e,otg_info->average_jitter_ul_e2e);
  }

201 202
}

203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
void average_total_jitter(void)
{
  unsigned int i,j,k;

  otg_info->average_jitter_dl=0;
  otg_info->average_jitter_ul=0;
  otg_info->average_jitter_dl_e2e=0;
  otg_info->average_jitter_ul_e2e=0;

  for (i=0; i<(NB_eNB_INST + NB_UE_INST); i++) {
    for (j=0; j<(NB_eNB_INST + NB_UE_INST); j++) {
      for (k=0; k<MAX_EMU_TRAFFIC; k++) {
        if (i<NB_eNB_INST) {
          otg_info->average_jitter_dl+=otg_info->rx_jitter_avg[i][j][k];
          otg_info->average_jitter_dl_e2e+=otg_info->rx_jitter_avg_e2e[i][j][k];

        } else {
          otg_info->average_jitter_ul+=otg_info->rx_jitter_avg[i][j][k];
          otg_info->average_jitter_ul_e2e+=otg_info->rx_jitter_avg_e2e[i][j][k];
        }
223 224 225
      }
    }
  }
226

227 228 229 230 231
  LOG_I(OTG,"average_jitter_dl %d average_jitter_ul %lf \n",otg_info->average_jitter_dl,otg_info->average_jitter_ul  );
  //  otg_info->average_jitter_dl/= (float)NB_UE_INST;
  // otg_info->average_jitter_ul/= (float)NB_UE_INST;
}

232 233
void kpi_gen()
{
234
  int i, j,k;
235

236 237 238 239 240 241 242 243
  int tx_total_bytes_dl=0;
  int tx_total_pkts_dl=0;
  int rx_total_bytes_dl=0;
  int rx_total_pkts_dl=0;
  int tx_total_bytes_ul=0;
  int tx_total_pkts_ul=0;
  int rx_total_bytes_ul=0;
  int rx_total_pkts_ul=0;
244 245 246 247

  float min_owd_dl=0;
  float max_owd_dl=0;

nikaeinn's avatar
nikaeinn committed
248 249 250
  float min_owd_dl_e2e=0;
  float max_owd_dl_e2e=0;

251 252 253 254 255 256 257 258
  int tx_total_bytes_dl_background=0;
  int tx_total_pkts_dl_background=0;
  int rx_total_bytes_dl_background=0;
  int rx_total_pkts_dl_background=0;
  int tx_total_bytes_ul_background=0;
  int tx_total_pkts_ul_background=0;
  int rx_total_bytes_ul_background=0;
  int rx_total_pkts_ul_background=0;
259

260
  float min_owd_ul=0;
261
  float max_owd_ul=0;
nikaeinn's avatar
nikaeinn committed
262
  float min_owd_ul_e2e=0;
263
  float max_owd_ul_e2e=0;
264

265 266 267 268 269 270 271

  int tx_total_bytes_dl_multicast=0;
  int tx_total_pkts_dl_multicast=0;
  int rx_total_bytes_dl_multicast=0;
  int rx_total_pkts_dl_multicast=0;


272
  int num_active_source=0;
273 274


275
  int dl_ok=1,ul_ok=1;
276

277 278
  char traffic_type[12];
  char traffic[30];
279

280
#ifdef STANDALONE
281
  FILE *file;
282
  file = fopen("log_OTG.txt", "w");
283
#else   // Maybe to do modifo log function in order to clear file before a new write !!!! 
284 285 286 287
  FILE *fc;
  fc=fopen("/tmp/otg.log","w");;

  if(fc!=0)
288
    fclose(fc);
289

290 291 292 293
#endif



294 295
  for (i=0; i<(NB_eNB_INST + NB_UE_INST); i++) {
    for (j=0; j<(NB_eNB_INST + NB_UE_INST); j++) {
296

297 298 299 300 301 302 303 304 305 306 307
      /*background stats*/
      if (i<NB_eNB_INST) {
        tx_total_bytes_dl_background+=otg_info->tx_num_bytes_background[i][j];
        tx_total_pkts_dl_background+=otg_info->tx_num_pkt_background[i][j];
        rx_total_bytes_dl_background+=otg_info->rx_num_bytes_background[i][j];
        rx_total_pkts_dl_background+=otg_info->rx_num_pkt_background[i][j];
      } else {
        tx_total_bytes_ul_background+=otg_info->tx_num_bytes_background[i][j];
        tx_total_pkts_ul_background+=otg_info->tx_num_pkt_background[i][j];
        rx_total_bytes_ul_background+=otg_info->rx_num_bytes_background[i][j];
        rx_total_pkts_ul_background+=otg_info->rx_num_pkt_background[i][j];
308
      }
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330

      for (k=0; k<MAX_NUM_APPLICATION; k++) {

        tx_throughput(i,j,k);
        rx_goodput(i,j,k);
        rx_loss_rate_pkts(i,j,k);
        average_pkt_jitter(i,j,k);

        /*
              LOG_I(OTG,"KPI: (src=%d, dst=%d, traffic=%d) NB TX Bytes= %d, NB packet TX= %d,  NB packet RX= %d\n ",
              i, j,  k,
              otg_info->tx_num_bytes[i][j][k],
              otg_info->tx_num_pkt[i][j][k],
              otg_info->rx_num_pkt[i][j][k]);
        */
        if (otg_multicast_info->tx_throughput[i][j]>0)  {
          //multicast
          tx_total_bytes_dl_multicast+=otg_multicast_info->tx_num_bytes[i][j][k];
          tx_total_pkts_dl_multicast+=otg_multicast_info->tx_num_pkt[i][j][k];
          rx_total_bytes_dl_multicast+=otg_multicast_info->rx_num_bytes[i][j][k];
          rx_total_pkts_dl_multicast+=otg_multicast_info->rx_num_pkt[i][j][k];

331
#ifdef STANDALONE
332
          LOG_I(OTG,"No stats for multicast ");       // do nothing
333
#else
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

          // Multicast
          //no multicast_status
          if (otg_multicast_info->tx_num_bytes[i][j][k]>0) {
            LOG_I(OTG,"----------------------------------------------------------\n");
            LOG_I(OTG,"Total Time (multicast) (ms)= %d \n", otg_info->ctime+1);

            //   LOG_I(OTG,"[%s] Multicast [eNB:%d -> UE:%d] \n",traffic_type, i, j);

            LOG_I(OTG,"[MULTICAST] Total packets(TX)= %d \n", otg_multicast_info->tx_num_pkt[i][j][k]);
            LOG_I(OTG,"[MULTICAST] Total bytes(TX)= %d \n", otg_multicast_info->tx_num_bytes[i][j][k]);
            LOG_I(OTG,"[MULTICAST] Total packets(RX)= %d \n", otg_multicast_info->rx_num_pkt[i][j][k]);
            LOG_I(OTG,"[MULTICAST] Total bytes(RX)= %d \n", otg_multicast_info->rx_num_bytes[i][j][k]);

            LOG_I(OTG,"[MULTICAST] TX throughput = %.7f (Kbit/s) \n", otg_multicast_info->tx_throughput[i][j]);
            LOG_I(OTG,"[MULTICAST] RX goodput = %.7f (Kbit/s) \n", otg_multicast_info->rx_goodput[i][j]);
            //   if (otg_multicast_info->rx_loss_rate[i][j]>0){
            //  LOG_I(OTG,"[MULTICAST] Loss rate = %lf \n", (otg_multicast_info->rx_loss_rate[i][j]));
            //  LOG_I(OTG,"[MULTICAST] NB Lost  packets=%d \n", (otg_multicast_info->tx_num_pkt[i][j][k]-otg_multicast_info->rx_num_pkt[i][j][k]));
            //}

            // if ((g_otg->background_stats==1)&&(otg_info->tx_num_bytes_background[i][j]>0)){
            LOG_F(OTG,"----------------------------------------------------------\n");
            LOG_F(OTG,"Total Time (multicast) (ms)= %d \n", otg_info->ctime+1);
            //  if (i<NB_eNB_INST){
            LOG_F(OTG,"[%s] DL [eNB:%d -> UE:%d] \n",traffic_type ,i, j);
            //else
            //    LOG_F(OTG,"[%s] UL [Ue:%d -> eNB:%d] \n",traffic_type, i, j);
            LOG_F(OTG,"[MULTICAST] Total packets(TX)= %d \n", otg_multicast_info->tx_num_pkt[i][j][k]);
            LOG_F(OTG,"[MULTICAST] Total bytes(TX)= %d \n", otg_multicast_info->tx_num_bytes[i][j][k]);
            LOG_F(OTG,"[MULTICAST] TX throughput = %.7f(Kbit/s) \n", otg_multicast_info->tx_throughput[i][j]);
            LOG_F(OTG,"[MULTICAST] RX goodput= %.7f (Kbit/s) \n", otg_multicast_info->rx_goodput[i][j]);

            if (otg_multicast_info->rx_loss_rate[i][j]>0) {
              LOG_F(OTG,"[MULTICAST] Loss rate = %lf \n", (otg_multicast_info->rx_loss_rate[i][j]));
              LOG_F(OTG,"[MULTICAST] NB Lost  packets=%d \n", (otg_multicast_info->tx_num_pkt[i][j][k]-otg_multicast_info->rx_num_pkt[i][j][k]));
            }
          }

373
#endif
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 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442

        }// end for multicast


        if ((otg_info->tx_throughput[i][j][k]>0)||((otg_info->tx_throughput_background[i][j]>0) && (otg_info->tx_num_bytes[i][j][k]>0)))  {

          num_active_source+=1;

          if (i<NB_eNB_INST) { // DL
            tx_total_bytes_dl+=otg_info->tx_num_bytes[i][j][k];
            tx_total_pkts_dl+=otg_info->tx_num_pkt[i][j][k];
            rx_total_bytes_dl+=otg_info->rx_num_bytes[i][j][k];
            rx_total_pkts_dl+=otg_info->rx_num_pkt[i][j][k];
            /*tx_total_bytes_dl_background+=otg_info->tx_num_bytes_background[i][j];
              tx_total_pkts_dl_background+=otg_info->tx_num_pkt_background[i][j];
              rx_total_bytes_dl_background+=otg_info->rx_num_bytes_background[i][j];
              rx_total_pkts_dl_background+=otg_info->rx_num_pkt_background[i][j]; */

            if ((min_owd_dl>otg_info->rx_owd_min[i][j][k]) || (min_owd_dl==0))
              min_owd_dl=otg_info->rx_owd_min[i][j][k];

            if ((max_owd_dl<otg_info->rx_owd_max[i][j][k]) || (max_owd_dl==0))
              max_owd_dl=otg_info->rx_owd_max[i][j][k];

            if ((min_owd_dl_e2e>otg_info->rx_owd_min_e2e[i][j][k]) || (min_owd_dl_e2e==0))
              min_owd_dl_e2e=otg_info->rx_owd_min_e2e[i][j][k];

            if ((max_owd_dl_e2e<otg_info->rx_owd_max_e2e[i][j][k]) || (max_owd_dl_e2e==0))
              max_owd_dl_e2e=otg_info->rx_owd_max_e2e[i][j][k];

          } else { // UL
            tx_total_bytes_ul+=otg_info->tx_num_bytes[i][j][k];
            tx_total_pkts_ul+=otg_info->tx_num_pkt[i][j][k];
            rx_total_bytes_ul+=otg_info->rx_num_bytes[i][j][k];
            rx_total_pkts_ul+=otg_info->rx_num_pkt[i][j][k];

            /*tx_total_bytes_ul_background+=otg_info->tx_num_bytes_background[i][j];
              tx_total_pkts_ul_background+=otg_info->tx_num_pkt_background[i][j];
              rx_total_bytes_ul_background+=otg_info->rx_num_bytes_background[i][j];
              rx_total_pkts_ul_background+=otg_info->rx_num_pkt_background[i][j];*/
            if ((min_owd_ul>otg_info->rx_owd_min[i][j][k]) || (min_owd_ul==0))
              min_owd_ul=otg_info->rx_owd_min[i][j][k];

            if ((max_owd_ul<otg_info->rx_owd_max[i][j][k]) || (max_owd_ul==0))
              max_owd_ul=otg_info->rx_owd_max[i][j][k];

            if ((min_owd_ul_e2e>otg_info->rx_owd_min_e2e[i][j][k]) || (min_owd_ul_e2e==0))
              min_owd_ul_e2e=otg_info->rx_owd_min_e2e[i][j][k];

            if ((max_owd_ul_e2e<otg_info->rx_owd_max_e2e[i][j][k]) || (max_owd_ul_e2e==0))
              max_owd_ul_e2e=otg_info->rx_owd_max_e2e[i][j][k];

          }

          //LOG_D(OTG,"KPI: (src=%d, dst=%d, appli %d) NB packet TX= %d,  NB packet RX= %d\n ",i, j,  otg_info->tx_num_pkt[i][j][k],  otg_info->rx_num_pkt[i][j][k]);

          if (g_otg->application_idx[i][j]>1)
            strcpy(traffic_type,"GATEWAY");
          else
            strcpy(traffic_type,"APPLICATION");

          if (map_int_to_str(otg_app_type_names,g_otg->application_type[i][j][k]) == 0) {
            LOG_E(OTG,"(src=%d, dst=%d, appli %d) : Unknown traffic \n ", i, j,k);
            strcpy(traffic,"UKNOWN TRAFFIC");
          } else {
            strncpy (traffic, map_int_to_str(otg_app_type_names,g_otg->application_type[i][j][k]), sizeof(traffic));
            traffic[sizeof(traffic) - 1] = 0; // terminate string
          }

443 444 445

#ifdef STANDALONE

446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
          fprintf(file,"----------------------------------------------------------\n");
          fprintf(file,"Total Time (ms)= %d \n", otg_info->ctime+1);

          if (i<NB_eNB_INST) {
            fprintf(file,"[%s] DL [eNB:%d, UE:%d][%s] \n", traffic_type,i,j,traffic);
          } else
            fprintf(file,"[%s] UL [eNB:%d, UE:%d][%s] \n",traffic_type,j,i,traffic);

          fprintf(file,"[%s] Total packets(TX)= %d \n",traffic_type, otg_info->tx_num_pkt[i][j][k]);
          fprintf(file,"[%s] Total bytes(TX)= %d \n",traffic_type, otg_info->tx_num_bytes[i][j][k]);
          fprintf(file,"[%s] OWD MIN (one way)ms= %.2f \n",traffic_type, otg_info->rx_owd_min[i][j][k]);
          fprintf(file,"[%s] OWD MAX (one way)ms= %.2f \n",traffic_type, otg_info->rx_owd_max[i][j][k]);
          fprintf(file,"[%s] TX throughput = %.7f(Kbit/s) \n",traffic_type, otg_info->tx_throughput[i][j][k]);
          fprintf(file,"[%s] RX goodput= %.7f (K/s) \n",traffic_type, otg_info->rx_goodput[i][j][k]);

          if (otg_info->rx_loss_rate[i][j[k]]>0) {
            fprintf(file,"[%s] Loss rate = %.2f \n",traffic_type, (otg_info->rx_loss_rate[i][j][k]));
            fprintf(file,"[%s] NB Lost  packets=%d \n",traffic_type, (otg_info->tx_num_pkt[i][j][k]-otg_info->rx_num_pkt[i][j][k]));
            //fprintf(file,"[%s] NB Lost [OTG] packets=%d \n",traffic_type, otg_info->nb_loss_pkts_otg[i][j]);
          }

          /* if ((g_otg->background_stats==1)&&(otg_info->tx_num_bytes_background[i][j]>0)){
             fprintf(file,"[BACKGROUND] Total packets(TX)= %d \n", otg_info->tx_num_pkt_background[i][j]);
            fprintf(file,"[BACKGROUND] Total bytes(TX)= %d \n", otg_info->tx_num_bytes_background[i][j]);
            fprintf(file,"[BACKGROUND] TX throughput = %.7f(Kbit/s) \n", otg_info->tx_throughput_background[i][j]);
            fprintf(file,"[BACKGROUND] RX goodput= %.7f (Kbit/s) \n", otg_info->rx_goodput_background[i][j]);
            if (otg_info->rx_loss_rate_background[i][j]>0){
              fprintf(file,"[BACKGROUND] Loss rate(percentage)= %lf \n", (otg_info->rx_loss_rate_background[i][j]*100));
              fprintf(file,"[BACKGROUND] NB Lost  packets=%d \n", (otg_info->tx_num_pkt_background[i][j]-otg_info->rx_num_pkt_background[i][j]));
            }
          }
          */
478 479 480


#else
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 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 553 554 555 556 557 558 559 560 561 562 563 564 565
          LOG_I(OTG,"----------------------------------------------------------\n");
          LOG_I(OTG,"Total Time (ms)= %d \n", otg_info->ctime+1);

          if (i<NB_eNB_INST)
            LOG_I(OTG,"[%s] DL [eNB:%d -> UE:%d][%s] \n",traffic_type, i, j, traffic);
          else
            LOG_I(OTG,"[%s] UL [UE:%d -> eNB:%d][%s] \n",traffic_type, i, j, traffic);

          LOG_I(OTG,"[%s] Total packets(TX)           = %d \n",traffic_type, otg_info->tx_num_pkt[i][j][k]);
          LOG_I(OTG,"[%s] Total packets(RX)           = %d \n",traffic_type, otg_info->rx_num_pkt[i][j][k]);
          LOG_I(OTG,"[%s] Total bytes(TX)             = %d \n",traffic_type, otg_info->tx_num_bytes[i][j][k]);
          LOG_I(OTG,"[%s] Total bytes(RX)             = %d \n",traffic_type, otg_info->rx_num_bytes[i][j][k]);
          LOG_I(OTG,"[%s] OWD MIN (one way)ms         = %.2f \n",traffic_type, otg_info->rx_owd_min[i][j][k]);
          LOG_I(OTG,"[%s] OWD MAX (one way)ms         = %.2f \n",traffic_type, otg_info->rx_owd_max[i][j][k]);
          LOG_I(OTG,"[%s] Estimated E2E OWD MIN ms    = %.2f \n",traffic_type, otg_info->rx_owd_max_e2e[i][j][k]);
          LOG_I(OTG,"[%s] Estimated E2E OWD MAX ms    = %.2f \n",traffic_type, otg_info->rx_owd_max_e2e[i][j][k]);
          LOG_I(OTG,"[%s] JITTER AVG ms               = %.2f \n",traffic_type, otg_info->rx_jitter_avg[i][j][k]);
          LOG_I(OTG,"[%s] JITTER MIN ms               = %.2f \n",traffic_type, otg_info->rx_jitter_min[i][j][k]);
          LOG_I(OTG,"[%s] JITTER MAX ms               = %.2f \n",traffic_type, otg_info->rx_jitter_max[i][j][k]);
          LOG_I(OTG,"[%s] Estimated E2E JITTER AVG ms = %.2f \n",traffic_type, otg_info->rx_jitter_avg_e2e[i][j][k]);
          LOG_I(OTG,"[%s] Estimated E2E JITTER MIN ms = %.2f \n",traffic_type, otg_info->rx_jitter_min_e2e[i][j][k]);
          LOG_I(OTG,"[%s] Estimated E2E JITTER MAX ms = %.2f \n",traffic_type, otg_info->rx_jitter_max_e2e[i][j][k]);
          LOG_I(OTG,"[%s] TX throughput               = %.7f(Kbit/s) \n",traffic_type, otg_info->tx_throughput[i][j][k]);
          LOG_I(OTG,"[%s] RX goodput                  = %.7f (Kbit/s) \n",traffic_type, otg_info->rx_goodput[i][j][k]);

          if (otg_info->rx_loss_rate[i][j][k]>0) {
            LOG_I(OTG,"[%s] Loss rate               = %lf \n",traffic_type, (otg_info->rx_loss_rate[i][j][k]));
            LOG_I(OTG,"[%s] NB Lost packets         = %d \n",traffic_type, (otg_info->tx_num_pkt[i][j][k]-otg_info->rx_num_pkt[i][j][k]));
            //LOG_D(OTG,"[%s] NB Lost [OTG] packets=%d \n",traffic_type, otg_info->nb_loss_pkts_otg[i][j]);
          }

          /*  if ((g_otg->background_stats==1)&&(otg_info->tx_num_bytes_background[i][j]>0)){
              LOG_I(OTG,"[BACKGROUND] Total packets(TX)= %d \n", otg_info->tx_num_pkt_background[i][j]);
              LOG_I(OTG,"[BACKGROUND] Total bytes(TX)= %d \n", otg_info->tx_num_bytes_background[i][j]);
              LOG_I(OTG,"[BACKGROUND] TX throughput = %.7f(Kbit/s) \n", otg_info->tx_throughput_background[i][j]);
              LOG_I(OTG,"[BACKGROUND] RX goodput= %.7f (Kbit/s) \n", otg_info->rx_goodput_background[i][j]);
              if (otg_info->rx_loss_rate_background[i][j]>0){
                LOG_I(OTG,"[BACKGROUND] Loss rate(percentage)= %.2f \n", (otg_info->rx_loss_rate_background[i][j]*100));
                LOG_I(OTG,"[BACKGROUND] NB Lost  packets=%d \n", (otg_info->tx_num_pkt_background[i][j]-otg_info->rx_num_pkt_background[i][j]));
              }
            }
          */
          LOG_F(OTG,"----------------------------------------------------------\n");
          LOG_F(OTG,"Total Time (ms)= %d \n", otg_info->ctime+1);

          if (i<NB_eNB_INST) {
            LOG_F(OTG,"[%s] DL [eNB:%d -> UE:%d][%s] \n",traffic_type ,i, j, traffic);
          } else
            LOG_F(OTG,"[%s] UL [UE:%d -> eNB:%d][%s] \n",traffic_type, i, j,traffic);

          LOG_F(OTG,"[%s] Total packets(TX)= %d \n",traffic_type, otg_info->tx_num_pkt[i][j][k]);
          LOG_F(OTG,"[%s] Total packets(RX)= %d \n",traffic_type, otg_info->rx_num_pkt[i][j][k]);
          LOG_F(OTG,"[%s] Total bytes(TX)= %d \n",traffic_type, otg_info->tx_num_bytes[i][j][k]);
          LOG_F(OTG,"[%s] Total bytes(RX)= %d \n",traffic_type, otg_info->rx_num_bytes[i][j][k]);
          LOG_F(OTG,"[%s] OWD MIN (one way)ms= %.2f \n",traffic_type, otg_info->rx_owd_min[i][j][k]);
          LOG_F(OTG,"[%s] OWD MAX (one way)ms= %.2f \n",traffic_type, otg_info->rx_owd_max[i][j][k]);
          LOG_F(OTG,"[%s] Estimated E2E OWD MIN ms = %.2f \n",traffic_type, otg_info->rx_owd_max_e2e[i][j][k]);
          LOG_F(OTG,"[%s] Estimated E2E OWD MAX ms = %.2f \n",traffic_type, otg_info->rx_owd_max_e2e[i][j][k]);
          LOG_F(OTG,"[%s] JITTER AVG ms= %.2f \n",traffic_type, otg_info->rx_jitter_avg[i][j][k]);
          LOG_F(OTG,"[%s] JITTER MIN ms= %.2f \n",traffic_type, otg_info->rx_jitter_min[i][j][k]);
          LOG_F(OTG,"[%s] JITTER MAX ms= %.2f \n",traffic_type, otg_info->rx_jitter_max[i][j][k]);
          LOG_F(OTG,"[%s] Estimated E2E JITTER AVG ms = %.2f \n",traffic_type, otg_info->rx_jitter_avg_e2e[i][j][k]);
          LOG_F(OTG,"[%s] Estimated E2E JITTER MIN ms = %.2f \n",traffic_type, otg_info->rx_jitter_min_e2e[i][j][k]);
          LOG_F(OTG,"[%s] Estimated E2E JITTER MAX ms = %.2f \n",traffic_type, otg_info->rx_jitter_max_e2e[i][j][k]);
          LOG_F(OTG,"[%s] TX throughput = %.7f(Kbit/s) \n",traffic_type, otg_info->tx_throughput[i][j][k]);
          LOG_F(OTG,"[%s] RX goodput= %.7f (Kbit/s) \n",traffic_type, otg_info->rx_goodput[i][j][k]);

          if (otg_info->rx_loss_rate[i][j][k]>0) {
            LOG_F(OTG,"[%s] Loss rate = %lf \n",traffic_type, (otg_info->rx_loss_rate[i][j][k]));
            LOG_F(OTG,"[%s] NB Lost  packets= %d \n",traffic_type,(otg_info->tx_num_pkt[i][j][k]-otg_info->rx_num_pkt[i][j][k]));
            //LOG_D(OTG,"[%s] NB Lost [OTG] packets=%d \n",traffic_type, otg_info->nb_loss_pkts_otg[i][j]);
          }

          /*  if ((g_otg->background_stats==1)&&(otg_info->tx_num_bytes_background[i][j]>0)){
              LOG_F(OTG,"[BACKGROUND] Total packets(TX)= %d \n", otg_info->tx_num_pkt_background[i][j]);
              LOG_F(OTG,"[BACKGROUND] Total bytes(TX)= %d \n", otg_info->tx_num_bytes_background[i][j]);
              LOG_F(OTG,"[BACKGROUND] TX throughput = %.7f(Kbit/s) \n", otg_info->tx_throughput_background[i][j]);
              LOG_F(OTG,"[BACKGROUND] RX goodput= %.7f (Kbit/s) \n", otg_info->rx_goodput_background[i][j]);
              if (otg_info->rx_loss_rate_background[i][j]>0){
                LOG_F(OTG,"[BACKGROUND] Loss rate(percentage)= %.2f \n", (otg_info->rx_loss_rate_background[i][j]*100));
                LOG_F(OTG,"[BACKGROUND] NB Lost  packets=%d \n", (otg_info->tx_num_pkt_background[i][j]-otg_info->rx_num_pkt_background[i][j]));
              }
            }
          */
#endif
566

567
        }
568

569 570 571
        //     if ((otg_multicast_info->tx_throughput[i][j]>0) && (otg_info->tx_num_bytes[i][j][k]>0))  {

      }// end loop of k
572

573 574 575 576


#ifdef STANDALONE

577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
      if ((g_otg->background_stats==1)&&(otg_info->tx_num_bytes_background[i][j]>0)) {
        fprintf(file,"----------------------------------------------------------\n");
        fprintf(file,"Total Time (ms)= %d \n", otg_info->ctime+1);

        if (i<NB_eNB_INST) {
          fprintf(file,"[%s] DL [eNB:%d, UE:%d] \n", traffic_type,i,j);
        } else
          fprintf(file,"[%s] UL [eNB:%d, UE:%d] \n",traffic_type,j,i);

        fprintf(file,"[BACKGROUND] Total packets(TX)= %d \n", otg_info->tx_num_pkt_background[i][j]);
        fprintf(file,"[BACKGROUND] Total bytes(TX)= %d \n", otg_info->tx_num_bytes_background[i][j]);
        fprintf(file,"[BACKGROUND] TX throughput = %.7f(Kbit/s) \n", otg_info->tx_throughput_background[i][j]);
        fprintf(file,"[BACKGROUND] RX goodput= %.7f (Kbit/s) \n", otg_info->rx_goodput_background[i][j]);

        if (otg_info->rx_loss_rate_background[i][j]>0) {
          fprintf(file,"[BACKGROUND] Loss rate = %lf \n", (otg_info->rx_loss_rate_background[i][j]));
          fprintf(file,"[BACKGROUND] NB Lost  packets=%d \n", (otg_info->tx_num_pkt_background[i][j]-otg_info->rx_num_pkt_background[i][j]));
        }
      }

597 598
#else

599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
      if ((g_otg->background_stats==1)&&(otg_info->tx_num_bytes_background[i][j]>0)) {
        LOG_I(OTG,"----------------------------------------------------------\n");
        LOG_I(OTG,"Total Time (ms)= %d \n", otg_info->ctime+1);

        if (i<NB_eNB_INST) {
          LOG_I(OTG,"[%s] DL [eNB:%d -> UE:%d] \n",traffic_type, i, j);
        } else
          LOG_I(OTG,"[%s] UL [UE:%d -> eNB:%d] \n",traffic_type, i, j);

        LOG_I(OTG,"[BACKGROUND] Total packets(TX)= %d \n", otg_info->tx_num_pkt_background[i][j]);
        LOG_I(OTG,"[BACKGROUND] Total bytes(TX)= %d \n", otg_info->tx_num_bytes_background[i][j]);
        LOG_I(OTG,"[BACKGROUND] TX throughput = %.7f(Kbit/s) \n", otg_info->tx_throughput_background[i][j]);
        LOG_I(OTG,"[BACKGROUND] RX goodput= %.7f (Kbit/s) \n", otg_info->rx_goodput_background[i][j]);

        if (otg_info->rx_loss_rate_background[i][j]>0) {
          LOG_I(OTG,"[BACKGROUND] Loss rate = %lf \n", (otg_info->rx_loss_rate_background[i][j]));
          LOG_I(OTG,"[BACKGROUND] NB Lost  packets=%d \n", (otg_info->tx_num_pkt_background[i][j]-otg_info->rx_num_pkt_background[i][j]));
        }
      }

      if ((g_otg->background_stats==1)&&(otg_info->tx_num_bytes_background[i][j]>0)) {
        LOG_F(OTG,"----------------------------------------------------------\n");
        LOG_F(OTG,"Total Time (ms)= %d \n", otg_info->ctime+1);

        if (i<NB_eNB_INST) {
          LOG_F(OTG,"[%s] DL [eNB:%d -> UE:%d] \n",traffic_type ,i, j);
        } else
          LOG_F(OTG,"[%s] UL [UE:%d -> eNB:%d] \n",traffic_type, i, j);

        LOG_F(OTG,"[BACKGROUND] Total packets(TX)= %d \n", otg_info->tx_num_pkt_background[i][j]);
        LOG_F(OTG,"[BACKGROUND] Total bytes(TX)= %d \n", otg_info->tx_num_bytes_background[i][j]);
        LOG_F(OTG,"[BACKGROUND] TX throughput = %.7f(Kbit/s) \n", otg_info->tx_throughput_background[i][j]);
        LOG_F(OTG,"[BACKGROUND] RX goodput= %.7f (Kbit/s) \n", otg_info->rx_goodput_background[i][j]);

        if (otg_info->rx_loss_rate_background[i][j]>0) {
          LOG_F(OTG,"[BACKGROUND] Loss rate = %lf \n", (otg_info->rx_loss_rate_background[i][j]));
          LOG_F(OTG,"[BACKGROUND] NB Lost  packets=%d \n", (otg_info->tx_num_pkt_background[i][j]-otg_info->rx_num_pkt_background[i][j]));
        }
      }

639 640 641
#endif


642
    }// end loop of j
643 644
  }// end loop of i

645

646
  //  average_total_jitter();
647

648 649 650 651 652 653 654 655 656 657 658
#ifdef STANDALONE
  fprintf (file,"**************** TOTAL DL RESULTS ******************\n");
  fprintf(file,"Total Time= %d \n", otg_info->ctime+1);
  fprintf(file,"[DATA] Total packets(TX)= %d \n", tx_total_pkts_dl);
  fprintf(file,"[DATA] Total bytes(TX)= %d \n", tx_total_bytes_dl);
  fprintf(file,"[DATA] Total packets(RX)= %d \n", rx_total_pkts_dl);
  fprintf(file,"[DATA] Total bytes(RX)= %d \n", rx_total_bytes_dl);
  fprintf(file,"[DATA] OWD MIN (one way)ms= %.2f \n", min_owd_dl);
  fprintf(file,"[DATA] OWD MAX (one way)ms= %.2f \n", max_owd_dl);
  fprintf(file,"[DATA] TX throughput = %.7f(Kbit/s) \n", ((double)tx_total_bytes_dl*1000*8)/(otg_info->ctime*1024));
  fprintf(file,"[DATA] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_dl*1000*8)/(otg_info->ctime*1024));
659 660

  if ((g_otg->background_stats==1)&&(tx_total_pkts_dl_background>0)) {
661 662 663 664 665 666 667
    fprintf(file,"[BACKGROUND] Total packets(TX)= %d \n", tx_total_pkts_dl_background);
    fprintf(file,"[BACKGROUND] Total bytes(TX)= %d \n", tx_total_bytes_dl_background);
    fprintf(file,"[BACKGROUND] Total packets(RX)= %d \n", rx_total_pkts_dl_background);
    fprintf(file,"[BACKGROUND] Total bytes(RX)= %d \n", rx_total_bytes_dl_background);
    fprintf(file,"[BACKGROUND] TX throughput = %.7f(Kbit/s) \n", ((double)tx_total_bytes_dl_background*1000*8)/(otg_info->ctime*1024));
    fprintf(file,"[BACKGROUND] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_dl_background*1000*8)/(otg_info->ctime*1024));
  }
668

669 670 671 672 673 674 675 676 677 678
  fprintf (file,"**************** TOTAL UL RESULTS ******************\n");
  fprintf(file,"Total Time (ms)= %d \n", otg_info->ctime+1);
  fprintf(file,"[DATA] Total packets(TX)= %d \n", tx_total_pkts_ul);
  fprintf(file,"[DATA] Total bytes(TX)= %d \n", tx_total_bytes_ul);
  fprintf(file,"[DATA] Total packets(RX)= %d \n", rx_total_pkts_ul);
  fprintf(file,"[DATA] Total bytes(RX)= %d \n", rx_total_bytes_ul);
  fprintf(file,"[DATA] OWD MIN (one way)ms= %.2f \n", min_owd_ul);
  fprintf(file,"[DATA] OWD MAX (one way)ms= %.2f \n", max_owd_ul);
  fprintf(file,"[DATA] TX throughput = %.7f(Kbit/s) \n", ((double)tx_total_bytes_ul*1000*8)/(otg_info->ctime*1024));
  fprintf(file,"[DATA] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_ul*1000*8)/(otg_info->ctime*1024));
679 680

  if ((g_otg->background_stats==1)&&(tx_total_pkts_ul_background>0)) {
681 682 683 684 685 686 687
    fprintf(file,"[BACKGROUND] Total packets(TX)= %d \n", tx_total_pkts_ul_background);
    fprintf(file,"[BACKGROUND] Total bytes(TX)= %d \n", tx_total_bytes_ul_background);
    fprintf(file,"[BACKGROUND] Total packets(RX)= %d \n", rx_total_pkts_ul_background);
    fprintf(file,"[BACKGROUND] Total bytes(RX)= %d \n", rx_total_bytes_ul_background);
    fprintf(file,"[BACKGROUND] TX throughput = %.7f(Kbit/s) \n", ((double)tx_total_bytes_ul_background*1000*8)/(otg_info->ctime*1024));
    fprintf(file,"[BACKGROUND] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_ul_background*1000*8)/(otg_info->ctime*1024));
  }
688

689 690 691 692 693 694 695 696 697 698
  fclose(file);
#else
  LOG_I(OTG,"**************** TOTAL DL RESULTS ******************\n");
  LOG_I(OTG,"Total Time (ms)= %d \n", otg_info->ctime+1);
  LOG_I(OTG,"[DATA] Total packets(TX)= %d \n", tx_total_pkts_dl);
  LOG_I(OTG,"[DATA] Total packets(RX)= %d \n", rx_total_pkts_dl);
  LOG_I(OTG,"[DATA] Total bytes(TX)= %d \n", tx_total_bytes_dl);
  LOG_I(OTG,"[DATA] Total bytes(RX)= %d \n", rx_total_bytes_dl);
  LOG_I(OTG,"[DATA] OWD MIN (one way)ms= %.2f \n", min_owd_dl);
  LOG_I(OTG,"[DATA] OWD MAX (one way)ms= %.2f \n", max_owd_dl);
nikaeinn's avatar
nikaeinn committed
699 700
  LOG_I(OTG,"[DATA] Estimated E2E OWD MIN (one way)ms= %.2f \n", min_owd_dl_e2e);
  LOG_I(OTG,"[DATA] Estimated E2E OWD MAX (one way)ms= %.2f \n", max_owd_dl_e2e);
701

nikaeinn's avatar
nikaeinn committed
702 703 704 705
  if (num_active_source != 0) {
    LOG_I(OTG,"[DATA] JITTER AVG ms= %lf \n", otg_info->average_jitter_dl/(float)num_active_source );
    LOG_I(OTG,"[DATA] Estimated E2E JITTER AVG ms= %lf \n", otg_info->average_jitter_dl_e2e/(float)num_active_source );
  }
706

707 708
  LOG_I(OTG,"[DATA] TX throughput = %.7f(Kbit/s) \n", ((double)tx_total_bytes_dl*1000*8)/(otg_info->ctime*1024));
  LOG_I(OTG,"[DATA] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_dl*1000*8)/(otg_info->ctime*1024));
709
  LOG_I(OTG,"[DATA] NB lost packet = %d \n", tx_total_pkts_dl - rx_total_pkts_dl);
710

711 712 713
  if ( (tx_total_pkts_dl > 0) &&
       ((10*(tx_total_pkts_dl - rx_total_pkts_dl))  >  tx_total_pkts_dl)) // below 10% of loss
    dl_ok=0;
714 715

  if ((g_otg->background_stats==1)&&(tx_total_pkts_dl_background>0)) {
716 717 718 719 720 721
    LOG_I(OTG,"[BACKGROUND] Total packets(TX)= %d \n", tx_total_pkts_dl_background);
    LOG_I(OTG,"[BACKGROUND] Total bytes(TX)= %d \n", tx_total_bytes_dl_background);
    LOG_I(OTG,"[BACKGROUND] Total packets(RX)= %d \n", rx_total_pkts_dl_background);
    LOG_I(OTG,"[BACKGROUND] Total bytes(RX)= %d \n", rx_total_bytes_dl_background);
    LOG_I(OTG,"[BACKGROUND] TX throughput = %.7f(Kbit/s) \n", ((double)tx_total_bytes_dl_background*1000*8)/(otg_info->ctime*1024));
    LOG_I(OTG,"[BACKGROUND] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_dl_background*1000*8)/(otg_info->ctime*1024));
722 723 724
  }

  if (tx_total_pkts_dl_multicast>0) {
725 726 727 728 729 730 731
    LOG_I(OTG,"[MULTICAST] Total packets(TX)= %d \n", tx_total_pkts_dl_multicast);
    LOG_I(OTG,"[MULTICAST] Total bytes(TX)= %d \n", tx_total_bytes_dl_multicast);
    LOG_I(OTG,"[MULTICAST] Total packets(RX)= %d \n", rx_total_pkts_dl_multicast);
    LOG_I(OTG,"[MULTICAST] Total bytes(RX)= %d \n", rx_total_bytes_dl_multicast);
    LOG_I(OTG,"[MULTICAST] otg_multicast_info->ctime = %d \n", otg_multicast_info->ctime);
    LOG_I(OTG,"[MULTICAST] TX throughput = %.7f(Kbit/s) \n", ((double)tx_total_bytes_dl_multicast*1000*8)/(otg_info->ctime*1024));
    LOG_I(OTG,"[MULTICAST] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_dl_multicast*1000*8)/(otg_info->ctime*1024));
732
  }
733

734 735 736 737 738 739 740 741 742

  LOG_F(OTG,"**************** TOTAL DL RESULTS ******************\n");
  LOG_F(OTG,"Total Time (ms)= %d \n", otg_info->ctime+1);
  LOG_F(OTG,"[DATA] Total packets(TX)= %d \n", tx_total_pkts_dl);
  LOG_F(OTG,"[DATA] Total packets(RX)= %d \n", rx_total_pkts_dl);
  LOG_F(OTG,"[DATA] Total bytes(TX)= %d \n", tx_total_bytes_dl);
  LOG_F(OTG,"[DATA] Total bytes(RX)= %d \n", rx_total_bytes_dl);
  LOG_F(OTG,"[DATA] OWD MIN (one way)ms= %.2f \n", min_owd_dl);
  LOG_F(OTG,"[DATA] OWD MAX (one way)ms= %.2f \n", max_owd_dl);
nikaeinn's avatar
nikaeinn committed
743 744
  LOG_F(OTG,"[DATA] ESTIMATED E2E OWD MIN (one way)ms= %.2f \n", min_owd_dl_e2e);
  LOG_F(OTG,"[DATA] ESTIMATED E2E OWD MAX (one way)ms= %.2f \n", max_owd_dl_e2e);
745

nikaeinn's avatar
nikaeinn committed
746 747 748 749
  if (num_active_source != 0) {
    LOG_F(OTG,"[DATA] JITTER AVG ms= %lf \n",  otg_info->average_jitter_dl/(float)num_active_source);
    LOG_F(OTG,"[DATA]  ESTIMATED E2E JITTER AVG ms= %lf \n",  otg_info->average_jitter_dl_e2e/(float)num_active_source);
  }
750

751 752 753
  LOG_F(OTG,"[DATA] TX throughput = %.7f(Kbit/s) \n", ((double)tx_total_bytes_dl*1000*8)/(otg_info->ctime*1024));
  LOG_F(OTG,"[DATA] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_dl*1000*8)/(otg_info->ctime*1024));
  LOG_F(OTG,"[DATA] NB lost packet = %d \n", tx_total_pkts_dl - rx_total_pkts_dl );
754 755

  if ((g_otg->background_stats==1)&&(tx_total_pkts_dl_background>0)) {
756 757 758 759 760 761
    LOG_F(OTG,"[BACKGROUND] Total packets(TX)= %d \n", tx_total_pkts_dl_background);
    LOG_F(OTG,"[BACKGROUND] Total bytes(TX)= %d \n", tx_total_bytes_dl_background);
    LOG_F(OTG,"[BACKGROUND] Total packets(RX)= %d \n", rx_total_pkts_dl_background);
    LOG_F(OTG,"[BACKGROUND] Total bytes(RX)= %d \n", rx_total_bytes_dl_background);
    LOG_F(OTG,"[BACKGROUND] TX throughput = %.7f(Kbit/s) \n", ((double)tx_total_bytes_dl_background*1000*8)/(otg_info->ctime*1024));
    LOG_F(OTG,"[BACKGROUND] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_dl_background*1000*8)/(otg_info->ctime*1024));
762 763 764
  }

  if (tx_total_pkts_dl_multicast>0) {
765 766 767 768 769 770
    LOG_F(OTG,"[MULTICAST] Total packets(TX)= %d \n", tx_total_pkts_dl_multicast);
    LOG_F(OTG,"[MULTICAST] Total bytes(TX)= %d \n", tx_total_bytes_dl_multicast);
    LOG_F(OTG,"[MULTICAST] Total packets(RX)= %d \n", rx_total_pkts_dl_multicast);
    LOG_F(OTG,"[MULTICAST] Total bytes(RX)= %d \n", rx_total_bytes_dl_multicast);
    LOG_F(OTG,"[MULTICAST] TX throughput = %.7f(Kbit/s) \n", ((double)tx_total_bytes_dl_multicast*1000*8)/(otg_info->ctime*1024));
    LOG_F(OTG,"[MULTICAST] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_dl_multicast*1000*8)/(otg_info->ctime*1024));
771 772 773
  }


774

nikaeinn's avatar
nikaeinn committed
775
  LOG_I(OTG,"**************** TOTAL UL RESULTS ******************\n");
776 777 778 779 780 781 782
  LOG_I(OTG,"Total Time (ms)= %d \n", otg_info->ctime+1);
  LOG_I(OTG,"[DATA] Total packets(TX)= %d \n", tx_total_pkts_ul);
  LOG_I(OTG,"[DATA] Total packets(RX)= %d \n", rx_total_pkts_ul);
  LOG_I(OTG,"[DATA] Total bytes(TX)= %d \n", tx_total_bytes_ul);
  LOG_I(OTG,"[DATA] Total bytes(RX)= %d \n", rx_total_bytes_ul);
  LOG_I(OTG,"[DATA] OWD MIN (one way)ms= %.2f \n", min_owd_ul);
  LOG_I(OTG,"[DATA] OWD MAX (one way)ms= %.2f \n", max_owd_ul);
nikaeinn's avatar
nikaeinn committed
783 784
  LOG_I(OTG,"[DATA] ESTIMATED E2E OWD MIN (one way)ms= %.2f \n", min_owd_ul_e2e);
  LOG_I(OTG,"[DATA] ESTIMATED E2E OWD MAX (one way)ms= %.2f \n", max_owd_ul_e2e);
785

nikaeinn's avatar
nikaeinn committed
786 787 788 789
  if (num_active_source != 0) {
    LOG_I(OTG,"[DATA] JITTER AVG ms= %lf \n",  otg_info->average_jitter_ul_e2e/(float)num_active_source);
    LOG_I(OTG,"[DATA] ESTIMATED E2E JITTER AVG ms= %lf \n",  otg_info->average_jitter_ul/(float)num_active_source);
  }
790

791 792
  LOG_I(OTG,"[DATA] TX throughput = %.7f(Kbit/s) \n", ((double)tx_total_bytes_ul*1000*8)/(otg_info->ctime*1024));
  LOG_I(OTG,"[DATA] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_ul*1000*8)/(otg_info->ctime*1024));
nikaeinn's avatar
nikaeinn committed
793
  LOG_I(OTG,"[DATA] NB lost packet = %d \n", tx_total_pkts_ul - rx_total_pkts_ul );
794

795 796 797
  if ( (tx_total_pkts_ul > 0 ) &&
       ((10*(tx_total_pkts_ul - rx_total_pkts_ul)) > tx_total_pkts_ul))
    ul_ok=0;
798 799

  if ((g_otg->background_stats==1)&&(tx_total_pkts_ul_background>0)) {
800 801 802 803 804 805 806 807
    LOG_I(OTG,"[BACKGROUND] Total packets(TX)= %d \n", tx_total_pkts_ul_background);
    LOG_I(OTG,"[BACKGROUND] Total bytes(TX)= %d \n", tx_total_bytes_ul_background);
    LOG_I(OTG,"[BACKGROUND] Total packets(RX)= %d \n", rx_total_pkts_ul_background);
    LOG_I(OTG,"[BACKGROUND] Total bytes(RX)= %d \n", rx_total_bytes_ul_background);
    LOG_I(OTG,"[BACKGROUND] TX throughput = %.7f(Kbit/s) \n", ((double)tx_total_bytes_ul_background*1000*8)/(otg_info->ctime*1024));
    LOG_I(OTG,"[BACKGROUND] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_ul_background*1000*8)/(otg_info->ctime*1024));

  }
808

809
  LOG_F(OTG,"**************** TOTAL UL RESULTS ******************\n");
810 811 812 813 814 815 816
  LOG_F(OTG,"Total Time (ms)= %d \n", otg_info->ctime+1);
  LOG_F(OTG,"[DATA] Total packets(TX)= %d \n", tx_total_pkts_ul);
  LOG_F(OTG,"[DATA] Total packets(RX)= %d \n", rx_total_pkts_ul);
  LOG_F(OTG,"[DATA] Total bytes(TX)= %d \n", tx_total_bytes_ul);
  LOG_F(OTG,"[DATA] Total bytes(RX)= %d \n", rx_total_bytes_ul);
  LOG_F(OTG,"[DATA] OWD MIN (one way)ms= %.2f \n", min_owd_ul);
  LOG_F(OTG,"[DATA] OWD MAX (one way)ms= %.2f \n", max_owd_ul);
nikaeinn's avatar
nikaeinn committed
817 818
  LOG_F(OTG,"[DATA] ESTIMATED E2E OWD MIN (one way)ms= %.2f \n", min_owd_ul_e2e);
  LOG_F(OTG,"[DATA] ESTIMATED E2E OWD MAX (one way)ms= %.2f \n", max_owd_ul_e2e);
819

nikaeinn's avatar
nikaeinn committed
820 821 822 823
  if (num_active_source != 0) {
    LOG_F(OTG,"[DATA] JITTER AVG ms= %lf \n",  otg_info->average_jitter_ul/(float)num_active_source);
    LOG_F(OTG,"[DATA] ESTIMATED E2E JITTER AVG ms= %lf \n",  otg_info->average_jitter_ul_e2e/(float)num_active_source);
  }
824

825 826
  LOG_F(OTG,"[DATA] TX throughput = %.7f(Kbit/s) \n", ((double)tx_total_bytes_ul*1000*8)/(otg_info->ctime*1024));
  LOG_F(OTG,"[DATA] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_ul*1000*8)/(otg_info->ctime*1024));
nikaeinn's avatar
nikaeinn committed
827
  LOG_F(OTG,"[DATA] NB lost packet = %d \n", tx_total_pkts_ul - rx_total_pkts_ul );
828

829
  if ((g_otg->background_stats==1)&&(tx_total_pkts_ul_background>0)) {
830 831 832 833 834 835 836 837 838
    LOG_F(OTG,"[BACKGROUND] Total packets(TX)= %d \n", tx_total_pkts_ul_background);
    LOG_F(OTG,"[BACKGROUND] Total bytes(TX)= %d \n", tx_total_bytes_ul_background);
    LOG_F(OTG,"[BACKGROUND] Total packets(RX)= %d \n", rx_total_pkts_ul_background);
    LOG_F(OTG,"[BACKGROUND] Total bytes(RX)= %d \n", rx_total_bytes_ul_background);
    LOG_F(OTG,"[BACKGROUND] TX throughput = %.7f(Kbit/s) \n", ((double)tx_total_bytes_ul_background*1000*8)/(otg_info->ctime*1024));
    LOG_F(OTG,"[BACKGROUND] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_ul_background*1000*8)/(otg_info->ctime*1024));

  }

nikaeinn's avatar
nikaeinn committed
839
  if ((dl_ok == 1 ) && (ul_ok ==1))
840
    LOG_I(OTG,"************ DL and UL loss rate below 10 *************\n");
841
  else
842
    LOG_I(OTG,"************ DL(%d) and UL(%d) loss rate above 10 *************\n",dl_ok,ul_ok);
843

844 845 846 847
#endif
}


848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
void add_log_metric(int src, int dst, int ctime, double metric, unsigned int label)
{
  unsigned int i;
  unsigned int j;
  unsigned int node_actif=0;

  //LOG_I(OTG,"[%d][%d] LOGG_ADDED ctime=%d, metric=%.2f  \n", src, dst, ctime, metric);

  switch (label) {
  case OTG_LATENCY:
    add_log_label(label, &start_log_latency);
    break;

  case OTG_LATENCY_BG:
    add_log_label(label, &start_log_latency_bg);
    break;

  case OTG_GP:
    add_log_label(label, &start_log_GP);
    break;

  case OTG_GP_BG:
    add_log_label(label, &start_log_GP_bg);
    break;

  case OTG_JITTER:
    add_log_label(label, &start_log_GP_bg);
    break;

  default:
    LOG_E(OTG, "File label unknown %d \n", label);
  }

  LOG_F(label,"%d ", ctime);

  for (i=0; i<=(NB_eNB_INST + NB_UE_INST); i++) {
    for (j=0; j<=(NB_eNB_INST + NB_UE_INST); j++) {
      node_actif=0;

      if ((g_otg->idt_dist[i][j][0][PE_STATE]>0) || (g_otg->application_type[i][j][0] >0))
        node_actif=1;

      if ((node_actif>0) && ((i==src) && (j==dst)))
        LOG_F(label,"%f ", metric);

893
      if  ((node_actif>0) && ((i!=src) || (j!=dst)))
894 895
        LOG_F(label,"%d ", 0);
    }
896
  }
897 898

  LOG_F(label,"%f\n", metric);
899 900 901 902
}



903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918
void  add_log_label(unsigned int label, unsigned int * start_log_metric)
{
  unsigned int i;
  unsigned int j;
  unsigned int node_actif=0;

  if (*start_log_metric==0) {
    *start_log_metric=1;
    LOG_F(label,"Time ");

    for (i=0; i<=(NB_eNB_INST + NB_UE_INST); i++) {
      for (j=0; j<=(NB_eNB_INST + NB_UE_INST); j++) {
        node_actif=0;

        if (g_otg->idt_dist[i][j][0][PE_STATE]>0 )
          node_actif++;
919

920 921 922
        if (node_actif>0)
          LOG_F(label,"%d->%d ", i, j);
      }
923
    }
924 925 926

    LOG_F(label,"Aggregated\n");
  }
927 928
}