1
1

TCP_INFO seems to be working on FreeBSD now

Этот коммит содержится в:
Brian Tierney 2009-10-23 22:58:32 +00:00
родитель c0c797b0eb
Коммит a1eb8922d3
4 изменённых файлов: 43 добавлений и 31 удалений

Просмотреть файл

@ -7,7 +7,7 @@
/* /*
* TO DO list: * TO DO list:
* test TCP_INFO * test TCP_INFO on Linux
* restructure code pull out main.c * restructure code pull out main.c
* cleanup/fix/test UDP mode * cleanup/fix/test UDP mode
* add verbose and debug options * add verbose and debug options
@ -884,7 +884,7 @@ iperf_stats_callback(struct iperf_test * test)
struct iperf_stream_result *rp = test->streams->result; struct iperf_stream_result *rp = test->streams->result;
struct iperf_interval_results *ip, temp; struct iperf_interval_results *ip, temp;
printf("in stats_callback: num_streams = %d \n", test->num_streams); //printf("in stats_callback: num_streams = %d \n", test->num_streams);
for (i = 0; i < test->num_streams; i++) for (i = 0; i < test->num_streams; i++)
{ {
rp = sp->result; rp = sp->result;
@ -900,9 +900,6 @@ iperf_stats_callback(struct iperf_test * test)
temp.interval_duration = timeval_diff(&sp->result->start_time, &temp.interval_time); temp.interval_duration = timeval_diff(&sp->result->start_time, &temp.interval_time);
if (test->tcp_info)
get_tcpinfo(test);
gettimeofday(&sp->result->end_time, NULL); gettimeofday(&sp->result->end_time, NULL);
add_interval_list(rp, temp); add_interval_list(rp, temp);
} else } else
@ -924,12 +921,12 @@ iperf_stats_callback(struct iperf_test * test)
gettimeofday(&temp.interval_time, NULL); gettimeofday(&temp.interval_time, NULL);
temp.interval_duration = timeval_diff(&sp->result->start_time, &temp.interval_time); temp.interval_duration = timeval_diff(&sp->result->start_time, &temp.interval_time);
if (test->tcp_info)
get_tcpinfo(test);
gettimeofday(&sp->result->end_time, NULL); gettimeofday(&sp->result->end_time, NULL);
add_interval_list(rp, temp); add_interval_list(rp, temp);
} }
if (test->tcp_info)
get_tcpinfo(test, &temp);
/* for debugging */ /* for debugging */
/* display_interval_list(rp, test->tcp_info); */ /* display_interval_list(rp, test->tcp_info); */
@ -941,6 +938,7 @@ iperf_stats_callback(struct iperf_test * test)
} }
/**************************************************************************/ /**************************************************************************/
/* XXX: this routine is confusing, and should be cleaned up and/or better commented -blt */
char * char *
iperf_reporter_callback(struct iperf_test * test) iperf_reporter_callback(struct iperf_test * test)
{ {
@ -952,6 +950,7 @@ iperf_reporter_callback(struct iperf_test * test)
double start_time, end_time; double start_time, end_time;
char *message = (char *) malloc(500); char *message = (char *) malloc(500);
//printf("in iperf_reporter_callback \n");
/* used to determine the length of reporter buffer */ /* used to determine the length of reporter buffer */
while (sp) while (sp)
{ {
@ -971,7 +970,7 @@ iperf_reporter_callback(struct iperf_test * test)
if (test->default_settings->state == TEST_RUNNING) if (test->default_settings->state == TEST_RUNNING)
{ {
while (sp) while (sp) /* for each stream */
{ {
ip = sp->result->interval_results; ip = sp->result->interval_results;
while (ip->next != NULL) while (ip->next != NULL)
@ -990,17 +989,6 @@ iperf_reporter_callback(struct iperf_test * test)
test->default_settings->unit_format); test->default_settings->unit_format);
sprintf(message, report_bw_format, sp->socket, ip_prev->interval_duration, ip->interval_duration, ubuf, nbuf); sprintf(message, report_bw_format, sp->socket, ip_prev->interval_duration, ip->interval_duration, ubuf, nbuf);
#if defined(linux)
/* TODO: do something similar to this everywhere */
sprintf(message, report_tcpInfo, ip->tcpInfo.tcpi_snd_cwnd, ip->tcpInfo.tcpi_snd_ssthresh,
ip->tcpInfo.tcpi_rcv_ssthresh, ip->tcpInfo.tcpi_unacked, ip->tcpInfo.tcpi_sacked,
ip->tcpInfo.tcpi_lost, ip->tcpInfo.tcpi_retrans, ip->tcpInfo.tcpi_fackets);
#endif
#if defined(__FreeBSD__)
sprintf(message, report_tcpInfo, ip->tcpInfo.tcpi_snd_cwnd,
ip->tcpInfo.tcpi_snd_ssthresh, ip->tcpInfo.tcpi_rcv_space, ip->tcpInfo.__tcpi_retrans);
#endif
} else } else
{ {
@ -1011,6 +999,11 @@ iperf_reporter_callback(struct iperf_test * test)
sprintf(message, report_bw_format, sp->socket, 0.0, ip->interval_duration, ubuf, nbuf); sprintf(message, report_bw_format, sp->socket, 0.0, ip->interval_duration, ubuf, nbuf);
} }
strcat(message_final, message); strcat(message_final, message);
if(test->tcp_info)
{
build_tcpinfo_message(ip, message);
strcat(message_final, message);
}
sp = sp->next; sp = sp->next;
} }
@ -1029,8 +1022,12 @@ iperf_reporter_callback(struct iperf_test * test)
unit_snprintf(nbuf, UNIT_LEN, (double) (bytes / ip->interval_duration), test->default_settings->unit_format); unit_snprintf(nbuf, UNIT_LEN, (double) (bytes / ip->interval_duration), test->default_settings->unit_format);
sprintf(message, report_sum_bw_format, 0.0, ip->interval_duration, ubuf, nbuf); sprintf(message, report_sum_bw_format, 0.0, ip->interval_duration, ubuf, nbuf);
} }
strcat(message_final, message); strcat(message_final, message);
if(test->tcp_info)
{
build_tcpinfo_message(ip, message);
strcat(message_final, message);
}
free(message); free(message);
} }
} }
@ -1084,6 +1081,7 @@ iperf_reporter_callback(struct iperf_test * test)
if (sp->outoforder_packets > 0) if (sp->outoforder_packets > 0)
printf(report_sum_outoforder, start_time, end_time, sp->cnt_error); printf(report_sum_outoforder, start_time, end_time, sp->cnt_error);
} }
/* XXX: do we need to do something with any TCP_INFO results here too? */
} }
sp = sp->next; sp = sp->next;
} }

Просмотреть файл

@ -392,8 +392,10 @@ void iperf_init_stream(struct iperf_stream * sp, struct iperf_test * testp)
*/ */
void iperf_free_stream(struct iperf_test * test, struct iperf_stream * sp); void iperf_free_stream(struct iperf_test * test, struct iperf_stream * sp);
void get_tcpinfo(struct iperf_test *test); void get_tcpinfo(struct iperf_test *test, struct iperf_interval_results *rp);
void print_tcpinfo(struct iperf_interval_results *); void print_tcpinfo(struct iperf_interval_results *);
void build_tcpinfo_message(struct iperf_interval_results *r, char *message);
#endif /* IPERF_API_H */ #endif /* IPERF_API_H */

Просмотреть файл

@ -226,11 +226,11 @@ const char reportCSV_peer[] =
#if defined(linux) #if defined(linux)
const char report_tcpInfo[] = const char report_tcpInfo[] =
" event=TCP_Info CWND=%u RCV_WIND=%u SND_SSTHRESH=%u UNACKED=%u SACK=%u LOST=%u RETRANS=%u FACK=%u RTT=%u"; "event=TCP_Info CWND=%u RCV_WIND=%u SND_SSTHRESH=%u UNACKED=%u SACK=%u LOST=%u RETRANS=%u FACK=%u RTT=%u";
#endif #endif
#if defined(__FreeBSD__) #if defined(__FreeBSD__)
const char report_tcpInfo[] = const char report_tcpInfo[] =
" event=TCP_Info CWND=%u RCV_WIND=%u SND_SSTHRESH=%u RTT=%u"; "event=TCP_Info CWND=%u RCV_WIND=%u SND_SSTHRESH=%u RTT=%u";
#endif #endif

