implemented UDP-timer changes , o/p format changes
This commit is contained in:
parent
8b44cd5a88
commit
c6ffef11b4
@ -88,6 +88,9 @@ void send_result_to_client(struct iperf_stream *sp)
|
||||
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));
|
||||
|
||||
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);
|
||||
|
||||
printf( server_reporting, sp->socket);
|
||||
|
||||
puts(buf);
|
||||
}
|
||||
|
||||
@ -261,7 +265,6 @@ int iperf_tcp_recv(struct iperf_stream *sp)
|
||||
printf(" Recieved %d from client\n", message);
|
||||
}
|
||||
|
||||
if(message!= STREAM_END)
|
||||
sp->result->bytes_received+= result;
|
||||
|
||||
free(buf);
|
||||
@ -291,7 +294,6 @@ int iperf_udp_recv(struct iperf_stream *sp)
|
||||
message = (int) ch;
|
||||
}
|
||||
|
||||
if(message!= STREAM_END)
|
||||
sp->result->bytes_received+= result;
|
||||
|
||||
free(buf);
|
||||
@ -315,7 +317,6 @@ int iperf_tcp_send(struct iperf_stream *sp)
|
||||
buf[0]= STREAM_BEGIN;
|
||||
break;
|
||||
case STREAM_END:
|
||||
printf("STREAM END STARTING\n");
|
||||
buf[0]= STREAM_END;
|
||||
break;
|
||||
case RESULT_REQUEST:
|
||||
@ -340,12 +341,6 @@ int iperf_tcp_send(struct iperf_stream *sp)
|
||||
|
||||
result = send(sp->socket, buf, size , 0);
|
||||
|
||||
if(result <=0)
|
||||
{
|
||||
perror("send:");
|
||||
return -1;
|
||||
}
|
||||
|
||||
sp->result->bytes_sent+= size;
|
||||
|
||||
free(buf);
|
||||
@ -354,7 +349,7 @@ int iperf_tcp_send(struct iperf_stream *sp)
|
||||
|
||||
int iperf_udp_send(struct iperf_stream *sp)
|
||||
{
|
||||
int result, i;
|
||||
int result = 0, i;
|
||||
struct timeval before, after;
|
||||
int64_t adjustus, dtargus;
|
||||
|
||||
@ -406,13 +401,8 @@ int iperf_udp_send(struct iperf_stream *sp)
|
||||
perror("gettimeofday");
|
||||
|
||||
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;
|
||||
|
||||
if(gettimeofday(&after, 0) < 0)
|
||||
@ -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_usec - after.tv_usec);
|
||||
|
||||
//printf(" the adjust time = %lld \n",dtargus- adjustus);
|
||||
if( adjustus > 0) {
|
||||
dtargus = adjustus;
|
||||
}
|
||||
memcpy(&before, &after, sizeof before);
|
||||
|
||||
// RESET THE TIMER
|
||||
sp->send_timer = new_timer(0, dtargus);
|
||||
//printf(" new timer is %lld usec\n", dtargus);
|
||||
update_timer(sp->send_timer, 0, dtargus);
|
||||
|
||||
} // timer_expired_micro
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -527,10 +514,10 @@ void iperf_init_test(struct iperf_test *test)
|
||||
FD_SET(s, &test->write_set);
|
||||
test->max_fd = (test->max_fd < s) ? s : test->max_fd;
|
||||
|
||||
set_tcp_windowsize(sp->socket, test->default_settings->socket_bufsize, SO_SNDBUF);
|
||||
|
||||
if(s < 0)
|
||||
exit(0);
|
||||
if( set_tcp_windowsize(s, test->default_settings->socket_bufsize, SO_SNDBUF))
|
||||
{
|
||||
perror("unable to set window");
|
||||
}
|
||||
|
||||
//setting noblock causes error in byte count -kprabhu
|
||||
//setnonblocking(s);
|
||||
@ -539,6 +526,8 @@ void iperf_init_test(struct iperf_test *test)
|
||||
sp->socket = s;
|
||||
iperf_init_stream(sp, test);
|
||||
iperf_add_stream(test, sp);
|
||||
|
||||
if(test->default_settings->state != RESULT_REQUEST)
|
||||
connect_msg(sp);
|
||||
}
|
||||
}
|
||||
@ -548,6 +537,7 @@ void iperf_free_test(struct iperf_test *test)
|
||||
{
|
||||
|
||||
free(test->default_settings);
|
||||
test->streams = NULL;
|
||||
free(test);
|
||||
}
|
||||
|
||||
@ -617,7 +607,8 @@ char *iperf_reporter_callback(struct iperf_test *test)
|
||||
double start_time, end_time;
|
||||
// need to reassign this
|
||||
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;
|
||||
|
||||
@ -876,9 +867,10 @@ int iperf_udp_accept(struct iperf_test *test)
|
||||
FD_SET(test->listener_sock, &test->read_set);
|
||||
test->max_fd = (test->max_fd < test->listener_sock) ? test->listener_sock : test->max_fd;
|
||||
|
||||
if(test->default_settings->state != RESULT_REQUEST)
|
||||
connect_msg(sp);
|
||||
free(buf);
|
||||
|
||||
free(buf);
|
||||
return 0;
|
||||
|
||||
}
|
||||
@ -908,6 +900,8 @@ int iperf_tcp_accept(struct iperf_test *test)
|
||||
sp->socket = peersock;
|
||||
iperf_init_stream(sp, test);
|
||||
iperf_add_stream(test, sp);
|
||||
|
||||
if(test->default_settings->state != RESULT_REQUEST)
|
||||
connect_msg(sp);
|
||||
|
||||
return 0;
|
||||
@ -1074,7 +1068,7 @@ void iperf_run_server(struct iperf_test *test)
|
||||
printf("TEST_END\n\n\n");
|
||||
|
||||
// reset TEST params
|
||||
iperf_defaults(test);
|
||||
test->default_settings->state = TEST_START;
|
||||
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)
|
||||
{
|
||||
int i,result;
|
||||
int i,result=0;
|
||||
struct iperf_stream *sp, *np;
|
||||
struct timer *timer, *stats_interval, *reporter_interval;
|
||||
char *buf, *read= NULL;
|
||||
int64_t delayus, adjustus, dtargus;
|
||||
int64_t delayus, adjustus, dtargus, remaining, min;
|
||||
struct timeval tv;
|
||||
int ret=0;
|
||||
tv.tv_sec = 15; // timeout interval in seconds
|
||||
@ -1168,7 +1162,7 @@ void iperf_run_client(struct iperf_test *test)
|
||||
while(!timer->expired(timer))
|
||||
{
|
||||
ret = select(test->max_fd+1, NULL, &test->write_set, NULL, &tv);
|
||||
if(ret<0)
|
||||
if(ret < 0)
|
||||
continue;
|
||||
|
||||
sp= test->streams;
|
||||
@ -1177,7 +1171,7 @@ void iperf_run_client(struct iperf_test *test)
|
||||
{
|
||||
if(FD_ISSET(sp->socket, &test->write_set))
|
||||
{
|
||||
result = sp->snd(sp);
|
||||
result+= sp->snd(sp);
|
||||
|
||||
if(sp->next==NULL)
|
||||
break;
|
||||
@ -1186,6 +1180,24 @@ void iperf_run_client(struct iperf_test *test)
|
||||
}// FD_ISSET
|
||||
}// 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))
|
||||
{
|
||||
test->stats_callback(test);
|
||||
@ -1214,8 +1226,6 @@ void iperf_run_client(struct iperf_test *test)
|
||||
sp = np;
|
||||
sp->settings->state = STREAM_END;
|
||||
sp->snd(sp);
|
||||
printf("sent the STREAM_END message \n");
|
||||
|
||||
np = sp->next;
|
||||
} while (np);
|
||||
|
||||
@ -1236,6 +1246,10 @@ void iperf_run_client(struct iperf_test *test)
|
||||
|
||||
// Requesting for result from Server
|
||||
receive_result_from_server(test);
|
||||
|
||||
free_timer(stats_interval);
|
||||
free_timer(reporter_interval);
|
||||
free_timer(timer);
|
||||
}
|
||||
|
||||
int iperf_run(struct iperf_test *test)
|
||||
@ -1312,11 +1326,10 @@ main(int argc, char **argv)
|
||||
test->default_settings->mss = atoi(optarg);
|
||||
case 'f':
|
||||
test->unit_format = *optarg;
|
||||
printf("%c is format \n", test->unit_format);
|
||||
break;
|
||||
}
|
||||
|
||||
printf("ROLE = %s\n", (test->role == 's') ? "Server" : "Client");
|
||||
|
||||
test->stats_callback = iperf_stats_callback;
|
||||
test->reporter_callback = iperf_reporter_callback;
|
||||
|
||||
@ -1337,5 +1350,7 @@ main(int argc, char **argv)
|
||||
|
||||
iperf_run(test);
|
||||
|
||||
iperf_free_test(test);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
62
src/timer.c
62
src/timer.c
@ -11,7 +11,8 @@
|
||||
|
||||
|
||||
|
||||
double timeval_to_double(struct timeval *tv)
|
||||
double
|
||||
timeval_to_double(struct timeval *tv)
|
||||
{
|
||||
double d;
|
||||
|
||||
@ -20,33 +21,15 @@ double timeval_to_double(struct timeval *tv)
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
double timeval_diff(struct timeval *tv0, struct timeval *tv1)
|
||||
double
|
||||
timeval_diff(struct timeval *tv0, struct timeval *tv1)
|
||||
{
|
||||
return timeval_to_double(tv1) - timeval_to_double(tv0);
|
||||
}
|
||||
|
||||
/*
|
||||
int
|
||||
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;
|
||||
int64_t end = 0, current= 0, diff= 0;
|
||||
if(gettimeofday(&now, NULL) < 0) {
|
||||
@ -64,8 +47,22 @@ timer_expired(struct timer *tp)
|
||||
|
||||
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 *
|
||||
new_timer(time_t sec, suseconds_t usec)
|
||||
@ -117,4 +114,27 @@ delay(int64_t ns)
|
||||
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_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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user