minor changes and packet payloads changed
Этот коммит содержится в:
родитель
6b65cf6e25
Коммит
71a7ccf6d3
152
src/iperf_api.c
152
src/iperf_api.c
@ -43,6 +43,27 @@ static struct option longopts[] =
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void setnonblocking(int sock)
|
||||||
|
{
|
||||||
|
int opts;
|
||||||
|
/*
|
||||||
|
opts = fcntl(sock,F_GETFL);
|
||||||
|
if (opts < 0) {
|
||||||
|
perror("fcntl(F_GETFL)");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
opts = (opts | O_NONBLOCK);
|
||||||
|
if (fcntl(sock,F_SETFL,opts) < 0)
|
||||||
|
{
|
||||||
|
perror("fcntl(F_SETFL)");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void add_interval_list(struct iperf_stream_result *rp, struct iperf_interval_results temp)
|
void add_interval_list(struct iperf_stream_result *rp, struct iperf_interval_results temp)
|
||||||
{
|
{
|
||||||
struct iperf_interval_results *n;
|
struct iperf_interval_results *n;
|
||||||
@ -80,7 +101,7 @@ void display_interval_list(struct iperf_stream_result *rp)
|
|||||||
void send_result_to_client(struct iperf_stream *sp)
|
void send_result_to_client(struct iperf_stream *sp)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
int size = sp->settings->blksize;
|
int size = strlen((char *)sp->data) + 1;
|
||||||
|
|
||||||
printf("BLKSIZE = %d \n", size);
|
printf("BLKSIZE = %d \n", size);
|
||||||
|
|
||||||
@ -97,7 +118,7 @@ void send_result_to_client(struct iperf_stream *sp)
|
|||||||
|
|
||||||
result = send(sp->socket, buf, size , 0);
|
result = send(sp->socket, buf, size , 0);
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void receive_result_from_server(struct iperf_test *test)
|
void receive_result_from_server(struct iperf_test *test)
|
||||||
@ -170,7 +191,7 @@ int set_socket_options(struct iperf_stream *sp, struct iperf_test *tp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TCP_MAXSEG
|
||||||
//-M
|
//-M
|
||||||
if(tp->default_settings->mss > 0)
|
if(tp->default_settings->mss > 0)
|
||||||
{
|
{
|
||||||
@ -181,22 +202,23 @@ int set_socket_options(struct iperf_stream *sp, struct iperf_test *tp)
|
|||||||
assert( sp->socket != -1);
|
assert( sp->socket != -1);
|
||||||
|
|
||||||
/* set */
|
/* set */
|
||||||
new_mss = tp->default_settings->mss;
|
new_mss = tp->default_settings->mss;
|
||||||
len = sizeof( new_mss );
|
len = sizeof( new_mss );
|
||||||
rc = setsockopt( sp->socket, IPPROTO_TCP, TCP_MAXSEG, (char*) &new_mss, len);
|
rc = setsockopt( sp->socket, IPPROTO_TCP, TCP_MAXSEG, (char*) &new_mss, len);
|
||||||
if ( rc == -1) {
|
if ( rc == -1) {
|
||||||
perror("setsockopt");
|
perror("setsockopt");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* verify results */
|
/* verify results */
|
||||||
rc = getsockopt( sp->socket, IPPROTO_TCP, TCP_MAXSEG, (char*) &new_mss, &len);
|
rc = getsockopt( sp->socket, IPPROTO_TCP, TCP_MAXSEG, (char*) &new_mss, &len);
|
||||||
if ( new_mss != tp->default_settings->mss )
|
if ( new_mss != tp->default_settings->mss )
|
||||||
{
|
{
|
||||||
perror("mismatch");
|
perror("mismatch");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,23 +349,30 @@ int iperf_tcp_send(struct iperf_stream *sp)
|
|||||||
{
|
{
|
||||||
case STREAM_BEGIN:
|
case STREAM_BEGIN:
|
||||||
buf[0]= STREAM_BEGIN;
|
buf[0]= STREAM_BEGIN;
|
||||||
break;
|
for(i=1; i < size; i++)
|
||||||
|
buf[i] = i % 37;
|
||||||
|
break;
|
||||||
|
|
||||||
case STREAM_END:
|
case STREAM_END:
|
||||||
buf[0]= STREAM_END;
|
buf[0]= STREAM_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RESULT_REQUEST:
|
case RESULT_REQUEST:
|
||||||
buf[0]= RESULT_REQUEST;
|
buf[0]= RESULT_REQUEST;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ALL_STREAMS_END:
|
case ALL_STREAMS_END:
|
||||||
buf[0]= ALL_STREAMS_END;
|
buf[0]= ALL_STREAMS_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
buf[0]= 0;
|
buf[0]= 0;
|
||||||
|
for(i=1; i < size; i++)
|
||||||
|
buf[i] = i % 37;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i=1; i < size; i++)
|
|
||||||
buf[i] = i % 37;
|
|
||||||
|
|
||||||
//applicable for 1st packet sent
|
//applicable for 1st packet sent
|
||||||
if(sp->settings->state == STREAM_BEGIN)
|
if(sp->settings->state == STREAM_BEGIN)
|
||||||
@ -384,23 +413,29 @@ int iperf_udp_send(struct iperf_stream *sp)
|
|||||||
{
|
{
|
||||||
case STREAM_BEGIN:
|
case STREAM_BEGIN:
|
||||||
buf[0]= STREAM_BEGIN;
|
buf[0]= STREAM_BEGIN;
|
||||||
break;
|
for(i=1; i < size; i++)
|
||||||
case STREAM_END:
|
buf[i] = i % 37;
|
||||||
buf[0]= STREAM_END;
|
break;
|
||||||
break;
|
|
||||||
|
case STREAM_END:
|
||||||
|
buf[0]= STREAM_END;
|
||||||
|
break;
|
||||||
|
|
||||||
case RESULT_REQUEST:
|
case RESULT_REQUEST:
|
||||||
buf[0]= RESULT_REQUEST;
|
buf[0]= RESULT_REQUEST;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ALL_STREAMS_END:
|
case ALL_STREAMS_END:
|
||||||
buf[0]= ALL_STREAMS_END;
|
buf[0]= ALL_STREAMS_END;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
buf[0]= 0;
|
buf[0]= 0;
|
||||||
break;
|
for(i=1; i < size; i++)
|
||||||
}
|
buf[i] = i % 37;
|
||||||
|
break;
|
||||||
for(i=1; i < size; i++)
|
}
|
||||||
buf[i] = i % 37;
|
|
||||||
|
|
||||||
// applicable for 1st packet sent
|
// applicable for 1st packet sent
|
||||||
if(sp->settings->state == STREAM_BEGIN)
|
if(sp->settings->state == STREAM_BEGIN)
|
||||||
{
|
{
|
||||||
@ -433,8 +468,6 @@ int iperf_udp_send(struct iperf_stream *sp)
|
|||||||
free(buf);
|
free(buf);
|
||||||
} // timer_expired_micro
|
} // timer_expired_micro
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -540,7 +573,6 @@ void iperf_init_test(struct iperf_test *test)
|
|||||||
perror("unable to set window");
|
perror("unable to set window");
|
||||||
}
|
}
|
||||||
|
|
||||||
//setting noblock causes error in byte count -kprabhu
|
|
||||||
//setnonblocking(s);
|
//setnonblocking(s);
|
||||||
|
|
||||||
sp = test->new_stream(test);
|
sp = test->new_stream(test);
|
||||||
@ -628,44 +660,43 @@ char *iperf_reporter_callback(struct iperf_test *test)
|
|||||||
iperf_size_t bytes=0;
|
iperf_size_t bytes=0;
|
||||||
double start_time, end_time;
|
double start_time, end_time;
|
||||||
// need to reassign this
|
// need to reassign this
|
||||||
char *message = (char *) malloc(500);
|
char *message = (char *) malloc(500);
|
||||||
|
|
||||||
// used to determine the length of reporter buffer
|
// used to determine the length of reporter buffer
|
||||||
while(sp)
|
while(sp)
|
||||||
{
|
{
|
||||||
count ++;
|
count ++;
|
||||||
sp = sp->next;
|
sp = sp->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
sp = test->streams;
|
|
||||||
|
|
||||||
char *message_final = (char *) malloc((count+1) * (strlen(report_bw_jitter_loss_header) + strlen(report_bw_jitter_loss_format) + strlen(report_sum_bw_jitter_loss_format)) );
|
char *message_final = (char *) malloc((count+1) * (strlen(report_bw_jitter_loss_header) + strlen(report_bw_jitter_loss_format) + strlen(report_sum_bw_jitter_loss_format)));
|
||||||
|
|
||||||
struct iperf_interval_results *ip = test->streams->result->interval_results;
|
struct iperf_interval_results *ip = test->streams->result->interval_results;
|
||||||
|
|
||||||
|
sp = test->streams;
|
||||||
|
|
||||||
if(test->default_settings->state == TEST_RUNNING)
|
if(test->default_settings->state == TEST_RUNNING)
|
||||||
{
|
{
|
||||||
while(sp)
|
while(sp)
|
||||||
{
|
{
|
||||||
while(ip->next!= NULL)
|
while(ip->next!= NULL)
|
||||||
ip = ip->next;
|
ip = ip->next;
|
||||||
|
|
||||||
bytes+= ip->bytes_transferred;
|
bytes+= ip->bytes_transferred;
|
||||||
unit_snprintf(ubuf, UNIT_LEN, (double) (ip->bytes_transferred), test->unit_format);
|
unit_snprintf(ubuf, UNIT_LEN, (double) (ip->bytes_transferred), test->unit_format);
|
||||||
|
|
||||||
test->stats_interval = test->stats_interval== 0 ? test->duration : test->stats_interval;
|
test->stats_interval = test->stats_interval== 0 ? test->duration : test->stats_interval;
|
||||||
|
|
||||||
unit_snprintf(nbuf, UNIT_LEN, (double) (ip->bytes_transferred / test->stats_interval), test->unit_format);
|
unit_snprintf(nbuf, UNIT_LEN, (double) (ip->bytes_transferred / test->stats_interval), test->unit_format);
|
||||||
|
|
||||||
sprintf(message,report_bw_header);
|
sprintf(message,report_bw_header);
|
||||||
strcat(message_final, message);
|
strcat(message_final, message);
|
||||||
|
|
||||||
if(test->stats_interval!= 0)
|
if(test->stats_interval!= 0)
|
||||||
sprintf(message, report_bw_format, sp->socket, (double)ip->interval_duration, (double)ip->interval_duration + test->stats_interval, ubuf, nbuf);
|
sprintf(message, report_bw_format, sp->socket, (double)ip->interval_duration, (double)ip->interval_duration + test->stats_interval, ubuf, nbuf);
|
||||||
|
|
||||||
strcat(message_final, message);
|
strcat(message_final, message);
|
||||||
|
|
||||||
sp = sp->next;
|
sp = sp->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
unit_snprintf(ubuf, UNIT_LEN, (double) ( bytes), test->unit_format);
|
unit_snprintf(ubuf, UNIT_LEN, (double) ( bytes), test->unit_format);
|
||||||
@ -761,7 +792,7 @@ char *iperf_reporter_callback(struct iperf_test *test)
|
|||||||
// -m option
|
// -m option
|
||||||
if((test->print_mss != 0) && (test->role == 'c'))
|
if((test->print_mss != 0) && (test->role == 'c'))
|
||||||
{
|
{
|
||||||
sprintf(message,"the TCP maximum segment size mss = %d \n", getsock_tcp_mss(sp->socket));
|
sprintf(message,"\nThe TCP maximum segment size mss = %d \n", getsock_tcp_mss(sp->socket));
|
||||||
strcat(message_final, message);
|
strcat(message_final, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -891,6 +922,9 @@ int iperf_udp_accept(struct iperf_test *test)
|
|||||||
sp = test->new_stream(test);
|
sp = test->new_stream(test);
|
||||||
sp->socket = test->listener_sock_udp;
|
sp->socket = test->listener_sock_udp;
|
||||||
|
|
||||||
|
//setting noblock doesn't report back to client
|
||||||
|
//setnonblocking( sp->socket);
|
||||||
|
|
||||||
iperf_init_stream(sp, test);
|
iperf_init_stream(sp, test);
|
||||||
sp->result->bytes_received+= sz;
|
sp->result->bytes_received+= sz;
|
||||||
iperf_add_stream(test, sp);
|
iperf_add_stream(test, sp);
|
||||||
@ -928,6 +962,8 @@ int iperf_tcp_accept(struct iperf_test *test)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
sp = test->new_stream(test);
|
sp = test->new_stream(test);
|
||||||
|
|
||||||
|
//setting noblock doesn't report back to client
|
||||||
//setnonblocking(peersock);
|
//setnonblocking(peersock);
|
||||||
|
|
||||||
FD_SET(peersock, &test->read_set);
|
FD_SET(peersock, &test->read_set);
|
||||||
@ -1355,7 +1391,8 @@ main(int argc, char **argv)
|
|||||||
test->default_settings->rate = unit_atof(optarg);
|
test->default_settings->rate = unit_atof(optarg);
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
test->default_settings->blksize = atol(optarg);
|
test->default_settings->blksize = unit_atoi(optarg);
|
||||||
|
printf("%lld is the blksize\n", unit_atoi(optarg));
|
||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
test->default_settings->socket_bufsize = unit_atof(optarg);
|
test->default_settings->socket_bufsize = unit_atof(optarg);
|
||||||
@ -1371,6 +1408,7 @@ main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
test->default_settings->mss = atoi(optarg);
|
test->default_settings->mss = atoi(optarg);
|
||||||
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
test->unit_format = *optarg;
|
test->unit_format = *optarg;
|
||||||
printf("%c is format \n", test->unit_format);
|
printf("%c is format \n", test->unit_format);
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user