⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pathload_rcv_func.c

📁 pashload是应用在linux下的网络带宽测试源程序精确度比较高 ///////////////////////////////////// Pathload is a tool for es
💻 C
📖 第 1 页 / 共 4 页
字号:
    }    else if ( pdt_metric[i] < .9 * PDT_THRESHOLD )    { if (Verbose)        printf("N");        fprintf(pathload_fp,"N");        pdt_trend[i] = NOTR ;    }    else if ( pdt_metric[i] <= PDT_THRESHOLD*1.1 && pdt_metric[i] >= PDT_THRESHOLD*.9 )    { if (Verbose)        printf("U");        fprintf(pathload_fp,"U");        pdt_trend[i] = UNCL ;    } } if (Verbose) printf("\n"); fprintf(pathload_fp,"\n");}/*  returns : trend in fleet or -1 if more than 50% of stream were discarded */l_int32 aggregate_trend_result(){  l_int32 total=0 ,i_cnt = 0, n_cnt = 0;  l_int32 num_dscrd_strm=0;  l_int32 i=0;  l_int32 pct_trend[TREND_ARRAY_LEN] , pdt_trend[TREND_ARRAY_LEN] ;   if (Verbose)    printf("  PCT metric/stream[%2d] :: ",trend_idx);   fprintf(pathload_fp,"  PCT metric/stream[%2d] :: ",trend_idx);   for (i=0; i < trend_idx;i++ )  {    if (Verbose)      printf("%3.2f:",pct_metric[i]);    fprintf(pathload_fp,"%3.2f:",pct_metric[i]);  }  if (Verbose)    printf("\n");   fprintf(pathload_fp,"\n");   if (Verbose)    printf("  PDT metric/stream[%2d] :: ",trend_idx);   fprintf(pathload_fp,"  PDT metric/stream[%2d] :: ",trend_idx);   for (i=0; i < trend_idx;i++ )  {    if (Verbose)      printf("%3.2f:",pdt_metric[i]);    fprintf(pathload_fp,"%3.2f:",pdt_metric[i]);  }  if (Verbose)    printf("\n");   fprintf(pathload_fp,"\n");   if (Verbose)    printf("  PCT Trend/stream [%2d] :: ",trend_idx);   fprintf(pathload_fp,"  PCT Trend/stream [%2d] :: ",trend_idx);   get_pct_trend(pct_metric,pct_trend,trend_idx);  if (Verbose)    printf("  PDT Trend/stream [%2d] :: ",trend_idx);   fprintf(pathload_fp,"  PDT Trend/stream [%2d] :: ",trend_idx);   get_pdt_trend(pdt_metric,pdt_trend,trend_idx);    if (Verbose)    printf("  Trend per stream [%2d] :: ",trend_idx);   fprintf(pathload_fp,"  Trend per stream [%2d] :: ",trend_idx);   for (i=0; i < trend_idx;i++ )  {    if ( pct_trend[i] == DISCARD || pdt_trend[i] == DISCARD )    {       if (Verbose)         printf("d");       fprintf(pathload_fp,"d");       num_dscrd_strm++ ;    }    else if ( pct_trend[i] == INCR &&  pdt_trend[i] == INCR )    {       if (Verbose)         printf("I");       fprintf(pathload_fp,"I");       i_cnt++;    }    else if ( pct_trend[i] == NOTR && pdt_trend[i] == NOTR )    {       if (Verbose)         printf("N");       fprintf(pathload_fp,"N");       n_cnt++;    }    else if ( pct_trend[i] == INCR && pdt_trend[i] == UNCL )    {       if (Verbose)         printf("I");       fprintf(pathload_fp,"I");       i_cnt++;    }    else if ( pct_trend[i] == NOTR && pdt_trend[i] == UNCL )    {       if (Verbose)         printf("N");       fprintf(pathload_fp,"N");       n_cnt++;    }    else if ( pdt_trend[i] == INCR && pct_trend[i] == UNCL )    {       if (Verbose)         printf("I");       fprintf(pathload_fp,"I");       i_cnt++;    }    else if ( pdt_trend[i] == NOTR && pct_trend[i] == UNCL )    {       if (Verbose)         printf("N");       fprintf(pathload_fp,"N");       n_cnt++ ;    }    else    {       if (Verbose)         printf("U");       fprintf(pathload_fp,"U");    }    total++ ;  }  if (Verbose) printf("\n");   fprintf(pathload_fp,"\n");   /* check whether number of usable streams is      atleast 50% of requested number of streams */  total-=num_dscrd_strm ;  if ( total < num_stream/2 && !slow && !interrupt_coalescence)  {    bad_fleet_cs = 1 ;    retry_fleet_cnt_cs++  ;    return -1 ;  }  else  {    bad_fleet_cs = 0 ;    retry_fleet_cnt_cs=0;  }  if( (double)i_cnt/(total) >= AGGREGATE_THRESHOLD )  {    if (Verbose)      printf("  Aggregate trend       :: INCREASING\n");    fprintf(pathload_fp,"  Aggregate trend       :: INCREASING\n");    return INCREASING ;  }  else if( (double)n_cnt/(total) >= AGGREGATE_THRESHOLD )  {    if (Verbose)      printf("  Aggregate trend       :: NO TREND\n");    fprintf(pathload_fp,"  Aggregate trend       :: NO TREND\n");    return NOTREND ;  }  else   {    if (Verbose)      printf("  Aggregate trend       :: GREY\n");    fprintf(pathload_fp,"  Aggregate trend       :: GREY\n");    return GREY ;  }}l_int32 get_sndr_time_interval(double snd_time[],double *sum){  l_int32 k,j=0,new_j=0;  double ordered[MAX_STREAM_LEN] ;  double ltime_interval[MAX_STREAM_LEN] ;  for ( k = 0; k < stream_len-1; k++ )  {    if ( snd_time[k] == 0 || snd_time[k+1] == 0 )      continue;    else       ltime_interval[j++] = snd_time[k+1] - snd_time[k] ;  }  order_dbl(ltime_interval, ordered , 0, j ) ;  /* discard the top 15% as outliers  */  new_j = j - rint(j*.15) ;  for ( k = 0 ; k < new_j ; k++ )    *sum += ordered[k] ;  return new_j ;}void get_sending_rate() { time_interval = snd_time_interval/num; cur_req_rate = tr ; cur_actual_rate = (28 + cur_pkt_sz) * 8. / time_interval ; if( !equal(cur_req_rate, cur_actual_rate)  )  {   if( !grey_max && !grey_min )   {     if( tr_min && tr_max && (less_than(cur_actual_rate,tr_min)||equal(cur_actual_rate,tr_min)))       converged_rmn_rmx_tm = 1;     if( tr_min && tr_max && (less_than(tr_max,cur_actual_rate)||equal(tr_max,cur_actual_rate)))       converged_rmn_rmx_tm = 1;        }   else if ( cur_req_rate < tr_max && cur_req_rate > grey_max )   {     if( !(less_than(cur_actual_rate,tr_max)&&grtr_than(cur_actual_rate,grey_max)) )       converged_gmx_rmx_tm = 1;   }   else if ( cur_req_rate < grey_min && cur_req_rate > tr_min )   {     if( !(less_than(cur_actual_rate,grey_min) && grtr_than(cur_actual_rate,tr_min)) )        converged_gmn_rmn_tm = 1;   }  }  tr = cur_actual_rate ;  transmission_rate = (l_int32) rint(1000000 * tr) ;  if(Verbose)    printf("  Fleet Parameter(act)  :: R=%.2fMbps, L=%ldB, K=%ldpackets, T=%ldusec\n",cur_actual_rate, cur_pkt_sz , stream_len,time_interval);  fprintf(pathload_fp,"  Fleet Parameter(act)  :: R=%.2fMbps, L=%ldB, K=%ldpackets, T=%ldusec\n",cur_actual_rate,cur_pkt_sz,stream_len,time_interval);  snd_time_interval=0;  num=0;}void terminate_gracefully(struct timeval exp_start_time){  l_int32 ctr_code;  char ctr_buff[8],buff[26];  struct timeval exp_end_time;  double min=0,max=0 ;  ctr_code = TERMINATE | CTR_CODE;  send_ctr_mesg(ctr_buff, ctr_code);  gettimeofday(&exp_end_time, NULL);  strncpy(buff, ctime(&(exp_end_time.tv_sec)), 24);  buff[24] = '\0';  if (verbose || Verbose)    printf("\n\t*****  RESULT *****\n");  fprintf(pathload_fp,"\n\t*****  RESULT *****\n");    if (netlog)    netlogger() ;  if ( min_rate_flag )  {    if (verbose || Verbose)    {      printf("Avail-bw < minimum sending rate.\n");      printf("Increase MAX_TIME_INTERVAL in pathload_rcv.h from 200000 usec to a higher value.\n");    }    fprintf(pathload_fp,"Avail-bw < minimum sending rate.\n");    fprintf(pathload_fp,"Increase MAX_TIME_INTERVAL in pathload_rcv.h from 200000 usec to a higher value.\n");  }  else if ( max_rate_flag && !interrupt_coalescence )  {    if (verbose || Verbose)    {      printf("Avail-bw > maximum sending rate.\n");      if ( tr_min)        printf("Avail-bw > %.2f (Mbps)\n", tr_min);    }    fprintf(pathload_fp,"Avail-bw > maximum sending rate.\n");    if ( tr_min)      fprintf(pathload_fp,"Avail-bw > %.2f (Mbps)\n", tr_min);  }  else if (bad_fleet_cs && !interrupt_coalescence)  {    if (verbose || Verbose)      printf("Measurement terminated due to frequent CS @ sender/receiver.\n");    fprintf(pathload_fp,"Measurement terminated due to frequent CS @ sender/receiver.\n");    if ((tr_min&& tr_max) || (grey_min&&grey_max))    {      if ( grey_min&& grey_max)      {        min = grey_min ; max = grey_max ;      }      else      {        min = tr_min ;max = tr_max ;      }      if (verbose || Verbose)      {        printf("Available bandwidth range : %.2f - %.2f (Mbps)\n", min, max);        printf("Measurements finished at %s \n",  buff);        printf("Measurement latency is %.2f sec \n", time_to_us_delta(exp_start_time, exp_end_time) / 1000000);      }      fprintf(pathload_fp,"Available bandwidth range : %.2f - %.2f (Mbps)\n", min, max);      fprintf(pathload_fp,"Measurements finished at %s \n",  buff);      fprintf(pathload_fp,"Measurement latency is %.2f sec \n", time_to_us_delta(exp_start_time, exp_end_time) / 1000000);    }  }  else   {    if ( !interrupt_coalescence && ((converged_gmx_rmx_tm && converged_gmn_rmn_tm) || converged_rmn_rmx_tm ))    {      if (Verbose)        printf("Actual probing rate != desired probing rate.\n");      fprintf(pathload_fp,"Actual probing rate != desired probing rate.\n");      if ( converged_rmn_rmx_tm )      {        min = tr_min ; max = tr_max;      }      else      {        min = grey_min ; max = grey_max ;      }    }    else if ( !interrupt_coalescence && converged_rmn_rmx )    {      if (Verbose)        printf("User specified bandwidth resolution achieved\n");      fprintf(pathload_fp,"User specified bandwidth resolution achieved\n");      min = tr_min ; max = tr_max ;    }    else if ( !interrupt_coalescence && converged_gmn_rmn && converged_gmx_rmx )    {      if (Verbose)        printf("Exiting due to grey bw resolution\n");      fprintf(pathload_fp,"Exiting due to grey bw resolution\n");      min = grey_min ; max = grey_max;    }    else    {      min = tr_min ; max = tr_max;    }    if (verbose||Verbose)    {      if ( lower_bound)      {        printf("Receiver NIC has interrupt coalescence enabled\n");        printf("Available bandwidth is greater than %.2f (Mbps)\n", min);      }      else        printf("Available bandwidth range : %.2f - %.2f (Mbps)\n", min, max);      printf("Measurements finished at %s \n",  buff);      printf("Measurement latency is %.2f sec \n",time_to_us_delta(exp_start_time,exp_end_time)/1000000);    }        if ( lower_bound)    {      fprintf(pathload_fp,"Receiver NIC has interrupt coalescence enabled\n");      fprintf(pathload_fp,"Available bandwidth is greater than %.2f (Mbps)\n", min);    }    else      fprintf(pathload_fp,"Available bandwidth range : %.2f - %.2f (Mbps)\n", min, max);    fprintf(pathload_fp,"Measurements finished at %s \n",  buff);    fprintf(pathload_fp,"Measurement latency is %.2f sec \n", time_to_us_delta(exp_start_time, exp_end_time) / 1000000);  }  if (netlog)    fclose(netlog_fp);  fclose(pathload_fp);   close(sock_tcp);  exit(0);}void netlogger(){    struct tm *tm;    struct hostent *rcv_host, *snd_host;    char rcv_name[256];    struct timeval curr_time;    gettimeofday(&curr_time,NULL);    tm = gmtime(&curr_time.tv_sec);    fprintf(netlog_fp,"DATE=%4d",tm->tm_year+1900);    print_time(netlog_fp,tm->tm_mon+1);    print_time(netlog_fp,tm->tm_mday);    print_time(netlog_fp,tm->tm_hour);    print_time(netlog_fp,tm->tm_min);    if (tm->tm_sec <10) {      fprintf(netlog_fp,"0");      fprintf(netlog_fp,"%1.6f",tm->tm_sec+curr_time.tv_usec/1000000.0);    }    else{      fprintf(netlog_fp,"%1.6f",tm->tm_sec+curr_time.tv_usec/1000000.0);    }    gethostname(rcv_name, 255);    rcv_host = gethostbyname(rcv_name);    if(strcmp(rcv_name, "\0")!=0) fprintf(netlog_fp," HOST=%s",rcv_host->h_name);    else fprintf(netlog_fp," HOST=NO_NAME");    fprintf(netlog_fp," PROG=pathload");    fprintf(netlog_fp," LVL=Usage");    if ((snd_host = gethostbyname(hostname)) == 0) {        snd_host = gethostbyaddr(hostname,256,AF_INET);    }    fprintf(netlog_fp," PATHLOAD.SNDR=%s",snd_host->h_name);    fprintf(netlog_fp," PATHLOAD.ABWL=%.1fMbps",tr_min);    fprintf(netlog_fp," PATHLOAD.ABWH=%.1fMbps\n",tr_max);    fclose(netlog_fp);}/* prl_int32 time */void print_time(FILE *fp, l_int32 time){  if( time<10){    fprintf(fp,"0");    fprintf(fp,"%1d",time);  }  else{    fprintf(fp,"%2d",time);  }}l_int32 less_than(double a, double b){  if ( !equal(a,b) && a < b)    return 1;  else     return 0;}l_int32 grtr_than(double a, double b){  if ( !equal(a,b) && a > b)    return 1;  else     return 0;}/*   if a approx-equal b, return 1   else 0*/l_int32 equal(double a , double b){  l_int32 maxdiff ;  if ( a<b?a:b < 500 ) maxdiff = 2.5 ;  else maxdiff = 5 ;  if ( abs( a - b ) / b <= .02  && abs(a-b) < maxdiff )    return 1 ;  else    return 0;}/* *  Help *  */void help(){  fprintf(stderr, "usage: pathload_rcv [-q|-v] [-o|-O <filename>] [-N <filename>]\[-w <bw_resol>] [-h|-H] -s <sender>\n");  fprintf (stderr,"-s        : hostname/ipaddress of sender\n");  fprintf (stderr,"-q        : quite mode\n");  fprintf (stderr,"-v        : verbose mode\n");  fprintf (stderr,"-w        : user specified bw resolution\n");  fprintf (stderr,"-o <file> : write log in user specified file [default is pathload.log]\n");  fprintf (stderr,"-O <file> : append log in user specified file [default is pathload.log]\n");  fprintf (stderr,"-N <file> : print output in netlogger format to <file>\n");  fprintf (stderr,"-h|H      : print this help and exit\n");  exit(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -