implemented UDP-timer changes , o/p format changes
Этот коммит содержится в:
родитель
8b44cd5a88
Коммит
c6ffef11b4
@ -88,6 +88,9 @@ void send_result_to_client(struct iperf_stream *sp)
|
|||||||
perror("malloc: unable to allocate transmit buffer");
|
perror("malloc: unable to allocate transmit buffer");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// adding the string terminator to the message
|
||||||
|
buf[strlen((char *)sp->data)] = '\0';
|
||||||
|
|
||||||
memcpy(buf, sp->data, strlen((char *)sp->data));
|
memcpy(buf, sp->data, strlen((char *)sp->data));
|
||||||
|
|
||||||
result = send(sp->socket, buf, size , 0);
|
result = send(sp->socket, buf, size , 0);
|
||||||
@ -124,6 +127,7 @@ void receive_result_from_server(struct iperf_test *test)
|
|||||||
} while (result == -1 && errno == EINTR);
|
} while (result == -1 && errno == EINTR);
|
||||||
|
|
||||||
printf( server_reporting, sp->socket);
|
printf( server_reporting, sp->socket);
|
||||||
|
|
||||||
puts(buf);
|
puts(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,8 +265,7 @@ int iperf_tcp_recv(struct iperf_stream *sp)
|
|||||||
printf(" Recieved %d from client\n", message);
|
printf(" Recieved %d from client\n", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(message!= STREAM_END)
|
sp->result->bytes_received+= result;
|
||||||
sp->result->bytes_received+= result;
|
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
return message;
|
return message;
|
||||||
@ -291,8 +294,7 @@ int iperf_udp_recv(struct iperf_stream *sp)
|
|||||||
message = (int) ch;
|
message = (int) ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(message!= STREAM_END)
|
sp->result->bytes_received+= result;
|
||||||
sp->result->bytes_received+= result;
|
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
return message;
|
return message;
|
||||||
@ -315,7 +317,6 @@ int iperf_tcp_send(struct iperf_stream *sp)
|
|||||||
buf[0]= STREAM_BEGIN;
|
buf[0]= STREAM_BEGIN;
|
||||||
break;
|
break;
|
||||||
case STREAM_END:
|
case STREAM_END:
|
||||||
printf("STREAM END STARTING\n");
|
|
||||||
buf[0]= STREAM_END;
|
buf[0]= STREAM_END;
|
||||||
break;
|
break;
|
||||||
case RESULT_REQUEST:
|
case RESULT_REQUEST:
|
||||||
@ -340,12 +341,6 @@ int iperf_tcp_send(struct iperf_stream *sp)
|
|||||||
|
|
||||||
result = send(sp->socket, buf, size , 0);
|
result = send(sp->socket, buf, size , 0);
|
||||||
|
|
||||||
if(result <=0)
|
|
||||||
{
|
|
||||||
perror("send:");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
sp->result->bytes_sent+= size;
|
sp->result->bytes_sent+= size;
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
@ -354,7 +349,7 @@ int iperf_tcp_send(struct iperf_stream *sp)
|
|||||||
|
|
||||||
int iperf_udp_send(struct iperf_stream *sp)
|
int iperf_udp_send(struct iperf_stream *sp)
|
||||||
{
|
{
|
||||||
int result, i;
|
int result = 0, i;
|
||||||
struct timeval before, after;
|
struct timeval before, after;
|
||||||
int64_t adjustus, dtargus;
|
int64_t adjustus, dtargus;
|
||||||
|
|
||||||
@ -406,14 +401,9 @@ int iperf_udp_send(struct iperf_stream *sp)
|
|||||||
perror("gettimeofday");
|
perror("gettimeofday");
|
||||||
|
|
||||||
result = send(sp->socket, buf, size, 0);
|
result = send(sp->socket, buf, size, 0);
|
||||||
if(result <=0)
|
|
||||||
{
|
|
||||||
perror("send:");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if(sp->settings->state != STREAM_END)
|
||||||
sp->result->bytes_sent+= result;
|
sp->result->bytes_sent+= result;
|
||||||
|
|
||||||
if(gettimeofday(&after, 0) < 0)
|
if(gettimeofday(&after, 0) < 0)
|
||||||
perror("gettimeofday");
|
perror("gettimeofday");
|
||||||
@ -422,19 +412,16 @@ int iperf_udp_send(struct iperf_stream *sp)
|
|||||||
adjustus += (before.tv_sec - after.tv_sec) * SEC_TO_US ;
|
adjustus += (before.tv_sec - after.tv_sec) * SEC_TO_US ;
|
||||||
adjustus += (before.tv_usec - after.tv_usec);
|
adjustus += (before.tv_usec - after.tv_usec);
|
||||||
|
|
||||||
//printf(" the adjust time = %lld \n",dtargus- adjustus);
|
|
||||||
if( adjustus > 0) {
|
if( adjustus > 0) {
|
||||||
dtargus = adjustus;
|
dtargus = adjustus;
|
||||||
}
|
}
|
||||||
memcpy(&before, &after, sizeof before);
|
memcpy(&before, &after, sizeof before);
|
||||||
|
|
||||||
// RESET THE TIMER
|
// RESET THE TIMER
|
||||||
sp->send_timer = new_timer(0, dtargus);
|
update_timer(sp->send_timer, 0, dtargus);
|
||||||
//printf(" new timer is %lld usec\n", dtargus);
|
|
||||||
|
|
||||||
} // timer_expired_micro
|
} // timer_expired_micro
|
||||||
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,10 +514,10 @@ void iperf_init_test(struct iperf_test *test)
|
|||||||
FD_SET(s, &test->write_set);
|
FD_SET(s, &test->write_set);
|
||||||
test->max_fd = (test->max_fd < s) ? s : test->max_fd;
|
test->max_fd = (test->max_fd < s) ? s : test->max_fd;
|
||||||
|
|
||||||
set_tcp_windowsize(sp->socket, test->default_settings->socket_bufsize, SO_SNDBUF);
|
if( set_tcp_windowsize(s, test->default_settings->socket_bufsize, SO_SNDBUF))
|
||||||
|
{
|
||||||
if(s < 0)
|
perror("unable to set window");
|
||||||
exit(0);
|
}
|
||||||
|
|
||||||
//setting noblock causes error in byte count -kprabhu
|
//setting noblock causes error in byte count -kprabhu
|
||||||
//setnonblocking(s);
|
//setnonblocking(s);
|
||||||
@ -539,6 +526,8 @@ void iperf_init_test(struct iperf_test *test)
|
|||||||
sp->socket = s;
|
sp->socket = s;
|
||||||
iperf_init_stream(sp, test);
|
iperf_init_stream(sp, test);
|
||||||
iperf_add_stream(test, sp);
|
iperf_add_stream(test, sp);
|
||||||
|
|
||||||
|
if(test->default_settings->state != RESULT_REQUEST)
|
||||||
connect_msg(sp);
|
connect_msg(sp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -548,6 +537,7 @@ void iperf_free_test(struct iperf_test *test)
|
|||||||
{
|
{
|
||||||
|
|
||||||
free(test->default_settings);
|
free(test->default_settings);
|
||||||
|
test->streams = NULL;
|
||||||
free(test);
|
free(test);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,7 +607,8 @@ char *iperf_reporter_callback(struct iperf_test *test)
|
|||||||
double start_time, end_time;
|
double start_time, end_time;
|
||||||
// need to reassign this
|
// need to reassign this
|
||||||
char *message = (char *) malloc(300);
|
char *message = (char *) malloc(300);
|
||||||
char *message_final = (char *) malloc(test->num_streams * 50 + 200);
|
char *message_final = (char *) malloc(test->num_streams * (strlen(report_bw_header) + strlen(report_bw_format)) + strlen(report_sum_bw_format));
|
||||||
|
|
||||||
|
|
||||||
struct iperf_interval_results *ip = test->streams->result->interval_results;
|
struct iperf_interval_results *ip = test->streams->result->interval_results;
|
||||||
|
|
||||||
@ -876,9 +867,10 @@ int iperf_udp_accept(struct iperf_test *test)
|
|||||||
FD_SET(test->listener_sock, &test->read_set);
|
FD_SET(test->listener_sock, &test->read_set);
|
||||||
test->max_fd = (test->max_fd < test->listener_sock) ? test->listener_sock : test->max_fd;
|
test->max_fd = (test->max_fd < test->listener_sock) ? test->listener_sock : test->max_fd;
|
||||||
|
|
||||||
connect_msg(sp);
|
if(test->default_settings->state != RESULT_REQUEST)
|
||||||
free(buf);
|
connect_msg(sp);
|
||||||
|
|
||||||
|
free(buf);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -908,6 +900,8 @@ int iperf_tcp_accept(struct iperf_test *test)
|
|||||||
sp->socket = peersock;
|
sp->socket = peersock;
|
||||||
iperf_init_stream(sp, test);
|
iperf_init_stream(sp, test);
|
||||||
iperf_add_stream(test, sp);
|
iperf_add_stream(test, sp);
|
||||||
|
|
||||||
|
if(test->default_settings->state != RESULT_REQUEST)
|
||||||
connect_msg(sp);
|
connect_msg(sp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1074,7 +1068,7 @@ void iperf_run_server(struct iperf_test *test)
|
|||||||
printf("TEST_END\n\n\n");
|
printf("TEST_END\n\n\n");
|
||||||
|
|
||||||
// reset TEST params
|
// reset TEST params
|
||||||
iperf_defaults(test);
|
test->default_settings->state = TEST_START;
|
||||||
test->max_fd = test->listener_sock;
|
test->max_fd = test->listener_sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1125,11 +1119,11 @@ void iperf_run_server(struct iperf_test *test)
|
|||||||
|
|
||||||
void iperf_run_client(struct iperf_test *test)
|
void iperf_run_client(struct iperf_test *test)
|
||||||
{
|
{
|
||||||
int i,result;
|
int i,result=0;
|
||||||
struct iperf_stream *sp, *np;
|
struct iperf_stream *sp, *np;
|
||||||
struct timer *timer, *stats_interval, *reporter_interval;
|
struct timer *timer, *stats_interval, *reporter_interval;
|
||||||
char *buf, *read= NULL;
|
char *buf, *read= NULL;
|
||||||
int64_t delayus, adjustus, dtargus;
|
int64_t delayus, adjustus, dtargus, remaining, min;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
int ret=0;
|
int ret=0;
|
||||||
tv.tv_sec = 15; // timeout interval in seconds
|
tv.tv_sec = 15; // timeout interval in seconds
|
||||||
@ -1168,7 +1162,7 @@ void iperf_run_client(struct iperf_test *test)
|
|||||||
while(!timer->expired(timer))
|
while(!timer->expired(timer))
|
||||||
{
|
{
|
||||||
ret = select(test->max_fd+1, NULL, &test->write_set, NULL, &tv);
|
ret = select(test->max_fd+1, NULL, &test->write_set, NULL, &tv);
|
||||||
if(ret<0)
|
if(ret < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
sp= test->streams;
|
sp= test->streams;
|
||||||
@ -1177,7 +1171,7 @@ void iperf_run_client(struct iperf_test *test)
|
|||||||
{
|
{
|
||||||
if(FD_ISSET(sp->socket, &test->write_set))
|
if(FD_ISSET(sp->socket, &test->write_set))
|
||||||
{
|
{
|
||||||
result = sp->snd(sp);
|
result+= sp->snd(sp);
|
||||||
|
|
||||||
if(sp->next==NULL)
|
if(sp->next==NULL)
|
||||||
break;
|
break;
|
||||||
@ -1186,6 +1180,24 @@ void iperf_run_client(struct iperf_test *test)
|
|||||||
}// FD_ISSET
|
}// FD_ISSET
|
||||||
}// for
|
}// for
|
||||||
|
|
||||||
|
//result =0 hence no data sent, hence sleep
|
||||||
|
|
||||||
|
if(result == 0)
|
||||||
|
{
|
||||||
|
sp = test->streams;
|
||||||
|
min = timer_remaining(sp->send_timer);
|
||||||
|
while(sp)
|
||||||
|
{
|
||||||
|
remaining = timer_remaining(sp->send_timer);
|
||||||
|
min = min < remaining ? min : remaining;
|
||||||
|
sp = sp->next;
|
||||||
|
}
|
||||||
|
usleep (min/2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
result = 0;
|
||||||
|
|
||||||
|
|
||||||
if((test->stats_interval!= 0) && stats_interval->expired(stats_interval))
|
if((test->stats_interval!= 0) && stats_interval->expired(stats_interval))
|
||||||
{
|
{
|
||||||
test->stats_callback(test);
|
test->stats_callback(test);
|
||||||
@ -1214,8 +1226,6 @@ void iperf_run_client(struct iperf_test *test)
|
|||||||
sp = np;
|
sp = np;
|
||||||
sp->settings->state = STREAM_END;
|
sp->settings->state = STREAM_END;
|
||||||
sp->snd(sp);
|
sp->snd(sp);
|
||||||
printf("sent the STREAM_END message \n");
|
|
||||||
|
|
||||||
np = sp->next;
|
np = sp->next;
|
||||||
} while (np);
|
} while (np);
|
||||||
|
|
||||||
@ -1236,6 +1246,10 @@ void iperf_run_client(struct iperf_test *test)
|
|||||||
|
|
||||||
// Requesting for result from Server
|
// Requesting for result from Server
|
||||||
receive_result_from_server(test);
|
receive_result_from_server(test);
|
||||||
|
|
||||||
|
free_timer(stats_interval);
|
||||||
|
free_timer(reporter_interval);
|
||||||
|
free_timer(timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int iperf_run(struct iperf_test *test)
|
int iperf_run(struct iperf_test *test)
|
||||||
@ -1312,11 +1326,10 @@ main(int argc, char **argv)
|
|||||||
test->default_settings->mss = atoi(optarg);
|
test->default_settings->mss = atoi(optarg);
|
||||||
case 'f':
|
case 'f':
|
||||||
test->unit_format = *optarg;
|
test->unit_format = *optarg;
|
||||||
|
printf("%c is format \n", test->unit_format);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("ROLE = %s\n", (test->role == 's') ? "Server" : "Client");
|
|
||||||
|
|
||||||
test->stats_callback = iperf_stats_callback;
|
test->stats_callback = iperf_stats_callback;
|
||||||
test->reporter_callback = iperf_reporter_callback;
|
test->reporter_callback = iperf_reporter_callback;
|
||||||
|
|
||||||
@ -1337,5 +1350,7 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
iperf_run(test);
|
iperf_run(test);
|
||||||
|
|
||||||
|
iperf_free_test(test);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
64
src/timer.c
64
src/timer.c
@ -11,7 +11,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
double timeval_to_double(struct timeval *tv)
|
double
|
||||||
|
timeval_to_double(struct timeval *tv)
|
||||||
{
|
{
|
||||||
double d;
|
double d;
|
||||||
|
|
||||||
@ -20,33 +21,15 @@ double timeval_to_double(struct timeval *tv)
|
|||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double
|
||||||
double timeval_diff(struct timeval *tv0, struct timeval *tv1)
|
timeval_diff(struct timeval *tv0, struct timeval *tv1)
|
||||||
{
|
{
|
||||||
return timeval_to_double(tv1) - timeval_to_double(tv0);
|
return timeval_to_double(tv1) - timeval_to_double(tv0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
int
|
int
|
||||||
timer_expired(struct timer *tp)
|
timer_expired(struct timer *tp)
|
||||||
{
|
{
|
||||||
struct timeval now;
|
|
||||||
double d= 0;
|
|
||||||
if(gettimeofday(&now, NULL) < 0) {
|
|
||||||
perror("gettimeofday");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
d = timeval_to_double(&tp->end) - timeval_to_double(&now);
|
|
||||||
|
|
||||||
return d <= 0;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
int
|
|
||||||
timer_expired(struct timer *tp)
|
|
||||||
{
|
|
||||||
|
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
int64_t end = 0, current= 0, diff= 0;
|
int64_t end = 0, current= 0, diff= 0;
|
||||||
if(gettimeofday(&now, NULL) < 0) {
|
if(gettimeofday(&now, NULL) < 0) {
|
||||||
@ -64,8 +47,22 @@ timer_expired(struct timer *tp)
|
|||||||
|
|
||||||
return diff <= 0;
|
return diff <= 0;
|
||||||
|
|
||||||
}
|
// currently using microsecond limit. Else we need to introduce timespec instread of timeval
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
update_timer(struct timer *tp, time_t sec, suseconds_t usec)
|
||||||
|
{
|
||||||
|
if(gettimeofday(&tp->begin, NULL) < 0) {
|
||||||
|
perror("gettimeofday");
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(&tp->end, &tp->begin, sizeof(struct timer));
|
||||||
|
tp->end.tv_sec = tp->begin.tv_sec + (time_t) sec;
|
||||||
|
tp->end.tv_usec = tp->begin.tv_usec + (time_t) usec;
|
||||||
|
|
||||||
|
tp->expired = timer_expired;
|
||||||
|
}
|
||||||
|
|
||||||
struct timer *
|
struct timer *
|
||||||
new_timer(time_t sec, suseconds_t usec)
|
new_timer(time_t sec, suseconds_t usec)
|
||||||
@ -117,4 +114,27 @@ delay(int64_t ns)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t
|
||||||
|
timer_remaining(struct timer *tp)
|
||||||
|
{
|
||||||
|
struct timeval now;
|
||||||
|
int64_t end = 0, current= 0, diff= 0;
|
||||||
|
if(gettimeofday(&now, NULL) < 0) {
|
||||||
|
perror("gettimeofday");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
end+= tp->end.tv_sec * 1000000 ;
|
||||||
|
end+= tp->end.tv_usec;
|
||||||
|
|
||||||
|
current+= now.tv_sec * 1000000 ;
|
||||||
|
current+= now.tv_usec;
|
||||||
|
|
||||||
|
diff = end - current;
|
||||||
|
if(diff > 0)
|
||||||
|
return diff;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,3 +11,10 @@ int delay(int64_t ns);
|
|||||||
double timeval_to_double(struct timeval *tv);
|
double timeval_to_double(struct timeval *tv);
|
||||||
|
|
||||||
double timeval_diff(struct timeval *tv0, struct timeval *tv1);
|
double timeval_diff(struct timeval *tv0, struct timeval *tv1);
|
||||||
|
|
||||||
|
void update_timer(struct timer *tp, time_t sec, suseconds_t usec);
|
||||||
|
|
||||||
|
int64_t timer_remaining(struct timer *tp);
|
||||||
|
|
||||||
|
void free_timer(struct timer *tp);
|
||||||
|
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user