Просмотреть файл

@ -22,7 +22,7 @@
/*************************************************************/ /*************************************************************/
void void
get_tcpinfo(struct iperf_test *test) get_tcpinfo(struct iperf_test *test, struct iperf_interval_results *rp)
{ {
#if defined(linux) || defined(__FreeBSD__) #if defined(linux) || defined(__FreeBSD__)
socklen_t tcp_info_length; socklen_t tcp_info_length;
@ -35,12 +35,10 @@ get_tcpinfo(struct iperf_test *test)
if (getsockopt(sp->socket, IPPROTO_TCP, TCP_INFO, (void *)&tcpInfo, &tcp_info_length) < 0) { if (getsockopt(sp->socket, IPPROTO_TCP, TCP_INFO, (void *)&tcpInfo, &tcp_info_length) < 0) {
perror("getsockopt"); perror("getsockopt");
} }
printf("get TCP_INFP: %d, %d, %d, %d\n", tcpInfo.tcpi_snd_cwnd, memcpy(&rp->tcpInfo, &tcpInfo, sizeof(tcpInfo));
tcpInfo.tcpi_snd_ssthresh, tcpInfo.tcpi_rcv_space, tcpInfo.tcpi_rtt); printf(" got TCP_INFO: %d, %d, %d, %d\n", rp->tcpInfo.tcpi_snd_cwnd,
/* rp->tcpInfo.tcpi_snd_ssthresh, rp->tcpInfo.tcpi_rcv_space, rp->tcpInfo.tcpi_rtt);
* memcpy(&temp.tcpInfo, &tcpInfo, sizeof(tcpInfo)); return;
*/
/* need to copy these results somewhere! */
#else #else
return; return;
#endif #endif
@ -53,13 +51,27 @@ print_tcpinfo(struct iperf_interval_results *r)
#if defined(linux) #if defined(linux)
printf(report_tcpInfo, r->tcpInfo.tcpi_snd_cwnd, r->tcpInfo.tcpi_snd_ssthresh, printf(report_tcpInfo, r->tcpInfo.tcpi_snd_cwnd, r->tcpInfo.tcpi_snd_ssthresh,
r->tcpInfo.tcpi_rcv_ssthresh, r->tcpInfo.tcpi_unacked, r->tcpInfo.tcpi_sacked, r->tcpInfo.tcpi_rcv_ssthresh, r->tcpInfo.tcpi_unacked, r->tcpInfo.tcpi_sacked,
r->tcpInfo.tcpi_lost, r->tcpInfo.tcpi_retrans, r->tcpInfo.tcpi_fackets); r->tcpInfo.tcpi_lost, r->tcpInfo.tcpi_retrans, r->tcpInfo.tcpi_fackets);
#endif #endif
#if defined(__FreeBSD__) #if defined(__FreeBSD__)
printf(report_tcpInfo, r->tcpInfo.tcpi_snd_cwnd, r->tcpInfo.tcpi_rcv_space, printf(report_tcpInfo, r->tcpInfo.tcpi_snd_cwnd, r->tcpInfo.tcpi_rcv_space,
r->tcpInfo.tcpi_snd_ssthresh, r->tcpInfo.tcpi_rtt); r->tcpInfo.tcpi_snd_ssthresh, r->tcpInfo.tcpi_rtt);
#endif #endif
}
/*************************************************************/
void
build_tcpinfo_message(struct iperf_interval_results *r, char *message)
{
#if defined(linux)
sprintf(message, report_tcpInfo, r->tcpInfo.tcpi_snd_cwnd, r->tcpInfo.tcpi_snd_ssthresh,
r->tcpInfo.tcpi_rcv_ssthresh, r->tcpInfo.tcpi_unacked, r->tcpInfo.tcpi_sacked,
r->tcpInfo.tcpi_lost, r->tcpInfo.tcpi_retrans, r->tcpInfo.tcpi_fackets);
#endif
#if defined(__FreeBSD__)
sprintf(message, report_tcpInfo, r->tcpInfo.tcpi_snd_cwnd,
r->tcpInfo.tcpi_snd_ssthresh, r->tcpInfo.tcpi_rcv_space, r->tcpInfo.tcpi_rtt);
#endif
} }